:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --background: #070c12;
  --surface: #0d141e;
  --surface-soft: #111a26;
  --border: #3a4656;
  --border-muted: #273240;
  --text: #f5f2ea;
  --muted: #9ba6b6;
  --accent: #ffd83d;
  --accent-strong: #ffcf19;
  --ink: #17150d;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--background);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--text);
}

button {
  font: inherit;
}

.app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(22px, 2.6vh, 42px) clamp(28px, 3vw, 64px) clamp(16px, 2vh, 30px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(14px, 1.8vh, 24px);
  background:
    radial-gradient(circle at 50% 42%, rgb(25 34 47 / 34%), transparent 55%),
    var(--background);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.game-layout {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(340px, 1.22fr);
  gap: clamp(14px, 1.4vw, 24px);
}

.game-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(250px, 1.55fr) minmax(150px, 0.8fr) auto auto;
  gap: clamp(14px, 1.8vh, 24px);
}

.brand {
  position: relative;
  margin: 0;
  padding-bottom: 12px;
  font-size: clamp(30px, 3.1vw, 58px);
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.brand::after {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 96px;
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
}

.track-position {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: clamp(16px, 1.45vw, 26px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.player-card,
.clue-card {
  border: 2px solid var(--border);
  background: linear-gradient(145deg, rgb(17 26 38 / 95%), rgb(10 16 24 / 98%));
}

.player-card {
  min-height: 0;
  padding: clamp(20px, 2.5vh, 34px) clamp(24px, 2.4vw, 48px);
  border-radius: 22px;
  display: grid;
  grid-template-rows: auto minmax(58px, 1fr) auto;
  align-items: center;
}

.player-heading {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
}

.playback-status {
  justify-self: start;
  margin: 0;
  padding: 12px 22px;
  border: 2px solid var(--border);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--text);
  font-size: clamp(15px, 1.25vw, 23px);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-dot {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.is-playing .status-dot {
  background: var(--accent);
}

.is-playing .playback-status {
  border-color: #70632a;
}

.timer {
  justify-self: center;
  font-variant-numeric: tabular-nums;
  font-size: clamp(64px, 7.4vw, 134px);
  font-weight: 850;
  line-height: 0.88;
  letter-spacing: -0.035em;
}

.waveform {
  height: 100%;
  min-height: 64px;
  padding: 8px 2.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(3px, 0.29vw, 7px);
  overflow: hidden;
}

.waveform-bar {
  width: clamp(2px, 0.18vw, 4px);
  height: calc(var(--bar-size) * 1%);
  min-height: 4px;
  border-radius: 999px;
  background: #cbd1da;
  opacity: 0.74;
  transform: scaleY(0.72);
  transform-origin: center;
  transition: opacity 180ms ease, transform 180ms ease;
}

.is-playing .waveform-bar {
  opacity: 0.95;
  animation: pulse-wave 900ms ease-in-out infinite alternate;
  animation-delay: calc(var(--bar-index) * -17ms);
}

@keyframes pulse-wave {
  from { transform: scaleY(0.58); }
  to { transform: scaleY(1); }
}

.timeline {
  position: relative;
  height: 78px;
  margin: 0 2px;
}

.timeline-line {
  position: absolute;
  top: 4px;
  right: 0;
  left: 0;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #394454;
}

.timeline-progress {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 120ms linear;
}

.cue {
  --cue-position: 0%;
  position: absolute;
  top: -4px;
  left: var(--cue-position);
  width: 130px;
  display: grid;
  justify-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: clamp(13px, 1vw, 19px);
  line-height: 1.1;
  text-align: center;
  text-transform: uppercase;
  transform: translateX(-50%);
}

.cue strong {
  margin-top: 27px;
  color: inherit;
  font-size: 1.12em;
}

.cue-point {
  position: absolute;
  top: 0;
  width: 22px;
  height: 22px;
  border: 4px solid var(--muted);
  border-radius: 50%;
  background: var(--surface);
}

.cue.reached {
  color: var(--text);
}

.cue.reached .cue-point {
  border-color: var(--accent);
  background: var(--accent);
}

.clue-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(14px, 1.4vw, 24px);
}

.clue-card {
  min-width: 0;
  min-height: 0;
  padding: clamp(16px, 1.8vh, 26px) clamp(18px, 1.9vw, 34px);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: border-color 180ms ease, background 180ms ease;
}

.clue-card.revealed {
  border-color: #73662e;
  background: linear-gradient(145deg, rgb(31 30 23 / 95%), rgb(12 17 23 / 98%));
}

.card-label {
  width: 100%;
  margin: 0 0 clamp(10px, 1.3vh, 18px);
  padding-bottom: clamp(8px, 1vh, 14px);
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-size: clamp(15px, 1.25vw, 23px);
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.card-value,
.answer-title {
  margin: 0;
  font-size: clamp(25px, 2.55vw, 47px);
  font-weight: 850;
  line-height: 1.05;
  text-transform: uppercase;
}

.card-value.masked {
  color: #6f7a8a;
}

.answer-card {
  position: relative;
}

.answer-lock {
  position: relative;
  width: 26px;
  height: 22px;
  margin-bottom: 14px;
  border: 4px solid var(--muted);
  border-top: 0;
  border-radius: 4px;
}

.answer-lock::before {
  position: absolute;
  top: -15px;
  left: 50%;
  width: 18px;
  height: 17px;
  margin: 0;
  border: 4px solid var(--muted);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  content: "";
  transform: translateX(-50%);
}

.answer-card .card-label {
  margin: 0;
  border: 0;
  font-size: clamp(19px, 1.8vw, 34px);
}

.answer-card.revealed .card-label,
.answer-card.revealed .answer-lock {
  display: none;
}

.answer-title {
  color: var(--accent);
}

.answer-artist {
  margin: 12px 0 0;
  color: var(--text);
  font-size: clamp(16px, 1.35vw, 25px);
  font-weight: 700;
}

.controls {
  display: grid;
  grid-template-columns: 0.95fr 1.75fr 1.05fr;
  gap: clamp(14px, 1.4vw, 24px);
}

.button {
  min-height: clamp(70px, 8.4vh, 100px);
  padding: 16px clamp(18px, 2vw, 34px);
  border: 2px solid var(--border);
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: clamp(18px, 1.65vw, 31px);
  font-weight: 850;
  line-height: 1.05;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 130ms ease, border-color 130ms ease, background 130ms ease, opacity 130ms ease;
}

.button:hover:not(:disabled) {
  border-color: #8792a2;
  transform: translateY(-2px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:focus-visible {
  outline: 4px solid rgb(255 216 61 / 42%);
  outline-offset: 4px;
}

.button-primary {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent);
}

.button-primary:hover:not(:disabled) {
  border-color: #ffe67e;
  background: #ffe16a;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.button-icon {
  flex: 0 0 auto;
  font-size: 1.25em;
}

.helper {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: clamp(14px, 1.25vw, 23px);
  text-align: center;
}

.scoreboard {
  min-width: 0;
  min-height: 0;
  padding: clamp(18px, 2vh, 28px) clamp(14px, 1.25vw, 24px);
  border: 2px solid var(--border);
  border-radius: 22px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(14px, 1.6vh, 22px);
  background: linear-gradient(145deg, rgb(17 26 38 / 95%), rgb(10 16 24 / 98%));
}

.scoreboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.scoreboard-header h2 {
  margin: 0;
  font-size: clamp(25px, 2.1vw, 40px);
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.team-count {
  padding: 6px 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: clamp(13px, 1vw, 18px);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.team-count:hover,
.team-count:focus-visible {
  color: var(--accent);
}

.score-list {
  min-height: 0;
  margin: 0;
  padding: 0 4px 0 0;
  display: grid;
  grid-auto-rows: minmax(58px, 1fr);
  gap: clamp(8px, 1vh, 14px);
  overflow-y: auto;
  list-style: none;
  scrollbar-color: var(--border) transparent;
}

.score-row {
  position: relative;
  min-width: 0;
  padding: 10px 10px 10px 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 44px 40px 40px;
  align-items: center;
  gap: clamp(6px, 0.55vw, 11px);
  background: rgb(17 26 38 / 78%);
}

.score-row.leader {
  border-color: #73662e;
  background: linear-gradient(90deg, rgb(63 57 27 / 55%), rgb(17 26 38 / 82%) 68%);
}

.score-row.leader::before {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: -2px;
  width: 5px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
}

.score-rank {
  color: var(--muted);
  font-size: clamp(17px, 1.3vw, 25px);
  font-weight: 850;
  text-align: center;
}

.leader .score-rank {
  color: var(--accent);
}

.score-team-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: clamp(14px, 1.12vw, 21px);
  font-weight: 800;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.score-value {
  font-size: clamp(24px, 2vw, 38px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
}

.score-adjust-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid #566274;
  border-radius: 8px;
  color: var(--text);
  background: #1a2431;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.score-adjust-button:hover:not(:disabled),
.score-adjust-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.score-adjust-button:disabled {
  cursor: not-allowed;
  opacity: 0.3;
}

.score-list-empty {
  min-height: 160px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.scoreboard-footer {
  display: grid;
  gap: 12px;
}

.undo-score-button {
  min-height: 58px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: clamp(13px, 1vw, 18px);
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.undo-score-button:hover:not(:disabled),
.undo-score-button:focus-visible {
  border-color: #8792a2;
}

.undo-score-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.scoreboard-footer p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(11px, 0.82vw, 16px);
  text-align: center;
}

.modal {
  width: min(760px, calc(100vw - 36px));
  max-height: min(900px, calc(100dvh - 36px));
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  background: #0c131d;
  box-shadow: 0 30px 90px rgb(0 0 0 / 65%);
}

.modal::backdrop {
  background: rgb(2 6 10 / 78%);
  backdrop-filter: blur(5px);
}

.modal-content {
  max-height: min(900px, calc(100dvh - 40px));
  padding: clamp(22px, 2.5vw, 38px);
  display: grid;
  gap: 20px;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.modal-header h2 {
  margin: 2px 0 0;
  font-size: clamp(30px, 3vw, 48px);
  line-height: 1;
}

.modal-eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.modal-copy {
  margin: 0;
  color: var(--muted);
  font-size: clamp(15px, 1.3vw, 20px);
  line-height: 1.45;
}

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

.team-input-list {
  display: grid;
  gap: 10px;
}

.team-input-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 66px 42px;
  align-items: center;
  gap: 10px;
}

.team-input-number {
  color: var(--muted);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.team-name-input {
  width: 100%;
  min-width: 0;
  height: 50px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  outline: 0;
  background: #101a26;
  font-size: 17px;
  font-weight: 700;
}

.team-name-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(255 216 61 / 14%);
}

.team-current-score {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}

.remove-team-button {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: #f2b2b2;
  background: #26191c;
  font-size: 24px;
  cursor: pointer;
}

.remove-team-button:disabled {
  cursor: not-allowed;
  opacity: 0.25;
}

.form-error {
  margin: -8px 0 0;
  padding: 12px 14px;
  border: 1px solid #784b4b;
  border-radius: 9px;
  color: #ffb8b8;
  background: #321b1d;
  font-weight: 700;
}

.team-form-actions,
.modal-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.modal-footer {
  padding-top: 18px;
  border-top: 1px solid var(--border-muted);
}

.modal-footer-stacked {
  display: grid;
  grid-template-columns: 1fr;
}

.modal-button {
  min-height: 50px;
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.modal-button-primary {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent);
}

.modal-button-danger {
  color: #f2b2b2;
}

.modal-button-danger-solid {
  border-color: #ba4e55;
  color: #fff4f4;
  background: #8f3138;
}

.modal-button-quiet {
  border-color: transparent;
  color: var(--muted);
  background: transparent;
}

.modal-button:hover:not(:disabled),
.icon-button:hover,
.remove-team-button:hover:not(:disabled) {
  border-color: var(--accent);
}

.modal-button:focus-visible,
.icon-button:focus-visible,
.remove-team-button:focus-visible,
.team-count:focus-visible,
.score-adjust-button:focus-visible,
.undo-score-button:focus-visible {
  outline: 3px solid rgb(255 216 61 / 38%);
  outline-offset: 3px;
}

.modal-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.winner-team-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.winner-team-button {
  min-width: 0;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto 26px;
  align-items: center;
  gap: 10px;
  color: var(--text);
  background: var(--surface-soft);
  text-align: left;
  cursor: pointer;
}

.winner-team-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgb(255 216 61 / 12%);
}

.winner-check {
  width: 30px;
  height: 30px;
  border: 2px solid var(--border);
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: transparent;
  font-weight: 900;
}

.winner-team-button[aria-pressed="true"] .winner-check {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent);
}

.winner-team-button strong {
  min-width: 0;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.winner-team-button > span:nth-of-type(2) {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.winner-team-button kbd {
  color: #778395;
  font: 700 12px/1 ui-monospace, monospace;
}

.toast {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 20;
  max-width: min(480px, calc(100vw - 56px));
  margin: 0;
  padding: 16px 20px;
  border: 1px solid #784b4b;
  border-radius: 12px;
  color: #ffe8e8;
  background: #321b1d;
  font-weight: 700;
  box-shadow: 0 18px 50px rgb(0 0 0 / 40%);
}

.toast[data-tone="success"] {
  border-color: #6d622f;
  color: #fff3bd;
  background: #2b2818;
}

@media (max-height: 820px) and (min-width: 1101px) {
  .app {
    padding-top: 16px;
    padding-bottom: 12px;
    gap: 10px;
  }

  .game-column {
    grid-template-rows: minmax(205px, 1.4fr) minmax(125px, 0.78fr) auto auto;
    gap: 9px;
  }

  .player-card {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .button {
    min-height: 62px;
  }

  .scoreboard {
    padding-top: 14px;
    padding-bottom: 12px;
    gap: 9px;
  }

  .score-list {
    grid-auto-rows: minmax(48px, 1fr);
    gap: 6px;
  }

  .score-row {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .undo-score-button {
    min-height: 46px;
  }
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    grid-template-rows: auto auto;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .scoreboard {
    min-height: 560px;
  }
}

@media (max-width: 900px) {
  .app {
    min-height: 100dvh;
    padding: 22px 18px 28px;
    grid-template-rows: auto auto;
  }

  .topbar,
  .player-heading {
    gap: 18px;
  }

  .track-position {
    gap: 8px;
    font-size: 13px;
  }

  .player-heading {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .playback-status,
  .timer {
    justify-self: center;
  }

  .heading-spacer {
    display: none;
  }

  .waveform {
    height: 100px;
  }

  .clue-grid,
  .controls {
    grid-template-columns: 1fr;
  }

  .clue-card {
    min-height: 170px;
  }

  .button {
    min-height: 72px;
  }

  .scoreboard {
    min-height: 620px;
  }

  .winner-team-list {
    grid-template-columns: 1fr;
  }

  .team-form-actions,
  .modal-footer {
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .team-input-row {
    grid-template-columns: 24px minmax(0, 1fr) 38px;
  }

  .team-current-score {
    display: none;
  }

  .score-row {
    grid-template-columns: 25px minmax(0, 1fr) 38px 38px 38px;
    padding-left: 8px;
  }

  .score-adjust-button {
    width: 38px;
    height: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
