:root {
  --bg: #f1f0ec;
  --surface: #ffffff;
  --ink: #1c1d21;
  --muted: #45474e;
  --line: #b9b7ae;
  --field: #7d7b72;
  --accent: #7a4a00;
  --accent-ink: #ffffff;
  --accent-soft: #f3e4c6;
  --err: #a1251a;
  --tick: #1c1d21;
  --strip: #fbf3df;
  --rail: #6b6a64;
  --r: 4px;
  --head: Bahnschrift, "DIN Alternate", "D-DIN", "Roboto Condensed", "Arial Narrow", "Segoe UI", sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #202227;
    --ink: #ebe9e3;
    --muted: #bfbcb3;
    --line: #4a4c52;
    --field: #7b7d84;
    --accent: #e3ae55;
    --accent-ink: #16171a;
    --accent-soft: #3a3020;
    --err: #ff9b8c;
    --tick: #ebe9e3;
    --strip: #2b2a24;
    --rail: #8e8c85;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--body); }
a { color: var(--accent); text-underline-offset: 2px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--surface); color: var(--ink); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Track along the top: two rails over sleepers. */
.top { background:
  linear-gradient(var(--rail), var(--rail)) left calc(100% - 9px) / 100% 2px no-repeat,
  linear-gradient(var(--rail), var(--rail)) left calc(100% - 3px) / 100% 2px no-repeat,
  repeating-linear-gradient(90deg, var(--line) 0 6px, transparent 6px 18px) left bottom / 100% 14px no-repeat; }
.top-in { padding: 14px 16px 24px; }
.brand { font: 700 20px/1.2 var(--head); color: var(--ink); text-decoration: none; letter-spacing: 0.02em; }

.intro { padding: 20px 0 4px; max-width: 46rem; }
h1 { font: 700 clamp(30px, 5.4vw, 44px)/1.08 var(--head); margin: 0 0 8px; }
.lede { margin: 0; color: var(--muted); font-size: 18px; }
h2 { font: 700 23px/1.25 var(--head); margin: 0 0 10px; }
h3 { font: 700 19px/1.3 var(--head); margin: 22px 0 6px; }

.tool { display: grid; gap: 18px; margin: 16px 0 8px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .tool { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); grid-template-areas: "in opts" "res res"; gap: 18px 36px; }
  .inputs { grid-area: in; }
  .opts { grid-area: opts; }
  .result { grid-area: res; }
}
.panel { min-width: 0; }

/* Ruler rows */
#rows { display: grid; gap: 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; padding: 10px 0 8px; border-top: 1px solid var(--line); align-items: end; }
.row:first-child { border-top: 0; padding-top: 0; }
.row .pick { grid-column: 1 / -1; }
.row .note, .row .err { grid-column: 1 / -1; }
.row .del { grid-column: 1 / -1; justify-self: start; margin-bottom: 4px; }
@media (min-width: 560px) {
  .row { grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 1.4fr) auto; }
  .row .pick { grid-column: auto; }
  .row .del { grid-column: auto; margin-bottom: 12px; }
}
.ratio-box { display: flex; align-items: center; gap: 6px; }
.ratio-box b { font: 700 19px var(--head); }

fieldset { border: 0; margin: 0 0 14px; padding: 0; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: 6px; }
.seg { display: flex; flex-wrap: wrap; }
.seg legend { width: 100%; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-opt span { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 13px; border: 1.5px solid var(--field); margin-left: -1.5px; background: var(--surface); color: var(--ink); font-size: 16px; white-space: nowrap; cursor: pointer; }
.seg-opt:first-of-type span { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.seg-opt:last-of-type span { border-radius: 0 var(--r) var(--r) 0; }
.seg-opt input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 600; position: relative; z-index: 1; }
.seg-opt input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 2; }

.field { display: block; margin: 0 0 12px; min-width: 0; }
.field > span:first-child { display: block; font-weight: 600; margin-bottom: 4px; }
input[type=text], select {
  width: 100%; min-height: 46px; font: 17px/1.3 var(--body); color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--field); border-radius: var(--r); padding: 8px 10px;
}
input[aria-invalid=true] { border-color: var(--err); border-width: 2px; }
.ratio-box input { font: 700 20px/1.2 var(--head); }
.pair { display: flex; flex-wrap: wrap; gap: 0 22px; align-items: flex-start; }
.err { color: var(--err); margin: -4px 0 10px; font-weight: 600; }
.note { margin: -4px 0 10px; color: var(--muted); font-size: 16px; }

/* Result: the ruler, then the numbers */
.result { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px 18px; }
.answer { font: 400 20px/1.3 var(--head); margin: 0 0 4px; }
.answer b { font-size: clamp(24px, 6.4vw, 40px); }
.answer-sub { margin: 0 0 12px; }
.res-wait { margin: 0; font-weight: 600; color: var(--err); }
.preview { margin: 0 0 4px; }
.preview-cap { margin: 0 0 12px; color: var(--muted); font-size: 16px; }
.preview svg { display: block; width: 100%; max-width: 560px; height: auto; }
.preview .body { fill: var(--strip); stroke: var(--tick); stroke-width: 0.25; }
.preview .tick { stroke: var(--tick); }
.preview .num, .preview .unit { fill: var(--tick); font-family: var(--body); font-weight: 700; }
.preview .unit { font-weight: 400; }
.facts { border-collapse: collapse; font-variant-numeric: tabular-nums; width: 100%; max-width: 640px; }
.facts th, .facts td { text-align: left; padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line); font-size: 16px; vertical-align: top; }
.facts thead th { font-weight: 700; }
.facts tbody th { font-weight: 600; }

.opts h2 { margin-top: 0; }
.print-sum { margin: 2px 0 10px; }
.res-print { margin: 14px 0 0; }
.jump { margin: -4px 0 8px; }
.jump a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 2px; }
.jump a[hidden] { display: none; }
@media (min-width: 900px) { .jump { display: none; } }
@media (min-width: 900px) { .res-print { display: none; } }
.unit-hint { font-weight: 400; color: var(--muted); }
.link-note { margin: 12px 0 0; padding: 8px 12px; background: var(--accent-soft); border-radius: var(--r); max-width: 46rem; }
.link-note[hidden] { display: none; }
.tip { margin: 10px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 6px 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 8px 18px;
  font: 600 17px/1.2 var(--body); color: var(--ink); background: var(--surface); border: 1.5px solid var(--field);
  border-radius: var(--r); cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.quiet { background: transparent; }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: 16px; }
#share-note, #reset-note { font-size: 16px; }

.conv-sec { margin: 30px 0 10px; padding-top: 18px; border-top: 3px double var(--ink); }
.conv-in .field { flex: 1 1 14rem; max-width: 20rem; }
#conv-out table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
#conv-out th, #conv-out td { text-align: left; padding: 6px 16px 6px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
#conv-out p { margin: 6px 0; }
.conv-block { margin: 6px 0 14px; overflow-x: auto; }

.saved-sec { margin: 8px 0 20px; }
.save-note { padding: 8px 10px; background: var(--accent-soft); border-radius: var(--r); }
#earlier summary { cursor: pointer; font-weight: 600; padding: 10px 0; display: list-item; }
#earlier-list { list-style: none; padding: 0; margin: 4px 0 8px; }
#earlier-list li { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }

.content { max-width: 46rem; padding: 10px 0 30px; }
.content h2 { margin-top: 30px; }
.tbl-wrap { overflow-x: auto; }
.ratios { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.ratios th, .ratios td { text-align: left; padding: 7px 12px 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 16px; }
.ratios tbody th { font-weight: 700; }
.ratios th, .ratios td { overflow-wrap: anywhere; }
.faq h3 { margin-top: 18px; }
.faq p { margin: 0 0 6px; }
.sources { color: var(--muted); margin-top: 22px; }

.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20; display: flex; gap: 12px; align-items: center;
  background: var(--ink); color: var(--bg); padding: 8px 10px 8px 16px; border-radius: var(--r); max-width: calc(100vw - 32px); pointer-events: none; }
.toast .btn { pointer-events: auto; background: var(--bg); color: var(--ink); border-color: var(--bg); }
.toast[hidden] { display: none; }

.foot { border-top: 1px solid var(--line); padding: 18px 0 30px; }
.sb-footer { font-size: 16px; color: var(--muted); }
.sb-more { margin: 0 0 10px; line-height: 1.7; }
.sb-privacy, .sb-credit { margin: 0 0 6px; }
.sb-footer a { color: var(--ink); }

#print-root { display: none; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

@page { margin: 10mm; }
@media print {
  body { background: #fff; color: #000; font: 11pt/1.4 Arial, Helvetica, sans-serif; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root svg.sheet { display: block; break-after: page; page-break-after: always; overflow: hidden; }
  #print-root svg.sheet:last-child { break-after: auto; page-break-after: auto; }
  .print-msg { font: 13pt Arial, sans-serif; }
}
