:root {
  --navy: #07143a;
  --navy-deep: #040b22;
  --navy-mid: #0b1c4d;
  --board: #0a1ad0;
  --board-dark: #0610a0;
  --board-used: #08103a;
  --gold: #f5d76e;
  --gold-deep: #c9a227;
  --gold-text: #ffe9a8;
  --cream: #f7f0d8;
  --crimson: #9c1d32;
  --crimson-dark: #6d1021;
  --forest: #1d6b3d;
  --holly: #163a28;
  --muted: #9bb0d4;
  --snow: #eef4ff;
  --ink: #f8f4ea;
  --shadow: rgba(0, 0, 0, 0.45);
  --font-ui: "Source Sans 3", "Segoe UI", sans-serif;
  --font-display: Cinzel, "Times New Roman", serif;
  --font-clue: "Libre Baskerville", Georgia, serif;
  --team-0: #e8b44c;
  --team-1: #e06b5a;
  --team-2: #4caf7a;
  --team-3: #6b8edb;
  --team-4: #d07ab8;
  --team-5: #e09a3e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 50% -10%, #16301f 0%, transparent 55%),
    radial-gradient(800px 500px at 100% 100%, #3a1520 0%, transparent 50%),
    var(--navy-deep);
  color: var(--ink);
  font-family: var(--font-ui);
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.loading-msg {
  margin: auto;
  font-family: var(--font-display);
  color: var(--gold);
  letter-spacing: 0.12em;
  font-size: clamp(1.2rem, 3vw, 2rem);
}

/* Snow */
.snow {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}
.flake {
  position: absolute;
  top: -10px;
  width: 6px;
  height: 6px;
  background: white;
  border-radius: 50%;
  opacity: 0.55;
  animation: fall linear infinite;
}
@keyframes fall {
  to { transform: translateY(110dvh) rotate(200deg); }
}
@media (prefers-reduced-motion: reduce) {
  .flake { animation: none; display: none; }
}

/* Buttons */
button, input, select {
  font-family: inherit;
}
.btn {
  appearance: none;
  border: 2px solid var(--gold-deep);
  background: linear-gradient(#2a1f08, #120e06);
  color: var(--gold-text);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.75rem 1.15rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: clamp(0.9rem, 1.4vw, 1.15rem);
  box-shadow: 0 4px 0 #3a2a0a;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #3a2a0a; }
.btn.primary {
  background: linear-gradient(#d4b35a, #8a6a1c);
  color: #1a1204;
  border-color: #f3e0a0;
}
.btn.good {
  background: linear-gradient(#2e8a52, #165530);
  border-color: #8fe0b0;
  color: #f2fff6;
  box-shadow: 0 4px 0 #0c3a20;
}
.btn.bad {
  background: linear-gradient(#b33545, #6d1021);
  border-color: #f0a0aa;
  color: #fff6f6;
  box-shadow: 0 4px 0 #3a0a12;
}
.btn.ghost {
  background: transparent;
  box-shadow: none;
  border-color: #4a6088;
  color: var(--muted);
}
.btn.lg { font-size: clamp(1.05rem, 2vw, 1.4rem); padding: 0.95rem 1.4rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

/* Setup */
.setup {
  margin: auto;
  width: min(1100px, calc(100% - 2rem));
  padding: 2rem 0 3rem;
}
.logo-block { text-align: center; margin-bottom: 1.5rem; }
.logo-kicker {
  color: var(--gold);
  letter-spacing: 0.35em;
  font-size: 0.85rem;
  text-transform: uppercase;
  margin: 0 0 0.4rem;
}
.logo {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(3rem, 10vw, 7rem);
  line-height: 0.9;
  margin: 0;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(245, 215, 110, 0.35), 0 6px 0 #6a4e10;
  letter-spacing: 0.06em;
}
.logo-sub {
  font-family: var(--font-display);
  color: var(--cream);
  font-size: clamp(1.1rem, 2.6vw, 1.8rem);
  margin: 0.6rem 0 0.2rem;
}
.logo-tag { color: var(--muted); margin: 0; font-size: clamp(1rem, 1.8vw, 1.2rem); }

.card {
  background: linear-gradient(180deg, rgba(12, 28, 70, 0.92), rgba(6, 14, 36, 0.94));
  border: 1px solid rgba(245, 215, 110, 0.28);
  border-radius: 18px;
  padding: clamp(1rem, 2vw, 1.6rem);
  box-shadow: 0 18px 50px var(--shadow);
}

.night-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
  margin: 0.6rem 0 1.2rem;
}
.night-btn {
  text-align: left;
  background: #0a173f;
  border: 2px solid #2a3f73;
  color: inherit;
  border-radius: 14px;
  padding: 1rem 1rem 1.1rem;
  cursor: pointer;
}
.night-btn h3 {
  font-family: var(--font-display);
  margin: 0;
  color: var(--gold-text);
  font-size: clamp(1.1rem, 2vw, 1.4rem);
}
.night-btn p { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.98rem; }
.night-btn.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(245, 215, 110, 0.25), inset 0 0 20px rgba(245, 215, 110, 0.07);
}

.field-label {
  display: block;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  font-size: 0.8rem;
  margin-bottom: 0.45rem;
}
.team-count {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.team-count button {
  min-width: 3rem;
  height: 3rem;
  border-radius: 999px;
  border: 2px solid #2a3f73;
  background: #0a173f;
  color: var(--cream);
  font-weight: 800;
  font-size: 1.2rem;
  cursor: pointer;
}
.team-count button.selected {
  border-color: var(--gold);
  background: #1b2f14;
  color: var(--gold);
}

.team-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1.2rem;
}
.team-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: #091433;
  border: 1px solid #2a3f73;
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
}
.swatch {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.15);
}
.team-field input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--cream);
  font-size: 1.15rem;
  font-weight: 650;
  outline: none;
  min-width: 0;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
}
.resume-note { color: var(--gold-text); margin-left: auto; font-size: 0.95rem; }

/* How-to */
.howto {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 1.02rem;
}
.howto summary {
  cursor: pointer;
  color: var(--gold-text);
  font-weight: 700;
}
.howto ol { margin: 0.5rem 0 0; padding-left: 1.3rem; }
.howto li { margin: 0.35rem 0; }

/* Play layout */
.play {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 0.6rem 0.7rem 0.5rem;
  gap: 0.55rem;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--font-display);
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.08em;
  font-size: clamp(1.3rem, 3vw, 2rem);
  text-shadow: 0 2px 0 #6a4e10;
  margin: 0;
}
.night-chip {
  color: var(--cream);
  font-size: clamp(0.95rem, 1.6vw, 1.2rem);
}
.topbar .spacer { flex: 1; }
.tiny { font-size: 0.85rem; padding: 0.45rem 0.7rem; }

/* Board */
.board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: minmax(70px, 0.7fr) repeat(5, 1fr);
  gap: 0.4rem;
}
.cat, .cell {
  background: linear-gradient(180deg, var(--board) 0%, var(--board-dark) 100%);
  border: 3px solid var(--gold-deep);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: inset 0 0 18px rgba(0,0,0,0.25);
}
.cat {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--cream);
  font-size: clamp(0.62rem, 1.45vw, 1.15rem);
  letter-spacing: 0.04em;
  line-height: 1.15;
  padding: 0.3rem 0.25rem;
  text-shadow: 0 2px 0 rgba(0,0,0,0.45);
  text-wrap: balance;
}
.cell {
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 900;
  color: var(--gold);
  font-size: clamp(1.4rem, 4.4vw, 3.4rem);
  text-shadow: 0 0 16px rgba(245, 215, 110, 0.25), 0 3px 0 #5a430c;
  user-select: none;
}
.cell:hover { filter: brightness(1.12); }
.cell.used {
  background: var(--board-used);
  border-color: #2a3558;
  color: transparent;
  text-shadow: none;
  cursor: default;
  filter: none;
}

/* Scores */
.scorebar {
  display: grid;
  gap: 0.4rem;
  grid-auto-rows: 1fr;
}
.scorebar.n2 { grid-template-columns: repeat(2, 1fr); }
.scorebar.n3 { grid-template-columns: repeat(3, 1fr); }
.scorebar.n4 { grid-template-columns: repeat(4, 1fr); }
.scorebar.n5 { grid-template-columns: repeat(5, 1fr); }
.scorebar.n6 { grid-template-columns: repeat(6, 1fr); }

.team-card {
  background: #0a173f;
  border: 3px solid #2a3f73;
  border-radius: 10px;
  padding: 0.35rem 0.5rem 0.45rem;
  text-align: center;
  cursor: pointer;
  min-width: 0;
}
.team-card.control {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(245, 215, 110, 0.2), 0 0 18px rgba(245, 215, 110, 0.12);
}
.team-name {
  font-weight: 800;
  font-size: clamp(0.8rem, 1.5vw, 1.15rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.team-score {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(1.3rem, 3.4vw, 2.4rem);
  line-height: 1;
  color: var(--gold);
}
.team-score.neg { color: #f0a0aa; }
.control-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background:
    radial-gradient(800px 400px at 50% 0%, rgba(80, 30, 30, 0.25), transparent 50%),
    linear-gradient(180deg, #0818c4 0%, #050d6a 60%, #07143a 100%);
  display: flex;
  flex-direction: column;
  padding: 1.2rem 1.4rem 1.3rem;
}
.overlay.dd {
  background:
    radial-gradient(700px 500px at 50% 40%, #c9a227 0%, transparent 55%),
    linear-gradient(180deg, #6d1021, #1a050c);
}
.overlay.final {
  background:
    radial-gradient(800px 500px at 50% 30%, rgba(245, 215, 110, 0.18), transparent 50%),
    linear-gradient(180deg, #0b1c4d, #07143a 60%, #040b22);
}

.overlay-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  font-family: var(--font-display);
  color: var(--gold-text);
  letter-spacing: 0.08em;
  font-size: clamp(1rem, 2.2vw, 1.6rem);
}
.overlay-value {
  color: var(--gold);
  font-weight: 900;
  font-size: clamp(1.4rem, 3.5vw, 2.6rem);
}

.clue-text, .answer-text, .splash-text {
  margin: auto;
  text-align: center;
  max-width: 22ch;
  text-wrap: balance;
  font-family: var(--font-clue);
  font-style: italic;
  font-size: clamp(1.8rem, 5.2vw, 4.4rem);
  line-height: 1.25;
  text-shadow: 0 3px 16px rgba(0,0,0,0.45);
}
.answer-text {
  font-style: normal;
  font-weight: 700;
  color: var(--gold);
  max-width: 24ch;
}
.answer-notes {
  text-align: center;
  color: var(--gold-text);
  font-size: clamp(1rem, 2vw, 1.3rem);
  margin: 0 auto 1rem;
  max-width: 40rem;
}
.splash-text {
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 900;
  color: var(--gold);
  font-size: clamp(3rem, 10vw, 8rem);
  letter-spacing: 0.06em;
  max-width: none;
  text-shadow: 0 0 30px rgba(245, 215, 110, 0.4), 0 8px 0 #5a120c;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  align-items: center;
}

.award-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto 0.6rem;
}
.award-team {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(245, 215, 110, 0.25);
  border-radius: 10px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
}
.award-team .name { text-align: center; font-weight: 800; }
.award-row { display: flex; gap: 0.35rem; }
.award-row .btn { flex: 1; padding: 0.55rem 0.4rem; font-size: 0.95rem; }

/* Wager */
.wager-box {
  margin: auto;
  width: min(640px, 100%);
  text-align: center;
}
.wager-box h2 {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: clamp(1.6rem, 4vw, 2.8rem);
  margin: 0 0 0.4rem;
}
.wager-box p { color: var(--cream); font-size: clamp(1.05rem, 2vw, 1.35rem); }
.wager-input {
  width: 100%;
  font-size: clamp(2.2rem, 6vw, 4rem);
  font-family: var(--font-display);
  font-weight: 900;
  text-align: center;
  background: rgba(0,0,0,0.3);
  color: var(--gold);
  border: 3px solid var(--gold-deep);
  border-radius: 12px;
  padding: 0.3rem;
  margin: 0.6rem 0;
}
.wager-presets { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-bottom: 1rem; }
.wager-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.7rem;
  width: min(900px, 100%);
  margin: auto;
}
.wager-card {
  background: rgba(0,0,0,0.28);
  border: 2px solid #2a3f73;
  border-radius: 12px;
  padding: 0.8rem;
}
.wager-card h3 { margin: 0 0 0.2rem; font-size: 1.15rem; }
.wager-card .have { color: var(--muted); margin: 0 0 0.4rem; }
.sit-out { color: #f0a0aa; font-weight: 700; }

/* Winner */
.winner {
  margin: auto;
  width: min(800px, calc(100% - 2rem));
  text-align: center;
  padding: 2rem 0;
}
.winner h1 {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: clamp(2.4rem, 7vw, 5rem);
  margin: 0 0 0.4rem;
  text-shadow: 0 4px 0 #6a4e10;
}
.standings { list-style: none; padding: 0; margin: 1rem 0 1.5rem; }
.standings li {
  display: flex;
  justify-content: space-between;
  font-size: clamp(1.2rem, 3vw, 2rem);
  padding: 0.45rem 0.2rem;
  border-bottom: 1px solid rgba(245, 215, 110, 0.2);
  font-family: var(--font-display);
}
.standings li:first-child { color: var(--gold); font-weight: 900; font-size: clamp(1.5rem, 4vw, 2.5rem); }

/* Modal light */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(4, 11, 34, 0.72);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  width: min(640px, 100%);
  background: var(--navy-mid);
  border: 2px solid var(--gold-deep);
  border-radius: 16px;
  padding: 1.2rem 1.3rem;
}
.modal h2 { font-family: var(--font-display); color: var(--gold); margin-top: 0; }

@media (max-width: 800px) {
  body { overflow: auto; }
  .night-grid { grid-template-columns: 1fr; }
  .board {
    grid-template-rows: minmax(52px, auto) repeat(5, minmax(52px, 1fr));
    min-height: 70dvh;
  }
  .scorebar.n5, .scorebar.n6 { grid-template-columns: repeat(3, 1fr); }
  .clue-text { max-width: 16ch; }
  .play { min-height: auto; }
}

.hidden-wager {
  -webkit-text-security: disc;
  color: var(--gold);
}
