/* todo-app と同じ iOS 風トークン(ダーク/ライト) */
:root, :root[data-theme="dark"] {
  --bg: #000000; --card: #1C1C1E; --card2: #2C2C2E; --line: #38383A;
  --text: #FFFFFF; --muted: #8E8E93; --dim: #48484A;
  --inc: #0A84FF; --exp: #FF453A; --ok: #30D158;
  --inc-soft: rgba(10,132,255,.18); --exp-soft: rgba(255,69,58,.18); --ok-soft: rgba(48,209,88,.18);
  --hl: rgba(255,255,255,.09); --on-text: #000000;
  --shadow: 0 4px 16px rgba(0,0,0,.35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F2F2F7; --card: #FFFFFF; --card2: #E7E7EC; --line: #D1D1D6;
  --text: #1C1C1E; --muted: #6E6E73; --dim: #B4B4BA;
  --inc: #0A6FD1; --exp: #D63A2C; --ok: #1D9E4B;
  --inc-soft: rgba(10,111,209,.12); --exp-soft: rgba(214,58,44,.12); --ok-soft: rgba(29,158,75,.12);
  --hl: rgba(0,0,0,.07); --on-text: #FFFFFF;
  --shadow: 0 4px 16px rgba(0,0,0,.12);
  color-scheme: light;
}
:root { --radius: 16px; --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", -apple-system, system-ui, sans-serif; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
body { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0; vertical-align: middle; }
.i.sm { width: 14px; height: 14px; stroke-width: 2; }

/* ヘッダー */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px; display: flex; align-items: center; justify-content: space-between;
  max-width: 640px; margin: 0 auto; }
h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: .01em; }
h2 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
#themeBtn { width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); padding: 0;
  display: flex; align-items: center; justify-content: center; border-radius: 999px; }

main { padding: 0 16px; max-width: 640px; margin: 0 auto; }
.tab { display: none; } .tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.inc { color: var(--inc); } .exp { color: var(--exp); }

/* ボタン・入力(todo-app と同じカプセル型) */
button, input, select { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px;
  padding: 10px 18px; cursor: pointer; touch-action: manipulation; transition: background .15s, opacity .15s; }
button:active { background: var(--hl); }
button.primary { background: var(--text); border-color: var(--text); color: var(--on-text); font-weight: 600; }
button.primary:active { opacity: .8; }
button.danger { color: var(--exp); border-color: var(--exp-soft); }
button.wide { width: 100%; margin: 8px 0; padding: 14px 18px; }
button.icon { width: 40px; height: 40px; padding: 0; border: 0; background: var(--card); display: flex; align-items: center; justify-content: center; color: var(--muted); }
button:disabled { opacity: .5; }
input, select { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card2); color: var(--text);
  font-size: 16px; -webkit-appearance: none; appearance: none; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type=checkbox] { width: 18px; height: 18px; padding: 0; -webkit-appearance: auto; appearance: auto; accent-color: var(--text); }
input:focus, select:focus { outline: none; border-color: var(--text); }
input::placeholder { color: var(--dim); }
.form label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0; }
.form label input, .form label select { margin-top: 6px; }
.row { display: flex; gap: 8px; margin-top: 12px; } .row > * { flex: 1; } .row > button { flex: 0 0 auto; }

/* 週ナビ・サマリー */
.weeknav { display: flex; align-items: center; justify-content: space-between; text-align: center; margin-top: 4px; }
.weeklabel { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
#weekBadge { min-height: 22px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 10px; border-radius: 999px;
  background: var(--ok-soft); color: var(--ok); margin-top: 4px; font-weight: 600; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.summary div { background: var(--card); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.summary span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.summary b { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.bar { margin: 12px 0; } .bar .lbl { display: flex; justify-content: space-between; font-size: 14px; }
.bar .lbl span:last-child { font-variant-numeric: tabular-nums; }
.bar .track { height: 6px; background: var(--card2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar .fill { height: 100%; background: var(--exp); border-radius: 99px; } .bar.income .fill { background: var(--inc); }

/* リスト */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-top: .5px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .main div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sub { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.list .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.list li.tap { cursor: pointer; } .list li.tap:active { background: var(--hl); }
.list li button { padding: 6px 12px; font-size: 13px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* 読み取り */
.scanbtn { display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px dashed var(--dim); border-radius: var(--radius);
  padding: 18px; margin: 12px 0; cursor: pointer; }
.scanbtn:active { background: var(--hl); }
.scanbtn .big { width: 48px; height: 48px; border-radius: 999px; background: var(--card2); display: flex; align-items: center; justify-content: center; }
.scanbtn .big .i { width: 24px; height: 24px; }
.scanbtn small { color: var(--muted); }
.cand { border-radius: 14px; padding: 12px; margin: 8px 0; background: var(--card); }
.cand .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cand .grid .full { grid-column: 1 / -1; }
.cand.off { opacity: .4; }
.cand header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.cand header label { display: flex; align-items: center; gap: 6px; color: var(--text); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--card2); color: var(--muted); }

/* セグメント(todo-app の切替と同じ見た目) */
.seg { display: flex; background: var(--card2); border-radius: 999px; padding: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.2); }

/* 資産 */
.total { text-align: center; padding-top: 20px; } .total b { display: block; font-size: 34px; font-weight: 700; margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
#assetChart svg { width: 100%; height: 120px; display: block; }
.group h2 { margin: 20px 0 4px; }

/* 下のタブバー(todo-app と同じフローティングのカプセル型) */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--bg);
  padding: 6px 10px calc(2px + env(safe-area-inset-bottom)); }
.tabs .pill { max-width: 480px; margin: 0 auto; display: flex; background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px; box-shadow: var(--shadow); }
.tabs button { flex: 1; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 3px;
  border-radius: 999px; padding: 7px 4px 8px; color: var(--muted); font-size: 10px; }
.tabs button.on { background: var(--card2); color: var(--text); font-weight: 600; }
.tabs button.on .i { stroke-width: 2.2; }

dialog { border: 0; border-radius: 20px; padding: 18px; width: min(92vw, 440px); max-height: 85vh; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h3 { margin: 0 0 6px; font-size: 18px; }
dialog input, dialog select { background: var(--card2); }
details summary { cursor: pointer; padding: 6px 0; }
#toast { position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top)); transform: translateX(-50%); background: var(--card2); color: var(--text);
  padding: 8px 16px; border-radius: 999px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 90;
  max-width: 90vw; box-shadow: var(--shadow); }
#toast.show { opacity: 1; }
