:root {
  color-scheme: light;
  --bg: #e7e6e1;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --border: #dddcd7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7b7a75;
  --accent: #2a78d6;
  --inc: #2a78d6;   /* 収入 = categorical slot 1 */
  --exp: #eb6834;   /* 支出 = categorical slot 2 */
  --grid: #e6e5e1;
  --axis: #b9b8b2;
  --sel: rgba(42, 120, 214, .08);
  --danger: #c62f2e;
  --radius: 12px;
  /* 消費・浪費・投資（categorical: aqua / yellow / violet。CVD検証済み） */
  --c-shohi: #00b894;
  --c-rohi: #f2a600;
  --c-toshi: #6a4ce2;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0a0a09;
    --surface: #1d1d1b;
    --surface-2: #2a2a27;
    --shadow: 0 1px 2px rgba(0,0,0,.5);
    --border: #33332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --inc: #3987e5;
    --exp: #d95926;
    --grid: #2a2a27;
    --axis: #4a4a45;
    --sel: rgba(57, 135, 229, .14);
    --danger: #e66767;
    --c-shohi: #00a888;
    --c-rohi: #d28e05;
    --c-toshi: #9887ef;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.3; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 6px 12px;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
label.check { display: flex; align-items: center; gap: 8px; }

/* ロック画面 */
.lock { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); z-index: 50; }
.lock-card {
  width: min(360px, 100%); display: grid; gap: 10px; padding: 28px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
.lock-card h1 { font-size: 22px; text-align: center; }
.lock-card p { margin: 0; font-size: 13px; }
.lock-card details { font-size: 13px; color: var(--text-2); }
.lock-card details[open] { display: grid; gap: 8px; }

/* ヘッダー */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
#tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
#tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; color: var(--text-2); }
#tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 16px 16px 64px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; box-shadow: var(--shadow); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 140px; }
.row > .fit { flex: 0 0 auto; }
.date-nav { display: flex; align-items: center; gap: 4px; }
.date-nav button { padding: 6px 10px; }
.date-nav input { width: auto; }
.spacer { flex: 1; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav strong { min-width: 9em; text-align: center; }
.note { margin: 0; font-size: 12px; color: var(--muted); }
.banner { padding: 10px 14px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }

/* セグメント */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 16px; border-radius: 8px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* 入力 */
.add-card form { display: grid; gap: 12px; }
.amount-row { display: flex; align-items: center; gap: 6px; border-bottom: 2px solid var(--border); padding-bottom: 4px; }
.amount-row:focus-within { border-color: var(--accent); }
.amount-row span { font-size: 28px; color: var(--muted); }
.amount-row input { border: 0; background: none; font-size: 34px; font-weight: 700; width: 100%; padding: 0; outline: none; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--text-2); }
.chips button.on { background: var(--text); color: var(--surface); border-color: var(--text); }

/* タイル */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.inc { background: var(--inc); }
.dot.exp { background: var(--exp); }

/* 明細リスト */
.day-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 10px 4px 4px; border-bottom: 1px solid var(--border); }
.tx {
  display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 8px;
  width: 100%; text-align: left; border: 0; border-radius: 0; background: none; padding: 9px 4px; border-bottom: 1px solid var(--grid);
}
.tx:hover { background: var(--surface-2); }
.tx .cat { font-size: 13px; }
.tx .cat.none { color: var(--muted); font-size: 12px; border: 1px dashed var(--border); border-radius: 6px; padding: 0 6px; }
.tx .memo { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .date { color: var(--muted); font-size: 12px; }
.tx .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.tx.fx-row .cat { color: var(--text-2); }
.tx.fx-row .amt { font-weight: 500; color: var(--text-2); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; font-size: 13px; }

/* グラフ */
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart { position: relative; width: 100%; overflow: hidden; }
.chart-svg { display: block; max-width: 100%; height: auto; }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart-svg .baseline { stroke: var(--axis); stroke-width: 1; }
.chart-svg .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .bar-inc { fill: var(--inc); }
.chart-svg .bar-exp { fill: var(--exp); }
.chart-svg .selbg { fill: var(--sel); }
.chart-svg .hit { fill: transparent; cursor: pointer; }
.chart-svg .hit:hover { fill: var(--sel); }
.tooltip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18); min-width: 150px;
}
.tooltip .t { font-weight: 600; margin-bottom: 4px; }
.tooltip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .r span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }

.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: 7em 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .track, .hbar .fill { display: block; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .fill.exp { background: var(--exp); }
.hbar .fill.inc { background: var(--inc); }
.hbar .val { font-variant-numeric: tabular-nums; text-align: right; min-width: 7.5em; }
.hbar .pct { color: var(--muted); font-size: 11px; margin-left: 4px; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }

/* テーブル */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; }
th { font-weight: 600; color: var(--text-2); font-size: 12px; white-space: nowrap; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
td.calc { font-weight: 600; }
.edit-table input { width: 100%; min-width: 5.5em; padding: 4px 6px; border-color: transparent; background: transparent; }
.edit-table input:hover { border-color: var(--border); }
.edit-table input:focus { background: var(--surface); }
.edit-table input.n { text-align: right; font-variant-numeric: tabular-nums; }
.edit-table input[type="month"] { min-width: 9.5em; }
.badge { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 5px; white-space: nowrap; }
.badge.changed { color: var(--accent); border-color: var(--accent); }
.edit-table select { padding: 4px 6px; }
.edit-table input.renew { min-width: 4.5em; width: 5em; }
.status { font-size: 12px; padding: 3px 10px; border-radius: 999px; white-space: nowrap; border: 1px solid var(--border); }
.status.is-on { color: var(--accent); border-color: var(--accent); background: transparent; }
.status.is-off { color: var(--muted); background: var(--surface-2); }
#fx-table tr.off input, #fx-table tr.off select { color: var(--muted); text-decoration: line-through; }
/* カレンダー */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-top: 8px; }
.cal-w { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0; }
.cal-w.sun, .cal-day.sun .cal-n { color: var(--danger); }
.cal-w.sat, .cal-day.sat .cal-n { color: var(--accent); }
.cal-day {
  display: flex; flex-direction: column; align-items: stretch; gap: 1px; min-height: 62px; padding: 4px 5px;
  border: 1px solid var(--grid); border-radius: 8px; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  background: color-mix(in srgb, var(--exp) var(--lv, 0%), var(--surface));
}
.cal-day:hover { border-color: var(--axis); background: color-mix(in srgb, var(--exp) var(--lv, 0%), var(--surface)); }
.cal-day.fut { opacity: .55; }
.cal-day.today { border: 2px solid var(--text); padding: 3px 4px; }
.cal-day.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-n { font-size: 11px; color: var(--text-2); display: flex; justify-content: space-between; }
.cal-mark { font-style: normal; font-size: 8px; color: var(--accent); }
.cal-exp { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-inc { font-size: 10px; color: var(--inc); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; overflow: hidden; }
/* 固定費（合計だけの行） */
.fx-sum {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; margin-top: 12px;
  padding: 10px 12px; border: 1px dashed var(--border); border-radius: 10px; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer;
}
.fx-sum:hover { background: var(--surface-2); }
.fx-sum .muted { font-size: 12px; }
.fx-sum .num { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fx-sum .chev { color: var(--muted); font-weight: 400; margin-left: 4px; }
.cal + .fx-sum { margin-top: 14px; }

/* 数字のまとめ */
.stats { padding: 14px 16px; }
.stats .stats-group.wide { margin-top: 18px; }
.stats > .stats-group:first-child { grid-column: 1 / -1; }
.stats-h { font-size: 12px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.stats-row { display: grid; gap: 0; }
.stats-row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stats-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { padding: 2px 12px; border-left: 1px solid var(--grid); min-width: 0; }
.stat:first-child { border-left: 0; padding-left: 0; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .s { font-size: 11px; color: var(--muted); }
.stat.pos .v { color: var(--inc); }
.stat.neg .v { color: var(--danger); }

/* 数字のまとめ（表） */
.stats-table { font-size: 14px; }
.stats-table th, .stats-table td { padding: 8px 10px; border-bottom: 1px solid var(--grid); }
.stats-table thead th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: right; vertical-align: bottom; }
.stats-table thead th small { display: block; font-size: 10px; font-weight: 400; }
.stats-table tbody th { text-align: left; white-space: nowrap; font-size: 13px; color: var(--text); }
.stats-table tbody th .dot { margin-right: 6px; }
.stats-table td { font-size: 17px; font-weight: 700; }
.stats-table tr.r-exp { background: color-mix(in srgb, var(--exp) 7%, transparent); }
.stats-table tr.r-inc { background: color-mix(in srgb, var(--inc) 7%, transparent); }
.stats-table tr.r-bal td, .stats-table tr.r-bal th { border-bottom: 0; }
.stats-table td.pos { color: var(--inc); }
.stats-table td.neg { color: var(--danger); }
.stats-note { font-size: 11px; color: var(--muted); margin: 6px 0 0; }

/* 消費・浪費・投資 */
.cdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--axis); vertical-align: middle; }
.cdot.shohi { background: var(--c-shohi); }
.cdot.rohi { background: var(--c-rohi); }
.cdot.toshi { background: var(--c-toshi); }
.chips button .cdot { margin-right: 5px; }
.chips button.on .cdot { box-shadow: 0 0 0 2px var(--surface); }
.stats-group.wide { grid-column: 1 / -1; }
.cls-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.clsbar { margin: 4px 0 12px; }
.clsbar-h { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.clsbar-h b { color: var(--text); font-size: 14px; }
.clsbar-track { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.clsbar-track span { min-width: 3px; }
.clsbar-track .seg-shohi { background: var(--c-shohi); }
.clsbar-track .seg-rohi { background: var(--c-rohi); }
.clsbar-track .seg-toshi { background: var(--c-toshi); }
.clsbar-track .seg-none { background: var(--axis); }
.clsbar-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); margin-top: 6px; }
.clsbar-legend > span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.clsbar-legend b { color: var(--text); font-weight: 600; }
.cls-table td { padding: 4px 8px; }
.seg.small button { padding: 3px 10px; font-size: 12px; }

/* 月の 消費・浪費・投資・合計 */
.month-cls { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 6px; }
.month-cls .ms { flex: 1 1 110px; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.month-cls .ms .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 5px; }
.month-cls .ms .v { font-size: 17px; font-weight: 700; white-space: nowrap; text-align: left; }
.month-cls .ms.tot { background: none; border: 1px solid var(--border); }
.month-cls .ms-note { flex-basis: 100%; margin: 0; font-size: 12px; color: var(--muted); }
.month-cls .ms.tot { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 6px 16px; }
.tot-split { display: flex; align-items: flex-end; gap: 10px; }
.tot-split > div { display: flex; flex-direction: column; }
.tot-split span { font-size: 11px; color: var(--muted); }
.tot-split b { font-size: 15px; font-weight: 700; }
.tot-split .op { color: var(--muted); font-size: 14px; padding-bottom: 1px; }
.day-head > span:first-child { white-space: nowrap; font-size: 15px; font-weight: 700; color: var(--text); }
.day-head { align-items: baseline; padding-top: 16px; border-bottom-color: var(--axis); }
.tx .cat { display: inline-flex; align-items: center; gap: 5px; }
.cls-tag { font-size: 10px; color: var(--text-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; line-height: 1.5; }
.cls-tag.shohi { border-color: var(--c-shohi); }
.cls-tag.rohi { border-color: var(--c-rohi); }
.cls-tag.toshi { border-color: var(--c-toshi); }
.ci { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.day-head .dh-r { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px 10px; }
.day-head .dh-tot { flex-basis: 100%; text-align: right; color: var(--text); font-size: 17px; font-weight: 700; }
.fx-cls { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.pop-cls { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-2); margin: -2px 0 8px; }
.cal-mini { display: flex; gap: 1px; height: 4px; border-radius: 2px; overflow: hidden; margin-top: auto; background: var(--surface); }
.cal-mini i { min-width: 2px; }
.cal-mini .seg-shohi { background: var(--c-shohi); }
.cal-mini .seg-rohi { background: var(--c-rohi); }
.cal-mini .seg-toshi { background: var(--c-toshi); }
.cal-mini .seg-none { background: var(--axis); }

/* ポップアップ */
dialog.pop { width: min(440px, calc(100% - 24px)); max-height: 80vh; padding: 16px 18px; }
.pop-head { display: flex; justify-content: space-between; align-items: center; }
.pop-head h3 { margin: 0; }
.pop-total { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 8px; }
.pop-total b { font-size: 22px; font-variant-numeric: tabular-nums; margin-right: 10px; }
.pop-total .inc-t { color: var(--inc); font-size: 16px; }
.pop-actions { margin: 14px 0 0; text-align: right; }
.pop .tx.fx-row { cursor: default; }
.pop .tx.fx-row:hover { background: none; }
.cal-sum { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 12px; font-size: 13px; }
.cal-sum div { display: flex; gap: 6px; align-items: baseline; }
.cal-sum b { font-variant-numeric: tabular-nums; }
.cal-sum .tot b { font-size: 16px; }
.cal-sum .inc-t { color: var(--inc); }
@media (max-width: 560px) {
  .cal { gap: 2px; }
  .cal-day { min-height: 52px; padding: 3px; }
  .cal-day.today { padding: 2px; }
  .cal-exp { font-size: 10.5px; }
  .stats { grid-template-columns: 1fr; gap: 14px; padding: 12px 14px; }
  .stats-row.four { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 10px; }
  .stats-row.four .stat:nth-child(3) { border-left: 0; padding-left: 0; }
  .stat .v { font-size: 18px; }
  .cls-pair { grid-template-columns: 1fr; gap: 4px; }
  .stats-table th, .stats-table td { padding: 7px 4px; }
  .stats-table td { font-size: 13px; }
  .stats-table tbody th { font-size: 12px; }
  .month-cls .ms { flex: 0 0 calc(50% - 4px); }
  .month-cls .ms.tot { flex-basis: 100%; }
}
.renew-list { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; margin: 0 0 10px; }

/* ダイアログ */
dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { display: grid; gap: 12px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; }

/* レポート */
.report { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; display: grid; gap: 20px; }
.report header h2 { font-size: 22px; margin: 0; }
.report .chart-svg { width: 100%; }
.report section h3 { border-left: 3px solid var(--accent); padding-left: 8px; }
.settings-grid { display: grid; gap: 16px; }
.settings-grid form, .settings-grid .card { display: grid; gap: 10px; }
textarea { width: 100%; min-height: 9em; resize: vertical; }

.sync-badge { font-size: 12px; color: var(--muted); white-space: nowrap; padding: 4px 6px; }
.sync-badge[data-st="error"], .sync-badge[data-st="blocked"] { color: var(--danger); }
.topbar { padding-top: max(8px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
main { padding-bottom: max(64px, env(safe-area-inset-bottom)); }

@media (max-width: 560px) {
  input, select, textarea { font-size: 16px; } /* iOSの自動ズーム防止 */
  .amount-row input { font-size: 34px; }
  #tabs button { padding: 8px 9px; }
  .hbar { grid-template-columns: 5.5em 1fr auto; }
  .hbar .val { min-width: 6em; }
  .tile .v { font-size: 19px; }
  .tx { grid-template-columns: auto 1fr auto; }
  .tx .date, .tx > span:first-child:empty { display: none; }
}

/* 印刷（PDF出力）: 常にライト配色 */
@media print {
  :root {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-2: #f1f1ef; --border: #d6d5d0; --shadow: none;
    --text: #0b0b0b; --text-2: #52514e; --muted: #6b6a65; --accent: #2a78d6;
    --inc: #2a78d6; --exp: #eb6834; --grid: #e6e5e1; --axis: #b9b8b2; --sel: transparent;
    --c-shohi: #00b894; --c-rohi: #f2a600; --c-toshi: #6a4ce2;
  }
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 11px; }
  .no-print, .topbar, #lock, dialog, .tooltip { display: none !important; }
  main { padding: 0; max-width: none; }
  .report { border: 0; padding: 0; gap: 14px; }
  .report section { break-inside: avoid; }
  .report section.long { break-inside: auto; }
  tr { break-inside: avoid; }
  .tile { padding: 8px 10px; }
  .tile .v { font-size: 16px; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.fm-actions { margin-top: 10px; }
#fm-table .fm-cat { margin-top: 4px; font-size: 12px; padding: 3px 6px; }
#fm-table tr.off td { color: var(--muted); }

/* 明細：日ごとのまとまり（交互に背景色） */
.day-group { border-radius: 12px; padding: 10px 12px 4px; margin-top: 10px; border: 1px solid var(--grid); }
.day-group:nth-of-type(odd) { background: var(--surface-2); border-color: transparent; }
.dg-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.dg-date { font-size: 16px; font-weight: 700; white-space: nowrap; }
.dg-tot { font-size: 18px; font-weight: 700; }
.dg-cls { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 6px 0 4px; }
.dgc { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); background: var(--surface); border: 1px solid var(--grid); border-radius: 999px; padding: 2px 10px 2px 8px; }
.dgc b { font-weight: 700; color: var(--text); }
.dgc.zero { opacity: .45; }
.day-group .tx { border-bottom-color: var(--border); }
.day-group .tx:last-child { border-bottom: 0; }
.day-group .tx:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
@media (max-width: 560px) {
  .dg-cls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .dg-cls .dgc.none { grid-column: 1 / -1; justify-self: start; }
  .dgc { font-size: 11px; padding: 2px 6px; gap: 3px; justify-content: center; white-space: nowrap; overflow: hidden; }
}
/* 年払いの行 */
/* 毎年・2年ごと：枠はそのまま、背景色だけ（2年ごとの方が濃い） */
#fx-table select.is-year1 { background-color: color-mix(in srgb, var(--text) 8%, var(--surface)); }
#fx-table select.is-year2 { background-color: color-mix(in srgb, var(--text) 18%, var(--surface)); }
#fx-table tr.yearly td { background: color-mix(in srgb, var(--text) 3%, transparent); }
#fx-table tr.yearly.y2 td { background: color-mix(in srgb, var(--text) 6%, transparent); }
.edit-table input.renew.wide { width: 7.5em; }

/* ============================================================
   カラー強化（意味のある色だけを使う：支出=オレンジ / 収入=青 / 消費=緑 / 浪費=黄 / 投資=紫）
   ============================================================ */
:root { --tint: 13%; --tint-strong: 22%; }
@media (prefers-color-scheme: dark) { :root { --tint: 20%; --tint-strong: 32%; } }

/* ページ背景：ほんのり色を混ぜる */
body { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 7%, var(--bg)) 0, var(--bg) 420px) fixed, var(--bg); }

/* ヘッダーのタブ：選択中を青で */
#tabs button.active { background: var(--accent); color: #fff; }

/* 月の 消費・浪費・投資 ボックスを各色で */
.month-cls .ms.shohi { background: color-mix(in srgb, var(--c-shohi) var(--tint), var(--surface)); }
.month-cls .ms.rohi { background: color-mix(in srgb, var(--c-rohi) var(--tint), var(--surface)); }
.month-cls .ms.toshi { background: color-mix(in srgb, var(--c-toshi) var(--tint), var(--surface)); }
.month-cls .ms.none { background: var(--surface-2); }
.month-cls .ms.tot { background: color-mix(in srgb, var(--exp) 8%, var(--surface)); border-color: color-mix(in srgb, var(--exp) 35%, var(--border)); }

/* カテゴリボタン：分類の色をうっすら。選んだものは濃く */
.chips button:has(.cdot.shohi) { background: color-mix(in srgb, var(--c-shohi) 9%, var(--surface)); border-color: color-mix(in srgb, var(--c-shohi) 35%, var(--border)); }
.chips button:has(.cdot.rohi) { background: color-mix(in srgb, var(--c-rohi) 11%, var(--surface)); border-color: color-mix(in srgb, var(--c-rohi) 40%, var(--border)); }
.chips button:has(.cdot.toshi) { background: color-mix(in srgb, var(--c-toshi) 9%, var(--surface)); border-color: color-mix(in srgb, var(--c-toshi) 35%, var(--border)); }
.chips button.on, .chips button.on:has(.cdot) { background: var(--text); color: var(--surface); border-color: var(--text); }

/* 日ごとの 消費・浪費・投資 チップ、分類タグ */
.dgc.shohi { background: color-mix(in srgb, var(--c-shohi) var(--tint), var(--surface)); border-color: transparent; }
.dgc.rohi { background: color-mix(in srgb, var(--c-rohi) var(--tint), var(--surface)); border-color: transparent; }
.dgc.toshi { background: color-mix(in srgb, var(--c-toshi) var(--tint), var(--surface)); border-color: transparent; }
.cls-tag.shohi { background: color-mix(in srgb, var(--c-shohi) var(--tint), transparent); }
.cls-tag.rohi { background: color-mix(in srgb, var(--c-rohi) var(--tint), transparent); }
.cls-tag.toshi { background: color-mix(in srgb, var(--c-toshi) var(--tint), transparent); }

/* 日ごとのまとまり：左に色の帯 */
.day-group, .day-group:nth-of-type(odd) { border-left: 4px solid color-mix(in srgb, var(--exp) 55%, transparent); }

/* 数字のまとめ表：行の色を少し濃く */
.stats-table tr.r-exp { background: color-mix(in srgb, var(--exp) var(--tint), transparent); }
.stats-table tr.r-inc { background: color-mix(in srgb, var(--inc) var(--tint), transparent); }

/* 固定費のまとめ行・セクション見出し */
.fx-sum { background: color-mix(in srgb, var(--exp) 6%, var(--surface)); border-color: color-mix(in srgb, var(--exp) 35%, var(--border)); }
.card > h3:first-child, .card .toolbar h3 { padding-left: 10px; border-left: 4px solid var(--accent); }

/* 給与：総支給・手取りを収入の青で */
#sal-table td.calc { background: color-mix(in srgb, var(--inc) 8%, transparent); }
#sal-table td[data-c="net"] { background: color-mix(in srgb, var(--inc) var(--tint), transparent); }

/* 固定費：年払い・2年ごとの背景を色つきに（枠はそのまま） */
#fx-table select.is-year1 { background-color: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
#fx-table select.is-year2 { background-color: color-mix(in srgb, var(--accent) 26%, var(--surface)); }
#fx-table tr.yearly td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
#fx-table tr.yearly.y2 td { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* カレンダー：今日と土日に色 */
.cal-day.sat:not([style]) { background: color-mix(in srgb, var(--inc) 5%, var(--surface)); }
.cal-day.sun:not([style]) { background: color-mix(in srgb, var(--danger) 5%, var(--surface)); }

@media print {
  body { background: #fff; }
  #tabs button.active { background: none; color: inherit; }
}
/* 分類ボックス内のカテゴリ別金額 */
.ms-cats { list-style: none; margin: 6px 0 0; padding: 6px 0 0; border-top: 1px solid color-mix(in srgb, var(--text) 10%, transparent); display: grid; gap: 2px; }
.ms-cats li { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-2); }
.ms-cats li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-cats li b { font-weight: 600; color: var(--text); }
.month-cls { align-items: stretch; }
.month-cls .ms.tot { flex-basis: 100%; align-items: center; }
.month-cls .ms:not(.tot) { align-self: stretch; }

/* ===== 記録ページ：円グラフ・棒グラフ・表 ===== */
:root { --c-none: var(--axis); }
.rec-tabs { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.rec-tabs button { white-space: nowrap; }
.sub-h { font-size: 13px; margin: 18px 0 6px; }
.sub-h .muted { font-weight: 400; font-size: 11px; }
.chart-svg.wide { width: 100%; }
.chart-svg .seg-shohi { fill: var(--c-shohi); }
.chart-svg .seg-rohi { fill: var(--c-rohi); }
.chart-svg .seg-toshi { fill: var(--c-toshi); }
.chart-svg .seg-none { fill: var(--c-none); }
.hbar .name .cdot { margin-right: 2px; }

.donut { display: block; flex: none; max-width: 100%; height: auto; }
.donut .slice { stroke: var(--surface); stroke-width: 2; cursor: pointer; }
.donut .slice:hover { opacity: .85; }
.donut .d-k { fill: var(--muted); font-size: 12px; }
.donut .d-v { fill: var(--text); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pie-main { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; margin: 8px 0 6px; }
.pie-main .d-legend { flex: 1 1 220px; }
.d-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.d-legend li { display: grid; grid-template-columns: 12px 1fr auto 3.2em; align-items: center; gap: 8px; }
.d-legend i { width: 10px; height: 10px; border-radius: 3px; }
.d-legend .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.d-legend .muted { text-align: right; font-size: 12px; }
.pie-subs { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 14px; }
.pie-sub { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.pie-sub h4 { margin: 0 0 8px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.pie-sub h4 b { margin-left: auto; }
.pie-sub-body { display: flex; align-items: center; gap: 12px; }
.pie-sub-body .d-legend { flex: 1; font-size: 12px; }
.pie-sub .donut .slice { stroke: var(--surface-2); }

.data-table { font-size: 13px; }
.data-table td, .data-table th { white-space: nowrap; }
.data-table tr.row-shohi td:first-child { box-shadow: inset 3px 0 var(--c-shohi); }
.data-table tr.row-rohi td:first-child { box-shadow: inset 3px 0 var(--c-rohi); }
.data-table tr.row-toshi td:first-child { box-shadow: inset 3px 0 var(--c-toshi); }
.data-table tr.row-none td:first-child { box-shadow: inset 3px 0 var(--c-none); }
@media (max-width: 560px) {
  .rec-tabs button { padding: 6px 9px; font-size: 13px; }
  .pie-main { justify-content: center; }
}

.chart-svg.wide { width: 100%; height: auto; }
.rec-bars .hbar { grid-template-columns: 8.5em 1fr auto; }
.pie-sub-body { flex-wrap: wrap; justify-content: center; }
.pie-sub-body .d-legend { min-width: 170px; }
@media (max-width: 560px) {
  .rec-bars .hbar { grid-template-columns: 7.5em 1fr auto; }
  .pie-sub-body .donut { width: 96px; height: 96px; }
  .d-legend li { grid-template-columns: 10px 1fr auto 2.6em; gap: 6px; }
}

/* ===== 分析ページ ===== */
.tile .v.pos { color: var(--inc); }
.tile .v.neg { color: var(--danger); }
.diff { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.diff.bad, td.bad { color: var(--danger); }
.diff.good, td.good { color: var(--inc); }
.an-cls { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 6px 0 14px; }
.an-cls .ms { border-radius: 10px; padding: 8px 10px; }
.an-cls .ms .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 5px; }
.an-cls .ms .v { font-size: 18px; font-weight: 700; }
.an-cls .ms.shohi { background: color-mix(in srgb, var(--c-shohi) var(--tint), var(--surface)); }
.an-cls .ms.rohi { background: color-mix(in srgb, var(--c-rohi) var(--tint), var(--surface)); }
.an-cls .ms.toshi { background: color-mix(in srgb, var(--c-toshi) var(--tint), var(--surface)); }
.an-cls .ms.none { background: var(--surface-2); }
.an-filters { flex-wrap: wrap; gap: 6px; }
.an-filters select, .an-filters input { font-size: 13px; padding: 5px 8px; }
#an-q { width: 11em; }
.cmp-table td.num b { font-weight: 700; }
@media (max-width: 560px) { .an-filters > * { flex: 1 1 45%; } #an-q { width: auto; } }
.an-cls .ms .v { text-align: left; }

/* ===== 入力欄（記録ページ上部）を目立たせる ===== */
.card.add-card {
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 16%, var(--surface)) 0%, color-mix(in srgb, var(--accent) 6%, var(--surface)) 100%);
  border: 1.5px solid color-mix(in srgb, var(--accent) 45%, var(--border));
}
.add-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin-bottom: 12px; }
.add-head h2 { margin: 0; font-size: 18px; }
.add-icon { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-grid; place-items: center; font-weight: 700; font-size: 18px; line-height: 1; }
.add-sub { font-size: 12px; color: var(--text-2); }
.add-card input, .add-card .date-nav button { background: var(--surface); }
.add-card .amount-row { background: var(--surface); border-radius: 10px; padding: 4px 12px; }
.add-card .err:empty { display: none; }

/* ===== NISA・iDeCo ===== */
.page-h { margin: 0; font-size: 18px; }
.inv-chart .ln-value { fill: none; stroke: var(--c-toshi); stroke-width: 2; stroke-linejoin: round; }
.inv-chart .ln-principal { fill: none; stroke: var(--text-2); stroke-width: 2; stroke-dasharray: 5 4; }
.inv-chart .gain-band { fill: color-mix(in srgb, var(--c-toshi) 16%, transparent); }
.inv-chart .pt-value { fill: var(--c-toshi); stroke: var(--surface); stroke-width: 2; }
.legend .lg-line { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--c-toshi); }
.legend .lg-line.principal { border-top: 2px dashed var(--text-2); }
.legend .lg-band { display: inline-block; width: 14px; height: 10px; border-radius: 2px; background: color-mix(in srgb, var(--c-toshi) 22%, transparent); }
.inv-table input.n { min-width: 6.5em; }
.inv-table input.n::placeholder { color: var(--muted); opacity: .7; }
.inv-table input.val:not(:placeholder-shown) { background: color-mix(in srgb, var(--c-toshi) 10%, var(--surface)); }
.inv-table td:first-child { white-space: nowrap; }
.card.inv-input { background: linear-gradient(160deg, color-mix(in srgb, var(--c-toshi) 16%, var(--surface)) 0%, color-mix(in srgb, var(--c-toshi) 6%, var(--surface)) 100%); border: 1.5px solid color-mix(in srgb, var(--c-toshi) 45%, var(--border)); margin-bottom: 12px; }
.inv-input .add-icon { background: var(--c-toshi); }
.inv-input .amount-row { background: var(--surface); border-radius: 10px; padding: 2px 10px; flex: 1 1 180px; }
.inv-input .amount-row input { font-size: 22px; }
.inv-input input[type="month"] { background: var(--surface); }
.inv-input .err:empty { display: none; }
.pos-t { color: var(--inc); font-weight: 600; }
.neg-t { color: var(--danger); font-weight: 600; }
.inv-date { display: flex; flex-direction: column; font-size: 11px; color: var(--text-2); gap: 2px; }
.inv-date input { background: var(--surface); }
.inv-table input[type="date"] { min-width: 9.5em; }
.edit-table input.day { min-width: 3em; width: 4em; }
/* NISA：シンプル版 */
.inv-fields { display: grid; grid-template-columns: 11em 1fr 1fr auto; gap: 8px; align-items: end; }
.inv-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-2); }
.inv-fields input { background: var(--surface); font-size: 17px; font-variant-numeric: tabular-nums; }
.inv-now .k { font-size: 14px; font-weight: 700; }
.inv-now .k .muted { font-weight: 400; font-size: 12px; margin-left: 6px; }
.inv-now .v { font-size: 34px; font-weight: 800; text-align: left; margin-top: 4px; }
.inv-now .v small { font-size: 14px; font-weight: 600; margin-left: 4px; }
.inv-now .g { font-size: 16px; }
.inv-now .d { font-size: 12px; margin-top: 4px; }
.inv-chart .hit-pt { fill: transparent; cursor: pointer; }
.inv-table input.pos-t, .inv-table input.neg-t { font-weight: 600; }
@media (max-width: 560px) { .inv-fields { grid-template-columns: 1fr 1fr; } .inv-fields label:first-child { grid-column: 1 / -1; } .inv-fields button { grid-column: 1 / -1; } }
.inv-fields { grid-template-columns: 11em minmax(0, 1fr) minmax(0, 1fr) auto; }
.inv-fields input { width: 100%; min-width: 0; }
@media (max-width: 560px) { .inv-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.inv-input .note { margin: 8px 0 0; }
@media (max-width: 560px) {
  .inv-table .col-prev { display: none; }
  .inv-table input[type="date"] { min-width: 0; width: 8.6em; font-size: 13px; padding: 4px 2px; }
  .inv-table input.n { min-width: 0; width: 6.8em; font-size: 13px; }
  .inv-table th, .inv-table td { padding: 6px 3px; }
}
/* 資産 */
.card.cash-input { background: linear-gradient(160deg, color-mix(in srgb, var(--inc) 14%, var(--surface)) 0%, color-mix(in srgb, var(--inc) 5%, var(--surface)) 100%); border: 1.5px solid color-mix(in srgb, var(--inc) 40%, var(--border)); }
.cash-fields { grid-template-columns: 11em minmax(0, 1fr) auto; }
.lg-sq { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tile .k .lg-sq { margin-right: 2px; }
@media (max-width: 560px) { .cash-fields { grid-template-columns: minmax(0, 1fr); } .cash-fields label:first-child, .cash-fields button { grid-column: auto; } }
/* 旧URLでの引っ越し案内 */
.moved-banner { position: relative; z-index: 50; background: var(--accent); color: #fff; font-size: 13px; line-height: 1.5; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); text-align: center; }
.moved-banner a { color: #fff; font-weight: 700; text-decoration: underline; }
.moved-banner #move-btn { display: inline-block; margin: 6px 0 0 8px; background: #fff; color: var(--accent); border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 13px; }
/* 記録ページ：支出カードの見出し */
.rec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.rec-head h2 { margin: 0; font-size: 18px; padding-left: 10px; border-left: 4px solid var(--exp); }
.year-jump { font-size: 13px; padding: 6px 12px; border-radius: 999px; background: color-mix(in srgb, var(--exp) 10%, var(--surface)); border-color: color-mix(in srgb, var(--exp) 40%, var(--border)); font-weight: 600; }
