@font-face {
  font-family: "Roboto";
  src: url("/fonts/roboto-latin.woff2") format("woff2");
  font-weight: 300 900;
  font-display: swap;
}

:root {
  --spruce: #15171c;
  --spruce-2: #2448ff;
  --sun: #ffd21f;
  --sun-soft: #fff3b8;
  --blue: #2448ff;
  --coral: #ff5a4e;
  --fog: #f6f6f2;
  --paper: #ffffff;
  --brass: #ffd21f;
  --brass-ink: #15171c;
  --line: #e2e2da;
  --ink: #15171c;
  --muted: #5a5d66;
  --key: #ffffff;
  --key-op: #fff3b8;
  --key-fn: #2a2d35;
  --danger: #e2382b;
  --focus: #2448ff;
  --radius-lg: 18px;
  --radius: 10px;
  --wrap: 1120px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fog: #101114;
    --paper: #1a1c21;
    --ink: #f1f1ec;
    --muted: #a6a9b2;
    --line: #2e3138;
    --key: #2a2d35;
    --key-op: #3a3420;
    --key-fn: #2a2d35;
    --spruce: #000000;
    --spruce-2: #7d93ff;
    --blue: #7d93ff;
    --sun-soft: #3a3420;
    --danger: #ff7a70;
    --focus: #7d93ff;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fog);
  color: var(--ink);
  font: 400 1.0625rem/1.6 "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
img, svg { display: block; max-width: 100%; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 10; }

/* Header */
.site-header { border-bottom: 1px solid var(--line); background: var(--paper); }
.site-header .wrap { display: flex; align-items: center; gap: 24px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; letter-spacing: -0.01em; text-decoration: none; }
.brand svg { width: 32px; height: 32px; }
.brand b { font-weight: inherit; }
.brand span { color: var(--muted); font-weight: 500; }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a { text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 500; font-size: 0.98rem; }
.nav a:hover, .nav a[aria-current="page"] { background: var(--fog); }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: inherit; }
@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .nav { display: none; width: 100%; flex-direction: column; margin: 0 0 12px; }
  .site-header .wrap { flex-wrap: wrap; }
  .nav.open { display: flex; }
}

/* Hero */
.hero { padding: 40px 0 36px; background: #fffaeb; color: #15171c; border-bottom: 4px solid var(--sun); }
.hero .lede { color: var(--muted); }
.hero h1 { color: #15171c; }
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); line-height: 1.05; letter-spacing: -0.015em; font-weight: 800; margin: 0 0 12px; max-width: 16ch; }
.lede { font-size: 1.15rem; color: var(--muted); max-width: 60ch; margin: 0; }

/* Calculator + tape */
.calc-area { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: stretch; margin: 28px 0 12px; }
@media (max-width: 860px) { .calc-area { grid-template-columns: 1fr; } }

.calc { background: #15171c; border-radius: var(--radius-lg); padding: 18px; color: #fff; box-shadow: 0 18px 40px -18px rgba(21,23,28,.55); }
.calc-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.modes { display: inline-flex; background: rgba(255,255,255,.08); border-radius: 999px; padding: 4px; }
.modes button { border: 0; background: none; color: #d9dbe2; font: inherit; font-weight: 600; font-size: .92rem; padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.modes button[aria-pressed="true"] { background: var(--sun); color: #15171c; }
.angle { border: 1px solid rgba(255,255,255,.25); background: none; color: #d9dbe2; font: inherit; font-size: .85rem; font-weight: 600; padding: 5px 10px; border-radius: 8px; cursor: pointer; }
.calc:not([data-mode="adv"]) .angle { visibility: hidden; }

.display { background: #000; border-radius: var(--radius); padding: 14px 16px; min-height: 108px; display: flex; flex-direction: column; justify-content: flex-end; text-align: right; overflow: hidden; }
.display .expr { color: #a6a9b2; font-size: 1.05rem; min-height: 1.6em; word-break: break-all; }
.display .result { color: var(--sun); font-size: clamp(2.2rem, 6vw, 3.2rem); font-weight: 300; line-height: 1.1; letter-spacing: -0.02em; white-space: nowrap; overflow-x: auto; scrollbar-width: none; }
.display .result.error { color: #ffb4a9; font-size: 1.4rem; font-weight: 500; }

.pads { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
.calc[data-mode="adv"] .pads { grid-template-columns: 5fr 4fr; }
.pad { display: grid; gap: 8px; }
.pad-main { grid-template-columns: repeat(4, 1fr); }
.pad-adv { grid-template-columns: repeat(5, 1fr); display: none; align-content: start; }
.calc[data-mode="adv"] .pad-adv { display: grid; }
@media (max-width: 640px) { .calc[data-mode="adv"] .pads { grid-template-columns: 1fr; } }

.k { border: 0; border-radius: 12px; min-height: 58px; font: inherit; font-size: 1.35rem; font-weight: 500; cursor: pointer; background: var(--key); color: var(--ink); transition: transform .06s ease, filter .12s; touch-action: manipulation; }
.k:hover { filter: brightness(.96); }
.k:active { transform: scale(.97); }
.k.op { background: var(--key-op); }
.k.fn { background: rgba(255,255,255,.1); color: #f1f1ec; font-size: 1.02rem; min-height: 48px; }
.k.clear { background: var(--coral); color: #fff; font-weight: 700; }
.k.eq { background: var(--brass); color: var(--brass-ink); font-weight: 700; font-size: 1.6rem; }
@media (prefers-color-scheme: dark) { .k.eq { color: var(--brass-ink); } }
@media (prefers-reduced-motion: reduce) { .k { transition: none; } .k:active { transform: none; } }

.keys-hint { color: #a6a9b2; font-size: .85rem; margin: 12px 2px 0; }
.keys-hint kbd { font: inherit; font-weight: 600; color: #fff; background: rgba(255,255,255,.1); padding: 1px 6px; border-radius: 5px; }

/* Tape: paper roll with torn top edge */
.tape { position: relative; background: #fff; color: #15171c; box-shadow: 0 18px 40px -22px rgba(21,23,28,.5); border-radius: 0 0 var(--radius) var(--radius); border: 1px solid var(--line); border-top: 0; display: flex; flex-direction: column; min-height: 320px; margin-top: 10px; }
.tape::before { content: ""; position: absolute; left: -1px; right: -1px; top: -10px; height: 10px; background: radial-gradient(circle at 6px 0, transparent 6px, var(--paper) 6.5px) -1px 0 / 12px 10px repeat-x; }
.tape-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; border-bottom: 1px dashed var(--line); }
.tape-head h2 { font-size: 1rem; margin: 0; font-weight: 700; }
.tape-actions { display: flex; gap: 6px; }
.tape-actions button { font: inherit; font-size: .85rem; font-weight: 600; border: 1px solid var(--line); background: none; color: var(--ink); border-radius: 7px; padding: 4px 9px; cursor: pointer; }
.tape ol { list-style: none; margin: 0; padding: 8px 0; overflow-y: auto; flex: 1; max-height: 420px; }
.tape li button { all: unset; box-sizing: border-box; display: block; width: 100%; padding: 8px 16px; text-align: right; cursor: pointer; }
.tape li button:hover { background: var(--fog); }
.tape li button:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.tape .t-expr { display: block; color: var(--muted); font-size: .92rem; word-break: break-all; }
.tape .t-res { display: block; font-weight: 700; font-size: 1.15rem; }
.tape .empty { color: var(--muted); padding: 16px; font-size: .95rem; text-align: left; }
.tape-note { font-size: .8rem; color: var(--muted); padding: 8px 16px 12px; margin: 0; border-top: 1px dashed var(--line); }

/* Calculator directory */
.directory { padding: 36px 0 8px; }
.directory > h2 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 0 0 18px; }
.cols { display: grid; grid-template-columns: repeat(4, 1fr); gap: 28px; border-top: 2px solid var(--ink); padding-top: 18px; }
@media (max-width: 900px) { .cols { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .cols { grid-template-columns: 1fr; } }
.cols h3 { font-size: 1.05rem; margin: 0 0 10px; }
.cols ul { list-style: none; margin: 0; padding: 0; }
.cols li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.cols li a { font-weight: 600; text-decoration: none; }
.cols li a:hover { text-decoration: underline; }
.cols li small { display: block; color: var(--muted); font-size: .9rem; }

/* Prose */
.prose { max-width: 72ch; padding: 24px 0 8px; }
.prose h2 { font-size: 1.55rem; letter-spacing: -0.015em; line-height: 1.2; margin: 2em 0 .5em; }
.prose h3 { font-size: 1.2rem; margin: 1.6em 0 .4em; }
.prose p, .prose li { color: var(--ink); }
.prose table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: .98rem; }
.prose th, .prose td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.prose th { font-weight: 700; }
.prose kbd { font: inherit; font-weight: 600; background: var(--paper); border: 1px solid var(--line); padding: 0 6px; border-radius: 5px; }
.table-scroll { overflow-x: auto; }

/* FAQ */
.faq { max-width: 72ch; padding: 8px 0 40px; }
.faq h2 { font-size: 1.55rem; margin: 1.6em 0 .6em; }
.faq-item { border-bottom: 1px solid var(--line); }
.faq-item summary { cursor: pointer; padding: 14px 0; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 16px; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; font-weight: 400; font-size: 1.4rem; line-height: 1; color: var(--muted); }
.faq-item[open] summary::after { content: "\2212"; }
.faq-item > div { padding: 0 0 16px; color: var(--ink); }

/* Footer */
.site-footer { background: #15171c; color: #d9dbe2; margin-top: 40px; padding: 40px 0 28px; font-size: .95rem; }
.site-footer .grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 28px; }
@media (max-width: 760px) { .site-footer .grid { grid-template-columns: 1fr 1fr; } }
.site-footer h2 { font-size: 1rem; color: var(--sun); margin: 0 0 10px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { padding: 3px 0; }
.site-footer a { color: #d9dbe2; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; color: var(--sun); }
.site-footer .legal { border-top: 1px solid rgba(255,255,255,.15); margin-top: 28px; padding-top: 16px; color: #a6a9b2; }

/* ---------- Calculator pages ---------- */
.crumbs { font-size: .9rem; color: var(--muted); padding: 18px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }
.page-head { padding: 14px 0 8px; }
.page-head h1 { font-size: clamp(1.9rem, 4.4vw, 2.8rem); line-height: 1.08; letter-spacing: -0.01em; font-weight: 800; margin: 0 0 10px; }
.meta { font-size: .9rem; color: var(--muted); margin: 10px 0 0; }

.tool { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0; margin: 20px 0 8px; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--line); }
@media (max-width: 820px) { .tool { grid-template-columns: 1fr; } }
.tool-in { background: var(--paper); padding: 22px; display: grid; gap: 16px; align-content: start; }
.tool-out { background: var(--sun); color: #15171c; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-weight: 600; font-size: .95rem; }
.field small { color: var(--muted); font-size: .85rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .row2 { grid-template-columns: 1fr; } }
.input { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); overflow: hidden; }
.input:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.input input, .input select { flex: 1; min-width: 0; border: 0; background: none; color: var(--ink); font: inherit; font-size: 1.1rem; padding: 11px 12px; outline: none; }
.input .unit { display: flex; align-items: center; padding: 0 12px; color: var(--muted); background: var(--fog); font-size: .95rem; }
select.plain, .tool-in select { appearance: auto; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-weight: 600; font-size: .95rem; }
.seg input:checked + span { background: var(--sun); border-color: #15171c; color: #15171c; box-shadow: inset 0 0 0 1px #15171c; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--spruce-2); }

.out-label { color: #4a4636; font-weight: 600; font-size: .95rem; margin: 0; }
.big { font-size: clamp(2.2rem, 5.5vw, 3rem); font-weight: 300; letter-spacing: -0.02em; line-height: 1.05; margin: 0; }
.big small { font-size: 1.1rem; font-weight: 500; color: #4a4636; margin-left: 6px; }
.breakdown { width: 100%; border-collapse: collapse; font-size: .98rem; }
.breakdown td { padding: 7px 0; border-bottom: 1px solid rgba(21,23,28,.14); }
.breakdown td:last-child { text-align: right; font-weight: 600; white-space: nowrap; padding-left: 12px; }
.breakdown tr.sum td { border-bottom: 0; border-top: 2px solid #15171c; font-weight: 700; }
.out-note { font-size: .85rem; color: #4a4636; margin: 0; }
.bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: rgba(21,23,28,.12); }
.bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .85rem; color: #4a4636; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.copy-btn { align-self: flex-start; font: inherit; font-size: .88rem; font-weight: 600; background: #15171c; color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer; }

.sched { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0 20px; background: var(--paper); }
.sched table { margin: 0; }
.sched th { position: sticky; top: 0; background: var(--paper); }
.num { text-align: right !important; white-space: nowrap; }

.sources, .related { max-width: 72ch; }
.sources h2, .related h2 { font-size: 1.3rem; margin: 2em 0 .5em; }
.sources ul { padding-left: 1.1em; font-size: .95rem; }
.sources li { margin: 4px 0; }
.related ul { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 24px; }
.related li { border-bottom: 1px solid var(--line); padding: 8px 0; }
.related li a { font-weight: 600; text-decoration: none; }
.related li small { display: block; color: var(--muted); font-size: .88rem; }
.note { background: var(--paper); border-left: 4px solid var(--brass); padding: 12px 16px; border-radius: 0 var(--radius) var(--radius) 0; }

[hidden] { display: none !important; }

.cat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.cat-item { display: block; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; }
.cat-item:hover { border-color: var(--spruce-2); }
.cat-item strong { display: block; font-size: 1.1rem; }
.cat-item span { color: var(--muted); font-size: .93rem; }
.directory h2 a { text-decoration: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nav-search { display: inline-flex; align-items: center; }
.search-box { margin: 16px 0 20px; max-width: 640px; }
.search-results { list-style: none; padding: 0; max-width: 72ch; }
.search-results li { border-bottom: 1px solid var(--line); padding: 12px 0; }
.search-results a { font-weight: 600; font-size: 1.1rem; }
.search-results p { margin: 4px 0 0; color: var(--muted); }

body { display: flex; flex-direction: column; min-height: 100vh; }
body > main { flex: 1; }

/* ---------- Yellow theme accents ---------- */
.prose a, .faq a, .sources a, .note a { color: var(--blue); }
.nav a:hover, .nav a[aria-current="page"] { background: var(--sun); color: #15171c; }
.cols { border-top: 3px solid var(--ink); }
.cols h3 a { text-decoration: none; }
.cols h3 a::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--sun); margin-right: 8px; box-shadow: inset 0 0 0 1px var(--ink); }
.cat-item { border-left: 6px solid var(--sun); }
.cat-item:hover { border-color: var(--ink); border-left-color: var(--sun); background: var(--sun-soft); }
.note { border-left-color: var(--blue); }
.tool { border: 2px solid var(--ink); }
.faq-item summary::after { color: var(--blue); }
.k.op { color: #15171c; }
@media (prefers-color-scheme: dark) {
  .k.op { color: var(--ink); }
  .tool { border-color: var(--line); }
  .hero { background: #1d1a0c; color: var(--ink); }
  .hero h1 { color: var(--sun); }
  .hero .lede { color: var(--muted); }
}

/* Scientific mode */
.display .ind { display: flex; gap: 10px; justify-content: flex-start; font-size: .75rem; font-weight: 700; letter-spacing: .04em; color: var(--sun); min-height: 1em; }
.calc:not([data-mode="adv"]) .adv-only { display: none; }
.k.fn sup { font-size: .62em; line-height: 0; }
.k.tog[aria-pressed="true"] { background: var(--sun); color: #15171c; }
.k.mem-k { color: #ffe27a; }
.pad-adv { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 640px) { .pad-adv .k.fn { min-height: 44px; font-size: .95rem; } }
