:root {
  --paper: #f3ecdf;
  --paper-2: #e6dccb;
  --panel: #fffaf2;
  --ink: #1c1612;
  --muted: #5c5146;
  --line: #d8ccb8;
  --line-strong: #1c1612;
  --tally: #c8342a;
  --tally-ink: #fff8f5;
  --warn: #7a3010;
  --good: #1b5a3e;
  --serif: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Public Sans", "Avenir Next", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
  --header-h: 3.5rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12100e;
    --paper-2: #1d1a16;
    --panel: #191714;
    --ink: #f4eee6;
    --muted: #cbbba8;
    --line: #3c342c;
    --line-strong: #f4eee6;
    --tally: #ff5d4d;
    --tally-ink: #2a0c0a;
    --warn: #ffc2a4;
    --good: #9be0bf;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #12100e;
  --paper-2: #1d1a16;
  --panel: #191714;
  --ink: #f4eee6;
  --muted: #cbbba8;
  --line: #3c342c;
  --line-strong: #f4eee6;
  --tally: #ff5d4d;
  --tally-ink: #2a0c0a;
  --warn: #ffc2a4;
  --good: #9be0bf;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

html { overflow-x: clip; }
body {
  margin: 0;
  min-width: 320px;
  max-width: 100%;
  color: var(--ink);
  background: var(--paper);
  border-top: 8px solid var(--tally);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  overflow-x: clip;
}

::selection { background: var(--tally); color: var(--tally-ink); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--tally); outline-offset: 2px; }

.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;
}

.skip {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 20;
  background: var(--ink);
  color: var(--paper);
  padding: 0.4rem 0.7rem;
  text-decoration: none;
}
.skip:focus { top: 0.75rem; }

.page, .mast, .site-footer { width: min(1120px, calc(100% - 2rem)); margin-inline: auto; }
.mast {
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: inherit;
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}
.brand svg { width: 1.6rem; height: 1.6rem; display: block; }
.tally-fill { fill: var(--tally); }
.period { color: var(--tally); }
.nav { display: flex; gap: 0.9rem; margin-left: auto; }
.nav a { color: inherit; text-underline-offset: 0.18em; }
#theme {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: inherit;
  font: inherit;
  min-height: 2.4rem;
  padding: 0 0.7rem;
  cursor: pointer;
}
#theme:hover { background: var(--ink); color: var(--paper); }

.intro {
  display: grid;
  gap: 1.25rem;
  padding: 2.2rem 0 1.4rem;
}
.eyebrow {
  margin: 0 0 0.35rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.calc, .command, .reference, h1 { scroll-margin-top: 4.6rem; }
h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 560;
  font-size: clamp(2.3rem, 6vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
}
.lede { max-width: 38rem; font-size: 1.08rem; margin: 0.8rem 0 0; }
.formula {
  margin: 0;
  align-self: end;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-top: 6px solid var(--tally);
  padding: 0.9rem 1rem 1rem;
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.45;
}
.formula strong { display: block; font-family: var(--sans); font-weight: 600; margin-bottom: 0.35rem; }

h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 560;
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.section-top { display: grid; gap: 0.35rem; margin-bottom: 1rem; }
.section-top p, .quiet { color: var(--muted); margin: 0; }

.report {
  display: grid;
  grid-template-columns: 1fr;
  border: 1px solid var(--line-strong);
  background: var(--panel);
}
.readout {
  appearance: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0.85rem 1rem 0.95rem;
  cursor: pointer;
  font: inherit;
  min-height: 5.4rem;
}
.readout:last-child { border-bottom: 0; }
.readout:hover { background: var(--paper-2); }
.readout-k {
  display: block;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.readout-v {
  display: block;
  margin-top: 0.2rem;
  font-family: var(--mono);
  font-size: clamp(1.45rem, 3vw, 2rem);
  font-weight: 500;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.readout-s { display: block; color: var(--muted); font-size: 0.88rem; }

.workspace {
  display: grid;
  gap: 1.25rem;
  margin-top: 1.25rem;
}
.numbers, .modebox, .command, .reference {
  min-width: 0;
}
.numbers, .modebox {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 1rem;
}
.field { display: grid; gap: 0.3rem; margin-bottom: 0.9rem; }
.field-label, .field legend, .units span {
  font-size: 0.92rem;
  font-weight: 600;
}
.tag {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--line-strong);
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 0.15em;
}
.duration-grid, .split {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}
.split.two { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.35rem 0.6rem; }
label.unit-field { display: grid; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); font-weight: 500; }

input[type="number"], input[type="text"], input[type="search"], select {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: inherit;
  font: inherit;
  font-family: var(--mono);
  padding: 0.4rem 0.55rem;
  border-radius: 0;
}
input[type="search"] { font-family: var(--sans); }
.units { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.units label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 2.4rem;
  padding: 0 0.55rem;
  border: 1px solid var(--line);
  background: var(--paper);
  font-weight: 500;
  cursor: pointer;
}
.units input { accent-color: var(--tally); }
.chips, .filters { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip, .filters button, .use, .text-btn, .outline {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: inherit;
  font: inherit;
  min-height: 2.4rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}
.chip { font-family: var(--mono); font-size: 0.84rem; }
.chip[aria-pressed="true"], .preset[aria-pressed="true"], .filters button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.chip:hover, .preset:hover, .filters button:hover, .use:hover, .outline:hover {
  border-color: var(--tally);
}
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11.5rem), 1fr)); gap: 0.45rem; }
.preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  text-align: left;
  min-height: 3.4rem;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: inherit;
  font: inherit;
  padding: 0.45rem 0.6rem;
  cursor: pointer;
}
.preset-name { font-size: 0.82rem; line-height: 1.25; }
.preset-figure { font-family: var(--mono); font-size: 0.95rem; }

.modes { display: flex; gap: 0; border-bottom: 1px solid var(--line-strong); margin: -1rem -1rem 1rem; }
.modes button {
  flex: 1 1 0;
  min-height: 2.9rem;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  padding: 0.4rem 0.35rem;
  cursor: pointer;
}
.modes button[aria-selected="true"] { border-bottom-color: var(--tally); }
.panel p { margin-top: 0; }
#breakdown, #fit-note, #name-note, #codec-note, #target-blurb, #target-preview {
  font-size: 0.92rem;
}
#breakdown, #fit-note { font-family: var(--mono); font-size: 0.78rem; line-height: 1.45; color: var(--muted); }
#problem { min-height: 0; margin: 0.2rem 0 0; }
#problem:empty, #fit-note:empty, #name-note:empty { display: none; }
.is-warn { color: var(--warn); font-weight: 600; }

.math { margin: 1rem 0 2rem; }
.math summary { cursor: pointer; font-weight: 600; }
.math p { color: var(--muted); }

.command, .reference { padding-bottom: 2rem; }
.command-bar, .table-tools, .table-footer, .search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
}
pre {
  margin: 0.8rem 0;
  padding: 0.9rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
:root[data-theme="dark"] pre, :root:not([data-theme="light"]) pre { }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) pre { background: #090807; color: var(--ink); border: 1px solid var(--line); }
}
:root[data-theme="dark"] pre { background: #090807; color: var(--ink); border: 1px solid var(--line); }
#copy-command, .outline {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  font-weight: 600;
  min-height: 2.75rem;
  padding: 0.4rem 0.8rem;
}
#copy-command:disabled { opacity: 0.45; cursor: not-allowed; }
.names { display: grid; gap: 0.7rem; }
.search-row { margin: 0.8rem 0; position: relative; }
.search-row input { padding-right: 4.5rem; }
#clear-search, .kbd {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}
#clear-search { right: 2.2rem; min-height: 2rem; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; }
.kbd {
  right: 0.55rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  border: 1px solid var(--line);
  padding: 0.05rem 0.3rem;
  color: var(--muted);
  pointer-events: none;
}
.filters { margin-bottom: 0.7rem; }
.table-scroll {
  max-width: 100%;
  max-height: min(70vh, 820px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  overscroll-behavior-x: contain;
  contain: paint;
}
table { width: 100%; border-collapse: collapse; min-width: 46rem; }
caption { caption-side: bottom; text-align: left; padding: 0.6rem; color: var(--muted); }
th, td { text-align: left; vertical-align: top; padding: 0.7rem 0.75rem; border-bottom: 1px solid var(--line); }
thead th {
  position: sticky;
  top: 0;
  background: var(--paper-2);
  z-index: 1;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.kind {
  display: block;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.item-name { display: block; font-weight: 600; }
.figure { font-family: var(--mono); white-space: nowrap; }
.figure .use { display: block; margin-top: 0.35rem; white-space: normal; }
.detail { min-width: 16rem; color: var(--muted); font-size: 0.92rem; }
.detail a { color: var(--ink); }
.empty {
  padding: 1.5rem 1rem 1.7rem;
  text-align: center;
}
.empty h3 { margin: 0.2rem 0; font-family: var(--serif); }
.table-footer { margin-top: 0.55rem; color: var(--muted); font-size: 0.9rem; }
.notes { padding-left: 1.1rem; }
.notes li { margin: 0.55rem 0; }
.source-list { padding-left: 1.1rem; }
.source-list a { color: inherit; }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
  justify-content: space-between;
  align-items: baseline;
  border-top: 1px solid var(--line-strong);
  padding: 1rem 0 2rem;
  margin-top: 0.5rem;
}
.site-footer a { color: inherit; }
.footer-brand { font-family: var(--serif); font-size: 1.2rem; text-decoration: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translate(-50%, 0.4rem);
  background: var(--ink);
  color: var(--paper);
  padding: 0.55rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.manual-copy {
  position: fixed;
  inset: auto 1rem 1rem 1rem;
  z-index: 25;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  padding: 0.9rem;
  max-width: 28rem;
  margin-inline: auto;
}
.manual-copy div { display: flex; justify-content: space-between; align-items: center; }
.manual-copy h2 { font-size: 1.3rem; }
.noscript {
  width: min(1120px, calc(100% - 2rem));
  margin: 1rem auto 2rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line-strong);
  background: var(--panel);
}

@media (min-width: 720px) {
  .report { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .readout { border-bottom: 0; border-right: 1px solid var(--line); }
  .readout:last-child { border-right: 0; }
  .intro { grid-template-columns: 1.4fr 0.8fr; align-items: end; }
  .names { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 960px) {
  .workspace { grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr); align-items: start; }
  .page { width: min(1120px, calc(100% - 3rem)); }
}
@media (max-width: 640px) {
  .mast { flex-wrap: wrap; width: min(1120px, calc(100% - 1.25rem)); padding: 0.45rem 0 0.2rem; }
  .nav { order: 3; width: 100%; margin-left: 0; padding: 0.15rem 0 0.45rem; gap: 0.85rem; }
  #theme { margin-left: auto; }
  .page, .site-footer { width: min(1120px, calc(100% - 1.25rem)); }
  .modes button { font-size: 0.82rem; min-width: 0; }
  .kbd { display: none; }
}
