/* One working column: intake (drop + options), a key, then a card per design.
   The pictures are always the diagram's own dark navy; the page around them
   follows the viewer's theme. */
:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --ink: #141823;
  --muted: #586174;
  --line: #d5dae4;
  --accent: #1d68c9;
  --accent-ink: #ffffff;
  --plate: #0c0e14;             /* the diagram's own background */
  --bad: #c8373d;
  --warn: #9a6a00;
  --ok: #24804a;
  --chip-bad: #fbe9ea;
  --chip-warn: #fbf1d9;
  --chip-ok: #e3f4ea;
  --chip: #e8ecf3;
  --display: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
  --body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #090b10; --surface: #121620; --ink: #e2e6ef; --muted: #8f98ab; --line: #252c3a;
    --accent: #5aaaff; --accent-ink: #06101f; --plate: #0c0e14;
    --bad: #ff6b6f; --warn: #f2c14e; --ok: #5fd38d;
    --chip-bad: #3a1517; --chip-warn: #332810; --chip-ok: #10301e; --chip: #1c2230;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #090b10; --surface: #121620; --ink: #e2e6ef; --muted: #8f98ab; --line: #252c3a;
  --accent: #5aaaff; --accent-ink: #06101f; --plate: #0c0e14;
  --bad: #ff6b6f; --warn: #f2c14e; --ok: #5fd38d;
  --chip-bad: #3a1517; --chip-warn: #332810; --chip-ok: #10301e; --chip: #1c2230;
  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: 15px/1.5 var(--body);
}
[hidden] { display: none !important; }
code { font-family: var(--mono); font-size: 0.92em; }

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding-block: 32px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 20px;
}

.masthead h1 {
  font: 600 clamp(28px, 4vw, 40px)/1.1 var(--display);
  letter-spacing: 0.01em;
  margin: 0 0 8px;
  text-wrap: balance;
}
.lede { margin: 0; max-width: 68ch; color: var(--muted); font-size: 16px; }

/* ---- intake ------------------------------------------------------------ */
.intake { display: grid; gap: 12px; }
.dropzone {
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
  padding: 28px 16px;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 120ms, background 120ms;
}
.dropzone:hover, .dropzone:focus-within, body.dragging .dropzone {
  border-color: var(--accent);
}
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dz-main { font-size: 16px; }
.dz-button {
  display: inline-block;
  padding: 6px 14px;
  margin-right: 4px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.dz-note { color: var(--muted); font-size: 13px; }

.options {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px 20px;
}
.field { display: grid; gap: 4px; }
.field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
select, button { font: inherit; }
select {
  padding: 6px 30px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}
button { cursor: pointer; border-radius: 6px; padding: 6px 14px; }
button.primary { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { border: 1px solid var(--line); background: transparent; color: var(--ink); }
button.ghost:hover { border-color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- key --------------------------------------------------------------- */
.key { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; }
.key summary { cursor: pointer; font-weight: 600; }
.key-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 8px 24px;
  font-size: 14px;
}
.key-list li { display: flex; gap: 10px; align-items: center; min-width: 0; }
.key-note { color: var(--muted); font-size: 13px; max-width: 90ch; margin: 12px 0 2px; }
.sw {
  flex: none;
  width: 34px;
  height: 20px;
  border-radius: 4px;
  background: var(--plate);
  position: relative;
  display: inline-grid;
  place-items: center;
}
.sw.line::after { content: ""; width: 24px; height: 3px; background: var(--c); }
.sw.dot::after { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.sw.ramp {
  background: linear-gradient(90deg, #ff9628 0 25%, #f5e13c 25% 50%, #50dc78 50% 75%, #5aaaff 75%);
  box-shadow: inset 0 0 0 3px var(--plate);
}
.sw.num { color: #000; font: 700 10px/1 var(--body); z-index: 0; }
.sw.num::before { content: ""; position: absolute; z-index: -1; width: 14px; height: 14px; border-radius: 50%; background: #ff9628; }
.sw.halo::after { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #5aaaff; }
.sw.cross::before, .sw.cross::after { content: ""; position: absolute; width: 14px; height: 2.5px; background: #ff3c3c; transform: rotate(45deg); }
.sw.cross::after { transform: rotate(-45deg); }
.sw.dash::after { content: ""; width: 26px; height: 0; border-top: 3px dashed #ff3c3c; }
.sw.arc::after { content: ""; width: 26px; height: 26px; margin-top: 14px; border-radius: 50%; border: 2px solid transparent; border-top-color: #5adcff; }
.sw.arc { overflow: hidden; }
.sw.hull::after { content: ""; width: 14px; height: 12px; background: #3e424c; box-shadow: 12px 0 0 #1e2128; margin-right: 12px; }

/* ---- results ----------------------------------------------------------- */
#results { display: grid; gap: 24px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  gap: 12px;
  min-width: 0;
}
.card-head { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: start; justify-content: space-between; }
.card-title { min-width: 0; }
.card-title h2 { font: 600 22px/1.2 var(--display); margin: 0; overflow-wrap: anywhere; }
.card-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card .status { font-size: 13px; color: var(--muted); align-self: center; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.chips li.bad { background: var(--chip-bad); color: var(--bad); font-weight: 600; }
.chips li.warn { background: var(--chip-warn); color: var(--warn); font-weight: 600; }
.chips li.ok { background: var(--chip-ok); color: var(--ok); font-weight: 600; }
.chips li.sample { background: transparent; border: 1px solid var(--line); color: var(--muted); }

.figure {
  background: var(--plate);
  border-radius: 8px;
  overflow: hidden;
}
.figure.actual { overflow: auto; max-height: 85vh; }
.zoom { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; border-radius: 0; }
.zoom img { display: block; width: 100%; height: auto; }
.figure.actual .zoom { width: max-content; cursor: zoom-out; }
.figure.actual .zoom img { width: auto; max-width: none; }

.details {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px 28px;
}
.details h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.notes { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; max-width: 75ch; }
.notes li.none { list-style: none; margin-left: -18px; color: var(--muted); }
.notes li.more { list-style: none; margin-left: -18px; }
.notes li.more button { padding: 2px 10px; font-size: 13px; }
.table-scroll { overflow-x: auto; }
.exits { border-collapse: collapse; font-size: 13px; width: 100%; }
.exits th, .exits td { text-align: left; padding: 4px 12px 4px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.exits th { font-weight: 600; color: var(--muted); }
.exits td { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.exits .num { text-align: right; }
.exits td.tight { color: var(--warn); font-weight: 500; }
.exits td.clipped { color: var(--bad); font-weight: 500; }

.card.error { border-color: var(--bad); }
.card.error .card-sub { color: var(--bad); }

.empty { color: var(--muted); text-align: center; padding: 24px; }

.colophon { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 16px; }
.colophon p { margin: 0; max-width: 90ch; }

.drop-veil {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border: 3px dashed var(--accent);
  pointer-events: none;
}
.drop-veil span { font: 600 28px var(--display); color: var(--accent); }

@media (max-width: 760px) {
  .details { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
