:root {
  --bg: #f3f1ec;
  --panel: #fffdf9;
  --ink: #1b1a17;
  --muted: #6b675e;
  --line: #ddd8cc;
  --accent: #c2410c;
  --accent-ink: #fff;
  --ok: #15803d;
  --bad: #b91c1c;
  --chip: #efebe2;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 8px 24px rgb(0 0 0 / .06);
  --stage: radial-gradient(circle at 50% 40%, #fbfaf7 0%, #e9e5dc 70%);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --panel: #1d1f24;
    --ink: #ecebe7;
    --muted: #9a978f;
    --line: #2e3138;
    --accent: #fb923c;
    --accent-ink: #1b1209;
    --ok: #4ade80;
    --bad: #f87171;
    --chip: #262930;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    --stage: radial-gradient(circle at 50% 40%, #30333b 0%, #1a1c21 70%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
code, pre { font-family: var(--mono); font-size: .9em; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin-bottom: .4rem; }

.top {
  max-width: 1200px; margin: 0 auto; padding: 28px 16px 12px;
  display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap;
}
.top h1 { font-family: var(--mono); font-size: 1.9rem; font-weight: 700; }
.top p { margin: .2rem 0 0; color: var(--muted); max-width: 60ch; }
.gh { color: var(--muted); font-size: .9rem; }
.gh[hidden] { display: none; }

main {
  max-width: 1200px; margin: 0 auto; padding: 12px 16px 24px;
  display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); align-items: start;
}
@media (max-width: 900px) { main { grid-template-columns: minmax(0, 1fr); } .result { order: -1; } }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 20px;
}
.controls section + section, .controls section + details, .controls details + .actions { margin-top: 20px; }
.hint { color: var(--muted); font-size: .85rem; margin: 0 0 .6rem; }
.hint.center { text-align: center; margin: .6rem 0 0; }
small { color: var(--muted); font-size: .8rem; display: block; margin-top: .3rem; }
.label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .35rem; }

input[type=text], input[type=number] {
  width: 100%; min-width: 0; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
input:focus-visible, button:focus-visible, .stage:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button {
  font: inherit; color: inherit; background: var(--chip); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; padding: 9px 20px; }

.msgs { display: grid; gap: 8px; }
.msg { display: grid; grid-template-columns: 3.6rem minmax(0, 1fr) 4.6rem; gap: 8px; align-items: center; }
.msg .deg { font-family: var(--mono); font-size: .9rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.msg .deg i { width: 18px; height: 18px; display: inline-block; flex: none; }
.msg input { font-family: var(--mono); }
.msg .mode { font-size: .72rem; text-align: center; border-radius: 999px; padding: 2px 6px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.msg .mode.byte { color: var(--accent); }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; margin-top: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: minmax(0, 1fr); } .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.field { display: block; min-width: 0; }
.field.check { display: flex; gap: 8px; align-items: center; align-self: end; padding-bottom: 8px; }
.field[hidden] { display: none; }
.unit { display: flex; align-items: center; gap: 6px; }
.unit i { font-style: normal; color: var(--muted); font-size: .85rem; }
.unit button { padding: 6px 10px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 2px; background: var(--bg); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 5px 13px; border-radius: 7px; font-weight: 500; font-size: .9rem; }
.seg input:checked + span { background: var(--panel); box-shadow: 0 1px 3px rgb(0 0 0 / .15); color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

details.advanced { border-top: 1px solid var(--line); padding-top: 14px; }
details summary { cursor: pointer; font-weight: 600; }

.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.status { color: var(--muted); font-size: .9rem; }
.status .spin { display: inline-block; width: .9em; height: .9em; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { color: var(--bad); margin: 12px 0 0; font-size: .9rem; }

/* ---------- the dial ---------- */
.stage-wrap { max-width: 520px; margin: 0 auto; }
.stage {
  position: relative; aspect-ratio: 1; width: 100%; border-radius: 18px; background: var(--stage);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; overflow: hidden;
}
.stage.dragging { cursor: grabbing; }
.stage img { position: absolute; inset: 4%; width: 92%; height: 92%; pointer-events: none; }
.stage img:not([src]) { visibility: hidden; }
#backing { filter: drop-shadow(0 6px 14px rgb(0 0 0 / .28)); }
#disk { transform-origin: 50% 50%; will-change: transform; }
#disk.settle { transition: transform .32s cubic-bezier(.3, 1.45, .55, 1); }
.plug #disk { transition: filter .18s ease, scale .18s ease; }
.plug #disk.settle { transition: transform .3s cubic-bezier(.3, 1.2, .55, 1), filter .2s ease .22s, scale .2s ease .22s; }
.plug #disk.lifted { scale: 1.045; filter: drop-shadow(0 10px 14px rgb(0 0 0 / .45)); }
.stage.click #disk { animation: click .12s ease-out; }
@keyframes click { 50% { scale: .992; } }
.placeholder {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted);
  background: var(--stage); transition: opacity .25s;
}
.placeholder[hidden] { display: grid; opacity: 0; pointer-events: none; }

.stage-bar { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.stage-bar button { font-size: 1.25rem; line-height: 1; padding: 8px 14px; flex: none; }
.reads { flex: 1; min-width: 0; text-align: center; border-radius: 10px; padding: 6px 10px; background: var(--chip); }
.reads .cam { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.reads b { display: block; font-family: var(--mono); font-weight: 600; overflow-wrap: anywhere; }
.reads.none b { color: var(--muted); font-weight: 400; }

.states { list-style: none; padding: 0; margin: 20px 0 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 480px) { .states { grid-template-columns: minmax(0, 1fr); } }
.states li button {
  width: 100%; text-align: left; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center;
  background: var(--bg); padding: 8px 10px;
}
.states li.active button { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.states .deg { font-family: var(--mono); color: var(--muted); font-size: .85rem; }
.states .m { font-family: var(--mono); overflow-wrap: anywhere; }
.states .m.empty { color: var(--muted); font-family: inherit; font-style: italic; }
.states .ok { color: var(--ok); font-size: .8rem; }
.states .bad { color: var(--bad); font-size: .8rem; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 20px 0 0; }
.facts div { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.facts dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.facts dd small { display: inline; font-weight: 400; }

.downloads { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.dl-group { margin-top: 12px; }
.dl-row { display: flex; flex-wrap: wrap; gap: 8px; }
.dl { font-family: var(--mono); font-size: .85rem; }
.dl::before { content: "↓ "; color: var(--accent); }
.cli { display: flex; gap: 8px; align-items: flex-start; }
.cli code { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; font-size: .8rem; }

.log { margin-top: 18px; }
.log pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .78rem; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 10px; max-height: 260px; overflow: auto; }

footer { max-width: 1200px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: .85rem; }
footer p { max-width: 80ch; }

.result.busy .stage, .result.busy .states, .result.busy .downloads { opacity: .55; transition: opacity .2s; }
.sound { white-space: nowrap; margin-left: .4em; cursor: pointer; }
.sound input { vertical-align: -1px; }
.dl-group .label { text-transform: none; letter-spacing: 0; font-size: .85rem; }
footer a { color: inherit; }

/* shown design no longer matches the form */
.stage img { transition: opacity .2s, filter .2s; }
.result.stale #backing, .result.stale #ring, .result.stale #disk { opacity: .22; }
.result.stale .states, .result.stale .facts, .result.stale .downloads, .result.stale .reads { opacity: .5; }
.stale-banner {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; width: min(84%, 340px);
  display: grid; gap: 10px; justify-items: center; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 14px 16px; font-size: .9rem; cursor: default;
}
.stale-banner[hidden] { display: none; }
