/* 桜色の紙に、丸みのある文字で書き込む家計ノート。スマホ縦画面優先。
   上：見出し / 中：1列のセクション / 下：固定タブ（5画面）
   文字は端末内蔵の丸ゴシックだけを使う（外部フォントは読み込まない）：
   欧文・数字は ui-rounded（Apple 端末の SF Rounded）、和文はヒラギノ丸ゴ。無い端末では通常のゴシック。 */
:root {
  --paper: #fff6f8;
  --surface: #ffffff;
  --sunken: #fbe9ee;
  --ink: #3d2a30;
  --muted: #8a6870;
  --line: #f0d7de;
  --accent: #b8405f;
  --accent-ink: #ffffff;
  --accent-soft: #fbe4eb;
  --gain: #2e7a68;
  --deficit: #b42318;
  --deficit-soft: #fdeecf;
  --warn-soft: #fff1d6;
  --warn-ink: #6d4a00;
  --chart-1: #c2456c;
  --chart-2: #3a6ea8;
  --chart-3: #9a6a14;
  --font-body: ui-rounded, "Hiragino Maru Gothic ProN", "ヒラギノ丸ゴ ProN W4", "HiraMaruProN-W4", "Zen Maru Gothic", "M PLUS Rounded 1c", "Kosugi Maru", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-figure: var(--font-body);
  --tabbar-h: 60px;
  --r: 16px;
  --r-control: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1f1517; --surface: #2a1d21; --sunken: #170f11; --ink: #f5e4e9; --muted: #c3a1aa;
    --line: #45303a; --accent: #f08fb0; --accent-ink: #2a0c17; --accent-soft: #4a2533; --gain: #6fcdb4;
    --deficit: #ff8a7a; --deficit-soft: #3a2c12; --warn-soft: #3a2c12; --warn-ink: #f6d58e;
    --chart-1: #d8648c; --chart-2: #6f95d6; --chart-3: #b8862e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1f1517; --surface: #2a1d21; --sunken: #170f11; --ink: #f5e4e9; --muted: #c3a1aa;
  --line: #45303a; --accent: #f08fb0; --accent-ink: #2a0c17; --accent-soft: #4a2533; --gain: #6fcdb4;
  --deficit: #ff8a7a; --deficit-soft: #3a2c12; --warn-soft: #3a2c12; --warn-ink: #f6d58e;
  --chart-1: #d8648c; --chart-2: #6f95d6; --chart-3: #b8862e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.6 var(--font-body);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 10; background: var(--paper);
}
.wrap {
  max-width: 720px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
header.app {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
header.app .wrap { display: flex; align-items: baseline; gap: 10px; padding-block: 10px; }
header.app h1 { margin: 0; font: 700 18px/1.3 var(--font-figure); letter-spacing: .06em; color: var(--accent); }
header.app .sub { color: var(--muted); font-size: 12px; }
main .wrap { display: flex; flex-direction: column; gap: 18px; padding-block: 16px; }

h2 { margin: 0; font-size: 16px; font-weight: 700; text-wrap: balance; }
h3 { margin: 0; font-size: 14px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num, td.n, .fig { font-variant-numeric: tabular-nums; }

section.block { display: flex; flex-direction: column; gap: 10px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px; display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 140px; min-width: 0; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* 主要な数字（純資産など） */
.hero-fig { font: 700 36px/1.15 var(--font-figure); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.hero-fig .unit { font-size: 15px; margin-left: 4px; color: var(--muted); font-family: var(--font-body); }
.delta { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.plus { color: var(--gain); }
.minus { color: var(--deficit); }
.kv { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.kv .total { font-weight: 700; border-top: 1px solid var(--line); padding-top: 4px; }

/* 入力 */
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.line-field { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 9.5em); gap: 10px; align-items: center; }
.line-field > span { min-width: 0; overflow-wrap: anywhere; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="date"], input[type="number"], select, textarea {
  width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--paper); color: var(--ink); font-size: 16px; /* 16px未満だとiOSが拡大する */
}
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.suffix { display: flex; align-items: center; gap: 6px; }
.suffix span { color: var(--muted); font-size: 13px; white-space: nowrap; }

button, .btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 16px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
}
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--deficit); }
button.icon { padding: 6px 10px; min-height: 36px; }
button:disabled { opacity: .45; cursor: default; }

/* セグメント（サブタブ） */
.seg { display: flex; background: var(--sunken); border-radius: 999px; padding: 3px; gap: 2px; overflow-x: auto; }
.seg button { flex: 1 0 auto; border: 0; background: transparent; min-height: 34px; padding: 6px 10px; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

/* お知らせ */
.notice { border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn-ink); }
.notice.info { background: var(--accent-soft); color: var(--ink); }
.notice.bad { background: var(--deficit-soft); color: var(--ink); }

/* 表（年表・キャッシュフロー） */
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); max-height: 70vh; }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 13px; width: max-content; min-width: 100%; }
table.grid th, table.grid td { padding: 6px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid thead th { position: sticky; top: 0; background: var(--sunken); z-index: 2; font-weight: 600; text-align: center; }
table.grid th.y, table.grid td.y { position: sticky; left: 0; background: var(--surface); z-index: 1; text-align: left; font-variant-numeric: tabular-nums; border-right: 1px solid var(--line); }
table.grid thead th.y { z-index: 3; background: var(--sunken); }
table.grid td.n { text-align: right; }
table.grid tr.neg td { background: var(--deficit-soft); }
table.grid tr.neg td.y { background: var(--deficit-soft); }
table.grid td.neg { color: var(--deficit); font-weight: 600; }
table.grid tr.now td { font-weight: 600; }
table.grid td.ev { white-space: normal; min-width: 12em; max-width: 22em; }
.chip { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 99px; margin: 1px 3px 1px 0; background: var(--sunken); color: var(--ink); }
.chip.manual { background: var(--accent-soft); }
.grade { color: var(--accent); font-weight: 600; margin-left: 4px; }

.chart-box { position: relative; height: 280px; }

/* 下部タブ */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
nav.tabs ul { list-style: none; margin: 0 auto; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); max-width: 720px; height: var(--tabbar-h); }
nav.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 100%; color: var(--muted); text-decoration: none; font-size: 11px;
}
nav.tabs a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; }
nav.tabs a[aria-current="page"] { color: var(--accent); font-weight: 700; }

/* ダイアログとトースト */
.modal-back { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.modal { background: var(--surface); color: var(--ink); border-radius: 22px; padding: 20px; width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 12px; margin-bottom: env(safe-area-inset-bottom, 0px); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 99px; font-size: 14px;
  max-width: calc(100vw - 32px);
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }
}
