/* =====================================================================
   Stack Games — DARK kid-friendly theme
   (All class names match what host.js / player.js / games.js render.)
   ===================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Nunito:wght@500;700;800&display=swap');

/* ---------- design tokens (dark) ---------- */
:root {
  /* night surfaces */
  --bg:       #0d0c1c;   /* page */
  --bg-1:     #15132a;   /* deepest panel */
  --bg-2:     #1c1a36;   /* cards */
  --bg-3:     #252247;   /* raised surface / inputs hover */
  --bg-card:  #1c1a36;
  --surface-2: #252247;

  /* text */
  --ink:      #f1eeff;
  --ink-soft: #b6b0e0;
  --muted:    #7d77a8;
  --line:     #2e2a52;

  /* brand accents (punchy on dark) */
  --accent:        #9d82ff;
  --accent-strong: #7c5cff;
  --accent-soft:   #2a224f;

  /* status */
  --warm: #ffae5e;
  --good: #34d27a;
  --good-strong: #21c87a;
  --bad:  #ff6b7d;
  --pipe: #5b4d96;

  /* candy block colors (slightly punchier than before) */
  --c-red:    #ff5b6e;
  --c-blue:   #3aa9ff;
  --c-green:  #34d27a;
  --c-yellow: #ffd23a;
  --c-purple: #b46bff;
  --c-orange: #ff8a3d;

  --radius:    18px;
  --radius-lg: 26px;
  --shadow:      0 14px 36px rgba(0, 0, 0, 0.55);
  --shadow-soft: 0 10px 22px rgba(0, 0, 0, 0.35);
  --glow-purple: 0 0 32px rgba(157, 130, 255, 0.30);

  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-body:    'Nunito', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font-body);
  font-weight: 600;
  background: var(--bg);
  color: var(--ink);
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  letter-spacing: 0.01em;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 0 0 0.5rem;
  line-height: 1.15;
  letter-spacing: 0.005em;
  color: var(--ink);
}
h1 { font-size: clamp(1.6rem, 5vw, 2.2rem); }
h2 { font-size: clamp(1.2rem, 4vw, 1.5rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.5rem; color: var(--ink-soft); line-height: 1.45; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* inline icon used inside headings (replaces emoji) */
.icon-inline {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  flex-shrink: 0;
}

/* ---------- buttons (chunky 3D, dark) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  cursor: pointer;
  font: inherit;
  font-family: var(--font-display);
  font-weight: 600;
  padding: 0.85rem 1.3rem;
  border-radius: 14px;
  text-decoration: none;
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.45);
  transition:
    transform 90ms cubic-bezier(.2,.9,.3,1.4),
    box-shadow 90ms ease,
    background 150ms ease,
    color 150ms ease;
  min-height: 44px;
  position: relative;
}
.btn:hover { background: #2f2c54; transform: translateY(-1px); }
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}
.btn.primary {
  background: linear-gradient(180deg, #b59cff 0%, var(--accent) 60%, var(--accent-strong) 100%);
  color: white;
  box-shadow:
    0 6px 0 #4a36b8,
    0 14px 30px rgba(124, 92, 255, 0.55);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary:active {
  box-shadow:
    0 2px 0 #4a36b8,
    0 6px 14px rgba(124, 92, 255, 0.40);
}
.btn.secondary {
  background: var(--bg-card);
  color: var(--accent);
  box-shadow:
    inset 0 0 0 3px var(--accent),
    0 6px 0 rgba(0, 0, 0, 0.45);
}
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  box-shadow: none;
}
.btn.ghost:hover { background: rgba(157, 130, 255, 0.12); color: var(--ink); }
.btn.big {
  padding: 1.05rem 1.5rem;
  font-size: 1.1rem;
  border-radius: 18px;
}

/* ---------- pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: linear-gradient(135deg, #ff8a3d, #ff5b6e);
  color: white;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: 0 6px 16px rgba(255, 91, 110, 0.45);
  max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pill.ghost {
  background: var(--bg-card);
  color: var(--ink);
  box-shadow:
    inset 0 0 0 2px var(--line),
    0 2px 8px rgba(0, 0, 0, 0.35);
}

/* =====================================================================
   LANDING PAGE
   ===================================================================== */
.landing {
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(255, 138, 61, 0.18) 0%, transparent 60%),
    radial-gradient(800px 600px at 10% 110%, rgba(58, 169, 255, 0.20) 0%, transparent 55%),
    radial-gradient(700px 400px at 50% 50%, rgba(180, 107, 255, 0.18) 0%, transparent 60%),
    var(--bg);
  position: relative;
  overflow: hidden;
}
/* floating bubble decorations (purely decorative) */
.landing::before,
.landing::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.55;
  pointer-events: none;
  animation: float 9s ease-in-out infinite;
}
.landing::before {
  width: 120px; height: 120px;
  top: 8%; left: 6%;
  background: radial-gradient(circle at 30% 30%, #ffd23a, #ff8a3d);
  box-shadow: 0 0 60px rgba(255, 170, 60, 0.4);
}
.landing::after {
  width: 160px; height: 160px;
  bottom: 6%; right: 8%;
  background: radial-gradient(circle at 30% 30%, #6dc1ff, #3aa9ff);
  box-shadow: 0 0 70px rgba(58, 169, 255, 0.45);
  animation-delay: -4s;
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0); }
  50%      { transform: translateY(-20px) rotate(8deg); }
}

.landing-card {
  position: relative;
  z-index: 1;
  max-width: 580px;
  margin: clamp(2rem, 10vh, 6rem) 1rem;
  margin-left: auto; margin-right: auto;
  background: var(--bg-card);
  padding: clamp(1.6rem, 5vw, 2.6rem);
  border-radius: var(--radius-lg);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(157, 130, 255, 0.18),
    var(--glow-purple);
  text-align: center;
  border: 1px solid var(--line);
}
.landing-card h1 {
  font-size: clamp(1.9rem, 7vw, 2.5rem);
  background: linear-gradient(135deg, #ffae5e, #c39bff 50%, #6dc1ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.landing-card .tag { font-size: 1.1rem; }
.landing-card .hint {
  margin-top: 1.2rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.cta {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin: 1.6rem 0 1rem;
}

/* logo: stack of disks that gently wiggles */
.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  margin-bottom: 1.2rem;
  animation: wiggle 4s ease-in-out infinite;
  transform-origin: 50% 100%;
}
.logo .disk {
  height: 18px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.30),
    inset 0 3px 0 rgba(255, 255, 255, 0.30),
    0 8px 18px rgba(0, 0, 0, 0.45);
}
.logo .d1 {
  width: 64px;
  background: linear-gradient(180deg, #b46bff, #7c5cff);
}
.logo .d2 {
  width: 100px;
  background: linear-gradient(180deg, #ff8a3d, #ff5b6e);
}
.logo .d3 {
  width: 136px;
  background: linear-gradient(180deg, #ffd23a, #ff8a3d);
}
@keyframes wiggle {
  0%, 100% { transform: rotate(-2deg); }
  50%      { transform: rotate(2deg); }
}

/* =====================================================================
   HOST PAGE — classroom view
   ===================================================================== */
.host-page {
  background:
    radial-gradient(1100px 500px at 100% -10%, rgba(255, 138, 61, 0.14), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(58, 169, 255, 0.18), transparent 60%),
    var(--bg);
  min-height: 100svh;
}
.host-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
  gap: 0.5rem;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.30);
}
.host-header h1 {
  font-size: 1.05rem;
  margin: 0;
  background: linear-gradient(135deg, #c39bff, #ff8a9b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.host-header .controls { display: flex; gap: 0.5rem; }

.lobby-grid {
  display: grid;
  gap: 1.1rem;
  grid-template-columns: 1fr;
  padding: 1.1rem;
  max-width: 1200px;
  margin: 0 auto;
}
@media (min-width: 900px) {
  .lobby-grid { grid-template-columns: 1fr 1fr; padding: 1.5rem; gap: 1.4rem; }
  .game-picker {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.4rem;
  }
  .game-picker > h2 { grid-column: 1 / -1; margin-bottom: 0; }
}

.qr-card, .players-card, .game-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.3rem 1.4rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--line);
  position: relative;
}

.qr-card { text-align: center; }
.qr-card::before {
  content: "";
  position: absolute;
  top: -14px; left: 18px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='7' y='2.5' width='10' height='19' rx='2.5'/%3E%3Cline x1='10.5' y1='5.5' x2='13.5' y2='5.5'/%3E%3Ccircle cx='12' cy='18.2' r='0.9' fill='white' stroke='none'/%3E%3C/svg%3E") center / 18px 18px no-repeat,
    linear-gradient(135deg, #ffd23a, #ff8a3d);
  box-shadow: 0 6px 16px rgba(255, 138, 61, 0.55);
}
.qr-card img {
  /* QR must stay light for camera scanning */
  width: min(260px, 70vw);
  height: auto;
  aspect-ratio: 1;
  image-rendering: pixelated;
  border-radius: 14px;
  background: white;
  padding: 8px;
  box-shadow:
    inset 0 0 0 3px rgba(157, 130, 255, 0.4),
    0 0 0 4px rgba(0, 0, 0, 0.35);
}
.join-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  font-size: 0.9rem;
  background: var(--accent-soft);
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  color: #d2c0ff;
  border: 1px solid var(--line);
}

.players-card::before {
  content: "";
  position: absolute;
  top: -14px; left: 18px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='8' r='3.2'/%3E%3Cpath d='M3 20c0-3.2 2.7-5.5 6-5.5s6 2.3 6 5.5'/%3E%3Ccircle cx='17' cy='9.5' r='2.5'/%3E%3Cpath d='M16 14.6c2.5.5 4 2.5 4 5'/%3E%3C/svg%3E") center / 20px 20px no-repeat,
    linear-gradient(135deg, #3aa9ff, #7c5cff);
  box-shadow: 0 6px 16px rgba(124, 92, 255, 0.55);
}

.player-list {
  list-style: none;
  padding: 0; margin: 0;
  display: flex; flex-direction: column;
  gap: 0.5rem;
}
.player-list li {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  background: linear-gradient(135deg, #221f42, #2c2752);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  font-weight: 700;
  color: var(--ink);
  animation: pop-in 0.4s cubic-bezier(.2,.9,.3,1.4);
}
.player-list .dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  flex: 0 0 16px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
.player-list.small li { padding: 0.4rem 0.6rem; font-size: 0.95rem; }
@keyframes pop-in {
  0%   { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}

.game-card { transition: transform 200ms ease, box-shadow 200ms ease; }
.game-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow), var(--glow-purple);
}
.game-card h3 {
  font-size: 1.25rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.game-card .opts {
  display: flex; flex-wrap: wrap;
  gap: 0.7rem;
  margin: 0.8rem 0 1.1rem;
}
.game-card label {
  display: inline-flex; flex-direction: column;
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.game-card label input {
  margin-top: 0.3rem;
  width: 4.8rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  color: var(--ink);
  background: var(--bg-1);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
.game-card label input:focus {
  outline: none;
  background: var(--surface-2);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(157, 130, 255, 0.25);
}

/* =====================================================================
   GAME LAYOUT (host)
   ===================================================================== */
.game-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}
@media (min-width: 980px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
    padding: 1rem 1.25rem;
  }
}
.game-stage {
  background:
    radial-gradient(800px 400px at 50% 100%, rgba(157, 130, 255, 0.15), transparent 60%),
    var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 0.9rem;
  min-height: 320px;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--line);
  display: flex; align-items: flex-end; justify-content: center;
  overflow: visible;
  position: relative;
}
.game-side { display: flex; flex-direction: column; gap: 1rem; }
.info-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--line);
}
.info-card h3 {
  font-size: 1.05rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.info-card h3::before {
  content: "";
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%239d82ff'%3E%3Cpath d='M12 2.5l2.2 6.3 6.3 2.2-6.3 2.2L12 19.5l-2.2-6.3-6.3-2.2 6.3-2.2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  filter: drop-shadow(0 0 6px rgba(157, 130, 255, 0.5));
}
.stats { list-style: none; padding: 0; margin: 0; }
.stats li {
  padding: 0.4rem 0;
  color: var(--ink-soft);
  border-bottom: 1px dashed var(--line);
  font-weight: 700;
}
.stats li:last-child { border-bottom: none; }
.stats strong {
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 1.1rem;
}
.log {
  list-style: decimal inside;
  padding: 0; margin: 0;
  max-height: 220px; overflow: auto;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.log li { padding: 0.2rem 0; }
.log li b { color: var(--ink); }

/* ---------- WIN BANNER (party time) ---------- */
.win-banner {
  position: fixed; left: 50%; bottom: 1.2rem;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #34d27a, var(--good-strong));
  color: white;
  padding: 1.1rem 1.5rem;
  border-radius: 22px;
  box-shadow:
    0 16px 50px rgba(33, 200, 122, 0.55),
    0 6px 0 rgba(11, 110, 70, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.15) inset;
  text-align: center; z-index: 50;
  display: flex; flex-direction: column;
  gap: 0.6rem; align-items: center;
  max-width: 92vw;
  border: 2px solid rgba(255, 255, 255, 0.4);
  animation: pop-in 0.45s cubic-bezier(.2,.9,.3,1.5), bounce 1.5s ease-in-out 0.5s infinite;
}
.win-banner h2 {
  color: white;
  font-size: 1.5rem;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  display: inline-flex; align-items: center; gap: 0.5rem;
  justify-content: center;
}
.win-banner p { color: rgba(255, 255, 255, 0.92); margin: 0; }
.win-banner .controls {
  display: flex; gap: 0.5rem;
  flex-wrap: wrap; justify-content: center;
  margin-top: 0.2rem;
}
.win-banner .btn {
  background: white;
  color: var(--good-strong);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.20);
}
.win-banner .btn.ghost {
  background: rgba(255, 255, 255, 0.20);
  color: white;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55);
}
@keyframes bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-6px); }
}

/* =====================================================================
   PLAY PAGE (phone)
   ===================================================================== */
.play-page {
  background:
    radial-gradient(700px 400px at 100% 0%, rgba(255, 138, 61, 0.15), transparent 55%),
    radial-gradient(700px 500px at 0% 100%, rgba(58, 169, 255, 0.18), transparent 55%),
    var(--bg);
  display: flex; flex-direction: column;
  min-height: 100svh;
}
.play-page #view-join,
.play-page #view-waiting { flex: 1; }
.play-page #view-game {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}

.join-card, .waiting-card {
  max-width: 480px;
  margin: clamp(1.5rem, 8vh, 4rem) 1rem 1rem;
  margin-left: auto; margin-right: auto;
  background: var(--bg-card);
  padding: clamp(1.4rem, 6vw, 2.2rem);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), var(--glow-purple);
  text-align: center;
  border: 1px solid var(--line);
  animation: pop-in 0.4s cubic-bezier(.2,.9,.3,1.4);
}
.join-card h1, .waiting-card h1 {
  background: linear-gradient(135deg, #ffae5e, #c39bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: inline-flex; align-items: center; gap: 0.4rem;
  justify-content: center;
}
.join-card .field {
  display: flex; flex-direction: column;
  gap: 0.3rem; text-align: left;
  margin: 0.85rem 0;
}
.join-card .field span {
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.join-card input {
  border: 2.5px solid var(--line);
  border-radius: 14px;
  padding: 1rem 0.9rem;
  font-size: 1.15rem;
  font: inherit;
  font-family: var(--font-display);
  font-weight: 600;
  text-transform: uppercase;
  min-height: 50px;
  background: var(--bg-1);
  color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.join-card input::placeholder { color: var(--muted); }
.join-card input:focus {
  outline: none;
  background: var(--surface-2);
  border-color: var(--accent);
  box-shadow: 0 0 0 5px rgba(157, 130, 255, 0.25);
}
.join-card #name-input { text-transform: none; }
.join-card .error {
  color: var(--bad);
  min-height: 1.2em;
  font-weight: 700;
  margin: 0.9rem 0 0;
  text-align: center;
}

.play-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.7rem 0.85rem; gap: 0.5rem;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.play-page .game-stage {
  margin: 0.85rem;
  flex: 1;
  min-height: 280px;
}
.stats-strip {
  display: flex; justify-content: space-around; align-items: center;
  margin: 0 0.85rem;
  padding: 0.8rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  background:
    linear-gradient(var(--bg-card), var(--bg-card)) padding-box,
    linear-gradient(135deg, #ffd23a, #ff8a3d, #b46bff, #3aa9ff) border-box;
  border: 3px solid transparent;
}
.stats-strip .stat {
  display: flex; flex-direction: column;
  align-items: center; gap: 0.15rem;
}
.stats-strip .k {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
}
.stats-strip .v {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--accent);
}
.play-status {
  text-align: center;
  color: var(--ink-soft);
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
}
.play-info {
  margin: 0 0.85rem 1rem;
  padding: 0.6rem 0.95rem;
  background: var(--bg-card);
  border-radius: 14px;
  border: 1px solid var(--line);
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.play-info summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--accent);
  padding: 0.3rem 0;
  font-family: var(--font-display);
}
.play-info p { margin: 0.4rem 0; }
.play-info ul {
  margin: 0.5rem 0 0.2rem;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.play-info li { line-height: 1.4; }
.play-info li::marker { color: var(--accent); }

/* =====================================================================
   HANOI rendering
   ===================================================================== */
.hanoi-board {
  display: flex;
  gap: clamp(0.5rem, 2vw, 1.4rem);
  padding: 1.8rem 0.4rem 2rem;
  align-items: flex-end;
  width: 100%;
  justify-content: center;
}
.hanoi-peg {
  position: relative;
  display: flex; flex-direction: column-reverse; align-items: center;
  flex: 1 1 0;
  min-width: 60px;
  min-height: clamp(220px, 36vh, 320px);
  user-select: none;
  transition: background 150ms ease, transform 150ms ease;
  border-radius: 16px;
  padding-bottom: 4px;
}
.hanoi-peg::before {
  /* the wooden post */
  content: '';
  position: absolute;
  bottom: 14px; left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: clamp(180px, 30vh, 260px);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.25) 0%, transparent 30%, transparent 70%, rgba(0, 0, 0, 0.40) 100%),
    linear-gradient(180deg, #b59cff, #6f53e8);
  border-radius: 6px 6px 0 0;
  z-index: 0;
  box-shadow: 0 0 12px rgba(124, 92, 255, 0.45);
}
.hanoi-peg .base {
  position: absolute;
  bottom: 0; left: 4%; right: 4%;
  height: 14px;
  background: linear-gradient(180deg, #ff8a3d, #b8480f);
  border-radius: 8px;
  z-index: 0;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
}
.hanoi-peg.drop-target {
  background: rgba(33, 200, 122, 0.18);
  transform: scale(1.02);
}
.hanoi-peg.drop-target .base {
  background: linear-gradient(180deg, var(--good), var(--good-strong));
  box-shadow:
    0 0 0 4px rgba(33, 200, 122, 0.30),
    0 4px 0 rgba(11, 110, 70, 0.7),
    0 0 24px rgba(52, 210, 122, 0.55);
}
.hanoi-peg.drop-target::after {
  content: "";
  position: absolute;
  top: -38px; left: 50%; transform: translateX(-50%);
  width: 32px; height: 32px;
  border-radius: 50%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2316a364' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 10 12 16 18 10'/%3E%3C/svg%3E") center / 20px 20px no-repeat,
    white;
  box-shadow: 0 6px 16px rgba(33, 200, 122, 0.55), inset 0 0 0 3px var(--good);
  animation: bounce 0.7s ease-in-out infinite;
}

.hanoi-disk {
  position: relative; z-index: 1;
  height: 28px;
  border-radius: 14px;
  margin-bottom: 5px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: white;
  font-weight: 700;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow:
    inset 0 -5px 0 rgba(0, 0, 0, 0.30),
    inset 0 3px 0 rgba(255, 255, 255, 0.30),
    0 6px 14px rgba(0, 0, 0, 0.50);
  transition: transform 100ms cubic-bezier(.2,.9,.3,1.4);
  touch-action: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
.hanoi-disk.top { animation: tip-glow 2.4s ease-in-out infinite; }
.hanoi-disk.draggable { cursor: grab; }
.hanoi-disk.draggable:hover { transform: translateY(-2px) scale(1.03); }
.hanoi-disk.grabbed {
  cursor: grabbing;
  box-shadow:
    inset 0 -5px 0 rgba(0, 0, 0, 0.30),
    inset 0 3px 0 rgba(255, 255, 255, 0.30),
    0 22px 40px rgba(0, 0, 0, 0.65),
    0 0 30px rgba(157, 130, 255, 0.55);
  z-index: 1000;
  transform: scale(1.06);
}
.hanoi-disk.held-by-other {
  opacity: 0.45;
  filter: saturate(0.6) brightness(0.85);
  pointer-events: none;
}
@keyframes tip-glow {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.12); }
}

.hanoi-peg-label {
  position: absolute; bottom: -26px;
  left: 0; right: 0; text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

/* =====================================================================
   PIPES rendering (cartoon test tubes)
   ===================================================================== */
.pipes-board {
  display: flex;
  gap: 0.7rem;
  padding: 1.4rem 0.5rem 2rem;
  align-items: flex-end;
  flex-wrap: nowrap;
  justify-content: center;
  max-width: 100%;
}
.pipe {
  background:
    linear-gradient(180deg, transparent 0%, rgba(157, 130, 255, 0.12) 100%),
    rgba(255, 255, 255, 0.04);
  border: 4px solid var(--pipe);
  border-top: none;
  display: flex; flex-direction: column-reverse;
  padding: 6px;
  gap: 5px;
  position: relative;
  transition:
    transform 150ms cubic-bezier(.2,.9,.3,1.4),
    border-color 150ms ease,
    background 150ms ease,
    box-shadow 150ms ease;
  touch-action: none;
  box-shadow:
    inset 3px 0 0 rgba(255, 255, 255, 0.10),
    inset -3px 0 0 rgba(0, 0, 0, 0.30),
    0 8px 20px rgba(0, 0, 0, 0.45);
}
.pipe.free {
  background: rgba(157, 130, 255, 0.06);
  border-style: dashed;
  border-color: var(--accent);
}
.pipe.drop-target {
  border-color: var(--good);
  background: rgba(33, 200, 122, 0.15);
  transform: translateY(-3px) scale(1.03);
  box-shadow:
    inset 3px 0 0 rgba(255, 255, 255, 0.15),
    0 12px 24px rgba(33, 200, 122, 0.40),
    0 0 24px rgba(52, 210, 122, 0.40);
}
.pipe.drop-target::after {
  content: "";
  position: absolute;
  top: -40px; left: 50%; transform: translateX(-50%);
  width: 30px; height: 30px;
  border-radius: 50%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2316a364' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 10 12 16 18 10'/%3E%3C/svg%3E") center / 18px 18px no-repeat,
    white;
  box-shadow: 0 6px 16px rgba(33, 200, 122, 0.55), inset 0 0 0 3px var(--good);
  animation: bounce 0.7s ease-in-out infinite;
}

.pipe-block {
  /* Flexbox shares the pipe's content height across N blocks. The old
     calc()-based height was tuned for cap=4 and overflowed at cap=6. */
  flex: 1 1 0;
  min-height: 0;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.28),
    inset 0 3px 0 rgba(255, 255, 255, 0.32),
    0 4px 8px rgba(0, 0, 0, 0.50);
  transition: transform 100ms cubic-bezier(.2,.9,.3,1.4);
  touch-action: none;
  position: relative;
}
.pipe-block.top { animation: tip-glow 2.4s ease-in-out infinite; }
.pipe-block.draggable { cursor: grab; }
.pipe-block.draggable:hover { transform: translateY(-2px) scale(1.04); }
.pipe-block.grabbed {
  cursor: grabbing;
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.28),
    inset 0 3px 0 rgba(255, 255, 255, 0.32),
    0 18px 32px rgba(0, 0, 0, 0.60),
    0 0 28px rgba(157, 130, 255, 0.50);
  z-index: 1000;
  transform: scale(1.08);
}
.pipe-block.held-by-other {
  opacity: 0.45;
  filter: saturate(0.6) brightness(0.85);
  pointer-events: none;
}

.pipe-block.red    { background: linear-gradient(180deg, #ff8694, var(--c-red)); }
.pipe-block.blue   { background: linear-gradient(180deg, #6dc1ff, var(--c-blue)); }
.pipe-block.green  { background: linear-gradient(180deg, #6be39d, var(--c-green)); }
.pipe-block.yellow { background: linear-gradient(180deg, #ffe26d, var(--c-yellow)); }
.pipe-block.purple { background: linear-gradient(180deg, #d29bff, var(--c-purple)); }
.pipe-block.orange { background: linear-gradient(180deg, #ffb077, var(--c-orange)); }

.pipe-label {
  position: absolute; bottom: -1.6rem;
  left: 0; right: 0; text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent);
  font-size: 0.85rem;
}
.pipe-tag-free {
  position: absolute; top: -1.7rem;
  left: -10%; right: -10%; text-align: center;
  font-family: var(--font-display);
  font-size: 0.62rem;
  color: var(--accent);
  letter-spacing: 0.08em;
  font-weight: 700;
  white-space: nowrap;
}
.pipe-tag-free em {
  font-style: normal;
  color: var(--ink-soft);
  font-weight: 600;
}

/* =====================================================================
   FLOATING NAME TAG (stuck to grabbed piece)
   ===================================================================== */
.name-tag {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  background: var(--tag-color, var(--ink));
  color: white;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.30);
  pointer-events: none;
  z-index: 1001;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.45);
  animation: pop-in 0.25s cubic-bezier(.2,.9,.3,1.5);
}
.name-tag::before {
  content: '';
  position: absolute;
  left: 50%; top: 100%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--tag-color, var(--ink));
}

/* =====================================================================
   TOAST
   ===================================================================== */
.toast {
  position: fixed; left: 50%; bottom: 5.5rem;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #2a224f, #5b3fe0);
  color: white;
  font-family: var(--font-display);
  font-weight: 600;
  padding: 0.65rem 1.2rem;
  border-radius: 14px;
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.55),
    0 0 24px rgba(157, 130, 255, 0.35);
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
  z-index: 100;
  max-width: 92vw;
  text-align: center;
  font-size: 0.95rem;
  border: 2px solid rgba(255, 255, 255, 0.18);
}
.toast.show {
  opacity: 0.97;
  transform: translateX(-50%) translateY(-4px);
}
.toast.error {
  background: linear-gradient(135deg, #ff5d6c, #8a1d2a);
  box-shadow: 0 12px 28px rgba(255, 93, 108, 0.50);
}

/* =====================================================================
   BIG-SCREEN tweaks
   ===================================================================== */
@media (min-width: 700px) {
  .play-page .game-stage { min-height: 380px; }
  .stats-strip .v { font-size: 1.6rem; }
  .hanoi-peg { min-height: 320px; }
}

/* =====================================================================
   QR focus overlay — opens when the teacher taps the QR in the lobby.
   Big QR, rotating rainbow halo, floating confetti dots. Backdrop click
   or Esc closes. Backdrop fades + card springs in.
   ===================================================================== */
#qr-img {
  cursor: zoom-in;
  transition: transform 140ms cubic-bezier(.2,.9,.3,1.4);
}
#qr-img:hover { transform: scale(1.03) rotate(-1deg); }
#qr-img:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }

.qr-focus {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0.5rem, 3vw, 1.5rem);
  background:
    radial-gradient(900px 600px at 15% 10%, rgba(255, 138, 61, 0.22), transparent 60%),
    radial-gradient(900px 600px at 85% 90%, rgba(58, 169, 255, 0.22), transparent 60%),
    radial-gradient(700px 500px at 50% 50%, rgba(180, 107, 255, 0.30), transparent 65%),
    rgba(8, 7, 18, 0.78);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}
.qr-focus.open { opacity: 1; pointer-events: auto; }

.qr-focus-close {
  position: absolute;
  top: clamp(0.8rem, 2vw, 1.4rem);
  right: clamp(0.8rem, 2vw, 1.4rem);
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink);
  font-size: 1.8rem; line-height: 1; font-weight: 700;
  cursor: pointer;
  box-shadow:
    0 8px 0 rgba(0, 0, 0, 0.50),
    0 12px 28px rgba(0, 0, 0, 0.6);
  z-index: 5;
  transition: transform 120ms ease;
}
.qr-focus-close:hover { transform: rotate(90deg) scale(1.05); background: var(--surface-2); }
.qr-focus-close:active { transform: rotate(90deg) translateY(2px); }

.qr-focus-card {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: clamp(1.2rem, 3vw, 2rem) clamp(1.2rem, 4vw, 2.4rem) clamp(1rem, 3vw, 1.6rem);
  text-align: center;
  border: 1px solid var(--line);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.70),
    0 8px 0 rgba(0, 0, 0, 0.40),
    var(--glow-purple);
  transform: scale(0.55) rotate(-4deg);
  opacity: 0;
  transition:
    transform 380ms cubic-bezier(.34, 1.56, .64, 1),
    opacity 220ms ease;
  z-index: 3;
  max-width: min(94vw, 580px);
}
.qr-focus.open .qr-focus-card {
  transform: scale(1) rotate(0deg);
  opacity: 1;
}

.qr-focus-frame {
  position: relative;
  display: inline-block;
  padding: 14px;
  border-radius: var(--radius);
}
.qr-focus-frame img {
  display: block;
  width: clamp(220px, 56vmin, 420px);
  height: auto;
  aspect-ratio: 1;
  image-rendering: pixelated;
  border-radius: 14px;
  background: white;
  position: relative;
  z-index: 2;
  padding: 10px;
  box-shadow: inset 0 0 0 3px rgba(157, 130, 255, 0.4);
}
.qr-focus-halo {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--radius) + 4px);
  background: conic-gradient(
    from 0deg,
    #ff5b6e 0deg, #ff8a3d 60deg, #ffd23a 120deg,
    #34d27a 180deg, #3aa9ff 240deg, #b46bff 300deg, #ff5b6e 360deg
  );
  filter: blur(6px);
  z-index: 1;
  animation: qr-halo-spin 6s linear infinite;
}
.qr-focus-frame::after {
  /* inner mask so the halo only shows as a ring, not behind the QR */
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 16px;
  background: white;
  z-index: 1;
}

.qr-focus-code {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 9vw, 3.4rem);
  letter-spacing: 0.14em;
  margin: 1rem 0 0.2rem;
  background: linear-gradient(135deg, #ffae5e, #c39bff 50%, #6dc1ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: qr-code-bounce 1.8s ease-in-out infinite;
}
.qr-focus-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  color: var(--ink-soft);
  word-break: break-all;
  margin-top: 0.2rem;
}
.qr-focus-hint {
  margin-top: 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Confetti — small colorful dots that drift around the whole overlay */
.qr-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}
.qr-confetti span {
  position: absolute;
  border-radius: 50%;
  opacity: 0.9;
  animation: qr-float 6s ease-in-out infinite;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
.qr-confetti span:nth-child(1)  { top: 8%;  left: 10%;  width: 22px; height: 22px; background: #ff5b6e; animation-delay: 0s;    }
.qr-confetti span:nth-child(2)  { top: 18%; right: 12%; width: 28px; height: 28px; background: #ffd23a; animation-delay: -0.7s; }
.qr-confetti span:nth-child(3)  { bottom: 12%; left: 8%;  width: 20px; height: 20px; background: #34d27a; animation-delay: -1.4s; }
.qr-confetti span:nth-child(4)  { bottom: 18%; right: 9%; width: 26px; height: 26px; background: #3aa9ff; animation-delay: -2.1s; }
.qr-confetti span:nth-child(5)  { top: 48%; left: 4%;   width: 16px; height: 16px; background: #b46bff; animation-delay: -2.8s; }
.qr-confetti span:nth-child(6)  { top: 6%;  right: 36%; width: 22px; height: 22px; background: #ff8a3d; animation-delay: -3.5s; }
.qr-confetti span:nth-child(7)  { bottom: 6%;  left: 38%; width: 18px; height: 18px; background: #ff5b6e; animation-delay: -4.2s; }
.qr-confetti span:nth-child(8)  { top: 42%; right: 5%;  width: 24px; height: 24px; background: #ffd23a; animation-delay: -4.9s; }
.qr-confetti span:nth-child(9)  { top: 14%; left: 42%;  width: 16px; height: 16px; background: #34d27a; animation-delay: -1.1s; }
.qr-confetti span:nth-child(10) { bottom: 32%; right: 24%; width: 22px; height: 22px; background: #b46bff; animation-delay: -3.2s; }
.qr-confetti span:nth-child(11) { top: 68%; left: 22%;  width: 18px; height: 18px; background: #3aa9ff; animation-delay: -1.8s; }
.qr-confetti span:nth-child(12) { bottom: 10%; right: 48%; width: 14px; height: 14px; background: #ff8a3d; animation-delay: -3.9s; }

@keyframes qr-float {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  50%      { transform: translate(10px, -18px) rotate(22deg); }
}
@keyframes qr-halo-spin {
  to { transform: rotate(360deg); }
}
@keyframes qr-code-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

/* =====================================================================
   Stuck-state voting UI — visible on phones when the board has no legal
   moves left. Half-of-class (ceil(n/2)) agreement triggers undo/reset.
   ===================================================================== */
.vote-bar {
  margin: 0 0.75rem 0.5rem;
  padding: 0.9rem 1rem 1rem;
  background:
    linear-gradient(180deg, rgba(255, 174, 94, 0.10), rgba(255, 91, 110, 0.08)),
    var(--bg-card);
  border-radius: var(--radius);
  border: 2px solid var(--warm);
  box-shadow: 0 0 0 4px rgba(255, 174, 94, 0.12), 0 10px 24px rgba(0, 0, 0, 0.35);
  animation: vote-pulse 2.4s ease-in-out infinite;
}
@keyframes vote-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(255, 174, 94, 0.10), 0 10px 24px rgba(0, 0, 0, 0.35); }
  50%      { box-shadow: 0 0 0 7px rgba(255, 174, 94, 0.22), 0 14px 28px rgba(0, 0, 0, 0.40); }
}
.vote-title {
  font-family: var(--font-display);
  font-weight: 700;
  text-align: center;
  color: var(--warm);
  margin-bottom: 0.6rem;
  font-size: 1rem;
  letter-spacing: 0.01em;
}
.vote-buttons {
  display: flex;
  gap: 0.6rem;
}
.vote-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.7rem 0.5rem;
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 14px;
  font: inherit;
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
  min-height: 64px;
  transition: transform 100ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
  -webkit-tap-highlight-color: transparent;
}
.vote-btn:active { transform: translateY(2px); }
.vote-btn .vote-label { font-size: 0.95rem; }
.vote-btn .vote-count {
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: rgba(157, 130, 255, 0.12);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.vote-btn.voted {
  background: linear-gradient(180deg, #b59cff, var(--accent));
  border-color: var(--accent-strong);
  color: white;
  box-shadow: 0 6px 0 #4a36b8, 0 12px 24px rgba(124, 92, 255, 0.45);
}
.vote-btn.voted .vote-count {
  background: rgba(255, 255, 255, 0.22);
  color: white;
}
.vote-hint {
  margin-top: 0.6rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

/* Host-side vote card sits in the side panel during a stuck vote. */
.vote-card {
  border: 2px solid var(--warm) !important;
  box-shadow: 0 0 0 4px rgba(255, 174, 94, 0.15), var(--shadow);
}
.vote-tally {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-family: var(--font-display);
  font-weight: 600;
}
.vote-tally li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.4rem 0.7rem;
  background: var(--surface-2);
  border-radius: 10px;
  color: var(--ink);
}
.vote-tally strong {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

/* Respect users who prefer no animation */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
