:root {
  --red: #b01a1a;
  --red-deep: #6e1014;
  --red-hot: #e31b1b;
  --ink: #120c0a;
  --ink-2: #1c1210;
  --paper: #fff6ea;
  --muted: #c9b8a4;
  --gold: #e8c36a;
  --amber: #f5b942;
  --neon: #ffb703;
  --line: rgba(255, 246, 234, 0.14);
  --card: rgba(28, 16, 14, 0.92);
  --ok: #9be7a3;
  --bad: #ff8d8d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
  font-family: Outfit, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 420px at 8% -12%, rgba(176, 26, 26, 0.42), transparent 55%),
    radial-gradient(640px 380px at 100% 0%, rgba(232, 195, 106, 0.16), transparent 42%),
    radial-gradient(700px 500px at 50% 110%, rgba(245, 185, 66, 0.08), transparent 50%),
    var(--ink);
  color: var(--paper);
}

body { min-height: 100dvh; }

img { max-width: 100%; height: auto; }

button, input { font: inherit; color: inherit; }

a { color: var(--gold); }
a:hover { color: white; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

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

/* Decorative piano keys along the top */
body > .keys {
  height: 18px;
  background:
    repeating-linear-gradient(
      90deg,
      #f6efe4 0 18px,
      #16110f 18px 20px
    );
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.35), 0 8px 18px rgba(0, 0, 0, 0.25);
  position: relative;
}
body > .keys::after {
  content: "";
  position: absolute;
  inset: 0 auto auto 10px;
  height: 11px;
  width: calc(100% - 20px);
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0 12px,
      #111 12px 20px,
      transparent 20px 32px
    );
  pointer-events: none;
}

#app, .page {
  width: min(1080px, calc(100% - 20px));
  margin: 0 auto;
  padding: 16px 0 28px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  flex: none;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--muted);
}

h1, h2, .neon-tag {
  font-family: Oswald, "Impact", sans-serif;
  letter-spacing: 0.02em;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.55rem, 2.6vw, 2.15rem);
  line-height: 1;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.listen, .ghost, .primary, .danger, .share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
}

.listen {
  background: white;
  color: var(--red-deep);
}
.listen:hover { color: var(--red); }

.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--paper);
}
.ghost[disabled] { opacity: 0.45; cursor: default; }

.primary {
  background: linear-gradient(180deg, var(--red-hot), var(--red));
  color: white;
  border-color: #ff8a8a;
  box-shadow: 0 8px 20px rgba(176, 26, 26, 0.35);
}
.primary:hover { filter: brightness(1.08); }

.danger {
  background: transparent;
  border-color: #ff8d8d;
  color: #ffd0d0;
}

.prize {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(176, 26, 26, 0.95), rgba(80, 18, 12, 0.92));
  border: 1px solid rgba(232, 195, 106, 0.28);
  font-weight: 700;
}

.toast {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(232, 195, 106, 0.16);
  border: 1px solid rgba(232, 195, 106, 0.35);
}

#layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(250px, 330px);
  gap: 16px;
  align-items: start;
}

#stage-wrap { min-width: 0; }

#stage {
  position: relative;
  width: 100%;
  min-height: min(72dvh, 640px);
  background:
    radial-gradient(400px 220px at 50% 0%, rgba(232, 195, 106, 0.12), transparent 70%),
    var(--ink-2);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(232, 195, 106, 0.18);
}

.overlay, .playfield {
  position: absolute;
  inset: 0;
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.overlay {
  justify-content: center;
  text-align: center;
  background: rgba(16, 8, 6, 0.55);
  backdrop-filter: blur(8px);
}

.overlay[hidden], .playfield[hidden] { display: none; }

#overlay-over {
  justify-content: flex-start;
  text-align: left;
  overflow: auto;
}

#stage.ended {
  min-height: auto;
  height: auto;
}
#stage.ended #overlay-over {
  position: relative;
  inset: auto;
  background: transparent;
  backdrop-filter: none;
  padding: 18px 18px 22px;
}

.overlay h2, .playfield h2 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  text-transform: uppercase;
  line-height: 1.05;
}

.neon-tag {
  margin: 0 0 8px;
  color: var(--gold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.82rem;
  text-shadow: 0 0 16px rgba(232, 195, 106, 0.55);
}

.lede, .hint, .fine, .reason, .reset, .keys-help {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.overlay .primary, .overlay .danger, .overlay .ghost {
  width: 100%;
  margin-top: 6px;
}

.share-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 12px;
}
.share-row .ghost { width: 100%; margin-top: 0; }

.best, .nudge {
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.nudge {
  color: var(--gold);
  font-size: 1.05rem;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.hud-timer, .hud-score, .hud-streak {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  text-align: center;
}

.timer-label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.timer-value {
  font-family: Oswald, sans-serif;
  font-size: 1.8rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

#hud-timer.urgent .timer-value {
  color: #ffb4b4;
  animation: pulse 0.7s ease-in-out infinite;
}

@keyframes pulse {
  50% { transform: scale(1.06); text-shadow: 0 0 12px rgba(255, 80, 80, 0.6); }
}

.q-type {
  margin: 0 0 6px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--gold);
}

.q-prompt {
  font-size: clamp(1.15rem, 3.2vw, 1.7rem) !important;
  text-transform: none !important;
  font-family: Outfit, sans-serif;
  font-weight: 600;
  margin: 0 0 16px !important;
  line-height: 1.25;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  flex: 1 1 auto;
  align-content: start;
}

.choices button {
  min-height: 64px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(232, 195, 106, 0.28);
  background: rgba(255, 246, 234, 0.06);
  text-align: left;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.25;
}

.choices button:hover:not([disabled]) {
  border-color: var(--gold);
  background: rgba(232, 195, 106, 0.14);
}

.choices button.correct {
  background: rgba(80, 160, 100, 0.35);
  border-color: var(--ok);
}

.choices button.wrong {
  background: rgba(176, 26, 26, 0.38);
  border-color: var(--bad);
}

.choices button[disabled] { cursor: default; }

.feedback {
  margin: 12px 0 0;
  min-height: 1.4em;
  font-weight: 700;
}
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

form label, .login label {
  display: block;
  margin: 10px 0 4px;
  font-weight: 600;
}

input[type="text"], input[type="email"], input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-weight: 500;
  margin: 12px 0;
}
.check input { margin-top: 4px; }

.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

aside .panel, .panel, .winner, .prose {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.panel h2, .winner h2, .prose h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  text-transform: uppercase;
}

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button {
  flex: 1;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}
.tabs button.on {
  background: var(--red);
  border-color: #ff8a8a;
}

#board {
  margin: 0;
  padding: 0;
  list-style: none;
}
#board li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
#board li span:first-child { opacity: 0.8; }

.how ul { margin: 0 0 10px; padding-left: 1.1em; }
.how li { margin: 0 0 6px; }

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.88rem;
}

.draft {
  display: inline-block;
  margin: 0 0 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--red);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.prose p, .prose li { color: var(--paper); line-height: 1.5; }

.flash {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(232, 195, 106, 0.16);
  border: 1px solid rgba(232, 195, 106, 0.4);
  font-weight: 600;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.admin-table th, .admin-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-actions button, .lookup-form button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}

.prize-code {
  font-family: Oswald, sans-serif;
  font-size: 1.4rem;
  letter-spacing: 0.12em;
  color: var(--gold);
}

.lookup-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}
.lookup-form input { width: 8rem; }

.mail-preview {
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
  font-size: 0.85rem;
}

.login { max-width: 420px; }

@media (max-width: 840px) {
  #layout { grid-template-columns: 1fr; }
  header { flex-direction: column; align-items: flex-start; }
  .choices { grid-template-columns: 1fr; }
  .choices button { min-height: 54px; }
  #stage { min-height: auto; }
  .playfield, .overlay { position: relative; inset: auto; }
  #overlay-title, #overlay-over { min-height: 520px; }
  .share-row { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .brand img { width: 52px; height: 52px; }
  .listen { width: 100%; }
}
