/* ==========================================================================
   Ludo Zoo — design system
   Toy-box look: sky gradient, chunky glassy trays, candy buttons with a
   pressable bottom edge, sticker lettering outlined in the same plum ink as
   the 3D animals' outlines. Bootstrap supplies grid/modal/toast/dropdown
   behaviour; everything visible is restyled here.
   ========================================================================== */

:root {
  /* Ink = the animals' outline colour, so UI and 3D art read as one family. */
  --ink: #2e1d2a;
  --ink-2: #5c4b5e;
  --ink-3: #8d7f90;
  --line: #e3edf7;

  --sky-top: #4aaeff;
  --sky-mid: #8fd2ff;
  --sky-low: #dcf2ff;

  /* Player colours (mirror board.js COLOR_HEX / COLOR_DARK / COLOR_LIGHT). */
  --red: #ff5a5f;    --red-d: #d63a44;    --red-l: #ffd6d7;
  --green: #3ccf6e;  --green-d: #22a653;  --green-l: #d2f6de;
  --yellow: #ffc53d; --yellow-d: #e0a100; --yellow-l: #fff0c7;
  --blue: #3d9bff;   --blue-d: #2173d9;   --blue-l: #d3e8ff;

  /* Candy accents. */
  --sun: #ffc93f;    --sun-d: #e3a008;
  --grass: #36c96a;  --grass-d: #1f9f50;
  --sky: #3d9bff;    --sky-d: #2173d9;
  --berry: #ff5a6e;  --berry-d: #d63a52;
  --cloud: #ffffff;  --cloud-d: #c7dbee;
  --gold: #ffcf3f;   --silver: #cfd9e6;  --bronze: #f0a56b;

  --tray: rgba(255, 255, 255, 0.88);
  --tray-edge: rgba(84, 146, 207, 0.38);
  --shadow-far: 0 26px 50px -26px rgba(16, 60, 120, 0.6);
  /* White text straight on the sky (or a passing cloud) needs a solid deep-blue outline to read. */
  --sky-text-outline: 0 2px 0 #1f64b3, 2px 0 0 #1f64b3, -2px 0 0 #1f64b3, 0 -2px 0 #1f64b3, 0 6px 14px rgba(16, 60, 120, 0.45);

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

  --r-xl: 30px;
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  /* Bootstrap hooks */
  --bs-body-font-family: var(--font-body);
  --bs-body-color: var(--ink);
  --bs-body-bg: transparent;
  --bs-border-radius: var(--r-md);
  --bs-link-color-rgb: 33, 115, 217;
}

/* ---------- Base ---------- */
*, *::before, *::after { -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
/* Quick repeated taps (emotes, Roll then a choice) must not double-tap zoom the fixed layout on
   iOS; pinch zoom still works. The board canvas sets its own touch-action: none. */
html { touch-action: manipulation; }
/* A game, not a document: long presses must not select text or pop up the iOS callout
   (copy / look up / share). Text fields stay editable and selectable. */
html {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, [contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  background-color: var(--sky-mid);
  background-image: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 48%, var(--sky-low) 100%);
  background-attachment: fixed;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, .font-display { font-family: var(--font-display); font-weight: 600; letter-spacing: 0.005em; }

button { font: inherit; color: inherit; }
button:not(:disabled) { cursor: pointer; }
img { -webkit-user-drag: none; user-select: none; }

/* Ink outline: readable on white trays and on the sky, and it never fights component shadows. */
:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}
.code-input:focus-visible { outline: none; }   /* the letter boxes show their own caret */

.c-red { color: var(--red); }
.c-green { color: var(--green); }
.c-yellow { color: var(--yellow); }
.c-blue { color: var(--blue); }

/* Colour context for anything tied to a player: set data-color on the element. */
[data-color="red"]    { --pc: var(--red);    --pc-d: var(--red-d);    --pc-l: var(--red-l); }
[data-color="green"]  { --pc: var(--green);  --pc-d: var(--green-d);  --pc-l: var(--green-l); }
[data-color="yellow"] { --pc: var(--yellow); --pc-d: var(--yellow-d); --pc-l: var(--yellow-l); }
[data-color="blue"]   { --pc: var(--blue);   --pc-d: var(--blue-d);   --pc-l: var(--blue-l); }

/* ---------- Sky scenery ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; transition: opacity 0.6s; }
body.on-game .sky { opacity: 0; }
/* Behind the 3D board in the other worlds: deep space (the stars and planets are in 3D), and a
   brighter tropical sky over the sea. */
body.on-game[data-world="space"] {
  background-color: #120f33;
  background-image:
    radial-gradient(ellipse 60% 40% at 18% 22%, rgba(255, 110, 199, 0.28), transparent 70%),
    radial-gradient(ellipse 55% 45% at 85% 70%, rgba(80, 150, 255, 0.3), transparent 70%),
    linear-gradient(180deg, #1b1446 0%, #120f33 55%, #0a0a24 100%);
}
body.on-game[data-world="water"] { background-image: linear-gradient(180deg, #3fb4ff 0%, #9fe1ff 55%, #e2f7ff 100%); }
/* Painted planets behind the (transparent) board canvas, so they show whatever the screen's shape. */
body[data-world="space"] .board-canvas {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 220 140'%3E %3Cdefs%3E %3CclipPath id='p'%3E%3Ccircle cx='110' cy='70' r='46'/%3E%3C/clipPath%3E %3CclipPath id='f'%3E%3Crect x='0' y='70' width='220' height='70'/%3E%3C/clipPath%3E %3CradialGradient id='s' cx='34%25' cy='28%25' r='80%25'%3E%3Cstop offset='0' stop-color='%23fff' stop-opacity='.38'/%3E%3Cstop offset='.6' stop-color='%23fff' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%232a0f3a' stop-opacity='.45'/%3E%3C/radialGradient%3E %3C/defs%3E %3Cg transform='rotate(-16 110 70)'%3E%3Cellipse cx='110' cy='70' rx='100' ry='22' fill='none' stroke='%23ffd9b0' stroke-width='10' opacity='.55'/%3E%3C/g%3E %3Cg clip-path='url(%23p)'%3E%3Crect width='220' height='140' fill='%23ff9f6b'/%3E%3Crect y='36' width='220' height='9' fill='%23f37b5c'/%3E%3Crect y='52' width='220' height='14' fill='%23ffc59a'/%3E%3Crect y='74' width='220' height='7' fill='%23e8685a'/%3E%3Crect y='88' width='220' height='12' fill='%23ffb88a'/%3E%3Crect y='104' width='220' height='6' fill='%23f37b5c'/%3E%3C/g%3E %3Ccircle cx='110' cy='70' r='46' fill='url(%23s)'/%3E %3Cg transform='rotate(-16 110 70)' clip-path='url(%23f)'%3E%3Cellipse cx='110' cy='70' rx='100' ry='22' fill='none' stroke='%23ffe6c8' stroke-width='10'/%3E%3Cellipse cx='110' cy='70' rx='86' ry='17' fill='none' stroke='%23f0b890' stroke-width='4'/%3E%3C/g%3E %3C/svg%3E"), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E %3Cdefs%3E%3CradialGradient id='m' cx='36%25' cy='30%25' r='80%25'%3E%3Cstop offset='0' stop-color='%23e3eaff'/%3E%3Cstop offset='.7' stop-color='%23a9b6e0'/%3E%3Cstop offset='1' stop-color='%237482b8'/%3E%3C/radialGradient%3E%3C/defs%3E %3Ccircle cx='50' cy='50' r='44' fill='url(%23m)'/%3E %3Ccircle cx='36' cy='40' r='8' fill='%238c99c9' opacity='.7'/%3E%3Ccircle cx='62' cy='62' r='11' fill='%238c99c9' opacity='.6'/%3E%3Ccircle cx='64' cy='32' r='5' fill='%238c99c9' opacity='.7'/%3E%3Ccircle cx='34' cy='68' r='5' fill='%238c99c9' opacity='.6'/%3E %3C/svg%3E");
  background-repeat: no-repeat;
  background-size: min(62vw, 360px) auto, min(20vw, 110px) auto;
  background-position: left -12vw bottom 13%, right 5% top 26%;
}

.cloud {
  position: absolute;
  width: 220px; height: 70px;
  background: #fff;
  border-radius: 999px;
  opacity: 0.9;
  filter: drop-shadow(0 10px 0 rgba(120, 180, 230, 0.25));
  animation: cloud-drift 90s linear infinite;
}
.cloud::before, .cloud::after { content: ''; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 100px; height: 100px; left: 34px; top: -48px; }
.cloud::after { width: 76px; height: 76px; left: 112px; top: -30px; }
.cloud-a { top: 12%; left: -240px; animation-duration: 95s; }
.cloud-b { top: 30%; left: -240px; transform: scale(0.65); animation-duration: 120s; animation-delay: -60s; opacity: 0.75; }
.cloud-c { top: 6%; left: -240px; transform: scale(0.45); animation-duration: 140s; animation-delay: -25s; opacity: 0.7; }
@keyframes cloud-drift { from { translate: 0 0; } to { translate: calc(100vw + 480px) 0; } }

.hills { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 22vh; min-height: 120px; }
.hill-back { fill: #8fdc6a; }
.hill-front { fill: #6fcf55; }

/* ---------- Screens ---------- */
#app { position: relative; z-index: 1; height: 100%; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 14px) calc(var(--safe-r) + 18px) calc(var(--safe-b) + 24px) calc(var(--safe-l) + 18px);
}
.screen[hidden] { display: none; }
.screen.is-entering { animation: screen-in 0.4s cubic-bezier(0.33, 1, 0.68, 1) backwards; }
@keyframes screen-in { from { opacity: 0; transform: translateY(14px); } }
.screen-game { padding: 0; overflow: hidden; }
/* Room for the on-screen keyboard under a focused field (app.js _wireKeyboard). */
.screen.has-keyboard::after { content: ''; display: block; flex: none; height: var(--kb, 0px); }
/* Touch screens: the home page and lobby always rubber-band when pulled, like a native app, even
   when everything fits. A scroll area only springs if it can scroll, so an invisible spacer makes
   them exactly 1px taller than the screen; contain keeps the pull from reaching the page itself
   (the body's overscroll stays off, so the game board never bounces). */
@media not all and (any-pointer: fine) {
  .screen-menu, .screen-lobby { overscroll-behavior-y: contain; }
  .screen-menu::before, .screen-lobby::before {
    content: '';
    position: absolute; top: 0; left: 0;
    width: 1px; height: calc(100% + 1px);
    pointer-events: none;
  }
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto 10px;
  min-height: 48px;
}
.topbar-start { display: flex; gap: 8px; }
.topbar-end { display: flex; gap: 8px; justify-content: flex-end; grid-column: 3; }
.topbar-title { margin: 0; font-size: 1.35rem; color: #fff; text-shadow: var(--sky-text-outline); }

/* ---------- Trays (glassy toy cards) ---------- */
.tray, .screen-lobby > .lobby-start {
  background: var(--tray);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: var(--r-xl);
  box-shadow: 0 7px 0 var(--tray-edge), var(--shadow-far);
}

/* ---------- Candy buttons ---------- */
.btn-candy {
  --face: var(--cloud);
  --edge: var(--cloud-d);
  --text: var(--ink);
  --lift: 5px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-height: 46px;
  padding: 0.62em 1.2em;
  border: 0;
  border-radius: var(--r-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.1;
  letter-spacing: 0.01em;
  color: var(--text);
  background-color: var(--face);
  background-image: linear-gradient(180deg, color-mix(in srgb, var(--face) 70%, #fff) 0%, var(--face) 52%);
  box-shadow:
    0 var(--lift) 0 var(--edge),
    0 calc(var(--lift) + 8px) 16px -8px rgba(20, 60, 110, 0.45),
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -2px 0 rgba(0, 0, 0, 0.05);
  transform: translateY(0);
  transition: transform 0.09s ease, box-shadow 0.09s ease, filter 0.15s ease;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
}
.btn-candy:hover:not(:disabled) { filter: brightness(1.05) saturate(1.06); }
.btn-candy:active:not(:disabled), .btn-candy.is-pressed {
  transform: translateY(calc(var(--lift) - 1px));
  box-shadow: 0 1px 0 var(--edge), 0 3px 8px -4px rgba(20, 60, 110, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.45);
}
.btn-candy:disabled { cursor: not-allowed; filter: saturate(0.35) brightness(1.02); opacity: 0.72; }
.btn-candy .bi { font-size: 1.1em; line-height: 1; }

.btn-candy-sun   { --face: var(--sun);   --edge: var(--sun-d);   --text: var(--ink); }
.btn-candy-grass { --face: var(--grass); --edge: var(--grass-d); --text: #fff; }
.btn-candy-sky   { --face: var(--sky);   --edge: var(--sky-d);   --text: #fff; }
.btn-candy-berry { --face: var(--berry); --edge: var(--berry-d); --text: #fff; }
.btn-candy-cloud { --face: var(--cloud); --edge: var(--cloud-d); --text: var(--ink); }
.btn-candy-grass, .btn-candy-sky, .btn-candy-berry { text-shadow: 0 2px 0 rgba(0, 0, 0, 0.16); }

.btn-candy.btn-sm { min-height: 38px; padding: 0.45em 0.9em; font-size: 0.95rem; border-radius: var(--r-sm); --lift: 4px; }
.btn-candy.btn-lg { min-height: 54px; font-size: 1.15rem; padding: 0.7em 1.4em; }
.btn-candy.btn-xl { min-height: 62px; font-size: 1.35rem; border-radius: 20px; --lift: 6px; }

.btn-candy.is-busy { pointer-events: none; }
.btn-candy.is-busy .btn-text::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.1s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 46px; height: 46px;
  border: 0;
  border-radius: 15px;
  font-size: 1.3rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 0 var(--cloud-d), 0 10px 18px -10px rgba(20, 60, 110, 0.5);
  transition: transform 0.09s, box-shadow 0.09s, background 0.15s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--cloud-d); }

/* ---------- Coins (top right, next to the settings gear) ---------- */
.coin-pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 46px; padding: 0 14px 0 10px;
  border-radius: 15px;
  font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; line-height: 1;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 0 var(--cloud-d), 0 10px 18px -10px rgba(20, 60, 110, 0.5);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border: 0;
  cursor: pointer;
  transition: transform 0.09s ease, box-shadow 0.09s ease;
}
.coin-pill:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--cloud-d); }
.coin-icon {
  position: relative; flex: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff7c7 0 14%, #ffd54a 42%, #f0a400 100%);
  box-shadow: inset 0 0 0 2px #dd9500, inset 0 -3px 0 rgba(150, 85, 0, 0.3);
}
.coin-icon::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.6); }
.coin-pill.is-bump { animation: coin-bump 0.7s var(--ease-bounce); }
@keyframes coin-bump { 0% { transform: scale(1); } 30% { transform: scale(1.28); } 100% { transform: scale(1); } }
.hud-menu { display: flex; align-items: center; gap: 8px; }
.icon-btn-soft { box-shadow: none; background: #eef5fc; width: 52px; height: 52px; font-size: 1.5rem; color: #f5a623; }
.icon-btn-soft:active { transform: translateY(2px); box-shadow: none; }

.link-btn { background: none; border: 0; color: #fff; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Form fields ---------- */
.field { margin-bottom: 16px; }
.field-label { display: block; margin-bottom: 7px; font-family: var(--font-display); font-weight: 600; font-size: 1rem; color: var(--ink-2); }
.field-error { min-height: 0; font-size: 0.9rem; font-weight: 700; color: var(--berry-d); }
.field-error:not(:empty) { margin-top: 6px; }

.input-chunky.form-control, .input-chunky.form-select {
  height: 52px;
  padding: 0 16px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.2rem;
  color: var(--ink);
  background: #fff;
  border: 3px solid #dbe8f4;
  border-radius: var(--r-md);
  box-shadow: inset 0 3px 0 rgba(20, 60, 110, 0.06);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-chunky.form-control::placeholder { color: #b6c3d1; }
.input-chunky.form-control:focus, .input-chunky.form-select:focus { border-color: var(--sky); box-shadow: 0 0 0 4px rgba(61, 155, 255, 0.22); }
/* The shorthand background above drops Bootstrap's arrow: a chunkier one in the ink colour. */
.input-chunky.form-select {
  padding-right: 46px;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%235c4b5e' stroke-linecap='round' stroke-linejoin='round' stroke-width='2.5' d='m3 6 5 5 5-5'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 16px 16px;
  cursor: pointer;
}
.input-chunky.is-invalid { border-color: var(--berry) !important; }

.shake { animation: shake 0.42s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px) rotate(-1deg); }
  40% { transform: translateX(6px) rotate(1deg); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.hint { margin: 8px 0 0; font-size: 0.92rem; color: var(--ink-2); text-align: center; }
.hint:empty { display: none; }

/* ---------- Avatars (animal portraits) ---------- */
.avatar {
  --size: 44px;
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--size); height: var(--size);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #fff 0%, var(--pc-l, #eaf4ff) 72%);
  box-shadow: 0 0 0 3px var(--pc, #fff), 0 3px 0 3px var(--pc-d, var(--cloud-d));
  overflow: hidden;
}
/* The portrait is a head-and-shoulders shot: zoom in a little and lift it so the whole face sits in
   the circle with the scarf at the bottom. Positioned against the avatar box itself, so the
   framing doesn't depend on how the inline-grid sizes its track. */
.avatar img { position: absolute; left: -10%; top: -17%; width: 120%; height: 120%; max-width: none; object-fit: cover; }
.avatar .avatar-emoji { font-size: calc(var(--size) * 0.58); line-height: 1; }
.avatar.is-loading .avatar-emoji { opacity: 0.85; }

/* ---------- Boot splash ---------- */
.boot {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center;
  transition: opacity 0.4s ease, visibility 0.4s;
}
body:not(.is-booting) .boot { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-logo { font-family: var(--font-display); font-weight: 700; font-size: clamp(48px, 12vw, 88px); }
.boot-logo .lt { display: inline-block; animation: letter-hop 1.6s var(--ease-out) infinite; }
.boot-logo .lt:nth-child(2) { animation-delay: 0.08s; } .boot-logo .lt:nth-child(3) { animation-delay: 0.16s; }
.boot-logo .lt:nth-child(4) { animation-delay: 0.24s; } .boot-logo .lt:nth-child(5) { animation-delay: 0.4s; }
.boot-logo .lt:nth-child(6) { animation-delay: 0.48s; } .boot-logo .lt:nth-child(7) { animation-delay: 0.56s; }
.boot-msg { color: #fff; font-family: var(--font-display); font-size: 1.2rem; text-shadow: var(--sky-text-outline); }
.boot-error { max-width: 340px; padding: 18px; background: var(--tray); border-radius: var(--r-lg); }
.boot-error p:last-child { margin-bottom: 0; }   /* the "browser too old" card has no Reload button */
.dots span { animation: blink 1.2s infinite; } .dots span:nth-child(2) { animation-delay: 0.2s; } .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }

.noscript-card { position: fixed; inset: 20% 16px auto; z-index: 60; max-width: 420px; margin: 0 auto; padding: 24px; text-align: center; background: #fff; border-radius: var(--r-lg); }

/* ---------- Sticker lettering (logo, banners) ---------- */
.lt, .sticker {
  display: inline-block;
  text-shadow:
    0 -4px 0 var(--ink), 4px 0 0 var(--ink), 0 4px 0 var(--ink), -4px 0 0 var(--ink),
    3px -3px 0 var(--ink), 3px 3px 0 var(--ink), -3px 3px 0 var(--ink), -3px -3px 0 var(--ink),
    2px 7px 0 var(--ink), -2px 7px 0 var(--ink), 0 10px 0 var(--ink);
}

.logo {
  margin: 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0 0.28em;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(64px, 11vw, 124px);
  line-height: 0.95;
  letter-spacing: 0.01em;
}
.logo-word { white-space: nowrap; }
.logo .lt { --r: -4deg; animation: letter-hop 3.6s var(--ease-out) infinite; animation-delay: calc(var(--i, 0) * 0.11s); transform-origin: 50% 90%; }
.logo .logo-word .lt:nth-child(1) { --i: 0; --r: -5deg; }
.logo .logo-word .lt:nth-child(2) { --i: 1; --r: 4deg; }
.logo .logo-word .lt:nth-child(3) { --i: 2; --r: -3deg; }
.logo .logo-word .lt:nth-child(4) { --i: 3; --r: 5deg; }
.logo .logo-word + .logo-word .lt:nth-child(1) { --i: 5; --r: 4deg; }
.logo .logo-word + .logo-word .lt:nth-child(2) { --i: 6; --r: -5deg; }
.logo .logo-word + .logo-word .lt:nth-child(3) { --i: 7; --r: 3deg; }
@keyframes letter-hop {
  0%, 62%, 100% { transform: translateY(0) rotate(var(--r, 0deg)) scale(1); }
  70% { transform: translateY(-16px) rotate(calc(var(--r, 0deg) * -1)) scale(0.96, 1.05); }
  79% { transform: translateY(0) rotate(var(--r, 0deg)) scale(1.1, 0.9); }
  86% { transform: translateY(-3px) rotate(var(--r, 0deg)) scale(0.97, 1.03); }
}

.tagline {
  margin: 14px auto 0;
  max-width: 30ch;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.05rem, 1.8vw, 1.3rem);
  line-height: 1.35;
  color: #fff;
  text-align: center;
  text-shadow: var(--sky-text-outline);
}

/* ---------- Menu ---------- */
.menu-layout {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 430px);
  align-items: center;
  gap: 28px 44px;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}
.menu-hero { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.hero-stage-wrap { width: 100%; max-width: 560px; }
.hero-stage { --stage-h: clamp(200px, 34vh, 320px); --stage-gap: 6px; cursor: pointer; }
/* The animal stages frame headroom above the animals for hop-ins and jumps (scene3d.js AnimalStage),
   so each canvas is drawn a sixth taller than the room it takes (--stage-h) and reaches up over the
   words or card above it. It is transparent there, and the lobby's lets clicks through to the card. */
.hero-stage, .lobby-stage {
  height: calc(var(--stage-h) * 1.16);
  margin-top: calc(var(--stage-gap, 0px) - var(--stage-h) * 0.16);
}
/* The preview's grassy disc is wider than its canvas; feather the edges so it floats instead of being clipped. */
.hero-stage, .lobby-stage {
  -webkit-mask-image: radial-gradient(ellipse 50% 58% at 50% 40%, #000 64%, transparent 100%);
  mask-image: radial-gradient(ellipse 50% 58% at 50% 40%, #000 64%, transparent 100%);
}
.menu-card { padding: 22px 22px 20px; position: relative; }

.invite-banner {
  display: flex; gap: 10px; align-items: center;
  margin: -4px -4px 16px; padding: 12px 14px;
  font-size: 0.98rem; line-height: 1.35;
  background: var(--yellow-l);
  border: 2px dashed var(--yellow-d);
  border-radius: var(--r-md);
}
.invite-emoji { font-size: 1.8rem; }
.invite-banner strong { font-family: var(--font-display); letter-spacing: 0.08em; }

.animal-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
/* Animal pickers: two rows that scroll sideways (free animals first), showing a peek of the next
   column. The padding (undone by the negative margin) keeps a picked tile's lift, its tick and the
   lock badges inside the scroller, which would otherwise clip them. */
.animal-grid {
  --gap: 10px; --cols: 4.35;
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, auto);
  grid-auto-columns: calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols));
  gap: var(--gap);
  overflow-x: auto; overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 7px;
  scrollbar-width: none;
  padding: 10px 7px 9px; margin: -10px -7px -9px;
}
.animal-grid::-webkit-scrollbar { display: none; }
.animal-grid > .animal-tile { scroll-snap-align: start; }
/* Fade out the side that has more to scroll to. */
.animal-grid.can-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 30px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 30px), transparent); }
.animal-grid.can-left { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 30px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 30px), transparent); }
.animal-grid.can-left.can-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 30px, #000 calc(100% - 30px), transparent); mask-image: linear-gradient(to right, transparent, #000 30px, #000 calc(100% - 30px), transparent); }
.animal-tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px;
  border: 0;
  border-radius: var(--r-md);
  background: #f2f7fc;
  box-shadow: 0 4px 0 #d6e4f1;
  transition: transform 0.15s var(--ease-bounce), box-shadow 0.15s, background 0.15s;
}
.animal-tile .avatar { --size: 54px; box-shadow: none; background: radial-gradient(circle at 50% 40%, #fff 0%, #e4f0fb 75%); }
.animal-tile .tile-name { font-family: var(--font-display); font-weight: 500; font-size: 0.86rem; color: var(--ink-2); }
.animal-tile:hover:not(:disabled) { transform: translateY(-3px) rotate(-1.5deg); }
.animal-tile[aria-checked="true"] {
  background: #fff;
  box-shadow: 0 0 0 3px var(--pc, var(--sun)), 0 7px 0 var(--pc-d, var(--sun-d));
  transform: translateY(-3px);
}
.animal-tile[aria-checked="true"] .tile-name { color: var(--ink); }
.animal-tile[aria-checked="true"]::after {
  content: '\F26E'; font-family: 'bootstrap-icons';
  position: absolute; top: -8px; right: -6px;
  display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 1rem; color: #fff;
  background: var(--pc-d, var(--sun-d));
  box-shadow: 0 0 0 2px #fff;
}
.animal-tile:disabled { cursor: not-allowed; transform: none; box-shadow: none; background: rgba(242, 247, 252, 0.6); }
.animal-tile:disabled > .avatar:not(.taken-by), .animal-tile:disabled .tile-name { opacity: 0.38; filter: grayscale(0.85); }
/* Who took it: the owner's own portrait, crisp, in their colour. */
.animal-grid .animal-tile .avatar.taken-by { position: absolute; top: -7px; right: -7px; --size: 28px; box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--pc); background: radial-gradient(circle at 50% 38%, #fff 0%, var(--pc-l) 72%); }
.animal-grid-sm { --gap: 8px; }
.animal-grid-sm .animal-tile .avatar { --size: 46px; }
.animal-grid-sm .tile-name { font-size: 0.78rem; }
/* Not yours yet: faded, with its shop price; tapping it opens the shop. */
.animal-tile.is-locked > .avatar:not(.taken-by), .animal-tile.is-locked .tile-name { opacity: 0.55; filter: grayscale(0.8); }
.tile-lock {
  position: absolute; top: -7px; left: -5px;
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px 6px 2px 5px; border-radius: 999px;
  font-family: var(--font-display); font-weight: 700; font-size: 0.72rem; line-height: 1.2;
  color: #6b3f00; background: #ffd54a; box-shadow: 0 0 0 2px #fff;
  font-variant-numeric: tabular-nums;
}
.tile-lock .bi { font-size: 0.85em; }
.field-label-row { position: relative; z-index: 1; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.shop-link {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: -5px; padding: 3px 11px; border: 0; border-radius: 999px;
  font-family: var(--font-display); font-weight: 600; font-size: 0.86rem; line-height: 1.3;
  color: #6b3f00; background: #ffe27a; box-shadow: 0 3px 0 #e9b52d;
  transition: transform 0.09s ease, box-shadow 0.09s ease;
}
.shop-link:active { transform: translateY(2px); box-shadow: 0 1px 0 #e9b52d; }

.menu-actions { display: flex; flex-direction: column; margin-top: 4px; }
/* Invited players: the join row comes first, creating a game becomes the alternative. */
.is-invited .menu-actions #joinForm { order: 1; }
.is-invited .menu-actions #joinError { order: 2; }
.is-invited .menu-actions .divider { order: 3; }
.is-invited .menu-actions .create-group { order: 4; }
/* The new game's world, right above "Create game": label and picker on one line. */
.world-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.menu-card .world-row .field-label { flex: none; margin: 0; }
.world-row .form-select { flex: 1 1 0; min-width: 0; }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0 14px; color: var(--ink-3); font-size: 0.92rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 3px; border-radius: 3px; background: var(--line); }

.join-row { display: flex; gap: 10px; align-items: stretch; }
.code-boxes { position: relative; flex: 1; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.code-input {
  position: absolute; inset: 0; z-index: 2;
  width: 100%; height: 100%;
  font-size: 16px; /* keeps iOS from zooming in */
  color: transparent; caret-color: transparent;
  background: transparent; border: 0; outline: none;
  letter-spacing: 1em;
  opacity: 0.01;
}
.code-box {
  display: grid; place-items: center;
  height: 52px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.55rem;
  color: var(--ink);
  background: #fff;
  border: 3px solid #dbe8f4;
  border-radius: var(--r-sm);
  box-shadow: inset 0 3px 0 rgba(20, 60, 110, 0.06);
  transition: border-color 0.15s, transform 0.18s var(--ease-bounce), background 0.15s;
}
.code-box.is-filled { border-color: #bcd6ee; animation: pop-in 0.22s var(--ease-bounce); }
.code-boxes.is-focused .code-box.is-caret { border-color: var(--sky); box-shadow: 0 0 0 4px rgba(61, 155, 255, 0.2); }
.code-boxes.is-focused .code-box.is-caret:not(.is-filled)::after { content: ''; width: 3px; height: 26px; border-radius: 2px; background: var(--sky); animation: blink 1s steps(2) infinite; }
.code-boxes.is-complete .code-box { border-color: var(--grass); background: #f1fcf5; }
.code-boxes.is-invalid .code-box { border-color: var(--berry); background: #fff5f6; }
.btn-join { min-width: 92px; }
@keyframes pop-in { 0% { transform: scale(0.7); } 100% { transform: scale(1); } }

.rejoin-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  margin: 0 0 16px; padding: 10px 14px 10px 10px;
  text-align: left;
  background: linear-gradient(90deg, var(--green-l), #fff);
  border: 3px solid var(--green);
  border-radius: var(--r-md);
  box-shadow: 0 4px 0 var(--green-d);
  transition: transform 0.1s, box-shadow 0.1s;
  animation: pop-in 0.35s var(--ease-bounce);
}
.rejoin-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-d); }
.rejoin-btn .avatar { --size: 44px; }
.rejoin-text { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.rejoin-title { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.rejoin-title strong { letter-spacing: 0.08em; }
.rejoin-sub { font-size: 0.86rem; color: var(--ink-2); }
.rejoin-btn > .bi { font-size: 1.7rem; color: var(--green-d); }

/* ---------- Lobby ---------- */
.lobby-layout {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 22px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  align-items: start;
  align-content: center;
}
.lobby-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.code-card { container: code-card / inline-size; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px 18px; padding: 16px 20px; }
.code-card-label { margin: 0 0 8px; font-family: var(--font-display); font-weight: 500; color: var(--ink-2); }
.code-tiles { display: flex; gap: 7px; }
.code-tile {
  display: grid; place-items: center;
  width: 50px; height: 58px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  color: var(--ink);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 5px 0 var(--pc-d, var(--cloud-d)), inset 0 -4px 0 var(--pc-l, #eef5fc);
  border-top: 3px solid var(--pc, #fff);
}
.code-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.code-actions .btn-candy.is-done { --face: var(--green-l); --edge: var(--green); }
/* A narrow code card (phones, or the main column of a phone held sideways) with the Share button:
   one row of three icon-over-label buttons instead of two rows with "Share" alone on the second.
   Equal columns also stop the reflow while a label reads "Link copied!". */
@container code-card (max-width: 380px) {
  .code-actions:has(> #shareBtn:not([hidden])) { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); width: 100%; }
  .code-actions:has(> #shareBtn:not([hidden])) .btn-candy { flex-direction: column; gap: 0; min-height: 44px; padding: 4px 2px; font-size: 0.8rem; white-space: normal; text-align: center; }
}
/* Very narrow cards (small phones, phones held sideways) shrink the code tiles so all six letters show. */
@container code-card (max-width: 290px) {
  .code-card .code-tiles { gap: 5px; }
  .code-card .code-tile { width: 36px; height: 46px; font-size: 1.5rem; border-radius: 11px; }
}

.lobby-stage-wrap { position: relative; }
.lobby-stage { --stage-h: clamp(170px, 26vh, 250px); pointer-events: none; }
.lobby-count {
  position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%);
  padding: 4px 14px;
  font-family: var(--font-display); font-weight: 600; font-size: 0.95rem;
  color: var(--ink-2); background: rgba(255, 255, 255, 0.9); border-radius: 999px;
  box-shadow: 0 3px 0 var(--tray-edge);
}

.slots { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.slot {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  min-height: 168px;
  padding: 18px 10px 14px;
  text-align: center;
  background: var(--tray);
  border: 3px solid #fff;
  border-radius: var(--r-lg);
  box-shadow: 0 6px 0 var(--pc-d, var(--tray-edge)), var(--shadow-far);
  animation: slot-in 0.45s var(--ease-bounce);
}
.slot::before {
  content: ''; position: absolute; inset: 0 0 auto; height: 44%;
  border-radius: 19px 19px 50% 50% / 19px 19px 22px 22px;
  background: var(--pc-l, transparent);
  z-index: -1;
}
@keyframes slot-in { 0% { transform: scale(0.8) translateY(10px); opacity: 0; } 100% { transform: none; opacity: 1; } }
.slot .avatar { --size: 76px; }
.slot-text { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.slot-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-display); font-weight: 600; font-size: 1.12rem; }
.slot-meta { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.badge-you, .badge-host, .badge-soft {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px;
  font-family: var(--font-display); font-weight: 600; font-size: 0.78rem;
  border-radius: 999px;
}
.badge-you { color: #fff; background: var(--pc-d, var(--sky-d)); }
[data-color="yellow"] .badge-you { color: var(--ink); }   /* white on dark yellow is ~2:1 */
.badge-host { color: #7a5200; background: #ffe7a3; }
.badge-soft { color: var(--ink-2); background: #eef3f8; }
.slot-crown { position: absolute; top: -18px; left: 50%; transform: translateX(-50%) rotate(-8deg); font-size: 1.8rem; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.15)); animation: crown-bob 2.6s ease-in-out infinite; }
@keyframes crown-bob { 0%, 100% { transform: translateX(-50%) rotate(-8deg) translateY(0); } 50% { transform: translateX(-50%) rotate(6deg) translateY(-3px); } }
.online-dot {
  position: absolute; right: 2px; bottom: 2px; z-index: 2;
  width: 16px; height: 16px; border-radius: 50%;
  background: #b8c4d0; box-shadow: 0 0 0 3px #fff;
}
.online-dot.is-on { background: var(--grass); }
.slot-kick {
  position: absolute; top: 8px; right: 8px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  font-size: 1rem; color: var(--ink-3);
  background: #fff; border: 0; border-radius: 10px;
  box-shadow: 0 3px 0 var(--cloud-d);
  transition: color 0.15s, transform 0.1s;
}
.slot-kick:hover { color: var(--berry-d); }
.slot-kick:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--cloud-d); }
.slot-empty {
  justify-content: center;
  color: var(--ink-3);
  background: rgba(255, 255, 255, 0.5);
  border: 3px dashed rgba(255, 255, 255, 0.95);
  box-shadow: none;
  animation: slot-pulse 2.4s ease-in-out infinite;
}
.slot-empty::before { display: none; }
.slot-empty .slot-plus { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; font-size: 1.8rem; color: #5d9ad3; background: rgba(255, 255, 255, 0.7); }
.slot-empty .slot-name { color: #3f78ad; font-weight: 500; }
@keyframes slot-pulse { 0%, 100% { opacity: 0.75; transform: scale(1); } 50% { opacity: 1; transform: scale(1.02); } }

.lobby-side { padding: 20px; position: sticky; top: 0; }
.side-title { margin: 0 0 14px; font-size: 1.4rem; }

.swatches { display: flex; gap: 12px; }
.swatch {
  position: relative;
  width: 48px; height: 48px;
  border: 0; border-radius: 50%;
  background: var(--pc);
  box-shadow: 0 4px 0 var(--pc-d), inset 0 3px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.18s var(--ease-bounce);
}
.swatch:hover:not(:disabled) { transform: translateY(-3px) scale(1.05); }
.swatch[aria-checked="true"] { transform: translateY(-3px) scale(1.08); box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--pc-d), 0 7px 0 4px var(--pc-d); }
.swatch[aria-checked="true"]::after { content: '\F26E'; font-family: 'bootstrap-icons'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.5rem; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2); }
.swatch:disabled { cursor: not-allowed; transform: scale(0.9); }
/* A taken colour shows the face of the player wearing it. */
.swatch .avatar.taken-by { position: absolute; left: 4px; top: 4px; --size: 40px; box-shadow: none; }

.lobby-start { margin: 22px 0 18px; }
/* Where the side panel stacks below the fold, app.js moves the start controls to the end of the
   screen (PIN_LOBBY_START_MQ), and they ride along the bottom edge as a sticky bar. Sticky keeps
   the bar's own space in the flow, so nothing ends up hidden under it at the end of the scroll. Its
   offset counts from inside the screen's bottom padding, which already clears the safe area. */
.screen-lobby > .lobby-start {
  position: sticky; bottom: 10px; z-index: 6;
  width: 100%; max-width: 640px;
  margin: 14px auto 0;
  padding: 10px 12px;
  border-radius: 24px;
}
.screen-lobby > .lobby-start .btn-xl { min-height: 54px; font-size: 1.2rem; }
.screen-lobby > .lobby-start .hint { margin: 4px 0 0; font-size: 0.82rem; }
.screen-lobby > .lobby-start .wait-host { padding: 10px; font-size: 1rem; }
.wait-host {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 16px;
  font-family: var(--font-display); font-weight: 500; font-size: 1.1rem;
  color: var(--ink-2);
  background: #f2f7fc;
  border-radius: var(--r-md);
}
.wait-dots { display: inline-flex; gap: 5px; }
.wait-dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--sky); animation: dot-bounce 1.1s ease-in-out infinite; }
.wait-dots span:nth-child(2) { animation-delay: 0.15s; background: var(--green); }
.wait-dots span:nth-child(3) { animation-delay: 0.3s; background: var(--yellow); }
@keyframes dot-bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-8px); } }

/* ---------- Emotes ---------- */
.emote-bar { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; padding-top: 14px; border-top: 3px solid var(--line); }
.emote-btn {
  display: grid; place-items: center;
  aspect-ratio: 1;
  min-width: 36px;
  font-size: 1.45rem;
  line-height: 1;
  background: #f2f7fc;
  border: 0; border-radius: 12px;
  box-shadow: 0 3px 0 #d6e4f1;
  transition: transform 0.15s var(--ease-bounce), box-shadow 0.1s;
}
.emote-btn:hover:not(:disabled) { transform: translateY(-3px) scale(1.12) rotate(-6deg); }
.emote-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #d6e4f1; }
.emote-btn:disabled { opacity: 0.4; cursor: default; }

.float-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.float-emoji {
  position: absolute;
  font-size: 46px;
  line-height: 1;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.12));
  will-change: transform, opacity;
}
.float-emoji .float-bubble {
  display: grid; place-items: center;
  width: 64px; height: 64px;
  background: #fff;
  border-radius: 50% 50% 50% 12%;
  box-shadow: 0 4px 0 var(--pc-d, var(--cloud-d)), 0 0 0 3px var(--pc, #fff);
}

/* ---------- Game HUD ---------- */
.board-canvas { position: absolute; inset: 0; z-index: 0; }
.board-canvas canvas { display: block; }
.no-webgl { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 1; max-width: 320px; padding: 18px; text-align: center; background: var(--tray); border-radius: var(--r-lg); }

.hud-top {
  position: absolute; z-index: 5;
  top: calc(var(--safe-t) + 12px); left: calc(var(--safe-l) + 12px); right: calc(var(--safe-r) + 12px);
  display: flex; justify-content: center; align-items: flex-start;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.hud-menu { position: absolute; right: 0; top: 0; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; gap: 10px; justify-content: center; max-width: calc(100% - 120px); }
.chip {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  min-width: 0;
  padding: 6px 14px 6px 6px;
  background: rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--pc-d), 0 14px 24px -14px rgba(16, 60, 120, 0.7);
  transition: transform 0.35s var(--ease-bounce), box-shadow 0.3s, opacity 0.3s, filter 0.3s;
}
.chip .avatar { --size: 46px; }
.chip-ring { position: absolute; left: 1px; top: 1px; width: 56px; height: 56px; pointer-events: none; transform: rotate(-90deg); opacity: 0; transition: opacity 0.3s; }
.chip-ring circle { fill: none; stroke: var(--pc-d); stroke-width: 5; stroke-linecap: round; transition: stroke 0.3s; }
.chip.is-turn .chip-ring { opacity: 1; }
.chip.is-urgent .chip-ring circle { stroke: var(--berry); }
.chip-body { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.chip-name { max-width: 128px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-display); font-weight: 600; font-size: 1rem; }
.chip-sub { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--ink-2); }
.home-dots { display: inline-flex; gap: 3px; }
.home-dots i { width: 10px; height: 10px; border-radius: 50%; background: #e3ebf3; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.06); transition: background 0.3s, transform 0.3s var(--ease-bounce); }
.home-dots i.on { background: var(--pc); box-shadow: inset 0 -2px 0 var(--pc-d); transform: scale(1.12); }
.chip-count { font-family: var(--font-display); font-weight: 600; }
.chip.is-turn {
  transform: translateY(2px) scale(1.07);
  background: #fff;
  box-shadow: 0 4px 0 var(--pc-d), 0 0 0 4px var(--pc);
}
/* The glow needs color-mix() (iOS 16.2+, Chrome 111+). Not as a second box-shadow line: with var()
   in it, a browser without color-mix() still picks it, then computes it to no shadow, ring and all. */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  .chip.is-turn { box-shadow: 0 4px 0 var(--pc-d), 0 0 0 4px var(--pc), 0 0 28px 6px color-mix(in srgb, var(--pc) 60%, transparent); }
}
.chip.is-turn .chip-name::after { content: ''; }
.chip.is-me .chip-name { color: var(--pc-d); }
.chip.is-offline { filter: grayscale(0.7); opacity: 0.8; }
.chip.is-away .online-dot { background: var(--sun); }   /* online, but timed out: we're playing for them */
.chip.is-left { filter: grayscale(1); opacity: 0.5; }
.chip.is-finished .avatar::after { content: none; }
.chip-medal { position: absolute; left: 30px; bottom: -8px; font-size: 1.25rem; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.15)); }
.chip .online-dot { left: 38px; right: auto; bottom: 4px; width: 13px; height: 13px; }
.chip-tag { font-family: var(--font-display); font-weight: 600; font-size: 0.72rem; color: var(--ink-3); }

/* Dock */
.dock {
  position: absolute; z-index: 5;
  left: 50%; bottom: calc(var(--safe-b) + 14px);
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: min(620px, calc(100% - 24px));
  pointer-events: none;
}
.dock > * { pointer-events: auto; }

/* ---------- Revenge: a pulsing angry button, 3 s after being bonked ---------- */
.revenge-btn {
  position: absolute; left: 6px; bottom: calc(100% + 16px); z-index: 8;
  display: grid; place-items: center;
  width: 84px; height: 84px; padding: 0; border: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 32%, #ff9a8a 0%, #ff4d4f 55%, #d72638 100%);
  box-shadow: 0 6px 0 #a3172a, 0 0 0 4px #fff, 0 16px 28px -8px rgba(160, 20, 40, 0.75);
  cursor: pointer;
  animation: revenge-in 0.35s var(--ease-bounce), revenge-pulse 0.55s ease-in-out 0.35s infinite alternate;
}
.revenge-btn[hidden] { display: none; }
.revenge-btn:active { transform: translateY(4px) scale(0.96); box-shadow: 0 2px 0 #a3172a, 0 0 0 4px #fff; animation: none; }
.revenge-emoji { font-size: 2.7rem; line-height: 1; filter: drop-shadow(0 3px 0 rgba(120, 10, 25, 0.35)); }
.revenge-label {
  position: absolute; left: 50%; bottom: -13px; transform: translateX(-50%);
  padding: 2px 11px; border-radius: 999px;
  font-family: var(--font-display); font-weight: 700; font-size: 0.86rem; line-height: 1.3; white-space: nowrap;
  color: #d72638; background: #fff; box-shadow: 0 3px 0 rgba(163, 23, 42, 0.35);
}
/* Time left: a gold ring round the button running out over the 3 s. */
.revenge-ring { position: absolute; inset: -11px; width: calc(100% + 22px); height: calc(100% + 22px); transform: rotate(-90deg); overflow: visible; pointer-events: none; }
.revenge-ring circle { fill: none; stroke: #ffd23f; stroke-width: 7; stroke-linecap: round; stroke-dasharray: 100; animation: revenge-time 3s linear forwards; }
@keyframes revenge-in { from { transform: scale(0.2) rotate(-25deg); opacity: 0; } }
@keyframes revenge-pulse { to { transform: scale(1.12); } }
@keyframes revenge-time { to { stroke-dashoffset: 100; } }
@media (prefers-reduced-motion: reduce) { .revenge-btn { animation: none; } }

/* ---------- Roll reveal: the latest roll as a big die just above the dock ---------- */
/* Absolutely placed, so showing it never changes the dock's size (the camera frames the board
   around the dock). Edges in the roller's colour; a six glows. */
.roll-reveal {
  --rr: 72px;
  position: absolute; left: 50%; bottom: 100%; z-index: 6;
  width: var(--rr); height: var(--rr);
  margin: 0 0 12px calc(var(--rr) / -2);
  perspective: 520px;
  pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.roll-reveal.is-shown { opacity: 1; visibility: visible; transition: opacity 0.12s ease; }
/* No resting tilt: the cube tumbles in 3D, then lands square-on, showing only the rolled face. */
.rr-die, .rr-tilt, .rr-cube { position: absolute; inset: 0; transform-style: preserve-3d; }
.rr-face {
  position: absolute; inset: 0;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); place-items: center;
  padding: 14%;
  background: #fffdf8;
  border: 4px solid var(--pc, #d5e0ea);
  border-radius: 24%;
  box-shadow: inset 0 -6px 0 rgba(46, 29, 42, 0.1);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.rr-face .pip { width: 74%; height: 74%; border-radius: 50%; background: var(--ink); box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.25); }
.rr-face.f1 .pip { width: 120%; height: 120%; background: #ff5a5f; }
.rr-face.f1 { transform: translateZ(calc(var(--rr) / 2)); }
.rr-face.f6 { transform: rotateY(180deg) translateZ(calc(var(--rr) / 2)); }
.rr-face.f3 { transform: rotateY(90deg) translateZ(calc(var(--rr) / 2)); }
.rr-face.f4 { transform: rotateY(-90deg) translateZ(calc(var(--rr) / 2)); }
.rr-face.f2 { transform: rotateX(90deg) translateZ(calc(var(--rr) / 2)); }
.rr-face.f5 { transform: rotateX(-90deg) translateZ(calc(var(--rr) / 2)); }
.roll-reveal.is-six .rr-die { animation: rr-six 1s ease-in-out 0.9s infinite alternate; }
@keyframes rr-six {
  from { filter: drop-shadow(0 0 0 rgba(255, 197, 61, 0)); }
  to   { filter: drop-shadow(0 0 14px rgba(255, 197, 61, 0.95)); }
}
.dock-status {
  max-width: 100%;
  padding: 6px 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;   /* one line: the dock never jumps */
  font-family: var(--font-display); font-weight: 500; font-size: 1.02rem;
  color: var(--ink);
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--tray-edge);
  transition: opacity 0.25s, transform 0.25s var(--ease-bounce);
}
.dock-status.is-hidden { opacity: 0; transform: translateY(6px); }
.dock-status.is-flash { animation: pop-in 0.3s var(--ease-bounce); }
.dock-tray { display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 12px; border-radius: 28px; }
/* min-height = the Roll button: the dock's resting height, which the board is framed above
   (app.js GameView._padding). The move choices may grow it; that growth is left out. */
.dock-main { flex: 1; display: flex; justify-content: center; align-items: center; min-width: 0; min-height: 68px; container: dock-main / inline-size; }
/* Wide screens: the dock widens while choosing so the choices fit one row and it doesn't grow. */
@media (min-width: 641px) and (min-height: 521px) {
  .dock.is-choosing { width: min(820px, calc(100% - 24px)); }
}

.last-die { flex: none; width: 58px; height: 58px; display: grid; place-items: center; }
/* No roll yet (game start, or rejoining before one): a quiet blank die holds the slot. */
.last-die:empty::before {
  content: '?';
  display: grid; place-items: center;
  width: 50px; height: 50px;
  font-family: var(--font-display); font-weight: 700; font-size: 1.5rem;
  color: #b9cadb;
  background: #eef4fa;
  border-radius: 15px;
  box-shadow: inset 0 -3px 0 #dde7f1;
}
.last-die svg { width: 56px; height: 56px; }
.last-die.is-new svg { animation: die-pop 0.5s var(--ease-bounce); }
@keyframes die-pop { 0% { transform: scale(0.4) rotate(-40deg); } 100% { transform: none; } }
.die-svg .die-face { fill: #fff; stroke: var(--ink); stroke-width: 5; }
.die-svg .die-edge { fill: var(--ink); }
.die-svg .die-pip { fill: var(--pip, var(--ink)); }

.roll-btn {
  --face: var(--pc, var(--grass));
  --edge: var(--pc-d, var(--grass-d));
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  width: min(100%, 280px);
  height: 68px;
  border: 0;
  border-radius: 22px;
  font-family: var(--font-display); font-weight: 700; font-size: 1.7rem; letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
  background-color: var(--face);
  background-image: linear-gradient(180deg, color-mix(in srgb, var(--face) 65%, #fff) 0%, var(--face) 55%);
  box-shadow: 0 7px 0 var(--edge), 0 16px 22px -10px rgba(16, 60, 120, 0.55), inset 0 3px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.09s, box-shadow 0.09s, filter 0.2s;
}
.roll-btn[data-color="yellow"] { color: var(--ink); text-shadow: 0 2px 0 rgba(255, 255, 255, 0.4); }
.roll-btn:active:not(:disabled) { transform: translateY(6px); box-shadow: 0 1px 0 var(--edge), inset 0 3px 0 rgba(255, 255, 255, 0.45); }
.roll-btn:disabled { filter: saturate(0.3) brightness(1.05); opacity: 0.7; cursor: default; }
.roll-btn.is-busy:disabled { filter: none; opacity: 1; }   /* my roll under way: inert, not broken */
.roll-btn.is-ready { animation: roll-pulse 1.6s ease-in-out infinite; }
.roll-btn.is-ready::after {
  content: ''; position: absolute; inset: -6px; border-radius: 28px;
  border: 4px solid var(--face);
  animation: ring-out 1.6s ease-out infinite;
  pointer-events: none;
}
@keyframes roll-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
@keyframes ring-out { 0% { opacity: 0.8; transform: scale(0.96); } 100% { opacity: 0; transform: scale(1.14, 1.3); } }
.roll-die {
  position: relative;
  width: 40px; height: 40px;
  background: #fff;
  border-radius: 11px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18), inset 0 -3px 0 #e2ebf3;
  transform: rotate(-12deg);
}
.roll-die .pip { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--edge); }
.roll-die .pip:nth-child(1) { left: 7px; top: 7px; } .roll-die .pip:nth-child(2) { right: 7px; top: 7px; }
.roll-die .pip:nth-child(3) { left: 16px; top: 16px; }
.roll-die .pip:nth-child(4) { left: 7px; bottom: 7px; } .roll-die .pip:nth-child(5) { right: 7px; bottom: 7px; }
.roll-btn.is-rolling .roll-die { animation: die-shake 0.32s linear infinite; }
@keyframes die-shake { 0% { transform: rotate(-12deg) translate(0, 0); } 25% { transform: rotate(20deg) translate(2px, -4px); } 50% { transform: rotate(-30deg) translate(-2px, 1px); } 75% { transform: rotate(10deg) translate(1px, -3px); } 100% { transform: rotate(-12deg); } }
.roll-btn[hidden] { display: none; }

.wait-pill {
  display: inline-flex; align-items: center; gap: 10px;
  max-width: 100%;
  padding: 6px 18px 6px 6px;
  font-family: var(--font-display); font-weight: 600; font-size: 1.1rem;
  color: var(--pc-d, var(--ink));
  background: var(--pc-l, #f2f7fc);
  border-radius: 999px;
  animation: pop-in 0.3s var(--ease-bounce);
}
.wait-pill .avatar { --size: 44px; }
.wait-pill .wait-icon { flex: none; display: grid; place-items: center; width: 44px; height: 44px; font-size: 1.5rem; background: #fff; border-radius: 50%; }
.wait-pill .wait-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.wait-pill .wait-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wait-pill .wait-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-body); font-weight: 700; font-size: 0.78rem; color: var(--ink-2); }
.wait-pill[data-color="yellow"] { color: #9a6c00; }

/* Move choices: equal buttons, two to a row (an odd last one centred); on wide docks one row. */
.move-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; }
.move-opt {
  display: flex; align-items: center; gap: 8px;
  width: 100%; min-width: 0;
  min-height: 56px;
  padding: 6px 12px 6px 8px;
  text-align: left;
  background: #fff;
  border: 3px solid var(--pc);
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--pc-d);
  transition: transform 0.15s var(--ease-bounce), box-shadow 0.1s;
  animation: pop-in 0.3s var(--ease-bounce) both;
}
.move-opt:last-child:nth-child(odd) { grid-column: 1 / -1; justify-self: center; width: calc(50% - 4px); }
@container dock-main (min-width: 540px) {
  .move-options { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 210px); justify-content: center; }
  .move-opt:last-child:nth-child(odd) { grid-column: auto; width: 100%; }
}
.move-opt:hover { transform: translateY(-3px); }
.move-opt:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--pc-d); }
/* The number matches the badge over the animal(s) on the board, and the 1–4 keys. */
.move-opt .keycap { flex: none; }
.move-opt-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.move-opt-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-display); font-weight: 600; font-size: 1rem; }
.move-opt-sub { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-size: 0.76rem; color: var(--ink-2); }
.move-opt.tag-bonk { border-color: var(--berry); box-shadow: 0 4px 0 var(--berry-d); }
.move-opt.tag-home { border-color: var(--grass); box-shadow: 0 4px 0 var(--grass-d); }

.keycap {
  display: inline-grid; place-items: center;
  min-width: 24px; height: 24px; padding: 0 6px;
  font-family: var(--font-display); font-weight: 600; font-size: 0.8rem;
  color: var(--ink-2);
  background: #f2f7fc;
  border-radius: 7px;
  box-shadow: 0 2px 0 #d3e1ee;
}

.emote-wrap { position: relative; flex: none; }
.emote-pop {
  position: absolute; right: -6px; bottom: calc(100% + 18px);
  display: grid; grid-template-columns: repeat(4, 48px); gap: 6px;
  padding: 10px;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--tray-edge), var(--shadow-far);
  transform-origin: 85% 100%;
  animation: pop-open 0.25s var(--ease-bounce);
}
.emote-pop::after { content: ''; position: absolute; right: 24px; bottom: -9px; width: 18px; height: 18px; background: #fff; transform: rotate(45deg); border-radius: 3px; }
.emote-pop[hidden] { display: none; }
/* Once opened it's moved to the top of the page and placed by app.js (_placeEmotes): above
   everything, the big die, floating emotes and toasts included. */
body > .emote-pop { position: fixed; z-index: 1100; }
.emote-pop .emote-btn { width: 48px; }
@keyframes pop-open { 0% { transform: scale(0.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* Candy dropdown (game settings) */
.candy-menu.dropdown-menu {
  --bs-dropdown-min-width: 230px;
  padding: 8px;
  border: 0;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 6px 0 var(--tray-edge), var(--shadow-far);
  margin-top: 10px !important;
}
.candy-menu .dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  font-family: var(--font-display); font-weight: 500; font-size: 1.02rem;
  color: var(--ink);
  border-radius: 12px;
}
.candy-menu .dropdown-item .bi { width: 22px; font-size: 1.1rem; color: var(--ink-2); }
.candy-menu .dropdown-item span:not(.switch) { flex: 1; }
.candy-menu .dropdown-item:hover, .candy-menu .dropdown-item:focus-visible { background: #eef5fc; }
.candy-menu .dropdown-item:active { background: #e1edf9; color: var(--ink); }
.candy-menu .dropdown-divider { margin: 6px 4px; border-top: 3px solid var(--line); opacity: 1; }
.candy-menu .text-danger-candy, .candy-menu .text-danger-candy .bi { color: var(--berry-d); }
.switch { position: relative; flex: none; width: 42px; height: 24px; border-radius: 999px; background: #d5e0ea; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15); transition: transform 0.25s var(--ease-bounce); }
[aria-pressed="true"] > .switch { background: var(--grass); }
[aria-pressed="true"] > .switch::after { transform: translateX(18px); }

/* ---------- Turn banner, countdown ---------- */
.turn-banner {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  padding-bottom: 14vh;
  pointer-events: none;
}
.banner-inner { text-align: center; white-space: nowrap; }
.banner-inner .sticker { font-family: var(--font-display); font-weight: 700; font-size: clamp(54px, 10vw, 104px); line-height: 1; color: var(--pc, var(--sun)); }
/* The reason line sits on a dark pill: bare white text vanishes over the cream board and the yards. */
.banner-inner .banner-sub {
  display: block; width: fit-content;
  margin: 16px auto 0; padding: 4px 16px;
  font-family: var(--font-display); font-weight: 600; font-size: clamp(18px, 2.5vw, 24px);
  color: #fff;
  background: rgba(46, 29, 42, 0.82);
  border-radius: 999px;
}

.countdown { position: fixed; inset: 0; z-index: 31; display: grid; place-items: center; pointer-events: none; }
.countdown .sticker { font-family: var(--font-display); font-weight: 700; font-size: clamp(110px, 22vw, 200px); line-height: 1; color: var(--sun); }
.countdown .sticker.go { color: var(--grass); }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed; z-index: 1090;
  top: calc(var(--safe-t) + 14px); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: min(440px, calc(100% - 24px));
  pointer-events: none;
}
body.on-game .toast-stack { top: calc(var(--safe-t) + var(--hud-top-h, 76px) + 16px); }
.candy-toast.toast {
  --bs-toast-max-width: 100%;
  display: flex; align-items: center; gap: 10px;
  width: auto; max-width: 100%;
  padding: 8px 16px 8px 8px;
  font-weight: 700; font-size: 0.98rem; line-height: 1.25;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--pc-d, var(--tray-edge)), 0 16px 26px -14px rgba(16, 60, 120, 0.65);
  /* Toasts hold no controls: let taps reach the buttons underneath (e.g. the lobby's Leave on
     phones). This also keeps a touch's synthetic mouseover from pausing Bootstrap's autohide. */
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.35s var(--ease-bounce);
}
.candy-toast.toast:not(.show) { display: flex; opacity: 0; transform: translateY(-14px) scale(0.92); }
.candy-toast.toast.hide { display: none; }
.candy-toast .toast-icon {
  flex: none;
  display: grid; place-items: center;
  width: 38px; height: 38px;
  font-size: 1.35rem;
  border-radius: 50%;
  background: var(--pc-l, #eef5fc);
}
.candy-toast .avatar { --size: 38px; }
.candy-toast .toast-text { min-width: 0; }
.candy-toast.tone-error { box-shadow: 0 4px 0 var(--berry-d), 0 16px 26px -14px rgba(16, 60, 120, 0.65); }
.candy-toast.tone-error .toast-icon { background: #ffe0e4; color: var(--berry-d); }

.net-pill {
  position: fixed; z-index: 1095;
  left: 50%; bottom: calc(var(--safe-b) + 16px);
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 18px;
  font-family: var(--font-display); font-weight: 600;
  color: var(--ink);
  background: var(--sun);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--sun-d), var(--shadow-far);
  animation: pop-in 0.3s var(--ease-bounce);
}
body.on-game .net-pill { bottom: auto; top: calc(var(--safe-t) + var(--hud-top-h, 76px) + 16px); }
.net-pill[hidden] { display: none; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 3px solid rgba(46, 29, 42, 0.25); border-top-color: var(--ink); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Results ---------- */
/* Safe centring: the two flex spacers centre the card while it fits; when it is taller than the
   screen they collapse and the card starts at the top padding, which leaves room for the trophy
   (grid centring would push the card's top above the scroll origin, out of reach). */
.results {
  position: fixed; inset: 0; z-index: 1050;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 48px) 16px calc(var(--safe-b) + 16px);
  overflow-y: auto;
  outline: 0;   /* the dialog itself takes focus when it opens without a keyboard, as Bootstrap's modals do */
  background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.12), rgba(18, 48, 96, 0.55));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.results::before, .results::after { content: ''; flex: 1 0 0; }
.results[hidden] { display: none; }
.results-card { position: relative; flex: none; width: min(600px, 100%); padding: 26px 24px 22px; text-align: center; }
.results-trophy { position: absolute; top: -40px; left: 50%; transform: translateX(-50%); font-size: 64px; filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.15)); animation: crown-bob 2.4s ease-in-out infinite; }
/* Names can be one long word (16 × "W"): let them break anywhere rather than widen the card. */
.results-title { margin: 14px 0 4px; font-size: clamp(2rem, 5vw, 2.8rem); font-weight: 700; overflow-wrap: anywhere; text-wrap: balance; }
.results-sub, .results-card .hint { overflow-wrap: anywhere; }
.results-sub { margin: 0 0 12px; color: var(--ink-2); font-size: 1.05rem; }

.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 10px; margin: 14px auto 8px; max-width: 460px; min-height: 240px; }
.podium-col { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.podium-col .avatar { --size: 74px; }
.podium-col.place-1 .avatar { --size: 92px; }
.podium-name { max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; line-height: 1.15; overflow-wrap: anywhere; }
.podium-medal { position: absolute; right: -10px; bottom: -6px; z-index: 1; font-size: 2rem; line-height: 1; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.15)); }
.podium-block {
  display: grid; place-items: start center;
  width: 100%;
  padding-top: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 2rem;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  background-color: var(--pc);
  background-image: linear-gradient(180deg, color-mix(in srgb, var(--pc) 75%, #fff) 0%, var(--pc) 40%);
  border-radius: 16px 16px 6px 6px;
  box-shadow: inset 0 -8px 0 var(--pc-d), 0 6px 0 rgba(0, 0, 0, 0.08);
  transform-origin: 50% 100%;
}
.podium-col.place-1 .podium-block { height: 130px; }
.podium-col.place-2 .podium-block { height: 96px; }
.podium-col.place-3 .podium-block { height: 70px; }
.podium-col.is-empty { visibility: hidden; }
/* app.js draws only the filled places (data-count); two or one of them sit centred, not in a 3-column grid. */
.podium[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 150px)); justify-content: center; }
.podium[data-count="1"] { grid-template-columns: minmax(0, 170px); justify-content: center; }
.podium-col.is-me .podium-name::after { content: ' (you)'; color: var(--ink-3); font-weight: 500; white-space: nowrap; }

.rest-list { list-style: none; margin: 8px auto 0; padding: 0; max-width: 420px; }
.rest-list:empty { display: none; }
.rest-list li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; margin-top: 6px; background: #f2f7fc; border-radius: 14px; font-weight: 700; }
.rest-list .avatar { --size: 34px; }
.rest-list .rest-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rest-list .rest-rank { margin-left: auto; font-family: var(--font-display); color: var(--ink-2); }

.results-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

/* ---------- Modals ---------- */
.candy-modal .modal-content {
  border: 3px solid #fff;
  border-radius: var(--r-xl);
  background: #fff;
  box-shadow: 0 8px 0 var(--tray-edge), var(--shadow-far);
}
.candy-modal {
  /* Keep dialogs clear of the notch/status bar and home indicator in the app (the page runs
     edge to edge), with a little extra room where there is an inset. */
  padding-top: calc(var(--safe-t) + min(var(--safe-t), 10px));
  padding-bottom: calc(var(--safe-b) + min(var(--safe-b), 6px));
}
.candy-modal .modal-header { padding: 18px 22px 8px; border: 0; }
.candy-modal .modal-title { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 1.7rem; overflow-wrap: anywhere; }
.candy-modal .modal-body { padding: 10px 22px 12px; font-size: 1.02rem; }
.candy-modal .modal-footer { padding: 10px 22px 20px; border: 0; gap: 10px; }
/* Scrolling dialogs: a soft edge above the footer shows the text carries on underneath. */
.candy-modal .modal-dialog-scrollable .modal-footer { position: relative; box-shadow: 0 -10px 14px -12px rgba(16, 60, 120, 0.35); }
.candy-modal .modal-footer > * { margin: 0; }
.modal-footer-split { display: grid; grid-template-columns: 1fr 1fr; }
.modal-sm-candy { max-width: 400px; }
.modal-emoji { font-size: 3.4rem; line-height: 1; margin: 6px 0 8px; }
.candy-modal .modal-body .modal-title { font-size: 1.5rem; margin-bottom: 6px; }
.candy-modal .modal-body p { color: var(--ink-2); margin-bottom: 0; }
.modal-backdrop { --bs-backdrop-bg: #173766; --bs-backdrop-opacity: 0.45; }
.candy-modal .modal-header .btn-close-candy { margin-left: auto; }

/* ---------- Daily reward ---------- */
.daily-coin { position: relative; width: 112px; height: 112px; margin: 4px auto 10px; perspective: 400px; }
.daily-coin .coin-icon {
  position: absolute; inset: 0; width: 100%; height: 100%;
  box-shadow: inset 0 0 0 7px #dd9500, inset 0 -9px 0 rgba(150, 85, 0, 0.3), 0 10px 22px -8px rgba(160, 100, 0, 0.6);
  animation: daily-spin 2.6s ease-in-out infinite;
}
.daily-coin .coin-icon::after { inset: 18px; border-width: 5px; }
.daily-shine {
  position: absolute; inset: -18px; z-index: -1; border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 213, 74, 0.55) 0deg 12deg, transparent 12deg 30deg);
  -webkit-mask-image: radial-gradient(circle, #000 35%, transparent 70%); mask-image: radial-gradient(circle, #000 35%, transparent 70%);
  animation: daily-rays 9s linear infinite;
}
@keyframes daily-spin { 0%, 55% { transform: rotateY(0deg); } 85%, 100% { transform: rotateY(360deg); } }
@keyframes daily-rays { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .daily-coin .coin-icon, .daily-shine { animation: none; } }
#dailyBody strong { color: #b86f00; }
#dailyClaim .coin-icon { width: 26px; height: 26px; }

/* ---------- Animal shop ---------- */
#shopModal .modal-header { gap: 10px; }
#shopModal .modal-header .coin-pill { margin-left: auto; height: 40px; padding: 0 12px 0 8px; font-size: 1.05rem; box-shadow: 0 3px 0 var(--cloud-d); background: #fff6d6; }
#shopModal .modal-header .btn-close-candy { margin-left: 0; }
.shop-intro { color: var(--ink-2); font-size: 0.95rem; margin: 0 0 14px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 12px; }
.shop-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 8px 12px; border-radius: var(--r-md);
  background: #f2f7fc; box-shadow: 0 4px 0 #d6e4f1;
}
.shop-card .avatar { --size: 64px; box-shadow: none; background: radial-gradient(circle at 50% 40%, #fff 0%, #e4f0fb 75%); }
.shop-card:not(.is-owned) .avatar { filter: grayscale(0.55); opacity: 0.8; }
.shop-card.is-current { background: #fff; box-shadow: 0 0 0 3px var(--sun), 0 6px 0 var(--sun-d); }
.shop-name { margin-top: 4px; font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; color: var(--ink); }
.shop-note { font-size: 0.8rem; color: var(--ink-2); min-height: 1.2em; }
.shop-card.is-owned .shop-note { color: #1f9d55; font-weight: 700; }
.shop-btn { width: 100%; min-height: 40px; margin-top: 8px; padding: 0.45em 0.6em; font-size: 1rem; --lift: 4px; }
.shop-btn .coin-icon { width: 20px; height: 20px; }
.shop-btn .coin-icon::after { inset: 4px; }
.shop-btn.is-armed { animation: shop-armed 0.9s ease-in-out infinite; }
@keyframes shop-armed { 50% { filter: brightness(1.12); transform: scale(1.04); } }
.shop-card.is-flash { animation: shop-flash 0.9s var(--ease-bounce); }
@keyframes shop-flash { 0% { transform: scale(1); } 35% { transform: scale(1.08) rotate(-2deg); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .shop-btn.is-armed, .shop-card.is-flash { animation: none; } }
.btn-close-candy { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 12px; font-size: 1.1rem; background: #eef5fc; box-shadow: 0 3px 0 #d3e1ee; }
.btn-close-candy:active { transform: translateY(2px); box-shadow: 0 1px 0 #d3e1ee; }
.candy-modal.fade .modal-dialog { transform: scale(0.9) translateY(10px); transition: transform 0.35s var(--ease-bounce); }
.candy-modal.show .modal-dialog { transform: none; }

/* How to play */
.howto-intro { font-size: 1.08rem; margin-bottom: 16px; }
.howto-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.howto-card { padding: 12px 14px 14px; background: #f3f8fd; border-radius: var(--r-lg); }
.howto-card h3 { margin: 10px 0 4px; font-size: 1.1rem; }
.howto-card p { margin: 0; font-size: 0.92rem; line-height: 1.4; color: var(--ink-2); }
.howto-art {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  height: 82px;
  background: #fff;
  border-radius: var(--r-md);
  box-shadow: inset 0 -4px 0 #e5eef7;
}
.howto-art .die-svg { width: 50px; height: 50px; }
.howto-art .die-svg.die-sm { width: 42px; height: 42px; }
.art-emoji { font-size: 2.3rem; line-height: 1; }
.art-tilt { transform: rotate(-24deg) translateY(6px); }
.art-arrow { font-size: 1.6rem; color: var(--ink-3); }
.art-track { display: inline-flex; gap: 4px; }
.art-track i { width: 20px; height: 20px; border-radius: 6px; background: #e7eef5; box-shadow: inset 0 -3px 0 #d3dde8; }
.art-track i.on { background: var(--green); box-shadow: inset 0 -3px 0 var(--green-d); }
.art-bonk { padding: 2px 10px; font-family: var(--font-display); font-weight: 700; font-size: 1rem; color: #fff; background: var(--berry); border-radius: 999px; transform: rotate(-8deg); box-shadow: 0 3px 0 var(--berry-d); }
.art-safe { display: grid; place-items: center; width: 44px; height: 44px; font-size: 1.5rem; color: #fff; background: #9fb5e6; border-radius: 12px; box-shadow: inset 0 -4px 0 #7f98cf; }
.art-plus { font-family: var(--font-display); font-weight: 700; font-size: 1.8rem; color: var(--grass-d); }
.art-timer { padding: 4px 12px; font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; color: #fff; background: var(--sky); border-radius: 999px; box-shadow: 0 3px 0 var(--sky-d); }
.howto-win { margin: 16px 0 6px; padding: 12px 16px; font-family: var(--font-display); font-weight: 500; font-size: 1.1rem; background: var(--yellow-l); border-radius: var(--r-md); }
.howto-keys { margin: 10px 0 0; font-size: 0.9rem; color: var(--ink-2); }
.howto-keys .keycap { margin: 0 2px; }
/* Keyboard shortcuts only where there's a keyboard-ish pointer; touch-only devices read tap wording. */
.keys-touch { display: none; }
@media not all and (any-pointer: fine) {
  .keys-kbd { display: none; }
  .keys-touch { display: inline; }
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .menu-layout { grid-template-columns: minmax(0, 1fr); gap: 8px; max-width: 520px; align-content: start; }
  .hero-stage { --stage-h: clamp(150px, 24vh, 220px); }
  .lobby-layout { grid-template-columns: minmax(0, 1fr); max-width: 640px; }
  .lobby-side { position: static; }
  .howto-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .screen { padding-left: calc(var(--safe-l) + 14px); padding-right: calc(var(--safe-r) + 14px); }
  .topbar-title { font-size: 1.15rem; }
  .icon-btn { width: 42px; height: 42px; font-size: 1.15rem; border-radius: 13px; }

  /* Menu: everything a little smaller and tighter, so the whole card fits under the logo. */
  .logo { font-size: 52px; }
  .tagline { margin-top: 10px; font-size: 1rem; }
  .menu-card { padding: 14px 12px 12px; border-radius: 24px; }
  .menu-card .field { margin-bottom: 10px; }
  .menu-card .field-label { margin-bottom: 6px; font-size: 0.92rem; }   /* room for a picked tile's lift */
  .menu-card .input-chunky.form-control, .menu-card .input-chunky.form-select { height: 46px; font-size: 1.1rem; }
  .menu-card .world-row { margin-bottom: 10px; }
  .invite-banner { gap: 8px; margin: 0 0 10px; padding: 6px 10px; font-size: 0.86rem; line-height: 1.3; }
  .invite-emoji { font-size: 1.3rem; }
  .rejoin-btn { gap: 10px; margin-bottom: 10px; padding: 6px 12px 6px 6px; }
  .rejoin-btn .avatar { --size: 36px; }
  .rejoin-title { font-size: 1rem; }
  .rejoin-sub { font-size: 0.8rem; }
  .rejoin-btn > .bi { font-size: 1.5rem; }
  .animal-grid { --gap: 6px; }
  .animal-tile { gap: 0; padding: 5px 2px 3px; }
  .animal-tile .avatar { --size: 40px; }
  .animal-tile .tile-name { font-size: 0.75rem; }
  .animal-tile[aria-checked="true"]::after { top: -7px; right: -5px; width: 20px; height: 20px; font-size: 0.85rem; }
  .animal-grid .animal-tile .avatar.taken-by { top: -6px; right: -6px; --size: 24px; }
  .menu-card .btn-xl { min-height: 52px; font-size: 1.2rem; border-radius: 18px; --lift: 5px; }
  .divider { margin: 10px 0 8px; font-size: 0.85rem; }
  .code-box { height: 44px; font-size: 1.3rem; }
  .btn-join { min-width: 76px; min-height: 44px; padding-left: 0.8em; padding-right: 0.8em; }

  /* Game: compact chips on top, dock across the bottom. */
  .hud-top { left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px); top: calc(var(--safe-t) + 8px); justify-content: flex-start; }
  .chips { gap: 6px; max-width: calc(100% - 118px); flex-wrap: nowrap; }
  .coin-pill { height: 44px; padding: 0 11px 0 8px; gap: 5px; font-size: 1.02rem; }
  .coin-icon { width: 20px; height: 20px; }
  .coin-icon::after { inset: 4px; }
  .chip { flex: 1 1 0; gap: 6px; padding: 4px 8px 4px 4px; }
  .chip .avatar { --size: 36px; }
  .chip-ring { width: 46px; height: 46px; left: 0; top: 0; }
  .chip-name { max-width: 100%; font-size: 0.82rem; }
  .chip-sub { gap: 4px; }
  .home-dots i { width: 7px; height: 7px; }
  .chip .online-dot { left: 28px; bottom: 2px; width: 11px; height: 11px; box-shadow: 0 0 0 2px #fff; }
  .chip-medal { left: 22px; font-size: 1rem; }
  .chip.is-turn { transform: translateY(1px) scale(1.04); }
  .hud-menu .icon-btn { width: 44px; height: 44px; }

  .dock { width: calc(100% - 16px); bottom: calc(var(--safe-b) + 10px); gap: 8px; }
  .dock-tray { gap: 8px; padding: 8px; border-radius: 24px; }
  .dock-main { min-height: 60px; }
  .dock.is-choosing .last-die { display: none; }        /* the choices need the width; they name the roll */
  .last-die, .last-die svg { width: 50px; height: 50px; }
  .last-die:empty::before { width: 42px; height: 42px; font-size: 1.3rem; }
  .roll-btn { height: 60px; font-size: 1.45rem; border-radius: 19px; }
  .roll-die { width: 34px; height: 34px; border-radius: 9px; }
  .roll-die .pip { width: 7px; height: 7px; }
  .roll-die .pip:nth-child(1) { left: 6px; top: 6px; } .roll-die .pip:nth-child(2) { right: 6px; top: 6px; }
  .roll-die .pip:nth-child(3) { left: 13.5px; top: 13.5px; }
  .roll-die .pip:nth-child(4) { left: 6px; bottom: 6px; } .roll-die .pip:nth-child(5) { right: 6px; bottom: 6px; }
  .icon-btn-soft { width: 46px; height: 46px; }
  .wait-pill { font-size: 1rem; padding-right: 14px; }
  .wait-pill .avatar { --size: 38px; }
  .wait-pill .wait-icon { width: 38px; height: 38px; font-size: 1.3rem; }
  .move-options { gap: 6px; }
  .move-opt { min-height: 48px; padding: 4px 8px 4px 6px; gap: 6px; }
  .move-opt-title { font-size: 0.92rem; }
  .move-opt-sub { font-size: 0.72rem; }
  .dock-status { font-size: 0.95rem; }

  .results-card { padding: 22px 14px 18px; }
  .podium { min-height: 200px; }
  .podium-col .avatar { --size: 58px; }
  .podium-col.place-1 .avatar { --size: 72px; }
  .podium-col.place-1 .podium-block { height: 104px; }
  .podium-col.place-2 .podium-block { height: 76px; }
  .podium-col.place-3 .podium-block { height: 56px; }
  .howto-grid { grid-template-columns: minmax(0, 1fr); }
  .howto-card { display: grid; grid-template-columns: 96px 1fr; gap: 0 12px; align-items: center; }
  .howto-card .howto-art { grid-row: span 2; height: 76px; gap: 2px; }
  .howto-card .howto-art .die-svg { width: 36px; height: 36px; }
  .howto-card .art-emoji { font-size: 1.4rem; }   /* the tilted pig and the fox fit the 96px art box */
  .howto-card h3 { margin-top: 0; }
  .howto-card .art-track i { width: 12px; height: 12px; }
  .howto-card .howto-art { overflow: hidden; }
  .howto-card .art-bonk { padding: 1px 5px; font-size: 0.66rem; }
  .howto-card .art-arrow { font-size: 1.1rem; }
  .howto-card .art-safe { width: 34px; height: 34px; font-size: 1.1rem; }
  .howto-card .art-plus, .howto-card .art-timer { font-size: 1.1rem; }
}

/* Phones, either way up: as much as possible on one screen, so less padding, a slim code card, the
   players as chips and the pickers in a tight panel. */
@media (max-width: 640px), (orientation: landscape) and (max-height: 520px) {
  .screen { padding-top: calc(var(--safe-t) + 8px); padding-bottom: calc(var(--safe-b) + 10px); }
  .topbar { min-height: 42px; margin-bottom: 6px; }
  /* The animal stages: each canvas fills its wrapper and reaches a sixth higher, as elsewhere. In a
     small wrapper it keeps a floor height with the animals centred, so what comes below crops the
     grass rather than the animals shrinking; in a tiny one it steps aside (@container below). The
     lobby's takes the height the rest leaves it, up to a ceiling, so on a short screen it gives way
     first and never pushes a control below the fold (the menu's does so upright only). */
  .hero-stage-wrap, .lobby-stage-wrap { position: relative; }
  .hero-stage-wrap { container: hero-stage / size; }
  .lobby-stage-wrap { flex: 1 1 0; min-height: 0; max-height: 190px; margin-top: -8px; container: lobby-stage / size; }   /* the canvas reaches up anyway */
  .hero-stage, .lobby-stage { position: absolute; left: 0; right: 0; bottom: min(0px, (116% - 120px) / 2); height: max(116%, 120px); margin: 0; }

  .lobby-main { gap: 8px; }
  .code-card { gap: 8px; padding: 10px 10px 12px; justify-content: center; text-align: center; border-radius: 24px; }
  .code-card-text { display: flex; flex-direction: column; align-items: center; }
  .code-card-label { margin-bottom: 5px; font-size: 0.85rem; line-height: 1.2; }
  .code-tiles { gap: 5px; }
  .code-tile { width: 38px; height: 44px; font-size: 1.5rem; border-radius: 11px; box-shadow: 0 4px 0 var(--pc-d, var(--cloud-d)), inset 0 -3px 0 var(--pc-l, #eef5fc); }
  .code-actions { justify-content: center; }
  .lobby-side { padding: 12px 12px 10px; border-radius: 24px; }
  .side-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }   /* read out, not shown: the labels say it */
  .lobby-side .field { margin-bottom: 10px; }
  .lobby-side .field-label { margin-bottom: 6px; font-size: 0.92rem; }
  .field-colors { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .field-colors .field-label { margin: 0; }
  .swatches { gap: 10px; }
  .swatch { width: 40px; height: 40px; }
  .swatch[aria-checked="true"]::after { font-size: 1.25rem; }
  .swatch .avatar.taken-by { left: 3px; top: 3px; --size: 34px; }
  .animal-grid-sm .animal-tile { padding: 4px 2px; }
  .animal-grid-sm .animal-tile .avatar { --size: 38px; }
  .animal-grid-sm .tile-name { display: none; }          /* the portraits say it (and each tile's aria-label) */
  .emote-bar { gap: 4px; padding-top: 10px; }
  .emote-btn { height: 38px; aspect-ratio: auto; font-size: 1.25rem; border-radius: 10px; }
  .screen-lobby .lobby-start .btn-xl { min-height: 48px; font-size: 1.15rem; border-radius: 16px; }
  .lobby-start .hint { text-wrap: balance; }
  .lobby-start:not(.needs-players) .hint { display: none; }   /* kept while it explains a greyed-out button */
  .screen-lobby .lobby-start .wait-host { padding: 8px; font-size: 0.98rem; }
  .screen-lobby > .lobby-start { margin-top: 10px; padding: 8px; border-radius: 22px; }

  .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .slot { flex-direction: row; gap: 8px; min-height: 0; padding: 7px 8px 7px 7px; text-align: left; border-radius: 18px; }
  .slot::before { inset: 0 auto 0 0; width: 54px; height: auto; border-radius: 15px 27px 27px 15px; }
  .slot .avatar { --size: 40px; }
  .slot .online-dot { right: -1px; bottom: -1px; width: 12px; height: 12px; box-shadow: 0 0 0 2px #fff; }
  .slot-text { align-items: flex-start; gap: 3px; }
  .slot-name { font-size: 0.98rem; line-height: 1.2; }
  .slot-meta { flex-wrap: nowrap; justify-content: flex-start; gap: 4px; }
  .slot-meta > * { padding: 1px 7px; font-size: 0.75rem; }
  .slot-meta > .badge-soft:not(:only-child) { display: none; }   /* "You" and "Host" need the room; the portrait shows the animal */
  .slot-crown { top: -13px; left: 27px; font-size: 1.15rem; }
  .slot-kick { top: -9px; right: -9px; width: 30px; height: 30px; border-radius: 50%; font-size: 0.85rem; }
  .slot-empty { justify-content: flex-start; }
  .slot-empty .slot-plus { width: 40px; height: 40px; font-size: 1.2rem; }
}
@container hero-stage (max-height: 40px) {
  .hero-stage { display: none; }
}
@container lobby-stage (max-height: 100px) {
  .lobby-count { display: none; }     /* it would cover the animals; the player chips say it too */
}
@container lobby-stage (max-height: 40px) {
  .lobby-stage { display: none; }
}

/* Phones held upright: one centred column. On the menu the settings gear floats in the corner
   instead of taking a row of its own, and .menu-hero steps aside so the stage can flex; in the
   lobby the code, stage and players take the height the panel below leaves them. */
@media (max-width: 640px) and (orientation: portrait) {
  .screen-menu .topbar { position: absolute; top: calc(var(--safe-t) + 8px); right: calc(var(--safe-r) + 14px); z-index: 3; display: block; width: auto; min-height: 0; margin: 0; }
  .menu-layout { display: flex; flex-direction: column; align-items: stretch; justify-content: center; }
  .menu-hero { display: contents; }
  .logo { margin-top: 14px; font-size: clamp(46px, min(6.6vh, 13vw), 62px); }   /* the margin leaves the letters room to hop */
  .tagline { display: none; }
  .hero-stage-wrap { flex: 1 1 0; min-height: 0; max-height: min(240px, 45vw); margin-top: -8px; }   /* past ~45vw it would only add sky */
  .lobby-layout { display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
  .lobby-main { flex: 1 1 auto; justify-content: center; }
}
/* Tall phones have room for the tagline too. */
@media (max-width: 640px) and (orientation: portrait) and (min-height: 800px) {
  .tagline { display: block; }
}

/* Player chips: four players on a narrow phone leave each chip ~80px, too little for a name
   (it read "W." or "L…"), so they show avatars only, as every chip does at ≤380px. */
@media (max-width: 440px) {
  .roll-reveal { --rr: 60px; margin-bottom: 8px; }
  .chips[data-count="4"] .chip-body { display: none; }
  .chips[data-count="4"] .chip { flex: 0 0 auto; padding: 4px; }
}
@media (max-width: 380px) {
  .chip-body { display: none; }
  .chip { flex: 0 0 auto; padding: 4px; }
  .code-boxes { gap: 4px; }
}
/* Tablets: the "2/4" repeats the home dots, and a floor width (avatar, gap, padding, border and
   four dots) keeps a short name's chip from being squeezed by long ones until its dots spill. */
@media (max-width: 900px) {
  .chip-count { display: none; }
}
@media (min-width: 641px) and (min-height: 521px) {
  .chip { min-width: min(131px, calc((100vw - 174px) / 4)); }
}

/* Phones held sideways: chips down the left, dock on the right, board in the gap between. */
@media (orientation: landscape) and (max-height: 520px) {
  .roll-reveal { --rr: 56px; left: auto; right: 100%; bottom: 8px; margin: 0 12px 0 0; }
  .board-canvas { right: 48px; -webkit-mask-image: linear-gradient(to right, #000 90%, transparent); mask-image: linear-gradient(to right, #000 90%, transparent); }
  .hud-top { top: calc(var(--safe-t) + 8px); bottom: calc(var(--safe-b) + 8px); left: calc(var(--safe-l) + 8px); right: auto; width: 150px; justify-content: flex-start; flex-direction: column; }
  .chips { flex-direction: column; max-width: 100%; gap: 6px; }
  .chip { padding: 4px 10px 4px 4px; }
  .chip .avatar { --size: 36px; }
  .chip-ring { width: 46px; height: 46px; left: -1px; top: -1px; }
  .chip-name { max-width: 88px; font-size: 0.85rem; }
  .chip-count { display: none; }
  .chip .online-dot { left: 28px; }
  .chip.is-turn { transform-origin: left center; }     /* grow away from the screen edge */
  .hud-menu { position: fixed; right: calc(var(--safe-r) + 8px); top: calc(var(--safe-t) + 8px); left: auto; }
  /* The dock stacks up from the bottom but never higher than just under the settings gear. */
  .dock { left: auto; right: calc(var(--safe-r) + 8px); top: calc(var(--safe-t) + 58px); bottom: calc(var(--safe-b) + 8px); transform: none; width: 190px; gap: 6px; justify-content: flex-end; justify-content: safe flex-end; }
  .dock-status { font-size: 0.85rem; padding: 4px 12px; }
  .dock.is-choosing .dock-status { display: none; }    /* the choices say it; their room is short here */
  .dock-tray { flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 8px; border-radius: 22px; }
  .dock-main { order: 3; flex-basis: 100%; min-height: 54px; }
  .last-die, .last-die svg { width: 46px; height: 46px; }
  .last-die:empty::before { width: 40px; height: 40px; font-size: 1.2rem; }
  .icon-btn-soft { width: 46px; height: 46px; }
  .roll-btn { height: 54px; font-size: 1.35rem; }
  .wait-pill { font-size: 0.9rem; padding-right: 12px; }
  .wait-pill .avatar { --size: 34px; }
  .wait-pill .wait-icon { width: 34px; height: 34px; font-size: 1.2rem; }
  .wait-pill .wait-title { white-space: normal; }
  .wait-pill .wait-sub { white-space: normal; font-size: 0.72rem; }
  .move-options { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .move-opt:last-child:nth-child(odd) { grid-column: auto; width: 100%; }
  .move-opt { min-height: 42px; padding: 3px 8px 3px 6px; gap: 6px; }
  .move-opt-title { font-size: 0.9rem; }
  .move-opt-sub { display: block; white-space: nowrap; text-overflow: ellipsis; font-size: 0.7rem; }
  /* The emote picker opens to the left of the dock: above it there's no room while choosing. */
  .emote-pop { right: calc(100% + 14px); bottom: auto; top: -6px; transform-origin: 100% 20%; }
  .revenge-btn { left: auto; right: calc(100% + 18px); bottom: 12px; }
  .emote-pop::after { right: -8px; bottom: auto; top: 20px; }
  /* Menu: hero on the left, a compact card on the right (the name beside its label, one row of
     animals without names; the tiles keep their aria-labels) so the main button stays above the fold. */
  .menu-layout { grid-template-columns: minmax(0, 1fr) 360px; max-width: 100%; gap: 12px 20px; align-items: start; }
  .topbar { min-height: 40px; }
  .screen-menu .topbar { margin-bottom: 2px; }
  .screen-menu .icon-btn, .screen-lobby .icon-btn { width: 40px; height: 40px; }
  .logo { font-size: 52px; }
  .tagline { font-size: 0.95rem; margin-top: 8px; }
  .hero-stage-wrap { height: 150px; }
  .menu-card { padding: 10px 12px; border-radius: 22px; }
  .menu-card .field { margin-bottom: 8px; }
  .menu-card .field-label { margin-bottom: 5px; font-size: 0.9rem; }
  .field-name { display: flex; flex-wrap: wrap; align-items: center; column-gap: 10px; }
  .field-name .field-label { margin: 0; }
  .field-name .input-chunky.form-control { flex: 1 1 0; min-width: 0; height: 42px; }
  .field-name .field-error { flex-basis: 100%; }
  .menu-card .animal-grid { grid-template-rows: auto; --cols: 8.4; --gap: 5px; }   /* one row */
  .menu-card .animal-tile { padding: 4px 1px; }
  .menu-card .animal-tile .tile-name { display: none; }
  .menu-card .animal-tile .avatar { --size: 34px; }
  .menu-card .animal-tile[aria-checked="true"]::after { width: 18px; height: 18px; font-size: 0.75rem; top: -6px; right: -4px; }
  .menu-card .btn-xl { min-height: 48px; font-size: 1.2rem; border-radius: 16px; --lift: 5px; }
  .menu-card .divider { margin: 6px 0 4px; font-size: 0.85rem; }
  .menu-card .code-box { height: 42px; }
  .menu-card .btn-join { min-height: 42px; }
  .invite-banner { margin: 0 0 8px; padding: 5px 10px; font-size: 0.86rem; line-height: 1.3; }
  .invite-emoji { font-size: 1.2rem; }
  .rejoin-btn { margin-bottom: 8px; }
  /* Lobby: code, stage and players on the left, your pickers with the start button (not pinned:
     the panel fits) on the right, both columns the full height left under the top bar, so the
     stage gets whatever the left column has spare. */
  .lobby-layout { grid-template-columns: minmax(0, 1fr) 300px; max-width: 100%; gap: 12px; align-items: stretch; align-content: stretch; }
  .code-card-label { display: none; }                   /* the code and its Copy / Share buttons say it */
  .lobby-side { padding: 10px 12px; border-radius: 22px; }
  .lobby-side .field { margin-bottom: 6px; }
  .lobby-side .field-label { margin-bottom: 2px; }
  .swatch { width: 36px; height: 36px; }
  .swatch .avatar.taken-by { --size: 30px; }
  .animal-grid-sm .animal-tile .avatar { --size: 34px; }
  .lobby-side .lobby-start { margin: 8px 0 6px; }
  .emote-bar { padding-top: 8px; }
  .emote-btn { height: 34px; font-size: 1.15rem; }
  body.on-game .toast-stack { top: calc(var(--safe-t) + 8px); width: min(380px, calc(100% - 380px)); }
  /* Results: podium on the left, words and buttons on the right, so it all fits one screen. */
  .results { padding-top: calc(var(--safe-t) + 10px); padding-bottom: calc(var(--safe-b) + 10px); }
  .results-card { width: min(760px, 100%); display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); column-gap: 18px; align-items: center; align-content: center; padding: 14px 18px; }
  .results-card > :not(.podium) { grid-column: 2; }
  .rest-list { width: 100%; }   /* auto margins would shrink-wrap it inside the grid cell */
  .results-trophy { display: none; }
  .results-title { margin: 0 0 2px; font-size: 2rem; }
  .podium { grid-column: 1; grid-row: 1 / span 5; min-height: 150px; margin: 0; }
  .podium-col .avatar { --size: 46px; }
  .podium-col.place-1 .avatar { --size: 56px; }
  .podium-block { padding-top: 8px; font-size: 1.6rem; line-height: 1; }
  .podium-col.place-1 .podium-block { height: 72px; }
  .podium-col.place-2 .podium-block { height: 54px; }
  .podium-col.place-3 .podium-block { height: 44px; }
  .results-actions { margin-top: 12px; }
  /* How to play: nearly the whole screen, and no intro line. */
  #howToModal { --bs-modal-margin: 8px; --bs-modal-width: calc(100vw - 24px - 2 * max(var(--safe-l), var(--safe-r))); }
  #howToModal .modal-header { padding: 10px 16px 0; }
  #howToModal .modal-footer { padding: 6px 16px 10px; }
  #howToModal .howto-intro { display: none; }
}
/* Wider landscape phones fit the six how-to cards three across (at 640px and below the cards are
   laid out art-beside-text, which needs the full width). */
@media (orientation: landscape) and (max-height: 520px) and (min-width: 641px) {
  .howto-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .howto-art { gap: 4px; }            /* the "bonk" art is the widest: keep it inside its box at ~667px */
  .art-emoji { font-size: 2rem; }
}

/* Short screens (landscape phones, laptops): the world picker shares the Create button's line, so
   the card is no taller than without it and Create / Join stay above the fold. Its label is still
   there for screen readers; the picked world's name says the rest. */
@media (orientation: landscape) and (max-height: 520px), (min-width: 641px) and (max-height: 860px) {
  .create-group { display: flex; align-items: stretch; gap: 10px; }
  .menu-card .world-row { flex: 0 0 146px; align-items: stretch; margin: 0; }
  .menu-card .world-row .field-label {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .menu-card .world-row .form-select {
    height: auto; padding-left: 12px; padding-right: 30px; font-size: 1.02rem;
    background-position: right 10px center; background-size: 14px 14px;
  }
  .create-group #createBtn { flex: 1 1 0; min-width: 0; }
}

@media (hover: none) {
  .animal-tile:hover:not(:disabled), .emote-btn:hover:not(:disabled), .move-opt:hover, .swatch:hover:not(:disabled) { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .cloud { display: none; }
}
