/* ==========================================================================
   +Carrera- — Styles
   Same visual language (topbar/controls/panels/overlay) as the other
   dundilgame games, adapted for a winding race board + a 3D dice tray.
   ========================================================================== */

:root {
  --bg-base: #140f2b;
  /* One diffused corner glow per team, set from each team's theme colours
     in JS (applyTeamBackgrounds). These are the pre-pick fallbacks. */
  --t1: 59, 130, 246;
  --t2: 239, 68, 68;
  --t3: 34, 197, 94;
  --t4: 250, 204, 21;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-solid: #241f3d;
  --text: #f5f3ff;
  --text-dim: #c4b5fd;
  --accent: #fbbf24;
  --accent-2: #34d399;
  --turn-color: #3b82f6;
  --radius: 16px;
  --topbar-h: 72px;
  --tray: 160px;
  --die: 84px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-base);
  background-image:
    radial-gradient(circle at 0% 0%, rgba(var(--t1), 0.55) 0%, rgba(var(--t1), 0) 55%),
    radial-gradient(circle at 100% 0%, rgba(var(--t2), 0.55) 0%, rgba(var(--t2), 0) 55%),
    radial-gradient(circle at 0% 100%, rgba(var(--t3), 0.45) 0%, rgba(var(--t3), 0) 55%),
    radial-gradient(circle at 100% 100%, rgba(var(--t4), 0.45) 0%, rgba(var(--t4), 0) 55%);
  background-attachment: fixed;
  color: var(--text);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------------- */
/* Top bar (shared chrome)                                                 */
/* ---------------------------------------------------------------------- */

.topbar {
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 10px 20px 10px 200px;
  background-color: #0c0c12;
  background-image:
    linear-gradient(rgba(8, 6, 16, 0.6), rgba(8, 6, 16, 0.6)),
    url("../../assets/textures/carbon-fiber.jpg");
  background-repeat: no-repeat, repeat;
  background-size: cover, 180px 135px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
  position: fixed;
  top: 12px;
  left: 18px;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-link { display: block; line-height: 0; transition: opacity 0.15s ease; }
.brand-link:hover { opacity: 0.85; }

.brand-logo {
  height: 44px;
  width: auto;
  display: block;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
}

.brand-link-mobile { display: none; }

.brand-home-icon {
  display: block;
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 18px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #f59e0b);
  color: #1a1a1a;
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 18px;
  padding: 10px 14px;
}

.btn-ghost.off { opacity: 0.5; }

/* ---------------------------------------------------------------------- */
/* Stats bar: one chip per team                                            */
/* ---------------------------------------------------------------------- */

.statsbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  padding: 6px 16px;
  background: rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.team-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  border: 3px solid transparent;
  opacity: 0.6;
  transition: transform 0.2s ease, opacity 0.2s ease, border-color 0.2s ease;
}

.team-chip.current {
  opacity: 1;
  border-color: var(--chip-color);
  transform: scale(1.08);
  box-shadow: 0 0 16px var(--chip-color);
}

.team-chip .mini-token {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 0 0 3px var(--chip-color);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.mini-token img { width: 82%; height: 82%; object-fit: contain; }
.mini-token .emoji { font-size: 24px; line-height: 1; }

.team-chip-text { display: flex; flex-direction: column; line-height: 1.15; }
.team-chip-name { font-weight: 800; font-size: 14px; }
.team-chip-pos { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------- */
/* Main area                                                               */
/* ---------------------------------------------------------------------- */

#mainArea {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow: hidden;
}

.info-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 720px;
  margin: auto;
}

.info-panel h2 { margin: 0; font-size: 26px; }

.info-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Spoken-text caption (also helps grown-ups follow along) */
.caption {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -6px);
  max-width: min(98%, 980px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 6px 18px;
  border-radius: 999px;
  background: rgba(10, 8, 25, 0.82);
  border: 2px solid var(--turn-color);
  font-size: clamp(13px, 1.8vw, 19px);
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 20;
}

.caption.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------------- */
/* Dice tray (bottom-right corner)                                         */
/* ---------------------------------------------------------------------- */

.dice-tray {
  position: absolute;
  right: 0;
  bottom: 0;
  width: var(--tray);
  height: var(--tray);
  border-radius: 26px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.35)),
    #1f1840;
  border: 4px solid var(--turn-color);
  box-shadow: 0 0 22px var(--turn-color), inset 0 0 30px rgba(0, 0, 0, 0.5);
  touch-action: none;
  cursor: grab;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
  z-index: 10;
}

.dice-tray.dragging { cursor: grabbing; }

.dice-tray.disabled {
  cursor: default;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5);
  border-color: rgba(255, 255, 255, 0.15);
}

.dice-tray.ready { animation: trayReady 1.6s ease-in-out infinite; }

@keyframes trayReady {
  0%, 100% { box-shadow: 0 0 14px var(--turn-color), inset 0 0 30px rgba(0, 0, 0, 0.5); }
  50% { box-shadow: 0 0 34px var(--turn-color), inset 0 0 30px rgba(0, 0, 0, 0.5); }
}

.dice-turn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: calc(var(--tray) * 0.24);
  height: calc(var(--tray) * 0.24);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px var(--turn-color);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}

.dice-turn img { width: 84%; height: 84%; object-fit: contain; }
.dice-turn .emoji { font-size: calc(var(--tray) * 0.14); }

.dice-shadow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--die) * 1.1);
  height: calc(var(--die) * 0.32);
  margin-left: calc(var(--die) * -0.55);
  margin-top: calc(var(--die) * 0.48);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0) 70%);
  pointer-events: none;
}

.dice-scene {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--die);
  height: var(--die);
  margin-left: calc(var(--die) / -2);
  margin-top: calc(var(--die) / -2);
  perspective: calc(var(--die) * 7);
  pointer-events: none;
}

.dice-bob, .dice-tilt, .dice-cube {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

/* A slight fixed viewing angle so the die always reads as a 3D cube; the
   face that counts is the one pointing at the viewer (front). */
.dice-tilt { transform: rotateX(-16deg) rotateY(16deg); }

.dice-face {
  position: absolute;
  inset: 0;
  border-radius: 16%;
  background: linear-gradient(145deg, #ffffff, #e7e3f5);
  box-shadow: inset 0 0 calc(var(--die) * 0.12) rgba(80, 60, 140, 0.35);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 13%;
  backface-visibility: hidden;
}

.dice-face.result {
  background: linear-gradient(145deg, #fffbea, #fde68a);
}

.pip-cell { display: flex; align-items: center; justify-content: center; }

.pip {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  background: var(--pip-color, #3b82f6);
  box-shadow: inset 0 calc(var(--die) * -0.02) 0 rgba(0, 0, 0, 0.3);
}

.dice-face.single .pip { width: 110%; height: 110%; }

.dice-hint {
  position: absolute;
  right: 8%;
  bottom: 6%;
  font-size: calc(var(--tray) * 0.2);
  pointer-events: none;
  opacity: 0;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.dice-tray.ready .dice-hint {
  opacity: 1;
  animation: swipeHint 2s ease-in-out infinite;
}

@keyframes swipeHint {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  15% { opacity: 1; }
  55% { transform: translate(-90%, -70%) rotate(-18deg); opacity: 1; }
  75%, 100% { transform: translate(-110%, -85%) rotate(-18deg); opacity: 0; }
}

.roll-bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  min-width: calc(var(--tray) * 0.62);
  padding: 6px 14px;
  border-radius: 22px;
  background: #fff;
  color: #1a1a1a;
  border: 4px solid var(--turn-color);
  text-align: center;
  font-weight: 900;
  font-size: calc(var(--tray) * 0.34);
  line-height: 1.05;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  animation: bubblePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.roll-bubble .bubble-pips {
  display: block;
  font-size: calc(var(--tray) * 0.1);
  letter-spacing: 2px;
  color: var(--turn-color);
}

@keyframes bubblePop {
  0% { transform: translateX(-50%) scale(0.3); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ---------------------------------------------------------------------- */
/* Quiz overlay                                                            */
/* ---------------------------------------------------------------------- */

.quiz-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 5, 30, 0.75);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.25s ease;
}

.quiz-card {
  width: min(760px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px 22px 24px;
  border-radius: 26px;
  background: linear-gradient(160deg, #312e81, #581c87);
  border: 4px solid var(--turn-color);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: winPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quiz-badge {
  font-size: 20px;
  font-weight: 900;
  color: var(--accent);
}

.quiz-card h2 {
  margin: 8px 0 14px;
  font-size: clamp(24px, 4.5vw, 40px);
}

.quiz-stage {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
}

.quiz-stage:empty { display: none; }

.stage-item {
  position: relative;
  width: clamp(64px, 13vw, 104px);
  height: clamp(64px, 13vw, 104px);
  border-radius: 22%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
  animation: winPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stage-item img { width: 88%; height: 88%; object-fit: contain; }
.stage-item .emoji { font-size: clamp(36px, 7vw, 60px); }

.stage-item.counted {
  transform: scale(1.12);
  box-shadow: 0 0 0 5px var(--accent), 0 0 20px var(--accent);
}

.stage-item .count-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(30px, 6vw, 54px);
  font-weight: 900;
  color: #fff;
  background: rgba(245, 158, 11, 0.6);
  -webkit-text-stroke: 2px rgba(0, 0, 0, 0.35);
}

.quiz-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(10px, 3vw, 24px);
}

.quiz-option {
  appearance: none;
  border: 5px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.95);
  color: #1a1a1a;
  font: inherit;
  width: clamp(96px, 22vw, 160px);
  height: clamp(96px, 22vw, 160px);
  border-radius: 24%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  padding: 8px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, opacity 0.2s ease, border-color 0.2s ease;
  touch-action: manipulation;
}

.quiz-option:hover { transform: translateY(-4px); }

.quiz-option img { width: 86%; height: 86%; object-fit: contain; pointer-events: none; }
.quiz-option .emoji { font-size: clamp(48px, 11vw, 90px); line-height: 1; }
.quiz-option svg { width: 80%; height: 80%; }

.quiz-option .num {
  font-size: clamp(44px, 10vw, 80px);
  font-weight: 900;
  line-height: 1;
}

.quiz-option .num-dots {
  font-size: clamp(11px, 2.2vw, 16px);
  letter-spacing: 1px;
  color: #6d28d9;
}

.quiz-option.color-blob {
  border-radius: 50%;
  background: var(--blob);
  border-color: rgba(255, 255, 255, 0.6);
}

.quiz-option.wrong {
  animation: shake 0.45s ease;
  opacity: 0.35;
  pointer-events: none;
}

.quiz-option.correct {
  border-color: #22c55e;
  box-shadow: 0 0 0 6px #22c55e, 0 0 30px #22c55e;
  transform: scale(1.1);
}

.quiz-options.done .quiz-option:not(.correct) { opacity: 0.3; pointer-events: none; }
.quiz-options.done .quiz-option.correct { pointer-events: none; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px) rotate(-4deg); }
  40% { transform: translateX(12px) rotate(4deg); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(8px); }
}

/* ---------------------------------------------------------------------- */
/* Win overlay + confetti                                                  */
/* ---------------------------------------------------------------------- */

.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 5, 30, 0.82);
  backdrop-filter: blur(4px);
  cursor: pointer;
  touch-action: manipulation;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.win-content {
  text-align: center;
  padding: 40px 56px;
  border-radius: 24px;
  background: linear-gradient(160deg, #312e81, #581c87);
  border: 4px solid var(--turn-color);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: winPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90vw;
}

@keyframes winPop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.win-token {
  width: 130px;
  height: 130px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 8px var(--turn-color), 0 0 40px var(--turn-color);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  animation: winBounce 1s ease-in-out infinite;
}

.win-token img { width: 84%; height: 84%; object-fit: contain; }
.win-token .emoji { font-size: 76px; }

@keyframes winBounce {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-14px) rotate(4deg); }
}

.win-content h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 5vw, 48px);
  color: var(--accent);
}

.win-content p {
  margin: 4px 0;
  font-size: clamp(16px, 2.2vw, 22px);
}

.win-stats { color: var(--text-dim); font-size: clamp(14px, 2vw, 18px) !important; }

.win-tap {
  margin-top: 18px !important;
  font-weight: 700;
  color: var(--accent-2);
  animation: tapPulse 1.4s ease-in-out infinite;
}

@keyframes tapPulse { 0%, 100% { opacity: 0.7; } 50% { opacity: 1; } }

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  animation: confettiFall var(--dur) linear forwards;
  animation-delay: var(--delay);
}

@keyframes confettiFall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--drift), 110vh) rotate(var(--rot)); opacity: 0.8; }
}

/* ---------------------------------------------------------------------- */
/* Small screens                                                           */
/* ---------------------------------------------------------------------- */

@media (max-width: 640px) {
  .topbar { padding: 8px 10px; }

  .brand { position: static; }
  .brand-link-desktop { display: none; }

  .brand-link-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.12);
  }

  .btn { padding: 8px 12px; font-size: 13px; min-height: 36px; }
  .btn-label { display: none; }
  .btn-start { font-size: 17px; }

  .statsbar { gap: 6px; padding: 4px 8px; min-height: 48px; }
  .team-chip { padding: 2px 8px 2px 2px; gap: 5px; }
  .team-chip .mini-token { width: 30px; height: 30px; }
  .team-chip-name { font-size: 12px; }
  .team-chip-pos { font-size: 11px; }

  .theme-grid, .theme-row { gap: 8px; }
  .theme-tile { width: 76px; padding: 5px; }
  .theme-tile-label { font-size: 11px; }
  .theme-tile-thumb .emoji { font-size: 34px; }

  .caption {
    font-size: 13px;
    padding: 5px 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .win-content { padding: 28px 22px; }
  .quiz-card { padding: 14px 12px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .square.type-star .sq-icon,
  .square.type-quiz .sq-icon,
  .square.type-goal,
  .token.current .fig-turn,
  .token.current .figure-base,
  .dice-tray.ready { animation: none; }
}

/* ---------------------------------------------------------------------- */
/* Player picker                                                           */
/* ---------------------------------------------------------------------- */

.player-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 920px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  padding: 8px;
  text-align: center;
}

.player-picker h1 { margin: 0; font-size: clamp(22px, 4vw, 34px); }
.picker-subtitle { margin: 0; color: var(--text-dim); font-size: 15px; }

.count-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }

.count-btn {
  appearance: none;
  border: 3px solid rgba(255, 255, 255, 0.15);
  background: var(--panel-solid);
  color: var(--text);
  border-radius: 16px;
  padding: 10px 14px;
  min-width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font: inherit;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.count-btn:hover { transform: translateY(-3px); }
.count-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35); }
.count-num { font-size: 34px; font-weight: 900; line-height: 1; }
.count-tokens { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; max-width: 92px; }

.picker-preview { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; margin: 8px 0 4px; }

.preview-chip { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 800; }

.rules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  text-align: left;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 14px;
  padding: 12px 16px;
  max-width: 760px;
}

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

.rule-sq {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 16px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

/* ---------------------------------------------------------------------- */
/* Game view + snake board                                                 */
/* ---------------------------------------------------------------------- */

.game-view {
  position: absolute;
  inset: 14px;
  /* own stacking context: towers (z-index by depth) never rise above overlays */
  isolation: isolate;
  z-index: 0;
}

.board { position: absolute; }

.track {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.4));
}

.board-squares, .board-tokens { position: absolute; inset: 0; }
.board-tokens { pointer-events: none; }

.square {
  position: absolute;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 calc(var(--sq) * -0.07) 0 rgba(0, 0, 0, 0.25), 0 3px 5px rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.75);
  transition: transform 0.2s ease;
}

.square.flash { animation: squareFlash 0.7s ease; }

@keyframes squareFlash {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.18); box-shadow: 0 0 0 4px #fff, 0 0 24px rgba(255, 255, 255, 0.9); }
}

.sq-label {
  font-weight: 900;
  font-size: calc(var(--sq) * 0.38);
  line-height: 1;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.sq-num {
  position: absolute;
  bottom: -2px;
  right: -2px;
  min-width: calc(var(--sq) * 0.36);
  height: calc(var(--sq) * 0.36);
  padding: 0 2px;
  border-radius: 999px;
  background: rgba(10, 8, 25, 0.75);
  color: #fff;
  font-size: calc(var(--sq) * 0.2);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sq-plus, .rule-sq.sq-plus { background: radial-gradient(circle at 35% 30%, #69db7c, #2b8a3e); }
.sq-minus, .rule-sq.sq-minus { background: radial-gradient(circle at 35% 30%, #ff8787, #c92a2a); }
.sq-siesta, .rule-sq.sq-siesta { background: radial-gradient(circle at 35% 30%, #b197fc, #5f3dc4); }
.sq-siesta .sq-label { font-size: calc(var(--sq) * 0.48); }
.sq-start { background: radial-gradient(circle at 35% 30%, #fff3bf, #f59f00); }
.sq-start .sq-label { font-size: calc(var(--sq) * 0.19); color: #7c2d12; text-shadow: none; }
.sq-goal, .rule-sq.sq-goal {
  background: radial-gradient(circle at 35% 30%, #fff3bf, #fab005 60%, #e8590c);
  animation: goalGlow 2s ease-in-out infinite;
}
.sq-goal .sq-label { font-size: calc(var(--sq) * 0.5); }

@keyframes goalGlow {
  0%, 100% { box-shadow: 0 0 0 3px #fff, 0 0 14px rgba(250, 204, 21, 0.6); }
  50% { box-shadow: 0 0 0 3px #fff, 0 0 32px rgba(250, 204, 21, 1); }
}

.hop-number {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: calc(var(--sq) * 0.55);
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 2px rgba(0, 0, 0, 0.45);
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: hopNumber 0.9s ease-out forwards;
  z-index: 999;
}

@keyframes hopNumber {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.5); }
  25% { opacity: 1; transform: translate(-50%, -140%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -200%) scale(1); }
}

/* ---------------------------------------------------------------------- */
/* Player tokens on the board (.tower = a player's token on its square)    */
/* ---------------------------------------------------------------------- */

.tower {
  position: absolute;
  width: var(--tw);
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: left 0.34s ease-in-out, top 0.34s ease-in-out, width 0.25s ease;
  pointer-events: none;
}

.tower.no-anim { transition: none; }

/* a new floor of regletas drops onto the wall and clicks into place */
@keyframes snapIn {
  0% { transform: translateY(-160%); opacity: 0.4; }
  60% { transform: translateY(6%) scaleY(0.86); opacity: 1; }
  100% { transform: translateY(0) scaleY(1); }
}

.tower-zzz {
  position: absolute;
  top: -10px;
  right: -14px;
  font-size: max(14px, calc(var(--tw) * 0.5));
  display: none;
  animation: zzz 1.6s ease-in-out infinite;
}

.tower.sleeping .tower-zzz { display: block; }
.tower.sleeping { filter: saturate(0.6) brightness(0.85); }

@keyframes zzz {
  0%, 100% { transform: translate(0, 0); opacity: 0.6; }
  50% { transform: translate(4px, -8px); opacity: 1; }
}

/* ---------------------------------------------------------------------- */
/* Player boxes: one per player, each in its own fixed corner (red top-    */
/* left, green top-right, blue bottom-left, yellow bottom-right), with the */
/* player's points and their wall of regletas.                             */
/* ---------------------------------------------------------------------- */

.player-boxes { position: absolute; inset: 0; pointer-events: none; z-index: 10; }

.player-box {
  position: absolute;
  width: var(--tray);
  height: var(--boxh);
  padding: 6px;
  border-radius: 18px;
  background: rgba(20, 15, 45, 0.88);
  border: 4px solid var(--player);
  box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  pointer-events: auto;
  opacity: 0.75;
  transition: opacity 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.player-box.corner-tl { left: 0; top: 0; }
.player-box.corner-tr { right: 0; top: 0; }
.player-box.corner-bl { left: 0; bottom: 0; }
.player-box.corner-br { right: 0; bottom: 0; }

.player-box.current { opacity: 1; box-shadow: 0 0 18px var(--player), inset 0 0 14px rgba(0, 0, 0, 0.5); }

.box-name { font-size: calc(var(--tray) * 0.12); font-weight: 900; line-height: 1.1; }

/* the die: bottom centre, it never leaves its place */
.game-view .dice-tray { left: 50%; right: auto; bottom: 0; transform: translateX(-50%); }

/* the caption sits between the two top boxes */
.game-view .caption { max-width: calc(100% - 2 * var(--tray) - 24px); }
.game-view.layout-stack .caption {
  top: calc(var(--boxh) / 2);
  white-space: normal;
  overflow: visible;
  line-height: 1.2;
  transform: translate(-50%, -50%);
}
.game-view.layout-stack .caption.show { transform: translate(-50%, -50%); }

/* ---------------------------------------------------------------------- */
/* Live standings: one info card per player, in race order. When somebody */
/* overtakes, the cards slide past each other (FLIP animation in JS).     */
/* ---------------------------------------------------------------------- */

.statsbar.standings, .statsbar {
  flex-wrap: nowrap;
  gap: 8px;
  padding: 6px 10px;
  min-height: 0;
}

.info-card {
  position: relative;
  flex: 0 1 250px;
  min-width: 0;
  display: flex;
  align-items: stretch;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(10, 8, 25, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  will-change: transform;
}

.info-card.current { border-color: var(--chip-color); box-shadow: 0 0 14px var(--chip-color); }
.info-card.finished { background: linear-gradient(90deg, rgba(250, 204, 21, 0.25), rgba(10, 8, 25, 0.82) 60%); }

.card-pos {
  flex: none;
  width: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--chip-color);
  color: #fff;
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.45);
}
.card-pos-num { font-size: 24px; font-weight: 900; line-height: 1; }
.card-move { font-size: 12px; line-height: 1; height: 12px; font-weight: 900; }
.card-move.up { color: #b2f2bb; animation: moveBlink 0.5s ease 3; }
.card-move.down { color: #ffc9c9; animation: moveBlink 0.5s ease 3; }

@keyframes moveBlink { 50% { opacity: 0.2; } }

.card-body { flex: 1; min-width: 0; padding: 4px 8px; display: flex; flex-direction: column; justify-content: center; gap: 1px; }
.card-name { display: flex; align-items: center; gap: 6px; font-weight: 900; font-size: 15px; line-height: 1.15; white-space: nowrap; }
.card-stats { display: flex; gap: 8px; font-size: 13px; white-space: nowrap; }
.card-stats b { font-variant-numeric: tabular-nums; }
.card-where { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card-points {
  flex: none;
  min-width: 52px;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  line-height: 1;
}
.card-points b { font-size: 22px; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; }
.card-points small { font-size: 10px; color: var(--text-dim); }

@media (max-width: 760px) {
  /* two rows of two cards */
  .statsbar { flex-wrap: wrap; gap: 4px; padding: 4px; }
  .info-card { flex: 0 0 calc(50% - 2px); }
  .card-pos { width: 26px; }
  .card-pos-num { font-size: 18px; }
  .card-body { padding: 2px 6px; }
  .card-name { font-size: 12px; gap: 4px; }
  .card-stats { gap: 5px; font-size: 11px; }
  .card-where { display: none; }
  .card-points { min-width: 38px; padding: 0 5px; }
  .card-points b { font-size: 17px; }
  .card-points small { font-size: 8px; }
}

/* ---------------------------------------------------------------------- */
/* Points on the start screen, after an operation and at the end           */
/* ---------------------------------------------------------------------- */

.rule-wide { grid-column: 1 / -1; font-weight: 800; }
.rule-sq.sq-op { background: radial-gradient(circle at 35% 30%, #74c0fc, #1864ab); }

.points-rules {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 10px;
  max-width: 760px;
}
.pt-rule {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 13px;
}
.pt-rule b, .rank-parts span, .op-points { font-weight: 900; }
.pos { color: #69db7c; }
.neg { color: #ff8787; }

.op-points { display: block; font-size: clamp(18px, 3vw, 26px); margin-top: 2px; }

.win-ranking li { flex-direction: column; align-items: stretch; gap: 2px; }
.rank-main { display: flex; align-items: center; gap: 10px; }
.rank-parts { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; padding-left: 34px; }

/* ---------------------------------------------------------------------- */
/* Stats bar chips, dice turn badge                                        */
/* ---------------------------------------------------------------------- */
.chip-count {
  min-width: 30px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff;
  color: #1a1a1a;
  font-weight: 900;
  text-align: center;
}
.dice-turn { background: rgba(255, 255, 255, 0.92); }

/* ---------------------------------------------------------------------- */
/* Siesta operations                                                       */
/* ---------------------------------------------------------------------- */

.op-text { font-size: clamp(40px, 9vw, 76px); font-weight: 900; letter-spacing: 2px; }
.op-text b { color: #69db7c; }

/* ---------------------------------------------------------------------- */
/* End of game                                                             */
/* ---------------------------------------------------------------------- */

.win-tower { display: flex; justify-content: center; gap: 22px; margin-bottom: 10px; }
.win-stack { display: flex; flex-direction: column-reverse; align-items: center; animation: winBounce 1s ease-in-out infinite; }

@keyframes winBounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}

.win-ranking { list-style: none; padding: 0; margin: 10px auto 0; max-width: 360px; text-align: left; }
.win-ranking li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  margin: 6px 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-left: 8px solid var(--chip-color);
  font-size: 18px;
}
.rank-name { flex: 1; font-weight: 800; }
.rank-count { font-weight: 900; color: var(--accent); }

@media (max-width: 640px) {
  .rules { grid-template-columns: 1fr; font-size: 13px; }
  .count-btn { min-width: 70px; padding: 8px; }
  .count-num { font-size: 26px; }
}

/* the 4 answers always fit in one row */
.quiz-options { flex-wrap: nowrap; }
.quiz-options .quiz-option { width: clamp(64px, 18vw, 140px); height: clamp(64px, 18vw, 140px); }

/* ---------------------------------------------------------------------- */
/* Countdown bar: 3 parts worth +3 / +2 / +1; the dark fill eats the time */
/* ---------------------------------------------------------------------- */

.quiz-timer {
  position: relative;
  display: flex;
  width: min(100%, 520px);
  height: 28px;
  margin: 4px auto 10px;
  border-radius: 999px;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: linear-gradient(90deg, #40c057, #fab005 50%, #fa5252);
}
.quiz-timer.thirds { background: none; }
.qt-seg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  transition: transform 0.2s ease;
}
.qt-seg:nth-child(1) { background: #2f9e44; }
.qt-seg:nth-child(2) { background: #f08c00; border-left: 2px solid #fff; }
.qt-seg:nth-child(3) { background: #e03131; border-left: 2px solid #fff; }
.quiz-timer[data-third="0"] .qt-seg:nth-child(1),
.quiz-timer[data-third="1"] .qt-seg:nth-child(2),
.quiz-timer[data-third="2"] .qt-seg:nth-child(3) { font-size: 19px; }
.qt-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  background: rgba(10, 8, 25, 0.78);
  pointer-events: none;
}

/* ---------------------------------------------------------------------- */
/* Who starts: picker option + quick-operation buzzers                     */
/* ---------------------------------------------------------------------- */

.start-mode { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.start-mode-title { font-weight: 900; font-size: 16px; }
.start-mode-grid { display: flex; gap: 8px; }
.mode-btn {
  appearance: none;
  font: inherit;
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
  background: var(--panel-solid);
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 8px 14px;
  cursor: pointer;
}
.mode-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35); }

.buzz-info { margin: 4px 0 0; font-size: clamp(15px, 2.4vw, 20px); font-weight: 800; text-align: center; }
.buzz-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 8px 0 12px; }
.buzz-btn {
  appearance: none;
  font: inherit;
  min-width: clamp(96px, 20vw, 150px);
  padding: 12px 14px 10px;
  border-radius: 20px;
  border: 4px solid #fff;
  background: linear-gradient(180deg, color-mix(in srgb, var(--player) 75%, #fff), var(--player-dark));
  color: #fff;
  font-weight: 900;
  font-size: clamp(15px, 2.4vw, 20px);
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.1s ease, opacity 0.2s ease;
}
.buzz-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
.buzz-btn:disabled { cursor: default; opacity: 0.45; }
.buzz-btn.pressed { opacity: 1; transform: scale(1.1); box-shadow: 0 0 26px var(--player); }
.buzz-btn.out { filter: grayscale(1); }

/* ---------------------------------------------------------------------- */
/* Regletas: smooth wooden rods in the classic Cuisenaire colours          */
/* (size from --u: one unit of length)                                     */
/* ---------------------------------------------------------------------- */

.rod {
  --u: 28px;
  position: relative;
  flex: none;
  width: calc(var(--u) * var(--n));
  height: var(--u);
  border-radius: calc(var(--u) * 0.14);
  background: linear-gradient(180deg, color-mix(in srgb, var(--rod) 72%, #fff) 0%, var(--rod) 40%, var(--rod-dark) 100%);
  box-shadow: inset 0 calc(var(--u) * -0.08) 0 rgba(0, 0, 0, 0.22), inset 0 0 0 1px rgba(0, 0, 0, 0.25), 0 2px 3px rgba(0, 0, 0, 0.35);
}
.rod-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: calc(var(--u) * 0.55);
  color: var(--rod-ink);
}

/* the operation drawn with regletas */
.rod-op { --u: 28px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin: 0 auto; }
.rod-op .rod { --u: inherit; }
.rod-row { display: flex; align-items: flex-end; gap: 0; }
.rod-row .rod.second { margin-left: calc(var(--u) * 0.5); }
.rod-row.take .rod { opacity: 0.55; outline: 2px dashed #fff; outline-offset: -3px; }

/* ---------------------------------------------------------------------- */
/* Building the result with regletas                                       */
/* ---------------------------------------------------------------------- */

.build-area { --u: 34px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.build-area .rod { --u: inherit; }
.build-title { font-size: clamp(26px, 5vw, 44px); font-weight: 900; }
.build-title b { color: var(--accent); font-size: 1.2em; }

/* the gap to fill: exactly n units long */
.build-gap {
  width: calc(var(--u) * var(--n) + 12px);
  min-height: calc(var(--u) * 1.4 + 12px);
  padding: 6px;
  border-radius: 12px;
  border: 3px dashed rgba(255, 255, 255, 0.85);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.12) 0 1px, transparent 1px var(--u)) 6px 0 / calc(100% - 12px) 100% no-repeat,
    rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: flex-end;
}
.build-placed { display: flex; align-items: flex-end; }
.build-placed .rod { cursor: pointer; animation: rodIn 0.25s ease-out; }
.build-area.done .build-gap { border-style: solid; border-color: #69db7c; box-shadow: 0 0 20px rgba(105, 219, 124, 0.7); }

@keyframes rodIn {
  0% { transform: translateY(-60%); opacity: 0.3; }
  100% { transform: translateY(0); opacity: 1; }
}

.build-palette { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 8px 10px; max-width: 100%; }
.build-palette .rod { cursor: pointer; transition: transform 0.12s ease; }
.build-palette .rod:hover { transform: translateY(-3px); }
.build-palette .rod:active { transform: translateY(2px); }
.rod.nofit { animation: noFit 0.4s ease; }

@keyframes noFit {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.build-help { margin: 0; font-size: 13px; color: var(--text-dim); }

/* ---------------------------------------------------------------------- */
/* Floors: towers on the board, walls in the boxes, end screen             */
/* ---------------------------------------------------------------------- */

.wall-floor {
  display: flex;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3);
}
.wall-floor > span { box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.35); }
.wall-floor.snap-in { animation: snapIn 0.38s cubic-bezier(0.3, 0.7, 0.4, 1.4); }
.tower { --tw: 30px; }

.player-box { justify-content: flex-start; gap: 4px; opacity: 0.8; }
.box-head { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.box-name { font-size: calc(var(--tray) * 0.11); font-weight: 900; }
.box-total {
  min-width: 26px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--player);
  color: #fff;
  font-weight: 900;
  font-size: calc(var(--tray) * 0.1);
  text-align: center;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}
.box-wall {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 1px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 3px;
}
.wall-floor {
  flex: 0 1 calc(var(--tray) * 0.09);
  min-height: 2px;
  width: calc(100% * var(--total) / 14);
  border-radius: 2px;
}

.win-stack { gap: 2px; flex-direction: column-reverse; }

.sq-op, .rule-sq.sq-op { background: radial-gradient(circle at 35% 30%, #74c0fc, #1864ab); }
.sq-op .sq-label { font-size: calc(var(--sq) * 0.42); }
.rule-sq.sq-build { background: radial-gradient(circle at 35% 30%, #ffd8a8, #e8590c); }
/* bigger tap targets for small fingers */
.build-palette .rod { height: max(var(--u), 30px); }

.sq-op .sq-label, .rule-sq.sq-op { font-size: calc(var(--sq) * 0.55); font-weight: 900; }
.rule-sq.sq-op { font-size: 24px; color: #fff; }

/* ---------------------------------------------------------------------- */
/* Design round: square colours, wooden regletas, player panel             */
/* ---------------------------------------------------------------------- */

/* normal squares orange, siestas pastel blue */
.sq-op, .rule-sq.sq-op { background: radial-gradient(circle at 35% 30%, #ffc078, #fd7e14 55%, #d9480f); }
.sq-siesta, .rule-sq.sq-siesta { background: radial-gradient(circle at 35% 30%, #e7f5ff, #a5d8ff 55%, #74c0fc); }
.sq-siesta .sq-label { text-shadow: none; }

/* regletas: their colour with a light wood grain, matte like real wood */
.rod {
  background:
    repeating-linear-gradient(178.5deg, rgba(60, 30, 0, 0.07) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(181.2deg, rgba(255, 255, 255, 0.07) 0 2px, transparent 2px 7px),
    linear-gradient(180deg, color-mix(in srgb, var(--rod) 85%, #fff) 0%, var(--rod) 50%, color-mix(in srgb, var(--rod) 82%, #000) 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 3px rgba(0, 0, 0, 0.35);
}

/* the operation happens in the player's box, grown and brought to the
   centre, low on the screen (the standings stay visible above) */
.quiz-overlay.panel {
  align-items: flex-end;
  padding-bottom: 2vh;
  background: rgba(10, 5, 30, 0.45);
  backdrop-filter: none;
  animation: fadeIn 0.3s ease;
}
.quiz-overlay.panel .quiz-card {
  animation: none;
  border: 5px solid var(--panel-color);
  background: rgba(20, 15, 45, 0.97);
  box-shadow: 0 0 30px var(--panel-color), 0 20px 60px rgba(0, 0, 0, 0.5);
  max-height: calc(100% - 2vh);
}
.quiz-overlay.panel .quiz-badge { color: #fff; background: var(--panel-color); padding: 3px 12px; border-radius: 999px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }
.player-box.opened { opacity: 0.35; }

/* the regletas as a staircase: 1 (white) at the top … 10 (orange) at the
   bottom, left-aligned with the gap so lengths can be compared */
.build-area { align-items: flex-start; width: fit-content; max-width: 100%; margin: 0 auto; }
.build-palette { flex-direction: column; align-items: flex-start; flex-wrap: nowrap; gap: 4px; padding-left: 9px; }
.build-help { align-self: center; }

.done-btn { display: block; margin: 14px auto 0; font-size: 20px; padding: 10px 28px; }
.done-btn.hidden { display: none; }

/* ---------------------------------------------------------------------- */
/* Player tokens: a shape in each colour (red square, green diamond, blue  */
/* circle, yellow triangle)                                                */
/* ---------------------------------------------------------------------- */

.token-shape { display: inline-block; flex: none; line-height: 0; }
.token-shape svg { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45)); }
.token-shape.mini { width: 20px; height: 20px; }
.token-shape.preview-token { width: 56px; height: 56px; }
.token-shape.box-token { width: 1.1em; height: 1.1em; margin-right: 5px; vertical-align: -0.15em; }
.token-shape.turn-token { width: 70%; height: 70%; }
.token-shape.buzz-token { width: 46px; height: 46px; }
.token-shape.win-token { width: 110px; height: 110px; }
.box-name { display: flex; align-items: center; }
.count-tokens { gap: 4px; }

/* on the board: the token sits on its square */
.tower {
  width: var(--tw);
  height: var(--tw);
  transform: translate(-50%, -50%);
}
.tower .board-token { width: 100%; height: 100%; }
.tower.current .board-token svg { animation: tokenGlow 1.2s ease-in-out infinite; }
.tower.hop { animation: tokenHop 0.34s ease-out; }
.tower-zzz { top: -12px; right: -12px; }

@keyframes tokenHop {
  0% { transform: translate(-50%, -50%); }
  45% { transform: translate(-50%, -95%); }
  100% { transform: translate(-50%, -50%); }
}
@keyframes tokenGlow {
  0%, 100% { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45)); }
  50% { filter: drop-shadow(0 0 7px #fff) drop-shadow(0 0 3px var(--player)); }
}

.build-how { display: block; font-size: clamp(18px, 3vw, 26px); font-weight: 900; color: var(--accent); margin-top: 2px; }

/* combinations already built for this number (can't be repeated) */
.build-used { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; max-width: 100%; font-size: 13px; }
.build-used:empty { display: none; }
.used-title { font-weight: 800; color: var(--text-dim); }
.used-combo { padding: 1px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); font-weight: 800; text-decoration: line-through; text-decoration-color: rgba(255, 135, 135, 0.8); }
.build-area .build-gap.repeated { border-color: #ff6b6b; border-style: solid; box-shadow: 0 0 18px rgba(255, 107, 107, 0.8); animation: noFit 0.4s ease; }

/* ---------------------------------------------------------------------- */
/* Start screen in steps: 1 mode (+ rules) · 2 players · 3 who starts      */
/* ---------------------------------------------------------------------- */

.player-picker { gap: 14px; }
.picker-step { width: 100%; max-width: 760px; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 14px 14px; border-radius: 18px; background: rgba(0, 0, 0, 0.22); }
.step-title { margin: 0; display: flex; align-items: center; gap: 10px; font-size: clamp(18px, 2.6vw, 24px); font-weight: 900; }
.step-num { width: 1.6em; height: 1.6em; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #1a1a1a; font-size: 0.8em; }

.gmode-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.gmode-btn { appearance: none; font: inherit; color: var(--text); background: var(--panel-solid); border: 3px solid rgba(255, 255, 255, 0.15); border-radius: 16px; padding: 10px 16px; min-width: 190px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; transition: transform 0.15s ease, border-color 0.15s ease; }
.gmode-btn:hover { transform: translateY(-3px); }
.gmode-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35); }
.gmode-icon { font-size: 30px; line-height: 1.1; }
.gmode-btn b { font-size: 20px; }
.gmode-btn small { font-size: 12px; color: var(--text-dim); }
.rules-btn { font-size: 15px; font-weight: 800; }

.start-mode-desc { margin: 0; font-size: 14px; color: var(--text-dim); text-align: center; max-width: 560px; min-height: 2.6em; }

/* the rules window */
.rules-overlay { z-index: 70; }
.rules-card { max-width: 620px; text-align: left; }
.rules-card h2 { margin: 0 0 10px; text-align: center; font-size: clamp(22px, 3.4vw, 30px); }
.rules-list { margin: 0; padding: 0; list-style: none; counter-reset: rule; display: flex; flex-direction: column; gap: 8px; }
.rules-list li { counter-increment: rule; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.08); font-size: clamp(15px, 2.2vw, 18px); line-height: 1.3; }
.rules-list li::before { content: counter(rule); flex: none; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--accent); color: #1a1a1a; font-weight: 900; }
.rule-icon { flex: none; font-size: 26px; }
.rules-list b { color: #ffe066; }
.rules-list b.neg { color: #ff8787; }

/* who starts: countdown before the quick operation */
.countdown-label { display: block; font-size: clamp(18px, 3vw, 26px); font-weight: 800; color: var(--text-dim); }
.countdown { display: inline-block; font-size: clamp(64px, 14vw, 120px); font-weight: 900; line-height: 1; color: var(--accent); animation: countPop 1s ease-out; }
.countdown.go { color: #69db7c; animation-duration: 0.6s; }
@keyframes countPop { 0% { transform: scale(1.8); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.9); opacity: 0.85; } }
.buzz-btn.waiting { opacity: 0.7; }

/* a compact start screen: the three steps + ¡A jugar! fit without scrolling */
.player-picker { gap: 8px; justify-content: flex-start; }
.picker-step { gap: 6px; padding: 8px 12px 10px; }
.gmode-btn { padding: 6px 14px; }
.gmode-icon { font-size: 24px; }
.picker-preview { margin: 0; gap: 14px; }
.token-shape.preview-token { width: 40px; height: 40px; }
.preview-chip { flex-direction: row; gap: 6px; }
.count-btn { padding: 6px 12px; }
.count-num { font-size: 28px; }
.start-mode-desc { min-height: 0; }
.btn-start { flex: none; }
