:root {
  --bg: #15110f;
  --panel: #1f1a17;
  --ink: #efe6dc;
  --muted: #a3958a;
  --line: #3a312c;
  --accent: #ff4d2e;      /* burn */
  --accent-ink: #1a0b07;
  --ok: #8fd18f;
  --warn: #f2b134;
  --stripe: repeating-linear-gradient(135deg, var(--accent) 0 14px, #2b211c 14px 28px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5efe7;
    --panel: #ffffff;
    --ink: #1a1512;
    --muted: #6d6159;
    --line: #e2d8cc;
    --accent: #d9341a;
    --accent-ink: #fff;
    --stripe: repeating-linear-gradient(135deg, var(--accent) 0 14px, #f1e4d6 14px 28px);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 560px; margin: 0 auto; padding: 32px 16px 48px; }

.masthead { margin-bottom: 20px; }
.stripe { height: 10px; background: var(--stripe); border-radius: 2px; margin-bottom: 18px; }
h1 {
  margin: 0;
  font: 700 2rem/1.1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tag { margin: 6px 0 0; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 22px;
}

/* state gating — the page is one element with data-state */
[class*="only-"] { display: none; }
[data-state="idle"] .only-idle,
[data-state="recording"] .only-recording,
[data-state="review"] .only-review,
[data-state="sealed"] .only-sealed,
[data-state="loading"] .only-loading,
[data-state="playing"] .only-playing,
[data-state="gone"] .only-gone,
[data-state="nokey"] .only-nokey,
[data-state="missing"] .only-missing,
[data-state="corrupt"] .only-corrupt,
[data-state="error"] .only-error { display: block; }
/* mode gating — audio | video | text */
.only-audio, .only-video, .only-text { display: none !important; }
[data-mode="audio"] .only-audio, [data-mode="video"] .only-video, [data-mode="text"] .only-text { display: block !important; }
[data-state="idle"]:not([data-mode="text"]) .recorder,
[data-state="recording"] .recorder { display: block; }
[data-mode="text"] .recorder { display: none !important; }
.recorder { display: none; text-align: center; }
.composer { display: none; }
[data-state="idle"][data-mode="text"] .composer { display: block !important; }

.modes { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.mode {
  border: 0; border-bottom: 3px solid transparent; border-radius: 0; padding: 8px 14px;
  color: var(--muted); font-weight: 600;
}
.mode[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

#live, #vpreview, #vplayer { width: 100%; background: #000; border-radius: 8px; aspect-ratio: 16/9; margin-bottom: 10px; }
#live { display: none; }
[data-mode="video"][data-state="recording"] #live { display: block; }
textarea {
  width: 100%; min-height: 160px; resize: vertical; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 12px; font: inherit;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.tpreview, .tview {
  white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 0 0 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px;
  max-height: 50vh; overflow: auto;
}
.tview { user-select: text; }
.between { justify-content: space-between; margin-top: 8px; }
.progress { height: 4px; background: var(--line); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.level {
  --lvl: 0;
  height: 6px; border-radius: 3px; background: var(--line); margin-bottom: 14px; overflow: hidden;
}
.level::after {
  content: ""; display: block; height: 100%; width: calc(var(--lvl) * 100%);
  background: var(--accent); transition: width 60ms linear;
}
.timer {
  font: 500 2.6rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums; margin: 10px 0 18px;
}
.controls { display: flex; justify-content: center; gap: 10px; }

button, .btn {
  appearance: none; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--ink);
  font: inherit; font-weight: 600; padding: 10px 18px; cursor: pointer;
  text-decoration: none; display: inline-block;
}
button:disabled { opacity: .6; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.danger { border-color: var(--accent); color: var(--accent); }
.ghost { color: var(--muted); }
.wide { width: 100%; margin-top: 8px; padding: 14px; font-size: 1.05rem; }

.hint { color: var(--muted); font-size: .92rem; }
.err { color: var(--accent); margin: 12px 0 0; }
.gone { color: var(--muted); font-size: 1.05rem; margin: 0; }

.field { display: block; margin: 16px 0 0; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.field small { font-weight: 400; }
.row { display: flex; gap: 8px; align-items: center; }
input, select, .pinout {
  width: 100%; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#pin, #pinout {
  font: 500 1.3rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: .25em;
}
.pinout { display: block; }
audio { width: 100%; margin: 4px 0 10px; }

.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 14px; }
.meta dt { font-size: .8rem; color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; }
.notice {
  border-left: 4px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
  padding: 10px 12px; border-radius: 0 8px 8px 0; margin-bottom: 8px; font-size: .95rem;
}
.playing-indicator { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.result h2 { margin: 0 0 6px; }
.foot { margin-top: 20px; color: var(--muted); font-size: .85rem; }
.foot a { color: inherit; }

@media (max-width: 420px) { .meta { grid-template-columns: 1fr; } }
