/* ── Clay Design System ─────────────────────────────────────── */
:root {
  --clay-coral:      #FF8C7A;
  --clay-butter:     #FFD56B;
  --clay-mint:       #7FD8A6;
  --clay-periwinkle: #8FA8FF;
  --clay-cream:      #FFF6E9;
  --clay-plum:       #5C3566;
  --clay-shadow:     rgba(120,80,40,.22);
  --clay-radius:     22px;
  --font-head:       'Baloo 2', 'Fredoka', sans-serif;
  --font-body:       'Nunito', sans-serif;
  --font-big:        'Bagel Fat One', cursive;
}

body {
  background: radial-gradient(ellipse at 50% 20%, #fff3e0 0%, #ffe0c4 55%, #f5c9a0 100%);
  font-family: var(--font-body);
  min-height: 100vh;
}

/* Paper grain overlay */
body::after {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.045;
  pointer-events: none;
  z-index: 9999;
  mix-blend-mode: multiply;
}

h1, h2, h3, .title, .screen-title { font-family: var(--font-big) !important; }

/* Answer buttons — clay colored panels */
.ans-btn {
  border-radius: 20px !important;
  font-family: var(--font-head) !important;
  font-size: 1.6rem !important;
  font-weight: 800 !important;
  border: none !important;
  box-shadow: 0 8px 0 rgba(0,0,0,.22), 0 12px 24px rgba(0,0,0,.14) !important;
  transition: transform 0.08s, box-shadow 0.08s !important;
  cursor: pointer;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px !important;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* 4 clay answer colors */
.ans-btn:nth-child(1), .ans-btn.a0 {
  background: linear-gradient(145deg, #ff9f91, #FF8C7A) !important;
  color: #fff !important;
}
.ans-btn:nth-child(2), .ans-btn.a1 {
  background: linear-gradient(145deg, #6fb8ff, #4A9EFF) !important;
  color: #fff !important;
}
.ans-btn:nth-child(3), .ans-btn.a2 {
  background: linear-gradient(145deg, #90e0b0, #5DC98A) !important;
  color: #fff !important;
}
.ans-btn:nth-child(4), .ans-btn.a3 {
  background: linear-gradient(145deg, #ffe080, #FFD056) !important;
  color: #4a3000 !important;
}

/* Pressed state */
.ans-btn:active {
  transform: translateY(5px) scale(0.97) !important;
  box-shadow: 0 3px 0 rgba(0,0,0,.22), 0 6px 12px rgba(0,0,0,.14) !important;
}

/* Answer label letter */
.ans-letter {
  font-family: var(--font-big) !important;
  font-size: 2rem !important;
}

/* Lobby / join screens */
#screen-join, #screen-lobby, #screen-wait {
  background: linear-gradient(145deg, #fff6ee, #ffe8cc);
  border-radius: var(--clay-radius);
  box-shadow: 0 12px 32px var(--clay-shadow), inset 0 3px 8px rgba(255,255,255,.6);
  margin: 12px;
  padding: 24px 18px;
}

/* Name/PIN input fields */
input[type="text"], input[type="number"] {
  font-family: var(--font-head) !important;
  font-size: 1.4rem !important;
  border-radius: 16px !important;
  border: 3px solid rgba(180,110,60,.25) !important;
  background: linear-gradient(145deg, #fffaf5, #fff3e0) !important;
  box-shadow: inset 0 3px 8px rgba(150,90,40,.12) !important;
  padding: 12px 18px !important;
  color: #3d2200 !important;
}

/* Primary CTA buttons */
button.btn-primary, .btn-join, #btn-join {
  font-family: var(--font-head) !important;
  font-size: 1.4rem !important;
  font-weight: 800 !important;
  background: linear-gradient(145deg, var(--clay-plum), #8B4FBE) !important;
  color: #fff !important;
  border: none !important;
  border-radius: 999px !important;
  padding: 14px 32px !important;
  box-shadow: 0 6px 0 rgba(0,0,0,.25), 0 10px 20px rgba(92,53,102,.3) !important;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s !important;
}
button.btn-primary:active, .btn-join:active, #btn-join:active {
  transform: translateY(4px) !important;
  box-shadow: 0 2px 0 rgba(0,0,0,.25), 0 4px 8px rgba(92,53,102,.3) !important;
}

/* Avatar selection (emoji grid) */
.avatar-option {
  font-size: 2.4rem !important;
  border-radius: 16px !important;
  width: 60px !important; height: 60px !important;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, #fff6ee, #ffe8cc);
  box-shadow: 0 4px 0 rgba(0,0,0,.15), 0 6px 12px var(--clay-shadow);
  border: 3px solid transparent !important;
  cursor: pointer;
  transition: transform 0.1s !important;
}
.avatar-option:active { transform: scale(0.88) !important; }
.avatar-option.selected {
  border-color: var(--clay-plum) !important;
  box-shadow: 0 0 0 3px var(--clay-plum), 0 6px 16px var(--clay-shadow) !important;
}

/* Power play cards on phone */
.pp-btn, .power-play-btn {
  background: linear-gradient(145deg, #ffeedd, #ffd0a0) !important;
  border-radius: 18px !important;
  font-family: var(--font-head) !important;
  font-weight: 700 !important;
  border: none !important;
  box-shadow: 0 6px 0 rgba(0,0,0,.18), 0 10px 20px var(--clay-shadow) !important;
  padding: 16px 20px !important;
  cursor: pointer;
}

/* Score display */
.score-display, #score-val {
  font-family: var(--font-big) !important;
  font-size: 3rem !important;
  color: var(--clay-plum) !important;
  text-shadow: 0 4px 0 rgba(92,53,102,.2) !important;
}

/* Waiting / result panels */
.result-correct {
  background: linear-gradient(145deg, #a8f0c0, #5DC98A) !important;
  color: #fff !important;
  border-radius: 20px !important;
  font-family: var(--font-big) !important;
}
.result-wrong {
  background: linear-gradient(145deg, #ffb0a0, #FF8C7A) !important;
  color: #fff !important;
  border-radius: 20px !important;
  font-family: var(--font-big) !important;
}

/* ── Reset & base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d001f;
  --bg2:       #160030;
  --surface:   #1e0040;
  --surface2:  #2a005a;
  --accent:    #c84bff;
  --accent2:   #ff6bff;
  --text:      #f0e6ff;
  --text-dim:  #a080c0;
  --radius:    16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --ans-r: #e74c3c;
  --ans-b: #3498db;
  --ans-g: #2ecc71;
  --ans-y: #f39c12;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

body {
  font-family: 'Fredoka', 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at top, #1e0040 0%, #0d001f 70%);
  display: flex;
  align-items: stretch;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 18px env(safe-area-inset-bottom, 30px);
  padding-bottom: max(30px, env(safe-area-inset-bottom));
  gap: 12px;
  -webkit-overflow-scrolling: touch;
  max-width: 100vw;
  box-sizing: border-box;
}
.screen.active { display: flex; }

/* ── Typography ───────────────────────────────────────────────────────────── */
h1 {
  font-size: 2.6rem;
  font-weight: 600;
  text-align: center;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}

h2, .screen-title {
  font-size: 1.55rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
}

.screen-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 1rem;
  margin-top: -6px;
}

.field-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: -6px;
}

/* ── Buttons (base) ───────────────────────────────────────────────────────── */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: transform 0.1s, opacity 0.15s, filter 0.15s;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(0.96); opacity: 0.85; }

.btn-primary {
  display: block;
  width: 100%;
  padding: 18px;
  font-size: 1.2rem;
  font-weight: 600;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), #7b2fff);
  color: #fff;
  box-shadow: 0 4px 20px rgba(200,75,255,0.4);
  margin-top: 4px;
}

.btn-skip {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Input ────────────────────────────────────────────────────────────────── */
input[type=text] {
  width: 100%;
  padding: 16px 18px;
  font-family: inherit;
  font-size: 1.15rem;
  border: 2px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
input[type=text]:focus { border-color: var(--accent); }
input[type=text].shake {
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

/* ── JOIN screen ──────────────────────────────────────────────────────────── */
.join-header {
  text-align: center;
  padding: 6px 0 2px;
  flex-shrink: 0;
}
.logo-emoji {
  font-size: clamp(2rem, 8vw, 3.5rem);
  line-height: 1;
  margin-bottom: 2px;
}
h1 {
  font-size: clamp(2rem, 7vw, 2.6rem);
}
.subtitle {
  color: var(--text-dim);
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  margin-top: 2px;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}
.avatar-btn {
  /* Use aspect-ratio to keep it square while shrinking */
  width: 100%;
  aspect-ratio: 1;
  min-width: 44px;
  max-width: 64px;
  font-size: clamp(1.3rem, 5vw, 1.6rem);
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 2px solid transparent;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Prevent text-size from ever hiding the emoji */
  line-height: 1;
}
.avatar-btn.selected {
  border-color: var(--accent);
  background: var(--surface2);
}

.color-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
}
.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  min-width: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}
.color-swatch.selected {
  border-color: #fff;
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--bg);
}

/* ── LOBBY screen ─────────────────────────────────────────────────────────── */
.lobby-header {
  text-align: center;
  padding: 10px 0;
}
.big-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  font-size: 2.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
  box-shadow: 0 0 24px rgba(200,75,255,0.4);
}
.waiting-text {
  color: var(--text-dim);
  font-size: 1rem;
  margin-top: 6px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--surface2);
}
.card-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.player-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.player-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border-radius: 20px;
  padding: 5px 12px 5px 5px;
}
.chip-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chip-name {
  font-size: 0.95rem;
  font-weight: 600;
}

/* ── CATEGORY VOTE screen ─────────────────────────────────────────────────── */
.door-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  flex: 1;
  /* Ensure rows stay balanced and don't overflow */
  grid-auto-rows: 1fr;
  min-height: 0;
}
.door-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 100px;
  border-radius: var(--radius-lg);
  color: #fff;
  font-size: clamp(0.95rem, 3vw, 1.1rem);
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.15s, filter 0.2s, opacity 0.2s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  /* Prevent overflow on long category names */
  word-break: break-word;
  hyphens: auto;
  padding: 10px 8px;
}
.door-btn:disabled { opacity: 0.4; }
.door-btn.my-vote {
  box-shadow: 0 0 0 4px #fff, 0 4px 20px rgba(255,255,255,0.3);
  transform: scale(1.04);
}
.door-emoji { font-size: clamp(1.5rem, 6vw, 2rem); }
.door-name  { font-size: clamp(0.85rem, 2.8vw, 1rem); text-align: center; }
.vote-status {
  text-align: center;
  color: var(--accent2);
  font-size: 1rem;
  font-weight: 600;
  min-height: 22px;
}

/* ── POWER PLAY screen ───────────────────────────────────────────────────── */
.pp-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.pp-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
  flex-shrink: 0;
}
.pp-card:active, .pp-card.selected {
  background: var(--surface2);
  transform: scale(0.97);
}
.pp-card-emoji { font-size: 2rem; flex-shrink: 0; }
.pp-card-body  { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.pp-card-name  { font-size: 1.1rem; font-weight: 600; }
.pp-card-desc  { font-size: 0.85rem; color: var(--text-dim); }

/* ── TARGET screen ───────────────────────────────────────────────────────── */
.target-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}
.target-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-family: inherit;
  width: 100%;
  border: 2px solid var(--surface2);
  transition: border-color 0.15s, background 0.15s;
}
.target-btn:active { background: var(--surface2); }
.target-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.target-name {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

/* ── QUESTION screen ─────────────────────────────────────────────────────── */
.q-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.q-category {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface);
  border-radius: 20px;
  padding: 4px 12px;
}
.answered-status {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.timer-bar {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: #2ecc71;
  border-radius: 4px;
  transform-origin: left;
}

.q-text {
  font-size: clamp(1.05rem, 3.5vw, 1.3rem);
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
  padding: 8px 0;
  /* Don't let it stretch the full remaining height — keep text near center */
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  /* Fill available space but cap growth so buttons don't become enormous */
  flex: 1 1 auto;
  align-content: stretch;
}
.answer-btn {
  min-height: 72px;
  /* Grow equally to fill the grid */
  height: 100%;
  font-size: clamp(0.9rem, 3vw, 1.05rem);
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius);
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  line-height: 1.3;
  padding: 10px 12px;
  word-break: break-word;
  transition: transform 0.1s, opacity 0.15s, filter 0.15s;
}
.answer-btn:disabled { cursor: default; }
.answer-btn.selected { filter: brightness(1.2); box-shadow: 0 0 0 4px rgba(255,255,255,0.6); }

.ans-0 { background: var(--ans-r); }
.ans-1 { background: var(--ans-b); }
.ans-2 { background: var(--ans-g); }
.ans-3 { background: var(--ans-y); }

/* Screen-question needs position:relative for power play overlays */
#screen-question {
  position: relative;
  /* Use flex justify to push answers toward bottom naturally */
  justify-content: space-between;
}

/* ── POWER PLAY OVERLAYS ─────────────────────────────────────────────────── */
.pp-overlay {
  position: absolute;
  left: 0; top: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}
.pp-overlay.hidden { display: none; }

/* GLOOP */
.pp-gloop {
  background: rgba(39, 174, 96, 0.15);
  cursor: crosshair;
}
.pp-gloop canvas {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  border-radius: var(--radius);
}
.gloop-label {
  position: relative;
  z-index: 2;
  font-size: 1.4rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 0 12px #000;
  pointer-events: none;
  text-align: center;
  padding: 10px 20px;
  background: rgba(0,0,0,0.4);
  border-radius: 20px;
}

/* FREEZE */
.pp-freeze {
  background: linear-gradient(160deg, rgba(52,152,219,0.7), rgba(180,220,255,0.5));
  backdrop-filter: blur(4px);
}
.pp-freeze.crack {
  animation: icecrack 0.15s ease;
}
@keyframes icecrack {
  0%   { filter: brightness(1); }
  50%  { filter: brightness(2) saturate(0.5); }
  100% { filter: brightness(1); }
}
.freeze-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.freeze-emoji  { font-size: 3rem; }
.freeze-text   { font-size: 2rem; font-weight: 600; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,0.5); }
.freeze-count  { font-size: 1.1rem; color: #ddeeff; font-weight: 600; }

/* BOMB */
.pp-bomb {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 11;
}
.pp-bomb.hidden { display: none; }
.bomb-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #1a0000;
  border: 2px solid #e74c3c;
  border-radius: 30px;
  padding: 8px 14px 8px 10px;
  cursor: pointer;
  transition: transform 0.1s;
}
.bomb-inner:active { transform: scale(0.9); }
.bomb-emoji  { font-size: 1.6rem; }
.bomb-count  { font-size: 1.4rem; font-weight: 600; color: #e74c3c; }
.bomb-pulse {
  animation: bombpulse 0.5s ease infinite alternate;
}
@keyframes bombpulse {
  from { box-shadow: 0 0 4px #e74c3c; }
  to   { box-shadow: 0 0 20px #e74c3c, 0 0 40px #ff0000; transform: scale(1.08); }
}

/* ── REVEAL screen ───────────────────────────────────────────────────────── */
.reveal-result {
  text-align: center;
  padding: 24px 0 16px;
}
.reveal-icon   { font-size: 4rem; line-height: 1; margin-bottom: 8px; }
.reveal-verdict {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.reveal-points {
  font-size: 1.2rem;
  color: var(--text-dim);
}
.pts-gained {
  font-size: 1.8rem;
  font-weight: 600;
  color: #2ecc71;
}

.reveal-scores {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
}
.reveal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.reveal-row.reveal-me {
  background: var(--surface2);
  border: 1px solid var(--accent);
}
.rr-rank  { font-size: 0.9rem; color: var(--text-dim); width: 20px; }
.rr-name  { flex: 1; font-weight: 600; font-size: 1rem; }
.rr-score { font-size: 1rem; font-weight: 600; color: var(--accent2); }

/* ── LINKING minigame ────────────────────────────────────────────────────── */
.linking-arena {
  display: grid;
  grid-template-columns: 1fr 40px 1fr;
  gap: 0;
  flex: 1;
  min-height: 250px;
  position: relative;
}
.linking-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: space-around;
}
.linking-col-left  { grid-column: 1; }
.linking-col-right { grid-column: 3; }
.linking-svg {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: visible;
}

.link-item {
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--surface2);
  text-align: center;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  word-break: break-word;
}
.link-item.selected {
  border-color: var(--accent);
  background: var(--surface2);
}
.link-item.paired {
  border-color: #2ecc71;
  background: rgba(46, 204, 113, 0.1);
}
.link-left  { margin-right: 4px; }
.link-right { margin-left: 4px; }

/* ── SORTING minigame ────────────────────────────────────────────────────── */
.sorting-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sort-label {
  flex: 1;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
}
.sort-label-a { background: rgba(231,76,60,0.2); color: #e74c3c; }
.sort-label-b { background: rgba(52,152,219,0.2); color: #3498db; }
.sort-progress {
  font-size: 0.9rem;
  color: var(--text-dim);
  white-space: nowrap;
  padding: 0 4px;
}

.sorting-arena {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
}
.sort-item {
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  background: var(--surface);
  border: 2px solid var(--surface2);
  border-radius: var(--radius);
  padding: 24px 20px;
  width: 100%;
  max-width: 280px;
  user-select: none;
  touch-action: none;
}

.sort-buttons {
  display: flex;
  gap: 10px;
}
.sort-btn {
  flex: 1;
  padding: 16px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius);
  color: #fff;
}
.sort-btn-a { background: var(--ans-r); }
.sort-btn-b { background: var(--ans-b); }

/* ── FINALE screen ───────────────────────────────────────────────────────── */
.finale-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.finale-steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.finale-step-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fs-avatar {
  font-size: 1.2rem;
  flex-shrink: 0;
}
.fs-bar-wrap {
  flex: 1;
  background: var(--surface2);
  border-radius: 4px;
  height: 10px;
  overflow: hidden;
}
.fs-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}
.fs-count {
  font-size: 0.8rem;
  color: var(--text-dim);
  width: 40px;
  text-align: right;
}
.finale-winner {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 600;
  color: #f39c12;
  padding: 10px 0;
}
.finale-fill { background: #f39c12; }
.finale-ans  {} /* inherits answer-btn styles */

/* ── GAME OVER screen ────────────────────────────────────────────────────── */
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  min-height: 160px;
}
.podium-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.podium-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.podium-name  { font-size: 0.85rem; font-weight: 600; text-align: center; }
.podium-score { font-size: 0.8rem; color: var(--text-dim); }
.podium-block {
  width: 100%;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.podium-rank { font-size: 1.3rem; padding: 6px 0; }
.podium-block-1 { height: 90px; background: #f39c12; }
.podium-block-2 { height: 65px; background: #7f8c8d; }
.podium-block-3 { height: 48px; background: #95744a; }

.final-scores {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  border: 1px solid transparent;
}
.score-row.score-me { border-color: var(--accent); }
.sr-rank  { font-size: 0.9rem; color: var(--text-dim); width: 22px; }
.sr-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sr-name  { flex: 1; font-size: 1rem; font-weight: 600; }
.sr-score { font-size: 1rem; font-weight: 600; color: var(--accent2); }

/* ── WAITING screen ──────────────────────────────────────────────────────── */
.waiting-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.spinner {
  width: 52px;
  height: 52px;
  border: 5px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.waiting-msg {
  font-size: 1.2rem;
  color: var(--text-dim);
  text-align: center;
  font-weight: 600;
}

/* ── SCROLL screen ───────────────────────────────────────────────────────── */
.scroll-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: center;
}
.scroll-text {
  font-size: 1.15rem;
  color: var(--text);
  line-height: 1.6;
  max-width: 340px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--surface2);
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* Safe area insets — already applied inline on .screen above; keep for legacy */

/* ═══════════════════════════════════════════════════════════════
   CLAY THEME OVERRIDES — last to win the cascade
   ═══════════════════════════════════════════════════════════════ */

body {
  background: radial-gradient(ellipse at 50% 20%, #fff3e0 0%, #ffe0c4 55%, #f5c9a0 100%) !important;
  color: #3d2200 !important;
}

h1 {
  background: none !important;
  -webkit-background-clip: unset !important;
  -webkit-text-fill-color: #5C3566 !important;
  background-clip: unset !important;
  color: #5C3566 !important;
  text-shadow: 0 4px 0 rgba(92,53,102,.2) !important;
}
h2, .screen-title { color: #5C3566 !important; }
.screen-sub { color: #8B7060 !important; }
.subtitle    { color: #8B7060 !important; }

/* Cards / panels */
.card {
  background: linear-gradient(145deg, #fff6ee, #ffe8cc) !important;
  border: 1px solid rgba(180,110,60,.18) !important;
  color: #3d2200 !important;
}
.card-label  { color: #8B4FBE !important; }
.field-label { color: #8B4FBE !important; }

/* Answer buttons — actual classes used in HTML are .answer-btn .ans-0/.ans-1 etc */
.answer-btn {
  border-radius: 18px !important;
  font-family: var(--font-head) !important;
  font-size: 1.05rem !important;
  font-weight: 800 !important;
  box-shadow: 0 7px 0 rgba(0,0,0,.22), 0 10px 20px rgba(0,0,0,.14) !important;
  transition: transform .08s, box-shadow .08s !important;
  text-shadow: 0 1px 3px rgba(0,0,0,.25) !important;
}
.answer-btn:active {
  transform: translateY(5px) scale(0.97) !important;
  box-shadow: 0 2px 0 rgba(0,0,0,.22) !important;
}
.ans-0 { background: linear-gradient(145deg, #ff9f91, #FF8C7A) !important; color: #fff !important; }
.ans-1 { background: linear-gradient(145deg, #6fb8ff, #4A9EFF) !important; color: #fff !important; }
.ans-2 { background: linear-gradient(145deg, #90e0b0, #5DC98A) !important; color: #fff !important; }
.ans-3 { background: linear-gradient(145deg, #ffe080, #FFD056) !important; color: #4a3000 !important; }

/* Category chip */
.q-category {
  background: rgba(139,79,190,.12) !important;
  color: #5C3566 !important;
  border: 1px solid rgba(139,79,190,.25) !important;
}
.answered-status { color: #8B7060 !important; }
.q-text { color: #3d2200 !important; font-weight: 700 !important; }

/* Timer bar */
.timer-fill { background: linear-gradient(90deg, #FF8C7A, #FFD56B) !important; }

/* Player chips */
.player-chip { background: linear-gradient(145deg, #fff0e0, #ffd9b8) !important; color: #3d2200 !important; }
.chip-name   { color: #3d2200 !important; }
.big-avatar  { box-shadow: 0 0 24px rgba(92,53,102,.35) !important; }

/* Waiting */
.waiting-msg { color: #8B7060 !important; }
.spinner { border-color: rgba(180,110,60,.2) !important; border-top-color: #8B4FBE !important; }

/* Vote doors */
.door-btn { border-radius: 20px !important; box-shadow: 0 7px 0 rgba(0,0,0,.18), 0 12px 24px rgba(0,0,0,.12) !important; }
.door-btn.my-vote { box-shadow: 0 0 0 4px #5C3566, 0 7px 0 rgba(0,0,0,.18) !important; }
.vote-status { color: #8B4FBE !important; }

/* Phone vote doors — clay tinted instead of saturated primary */
.door-btn {
  background: linear-gradient(145deg, #fff0e0, #ffd4a0) !important;
  color: #3d2200 !important;
  border: 2px solid rgba(180,110,60,.22) !important;
  box-shadow: 0 8px 20px rgba(120,80,40,.18), inset 0 3px 6px rgba(255,255,255,.6) !important;
}

/* Phone avatar buttons — clay */
.avatar-btn {
  background: linear-gradient(145deg, #fff0e0, #ffe0c4) !important;
  border: 3px solid rgba(180,110,60,.2) !important;
  border-radius: 16px !important;
  box-shadow: 0 4px 12px rgba(120,80,40,.15) !important;
  /* Don't override grid sizing — let the new grid rules control width */
}
.avatar-btn.selected, .avatar-btn:focus {
  border-color: #5C3566 !important;
  box-shadow: 0 4px 12px rgba(92,53,102,.3), 0 0 0 3px rgba(92,53,102,.2) !important;
}

/* Color swatches — let the grid control sizing, just enforce aspect-ratio */
.color-swatch { aspect-ratio: 1 !important; min-width: 40px !important; }

/* Reconnect banner */
.ws-reconnect-banner {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  background: linear-gradient(145deg, #ff8c6a, #e05030);
  color: #fff;
  text-align: center;
  padding: 10px 16px;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  animation: slideDown .3s ease;
}
body[data-ws-state="reconnecting"] .ws-reconnect-banner { display: block; }
body[data-ws-state="reconnecting"] .answer-btn,
body[data-ws-state="reconnecting"] .door-btn,
body[data-ws-state="reconnecting"] [data-cat] { opacity: 0.5; pointer-events: none; }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }

/* Score header bar */
.score-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: linear-gradient(145deg, rgba(255,240,224,.97), rgba(255,216,176,.97));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 2px solid rgba(180,110,60,.2);
  padding: 6px 16px;
  /* respect notch */
  padding-top: max(6px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: #3d2200;
  box-shadow: 0 4px 12px rgba(120,80,40,.12);
  /* height will be ~44px + safe-area */
}
.score-header .sh-avatar { font-size: 1.3rem; }
.score-header .sh-score { color: #5C3566; font-size: 1.1rem; }
.score-header .sh-rank { font-size: 0.85rem; color: #8a6040; }

/* All in-game screens need top padding to clear the fixed header */
#screen-question,
#screen-catevote,
#screen-powerplay,
#screen-target,
#screen-reveal,
#screen-linking,
#screen-sorting,
#screen-finale,
#screen-gameover,
#screen-waiting,
#screen-scroll {
  padding-top: calc(48px + env(safe-area-inset-top, 0px));
}

/* Hide on join/lobby screens */
#screen-join .score-header,
#screen-lobby .score-header { display: none !important; }

/* Numeric timer counter */
.timer-seconds {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: 'Bagel Fat One', cursive;
  font-size: 1rem;
  color: #3d2200;
  font-weight: 900;
  z-index: 2;
  pointer-events: none;
}
.timer-bar { position: relative; }
.timer-pulse { animation: timerPulse .5s ease-in-out infinite; }
@keyframes timerPulse {
  0%,100% { transform: scaleY(1); }
  50% { transform: scaleY(1.3); }
}

/* Answer lock confirmation */
.answer-locked-msg {
  text-align: center;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: #2ecc71;
  margin-top: 8px;
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* Power plays */
.pp-card {
  background: linear-gradient(145deg, #fff6ee, #ffe8cc) !important;
  border: 2px solid rgba(180,110,60,.18) !important;
  box-shadow: 0 6px 0 rgba(0,0,0,.14), 0 10px 20px var(--clay-shadow) !important;
  color: #3d2200 !important;
}
.pp-card:active { background: linear-gradient(145deg, #ffe8cc, #ffd0a0) !important; }
.pp-card-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.pp-card-name { color: #3d2200 !important; }
.pp-card-desc { color: #8B7060 !important; }

/* Target select */
.target-btn { background: linear-gradient(145deg, #fff6ee, #ffe8cc) !important; border-color: rgba(180,110,60,.2) !important; }
.target-name { color: #3d2200 !important; }

/* Reveal */
.reveal-verdict { color: #3d2200 !important; }
.reveal-points  { color: #8B7060 !important; }
.reveal-scores  { background: linear-gradient(145deg, #fff6ee, #ffe8cc) !important; }
.reveal-row     { color: #3d2200 !important; }
.rr-name        { color: #3d2200 !important; }
.rr-score       { color: #8B4FBE !important; }
.reveal-me      { background: rgba(139,79,190,.1) !important; border-color: #8B4FBE !important; }
.pts-gained     { color: #5DC98A !important; }

/* Linking */
.link-item { background: linear-gradient(145deg, #fff6ee, #ffe8cc) !important; border-color: rgba(180,110,60,.2) !important; color: #3d2200 !important; }
.link-item.selected { border-color: #8B4FBE !important; background: linear-gradient(145deg, #f0e0ff, #e8d0f8) !important; }
.link-item.paired   { border-color: #5DC98A !important; background: rgba(93,201,138,.1) !important; }

/* Sorting */
.sort-item { background: linear-gradient(145deg, #fff6ee, #ffe8cc) !important; border-color: rgba(180,110,60,.2) !important; color: #3d2200 !important; }

/* Scoreboard */
.score-row        { background: linear-gradient(145deg, #fff6ee, #ffe8cc) !important; border-color: rgba(180,110,60,.12) !important; color: #3d2200 !important; }
.score-row.score-me { border-color: #8B4FBE !important; }
.sr-name          { color: #3d2200 !important; }
.sr-score         { color: #8B4FBE !important; }

/* Scroll */
.scroll-text { background: linear-gradient(145deg, #fff6ee, #ffe8cc) !important; border-color: rgba(180,110,60,.18) !important; color: #3d2200 !important; }

/* Input */
input[type=text]:focus { border-color: #8B4FBE !important; }

/* Skip btn */
.btn-skip { background: rgba(180,110,60,.12) !important; color: #8B7060 !important; border: 2px solid rgba(180,110,60,.2) !important; border-radius: 999px !important; }
