:root {
  color-scheme: dark;
  --bg: #0c0f14;
  --bg-2: #141922;
  --line: #2a313c;
  --text: #f1f3f6;
  --muted: #8a93a1;
  --faint: #4b5361;
  --alarm: #ff4b55;
  --wrong-bg: #a8121e;
  --ok: #2fd27a;
  --ok-bg: #0b5a33;
  --clock-font: "Bahnschrift", "DIN Alternate", "Segoe UI", system-ui, sans-serif;
  --ui-font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui-font);
}

body {
  background:
    radial-gradient(ellipse 70% 55% at 50% 42%, rgba(120, 140, 170, 0.10), transparent 70%),
    var(--bg);
}

body.idle, body.idle * { cursor: none !important; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------- Game screen ---------------- */
.game {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4vh 5vw;
  text-align: center;
}

.title {
  margin: 0 0 1.5vh;
  color: var(--muted);
  font-size: clamp(14px, 1.35vw, 22px);
  font-weight: 600;
  letter-spacing: 0.32em;
  text-indent: 0.32em; /* balance the trailing letter-spacing */
}

.clock {
  font-family: var(--clock-font);
  font-size: clamp(96px, 21vw, 380px);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--text);
  transition: color 300ms ease, opacity 300ms ease;
}

.bar {
  width: min(900px, 70vw);
  height: 4px;
  margin: 3vh auto 6vh;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  background: var(--text);
  transform-origin: left center;
  transition: transform 120ms linear, background-color 300ms ease;
}

.entry { display: flex; gap: 12px; justify-content: center; }

.entry input {
  width: min(460px, 60vw);
  height: 68px;
  padding: 0 20px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  outline: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.entry input::placeholder {
  color: var(--faint);
  letter-spacing: 0.04em;
  text-transform: none;
  font-weight: 400;
}
.entry input:focus { border-color: rgba(255, 255, 255, 0.55); box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.07); }

.entry button {
  height: 68px;
  min-width: 150px;
  padding: 0 28px;
  border: 0;
  border-radius: 10px;
  background: var(--text);
  color: #0c0f14;
  font-size: 20px;
  font-weight: 700;
}
.entry button:hover { filter: brightness(0.92); }
.entry button:focus-visible { outline: 3px solid rgba(255,255,255,.5); outline-offset: 3px; }
.entry input:disabled, .entry button:disabled { opacity: 0.4; cursor: default; }

.status {
  min-height: 1.6em;
  margin: 2.4vh 0 0;
  color: var(--muted);
  font-size: clamp(15px, 1.4vw, 22px);
}

/* States */
body[data-state="urgent"] .clock { color: var(--alarm); animation: pulse 1s ease-in-out infinite; }
body[data-state="urgent"] .bar span,
body[data-state="timeout"] .bar span { background: var(--alarm); }
body[data-state="timeout"] .clock { color: var(--alarm); }
body[data-state="timeout"] .status { color: var(--alarm); font-weight: 600; }
body[data-state="paused"] .clock { opacity: 0.4; }
body[data-state="paused"] .status { color: var(--text); letter-spacing: 0.2em; }

/* ---------------- Full-screen layers ---------------- */
.layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5vh 6vw;
  text-align: center;
}
.layer-inner { display: flex; flex-direction: column; align-items: center; }
.layer h2 {
  margin: 0;
  font-size: clamp(56px, 8.5vw, 150px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}
.layer p { margin: 2.5vh 0 0; font-size: clamp(20px, 2.4vw, 40px); opacity: 0.85; }

.mark {
  width: clamp(90px, 11vw, 170px);
  height: auto;
  margin-bottom: 4vh;
  fill: none;
  stroke: currentColor;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.layer-wrong { background: var(--wrong-bg); color: #fff; animation: flash 420ms ease-out; }
.layer-wrong .layer-inner { animation: shake 480ms ease; }

.layer-accepted { background: radial-gradient(ellipse at center, #11774a, var(--ok-bg) 70%); color: #fff; }
.layer-accepted .layer-inner { animation: pop 460ms cubic-bezier(.2,.9,.3,1.3) both; }
.layer-accepted p { font-family: var(--clock-font); font-variant-numeric: tabular-nums; }

.layer-count { background: #07090c; }
.count-label {
  margin: 0 0 4vh !important;
  color: var(--muted);
  font-size: clamp(18px, 2vw, 32px) !important;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
}
.count-num {
  font-family: var(--clock-font);
  font-size: min(36vw, 58vh);
  font-weight: 700;
  line-height: 0.9;
}
.count-num.tick { animation: countIn 900ms ease-out both; }

/* Ending stage: video fills the screen, messages sit on top */
.layer-stage {
  padding: 0;
  z-index: 11;
  background: radial-gradient(ellipse 80% 60% at 50% 45%, #1a2130, #090b10 75%);
}
.layer-stage.has-video { background: #000; }
.layer-stage video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}
.layer-stage:not(.has-video) video { display: none; }
.stage-dim {
  position: absolute; inset: 0;
  background: #000;
  opacity: 0;
  transition: opacity 900ms ease;
  pointer-events: none;
}
.layer-stage:not(.has-video) .stage-dim { display: none; }

.msg {
  position: absolute; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5vh 6vw;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 700ms ease, visibility 0s linear 700ms;
  pointer-events: none;
}
.msg.on { opacity: 1; visibility: visible; transition: opacity 700ms ease, visibility 0s; }
.layer-stage.has-video .msg h1,
.layer-stage.has-video .msg p { text-shadow: 0 2px 24px rgba(0, 0, 0, 0.75), 0 1px 3px rgba(0, 0, 0, 0.6); }

.msg-big h1 {
  margin: 0;
  max-width: 92vw;
  font-size: clamp(56px, 10vw, 200px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
  white-space: pre-line;
}
.msg-big.on h1 { animation: zoomIn 900ms cubic-bezier(.2,.8,.2,1) both; }

.play-btn {
  position: absolute;
  z-index: 3;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 22px 44px;
  border: 0;
  border-radius: 12px;
  background: #fff;
  color: #000;
  font-size: 26px;
  font-weight: 700;
}

.final-box {
  --k: 1;
  width: min(1400px, 88vw);
  height: 82vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.final-box h1 {
  margin: 0;
  font-size: calc(var(--k) * clamp(44px, 7.2vw, 132px));
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.015em;
}
.final-box p {
  margin: 0;
  max-width: 38em;
  color: #c9cfd8;
  font-size: calc(var(--k) * clamp(22px, 2.7vw, 48px));
  line-height: 1.4;
  white-space: pre-line;
}
.layer-stage.has-video .final-box p { color: #eef1f5; }
.final-box h1 + p { margin-top: calc(var(--k) * 4vh); }
.msg-final.reveal h1 { animation: rise 1100ms ease-out both; }
.msg-final.reveal p { animation: rise 1100ms 450ms ease-out both; }

.preview-badge {
  position: fixed;
  z-index: 40;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: #f5c542;
  color: #1a1400;
  font-size: 15px;
  font-weight: 700;
}

/* ---------------- Corner controls ---------------- */
.staff-hotspot { position: fixed; z-index: 30; top: 0; left: 0; width: 90px; height: 90px; }

.fs-btn {
  position: fixed;
  z-index: 30;
  right: 16px;
  bottom: 16px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0.35;
  transition: opacity 200ms ease;
}
.fs-btn:hover, .fs-btn:focus-visible { opacity: 1; }
.fs-btn svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; }
body.idle .fs-btn { opacity: 0; }

/* ---------------- Staff dialogs ---------------- */
dialog {
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-2);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(3, 5, 8, 0.72); }

.pin form { width: min(360px, 90vw); padding: 26px; }
.pin h2 { margin: 0 0 18px; font-size: 22px; }
.pin label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 14px; }
.pin input { width: 100%; font-size: 24px; letter-spacing: 0.3em; text-align: center; }
.pin-error { margin: 10px 0 0; color: var(--alarm); font-size: 14px; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.panel {
  width: min(760px, 94vw);
  max-height: 92vh;
  display: none;
  flex-direction: column;
}
.panel[open] { display: flex; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 20px; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); }
.icon-btn:hover { background: #222a35; color: var(--text); }

.panel-body { overflow-y: auto; padding: 4px 22px 16px; }
.group { padding: 16px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h3 { margin: 0 0 12px; font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; }

.panel label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.panel label.switch { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; }
.switch input { width: 18px; height: 18px; accent-color: #f1f3f6; }

.panel input[type="text"], .panel input[type="password"], .panel input[type="number"], .panel textarea, .pin input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1117;
  color: var(--text);
  font-size: 16px;
  outline: 0;
}
.panel textarea { resize: vertical; min-height: 90px; line-height: 1.45; }
.panel input:focus, .panel textarea:focus, .pin input:focus { border-color: #8a93a1; }

.fields.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.with-btn { display: flex; gap: 8px; align-items: stretch; margin-top: 6px; }
.with-btn input { margin-top: 0 !important; }

.hint { margin: 4px 0 10px; color: var(--faint); font-size: 13px; line-height: 1.45; }

.btn {
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #222a35;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #2b3441; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .chips button:focus-visible { outline: 2px solid #f1f3f6; outline-offset: 2px; }
.btn.primary { border-color: #f1f3f6; background: #f1f3f6; color: #0c0f14; }
.btn.primary:hover:not(:disabled) { background: #d9dde3; }
.btn.warn { border-color: rgba(255, 75, 85, 0.5); color: #ff8a90; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 8px; }
.chips button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}
.chips button:hover { color: var(--text); border-color: #4b5361; }
.chips button.on { background: #f1f3f6; border-color: #f1f3f6; color: #0c0f14; }

.round-status { margin: 0 0 12px; font-size: 16px; }
.round-status b { font-family: var(--clock-font); font-variant-numeric: tabular-nums; font-size: 20px; }

.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.checks li { display: grid; grid-template-columns: 22px 130px 1fr; align-items: baseline; font-size: 15px; }
.checks .ic { font-weight: 700; }
.checks .k { color: var(--muted); }
.checks .ok .ic { color: var(--ok); }
.checks .bad .ic, .checks .bad .v { color: var(--alarm); }
.checks .warn .ic, .checks .warn .v { color: #f5c542; }
.checks .off .ic { color: var(--faint); }

.panel-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
}
.foot-msg { flex: 1; font-size: 14px; color: var(--ok); text-align: right; }
.foot-msg.err { color: var(--alarm); }

/* Media + messages in panel */
.media-row { padding: 12px 14px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: #10151d; }
.media-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.media-head label.switch { margin: 0; font-weight: 600; }
.media-name { color: var(--muted); font-size: 13px; text-align: right; overflow-wrap: anywhere; }
.media-name.bad { color: var(--alarm); }
.media-row .btn-row { margin-bottom: 10px; }
.panel label.range { display: grid; grid-template-columns: 1fr minmax(120px, 2fr) 44px; align-items: center; gap: 12px; margin: 0; }
.range input { width: 100%; accent-color: #f1f3f6; }
.range output { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; font-size: 14px; }
.group > label.range { margin: 4px 0 14px; }
.msg-fields { display: grid; grid-template-columns: 1fr 110px; gap: 14px; }
.upload-progress { display: flex; align-items: center; gap: 12px; margin: 8px 0; font-size: 14px; color: var(--text); }
.up-bar { flex: 1; height: 8px; border-radius: 4px; background: #222a35; overflow: hidden; }
.up-bar span { display: block; height: 100%; width: 0; background: var(--ok); transition: width 150ms linear; }
.upload-progress.err { color: var(--alarm); }

/* ---------------- Motion ---------------- */
@keyframes zoomIn { from { transform: scale(0.82); opacity: 0; filter: blur(6px); } to { transform: none; opacity: 1; filter: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes flash { from { filter: brightness(1.8); } to { filter: brightness(1); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-24px); }
  40% { transform: translateX(20px); }
  60% { transform: translateX(-12px); }
  80% { transform: translateX(6px); }
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes countIn {
  0% { transform: scale(1.25); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: scale(0.92); opacity: 0.15; }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 720px) {
  .entry { flex-direction: column; width: 100%; align-items: center; }
  .entry input, .entry button { width: min(460px, 90vw); }
  .fields.two, .msg-fields { grid-template-columns: 1fr; }
  .panel label.range { grid-template-columns: 1fr 44px; }
  .panel label.range input { grid-column: 1 / -1; grid-row: 2; }
  .panel-foot { flex-wrap: wrap; }
  .checks li { grid-template-columns: 22px 110px 1fr; }
}
