/* 色は全部ここのトークンで指定する。暗い表示はトークンを差し替えるだけ */
:root {
  color-scheme: light;
  --page: #f2f2ef;
  --card: #fcfcfb;
  --card-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #256abf;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --good-ink: #006300;
  --bad-ink: #b42828;
  --warn: #fab219;
  --critical: #d03b3b;
  /* グラフの系列（検証済み: 収入＝青・支出＝橙） */
  --s-income: #2a78d6;
  --s-expense: #eb6834;
  --key: #fcfcfb;
  --key-press: #e1e0d9;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 18px rgba(0, 0, 0, 0.05);
  --scrim: rgba(0, 0, 0, 0.32);
  /* 目立つカード（大事な数字）。テーマの色で塗り、字は白 */
  --hero-a: #2f78d0;
  --hero-b: #1d4f99;
  --hero-ink: #ffffff;
  --hero-ink-2: rgba(255, 255, 255, 0.82);
  --hero-track: rgba(255, 255, 255, 0.28);
  --hero-glow: rgba(37, 106, 191, 0.28);
  /* 設定の色の見本（明るさに関係なく同じ色で見せる） */
  --sw-blue: #256abf;
  --sw-green: #17784c;
  --sw-purple: #6a4bc4;
  --sw-pink: #c0306e;
  --sw-ink: #2f2f2d;
  --sheet-shadow: 0 -6px 28px rgba(0, 0, 0, 0.16);
  --font: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --card: #1a1a19;
    --card-2: #242422;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #898781;
    --line: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: #1c3a5e;
    --good-ink: #0ca30c;
    --bad-ink: #e66767;
    --s-income: #3987e5;
    --s-expense: #d95926;
    --key: #242422;
    --key-press: #383835;
    --shadow: none;
    --hero-a: #2a64b0;
    --hero-b: #173f7a;
    --hero-glow: transparent;
    --scrim: rgba(0, 0, 0, 0.6);
    --sheet-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --card: #1a1a19;
  --card-2: #242422;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --line: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --accent-soft: #1c3a5e;
  --good-ink: #0ca30c;
  --bad-ink: #e66767;
  --s-income: #3987e5;
  --s-expense: #d95926;
  --key: #242422;
  --key-press: #383835;
  --shadow: none;
  --hero-a: #2a64b0;
  --hero-b: #173f7a;
  --hero-glow: transparent;
  --scrim: rgba(0, 0, 0, 0.6);
  --sheet-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* テーマの色（設定で選ぶ。青は上の基本の値）。暗い表示の値も同時に決める */
:root[data-accent="green"] { --accent: #17784c; --accent-ink: #ffffff; --accent-soft: #cdeedd; --hero-a: #1f8a59; --hero-b: #0f5c3a; --hero-glow: rgba(23, 120, 76, 0.28); }
@media (prefers-color-scheme: dark) { :root[data-accent="green"]:not([data-theme="light"]) { --accent: #2a9a65; --accent-ink: #ffffff; --accent-soft: #173d2b; --hero-a: #1d7a4f; --hero-b: #0e4a30; --hero-glow: transparent; } }
:root[data-accent="green"][data-theme="dark"] { --accent: #2a9a65; --accent-ink: #ffffff; --accent-soft: #173d2b; --hero-a: #1d7a4f; --hero-b: #0e4a30; --hero-glow: transparent; }
:root[data-accent="purple"] { --accent: #6a4bc4; --accent-ink: #ffffff; --accent-soft: #e2dafc; --hero-a: #7a5bd6; --hero-b: #4f3399; --hero-glow: rgba(106, 75, 196, 0.28); }
@media (prefers-color-scheme: dark) { :root[data-accent="purple"]:not([data-theme="light"]) { --accent: #8a6ff0; --accent-ink: #ffffff; --accent-soft: #2e2552; --hero-a: #6a4bc4; --hero-b: #3d2878; --hero-glow: transparent; } }
:root[data-accent="purple"][data-theme="dark"] { --accent: #8a6ff0; --accent-ink: #ffffff; --accent-soft: #2e2552; --hero-a: #6a4bc4; --hero-b: #3d2878; --hero-glow: transparent; }
:root[data-accent="pink"] { --accent: #c0306e; --accent-ink: #ffffff; --accent-soft: #fadbe7; --hero-a: #d43f7e; --hero-b: #962056; --hero-glow: rgba(192, 48, 110, 0.28); }
@media (prefers-color-scheme: dark) { :root[data-accent="pink"]:not([data-theme="light"]) { --accent: #e0558f; --accent-ink: #ffffff; --accent-soft: #4a1f33; --hero-a: #b0386e; --hero-b: #741a43; --hero-glow: transparent; } }
:root[data-accent="pink"][data-theme="dark"] { --accent: #e0558f; --accent-ink: #ffffff; --accent-soft: #4a1f33; --hero-a: #b0386e; --hero-b: #741a43; --hero-glow: transparent; }
:root[data-accent="ink"] { --accent: #2f2f2d; --accent-ink: #ffffff; --accent-soft: #e4e3de; --hero-a: #3f3f3c; --hero-b: #151514; --hero-glow: rgba(0, 0, 0, 0.22); }
@media (prefers-color-scheme: dark) { :root[data-accent="ink"]:not([data-theme="light"]) { --accent: #d9d8d2; --accent-ink: #0b0b0b; --accent-soft: #3a3a37; --hero-a: #3a3a37; --hero-b: #1f1f1e; --hero-glow: transparent; } }
:root[data-accent="ink"][data-theme="dark"] { --accent: #d9d8d2; --accent-ink: #0b0b0b; --accent-soft: #3a3a37; --hero-a: #3a3a37; --hero-b: #1f1f1e; --hero-glow: transparent; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.sm { width: 16px; height: 16px; }
.ico circle[r="1"] { fill: currentColor; }

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding-top: var(--safe-t);
}
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 24px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 52px; padding: 6px 16px;
}
.title { font-size: 26px; font-weight: 800; letter-spacing: .02em; margin: 0; }
.link-btn { color: var(--accent); font-weight: 600; padding: 8px 4px; }

/* 種類の切り替え */
.seg { display: inline-flex; background: var(--card-2); border-radius: 10px; padding: 3px; }
.seg-btn { min-width: 84px; padding: 7px 14px; border-radius: 8px; font-weight: 600; color: var(--ink-2); }
.seg-btn[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 1px var(--ring); }

/* 月の切り替え */
.month-nav { display: flex; align-items: center; gap: 0; margin-left: auto; background: var(--card); border-radius: 12px; box-shadow: 0 0 0 1px var(--ring); }
.month-nav .icon-btn { width: 36px; height: 36px; }
.month-label { min-width: 104px; text-align: center; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; color: var(--ink-2); }
.icon-btn:active { background: var(--card-2); }
.icon-btn:disabled { opacity: .3; }

/* 入力 */
/* 余った高さは上に回し、入力のまとまりは親指の届くテンキーの上に寄せる */
/* justify-content: flex-end だとあふれた上側がスクロールで戻れないので、先頭の伸びる空き（::before）で寄せる */
.input-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.input-body::before { content: ""; flex: 1 0 0; margin-bottom: -10px; }
#view-input .topbar { justify-content: center; position: relative; }
#view-input .edit-actions { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); }
.edit-note { align-self: flex-start; font-size: 13px; color: var(--accent); background: var(--accent-soft); padding: 3px 10px; border-radius: 99px; font-weight: 600; }
/* 今月の支出は、上の余った場所に目立つ帯で出す（order で伸びる空きより前に置く） */
.month-mini {
  order: -1; flex: none; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 4px;
  font-size: 13px; color: var(--hero-ink-2); padding: 12px 16px; border-radius: 16px; font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); box-shadow: 0 6px 18px var(--hero-glow);
}
.month-mini b { color: var(--hero-ink); font-size: 17px; }
.month-mini .neg { color: var(--hero-ink); font-weight: 700; }
.amount-row {
  display: flex; align-items: baseline; justify-content: flex-end; gap: 6px;
  background: var(--card); border-radius: 14px; padding: 10px 16px; box-shadow: var(--shadow), 0 0 0 1px var(--ring);
}
.yen { font-size: 22px; color: var(--ink-3); font-weight: 600; }
.amount { font-size: 38px; font-weight: 700; letter-spacing: .01em; font-variant-numeric: tabular-nums; line-height: 1.15; overflow-wrap: anywhere; }
.amount.zero { color: var(--ink-3); }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat {
  min-height: clamp(36px, 5.4dvh, 48px); padding: 6px 4px; border-radius: 10px; background: var(--card);
  box-shadow: 0 0 0 1px var(--ring); font-size: 14px; line-height: 1.2; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis;
}
.cat[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: none; font-weight: 600; }
.meta-row { display: flex; gap: 8px; align-items: stretch; }
.date-box { display: flex; align-items: center; background: var(--card); border-radius: 12px; box-shadow: 0 0 0 1px var(--ring); }
.date-box .icon-btn { width: 34px; }
.date-label { position: relative; display: flex; align-items: center; gap: 5px; font-weight: 600; font-size: 15px; white-space: nowrap; padding: 0 2px; }
.date-label input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.memo {
  flex: 1; min-width: 0; border: 0; background: var(--card); border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 0 0 1px var(--ring); font-size: 16px;
}
.memo:focus, .field:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* テンキー（保存は2段ぶんの高さ） */
.keypad {
  display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: clamp(46px, 7.2dvh, 62px); gap: 6px;
  padding: 8px 16px 10px; background: var(--page);
}
.keypad button {
  background: var(--key); border-radius: 12px; font-size: 22px; font-weight: 600; box-shadow: var(--shadow), 0 0 0 1px var(--ring);
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.keypad button:active { background: var(--key-press); }
.keypad .k-fn { color: var(--ink-2); font-size: 18px; }
.keypad .k-save { grid-column: 4; grid-row: 3 / span 2; background: var(--accent); color: var(--accent-ink); font-size: 18px; box-shadow: none; }
.keypad .k-save:active { filter: brightness(.9); background: var(--accent); }
.keypad .k-save:disabled { opacity: .45; }
.edit-actions { display: flex; align-items: center; gap: 4px; }
.danger-ico { color: var(--bad-ink); }
.amount .op { color: var(--ink-3); font-weight: 400; margin: 0 .15em; }
.amount-sum { font-size: 14px; color: var(--ink-2); text-align: right; margin-top: -6px; font-variant-numeric: tabular-nums; }

/* 下のタブ */
.tabbar {
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 0 5px; font-size: 11px; color: var(--ink-3); }
.tab .ico { width: 52px; height: 28px; padding: 3px 15px; border-radius: 99px; transition: background-color .15s; }
.tab[aria-current="page"] { color: var(--accent); font-weight: 700; }
.tab[aria-current="page"] .ico { background: var(--accent-soft); }

/* カード・合計 */
.card { background: var(--card); border-radius: 18px; box-shadow: var(--shadow), 0 0 0 1px var(--ring); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 16px; color: var(--ink); font-weight: 700; margin: 0 0 10px; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.total { background: var(--card); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow), 0 0 0 1px var(--ring); min-width: 0; }
.total .k { font-size: 12px; color: var(--ink-2); }
.total .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos { color: var(--good-ink); }
.neg { color: var(--bad-ink); }

/* 明細 */
.day { margin-bottom: 12px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); padding: 0 4px 4px; font-variant-numeric: tabular-nums; }
.rows { background: var(--card); border-radius: 16px; box-shadow: var(--shadow), 0 0 0 1px var(--ring); overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 11px 14px; min-height: 52px; }
.row + .row { border-top: 1px solid var(--line); }
.row:active { background: var(--card-2); }
.row .main { flex: 1; min-width: 0; }
.row .cat-name { font-weight: 600; font-size: 15px; }
.row .memo-t { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.income { background: var(--s-income); }
.dot.expense { background: var(--s-expense); }
.empty { text-align: center; color: var(--ink-3); padding: 48px 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent);
  border-radius: 99px; padding: 5px 8px 5px 12px; font-size: 13px; font-weight: 600; margin-bottom: 12px;
}

/* 集計 */
.hero { background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); color: var(--hero-ink); box-shadow: 0 10px 28px var(--hero-glow); padding: 18px; }
.hero .k { font-size: 13px; color: var(--hero-ink-2); font-weight: 600; }
.hero .v { font-size: 38px; font-weight: 800; line-height: 1.15; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.hero .sub, .hero .note, .hero .meter-legend { color: var(--hero-ink-2); }
.hero .sub { font-size: 13px; margin-top: 4px; }
.hero .sub span { white-space: nowrap; }
/* 目立つカードの下段: 来月末 */
.hero-next { display: flex; align-items: baseline; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--hero-track); }
.hero-next .k { flex: 1; }
.hero-next b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hero-next .d { font-size: 13px; color: var(--hero-ink-2); font-variant-numeric: tabular-nums; }
.hero .pos, .hero .neg, .hero .v.neg { color: var(--hero-ink); }
.hero .meter { background: var(--hero-track); }
.hero .meter > span, .hero .meter.over > span { background: var(--hero-ink); }
.hero .meter-legend b { color: var(--hero-ink); }
.hero .status.over { color: var(--hero-ink); background: rgba(0, 0, 0, 0.18); border-radius: 99px; padding: 1px 8px; }
.meter { height: 10px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin: 12px 0 6px; }
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.meter.over > span { background: var(--critical); }
.meter-legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); gap: 8px; }
.status { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.status.over { color: var(--bad-ink); }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; text-align: left; }
.bar-row .name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .val { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.bar-row .val small { color: var(--ink-3); font-weight: 400; margin-left: 4px; }
.bar-row .track { grid-column: 1 / -1; height: 8px; }
.bar-row .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--s-expense); min-width: 2px; }
.bar-row.income .fill { background: var(--s-income); }
.seg.small .seg-btn { min-width: 64px; padding: 4px 10px; font-size: 13px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.trend svg { display: block; width: 100%; height: auto; overflow: visible; }
.trend text { font-family: var(--font); font-size: 11px; fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.trend .grid { stroke: var(--line); stroke-width: 1; }
.trend .base { stroke: var(--axis); stroke-width: 1; }
.trend .b-income { fill: var(--s-income); }
.trend .b-expense { fill: var(--s-expense); }
.trend .hit { fill: transparent; }
.trend .hl { fill: var(--card-2); }
.trend .cur text.m { fill: var(--ink); font-weight: 700; }
.table-toggle { font-size: 13px; color: var(--accent); margin-top: 8px; padding: 4px 0; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 6px; }
table.data th, table.data td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--ink-2); font-weight: 600; }

.tip {
  position: fixed; z-index: 30; pointer-events: none; background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.18), 0 0 0 1px var(--ring);
  font-variant-numeric: tabular-nums; min-width: 140px;
}
.tip b { display: block; margin-bottom: 3px; }
.tip .r { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.tip .r span { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-2); }
.tip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* 設定 */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row .lbl { font-size: 15px; }
.set-row .hint { font-size: 12px; color: var(--ink-2); }
.field {
  border: 0; background: var(--card-2); border-radius: 10px; padding: 8px 10px; font-size: 16px; min-width: 0;
  font-variant-numeric: tabular-nums;
}
.field.num { width: 130px; text-align: right; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 10px; background: var(--card-2); font-weight: 600; font-size: 15px;
}
.btn:active { filter: brightness(.95); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad-ink); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.cat-edit { display: flex; align-items: center; gap: 4px; padding: 5px 0; }
.cat-edit + .cat-edit { border-top: 1px solid var(--line); }
.cat-edit .field { flex: 1; padding: 6px 8px; }
.cat-edit .icon-btn { width: 36px; height: 36px; }
.cat-edit .danger-ico { color: var(--ink-3); }
.note { font-size: 13px; color: var(--ink-2); margin: 8px 0 0; }
.ok-line { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.ok-line .ico { width: 16px; height: 16px; }
.ok-line.good { color: var(--good-ink); }
.ok-line.warn { color: var(--bad-ink); }

/* 見通し */
.small-btn { min-height: 36px; padding: 6px 12px; font-size: 14px; gap: 4px; }
.status.line { display: flex; align-items: flex-start; gap: 6px; font-size: 13px; margin: 8px 0 0; }
.status.line .ico { margin-top: 2px; }
.plan-chart { margin-top: 10px; }
/* テーマの色の見本（選んでいるものに印） */
.swatches { display: flex; gap: 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #ffffff; box-shadow: 0 0 0 1px var(--ring); }
.swatch .ico { opacity: 0; stroke-width: 2.6; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink-3); }
.swatch[aria-checked="true"] .ico { opacity: 1; }
.sw-blue { background: var(--sw-blue); }
.sw-green { background: var(--sw-green); }
.sw-purple { background: var(--sw-purple); }
.sw-pink { background: var(--sw-pink); }
.sw-ink { background: var(--sw-ink); }
.trend .b-pos { fill: var(--accent); }
.trend .b-neg { fill: var(--critical); }
.subtabs { padding: 0 16px 8px; }
.subtabs .seg-btn { min-width: 0; padding: 7px 6px; }
.card-head .hint { font-size: 12px; color: var(--ink-2); }
.go-card { display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left; color: var(--ink-3); }
.go-card .go-k { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.go-card b { margin-left: auto; font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
.go-card .hint { font-size: 12px; color: var(--ink-2); }
.go-card .ico { align-self: center; }
.go-card:active { background: var(--card-2); }
.month-table tbody tr { cursor: pointer; }
.month-table tbody tr:active { background: var(--card-2); }
.month-table td.neg b { color: var(--bad-ink); }
.link-cell { color: var(--accent); font-weight: 600; padding: 2px 0; white-space: nowrap; }
.pfilter { margin-bottom: 12px; }
.steps { margin: 10px 0 0; padding-left: 1.3em; font-size: 14px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }
.acc-card .card-head { margin-bottom: 4px; }
.acc-sum { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; text-align: left; }
.acc-sum b { font-size: 22px; font-variant-numeric: tabular-nums; }
.acc-sum .hint { font-size: 13px; color: var(--ink-2); }
.acc-list { display: flex; flex-direction: column; }
.acc-row { display: flex; align-items: center; gap: 8px; min-height: 44px; width: 100%; text-align: left; color: var(--ink-3); }
.acc-list > * + * { border-top: 1px solid var(--line); }
.acc-ghead { display: flex; align-items: center; gap: 8px; min-height: 40px; padding-right: 24px; }
.acc-ghead .aname { flex: 1; min-width: 0; color: var(--ink); font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-ghead .hint { font-size: 12px; color: var(--ink-2); }
.acc-ghead .amt { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.acc-ghead .amt.neg { color: var(--bad-ink); }
/* 内訳は字下げして、左の細い線でまとまりを見せる */
.acc-row.sub { padding-left: 12px; margin-left: 4px; width: calc(100% - 4px); border-left: 2px solid var(--line); }
.acc-row.sub + .acc-row.sub { border-top: 0; }
.acc-row.sub .aname { font-size: 14px; color: var(--ink-2); }
.acc-row.sub .amt { font-weight: 500; }
.acc-row .usd { flex: none; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
/* 円とドルを切り替えるボタンと金額の欄を横に並べる */
.amt-in { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.amt-in .field { flex: 1; max-width: 180px; text-align: right; }
.acc-row:active { background: var(--card-2); }
.acc-row .aname { flex: 1; min-width: 0; color: var(--ink); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-row .amt { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.acc-row .amt.neg { color: var(--bad-ink); }
.acc-total-row { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--axis); padding: 8px 24px 0 0; font-weight: 600; }
.acc-total-row b { font-size: 18px; font-variant-numeric: tabular-nums; }

/* 入力の「どこから」 */
.amount-row { align-items: center; }
.acc-chip {
  position: relative; margin-right: auto; display: inline-flex; align-items: center; gap: 4px; max-width: 52%;
  padding: 6px 8px 6px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 600;
}
.acc-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.acc-chip small { font-size: 12px; font-weight: 400; white-space: nowrap; }
.acc-chip.none { background: var(--card-2); color: var(--ink-2); }
.acc-chip .chev { width: 14px; height: 14px; }
.acc-chip select { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; font-size: 16px; }
.acc-chip:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.pm { margin-bottom: 14px; }
.pm-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 4px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.pm-title { font-weight: 700; font-size: 15px; color: var(--ink); }
.prow { display: flex; align-items: center; min-height: 48px; }
.prow + .prow { border-top: 1px solid var(--line); }
.prow.none { padding: 0 14px; color: var(--ink-3); font-size: 14px; min-height: 40px; }
.chk { width: 46px; align-self: stretch; display: grid; place-items: center; flex: none; }
.chk .box { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--axis); display: grid; place-items: center; color: transparent; }
.chk[aria-pressed="true"] .box { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.chk .box .ico { width: 14px; height: 14px; stroke-width: 2.4; }
.pmain { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 10px 14px 10px 0; text-align: left; align-self: stretch; }
.pmain:active { background: var(--card-2); }
.pline { display: flex; align-items: center; gap: 8px; width: 100%; }
.psub { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.psub .status { display: inline-flex; gap: 3px; }
.psub .status .ico { width: 13px; height: 13px; }
.fmeter { display: block; width: 100%; height: 6px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.fmeter > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.fmeter.over > span { background: var(--critical); }
.prow.done .fmeter > span { background: var(--axis); }
.pname { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptag { flex: none; font-size: 11px; font-weight: 600; color: var(--ink-2); background: var(--card-2); border-radius: 99px; padding: 1px 7px; }
.prow .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.prow.done .pname, .prow.done .amt { color: var(--ink-3); text-decoration: line-through; font-weight: 400; }
.pfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; border-top: 1px solid var(--line); font-size: 14px; font-variant-numeric: tabular-nums; }
.pfoot b { font-size: 16px; margin-left: 4px; }
.add-in { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-size: 13px; font-weight: 600; padding: 6px; }

/* 下から出る板 */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 90dvh;
  background: var(--card); color: var(--ink); border-radius: 18px 18px 0 0; box-shadow: var(--sheet-shadow);
}
.sheet::backdrop { background: var(--scrim, rgba(0, 0, 0, 0.4)); }
.sheet-in { display: flex; flex-direction: column; gap: 10px; padding: 8px 16px calc(16px + var(--safe-b)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.sheet-head h2 { font-size: 17px; margin: 0; }
.seg.full { display: flex; }
.seg.full .seg-btn { flex: 1; }
.frow { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; border-bottom: 1px solid var(--line); }
.frow .lbl { font-size: 15px; flex: none; }
.frow .field { flex: 1; max-width: 220px; text-align: right; }
.frow select.field { text-align-last: right; appearance: none; -webkit-appearance: none; padding-right: 12px; }
.switch {
  appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--axis);
  position: relative; margin: 0; cursor: pointer; transition: background .15s; flex: none;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.form-err { margin: 0; font-size: 13px; color: var(--bad-ink); font-weight: 600; }
.month-only { background: var(--accent-soft); border-radius: 12px; padding: 2px 12px 10px; }
.month-only .frow { border-bottom: 0; }
.month-only .frow .lbl { font-weight: 600; }
.month-only .field { background: var(--card); }
.month-only .hint { margin: 0; font-size: 12px; color: var(--ink-2); }
.frow.col { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 0; }
.frow.col .hint { font-size: 12px; color: var(--ink-2); }
/* 予定の内訳（サブスクなど） */
.items .lbl .hint { font-weight: 400; margin-left: 4px; }
.item-row { display: flex; align-items: center; gap: 6px; }
.item-row .field { padding: 8px 10px; }
.item-row .it-name { flex: 1; min-width: 0; text-align: left; }
.item-row .it-amt { width: 96px; flex: none; text-align: right; font-variant-numeric: tabular-nums; }
.item-row .icon-btn { width: 34px; height: 34px; flex: none; color: var(--ink-3); }
.cur-btn { flex: none; width: 34px; height: 34px; border-radius: 8px; background: var(--card-2); color: var(--ink-2); font-weight: 700; font-variant-numeric: tabular-nums; }
.cur-btn:active { background: var(--line); }
.items .add-in { align-self: flex-start; }
.rate-row { border-bottom: 0; min-height: 40px; justify-content: flex-start; }
.rate-row .field { width: 96px; flex: none; text-align: right; margin-left: auto; }
.items-total { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-t {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 99px; font-size: 14px;
  background: var(--card-2); color: var(--ink-2); min-height: 34px;
}
.chip-t small { font-size: 11px; color: var(--ink-3); }
.chip-t[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip-t[aria-pressed="true"] small { color: var(--accent-ink); }
.pick.last { box-shadow: inset 0 0 0 2px var(--accent); }
.sheet-in > .btn { align-self: stretch; }
.sheet-actions { margin-top: 4px; }
.sheet-actions .grow { flex: 1; min-height: 46px; }
.picks { display: flex; flex-direction: column; gap: 6px; }
.pick {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px;
  background: var(--card-2); text-align: left; font-weight: 600; min-height: 48px;
}
.pick .after { font-weight: 400; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pick .after b { color: var(--ink); }
.pick.plain { background: none; box-shadow: inset 0 0 0 1px var(--line); color: var(--ink-2); justify-content: center; }
.pick:active { filter: brightness(.95); }

/* 帯・通知 */
.banner {
  display: flex; align-items: center; gap: 8px; margin: 6px 16px 0; padding: 9px 12px; border-radius: 12px;
  background: var(--accent-soft); color: var(--ink); font-size: 14px;
}
.banner .grow { flex: 1; }
.banner button.act { color: var(--accent); font-weight: 700; padding: 4px 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translate(-50%, 12px);
  background: var(--ink); color: var(--page); padding: 9px 16px; border-radius: 99px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 40;
  width: max-content; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 背の低い画面（SE など）ではテンキーを詰める */
@media (max-height: 700px) {
  .keypad { grid-auto-rows: 42px; gap: 5px; padding-top: 6px; }
  .amount { font-size: 30px; }
  .amount-row { padding: 6px 14px; }
  .cat { min-height: 34px; font-size: 13px; }
  .input-body { gap: 8px; }
  .topbar { min-height: 46px; padding-top: 3px; padding-bottom: 3px; }
  .banner { padding: 6px 10px; font-size: 13px; }
}
