:root {
  /* Board side length. Leaves room for the topbar + two pod rows above/below;
   * `dvh` (declared second, wins where supported) tracks mobile browser chrome. */
  --board: min(92vw, calc(100vh - 248px), 560px);
  --board: min(92vw, calc(100dvh - 248px), 560px);
  /* Theme tokens (dark is the default; [data-theme="light"] overrides below).
   * --surface-N are translucent fills over --panel: 0 barely-there → 3 hover. */
  --panel: rgba(15, 23, 42, 0.72);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --surface-0: rgba(255, 255, 255, 0.03);
  --surface-1: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.1);
  --surface-3: rgba(255, 255, 255, 0.16);
  --input-bg: rgba(255, 255, 255, 0.07);
  --input-bg-deep: rgba(0, 0, 0, 0.25);
  --dashed: rgba(255, 255, 255, 0.33);
  --placeholder: #64748b;
  --scrim-1: rgba(6, 10, 24, 0.82);
  --scrim-2: rgba(6, 10, 24, 0.9);
  --overlay-bg: rgba(3, 6, 16, 0.72);
  --shadow: rgba(0, 0, 0, 0.55);
  --ok-text: #6ee7b7;
  --danger-text: #fca5a5;
  --notice-bg: rgba(232, 185, 35, 0.12);
  --notice-border: rgba(232, 185, 35, 0.45);
  --notice-text: #fbe6a2;
}

/* "Light" is deliberately soft grey, not stark white — easier on the eyes and
 * the white dice / board cells still pop against it. */
:root[data-theme="light"] {
  --panel: rgba(226, 232, 240, 0.9);
  --panel-border: rgba(15, 23, 42, 0.16);
  --text: #1e293b;
  --text-dim: #56657a;
  --surface-0: rgba(15, 23, 42, 0.03);
  --surface-1: rgba(15, 23, 42, 0.06);
  --surface-2: rgba(15, 23, 42, 0.09);
  --surface-3: rgba(15, 23, 42, 0.15);
  --input-bg: rgba(15, 23, 42, 0.05);
  --input-bg-deep: rgba(15, 23, 42, 0.06);
  --dashed: rgba(15, 23, 42, 0.35);
  --placeholder: #8b99ab;
  --scrim-1: rgba(199, 210, 224, 0.88);
  --scrim-2: rgba(214, 223, 235, 0.94);
  --overlay-bg: rgba(51, 65, 85, 0.45);
  --shadow: rgba(15, 23, 42, 0.22);
  --ok-text: #047857;
  --danger-text: #b91c1c;
  --notice-bg: rgba(217, 119, 6, 0.1);
  --notice-border: rgba(217, 119, 6, 0.4);
  --notice-text: #854d0e;
}

* { box-sizing: border-box; }

html { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* max(...) keeps content clear of notches/home bars (viewport-fit=cover). */
  padding: max(16px, env(safe-area-inset-top))
           max(12px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom))
           max(12px, env(safe-area-inset-left));
  background:
    linear-gradient(var(--scrim-1), var(--scrim-2)),
    url("assets/bg.jpg") center / cover fixed no-repeat;
}

#root { width: 100%; display: flex; justify-content: center; }

button { font: inherit; color: inherit; touch-action: manipulation; }

/* =========================================================================
 * Menu screen
 * ======================================================================= */
.menu {
  width: min(94vw, 420px);
  margin-top: clamp(4px, 6vh, 64px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: clamp(18px, 4vw, 28px) clamp(14px, 4vw, 24px);
  text-align: center;
  backdrop-filter: blur(8px);
  box-shadow: 0 24px 60px var(--shadow);
}

.menu-logo {
  font-size: clamp(40px, 13vw, 56px);
  font-weight: 900;
  letter-spacing: clamp(3px, 1.5vw, 6px);
  line-height: 1;
}
.menu-logo span {
  color: var(--c);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
  display: inline-block;
  animation: bounce 2.4s infinite;
}
.menu-logo span:nth-child(2) { animation-delay: 0.12s; }
.menu-logo span:nth-child(3) { animation-delay: 0.24s; }
.menu-logo span:nth-child(4) { animation-delay: 0.36s; }
@keyframes bounce {
  0%, 12%, 24%, 100% { transform: translateY(0); }
  6% { transform: translateY(-7px); }
}

.menu-sub { color: var(--text-dim); font-size: 14px; margin: 10px 0 20px; }

.notice {
  background: var(--notice-bg);
  border: 1px solid var(--notice-border);
  color: var(--notice-text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 12px 0;
}

/* ---- Menu tabs ---- */
.tabs {
  display: flex; gap: 6px; margin: 18px 0 6px;
  background: var(--surface-1);
  border-radius: 12px; padding: 4px;
}
.tab {
  flex: 1;
  background: transparent; border: none; border-radius: 9px;
  padding: 9px 6px; font-size: 13px; font-weight: 600;
  color: var(--text-dim); cursor: pointer;
}
.tab.on { background: var(--surface-3); color: var(--text); }

/* ---- Text inputs ---- */
.field-label {
  display: block; text-align: left; font-size: 12px;
  color: var(--text-dim); margin: 4px 2px 6px;
}
.text-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font: inherit; font-size: 14px;
  margin-bottom: 14px;
}
.text-input:focus { outline: none; border-color: var(--dashed); }
.text-input::placeholder { color: var(--placeholder); }

.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-dim); font-size: 12px; margin: 18px 0 14px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--panel-border);
}

.join-row { display: flex; gap: 8px; }
.join-row .text-input { margin-bottom: 0; flex: 1; }
.join-row .btn-primary.join-cta { width: auto; padding: 11px 26px; }
.btn-ghost.full { width: 100%; }
.code-input {
  text-transform: uppercase; letter-spacing: 4px;
  font-weight: 700; text-align: center; font-size: 16px;
}

/* ---- Lobby ---- */
.lobby-title { margin: 0 0 14px; font-size: 20px; }
.room-code {
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  background: var(--surface-1);
  border: 1px dashed var(--dashed);
  border-radius: 14px; padding: 14px; margin-bottom: 16px;
}
.room-code-label { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--text-dim); }
.room-code-value { font-size: 34px; font-weight: 800; letter-spacing: 8px; }
.room-code-hint { font-size: 12px; color: var(--text-dim); }
.share-btn { margin-top: 8px; }
.share-btn.copied {
  background: rgba(52, 211, 153, 0.18);
  border-color: rgba(52, 211, 153, 0.6);
  color: var(--ok-text);
}
.notice.invite { border-color: rgba(52, 211, 153, 0.5); background: rgba(52, 211, 153, 0.1); color: var(--ok-text); }

.roster { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.roster-row {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface-1);
  border-left: 3px solid var(--c);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; font-weight: 600;
}
.roster-row .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); }
.roster-name { flex: 1; text-align: left; }

.extra-seats { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.seat.slim { padding: 8px 12px; }

/* Open (unclaimed) lobby seats: a dashed placeholder that reads "a friend can
 * still take this", with a small pill for the if-still-empty-at-start plan. */
.open-seat {
  display: flex; align-items: center; gap: 9px;
  border-style: dashed; cursor: default;
}
.open-seat:hover { transform: none; background: var(--surface-1); }
.open-seat-label {
  flex: 1; text-align: left;
  color: var(--text-dim); font-size: 13px; font-weight: 600;
}
.seat-fallback {
  background: var(--surface-2);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
  color: var(--text-dim);
}
button.seat-fallback { cursor: pointer; }
button.seat-fallback:hover { background: var(--surface-3); color: var(--text); }

.lobby-exit { width: 100%; margin-top: 10px; }

.waiting-dots::after {
  content: ""; display: inline-block; width: 1.2em; text-align: left;
  animation: dots 1.4s steps(4) infinite;
}
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; }
}

.room-chip {
  background: var(--surface-2);
  border: 1px dashed var(--dashed);
  border-radius: 8px; padding: 5px 9px;
  font-size: 12px; font-weight: 800; letter-spacing: 2px;
}

.seat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat {
  background: var(--surface-1);
  border: 2px solid var(--c);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
  text-align: left;
}
.seat:hover { transform: translateY(-2px); background: var(--surface-2); }
.seat.off { border-color: var(--panel-border); opacity: 0.55; }
.seat-row { display: flex; align-items: center; gap: 8px; }
.seat .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.seat-color { text-transform: capitalize; font-weight: 600; font-size: 14px; }
.seat-kind { margin-left: auto; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.seat-name {
  width: 100%; margin-top: 8px;
  background: var(--input-bg-deep);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 9px;
  font: inherit; font-size: 13px;
  cursor: text;
}
.seat-name:focus { outline: none; border-color: var(--c); }
.seat-name::placeholder { color: var(--placeholder); }
/* .seat.slim (lobby) keeps the original one-row button look */
button.seat { display: flex; align-items: center; gap: 8px; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px 0 20px; }
.preset {
  background: var(--surface-2);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.preset:hover { background: var(--surface-3); }
.preset.on {
  background: rgba(52, 211, 153, 0.2);
  border-color: rgba(52, 211, 153, 0.65);
  color: var(--ok-text);
  font-weight: 700;
}

/* Room-size picker shown above "Create room" */
.size-row {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; margin: 0 0 14px;
}
.size-label { font-size: 12px; color: var(--text-dim); }

.btn-primary {
  width: 100%;
  background: linear-gradient(180deg, #34d399, #059669);
  color: #fff; border: none;
  padding: 13px 18px; border-radius: 12px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 0 #065f46;
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #065f46; }
.btn-primary:disabled {
  background: var(--surface-2);
  box-shadow: none; cursor: not-allowed; color: var(--text-dim);
}

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn-ghost:hover { background: var(--surface-3); }
.btn-ghost.small { padding: 6px 10px; font-size: 13px; }

/* Floating 🌙/☀️ switch shown on menu/lobby screens (in-game it lives in the
 * topbar). Panel-backed so it stays legible over the photo background. */
.theme-toggle {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 60;
  background: var(--panel);
}

/* ---- Profile strip (menu): level badge, XP bar, totals ---- */
.profile-strip {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 14px;
  margin: 14px 0 2px;
  cursor: pointer;
  text-align: left;
}
.profile-strip:hover { background: var(--surface-2); }
.profile-avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(180deg, #34d399, #059669);
  color: #fff; font-weight: 800; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 0 #065f46;
}
.profile-main { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.profile-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-stats { font-size: 11px; color: var(--text-dim); }
.xp-bar { display: block; height: 5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.xp-fill { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #34d399, #059669); }
.profile-xp { font-size: 12px; font-weight: 700; color: var(--ok-text); white-space: nowrap; }

/* ---- Achievements gallery ---- */
.ach-card { max-width: min(92vw, 480px); }
.ach-title { text-transform: none; }
.ach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 18px; }
.ach-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--surface-1);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 6px;
  opacity: 0.45; filter: grayscale(1);   /* locked look; .got lights it up */
}
.ach-item.got { opacity: 1; filter: none; border-color: rgba(52, 211, 153, 0.5); }
.ach-icon { font-size: 22px; }
.ach-name { font-size: 11px; font-weight: 700; }
.ach-desc { font-size: 10px; color: var(--text-dim); }

/* ---- Global leaderboard (menu button + overlay) ---- */
.lb-open { width: 100%; margin: 10px 0 2px; }
.lb-card { max-width: min(92vw, 440px); }
.lb-tabs { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 0 0 14px; }
.lb-note { margin: 18px 0; }
.lb-list { list-style: none; margin: 0 0 16px; padding: 0; text-align: left; }
.lb-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-1);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 7px 10px;
  margin-bottom: 6px;
  font-size: 14px;
}
.lb-row.me { border-color: rgba(52, 211, 153, 0.55); background: rgba(52, 211, 153, 0.08); }
.lb-rank { flex: none; width: 30px; text-align: center; font-weight: 800; }
.lb-name { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-lvl { flex: none; font-size: 11px; color: var(--text-dim); }
.lb-xp { flex: none; font-weight: 800; color: var(--ok-text); white-space: nowrap; }

/* ---- First-visit welcome card ---- */
.welcome-card { max-width: min(92vw, 400px); }
.welcome-dice { font-size: 44px; line-height: 1; }
.welcome-points {
  list-style: none; margin: 0 0 20px; padding: 0; text-align: left;
}
.welcome-points li {
  background: var(--surface-1);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 13.5px;
}

/* ---- XP summary in the win overlay ---- */
.xp-report {
  background: var(--surface-1);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 0 14px;
  text-align: left;
}
.xp-line { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.xp-gain { margin-left: auto; font-weight: 800; color: var(--ok-text); }
.xp-levelup { font-weight: 800; color: #fbbf24; }
.ach-unlocks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ach-chip {
  background: rgba(52, 211, 153, 0.15);
  border: 1px solid rgba(52, 211, 153, 0.5);
  color: var(--ok-text);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px; font-weight: 700;
}

/* =========================================================================
 * Game screen
 * ======================================================================= */
.game { width: max-content; max-width: 100%; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.status {
  flex: 1;
  text-align: center;
  font-size: 14px; font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--c, var(--panel-border));
  border-radius: 999px;
  padding: 8px 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- Player pods (two above the board, two below, matching its corners) -- */
.pods-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  width: var(--board); margin: 10px auto;
}
.pod {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 8px 12px;
  min-height: 64px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.pod.active {
  border-color: var(--c);
  box-shadow: 0 0 14px color-mix(in srgb, var(--c) 55%, transparent);
}
.pod.finished { opacity: 0.75; }
.pod-empty { background: var(--surface-0); border: 1px dashed var(--panel-border); }

.pod-head { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.pod .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex: none; }
.pod-name { text-transform: capitalize; font-weight: 700; }
.pod-kind {
  font-size: 10px; font-weight: 700; letter-spacing: 0.4px;
  background: var(--surface-2); border-radius: 999px; padding: 2px 7px;
  color: var(--text-dim);
}
.pod-rank { margin-left: auto; font-size: 15px; }

.pod-body { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.pips { display: flex; gap: 5px; }
.pip {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1.5px solid var(--c); background: transparent;
}
.pip.home { background: var(--c); box-shadow: 0 0 5px var(--c); }

.pod-dice { min-height: 44px; display: flex; align-items: center; }

/* ---- Dice — a real 3D cube ------------------------------------------------
 * The button is just a transparent stage (perspective + ground shadow); the
 * .cube inside carries six absolutely-positioned faces pushed out with
 * translateZ. While rolling, a CSS animation tumbles the cube; when the class
 * comes off, the inline transform (the rolled value's orientation, set in
 * app.jsx) takes over and the transform transition eases it into place. */
.dice {
  width: 44px; height: 44px; --ds: 33px;
  padding: 0; border: none; background: transparent;
  cursor: default; position: relative;
  /* generous relative to the cube size — strong perspective fisheyes a die
   * this small and makes the pips hard to read */
  perspective: 420px;
  display: flex; align-items: center; justify-content: center;
}
/* soft ground shadow — pulls in while the die is airborne */
.dice::after {
  content: ''; position: absolute; left: 16%; right: 16%; bottom: 0; height: 7px;
  border-radius: 50%; background: var(--shadow); filter: blur(3px);
  transition: left 0.2s, right 0.2s, opacity 0.2s;
}
.dice.spinning::after { left: 30%; right: 30%; opacity: 0.6; }
.dice.clickable { cursor: pointer; animation: dice-nudge 1.1s infinite; }
@keyframes dice-nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.cube {
  position: relative; width: var(--ds); height: var(--ds);
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.22, 1.3, 0.36, 1);
}
.cube.rolling { animation: cube-tumble 0.55s linear infinite; }
@keyframes cube-tumble {
  from { transform: rotateX(0deg) rotateY(0deg); }
  to   { transform: rotateX(360deg) rotateY(720deg); }
}
/* landing spring: the `scale` property animates independently of the
 * orientation transform, so the pose settles while the size overshoots */
.dice.landed .cube { animation: cube-land 0.32s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes cube-land {
  from { scale: 1.3; }
  to   { scale: 1; }
}
.df {
  position: absolute; inset: 0; border-radius: 16%;
  background: linear-gradient(150deg, #ffffff 55%, #e4e9f0);
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.35);
  backface-visibility: hidden;
  /* side faces sit in "shade"; .front (the rolled value) stays bright */
  filter: brightness(0.78);
}
.df.front, .cube.rolling .df { filter: none; }
/* inset the pips like the old flat dice's padding — full-bleed pips sit on
 * the cube's rounded edges and look chopped off */
.df img { position: absolute; inset: 11%; width: 78%; height: 78%; display: block; }
/* real-die layout: opposite faces sum to 7 (1-6, 2-5, 3-4) */
.df1 { transform: translateZ(calc(var(--ds) / 2)); }
.df6 { transform: rotateY(180deg) translateZ(calc(var(--ds) / 2)); }
.df3 { transform: rotateY(90deg) translateZ(calc(var(--ds) / 2)); }
.df4 { transform: rotateY(-90deg) translateZ(calc(var(--ds) / 2)); }
.df2 { transform: rotateX(90deg) translateZ(calc(var(--ds) / 2)); }
.df5 { transform: rotateX(-90deg) translateZ(calc(var(--ds) / 2)); }
.dice-empty { font-size: 24px; line-height: 32px; }

/* ---- Board ---- */
.board {
  position: relative;
  width: var(--board); height: var(--board);
  margin: 0 auto;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 18px 50px var(--shadow);
}
.board-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; display: block;
  user-select: none; -webkit-user-drag: none;
}

/* ---- Tokens ----
 * One board cell is (100/15)% ≈ 6.667%. The pawn fits INSIDE one cell — and the
 * yard circles, which are exactly one cell wide — so it never spills over the
 * lines. left/top (set inline) place its CENTER, hence the centered translate.
 * left/top are transitioned so hops and capture fly-backs glide. */
.token {
  position: absolute;
  width: 4.1%; height: 6.4%;           /* pawn aspect ≈ 0.64 (6.61 : 10.4), < 1 cell */
  transform: translate(-50%, -50%);    /* dead-center on the cell / yard circle */
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
  cursor: default;
  transition: left 0.16s ease-in-out, top 0.16s ease-in-out;
}
.token svg { width: 100%; height: 100%; display: block; }

.token.lifted {
  transform: translate(-50%, -50%) scale(1.18);
  filter: drop-shadow(0 5px 6px rgba(0, 0, 0, 0.6));
}

/* Popping OUT of the yard (release): one longer glide with a springy overshoot
 * landing on the start square. Duration matches RELEASE_MS in app.jsx. */
.token.releasing {
  transition: left 0.34s cubic-bezier(0.3, 1.35, 0.6, 1), top 0.34s cubic-bezier(0.3, 1.35, 0.6, 1);
}

/* A captured token racing back to its yard ALONG the track it travelled
 * (not a straight-line jump): app.jsx retargets left/top every RETURN_MS,
 * so this transition must be just as short — and linear — to keep the token
 * on the path instead of cutting corners between cells. */
.token.returning {
  transition: left 0.05s linear, top 0.05s linear;
  transform: translate(-50%, -50%) scale(1.12);
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.6));
}

.token.movable { cursor: pointer; touch-action: manipulation; animation: pulse 0.85s infinite; }
.token.movable::before {
  content: "";
  position: absolute;
  left: 50%; top: 62%;
  width: 130%; height: 42%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 10px 2px rgba(255, 255, 255, 0.55);
  animation: halo 0.85s infinite;
}
@keyframes pulse {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(-50%, -57%); }
}
@keyframes halo {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.35; }
}

/* =========================================================================
 * Win overlay
 * ======================================================================= */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--overlay-bg);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 28px 34px;
  max-width: min(92vw, 440px);
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  text-align: center;
  backdrop-filter: blur(8px);
  box-shadow: 0 24px 60px var(--shadow);
  animation: card-in 0.35s ease-out;
  position: relative; z-index: 2;
}
@keyframes card-in {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.trophy { font-size: 52px; animation: trophy-pop 0.6s ease-out; }
@keyframes trophy-pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
.overlay-card h2 { margin: 6px 0 16px; font-size: 26px; text-transform: capitalize; }

.ranking { list-style: none; margin: 0 0 20px; padding: 0; text-align: left; }
.ranking li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 10px; font-weight: 600;
  background: var(--surface-1);
  margin-bottom: 6px;
}
.ranking .medal { width: 28px; text-align: center; font-size: 15px; }
.ranking .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); }

.overlay-btns { display: flex; gap: 10px; justify-content: center; }

/* ---- Leave-game confirmation ---- */
.confirm-card { max-width: min(88vw, 360px); }
.confirm-card h2 { text-transform: none; font-size: 22px; }
.confirm-card .menu-sub { margin: 0 0 18px; }
.confirm-card .btn-primary { width: auto; }
.btn-ghost.danger { border-color: rgba(229, 72, 77, 0.55); color: var(--danger-text); }
.btn-ghost.danger:hover { background: rgba(229, 72, 77, 0.18); }

.confetti {
  position: absolute; top: -12px; z-index: 1;
  width: 9px; height: 15px; border-radius: 2px;
  opacity: 0;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
@keyframes confetti-fall {
  0% { transform: translateY(-4vh) rotate(0); opacity: 1; }
  100% { transform: translateY(106vh) rotate(var(--spin)); opacity: 0.85; }
}

/* =========================================================================
 * Responsive layouts
 * ======================================================================= */

/* ---- Small phones (portrait) ---- */
@media (max-width: 480px) {
  :root {
    --board: max(min(94vw, calc(100vh - 224px)), 260px);
    --board: max(min(94vw, calc(100dvh - 224px)), 260px);
  }
  .pods-row { gap: 7px; margin: 8px auto; }
  .pod { min-height: 56px; padding: 7px 9px; }
  .pod-head { font-size: 12px; }
  .pod-dice { min-height: 40px; }
  .dice { width: 40px; height: 40px; --ds: 30px; }
  .topbar { gap: 7px; margin-bottom: 8px; }
  .status { font-size: 12px; padding: 7px 10px; white-space: normal; }
  .room-code-value { font-size: 28px; letter-spacing: 6px; }
  .overlay-card { padding: 22px 18px; }
  .overlay-card h2 { font-size: 22px; }
}

/* ---- Landscape phones, tablets and short windows: pods flank the board so
 * everything fits without scrolling. .pods-row dissolves (display: contents)
 * and the four pods + board + topbar become items of one grid. ---- */
@media (orientation: landscape) and (max-height: 800px) {
  body { align-items: center; }
  :root {
    --board: min(calc(100vh - 84px), 50vw, 560px);
    --board: min(calc(100dvh - 84px), 50vw, 560px);
  }
  .game {
    display: grid;
    grid-template-columns: minmax(132px, 220px) var(--board) minmax(132px, 220px);
    grid-template-rows: auto 1fr 1fr;
    grid-template-areas:
      "top  top   top"
      "p-tl board p-tr"
      "p-bl board p-br";
    gap: 8px 12px;
    align-items: stretch;
  }
  .topbar { grid-area: top; margin-bottom: 0; }
  .board { grid-area: board; margin: 0; }
  .pods-row { display: contents; }
  .pods-top > :first-child { grid-area: p-tl; }
  .pods-top > :last-child { grid-area: p-tr; }
  .pods-bottom > :first-child { grid-area: p-bl; }
  .pods-bottom > :last-child { grid-area: p-br; }
  /* Pods hug the board's corners, like the stacked layout. */
  .pods-top > .pod { align-self: start; }
  .pods-bottom > .pod { align-self: end; }
  .menu { margin-top: 0; }
}

/* ---- Large desktops: let the board and controls breathe. ---- */
@media (min-width: 1100px) and (min-height: 840px) {
  :root { --board: min(64vh, 680px); }
  .status { font-size: 15px; }
  .pod { min-height: 70px; padding: 10px 14px; }
  .pod-head { font-size: 14px; }
  .pod-dice { min-height: 50px; }
  .dice { width: 50px; height: 50px; --ds: 38px; }
  .menu { width: min(94vw, 460px); }
}

/* ---- Site links + sharing ---------------------------------------------------
 * .menu-footer stands in for the mcqmojo site header/footer (the hosted page
 * is standalone); .share-row is the WhatsApp/copy result-sharing strip on the
 * win and achievements overlays, matching the other games' share options. */
.menu-footer {
  display: flex;
  gap: 6px 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--panel-border);
}
.menu-footer a { color: var(--text-dim); font-size: 13px; text-decoration: none; white-space: nowrap; }
.menu-footer a:hover { color: var(--text); text-decoration: underline; }

.share-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 4px 0 12px; }
/* Anchors reuse .btn-ghost (buttons-only until now): kill link styling. */
a.btn-ghost { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.share-row .wa-btn { border-color: rgba(37, 211, 102, 0.55); color: var(--ok-text); }
.share-row .wa-btn:hover { background: rgba(37, 211, 102, 0.15); }

.lb-page-link { display: block; text-align: center; color: var(--text-dim); font-size: 13px; margin: 0 0 12px; }
.lb-page-link:hover { color: var(--text); }
