/* ==========================================================================
   Tell-A-Giraffe — "Savanna Sketchbook" design system
   Colour tokens are injected at runtime from content/themes/*.json
   (see js/theme.js). The values below are the Savanna defaults so the first
   paint never flashes.
   ========================================================================== */
:root {
  --bg: #f6ead0; --paper: #fffaf0; --ink: #2b2118; --muted: #7a6a58;
  --primary: #d9643a; --accent: #f5b82e; --success: #4f8a3c; --danger: #c8442f;
  --line: color-mix(in srgb, var(--ink) 18%, transparent);
  --soft: color-mix(in srgb, var(--ink) 6%, transparent);
  --on-primary: #1b130d; --on-accent: #1b130d;
  --shadow: 3px 3px 0 var(--ink);
  --shadow-lg: 5px 6px 0 var(--ink);
  --wobble: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wobble-2: 15px 255px 15px 225px / 225px 15px 255px 15px;
  --radius: 18px;
  --font-display: 'Baloo 2', 'Chalkboard SE', 'Comic Sans MS', system-ui, sans-serif;
  --font-hand: 'Patrick Hand', 'Chalkboard SE', 'Comic Sans MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --pattern: none;
  --ease-bounce: cubic-bezier(.34, 1.56, .64, 1);
  --header-h: 56px;
  color-scheme: light;
}
:root[data-scheme='dark'] { color-scheme: dark; --shadow: 3px 3px 0 #000; --shadow-lg: 5px 6px 0 #000; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image: var(--pattern);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  transition: background-color .4s ease, color .4s ease;
}
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.1; margin: 0 0 .4em; letter-spacing: .01em; }
h1 { font-size: clamp(2rem, 7vw, 3.2rem); }
h2 { font-size: clamp(1.5rem, 5vw, 2.1rem); }
h3 { font-size: 1.25rem; }
p { margin: 0 0 .8em; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
.hand { font-family: var(--font-hand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.nowrap { flex-wrap: nowrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 8px; }

/* ---------------------------------------------------------------- layout */
#app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 2px dashed var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 6px; font-family: var(--font-display); font-weight: 800; font-size: 1.25rem; text-decoration: none; color: var(--ink); }
.topbar .brand img { width: 34px; height: 34px; }
.topbar .code-pill { font-family: var(--font-display); font-weight: 800; letter-spacing: .18em; padding: 2px 10px; border: 2px solid var(--ink); border-radius: var(--wobble); background: var(--paper); cursor: pointer; }
main.screen { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 16px 16px 96px; }
main.screen.wide { max-width: 1200px; }
.screen-enter { animation: screenIn .38s var(--ease-bounce) both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: var(--wobble);
  box-shadow: var(--shadow);
  padding: 18px;
  position: relative;
}
.card.alt { border-radius: var(--wobble-2); }
.card.flat { box-shadow: none; }
.card.tape::before {
  content: ''; position: absolute; top: -12px; left: 50%; width: 90px; height: 24px; transform: translateX(-50%) rotate(-3deg);
  background: color-mix(in srgb, var(--accent) 55%, transparent); border-radius: 3px; opacity: .85;
}
.section-title { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; margin: 18px 0 8px; }
.section-title::after { content: ''; flex: 1; border-bottom: 2px dashed var(--line); }

/* ---------------------------------------------------------------- buttons */
.btn {
  --b-bg: var(--paper); --b-fg: var(--ink);
  appearance: none; border: 2.5px solid var(--ink); background: var(--b-bg); color: var(--b-fg);
  font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; line-height: 1;
  padding: 12px 20px; min-height: 48px; border-radius: var(--wobble);
  box-shadow: var(--shadow); cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s ease, box-shadow .12s ease, background-color .2s;
  touch-action: manipulation; text-decoration: none;
}
.btn:hover { transform: translate(-1px, -1px) rotate(-.4deg); box-shadow: 4px 5px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: var(--shadow); }
.btn.primary { --b-bg: var(--primary); --b-fg: var(--on-primary); }
.btn.accent { --b-bg: var(--accent); --b-fg: var(--on-accent); }
.btn.success { --b-bg: var(--success); --b-fg: #fff; }
.btn.danger { --b-bg: var(--danger); --b-fg: #fff; }
.btn.ghost { box-shadow: none; border-style: dashed; background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.big { min-height: 64px; font-size: 1.35rem; padding: 16px 28px; }
.btn.block { width: 100%; }
.btn.icon { width: 44px; min-height: 44px; padding: 0; font-size: 1.2rem; border-radius: 50%; }
.btn.icon.small { width: 36px; min-height: 36px; font-size: 1rem; }
.btn.busy { pointer-events: none; opacity: .75; }
.btn.busy::after { content: ''; width: 16px; height: 16px; border-radius: 50%; border: 3px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { appearance: none; border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; font-size: 1.25rem; cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--soft); }

/* ---------------------------------------------------------------- forms */
.input, select.input, textarea.input {
  width: 100%; border: 2.5px solid var(--ink); background: var(--paper); border-radius: 14px 18px 12px 16px;
  padding: 12px 14px; font-size: 1.1rem; min-height: 50px; outline: none; transition: box-shadow .15s;
}
.input:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 45%, transparent); }
textarea.input { min-height: 110px; resize: vertical; font-family: var(--font-hand); font-size: 1.25rem; line-height: 1.3; }
.input.hand { font-family: var(--font-hand); font-size: 1.4rem; }
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
label.field .help { font-weight: 400; color: var(--muted); font-size: .85rem; }
.code-input { display: flex; gap: 8px; justify-content: center; }
.code-input input {
  width: 58px; height: 70px; text-align: center; font-family: var(--font-display); font-weight: 800; font-size: 2rem; text-transform: uppercase;
  border: 2.5px solid var(--ink); border-radius: var(--wobble); background: var(--paper); box-shadow: var(--shadow); outline: none;
}
.code-input input:focus { background: color-mix(in srgb, var(--accent) 25%, var(--paper)); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.switch input { appearance: none; width: 52px; height: 30px; border-radius: 30px; border: 2.5px solid var(--ink); background: var(--soft); position: relative; flex: none; cursor: pointer; transition: background .2s; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); transition: transform .25s var(--ease-bounce); }
.switch input:checked { background: var(--success); }
.switch input:checked::after { transform: translateX(22px); background: #fff; }
.seg { display: inline-flex; border: 2.5px solid var(--ink); border-radius: 14px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; background: transparent; padding: 8px 12px; cursor: pointer; font-weight: 700; min-height: 40px; }
.seg button + button { border-left: 2px solid var(--line); }
.seg button[aria-pressed='true'] { background: var(--accent); color: var(--on-accent); }
input[type='range'] { width: 100%; accent-color: var(--primary); }

/* ---------------------------------------------------------------- chips & avatars */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); font-weight: 700; font-size: .85rem; white-space: nowrap; }
.chip.soft { border-color: var(--line); }
.chip.on { background: var(--accent); color: var(--on-accent); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 800; background: var(--ink); color: var(--paper); }
.avatar {
  --c: var(--accent); width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem;
  background: var(--c); border: 2.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); position: relative;
}
.avatar.sm { width: 32px; height: 32px; font-size: 1.05rem; border-width: 2px; }
.avatar.lg { width: 72px; height: 72px; font-size: 2.4rem; }
.avatar.xl { width: 110px; height: 110px; font-size: 3.6rem; }
.avatar.offline { filter: grayscale(1); opacity: .5; }
.avatar.speaking { box-shadow: 0 0 0 4px var(--success), 2px 2px 0 var(--ink); }
.avatar .crown { position: absolute; top: -14px; right: -6px; font-size: 1rem; transform: rotate(18deg); }
.avatar .status { position: absolute; bottom: -4px; right: -4px; font-size: .8rem; background: var(--paper); border: 2px solid var(--ink); border-radius: 50%; width: 20px; height: 20px; display: grid; place-items: center; }

.player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.player {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--paper); border: 2px solid var(--ink);
  border-radius: var(--wobble-2); min-height: 58px; position: relative; animation: popIn .4s var(--ease-bounce) both; touch-action: none;
}
.player .pname { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .meta { font-size: .75rem; color: var(--muted); }
.player.me { background: color-mix(in srgb, var(--accent) 22%, var(--paper)); }
.player.selected { outline: 3px dashed var(--primary); outline-offset: 2px; }
.player.dragging { opacity: .35; }
.player .kick { position: absolute; top: -10px; right: -10px; }
@keyframes popIn { from { opacity: 0; transform: scale(.6) rotate(-6deg); } to { opacity: 1; transform: none; } }
.drag-ghost { position: fixed; z-index: 100; pointer-events: none; transform: rotate(-4deg) scale(1.05); box-shadow: var(--shadow-lg); }

.teams { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.team { border: 2.5px dashed var(--tc, var(--ink)); border-radius: var(--wobble); padding: 10px; min-height: 140px; transition: background .2s, transform .2s; background: color-mix(in srgb, var(--tc) 8%, transparent); }
.team.drop-hover { background: color-mix(in srgb, var(--tc) 25%, transparent); transform: scale(1.02); }
.team h4 { display: flex; align-items: center; gap: 8px; color: var(--tc); margin-bottom: 8px; }
.team .stack { gap: 8px; }

/* ---------------------------------------------------------------- home */
.hero { text-align: center; padding: 12px 0 8px; }
.hero .mascot { width: min(220px, 52vw); height: auto; animation: bob 4s ease-in-out infinite; transform-origin: bottom center; }
.hero h1 { margin-top: -6px; }
.hero h1 .tag { display: inline-block; color: var(--primary); transform: rotate(-4deg); }
.hero .sub { font-family: var(--font-hand); font-size: 1.35rem; color: var(--muted); }
@keyframes bob { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg) translateY(-4px); } }
.home-grid { display: grid; gap: 16px; grid-template-columns: 1fr; max-width: 560px; margin: 0 auto; }
@media (min-width: 820px) { .home-grid { grid-template-columns: 1fr 1fr; max-width: 900px; } }
.nearby-list { display: flex; flex-direction: column; gap: 8px; }
.nearby { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 2px solid var(--ink); border-radius: var(--wobble-2); background: var(--paper); cursor: pointer; text-align: left; width: 100%; }
.nearby:hover { background: color-mix(in srgb, var(--accent) 18%, var(--paper)); }
.nearby .code { font-family: var(--font-display); font-weight: 800; letter-spacing: .15em; }

/* ---------------------------------------------------------------- lobby */
.lobby-head { display: grid; gap: 14px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 820px) { .lobby-head { grid-template-columns: 1.4fr 1fr; } }
.game-card { display: flex; gap: 14px; align-items: flex-start; }
.game-card .gemoji { font-size: 3rem; line-height: 1; filter: drop-shadow(2px 2px 0 var(--line)); }
.game-card h3 { margin: 0; }
.howto { margin: 8px 0 0; padding-left: 0; list-style: none; counter-reset: how; }
.howto li { counter-increment: how; display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; font-family: var(--font-hand); font-size: 1.15rem; }
.howto li::before { content: counter(how); font-family: var(--font-display); font-weight: 800; flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); border: 2px solid var(--ink); font-size: .85rem; }
.share-box { display: flex; gap: 12px; align-items: center; }
.share-box img { width: 108px; height: 108px; background: #fff; border: 2.5px solid var(--ink); border-radius: 12px; padding: 4px; flex: none; }
.share-box .bigcode { font-family: var(--font-display); font-weight: 800; font-size: 2.4rem; letter-spacing: .18em; line-height: 1; }
.host-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-top: 2px dashed var(--line); }
.host-bar .inner { max-width: 980px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.host-bar .btn.primary { flex: 1; }

.mode-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.mode-tile {
  appearance: none; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px; padding: 12px; min-height: 132px;
  background: var(--paper); border: 2.5px solid var(--ink); border-radius: var(--wobble-2); box-shadow: var(--shadow);
  transition: transform .15s var(--ease-bounce), box-shadow .15s;
}
.mode-tile:nth-child(3n) { border-radius: var(--wobble); }
.mode-tile:hover { transform: translateY(-3px) rotate(-1deg); box-shadow: var(--shadow-lg); }
.mode-tile.on { background: color-mix(in srgb, var(--accent) 30%, var(--paper)); }
.mode-tile .e { font-size: 2rem; }
.mode-tile .n { font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; line-height: 1.1; }
.mode-tile .t { font-size: .8rem; color: var(--muted); }
.mode-tile .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: auto; }
.mode-tile .tags span { font-size: .65rem; font-weight: 800; padding: 1px 6px; border-radius: 99px; background: var(--soft); }

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.theme-tile { appearance: none; border: 2.5px solid var(--ink); border-radius: var(--wobble-2); padding: 10px; cursor: pointer; text-align: left; box-shadow: var(--shadow); }
.theme-tile .sw { display: flex; gap: 3px; margin: 6px 0; }
.theme-tile .sw i { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid rgba(0,0,0,.4); }
.theme-tile.on { outline: 4px solid var(--primary); outline-offset: 2px; }

.pack-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.pack-row .info { flex: 1; min-width: 0; }
.pack-row .info b { display: block; }

/* ---------------------------------------------------------------- modal */
.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(20, 14, 8, .45); display: grid; place-items: end center; animation: fade .2s ease both; }
@media (min-width: 700px) { .modal-back { place-items: center; } }
.modal {
  width: min(720px, 100%); max-height: min(88vh, 900px); overflow: auto; background: var(--bg); border: 2.5px solid var(--ink);
  border-radius: 24px 24px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--shadow-lg); animation: sheetUp .32s var(--ease-bounce) both;
}
@media (min-width: 700px) { .modal { border-radius: var(--wobble); padding: 22px; } }
.modal .modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; position: sticky; top: -18px; background: var(--bg); padding-top: 4px; z-index: 2; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------------------------------------------------------------- toasts / reactions / confetti */
.toasts { position: fixed; top: calc(var(--header-h) + 8px); left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast { pointer-events: auto; background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 14px; font-weight: 700; box-shadow: var(--shadow); animation: toastIn .35s var(--ease-bounce) both; text-align: center; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
.toast.out { animation: toastOut .25s ease both; }
@keyframes toastIn { from { transform: translateY(-16px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(-10px); opacity: 0; } }
.reaction-layer { position: fixed; inset: 0; pointer-events: none; z-index: 80; overflow: hidden; }
.float-emoji { position: absolute; bottom: -60px; font-size: 2.6rem; animation: floatUp 2.6s ease-out forwards; }
@keyframes floatUp { 0% { transform: translateY(0) scale(.6); opacity: 0; } 15% { opacity: 1; transform: translateY(-15vh) scale(1.1); } 100% { transform: translateY(-95vh) translateX(var(--dx, 0)) rotate(var(--rot, 20deg)); opacity: 0; } }
.confetti-piece { position: absolute; top: -40px; font-size: 1.8rem; animation: fall var(--dur, 2.8s) linear forwards; }
@keyframes fall { to { transform: translateY(110vh) translateX(var(--dx, 0)) rotate(var(--rot, 360deg)); } }
.react-bar { display: flex; gap: 4px; justify-content: center; }
.react-bar button { appearance: none; border: 0; background: transparent; font-size: 1.6rem; cursor: pointer; padding: 4px; border-radius: 12px; transition: transform .15s var(--ease-bounce); }
.react-bar button:active { transform: scale(1.4); }

/* ---------------------------------------------------------------- task screens */
.task-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.task-head .instruction { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.15rem, 4.2vw, 1.6rem); line-height: 1.15; flex: 1; }
.link-count { font-size: .8rem; color: var(--muted); font-weight: 700; }
.prompt-card {
  font-family: var(--font-hand); font-size: clamp(1.6rem, 6vw, 2.4rem); line-height: 1.15; text-align: center; padding: 22px 16px;
  background: var(--paper); border: 2.5px solid var(--ink); border-radius: var(--wobble); box-shadow: var(--shadow); position: relative;
  animation: dealIn .55s var(--ease-bounce) both; word-break: break-word;
}
.prompt-card .label { position: absolute; top: -12px; left: 16px; background: var(--accent); color: var(--on-accent); font-family: var(--font-display); font-weight: 800; font-size: .8rem; padding: 2px 10px; border: 2px solid var(--ink); border-radius: 99px; }
@keyframes dealIn { from { transform: translateY(-30px) rotate(-8deg) scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
.spy-banner { background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 12px; font-weight: 800; text-align: center; margin-bottom: 10px; animation: popIn .4s var(--ease-bounce) both; }
.taboo-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.taboo-list .chip { background: color-mix(in srgb, var(--danger) 18%, var(--paper)); text-decoration: line-through; }
.word-limit { font-weight: 800; color: var(--primary); }

/* Timer ring */
.timer { --p: 1; position: relative; width: 54px; height: 54px; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 6; }
.timer .track { stroke: var(--line); }
.timer .bar { stroke: var(--success); stroke-linecap: round; stroke-dasharray: 151; stroke-dashoffset: calc(151 * (1 - var(--p))); transition: stroke-dashoffset .25s linear, stroke .3s; }
.timer.warn .bar { stroke: var(--accent); }
.timer.danger .bar { stroke: var(--danger); }
.timer.danger { animation: shake .4s ease-in-out infinite; }
.timer span { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; }
.timer.fuse span { font-size: 1.6rem; }
@keyframes shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }

/* Drawing pad */
.pad-wrap { display: flex; flex-direction: column; gap: 10px; }
.canvas-frame {
  position: relative; width: 100%; aspect-ratio: 4 / 3; background: #fff; border: 2.5px solid var(--ink); border-radius: 14px 18px 12px 16px;
  box-shadow: var(--shadow); overflow: hidden; touch-action: none; user-select: none;
}
:root[data-scheme='dark'] .canvas-frame { background: #fdf8ee; }
.canvas-frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.canvas-frame .overlay-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px; font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; background: rgba(255, 250, 240, .92); color: var(--on-accent); z-index: 3; }
.canvas-frame .strip-guide { position: absolute; left: 0; right: 0; top: 0; border-bottom: 2px dashed var(--primary); pointer-events: none; z-index: 2; background: repeating-linear-gradient(45deg, rgba(217,100,58,.06) 0 8px, transparent 8px 16px); }
.canvas-frame .peek-bar { position: absolute; left: 0; bottom: 0; height: 6px; background: var(--primary); z-index: 4; transition: width linear; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2.5px solid var(--ink); cursor: pointer; padding: 0; transition: transform .15s var(--ease-bounce); }
.swatch[aria-pressed='true'] { transform: scale(1.18); box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.tools { display: flex; gap: 6px; align-items: center; }
.tool { appearance: none; min-width: 42px; height: 42px; border: 2.5px solid var(--ink); border-radius: 12px; background: var(--paper); cursor: pointer; font-size: 1.1rem; display: grid; place-items: center; padding: 0 8px; }
.tool[aria-pressed='true'] { background: var(--accent); color: var(--on-accent); }
.tool .dot { border-radius: 50%; background: currentColor; display: block; }
.stamp-tray { display: flex; gap: 4px; flex-wrap: wrap; padding: 6px; border: 2px dashed var(--line); border-radius: 12px; }
.stamp-tray button { font-size: 1.5rem; background: none; border: 0; cursor: pointer; border-radius: 8px; padding: 2px 4px; }
.stamp-tray button[aria-pressed='true'] { background: var(--accent); }
.view-frame { position: relative; width: 100%; aspect-ratio: 4 / 3; background: #fff; border: 2.5px solid var(--ink); border-radius: 14px 18px 12px 16px; overflow: hidden; box-shadow: var(--shadow); }
:root[data-scheme='dark'] .view-frame { background: #fdf8ee; }
.view-frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.task-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .task-grid.two { grid-template-columns: 1fr 1fr; align-items: start; } }
.options { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .options { grid-template-columns: 1fr 1fr; } }
.option { appearance: none; text-align: center; font-family: var(--font-hand); font-size: 1.35rem; padding: 14px; border: 2.5px solid var(--ink); border-radius: var(--wobble-2); background: var(--paper); cursor: pointer; box-shadow: var(--shadow); transition: transform .15s var(--ease-bounce); min-height: 64px; }
.option:hover { transform: translateY(-2px) rotate(.5deg); }
.option[aria-pressed='true'] { background: var(--accent); color: var(--on-accent); }
.emoji-kb { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 4px; max-height: 220px; overflow: auto; padding: 6px; border: 2px dashed var(--line); border-radius: 12px; }
.emoji-kb button { font-size: 1.6rem; background: none; border: 0; cursor: pointer; border-radius: 8px; height: 44px; }
.emoji-kb button:hover { background: var(--soft); }
.emoji-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.emoji-tabs button { font-size: 1.3rem; border: 2px solid transparent; background: none; border-radius: 10px; cursor: pointer; padding: 2px 6px; }
.emoji-tabs button[aria-pressed='true'] { border-color: var(--ink); background: var(--paper); }

/* Waiting / progress */
.waiting { text-align: center; padding: 20px 0; }
.waiting .big-emoji { font-size: 4rem; display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.necks { display: flex; gap: 14px; justify-content: center; align-items: flex-end; flex-wrap: wrap; padding: 16px 0; min-height: 160px; }
.neck { display: flex; flex-direction: column-reverse; align-items: center; gap: 3px; }
.neck .nseg { width: 30px; height: 16px; border: 2px solid var(--ink); border-radius: 6px; background: var(--paper); transition: background .4s, transform .4s var(--ease-bounce); }
.neck .nseg.filled { background: var(--accent); background-image: radial-gradient(circle at 30% 40%, #a8642f 0 22%, transparent 23%), radial-gradient(circle at 75% 70%, #a8642f 0 18%, transparent 19%); animation: grow .5s var(--ease-bounce) both; }
.neck .nseg.current { background: color-mix(in srgb, var(--primary) 30%, var(--paper)); animation: pulse 1.2s ease-in-out infinite; }
.neck .head { font-size: 1.6rem; margin-bottom: -2px; }
.neck.done .head { animation: bob 1.6s ease-in-out infinite; }
@keyframes grow { from { transform: scaleY(0); } to { transform: none; } }
@keyframes pulse { 50% { transform: scale(1.12); } }
.status-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.status-list .chip.done { background: color-mix(in srgb, var(--success) 22%, var(--paper)); }
.status-list .chip.working { animation: pulse 1.6s ease-in-out infinite; }

/* ---------------------------------------------------------------- reveal / gallery */
.reveal-stage { display: flex; flex-direction: column; gap: 14px; }
.chain-strip { display: flex; flex-direction: column; gap: 16px; }
.entry {
  display: flex; flex-direction: column; gap: 8px; animation: flipIn .6s var(--ease-bounce) both; transform-origin: top center;
}
.entry .by { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.entry .by .what { font-weight: 400; color: var(--muted); font-size: .9rem; }
.entry .bubble { font-family: var(--font-hand); font-size: clamp(1.4rem, 5vw, 2rem); line-height: 1.2; padding: 14px 18px; background: var(--paper); border: 2.5px solid var(--ink); border-radius: var(--wobble); box-shadow: var(--shadow); word-break: break-word; position: relative; }
.entry .bubble.seed { background: color-mix(in srgb, var(--accent) 35%, var(--paper)); }
.entry .secret { font-size: .9rem; color: var(--muted); font-style: italic; }
.entry .verdict { position: absolute; top: -14px; right: -8px; font-size: 1.6rem; animation: stampIn .5s var(--ease-bounce) .4s both; }
.entry .star { position: absolute; bottom: -14px; right: 10px; }
.entry.votable { cursor: pointer; }
.entry.voted .bubble, .entry.voted .view-frame { outline: 4px solid var(--accent); outline-offset: 3px; }
.entry .auto { font-size: .75rem; }
@keyframes flipIn { from { transform: perspective(800px) rotateX(-70deg) translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes stampIn { from { transform: scale(3) rotate(-30deg); opacity: 0; } to { transform: rotate(-12deg); opacity: 1; } }
.arrow-down { text-align: center; font-size: 1.4rem; color: var(--muted); margin: -8px 0; }
.critter { display: flex; flex-direction: column; background: #fff; border: 2.5px solid var(--ink); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.critter canvas { width: 100%; display: block; }
.reveal-controls { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.chain-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 8px; }
.chain-tabs button { flex: none; }
.survived { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; text-align: center; padding: 10px; border: 2.5px dashed var(--ink); border-radius: var(--wobble); }
.survived.yes { background: color-mix(in srgb, var(--success) 20%, var(--paper)); }
.survived.no { background: color-mix(in srgb, var(--danger) 14%, var(--paper)); }

/* ---------------------------------------------------------------- results */
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 20px 0; }
.podium .place { display: flex; flex-direction: column; align-items: center; gap: 6px; animation: rise .8s var(--ease-bounce) both; }
.podium .block { width: 92px; border: 2.5px solid var(--ink); border-radius: 12px 12px 0 0; background: var(--accent); display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 1.8rem; box-shadow: var(--shadow); }
.podium .p1 .block { height: 130px; background: var(--accent); }
.podium .p2 .block { height: 95px; background: color-mix(in srgb, var(--muted) 45%, var(--paper)); }
.podium .p3 .block { height: 70px; background: color-mix(in srgb, var(--primary) 50%, var(--paper)); }
.podium .p1 { animation-delay: .5s; } .podium .p2 { animation-delay: .25s; }
@keyframes rise { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
.score-table { display: flex; flex-direction: column; gap: 8px; }
.score-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--paper); border: 2px solid var(--ink); border-radius: var(--wobble-2); animation: popIn .4s var(--ease-bounce) both; }
.score-row .rank { font-family: var(--font-display); font-weight: 800; width: 28px; text-align: center; }
.score-row .pts { font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; margin-left: auto; }
.score-row .delta { color: var(--success); font-weight: 800; font-size: .9rem; }
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.events li { display: flex; gap: 8px; align-items: center; font-family: var(--font-hand); font-size: 1.15rem; }
.events li b { font-family: var(--font-display); color: var(--success); }

/* ---------------------------------------------------------------- voice */
.voice-dock { display: flex; align-items: center; gap: 4px; }
.voice-dock .btn.icon.on { background: var(--success); color: #fff; }
.voice-dock .btn.icon.muted { background: var(--danger); color: #fff; }
.level { width: 6px; height: 24px; border-radius: 3px; background: var(--line); overflow: hidden; display: flex; align-items: flex-end; }
.level i { display: block; width: 100%; background: var(--success); height: 0; transition: height .08s; }

/* ---------------------------------------------------------------- misc */
.skeleton { background: linear-gradient(90deg, var(--soft), color-mix(in srgb, var(--ink) 12%, transparent), var(--soft)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.loading { display: grid; place-items: center; min-height: 50vh; text-align: center; gap: 12px; }
.loading .big-emoji { font-size: 3.5rem; animation: bob 1.4s ease-in-out infinite; }
.kbd { font-family: ui-monospace, monospace; font-size: .8rem; padding: 1px 6px; border: 1.5px solid var(--line); border-bottom-width: 3px; border-radius: 6px; }
.empty { text-align: center; color: var(--muted); padding: 18px; font-family: var(--font-hand); font-size: 1.2rem; }
hr.dash { border: 0; border-top: 2px dashed var(--line); margin: 16px 0; }
.decor { position: fixed; z-index: 0; font-size: 3rem; opacity: .16; pointer-events: none; user-select: none; }
.decor.d1 { top: 70px; right: 4vw; transform: rotate(14deg); } .decor.d2 { bottom: 90px; left: 3vw; transform: rotate(-10deg); } .decor.d3 { top: 45%; right: 1vw; transform: rotate(-20deg); font-size: 2.2rem; }
main.screen, .topbar { position: relative; z-index: 1; }
.after-dark-glow { position: fixed; inset: 0; pointer-events: none; z-index: 0; background: radial-gradient(circle at 80% 10%, rgba(255, 199, 95, .18), transparent 30%), radial-gradient(circle at 15% 85%, rgba(255, 111, 145, .14), transparent 35%); }
.firefly { position: fixed; width: 6px; height: 6px; border-radius: 50%; background: #ffe58a; box-shadow: 0 0 12px 4px rgba(255, 229, 138, .6); pointer-events: none; z-index: 0; animation: firefly var(--d, 9s) ease-in-out infinite; }
@keyframes firefly { 0%, 100% { transform: translate(0, 0); opacity: .2; } 25% { opacity: 1; } 50% { transform: translate(var(--x, 40px), var(--y, -60px)); opacity: .4; } 75% { opacity: .9; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
:root.reduce-motion *, :root.reduce-motion *::before, :root.reduce-motion *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }

.modal .card { scroll-margin-top: 80px; }
