/* Layout concept: a ledger page — calm content column, with each calculator set like a printed adding-machine tape. */
:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --sunk: #ecf1ee;
  --ink: #17262a;
  --muted: #56676a;
  --line: #d5ddd8;
  --accent: #1f6f5c;
  --accent-ink: #175646;
  --on-accent: #ffffff;
  --mark: #e8b931;
  --mark-soft: #fbefc4;
  --tape: #fffdf6;
  --danger: #b3261e;
  --ok: #1f6f3c;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  /* Figures use the body face with tabular numerals: familiar to finance readers, columns still align. */
  --font-num: var(--font-body);
  --font-code: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 10px;
  --maxw: 1180px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1614; --surface: #161f1d; --sunk: #1c2826; --ink: #e2ebe7; --muted: #95a6a1; --line: #2a3733;
    --accent: #4fbf9f; --accent-ink: #7fd6bd; --on-accent: #0b1513; --mark: #e8b931; --mark-soft: #3a3214; --tape: #1a2321;
    --danger: #f2827a; --ok: #6fd39a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1614; --surface: #161f1d; --sunk: #1c2826; --ink: #e2ebe7; --muted: #95a6a1; --line: #2a3733;
  --accent: #4fbf9f; --accent-ink: #7fd6bd; --on-accent: #0b1513; --mark: #e8b931; --mark-soft: #3a3214; --tape: #1a2321;
  --danger: #f2827a; --ok: #6fd39a; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 17px/1.6 var(--font-body);
}
img { max-width: 100%; height: auto; }
[hidden] { display: none !important; }
a { color: var(--accent-ink); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--mark); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.9rem, 4.2vw, 2.7rem); font-weight: 800; margin: 0 0 .4em; }
h2 { font-size: 1.45rem; font-weight: 600; margin: 1.6em 0 .5em; }
h3 { font-size: 1.12rem; font-weight: 600; margin: 1.2em 0 .4em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }

.wrap {
  max-width: var(--maxw); margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap.narrow { max-width: 760px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 21; background: var(--surface); }
.header-row { display: flex; align-items: center; gap: 16px; padding-block: 10px; }
.logo { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); font: 800 1.3rem var(--font-display); letter-spacing: -0.02em; flex-shrink: 0; }
.quick-search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.quick-search input { width: 100%; font: inherit; font-size: 16px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--sunk); color: var(--ink); }
.qs-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0,0,0,.14); overflow: hidden; z-index: 30; }
.qs-results a { display: block; padding: 9px 14px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); }
.qs-results a:last-child { border-bottom: 0; }
.qs-results a:hover, .qs-results a.active { background: var(--sunk); }
.qs-results small { display: block; color: var(--muted); font-size: .8rem; }
.qs-empty { padding: 10px 14px; color: var(--muted); }
.theme-toggle { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; display: grid; place-items: center; }
.cat-nav { border-top: 1px solid var(--line); }
.cat-nav-row { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-block: 4px; }
.cat-nav-row::-webkit-scrollbar { display: none; }
.cat-nav a { white-space: nowrap; padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .95rem; }
.cat-nav a:hover { background: var(--sunk); color: var(--ink); }

/* Buttons */
.btn { display: inline-block; background: var(--accent); color: var(--on-accent); padding: 11px 20px; border-radius: 8px; text-decoration: none; font-weight: 700; border: 0; cursor: pointer; font-size: 1rem; font-family: inherit; }
.btn:hover { color: var(--on-accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--accent-ink); box-shadow: inset 0 0 0 2px var(--accent); }
.btn-ghost:hover { color: var(--accent-ink); background: var(--sunk); }

/* Hero */
.hero { background: var(--surface); border-bottom: 1px solid var(--line); }
.hero-row { display: grid; grid-template-columns: 1.3fr 1fr; gap: 48px; align-items: center; padding-block: 48px 56px; }
.eyebrow { font: 700 .78rem var(--font-num); text-transform: uppercase; letter-spacing: .08em; color: var(--accent-ink); margin: 0 0 12px; }
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); max-width: 14ch; }
.lede { font-size: 1.15rem; color: var(--muted); max-width: 62ch; margin: 0 0 1em; }
.hero-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.tape { background: var(--tape); border: 1px solid var(--line); border-radius: 4px; padding: 22px 22px 30px; font-family: var(--font-num); font-size: .95rem; font-variant-numeric: tabular-nums; transform: rotate(1.2deg); box-shadow: 0 18px 40px -18px rgba(23,38,42,.35);
  -webkit-mask: linear-gradient(#000 0 0) top/100% calc(100% - 10px) no-repeat, radial-gradient(circle 6px at 8px 100%, transparent 98%, #000) bottom left/16px 10px repeat-x;
  mask: linear-gradient(#000 0 0) top/100% calc(100% - 10px) no-repeat, radial-gradient(circle 6px at 8px 100%, transparent 98%, #000) bottom left/16px 10px repeat-x; }
.tape-row { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; }
.tape-row span:first-child { color: var(--muted); }
.tape-rule { border-top: 2px dashed var(--line); margin: 8px 0; }
.tape-total { font-weight: 700; font-size: 1.15rem; }
.tape-total span:last-child { background: var(--mark-soft); padding: 0 6px; border-radius: 3px; }

/* Blocks & cards */
.block { margin-block: 40px; }
.block-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.block-head h2 { margin-top: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-block: 20px; }
.card { display: flex; flex-direction: column; gap: 4px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--accent); color: var(--ink); transform: translateY(-2px); }
.card strong { font: 600 1.1rem var(--font-display); }
.card-cat { font: 700 .7rem var(--font-num); text-transform: uppercase; letter-spacing: .08em; color: var(--accent-ink); }
.card-desc { color: var(--muted); font-size: .95rem; line-height: 1.45; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 32px; }
.topic { border-top: 2px solid var(--ink); padding-top: 4px; margin-bottom: 24px; }
.topic h2, .topic h3 { margin: 6px 0 8px; font-size: 1.15rem; display: flex; justify-content: space-between; align-items: baseline; }
.topic h2 a, .topic h3 a { color: var(--ink); text-decoration: none; }
.topic .count { font: 500 .8rem var(--font-num); color: var(--muted); }
.topic ul { list-style: none; padding: 0; margin: 0; }
.topic li { border-bottom: 1px dotted var(--line); }
.topic li a { display: block; padding: 6px 0; text-decoration: none; color: var(--ink); }
.topic li a:hover { color: var(--accent-ink); }
.topic .more { display: inline-block; margin-top: 8px; font-weight: 600; font-size: .92rem; }
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.post { display: flex; flex-direction: column; gap: 6px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.post:hover { border-color: var(--accent); color: var(--ink); }
.post strong { font: 600 1.08rem/1.3 var(--font-display); }
.post span { color: var(--muted); font-size: .95rem; line-height: 1.45; }
.post small { color: var(--muted); font-family: var(--font-num); font-size: .75rem; }
.post-list { display: flex; flex-direction: column; }
.post-row { display: flex; flex-direction: column; gap: 4px; padding: 18px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.post-row strong { font: 600 1.25rem/1.3 var(--font-display); }
.post-row:hover strong { color: var(--accent-ink); }
.post-row span { color: var(--muted); }
.post-meta { font: 500 .78rem var(--font-num); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.why { border-top: 1px solid var(--line); padding-top: 8px; }
.why-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; }
.why-grid p { color: var(--muted); margin: 0; }

/* Page */
.crumbs { font-size: .88rem; color: var(--muted); padding-block: 16px 4px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }
.page-head { padding-block: 12px 8px; }
.calc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; align-items: start; padding-bottom: 48px; }
.calc-main, .article { min-width: 0; }
.calc-head { padding-top: 8px; }

/* Calculator instrument */
.instrument { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin: 18px 0 8px; }
.calc-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; padding: 22px; align-content: start; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide, .field-textarea { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: .92rem; }
.field small { color: var(--muted); font-size: .8rem; line-height: 1.35; }
.input-wrap { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); overflow: hidden; }
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.input-wrap input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 10px 12px; font: 600 1.05rem var(--font-num); font-variant-numeric: tabular-nums; color: var(--ink); outline: none; }
.input-wrap { background: var(--surface); }
.affix { display: grid; place-items: center; padding: 0 10px; color: var(--muted); font-size: .88rem; background: var(--sunk); white-space: nowrap; }
.field select, .field textarea, .contact-form input, .contact-form textarea, .search-big input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); padding: 10px 12px; font: 500 1rem var(--font-body);
}
.field textarea { font-family: var(--font-num); font-size: .95rem; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.readout { background: var(--tape); border-left: 1px dashed var(--line); padding: 22px; font-family: var(--font-num); font-variant-numeric: tabular-nums; display: flex; flex-direction: column; gap: 4px; }
.readout-empty { color: var(--muted); font-family: var(--font-body); }
.r-primary { padding-bottom: 12px; margin-bottom: 8px; border-bottom: 2px dashed var(--line); }
.r-primary .r-label { font: 600 .78rem var(--font-num); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.r-primary .r-value { font-size: clamp(1.7rem, 4vw, 2.3rem); font-weight: 700; line-height: 1.15; word-break: break-word; }
.r-primary .r-value mark { background: linear-gradient(transparent 55%, var(--mark-soft) 55%); color: inherit; padding: 0 2px; }
.r-row { display: flex; justify-content: space-between; gap: 14px; padding: 5px 0; font-size: .95rem; border-bottom: 1px dotted var(--line); }
.r-row:last-child { border-bottom: 0; }
.r-row .r-label { color: var(--muted); font-family: var(--font-body); }
.r-row .r-value { font-weight: 700; text-align: right; word-break: break-word; }
.r-note { margin-top: 10px; font: 400 .88rem/1.45 var(--font-body); color: var(--muted); }
.r-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font: 700 .8rem var(--font-body); margin-top: 6px; background: var(--sunk); }
.r-badge.good { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.r-badge.warn { background: var(--mark-soft); color: var(--ink); }
.r-badge.bad { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.r-error { color: var(--danger); font-family: var(--font-body); }
.r-copy { align-self: flex-start; margin-top: 10px; font: 600 .82rem var(--font-body); background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 4px 10px; cursor: pointer; }

.calc-extra:empty { display: none; }
.calc-extra { margin: 18px 0; }
.bar { height: 14px; display: flex; border-radius: 999px; overflow: hidden; background: var(--sunk); margin: 6px 0 10px; }
.bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .88rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); max-height: 460px; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: var(--sunk); font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
td { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.prose table { margin: 1em 0; }
.prose .table-scroll { max-height: none; }

/* Prose */
.prose { max-width: 70ch; }
.prose p, .prose li { color: var(--ink); }
.prose h2 { border-top: 1px solid var(--line); padding-top: .9em; }
.prose code, .formula { font-family: var(--font-code); font-size: .92em; background: var(--sunk); padding: 2px 6px; border-radius: 4px; }
.formula { display: block; padding: 12px 16px; margin: 1em 0; border-left: 3px solid var(--mark); overflow-x: auto; white-space: pre-wrap; }
.prose blockquote { margin: 1em 0; padding: 4px 18px; border-left: 3px solid var(--accent); color: var(--muted); }
.prose .example { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 18px; }
.cat-intro { margin-top: 24px; }
.try-box { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; background: var(--mark-soft); border-radius: var(--radius); margin: 12px 0 8px; font-weight: 600; }
.try-box a { background: var(--surface); padding: 4px 12px; border-radius: 999px; text-decoration: none; font-size: .92rem; }

.faq { margin-top: 24px; max-width: 70ch; }
.faq details { border-bottom: 1px solid var(--line); padding: 4px 0; }
.faq summary { cursor: pointer; font-weight: 700; padding: 10px 0; list-style-position: outside; }
.faq details p { margin: 0 0 12px; color: var(--muted); }
.updated { color: var(--muted); font-size: .85rem; margin-top: 32px; }

/* Sidebar */
.calc-side { display: flex; flex-direction: column; gap: 24px; padding-top: 20px; }
.side-block h2 { font-size: 1rem; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .06em; font-family: var(--font-num); color: var(--muted); }
.side-list { list-style: none; padding: 0; margin: 0; border-top: 2px solid var(--ink); }
.side-list li { border-bottom: 1px solid var(--line); }
.side-list a { display: block; padding: 9px 0; text-decoration: none; color: var(--ink); font-weight: 600; }
.side-list a:hover { color: var(--accent-ink); }
.side-sticky { position: sticky; top: 130px; }

/* Ads */
.ad { margin: 24px auto; text-align: center; min-height: 90px; }
.ad-sidebar { min-height: 250px; margin: 0; }
.ad-placeholder { display: grid; place-items: center; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); font: 500 .72rem var(--font-num); text-transform: uppercase; letter-spacing: .1em; background: repeating-linear-gradient(-45deg, transparent 0 10px, var(--sunk) 10px 11px); }
.ad-sidebar.ad-placeholder { min-height: 600px; }

/* Forms & notices */
.contact-form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.hp { position: absolute; left: -5000px; }
.notice { padding: 12px 16px; border-radius: var(--radius); font-weight: 600; }
.notice.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.notice.err { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.search-big { display: flex; gap: 10px; margin-top: 12px; }

/* Footer */
.site-footer { background: var(--surface); border-top: 1px solid var(--line); margin-top: 40px; padding-bottom: env(safe-area-inset-bottom, 0px); }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 32px; padding-block: 36px 20px; }
.footer-grid h2 { font-size: .8rem; font-family: var(--font-num); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.footer-grid ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.footer-grid a { color: var(--ink); text-decoration: none; }
.footer-grid a:hover { color: var(--accent-ink); text-decoration: underline; }
.footer-brand strong { font: 800 1.3rem var(--font-display); }
.footer-brand p { color: var(--muted); max-width: 42ch; }
.footer-base { border-top: 1px solid var(--line); padding-block: 16px; font-size: .85rem; color: var(--muted); }

.embed-box { margin-top: 28px; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px; background: var(--surface); max-width: 70ch; }
.embed-box summary { cursor: pointer; font-weight: 700; padding: 10px 0; }
.embed-box textarea { width: 100%; font: .82rem var(--font-code); border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: var(--bg); color: var(--ink); margin-bottom: 12px; resize: vertical; }
.answer-box .readout:first-child { border-left: 0; }
.answer-box { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 760px) { .answer-box .readout + .readout { border-top: 1px dashed var(--line); } }

/* Trust line under calculator titles */
.calc-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: -4px 0 4px; padding: 0; list-style: none; color: var(--muted); font-size: .9rem; }
.calc-meta li { display: inline-flex; align-items: center; gap: 6px; }
.calc-meta svg { color: var(--accent); flex-shrink: 0; }

@media (max-width: 960px) {
  .calc-layout { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .side-sticky { position: static; }
  .ad-sidebar.ad-placeholder { min-height: 250px; }
}
@media (max-width: 760px) {
  body { font-size: 16px; }
  .hero-row { grid-template-columns: 1fr; gap: 28px; padding-block: 28px 36px; }
  .hero-tape { max-width: 380px; }
  .instrument { grid-template-columns: minmax(0, 1fr); }
  .readout { border-left: 0; border-top: 1px dashed var(--line); }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; }
  .site-header { position: static; }
  .header-row { flex-wrap: wrap; gap: 10px; }
  .quick-search { order: 3; flex-basis: 100%; max-width: none; }
  .theme-toggle { margin-left: auto; }
}
@media (max-width: 420px) {
  .calc-form { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .readout { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
