:root {
  --bg: #0b1220;
  --bg2: #111a2e;
  --card: #152038;
  --line: #24314f;
  --text: #e6ecf7;
  --muted: #8d9bb8;
  --accent: #2dd4bf;
  --accent-ink: #052e2b;
  --ok: #34d399;
  --warn: #fbbf24;
  --over: #f87171;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 80% -10%, #16304a 0%, transparent 60%) fixed, var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  line-height: 1.45;
}
main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 1rem; }
[hidden] { display: none !important; }
a { color: var(--accent); }
code { background: var(--bg2); padding: .05rem .35rem; border-radius: 5px; font-size: .9em; }
h2 { font-size: 1.1rem; margin: 0 0 .9rem; letter-spacing: .01em; }
h3 { font-size: 1rem; margin: 0 0 .7rem; color: var(--muted); font-weight: 600; }
.mt { margin-top: 1.6rem; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- Topbar / footer ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1.2rem; border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, .7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-size: 1.15rem; }
.brand b { color: var(--accent); }
.footer {
  display: flex; justify-content: center; gap: 1.2rem; flex-wrap: wrap;
  padding: .9rem; font-size: .85rem; color: var(--muted); border-top: 1px solid var(--line);
}

/* ---------- Cards / forms ---------- */
.setup-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 920px) { .setup-grid { grid-template-columns: minmax(0, 1fr); } }
.card { min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .9rem; }
.card-head h2 { margin: 0; }
.pill { font-size: .8rem; color: var(--muted); background: var(--bg2); border: 1px solid var(--line); padding: .2rem .6rem; border-radius: 999px; white-space: nowrap; }
.hint { font-size: .82rem; color: var(--muted); margin: .7rem 0 0; }

input[type=text], input[type=number], select {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: .55rem .7rem; font: inherit; min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input.invalid { border-color: var(--over); }
.time-input { width: 5.5rem; text-align: center; font-variant-numeric: tabular-nums; }
input[type=number] { width: 5rem; }
input[type=range] { accent-color: var(--accent); flex: 1; max-width: 220px; }

.field { margin: 0 0 1rem; border: 0; padding: 0; }
.field > label:first-child, legend { display: block; font-size: .88rem; color: var(--muted); margin-bottom: .35rem; padding: 0; }
.field.inline { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.field.inline > label:first-child { margin: 0; }
.radio, .check { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; cursor: pointer; color: var(--text) !important; font-size: .95rem !important; }
.radio input, .check input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-size: .92rem; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 9px; padding: .5rem .85rem; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #1b2948; border-color: #33456d; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #5eead4; }
.btn.big { width: 100%; padding: .9rem; font-size: 1.05rem; margin-top: 1.2rem; }
.btn.ghost { background: transparent; }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.icon { padding: .45rem .65rem; min-width: 2.4rem; }
.btn.danger-ghost { background: transparent; color: var(--over); border-color: #5a2a33; }
.btn.danger-ghost:hover { background: #2a1720; }
.btn.armed { background: var(--over) !important; color: #2a0b0b !important; border-color: var(--over) !important; }

/* ---------- Participant list ---------- */
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .45rem; counter-reset: p; }
.plist li {
  display: grid; grid-template-columns: auto 1.8rem 1fr auto auto; align-items: center; gap: .5rem;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: .4rem .5rem;
}
.plist li.empty { display: block; text-align: center; color: var(--muted); padding: 1.4rem; border-style: dashed; }
.plist li.dragging { opacity: .4; }
.plist li.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.plist li.drop-after { box-shadow: 0 3px 0 var(--accent); }
.plist .handle { cursor: grab; color: var(--muted); padding: 0 .25rem; user-select: none; font-size: 1.1rem; touch-action: none; }
.plist .num { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; font-size: .9rem; }
.plist input[type=text].name { width: 100%; background: transparent; border-color: transparent; }
.plist input[type=text].name:hover, .plist input[type=text].name:focus { border-color: var(--line); background: var(--card); }
.plist .row-btns { display: flex; gap: .2rem; }
.plist .row-btns .btn { padding: .3rem .5rem; font-size: .8rem; background: transparent; border-color: transparent; }
.plist .row-btns .btn:hover { border-color: var(--line); background: var(--card); }
.plist .row-btns .del:hover { color: var(--over); }
@media (max-width: 520px) {
  .plist li { grid-template-columns: auto 1fr auto; }
  .plist .num { display: none; }
  .plist .row-btns { grid-column: 1 / -1; justify-content: flex-end; }
}

.add-form { display: flex; gap: .5rem; margin-top: .9rem; }
.add-form #addName { flex: 1 1 10rem; }
@media (max-width: 520px) { .add-form { flex-wrap: wrap; } .add-form .btn { flex: 1; } }
.list-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; }

/* ---------- Sounds ---------- */
.sound-row { margin-bottom: .8rem; }
.sound-row > label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: .3rem; }
.sound-row small { opacity: .8; }
.sound-ctl { display: flex; gap: .4rem; }
.sound-ctl select { flex: 1; }
.custom-sounds { margin-top: .5rem; border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
.custom-sounds summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.custom-sounds ul { list-style: none; padding: 0; margin: .6rem 0 0; display: flex; flex-direction: column; gap: .35rem; }
.custom-sounds li { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.custom-sounds li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-sounds li.none { color: var(--muted); }

/* ---------- Run view ---------- */
.run-layout { display: grid; grid-template-columns: 1fr 300px; gap: 1rem; min-height: calc(100vh - 150px); }
@media (max-width: 920px) { .run-layout { grid-template-columns: minmax(0, 1fr); } }
.run-main {
  --state: var(--ok);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem 1rem;
  transition: background .4s;
}
.run-main.warn { --state: var(--warn); }
.run-main.over { --state: var(--over); background: #2a1620; }
.run-main.prep { --state: #60a5fa; }
.run-main.prep .run-time { opacity: .7; }
.prep-msg { color: #93c5fd; font-weight: 600; }
.field.sub { margin: .4rem 0 0 1.6rem; }
.field.sub > label:first-child { color: var(--muted); font-size: .88rem; }
.run-main.paused .run-time { opacity: .45; animation: blink 1.2s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.run-pos { color: var(--muted); font-size: 1rem; letter-spacing: .08em; text-transform: uppercase; }
.run-name { font-size: clamp(1.8rem, 5vw, 3.6rem); font-weight: 700; margin: .3rem 0 0; overflow-wrap: anywhere; }
.run-time {
  font-size: clamp(5rem, 19vw, 15rem); font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--state);
  margin: 1.2rem 0 1.4rem; transition: color .3s;
}
.run-bar { width: min(760px, 92%); height: 12px; background: var(--bg2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.run-bar > div { height: 100%; width: 0; background: var(--state); transition: width .2s linear, background .3s; }
.run-meta { display: flex; gap: 2rem; margin-top: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; flex-wrap: wrap; justify-content: center; }
.run-meta b { color: var(--text); font-weight: 600; margin-left: .3rem; }
.run-next { margin-top: 1rem; font-size: 1.1rem; color: var(--muted); min-height: 1.6em; }
.run-next b { color: var(--text); }
.controls { display: flex; gap: .6rem; margin-top: 1.6rem; flex-wrap: wrap; justify-content: center; }
.btn.ctl { font-size: 1.3rem; padding: .7rem 1.1rem; min-width: 3.6rem; }
.btn.ctl.main { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); min-width: 5.5rem; }
.btn.ctl.stop { font-size: 1rem; }
.kbd-hint { color: var(--muted); font-size: .8rem; margin-top: 1rem; }

.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.queue li {
  display: flex; justify-content: space-between; gap: .6rem; align-items: center;
  padding: .5rem .65rem; border-radius: 9px; cursor: pointer; border: 1px solid transparent;
}
.queue li:hover { background: var(--bg2); }
.queue li.current { background: var(--bg2); border-color: var(--accent); }
.queue li.done { color: var(--muted); }
.queue li .qn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue li .qt { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.queue li .qt.over { color: var(--over); }

/* Fullscreen: maximise the timer */
:fullscreen .topbar, :fullscreen .footer, :fullscreen .run-queue, :fullscreen .kbd-hint { display: none; }
:fullscreen main { max-width: none; padding: 0; }
:fullscreen .run-layout { grid-template-columns: 1fr; min-height: 100vh; }
:fullscreen .run-main { border-radius: 0; border: 0; }
:fullscreen .run-time { font-size: clamp(6rem, 26vw, 24rem); }

/* ---------- Summary ---------- */
.summary { max-width: 860px; margin: 0 auto; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
td:nth-child(n+3), th:nth-child(n+3) { text-align: right; }
tfoot td { font-weight: 700; border-bottom: 0; }
.pos { color: var(--over); }
.neg { color: var(--ok); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translate(-50%, 1rem);
  background: #1e2b48; border: 1px solid var(--line); color: var(--text);
  padding: .65rem 1rem; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: 90vw; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Legal page ---------- */
.legal { max-width: 820px; margin: 0 auto; }
.legal h1 { font-size: 1.6rem; margin: .4rem 0 1.2rem; }
.legal h2 { margin-top: 1.6rem; color: var(--accent); }
.legal p, .legal li { color: #cfd8ea; }
.legal dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; margin: 0; }
.legal dt { color: var(--muted); }
.legal dd { margin: 0; }
@media (max-width: 560px) { .legal dl { grid-template-columns: 1fr; } .legal dd { margin-bottom: .5rem; } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
