:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --ink: #1f2328;
  --sub: #5b6470;
  --line: #dcd9d0;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --warn: #9a3b2b;
  --good: #2f6f5e;
  --soft: #eef3f0;
  --radius: 10px;
  --font: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181b; --surface: #1d2125; --ink: #e8eaed; --sub: #a3abb5; --line: #343a40;
    --accent: #6fbfa6; --accent-ink: #0d1412; --warn: #f08b77; --good: #6fbfa6; --soft: #1f2a27;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15181b; --surface: #1d2125; --ink: #e8eaed; --sub: #a3abb5; --line: #343a40;
  --accent: #6fbfa6; --accent-ink: #0d1412; --warn: #f08b77; --good: #6fbfa6; --soft: #1f2a27;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.75; font-size: 16px; }
a { color: var(--accent); }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
header.site { border-bottom: 1px solid var(--line); background: var(--surface); }
header.site .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
header.site a.brand { color: var(--ink); text-decoration: none; font-weight: 700; }
header.site nav a { margin-left: 14px; font-size: 14px; color: var(--sub); text-decoration: none; }
header.site nav a:hover { color: var(--accent); }
main { padding: 24px 0 48px; }
h1 { font-size: 26px; line-height: 1.4; margin: 8px 0 12px; }
h2 { font-size: 20px; margin: 36px 0 10px; padding-top: 4px; border-top: 1px solid var(--line); }
h3 { font-size: 17px; margin: 22px 0 6px; }
p.lead { color: var(--sub); margin-top: 0; }
.note { font-size: 14px; color: var(--sub); }

form.calc, .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
fieldset { border: 0; margin: 0 0 18px; padding: 0; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.loanrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 520px) { .loanrow { grid-template-columns: 1fr 1fr; } }
label { display: block; font-size: 14px; color: var(--sub); }
label > span.u { margin-left: 4px; }
input[type=number], select { width: 100%; font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
input[type=number]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
details { margin-top: 6px; }
details > summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
button { font: inherit; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; }
button.ghost { background: transparent; color: var(--accent); }

#results { margin-top: 20px; display: grid; gap: 16px; }
#errors { color: var(--warn); font-weight: 700; }
.compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.card h3 { margin-top: 0; }
.big { font-size: 24px; font-weight: 700; }
.minus { color: var(--warn); }
.plus { color: var(--good); }
table.kv { width: 100%; border-collapse: collapse; font-size: 15px; }
table.kv th, table.kv td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.kv td.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.callout { background: var(--soft); border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: 15px; }
.aff { display: none; }
.aff.on { display: block; border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: 15px; }
.aff .pr { font-size: 12px; color: var(--sub); }

article p, article li { max-width: 46em; }
article table { border-collapse: collapse; margin: 10px 0; font-size: 15px; }
article th, article td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.formula { font-family: ui-monospace, Menlo, monospace; font-size: 14px; background: var(--soft); padding: 10px 12px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; }
ol.sources { font-size: 14px; }
footer.site { border-top: 1px solid var(--line); padding: 20px 0 40px; font-size: 13px; color: var(--sub); }
footer.site a { color: var(--sub); margin-right: 12px; }

@media print {
  header.site, footer.site, form.calc, .btns, .aff, nav { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #999; }
}
.summary { font-size: 18px; background: var(--surface); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px; margin: 0; }
.wf { margin-top: 12px; display: grid; gap: 6px; font-size: 13px; }
.wf-row { display: grid; grid-template-columns: 7.5em 1fr 6.5em; gap: 8px; align-items: center; }
.wf-track { position: relative; height: 14px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.wf-bar { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.wf-base { background: var(--sub); }
.wf-out { background: var(--line); outline: 1px solid var(--sub); }
.wf-plus { background: var(--good); }
.wf-minus { background: var(--warn); }
.wf-v { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wf-zero { position: absolute; top: -2px; bottom: -2px; width: 0; border-left: 1px dashed var(--ink); z-index: 1; }
.card, .summary, .callout { overflow-wrap: anywhere; min-width: 0; }
@media (max-width: 600px) {
  table.kv th { width: 42%; }
  table.kv td.n { white-space: normal; }
  .wf-row { grid-template-columns: 5.5em 1fr 5.8em; gap: 6px; }
  header.site nav a { margin-left: 0; margin-right: 12px; }
  h1 { font-size: 22px; }
}
