:root {
  --bg: #f6f8fa; --surface: #ffffff; --surface-2: #f0f3f6; --text: #1f2328; --muted: #57606a;
  --border: #d0d7de; --accent: #0b5cad; --accent-text: #ffffff; --fox: #c2410c;
  --good: #1a7f37; --bad: #cf222e; --warn-bg: #fff8c5; --warn-border: #d4a72c; --hl: #ddf4ff;
  --radius: 10px; --shadow: 0 1px 3px rgba(31, 35, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --surface: #161b22; --surface-2: #1c2128; --text: #e6edf3; --muted: #9198a1;
    --border: #30363d; --accent: #4493f8; --accent-text: #0d1117; --fox: #f0883e;
    --good: #3fb950; --bad: #f85149; --warn-bg: #2b2111; --warn-border: #9e6a03; --hl: #13304f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 4.5rem; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; animation: none !important; } }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.2; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 1rem; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--accent); color: var(--accent-text); padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: 1rem; top: .5rem; }
.num, .results, table { font-variant-numeric: tabular-nums; }

/* Header */
.site-header { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; align-items: center; gap: .75rem; min-height: 3.5rem; }
.logo { font-weight: 700; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.logo svg { width: 28px; height: 28px; }
.nav { display: flex; gap: .15rem; overflow-x: auto; flex: 1; scrollbar-width: thin; }
.nav a { color: var(--muted); text-decoration: none; padding: .35rem .5rem; border-radius: 6px; white-space: nowrap; font-size: .92rem; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.nav a.nav-social { position: relative; margin-left: .6rem; }
.nav a.nav-social::before { content: ""; position: absolute; left: -.4rem; top: 25%; bottom: 25%; border-left: 1px solid var(--border); }
.header-tools { display: flex; gap: .5rem; align-items: center; }
.header-tools label { font-size: .85rem; color: var(--muted); }
select, input, button, textarea { font: inherit; color: inherit; }
select { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .3rem .4rem; }
@media (max-width: 760px) {
  .site-header .wrap { flex-wrap: wrap; padding-top: .4rem; padding-bottom: .4rem; }
  .nav { order: 3; flex-basis: 100%; }
  .header-tools { margin-left: auto; }
}

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .4rem .75rem; border-radius: 6px; cursor: pointer; text-decoration: none; font-size: .9rem; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { padding: .2rem .5rem; font-size: .82rem; }
.linkbtn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; font-size: .9rem; }

/* Hero */
.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 2rem; align-items: center; padding: 2.5rem 0 1.5rem; }
.hero h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); margin: 0 0 .75rem; }
.hero p.lead { font-size: 1.1rem; color: var(--muted); margin: 0 0 1.25rem; max-width: 36rem; }
.noscript { background: var(--warn-bg); border: 1px solid var(--warn-border); padding: .75rem 1rem; border-radius: var(--radius); margin: 1rem 0; }

/* Fox */
.fox-hero { margin: 0; display: flex; align-items: flex-start; justify-content: flex-end; gap: .75rem; }
.fox-btn { background: none; border: 0; padding: 0; cursor: pointer; flex: none; border-radius: 12px; }
.fox-btn svg { width: 150px; height: 175px; display: block; }
.fox-name { font-size: .8rem; color: var(--muted); text-align: center; }
.fox-col { display: flex; flex-direction: column; align-items: center; }
.bubble { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .8rem 1rem .5rem; max-width: 300px; min-height: 6.5rem; box-shadow: var(--shadow); margin-top: 1.2rem; }
.bubble::after { content: ""; position: absolute; right: -10px; top: 1.6rem; width: 18px; height: 18px; background: var(--surface); border-right: 1px solid var(--border); border-top: 1px solid var(--border); transform: rotate(45deg); }
.bubble p { margin: 0 0 .4rem; font-size: .95rem; transition: opacity .35s ease; }
.bubble p.fading { opacity: 0; }
.bubble .who { font-size: .75rem; font-weight: 600; color: var(--fox); margin-bottom: .2rem; display: block; }
.bubble-controls { display: flex; gap: .25rem; justify-content: flex-end; }
.bubble-controls button { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; width: 2rem; height: 1.8rem; cursor: pointer; line-height: 1; }
.bubble.alert { border-color: var(--warn-border); }
@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; gap: 1rem; padding-top: 1.5rem; }
  .fox-hero { flex-direction: column-reverse; align-items: center; }
  .fox-btn svg { width: 90px; height: 105px; }
  .bubble { margin-top: 1rem; max-width: 100%; }
  .bubble::after { right: auto; left: calc(50% - 9px); top: -10px; border-right: 0; border-left: 1px solid var(--border); }
}
html.no-fox .fox-hero, html.no-fox .fox-mini, html.no-fox .fox-card-bubble { display: none !important; }
html.no-fox .hero { grid-template-columns: 1fr; }

/* Calculator cards */
.calcs { display: grid; gap: 1.5rem; padding: 1rem 0 2rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); position: relative; }
.card > h2 { margin: 0 2.5rem .25rem 0; font-size: 1.4rem; }
.card > .intro { margin: 0 0 1rem; color: var(--muted); }
.fox-mini { position: absolute; top: .75rem; right: .75rem; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); padding: 3px; cursor: pointer; }
.fox-mini svg { width: 100%; height: 100%; display: block; }
.fox-card-bubble { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: .6rem 2.2rem .6rem .8rem; margin: 0 0 1rem auto; max-width: 520px; font-size: .92rem; }
.fox-card-bubble::after { content: ""; position: absolute; right: 1.3rem; top: -8px; width: 14px; height: 14px; background: var(--surface-2); border-left: 1px solid var(--border); border-top: 1px solid var(--border); transform: rotate(45deg); }
.fox-card-bubble.alert { background: var(--warn-bg); border-color: var(--warn-border); }
.fox-card-bubble.alert::after { background: var(--warn-bg); border-color: var(--warn-border); }
.fox-card-bubble p { margin: 0; }
.fox-card-bubble .close { position: absolute; top: .3rem; right: .4rem; background: none; border: 0; cursor: pointer; font-size: 1.1rem; color: var(--muted); }
.calc-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem; }
@media (max-width: 860px) { .calc-body { grid-template-columns: 1fr; } }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .9rem 1rem; align-content: start; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .2rem; }
.field input[type="text"] { width: 100%; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
.field select { width: 100%; padding: .45rem .6rem; background: var(--bg); }
.field input[aria-invalid="true"] { border-color: var(--bad); }
.field small { display: block; color: var(--muted); font-size: .8rem; margin-top: .2rem; line-height: 1.35; }
.field.toggle { grid-column: 1 / -1; }
.field.toggle label { display: inline-flex; gap: .5rem; align-items: center; font-weight: 600; }
.results { background: var(--surface-2); border-radius: var(--radius); padding: 1rem; align-self: start; }
.results .empty { color: var(--muted); margin: 0; }
.results ul.errors { margin: .6rem 0 0; padding-left: 1.2rem; color: var(--bad); font-size: .9rem; }
.headline { margin: 0 0 .75rem; }
.headline .label { font-size: .85rem; color: var(--muted); display: block; }
.headline .value { font-size: 2rem; font-weight: 700; }
dl.kv { display: grid; grid-template-columns: 1fr auto; gap: .3rem 1rem; margin: 0; font-size: .95rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; font-weight: 600; }
.neg { color: var(--bad); }
.pos { color: var(--good); }
.subhead { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { border: 1px solid var(--border); padding: .35rem .5rem; text-align: right; white-space: nowrap; }
th { background: var(--surface-2); font-weight: 600; }
th[scope="row"] { text-align: left; }
td.center { background: var(--hl); font-weight: 700; outline: 2px solid var(--accent); outline-offset: -2px; }
caption { text-align: left; font-size: .85rem; color: var(--muted); padding-bottom: .3rem; caption-side: top; }
details.formulas { margin-top: 1rem; }
details.formulas summary { cursor: pointer; font-weight: 600; }
details.formulas pre { white-space: pre-wrap; background: var(--surface-2); padding: .75rem; border-radius: 6px; font-size: .85rem; overflow-x: auto; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.scenarios { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .6rem; font-size: .85rem; color: var(--muted); }
.status { font-size: .85rem; color: var(--good); min-height: 1.2em; margin-top: .3rem; }
.bridge-bar { display: grid; grid-template-columns: 11rem 1fr 4.5rem; gap: .5rem; align-items: center; font-size: .85rem; margin: .25rem 0; }
.bridge-bar .bar { height: .8rem; background: var(--accent); border-radius: 3px; min-width: 2px; }
.bridge-bar .bar.neg { background: var(--bad); }
.bridge-bar span:last-child { text-align: right; font-weight: 600; }

/* Explanations under each calculator */
.explainer { max-width: 760px; margin-top: 1.5rem; padding-top: .5rem; border-top: 1px solid var(--border); }
.explainer > summary { display: flex; align-items: center; gap: .5rem; cursor: pointer; list-style: none; padding: .5rem .6rem; margin: 0 -.6rem; border-radius: 6px; color: var(--muted); font-size: .95rem; font-weight: 600; }
.explainer > summary::-webkit-details-marker { display: none; }
.explainer > summary::before { content: ""; flex: none; width: .45rem; height: .45rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s ease; }
.explainer[open] > summary::before { transform: rotate(45deg); }
.explainer > summary:hover { color: var(--accent); background: var(--surface-2); }
.explainer-body { padding-top: .75rem; }
.explainer h3 { font-size: 1.05rem; margin: 1.25rem 0 .4rem; }
.explainer-body > h3:first-child { margin-top: 0; }
.expand-all { margin: 0 0 -.75rem; text-align: right; font-size: .9rem; }
.explainer p, .explainer ul, .explainer dl { margin: 0 0 .75rem; }
.explainer ul { padding-left: 1.2rem; }
.explainer li { margin-bottom: .3rem; }
.faq dt { font-weight: 600; }
.faq dd { margin: 0 0 .6rem; color: var(--muted); }
.explainer-foot { font-size: .88rem; color: var(--muted); }

/* Calculator pages: breadcrumbs and related links */
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: .35rem; margin: 0; padding: 1rem 0 0; font-size: .88rem; color: var(--muted); }
.breadcrumbs li + li::before { content: "›"; margin-right: .35rem; }
.hero-calc { padding-top: 1rem; }
.related { padding-bottom: 2rem; }
.related-list { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.related-list li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.related-list a { font-weight: 600; display: block; margin-bottom: .25rem; }
.related-list span { color: var(--muted); font-size: .92rem; }

/* Home page hub */
.hub-grid { list-style: none; padding: 0; margin: 0 0 2rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.hub-card h3 { margin: 0 0 .4rem; font-size: 1.15rem; }
.hub-card p { margin: 0; color: var(--muted); }
.hub-card .full-name { margin: -.2rem 0 .5rem; font-size: .85rem; color: var(--muted); }
.hub-card a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.hub-card:hover { border-color: var(--accent); }
.calc-link { font-size: .92rem; }

/* Cases & content */
.cases { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; padding-bottom: 2rem; }
@media (max-width: 860px) { .cases { grid-template-columns: 1fr; } }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 4px; padding: .05rem .4rem; }
.prose { max-width: 760px; padding: 2rem 0 3rem; }
.prose pre { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--border); padding: .75rem; border-radius: 6px; font-size: .88rem; }
.prose h2 { margin-top: 2rem; border-top: 1px solid var(--border); padding-top: 1.5rem; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 1.5rem 0; font-size: .88rem; color: var(--muted); }
.site-footer p { margin: .3rem 0; }
.site-footer nav { display: flex; gap: 1rem; flex-wrap: wrap; }

.print-only { display: none; }
@media print {
  .site-header, .site-footer nav, .hero, .cases, .breadcrumbs, .related, .actions, .scenarios, .fox-mini, .fox-card-bubble, .status, details.formulas, .explainer, .expand-all, .skip { display: none !important; }
  body.printing main > .wrap:not(.calcs), body.printing section.card:not(.print-target), body.printing .calcs > :not(.print-target) { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .print-only { display: block; margin-bottom: 1rem; }
  .calc-body { grid-template-columns: 1fr 1fr; }
  .field small { display: none; }
  td.center { background: #e8e8e8 !important; }
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
