:root {
  --bg: #0d232e;
  --bg-2: #143b4b;
  --surface: #163f52;
  --surface-border: #2d6478;
  --text: #fbf6ec;
  --text-dim: #a9c7d1;
  --team-a: #ff5d5d;
  --team-a-dark: #c73e3e;
  --team-b: #ffd23f;
  --team-b-dark: #d1a316;
  --accent: #ffd23f;
  --accent-dark: #d1a316;
  --radius: 20px;
  --border-w: 4px;
  --font-display: 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

/* Belt-and-suspenders: any element with the `hidden` attribute must stay
   hidden no matter what `display` a later class rule sets (e.g. .timer-wrap,
   .tiles-wrap) — same specificity as the browser's own [hidden] default, so
   without this override, source order lets those classes win and the
   element shows up anyway. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background: radial-gradient(circle at 20% 0%, var(--bg-2) 0%, var(--bg) 60%);
}

body:has(#screen-home:not([hidden])) {
  background:
    linear-gradient(180deg, rgba(13, 35, 46, 0.55) 0%, rgba(13, 35, 46, 0.93) 85%),
    url('../images/home-bg.jpg') center top / cover no-repeat;
}

h1, h2, h3 {
  font-family: var(--font-display);
  margin: 0;
}

.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen[hidden] {
  display: none;
}

.muted {
  color: var(--text-dim);
  font-weight: 400;
}

.error-text {
  color: var(--team-a);
  font-weight: 700;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-display);
  font-weight: 700;
  border: var(--border-w) solid transparent;
  border-radius: 16px;
  padding: 0.9rem 1.4rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-big {
  font-size: 1.2rem;
  width: 100%;
  padding: 1.1rem 1.4rem;
}

.btn-small {
  font-size: 0.85rem;
  padding: 0.5rem 0.9rem;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #2a1a00;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--surface-border);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: var(--surface-border);
  color: var(--text-dim);
  box-shadow: none;
}

.btn-award {
  font-size: 1.1rem;
  padding: 1.2rem;
  color: white;
}

.btn-award.team-a {
  background: var(--team-a);
  border-color: var(--team-a-dark);
}

.btn-award.team-b {
  background: var(--team-b);
  border-color: var(--team-b-dark);
  color: #2a1a00;
}

/* ==================================================================
   HOST VIEW — mobile-first (a phone in the emcee's hand)
   ================================================================== */
.host-view {
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
  padding: 1.5rem 1.25rem 2.5rem;
  align-items: stretch;
}

.home-hero {
  text-align: center;
  padding: 2.5rem 0 1.5rem;
}

.home-hero h1 {
  font-size: clamp(2.2rem, 9vw, 3rem);
  line-height: 1.05;
}

.home-hero h1 span {
  color: var(--accent);
}

.home-hero h2 {
  font-size: 1.8rem;
}

.tagline {
  color: var(--text-dim);
  font-size: 1.05rem;
  margin-top: 0.75rem;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.join-row {
  display: flex;
  gap: 0.5rem;
}

.join-row input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  border-radius: 16px;
  border: var(--border-w) solid var(--surface-border);
  background: var(--surface);
  color: var(--text);
  padding: 0.7rem;
}

.home-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: auto;
  padding-top: 2rem;
}

#dialog-how-to-play {
  border: var(--border-w) solid var(--surface-border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  padding: 0;
  max-width: 480px;
  width: calc(100% - 2.5rem);
  max-height: 85vh;
  overflow: hidden; /* only .htp-body scrolls — see below */
}

#dialog-how-to-play::backdrop {
  background: rgba(3, 10, 14, 0.7);
}

.htp-body {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: 85vh;
  box-sizing: border-box;
}

.htp-body h2 {
  margin-bottom: 1rem;
}

.htp-steps {
  padding-left: 1.2rem;
  margin: 0 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  line-height: 1.4;
}

.htp-note {
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.home-trophy {
  font-size: 4rem;
  text-align: center;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0 1rem;
}

.panel {
  background: var(--surface);
  border: var(--border-w) solid var(--surface-border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.panel h3 {
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.field-row input[type="text"] {
  flex: 1;
  font-family: var(--font-body);
  font-size: 1rem;
  border-radius: 12px;
  border: 2px solid var(--surface-border);
  background: var(--bg);
  color: var(--text);
  padding: 0.6rem 0.8rem;
}

.team-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
}

.team-swatch.team-a { background: var(--team-a); }
.team-swatch.team-b { background: var(--team-b); }

.select-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  border-radius: 12px;
  border: 2px solid var(--surface-border);
  background: var(--bg);
  color: var(--text);
  padding: 0.6rem 0.8rem;
}

.timer-hint {
  font-size: 0.8rem;
  margin: 0.6rem 0 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
}

/* ---------- Timer ---------- */
.timer-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--surface);
  border: var(--border-w) solid var(--surface-border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
}

.timer-display {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  min-width: 3ch;
  text-align: center;
}

.timer-display.timer-urgent {
  color: var(--team-a);
  animation: timer-pulse 0.6s ease infinite;
}

@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.timer-display-big {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
}

/* ---------- Letter-hint tiles ---------- */
.tiles-wrap {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.75rem 0;
}

.tile-word-group {
  display: flex;
  gap: 0.3rem;
}

.letter-tile {
  width: 2.1rem;
  height: 2.5rem;
  border: 3px solid var(--surface-border);
  background: var(--surface);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
}

.letter-tile.revealed {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #2a1a00;
  animation: tile-pop 0.3s ease;
}

@keyframes tile-pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.display-view .tiles-wrap-big .letter-tile {
  width: 3.6rem;
  height: 4.2rem;
  font-size: 2rem;
  border-radius: 12px;
}

.setup-body {
  flex: 1;
}

.setup-footer {
  margin-top: 1rem;
}

.room-code-label {
  color: var(--text-dim);
  margin-top: 0.5rem;
}

.room-code {
  font-family: var(--font-display);
  font-size: 3rem;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin: 0.25rem 0;
}

.pill {
  display: inline-block;
  background: var(--surface);
  border: 2px solid var(--surface-border);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
}

.game-header {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.host-scores {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.team-a-pill {
  border-color: var(--team-a);
  color: var(--team-a);
}

.team-b-pill {
  border-color: var(--team-b);
  color: var(--team-b);
}

.host-answer-card {
  background: var(--surface);
  border: var(--border-w) solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  margin-bottom: 1rem;
}

.word-label {
  margin: 0 0 0.3rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.host-answer {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--accent);
  margin: 0;
  word-break: break-word;
}

.host-controls {
  display: flex;
  gap: 0.6rem;
  margin: 1rem 0;
}

.host-controls .btn {
  flex: 1;
}

.award-row {
  display: flex;
  gap: 0.6rem;
  margin-top: auto;
}

.award-row .btn {
  flex: 1;
}

.final-scores {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 1rem 0;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

/* ---------- Rebus card image ---------- */
.card-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 0.5rem 0;
}

.rebus-card-image {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
  border: var(--border-w) solid var(--surface-border);
  border-radius: 16px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  transition: filter 0.25s ease;
}

/* Every puzzle deals in blurred — the Host taps the card to reveal it for
   everyone at once. .card-wrap (not just the image) carries the class so
   the reveal-hint overlay below can be positioned relative to it. */
.card-wrap.blurred .rebus-card-image {
  filter: blur(22px) brightness(0.75);
}

.host-card-wrap.blurred {
  cursor: pointer;
}

.reveal-hint {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.4rem;
  text-align: center;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  pointer-events: none;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.card-wrap.blurred .reveal-hint {
  display: flex;
}

.reveal-hint .reveal-hint-icon {
  font-size: 2rem;
}

/* ==================================================================
   DISPLAY VIEW — landscape / TV-first (the shared screen everyone reads)
   ================================================================== */
.display-view {
  padding: 2rem 3rem;
  justify-content: center;
  align-items: center;
  position: relative;
  gap: 2rem;
}

.score-plaque {
  position: fixed;
  top: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem 1.5rem;
  border-radius: 18px;
  border: var(--border-w) solid;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.25s ease;
}

.plaque-a {
  left: 1.5rem;
  background: var(--team-a);
  border-color: var(--team-a-dark);
  color: white;
}

.plaque-b {
  right: 1.5rem;
  background: var(--team-b);
  border-color: var(--team-b-dark);
  color: #2a1a00;
}

.plaque-name {
  font-weight: 700;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.plaque-score {
  font-family: var(--font-display);
  font-size: 2.6rem;
  line-height: 1;
}

.score-plaque.bump {
  animation: plaque-bump 0.5s ease;
}

@keyframes plaque-bump {
  0% { transform: scale(1); }
  30% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.category-banner {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--text-dim);
  text-align: center;
  padding: 0.4rem 1.2rem;
  border: 2px solid var(--surface-border);
  border-radius: 999px;
  background: var(--surface);
}

.display-waiting {
  text-align: center;
  font-size: 1.5rem;
  color: var(--text-dim);
}

.card-wrap-big .rebus-card-image {
  max-width: min(70vw, 620px);
}

.card-wrap-big .reveal-hint {
  font-size: 1.4rem;
}

.card-wrap-big .reveal-hint .reveal-hint-icon {
  font-size: 3.5rem;
}

/* ---------- Confetti (JS-appended, no library) ---------- */
.confetti-piece {
  position: fixed;
  top: -2rem;
  width: 10px;
  height: 16px;
  opacity: 0.9;
  pointer-events: none;
  z-index: 999;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0;
  }
}
