:root {
  color-scheme: dark;
  --bg: #171514;
  --surface: #24201e;
  --surface-2: #302925;
  --surface-3: #3b322d;
  --line: #574b43;
  --text: #fff9f2;
  --muted: #cbbfb3;
  --dim: #94877c;
  --red: #e7504f;
  --red-dark: #a92d2d;
  --teal: #31c7b7;
  --teal-dark: #137f77;
  --amber: #ffc85a;
  --ink: #161311;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.35);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(231, 80, 79, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(49, 199, 183, 0.13), transparent 30%),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.45);
  opacity: 0.52;
}

svg {
  display: block;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  margin-bottom: 18px;
}

body[data-screen="game"] .app-shell {
  padding-top: 14px;
}

body[data-screen="game"] .topbar {
  min-height: 52px;
  margin-bottom: 10px;
}

body[data-screen="game"] .brand {
  gap: 10px;
}

body[data-screen="game"] .brand-mark {
  width: 42px;
  height: 42px;
  box-shadow: none;
}

body[data-screen="game"] .brand-mark svg {
  width: 28px;
  height: 28px;
}

body[data-screen="game"] .brand .eyebrow {
  display: none;
}

body[data-screen="game"] .brand h1 {
  font-size: clamp(24px, 3vw, 34px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  background: var(--red);
  box-shadow: var(--shadow);
}

.brand-mark svg {
  width: 35px;
  height: 35px;
  fill: none;
  stroke: var(--text);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 5vw, 54px);
  line-height: 0.95;
}

h2 {
  font-size: clamp(21px, 3vw, 30px);
  line-height: 1.05;
}

h3 {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
}

.eyebrow {
  color: var(--amber);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.age-chip,
.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.age-chip {
  border-color: rgba(231, 80, 79, 0.42);
  color: #ffd8d8;
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

.setup-grid,
.game-grid {
  display: grid;
  gap: 18px;
}

.home-layout {
  display: grid;
  min-height: min(620px, calc(100vh - 140px));
  align-items: center;
}

.home-panel {
  width: min(780px, 100%);
  margin: 0 auto;
}

.game-library {
  display: grid;
  gap: 12px;
}

.game-tile {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 96px;
  border: 1px solid rgba(231, 80, 79, 0.46);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(231, 80, 79, 0.18), transparent 46%),
    var(--ink);
  color: var(--text);
  padding: 16px;
  text-align: left;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.game-tile:hover {
  border-color: rgba(255, 200, 90, 0.78);
  transform: translateY(-1px);
}

.game-tile strong {
  display: block;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1;
}

.game-tile small {
  display: block;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  margin-top: 6px;
}

.game-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: var(--radius);
  background: var(--red);
}

.game-icon svg {
  width: 31px;
  height: 31px;
  fill: none;
  stroke: var(--text);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.setup-grid {
  grid-template-columns: minmax(0, 1.3fr) minmax(310px, 0.7fr);
  align-items: start;
}

.game-grid {
  grid-template-columns: minmax(240px, 0.72fr) minmax(420px, 1.58fr) minmax(260px, 0.82fr);
  align-items: stretch;
}

.panel,
.play-panel {
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius);
  background: rgba(36, 32, 30, 0.93);
  box-shadow: var(--shadow);
}

.panel {
  padding: 20px;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.toggle-row strong {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--text);
  outline: none;
}

.field input[readonly] {
  color: var(--amber);
  cursor: default;
}

.field input {
  height: 46px;
  padding: 0 13px;
}

.field textarea {
  min-height: 96px;
  padding: 12px 13px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(49, 199, 183, 0.18);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
}

.toggle-row p {
  color: var(--dim);
  font-size: 13px;
  margin-top: 3px;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 54px;
  height: 30px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 100%;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background 160ms ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--text);
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: var(--teal-dark);
}

.switch input:checked + span::after {
  transform: translateX(24px);
}

.word-packs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.pack-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--muted);
  font-weight: 900;
  overflow: hidden;
}

.pack-card input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.pack-card:has(input:checked) {
  border-color: rgba(231, 80, 79, 0.75);
  background: rgba(231, 80, 79, 0.16);
  color: var(--text);
}

.participants {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.player-field {
  position: relative;
}

.player-field input {
  padding-left: 44px;
  padding-right: 46px;
}

.player-index {
  position: absolute;
  top: 50%;
  left: 10px;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--amber);
  font-size: 12px;
  font-weight: 900;
  transform: translateY(-50%);
}

.remove-player {
  position: absolute;
  top: 50%;
  right: 8px;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1px solid rgba(231, 80, 79, 0.42);
  border-radius: var(--radius);
  background: rgba(231, 80, 79, 0.12);
  color: #ffd8d8;
  transform: translateY(-50%);
}

.remove-player:disabled {
  opacity: 0.4;
}

.remove-player svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.6;
}

.add-player-button {
  width: 100%;
  margin: 0 0 16px;
}

.custom-words {
  margin-bottom: 16px;
}

.primary-button,
.ghost-button,
.success-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
  border-radius: var(--radius);
  font-weight: 900;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.primary-button:hover:not(:disabled),
.ghost-button:hover:not(:disabled),
.success-button:hover:not(:disabled),
.danger-button:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.primary-button svg,
.ghost-button svg,
.success-button svg,
.danger-button svg,
.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
}

.primary-button {
  width: 100%;
  background: var(--red);
  color: var(--text);
}

.ghost-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.success-button,
.danger-button {
  min-height: 68px;
  padding: 0 18px;
  font-size: clamp(17px, 2.5vw, 24px);
  color: var(--text);
}

.success-button {
  background: var(--teal-dark);
}

.danger-button {
  background: var(--red-dark);
}

.icon-button {
  width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.player-preview {
  display: grid;
  gap: 12px;
}

.player-card,
.score-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045);
  padding: 14px;
}

.player-card strong,
.score-card strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.score-card strong {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.player-card p {
  color: var(--dim);
  font-size: 13px;
  font-weight: 800;
  margin: 0;
}

.roster span,
.word-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.scoreboard {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 4px;
  margin-bottom: 12px;
}

.score-card {
  flex: 0 0 clamp(132px, 13vw, 180px);
  min-height: 66px;
  padding: 11px 12px;
}

.score-card.is-active {
  border-color: rgba(255, 200, 90, 0.7);
  box-shadow: inset 0 0 0 1px rgba(255, 200, 90, 0.2);
}

.score-card .score {
  color: var(--amber);
  font-size: 28px;
  font-weight: 950;
  line-height: 1;
}

.roster {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 38px;
  margin-bottom: 18px;
}

.timer-progress {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--teal);
  transition:
    width 250ms linear,
    background 160ms ease;
}

.timer-progress.is-warning {
  background: var(--amber);
}

.timer-progress.is-danger {
  background: var(--red);
}

.turn-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.turn-stats div {
  display: grid;
  place-items: center;
  min-height: 76px;
  border-radius: var(--radius);
  background: var(--ink);
}

.turn-stats span {
  font-size: 32px;
  font-weight: 950;
}

.turn-stats small {
  color: var(--dim);
  font-weight: 900;
}

.vertical-actions,
.round-controls {
  display: grid;
  gap: 10px;
}

.play-panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(240px, 1fr) auto auto;
  min-height: 560px;
  padding: 18px;
}

.play-lead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: var(--ink);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.play-lead > div {
  min-width: 0;
}

.play-lead span,
.play-lead em {
  color: var(--dim);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
  text-transform: uppercase;
}

.play-lead strong {
  display: block;
  color: var(--text);
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1;
  overflow-wrap: anywhere;
}

.play-status {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.play-metric {
  display: grid;
  gap: 4px;
  min-height: 70px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: var(--ink);
  padding: 11px 12px;
}

.play-metric span {
  color: var(--dim);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.play-metric strong {
  color: var(--text);
  font-size: clamp(20px, 3vw, 32px);
  line-height: 1;
  overflow-wrap: anywhere;
}

.main-timer {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(49, 199, 183, 0.35);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(49, 199, 183, 0.1), transparent 48%),
    var(--ink);
  padding: 16px;
  margin-bottom: 12px;
}

.main-timer > div:first-child {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.main-timer span {
  color: var(--dim);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.main-timer strong {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  color: var(--teal);
  font-size: clamp(54px, 8vw, 98px);
  line-height: 0.82;
}

.main-timer small {
  color: var(--muted);
  font-size: clamp(15px, 2vw, 22px);
  font-weight: 900;
}

.timer-line {
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-3);
}

.main-timer {
  border-color: rgba(49, 199, 183, 0.35);
}

.main-timer strong {
  color: var(--teal);
}

.main-timer.is-warning {
  border-color: rgba(255, 200, 90, 0.8);
  background: rgba(255, 200, 90, 0.12);
}

.main-timer.is-warning strong {
  color: var(--amber);
}

.main-timer.is-danger {
  border-color: rgba(231, 80, 79, 0.86);
  background: rgba(231, 80, 79, 0.16);
  animation: pulseTime 700ms ease-in-out infinite alternate;
}

.main-timer.is-danger strong {
  color: #ffd8d8;
}

.time-banner {
  min-height: 44px;
  border: 1px solid rgba(231, 80, 79, 0.72);
  border-radius: var(--radius);
  background: rgba(231, 80, 79, 0.16);
  color: #ffd8d8;
  display: grid;
  place-items: center;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 950;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.word-card {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  min-height: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 200, 90, 0.1), transparent 36%),
    linear-gradient(315deg, rgba(231, 80, 79, 0.18), transparent 35%),
    var(--surface-2);
  text-align: center;
}

.word-card.is-warning {
  border-color: rgba(255, 200, 90, 0.64);
  box-shadow: inset 0 0 0 1px rgba(255, 200, 90, 0.14);
}

.word-card.is-ended {
  border-color: rgba(231, 80, 79, 0.9);
  background:
    linear-gradient(135deg, rgba(231, 80, 79, 0.25), transparent 42%),
    var(--surface-2);
}

.word-card span {
  color: var(--amber);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.word-card strong {
  max-width: 92%;
  overflow-wrap: anywhere;
  font-size: clamp(40px, 7vw, 86px);
  line-height: 0.98;
}

.word-card small {
  max-width: 92%;
  color: var(--text);
  font-size: clamp(24px, 4vw, 44px);
  font-weight: 950;
  overflow-wrap: anywhere;
}

.round-controls,
.answer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.round-controls {
  margin-top: 14px;
}

.answer-actions {
  margin-top: 10px;
}

.log-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.log-columns ol {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 280px;
  max-height: 420px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.log-columns li {
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--muted);
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.round-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
  color: var(--text);
}

.round-dialog::backdrop {
  background: rgba(0, 0, 0, 0.64);
}

.dialog-card {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.dialog-card p {
  color: var(--muted);
  line-height: 1.5;
}

.pin-dialog {
  width: min(430px, calc(100vw - 28px));
}

.pin-field {
  margin-top: 4px;
}

.pin-field input {
  font-size: 28px;
  font-weight: 950;
  letter-spacing: 0;
  text-align: center;
}

.pin-error {
  min-height: 24px;
  color: #ffd8d8;
  font-size: 13px;
  font-weight: 800;
  margin-top: 8px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

@keyframes pulseTime {
  from {
    transform: translateY(0);
  }

  to {
    transform: translateY(-2px);
  }
}

@media (max-width: 1080px) {
  .setup-grid,
  .game-grid {
    grid-template-columns: 1fr;
  }

  .game-grid {
    align-items: start;
  }

  .turn-panel {
    display: block;
    order: 2;
  }

  .play-panel {
    order: 1;
  }

  .log-panel {
    order: 3;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  body[data-screen="game"] .topbar {
    align-items: center;
  }

  body[data-screen="game"] .top-actions {
    flex-direction: row;
    align-items: center;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .top-actions {
    flex-direction: column;
    align-items: end;
  }

  body[data-screen="game"] .top-actions {
    flex-direction: row;
    align-items: center;
  }

  .control-grid,
  .participants,
  .word-packs,
  .game-tile,
  .answer-actions,
  .log-columns,
  .dialog-actions {
    grid-template-columns: 1fr;
  }

  .home-layout {
    align-items: start;
    min-height: auto;
  }

  .game-tile {
    text-align: center;
  }

  .game-tile .age-chip,
  .game-icon {
    justify-self: center;
  }

  .panel {
    padding: 16px;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-card .panel-heading {
    align-items: flex-start;
    flex-direction: row;
  }

  .panel-heading .ghost-button,
  .panel-heading .count-pill {
    align-self: flex-start;
  }

  .turn-panel {
    display: block;
  }

  .score-card {
    flex-basis: min(42vw, 156px);
  }

  .play-panel {
    grid-template-rows: auto auto auto auto minmax(220px, 1fr) auto auto;
    min-height: 540px;
    padding: 12px;
  }

  .play-status {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .play-metric {
    min-height: 60px;
    padding: 9px;
  }

  .play-metric span {
    font-size: 10px;
  }

  .play-metric strong {
    font-size: 18px;
  }

  .main-timer {
    padding: 12px;
  }

  .play-lead {
    align-items: center;
    padding: 12px;
  }

  .play-lead strong {
    font-size: 28px;
  }

  .play-lead em {
    max-width: 45%;
    text-align: right;
  }

  .success-button,
  .danger-button {
    min-height: 58px;
  }
}
