/* デザイン方針は docs/design.md を参照（本文18px以上・コントラスト7:1以上・押せる場所は56px以上） */
:root {
  --bg: #fbf8f2;
  --surface: #ffffff;
  --surface-soft: #f3efe6;
  --text: #1b1b1b;
  --muted: #474747;
  --line: #cfc8bb;
  --accent: #0a5560;
  --accent-text: #ffffff;
  --accent-soft: #e2f0ee;
  --link: #0a4a8c;
  --warm: #fff1d6;
  --warm-line: #c98a14;
  --focus: #d35400;
  --radius: 14px;
  --font: "BIZ UDPGothic", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Noto Sans JP", Meiryo, system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191a;
    --surface: #1d2425;
    --surface-soft: #242c2d;
    --text: #f3f3f3;
    --muted: #cfd5d5;
    --line: #4a5657;
    --accent: #86d7dc;
    --accent-text: #0b1f21;
    --accent-soft: #20393b;
    --link: #9cc9ff;
    --warm: #3a2f17;
    --warm-line: #e0a93a;
    --focus: #ffb15c;
  }
}

/* 文字サイズ切替（標準18px／大20px／特大22px） */
html { font-size: 112.5%; -webkit-text-size-adjust: 100%; }
html[data-size="l"] { font-size: 125%; }
html[data-size="xl"] { font-size: 137.5%; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.85; font-size: 1rem; letter-spacing: .02em; }
a { color: var(--link); text-decoration: underline; text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 3px; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
.wrap { max-width: 46rem; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 12px 16px; z-index: 10; }
.skip:focus { left: 8px; }

/* ヘッダー */
.site-header { background: var(--surface); border-bottom: 2px solid var(--line); }
.header-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding-top: 12px; padding-bottom: 8px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.3rem; color: var(--text); text-decoration: none; min-height: 48px; }
.textsize { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }
.textsize button { font: inherit; font-weight: 700; min-width: 48px; min-height: 44px; padding: 0 10px; border: 2px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; }
.textsize button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-bottom: 12px; }
.nav a { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; padding: 6px 8px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface-soft); color: var(--text); text-decoration: none; font-weight: 700; font-size: .95rem; text-align: center; line-height: 1.35; }
.nav a:hover { border-color: var(--accent); }
.nav a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.nav svg { flex: none; width: 24px; height: 24px; }

main { padding-top: 28px; padding-bottom: 56px; }
h1 { font-size: 1.65rem; line-height: 1.45; margin: 0 0 12px; }
h2 { font-size: 1.3rem; line-height: 1.5; margin: 48px 0 14px; padding: 6px 0 6px 14px; border-left: 6px solid var(--accent); }
h3 { font-size: 1.1rem; margin: 28px 0 8px; }
p, li { max-width: 38em; }
.lead { font-size: 1.05rem; margin-top: 0; }
.updated { font-size: .9rem; color: var(--muted); }
ul, ol { padding-left: 1.4em; }
li { margin-bottom: 8px; }

.card { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 20px 0; }

/* トップのツール一覧 */
.tool-list { display: grid; gap: 16px; margin: 24px 0; }
.tool-link { display: grid; grid-template-columns: 56px 1fr; gap: 10px 14px; align-items: center; text-decoration: none; color: var(--text); background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 18px; }
.tool-link:hover { border-color: var(--accent); }
.tool-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.tool-icon svg { width: 32px; height: 32px; }
.tool-link strong { font-size: 1.15rem; color: var(--text); line-height: 1.5; }
.tool-link .when, .tool-link .go { grid-column: 1 / -1; }
.tool-link .when { color: var(--muted); font-size: .95rem; }
.tool-link .go { justify-self: start; display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 6px 18px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-weight: 700; }
.tool-link .go::after { content: "→"; }
.tool-link:hover .go { box-shadow: 0 0 0 3px var(--accent-soft); }

/* フォーム */
.step { display: inline-grid; place-items: center; width: 2em; height: 2em; margin-right: 8px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: .9em; font-weight: 700; }
form .row { display: grid; gap: 6px; margin-bottom: 20px; }
label, .label { font-weight: 700; font-size: 1rem; }
.hint { display: block; font-size: .9rem; color: var(--muted); font-weight: 400; line-height: 1.6; }
input[type="number"], input[type="date"], select {
  width: 100%; min-height: 56px; font: inherit; font-size: 1.1rem; padding: 10px 14px;
  border: 2px solid var(--muted); border-radius: 10px; background: var(--surface); color: var(--text);
}
input::placeholder { color: var(--muted); opacity: .8; }
.with-unit { display: flex; align-items: center; gap: 8px; }
.with-unit input { flex: 1; }
.with-unit .unit { font-weight: 700; min-width: 1.5em; }
.yen-read { font-size: 1rem; color: var(--accent); font-weight: 700; }
.yen-read:empty { display: none; }
.choice { display: flex; align-items: flex-start; gap: 12px; min-height: 52px; padding: 12px 14px; margin-bottom: 10px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface-soft); font-weight: 400; cursor: pointer; line-height: 1.6; }
.choice input { flex: none; width: 28px; height: 28px; margin: 0; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choices-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0 12px; }
.date-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0 12px; }
fieldset { border: 2px solid var(--line); border-radius: var(--radius); padding: 16px 16px 4px; margin: 0 0 24px; background: var(--surface); }
legend { font-weight: 700; font-size: 1.15rem; padding: 0 8px; }
.btn { display: block; width: 100%; min-height: 64px; font: inherit; font-size: 1.25rem; font-weight: 700; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 14px; padding: 12px 20px; cursor: pointer; box-shadow: 0 4px 0 rgba(0, 0, 0, .25); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }

/* 結果 */
.result { border: 3px solid var(--accent); }
.result .big { font-size: 2.2rem; font-weight: 800; color: var(--accent); line-height: 1.3; margin: 4px 0 8px; }
.result .sub, .card .sub { color: var(--text); font-size: 1rem; margin: 4px 0; }
.result-cards { display: grid; gap: 12px; }
.result-cards .card { margin: 0; }
.result-cards .amount { font-size: 1.5rem; font-weight: 800; margin: 2px 0; }
.table-wrap { overflow-x: auto; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 1rem; }
th, td { border-bottom: 1px solid var(--line); padding: 12px 12px; text-align: right; white-space: nowrap; vertical-align: top; }
th:first-child, td:first-child { text-align: left; }
thead th { background: var(--accent-soft); font-weight: 700; white-space: normal; line-height: 1.5; }
td { white-space: normal; }
table.nums td:not(:first-child) { white-space: nowrap; }
tbody tr:nth-child(even) { background: var(--surface-soft); }
tfoot th { background: var(--accent-soft); }
td .hint { display: block; }
.table-wrap.inputs td { white-space: normal; }

.note { background: var(--warm); border: 2px solid var(--warm-line); border-radius: var(--radius); padding: 14px 18px; font-size: 1rem; }
.note strong:first-child { display: block; margin-bottom: 4px; }
.error { background: var(--warm); border: 3px solid var(--focus); border-radius: var(--radius); padding: 14px 18px; font-weight: 700; }
.field-error { margin: 2px 0 0; padding: 8px 12px; border-left: 6px solid var(--focus); background: var(--warm); font-weight: 700; }
.field-error::before { content: "！ "; }
[aria-invalid="true"] { border-color: var(--focus) !important; border-width: 3px !important; }
.sources { font-size: .95rem; }

/* フッター */
.site-footer { border-top: 2px solid var(--line); background: var(--surface); padding: 28px 0; font-size: .95rem; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 16px 0; }
.footer-nav a { display: inline-flex; align-items: center; min-height: 44px; }
.copy { margin: 0; color: var(--muted); }

/* スマホでは表を「1行＝1枚のカード」に並べ替える（横スクロールに気づきにくいため） */
@media (max-width: 40rem) {
  .table-wrap:has(table.stack) { border: 0; background: none; overflow: visible; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tfoot { display: block; }
  table.stack tr { display: block; margin-bottom: 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
  table.stack tbody tr:nth-child(even) { background: var(--surface); }
  table.stack td, table.stack th { display: flex; justify-content: space-between; gap: 12px; text-align: right; white-space: normal; border-bottom: 1px solid var(--line); }
  table.stack td:first-child, table.stack th:first-child { background: var(--accent-soft); font-weight: 700; text-align: left; }
  table.stack td:last-child, table.stack th:last-child { border-bottom: 0; }
  table.stack td[data-label]::before, table.stack th[data-label]::before { content: attr(data-label); font-weight: 700; text-align: left; color: var(--text); }
  table.stack td:empty, table.stack th:empty { display: none; }
}
@media (max-width: 30rem) {
  .nav a { flex-direction: column; gap: 2px; font-size: .85rem; }
  .result .big { font-size: 1.9rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
