:root {
  --bg:        #F5F2EC;
  --surface:   #FFFFFF;
  --surface-2: #FBF9F5;
  --ink:       #2E2E2C;
  --muted:     #7C7871;
  --line:      #E4DFD5;
  --line-soft: #EFEBE3;
  --income:    #5F8F73;
  --income-bg: #E8F0EA;
  --expense:   #B5726C;
  --expense-bg:#F6E9E8;
  --goal:      #9A7B4B;
  --goal-bg:   #F4EDE1;
  --accent:    #4F6F7E;
  --warn:      #B8863B;
  --up:        #C43C3C;
  --up-bg:     #F8E7E5;
  --down:      #1F7A3A;
  --down-bg:   #E5F1E8;
  --s1:        #2a78d6;
  --s2:        #eb6834;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(46,46,44,.05), 0 4px 16px rgba(46,46,44,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #1B1A19;
    --surface:   #242322;
    --surface-2: #2B2A28;
    --ink:       #EDEAE4;
    --muted:     #9C978E;
    --line:      #3A3835;
    --line-soft: #322F2C;
    --income:    #86BE9C;
    --income-bg: #22302A;
    --expense:   #DB9A94;
    --expense-bg:#332524;
    --goal:      #D6B27A;
    --goal-bg:   #322B1F;
    --accent:    #8FB4C4;
    --warn:      #DCAE63;
    --up:        #E66767;
    --up-bg:     #3A2423;
    --down:      #4CB36A;
    --down-bg:   #1F3326;
    --s1:        #3987e5;
    --s2:        #d95926;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
               "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: 76px; }

a { color: var(--accent); }

/* ── ヘッダ ─────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.appbar h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .02em; }
.appbar .sub { color: var(--muted); font-size: 12px; margin-left: auto; }
.appbar .sub a { color: var(--muted); text-decoration: none; }

.wrap { max-width: 940px; margin: 0 auto; padding: 14px; }

/* ── ナビ ───────────────────────────────── */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 7px;
  font-size: 10px; text-decoration: none; color: var(--muted);
  border-top: 2px solid transparent;
}
.nav a .ico { font-size: 17px; line-height: 1; }
.nav a.on { color: var(--accent); border-top-color: var(--accent); }

/* ── カード ─────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card > h2 {
  margin: 0 0 10px;
  font-size: 13px; font-weight: 650; letter-spacing: .04em;
  color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.card > h2 .right { margin-left: auto; font-weight: 500; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .grid3 { grid-template-columns: 1fr 1fr; } }

/* ── 数字 ───────────────────────────────── */
.num  { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.big  { font-size: 30px; font-weight: 640; letter-spacing: -.02em; line-height: 1.15; }
.mid  { font-size: 20px; font-weight: 620; }
.big small { font-size: .5em; font-weight: 500; margin-left: 2px; opacity: .7; }
.yen::after { content: "円"; font-size: .62em; font-weight: 500; margin-left: 2px; opacity: .7; }
.income  { color: var(--income); }
.expense { color: var(--expense); }
.muted   { color: var(--muted); }
.small   { font-size: 12px; }
.tiny    { font-size: 11px; }


/* ── バッジ ─────────────────────────────── */
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 99px;
  font-size: 11px; font-weight: 600; line-height: 1.7;
  background: var(--line-soft); color: var(--muted);
  white-space: nowrap;
}
.badge.inc { background: var(--income-bg);  color: var(--income); }
.badge.exp { background: var(--expense-bg); color: var(--expense); }

/* ── テーブル ───────────────────────────── */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 9px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th { font-size: 11px; font-weight: 620; color: var(--muted); letter-spacing: .03em; background: var(--surface-2); position: sticky; top: 0; }
td.r, th.r { text-align: right; }
tr.past td { color: var(--muted); }
tr.cur td { background: color-mix(in srgb, var(--accent) 7%, transparent); font-weight: 600; }
tbody tr:hover td { background: var(--surface-2); }

/* ── フォーム ───────────────────────────── */
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 3px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=month],
input[type=password], input[type=file], select, textarea {
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); color: var(--ink);
  font-size: 15px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
textarea { min-height: 60px; resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 130px; min-width: 0; }
.chk { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink); margin: 10px 0 0; font-weight: 500; }
.chk input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink);
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--line-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger  { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 40%, transparent); background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: center; }

/* ── フラッシュ ─────────────────────────── */
.flash {
  padding: 10px 13px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; font-weight: 550;
  background: var(--income-bg); color: var(--income);
  border: 1px solid color-mix(in srgb, var(--income) 25%, transparent);
}
.flash.err { background: var(--expense-bg); color: var(--expense); border-color: color-mix(in srgb, var(--expense) 25%, transparent); }

/* ── 明細行 ─────────────────────────────── */
.list { list-style: none; margin: 0; padding: 0; }
.list > li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line-soft);
}
.list > li:last-child { border-bottom: 0; }
.list .name { flex: 1; min-width: 0; }
.list .name b { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 620; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

details.item { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--surface); }
details.item > summary {
  padding: 10px 12px; cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 9px;
}
details.item > summary::-webkit-details-marker { display: none; }
details.item > .body { padding: 0 12px 12px; border-top: 1px solid var(--line-soft); }

.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }

/* ── グラフのツールチップ ───────────────── */
.chartwrap { position: relative; }
.charttip {
  position: absolute; z-index: 5; top: 0; left: 0;
  transform: translate(-50%, 0);
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 2px 10px rgba(46, 46, 44, .14);
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) {
  .charttip { box-shadow: 0 2px 12px rgba(0, 0, 0, .5); }
}
.charttip[hidden] { display: none; }
.charttip .tipym { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.charttip .tiprow { display: flex; align-items: center; gap: 6px; }
.charttip .tiprow i { width: 9px; height: 3px; border-radius: 2px; flex: none; }
.charttip .tiprow b { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 650; }
.charttip .tiprow span { color: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 2.5px; border-radius: 2px; display: inline-block; }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 13px; }
hr.sep { border: 0; border-top: 1px solid var(--line-soft); margin: 14px 0; }
.pill-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.pill-tabs a {
  padding: 5px 13px; border-radius: 99px; font-size: 13px; text-decoration: none;
  border: 1px solid var(--line); color: var(--muted); background: var(--surface); white-space: nowrap;
}
.pill-tabs a.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ── reikabu ───────────────────────────── */
body.nonav { padding-bottom: 0; }

.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.badge.up   { background: var(--up-bg);   color: var(--up); }
.badge.down { background: var(--down-bg); color: var(--down); }
.badge.hit  { background: var(--accent); color: #fff; }
.badge.miss { background: var(--line-soft); color: var(--ink); }

.row-baseline { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 2px 0 4px; }

/* 予想の3択 */
.choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.choice .opt { position: relative; margin: 0; font-size: 13px; color: var(--ink); }
.choice .opt input { position: absolute; opacity: 0; pointer-events: none; }
.choice .opt span {
  display: block; text-align: center; padding: 10px 4px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2);
  cursor: pointer; font-weight: 600;
}
.choice .opt input:focus-visible + span { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.choice .opt.up   input:checked + span { background: var(--up-bg);   border-color: var(--up);   color: var(--up); }
.choice .opt.down input:checked + span { background: var(--down-bg); border-color: var(--down); color: var(--down); }
.choice .opt.flat input:checked + span { background: var(--line-soft); border-color: var(--muted); }

.mypred p { margin: 8px 0 10px; }
.vs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.vs > div { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.review { margin-top: 6px; }

/* ほかの動き */
.moves { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 16px; margin-bottom: 8px; }
.mgroup { min-width: 0; }
.mhead { font-size: 11px; color: var(--muted); font-weight: 620; margin: 6px 0 2px; }
.mrow { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 2px 0; border-bottom: 1px solid var(--line-soft); }

/* 理由ノート */
.notehead { display: flex; gap: 8px; align-items: baseline; }
.ntitle { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.item[open] .ntitle { white-space: normal; }
.factors { list-style: none; margin: 8px 0; padding: 0; }
.factors li { padding: 5px 0; font-size: 14px; border-bottom: 1px solid var(--line-soft); }
.factors li .badge { margin-right: 6px; }
.lesson {
  background: var(--goal-bg); border-radius: 9px; padding: 9px 11px; margin: 10px 0; font-size: 14px;
}
.lesson b { display: block; font-size: 11px; color: var(--goal); margin-bottom: 2px; }
.sources { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.sources li { margin: 3px 0; word-break: break-all; }

/* 連動 */
.linkchart { width: 100%; min-height: 200px; }
.linkchart .grid  { stroke: var(--line-soft); stroke-width: 1; }
.linkchart .axis0 { stroke: var(--line); stroke-width: 1.5; }
.linkchart .ylab, .linkchart .xlab { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.linkchart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.linkchart .dot { stroke: var(--surface); stroke-width: 2; }
.linklist > li { gap: 8px; }
.linklist > li.on { background: color-mix(in srgb, var(--accent) 8%, transparent); margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.linklist .name { text-decoration: none; color: var(--ink); }
.linklist .name .tiny { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linklist .amt { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; }
.linklist .corr { display: inline-flex; align-items: center; gap: 4px; }
.linklist .bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); }
.linklist .bar.neg { background: var(--muted); }
.tiny p { margin: 6px 0; }
