:root {
  --board-blue: #0a0a8c;
  --board-blue-dark: #050548;
  --board-edge: #000033;
  --gold: #ffcc33;
  --white: #f5f5ff;
  --good: #4ade80;
  --bad: #f8714a;
  --host-box: #0d1b4c;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--board-edge);
  color: var(--white);
  font-family: 'Press Start 2P', 'Courier New', monospace;
  overflow-x: hidden;
}

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

button {
  font-family: inherit;
  cursor: pointer;
}

.screen {
  display: none;
  min-height: 100vh;
  width: 100%;
}
.screen.active { display: flex; flex-direction: column; }
.screen.overlay.active {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0,0,10,0.85);
  padding: 16px;
  overflow-y: auto;
}
.screen.overlay.active > * { margin: auto; }

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

/* ---------------- Shared widgets ---------------- */

.nes-btn {
  background: var(--gold);
  color: var(--board-edge);
  border: 3px solid #000;
  border-radius: 4px;
  padding: 12px 18px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: bold;
  box-shadow: 3px 3px 0 #000;
  transition: transform 0.08s;
}
.nes-btn:hover { transform: translate(1px, 1px); box-shadow: 2px 2px 0 #000; }
.nes-btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 #000; }
.nes-btn.big { display: block; width: 100%; padding: 16px; font-size: 0.85rem; margin-top: 10px; }
.nes-btn.secondary { background: #3a4a8c; color: var(--white); }
.nes-btn.danger { background: var(--bad); color: #2b0a00; }
.nes-btn.good { background: var(--good); color: #042410; }
.nes-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pixel-input {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 10px;
  border: 3px solid #000;
  border-radius: 4px;
  background: #fff;
  color: #000;
  width: 100%;
}

/* ---------------- Title screen ---------------- */

#screen-title.active {
  position: relative;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #10109a 0%, var(--board-edge) 80%);
  padding: 24px;
  overflow: hidden;
}

.starfield {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 10% 20%, #fff, transparent),
    radial-gradient(2px 2px at 80% 10%, #fff, transparent),
    radial-gradient(1px 1px at 30% 60%, #fff, transparent),
    radial-gradient(1px 1px at 60% 80%, #fff, transparent),
    radial-gradient(2px 2px at 90% 70%, #fff, transparent),
    radial-gradient(1px 1px at 45% 30%, #fff, transparent),
    radial-gradient(1px 1px at 15% 85%, #fff, transparent);
  opacity: 0.6;
}

.title-wrap {
  position: relative;
  z-index: 1;
  max-width: 560px;
  width: 100%;
  text-align: center;
}

.title-logo {
  font-size: 2.6rem;
  color: var(--gold);
  text-shadow: 4px 4px 0 #000, 0 0 24px rgba(255,204,51,0.5);
  letter-spacing: 0.05em;
  line-height: 1.3;
}
.title-logo .bang { color: var(--white); }

.title-sub {
  margin-top: 14px;
  font-size: 0.75rem;
  color: var(--white);
  line-height: 1.6;
}

.title-footnote {
  margin-top: 18px;
  font-size: 0.6rem;
  color: #b9c3ff;
  line-height: 1.8;
}

.best-record {
  margin-top: 16px;
  font-size: 0.65rem;
  color: var(--gold);
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--gold);
  border-radius: 6px;
  padding: 8px;
}

.panel {
  margin-top: 24px;
  background: var(--board-blue);
  border: 4px solid #000;
  border-radius: 8px;
  padding: 18px;
  box-shadow: 6px 6px 0 #000;
}

.panel-label {
  font-size: 0.7rem;
  color: var(--gold);
  margin-bottom: 14px;
}

.difficulty-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.diff-btn {
  background: var(--board-blue-dark);
  color: var(--white);
  border: 3px solid #000;
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.65rem;
  font-family: inherit;
}
.diff-btn.selected { background: var(--gold); color: #000; }
.difficulty-blurb {
  font-size: 0.55rem;
  line-height: 1.8;
  color: #b9c3ff;
  min-height: 2em;
  margin-bottom: 18px;
}

.player-count-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.count-btn {
  background: var(--board-blue-dark);
  color: var(--white);
  border: 3px solid #000;
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.65rem;
  font-family: inherit;
}
.count-btn.selected { background: var(--gold); color: #000; }

.player-name-inputs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}

/* ---------------- Board screen ---------------- */

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 18px;
  background: var(--board-blue-dark);
  border-bottom: 4px solid #000;
}

.round-banner {
  font-size: 0.85rem;
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
}

.scoreboard { display: flex; gap: 10px; flex-wrap: wrap; }
.score-pill {
  background: var(--board-blue);
  border: 2px solid #000;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.score-pill.active-turn { outline: 3px solid var(--gold); }
.score-pill .score-amt { color: var(--gold); font-size: 0.7rem; }
.score-pill .score-amt.negative { color: var(--bad); }

.turn-banner {
  text-align: center;
  padding: 10px;
  font-size: 0.65rem;
  color: var(--white);
  background: rgba(255,204,51,0.08);
}

.board-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.category-row, .cell-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.category-row {
  margin-bottom: 6px;
}

.category-cell {
  background: var(--board-blue);
  border: 3px solid #000;
  border-radius: 4px;
  padding: 10px 6px;
  text-align: center;
  font-size: 0.6rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--white);
  min-height: 72px;
}
.category-cell .cat-icon { font-size: 1.2rem; margin-bottom: 4px; }

.cell-grid { flex: 1; }

.value-cell {
  background: var(--board-blue);
  border: 3px solid #000;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  font-size: 1.1rem;
  min-height: 64px;
  text-shadow: 2px 2px 0 #000;
  transition: transform 0.08s;
}
.value-cell.clickable { cursor: pointer; }
.value-cell.clickable:hover { transform: scale(1.04); background: #1414b0; }
.value-cell.used {
  background: var(--board-edge);
  color: #2a2a55;
  cursor: default;
}

/* ---------------- Clue / Final TV overlay ---------------- */

.tv-frame {
  width: 100%;
  max-width: 680px;
  background: #1a1a1a;
  border: 10px solid #2b2b2b;
  border-radius: 18px;
  box-shadow: 0 0 0 4px #000, 0 10px 40px rgba(0,0,0,0.6);
  padding: 10px;
}

.tv-screen {
  background: var(--board-blue);
  border: 3px solid #000;
  border-radius: 8px;
  padding: 24px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
}

.clue-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.6rem;
  color: var(--gold);
  margin-bottom: 18px;
}

.clue-text {
  font-size: 1.1rem;
  line-height: 1.7;
  text-align: center;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0 24px 0;
  color: var(--white);
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.action-row .nes-btn { flex: 1; min-width: 160px; }

.host-box {
  margin-top: 16px;
  background: var(--host-box);
  border: 3px solid #000;
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.host-avatar {
  font-size: 2rem;
  flex-shrink: 0;
}
.host-text { font-size: 0.65rem; line-height: 1.8; }
.host-text .host-label {
  color: var(--gold);
  display: block;
  margin-bottom: 8px;
}
.host-text .source-tag {
  display: block;
  margin-top: 10px;
  color: #9fb0ff;
  font-size: 0.55rem;
}

.answer-input-row { margin: 10px 0; }

.mc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.mc-option {
  background: var(--board-blue-dark);
  color: var(--white);
  border: 3px solid #000;
  border-radius: 6px;
  padding: 14px 12px;
  font-size: 0.68rem;
  font-family: inherit;
  text-align: center;
  line-height: 1.5;
  box-shadow: 3px 3px 0 #000;
  transition: transform 0.08s;
}
.mc-option:hover:not(:disabled) { transform: translate(1px, 1px); box-shadow: 2px 2px 0 #000; background: #1b2a66; }
.mc-option:disabled { cursor: default; }
.mc-option.correct { background: var(--good); color: #042410; border-color: #042410; }
.mc-option.chosen-wrong { background: var(--bad); color: #2b0a00; border-color: #2b0a00; }

.teach-link {
  display: block;
  width: 100%;
  margin-top: 4px;
}

.daily-double-banner {
  text-align: center;
  font-size: 1.4rem;
  color: var(--gold);
  text-shadow: 3px 3px 0 #000;
  margin-bottom: 20px;
  animation: pulse 0.8s infinite alternate;
}
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.06); } }

.wager-info { font-size: 0.6rem; color: #b9c3ff; margin-bottom: 10px; text-align: center; }

.timer-bar-outer {
  width: 100%;
  height: 16px;
  background: var(--board-blue-dark);
  border: 2px solid #000;
  border-radius: 8px;
  overflow: hidden;
  margin: 14px 0;
}
.timer-bar-inner {
  height: 100%;
  background: var(--gold);
  transition: width 1s linear;
}

.pass-device-card {
  text-align: center;
  font-size: 0.7rem;
  line-height: 2;
}

.result-note {
  text-align: center;
  font-size: 0.65rem;
  line-height: 1.8;
  margin-bottom: 4px;
}
.result-note.good { color: var(--good); }
.result-note.bad { color: var(--bad); }
.result-note.neutral { color: var(--gold); }

/* ---------------- Clue + Host layout ---------------- */

.stage-layout {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
  width: 100%;
  max-width: 1000px;
}
.stage-layout .tv-frame { flex: 1; min-width: 0; }
.host-dock { flex-shrink: 0; width: 250px; }

/* ---------------- The Host ---------------- */

.host {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.host-bubble {
  position: relative;
  width: 100%;
  background: #fff;
  color: #000;
  border: 3px solid #000;
  border-radius: 8px;
  box-shadow: 4px 4px 0 #000;
  cursor: pointer;
}
.host-bubble.is-empty { visibility: hidden; }
.host-bubble::before,
.host-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  border-style: solid;
}
.host-bubble::before {
  bottom: -15px;
  margin-left: -10px;
  border-width: 15px 10px 0;
  border-color: #000 transparent transparent;
}
.host-bubble::after {
  bottom: -9px;
  margin-left: -6px;
  border-width: 9px 6px 0;
  border-color: #fff transparent transparent;
}
.host-bubble-scroll {
  max-height: 260px;
  overflow-y: auto;
  padding: 12px;
  font-size: 0.58rem;
  line-height: 1.8;
  min-height: 3.6em;
}

.host-sprite {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  line-height: 0;
}
.host-sprite:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; border-radius: 4px; }
.host-sprite svg { width: 120px; height: 165px; overflow: visible; }

.host-caption {
  font-size: 0.5rem;
  line-height: 1.6;
  color: var(--gold);
  text-align: center;
  min-height: 1.6em;
  animation: host-caption-blink 1.2s steps(1, end) infinite;
}

.host-figure { animation: host-bob 1.2s steps(1, end) infinite; }
.host-eyes { transform-box: fill-box; transform-origin: center; animation: host-blink 4s infinite; }
.host-mouth-open { opacity: 0; }
.host.talking .host-mouth-open { animation: host-talk 0.24s steps(1, end) infinite; }
.host-arm { transform-box: view-box; transform-origin: 13.5px 11px; }
.host.talking .host-arm { animation: host-gesture 0.6s steps(1, end) infinite; }
.host.mood-happy .host-mood { animation: host-jump 0.5s steps(1, end) 2; }
.host.mood-sad .host-mood { animation: host-shake 0.4s steps(1, end) 2; }
.host-sprite:hover .host-mood { animation: host-jump 0.5s steps(1, end) 1; }

@keyframes host-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-0.4px); } }
@keyframes host-blink { 0%, 92%, 100% { transform: scaleY(1); } 94%, 96% { transform: scaleY(0.1); } }
@keyframes host-talk { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; } }
@keyframes host-gesture { 0% { transform: rotate(0deg); } 50% { transform: rotate(-18deg); } 100% { transform: rotate(0deg); } }
@keyframes host-jump { 0%, 50%, 100% { transform: translateY(0); } 25%, 75% { transform: translateY(-1.5px); } }
@keyframes host-shake { 0%, 50%, 100% { transform: translateX(0); } 25% { transform: translateX(-0.6px); } 75% { transform: translateX(0.6px); } }
@keyframes host-caption-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

@media (prefers-reduced-motion: reduce) {
  .host *, .host-caption { animation: none !important; }
}

/* ---------------- Transition / Results ---------------- */

#screen-results.active { align-items: center; justify-content: center; padding: 20px; }

.transition-card {
  max-width: 560px;
  width: 100%;
  background: var(--board-blue);
  border: 4px solid #000;
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  box-shadow: 6px 6px 0 #000;
}
.transition-card h2 {
  font-size: 1rem;
  color: var(--gold);
  margin-bottom: 18px;
  text-shadow: 2px 2px 0 #000;
}
.transition-body { font-size: 0.7rem; line-height: 2; margin-bottom: 16px; }
.result-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 2px solid #000;
}
.result-row:last-child { border-bottom: none; }
.result-row.winner { color: var(--gold); }

@media (max-width: 860px) {
  .stage-layout { flex-direction: column; align-items: center; }
  .stage-layout .tv-frame { width: 100%; }
  .host-dock { width: 100%; max-width: 420px; }
  .host { flex-direction: row-reverse; align-items: flex-end; }
  .host-bubble::before, .host-bubble::after { display: none; }
  .host-sprite svg { width: 80px; height: 110px; }
  .host-caption { display: none; }
}

@media (max-width: 640px) {
  :root { font-size: 13px; }
  .category-row, .cell-grid { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .category-cell { min-height: 56px; font-size: 0.5rem; }
  .value-cell { min-height: 48px; font-size: 0.8rem; }
  .mc-grid { grid-template-columns: 1fr; }
}
