:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1d1f22;
  --muted: #5d6166;
  --line: #d9d3c6;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --cell: #e9e3d6;
  --cell-line: #b9b09e;
  --pad: #f2c9a9;
  --error: #b91c1c;
  --focus: #2563eb;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1f2226;
    --ink: #ece8df;
    --muted: #a3a6ab;
    --line: #34383e;
    --accent: #fb923c;
    --accent-ink: #1a1206;
    --cell: #2b2f35;
    --cell-line: #4d535b;
    --pad: #6b3a1c;
    --error: #f87171;
    --focus: #93c5fd;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.wrap { width: min(1180px, 100% - 32px); margin-inline: auto; }

.top { padding: 32px 0 8px; }
.eyebrow { margin: 0; color: var(--accent); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.8rem; }
h1 { margin: 0 0 8px; font-size: clamp(2rem, 5vw, 2.8rem); line-height: 1.1; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }
.lede { margin: 0; max-width: 62ch; color: var(--muted); font-size: 1.05rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px 0 32px;
  align-items: start;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.controls, .result {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

fieldset { border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: 6px; }
label { display: block; font-size: 0.92rem; font-weight: 600; margin: 8px 0; }
.unit { color: var(--muted); font-weight: 400; }
.hint { margin: 4px 0 8px; color: var(--muted); font-size: 0.85rem; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair label { margin: 4px 0; }

input[type="number"], select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

input[aria-invalid="true"] { border-color: var(--error); }

.choices { display: grid; gap: 8px; }
.choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 400;
  cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice input { margin-top: 4px; accent-color: var(--accent); }
.choice strong { display: block; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; margin-top: 12px; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }
label:has(input:disabled), label:has(select:disabled) { opacity: 0.5; }

.nudge { margin: 0 0 16px; }
.nudge summary { cursor: pointer; font-weight: 600; }

button {
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; border-style: dashed; font-weight: 500; font-size: 0.9rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.small { padding: 4px 10px; font-size: 0.85rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.summary { display: block; margin-bottom: 16px; font-size: 1.05rem; }
.summary strong { font-size: 1.2rem; }
.summary .sub { display: block; color: var(--muted); font-size: 0.92rem; margin-top: 4px; }
.error { color: var(--error); font-weight: 600; }

.diagram { margin: 0 0 16px; }
.diagram svg { display: block; width: 100%; height: auto; max-height: 520px; }
figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }

.svg-drawer { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.svg-piece { fill: var(--pad); stroke: var(--ink); stroke-width: 1.2; }
.svg-cell { fill: var(--cell); stroke: var(--cell-line); stroke-width: 0.6; }
.svg-label { fill: var(--ink); font-weight: 800; font-family: inherit; }
.svg-dim { fill: var(--muted); font-family: inherit; }
.svg-dim-line { stroke: var(--muted); stroke-width: 0.8; }
.svg-front { fill: var(--accent); font-weight: 700; font-family: inherit; letter-spacing: 0.06em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
caption { text-align: left; font-weight: 700; margin-bottom: 6px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
td.label { font-weight: 800; font-size: 1.1rem; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 6px; }
.progress { min-height: 1.5em; color: var(--muted); font-size: 0.92rem; margin: 0 0 12px; }

.preview { margin: 8px 0 24px; }
.preview-canvas {
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  touch-action: none;
}
.preview-canvas canvas { display: block; width: 100%; height: 100%; }

.notes { border-top: 1px solid var(--line); padding-top: 20px; margin-top: 8px; }
.notes p { max-width: 70ch; }
.cache-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 8px; color: var(--muted); font-size: 0.9rem; }

.foot { color: var(--muted); font-size: 0.85rem; padding: 0 0 40px; }

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