/* Sketch: dark, glassy, one loud accent. The only bright surface is the drawing itself. */

@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('/fonts/bricolage-grotesque.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/geist.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/geist-mono.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #08080d;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.08);
  --surface-3: rgba(255, 255, 255, 0.13);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f4f4f8;
  --muted: #a1a1b3;
  --faint: #6c6c7e;
  --lime: #b9ff3b;
  --lime-soft: rgba(185, 255, 59, 0.14);
  --violet: #8b6cff;
  --pink: #ff5fa2;
  --cyan: #4fd8ff;
  --amber: #ffc24b;
  --red: #ff5c6c;
  --on-accent: #0b0d05;
  --radius: 24px;
  --radius-s: 14px;
  --display: 'Bricolage Grotesque', 'Geist', system-ui, sans-serif;
  --body: 'Geist', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --app-h: 100dvh;
  --pad: clamp(12px, 2vw, 20px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body:has(#game:not([hidden])) { overflow: hidden; }
h1, h2, p, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 3px; }
::selection { background: var(--lime); color: var(--on-accent); }

.sprite { position: absolute; width: 0; height: 0; }
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---- backdrop -------------------------------------------------------------- */

.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: var(--bg); }
.backdrop i { position: absolute; border-radius: 50%; will-change: transform; }
.backdrop i:nth-child(1) {
  width: 90vmax; height: 90vmax; left: -35vmax; top: -45vmax;
  background: radial-gradient(closest-side, rgba(139, 108, 255, 0.34), transparent);
  animation: drift-a 26s ease-in-out infinite alternate;
}
.backdrop i:nth-child(2) {
  width: 80vmax; height: 80vmax; right: -35vmax; bottom: -45vmax;
  background: radial-gradient(closest-side, rgba(255, 95, 162, 0.22), transparent);
  animation: drift-b 32s ease-in-out infinite alternate;
}
.backdrop i:nth-child(3) {
  width: 60vmax; height: 60vmax; right: -10vmax; top: -30vmax;
  background: radial-gradient(closest-side, rgba(79, 216, 255, 0.16), transparent);
  animation: drift-a 38s ease-in-out infinite alternate-reverse;
}
/* A faint dot grid that fades towards the edges. */
.backdrop::after {
  content: '';
  position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.09) 1px, transparent 1px);
  background-size: 28px 28px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 30%, #000 10%, transparent 75%);
  mask-image: radial-gradient(ellipse at 50% 30%, #000 10%, transparent 75%);
}
@keyframes drift-a { to { transform: translate3d(12vmax, 8vmax, 0) scale(1.15); } }
@keyframes drift-b { to { transform: translate3d(-10vmax, -8vmax, 0) scale(1.1); } }

/* ---- shared pieces --------------------------------------------------------- */

.view { animation: view-in 0.5s var(--ease) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } }

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 30px 60px -30px rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  backdrop-filter: blur(24px) saturate(140%);
}

.wordmark {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: -0.055em;
  line-height: 0.9;
}
.wordmark.small { font-size: 26px; letter-spacing: -0.05em; }
.wordmark.small::after { content: '.'; color: var(--lime); }

.eyebrow {
  font: 600 12px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex; align-items: center; gap: 10px;
}
.eyebrow .count { color: var(--faint); letter-spacing: 0.04em; }
.note { color: var(--faint); font-size: 13.5px; }
.center { text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 52px; padding: 0 22px;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-weight: 600; letter-spacing: -0.01em; white-space: nowrap;
  transition: transform 0.2s var(--ease), background 0.2s, box-shadow 0.25s, border-color 0.2s, opacity 0.2s;
}
.btn:hover { background: var(--surface-3); border-color: var(--line-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn.primary {
  background: var(--lime); color: var(--on-accent); border-color: transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 10px 30px -12px rgba(185, 255, 59, 0.7);
}
.btn.primary:hover { background: #c8ff63; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 14px 40px -10px rgba(185, 255, 59, 0.8); }
.btn.big { height: 60px; font-size: 18px; border-radius: 18px; }
.btn.icon-only { width: 52px; padding: 0; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-text { color: var(--muted); font-size: 14.5px; padding: 8px 6px; border-radius: 8px; transition: color 0.2s; }
.btn-text:hover { color: var(--text); }

.icon-btn {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: grid; place-items: center;
  color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  transition: color 0.2s, background 0.2s, transform 0.2s var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); transform: translateY(-1px); }

input {
  height: 52px; width: 100%; min-width: 0; padding: 0 16px;
  border-radius: var(--radius-s);
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--line);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
input::placeholder { color: var(--faint); }
input:focus-visible { outline: none; }
input:focus { border-color: var(--lime); box-shadow: 0 0 0 4px var(--lime-soft); background: rgba(0, 0, 0, 0.45); }
input.shake { animation: shake 0.35s; border-color: var(--red); }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

.avatar { display: block; width: 100%; height: 100%; }

.pill {
  font: 500 12.5px/1 var(--mono); letter-spacing: 0.02em;
  padding: 8px 12px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}

/* ---- home ------------------------------------------------------------------ */

.view-home {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(28px, 5vh, 48px);
  padding: clamp(32px, 6vh, 72px) var(--pad);
}
.hero { text-align: center; }
.hero .wordmark {
  position: relative; display: inline-block;
  font-size: clamp(84px, 19vw, 176px);
  background: linear-gradient(180deg, #fff 30%, #b9b9d6);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  padding: 0 0.04em 0.12em;
}
.hero .wordmark svg {
  position: absolute; left: 2%; bottom: -0.03em; width: 96%; height: auto; overflow: visible;
}
.hero .wordmark path {
  fill: none; stroke: var(--lime); stroke-width: 5; stroke-linecap: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: scribble 1.1s 0.35s var(--ease) forwards;
  filter: drop-shadow(0 0 14px rgba(185, 255, 59, 0.45));
}
@keyframes scribble { to { stroke-dashoffset: 0; } }
.tagline { margin-top: 22px; color: var(--muted); font-size: clamp(16px, 2.2vw, 19px); line-height: 1.55; }

.join-card { width: min(100%, 460px); padding: 22px; display: grid; gap: 18px; }
.invite {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius-s);
  background: var(--lime-soft); color: var(--lime); font-weight: 550; font-size: 15px;
  border: 1px solid rgba(185, 255, 59, 0.25);
}
.invite-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); flex: none; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(185, 255, 59, 0.6); } 100% { box-shadow: 0 0 0 10px rgba(185, 255, 59, 0); } }

.identity { display: flex; align-items: flex-end; gap: 16px; }
.avatar-picker {
  position: relative; width: 84px; height: 84px; flex: none;
  transition: transform 0.3s var(--spring);
}
.avatar-picker:hover { transform: rotate(-4deg) scale(1.05); }
.avatar-picker:active { transform: scale(0.94); }
.avatar-picker.spin #avatar-preview { animation: spin-in 0.4s var(--spring); }
#avatar-preview { display: block; width: 100%; height: 100%; }
@keyframes spin-in { from { transform: rotate(-120deg) scale(0.6); opacity: 0.4; } }
.avatar-badge {
  position: absolute; right: -6px; bottom: -6px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: #1b1b26; border: 1px solid var(--line-strong); color: var(--text);
}
.avatar-badge .icon { width: 14px; height: 14px; }
.field { flex: 1; display: grid; gap: 8px; min-width: 0; }
.field span { font: 600 12px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions > .btn { flex: 1; }
.code-entry .btn { flex: 0 0 auto; }
.code-input { flex: 1; font-family: var(--mono); font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; }
.code-input::placeholder { letter-spacing: 0.12em; font-weight: 400; }
#invite-actions { flex-direction: column; align-items: stretch; gap: 4px; }
#invite-actions > .btn { flex: none; }

.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(100%, 760px); }
.how li {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 16px; border-radius: 18px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.025);
}
.how b {
  width: 28px; height: 28px; border-radius: 9px; flex: none; display: grid; place-items: center;
  font: 600 13px var(--mono); color: var(--lime); background: var(--lime-soft);
}
.how span { color: var(--faint); font-size: 13.5px; line-height: 1.45; }
.how strong { display: block; color: var(--text); font-weight: 600; font-size: 15px; margin-bottom: 2px; }

/* ---- lobby ----------------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px var(--pad); max-width: 1080px; margin: 0 auto;
}
.topbar-actions { display: flex; gap: 8px; }

.view-lobby { min-height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) 40px env(safe-area-inset-left); }
.lobby-grid {
  max-width: 1080px; margin: 0 auto; padding: clamp(8px, 3vh, 32px) var(--pad) 0;
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  grid-template-areas: 'invite settings' 'players settings';
  align-items: start;
}
.lobby-grid > .card { padding: clamp(18px, 2.4vw, 28px); display: grid; gap: 18px; }
.invite-card { grid-area: invite; }
.settings-card { grid-area: settings; }
.players-card { grid-area: players; }

.room-code {
  font: 800 clamp(56px, 9vw, 96px)/0.95 var(--display);
  letter-spacing: 0.02em;
  background: linear-gradient(100deg, var(--lime), #6dffc2 55%, var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  user-select: all;
}
.share { display: flex; gap: 10px; }
.share input { font: 400 14px var(--mono); color: var(--muted); text-overflow: ellipsis; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.tile {
  position: relative; display: grid; justify-items: center; gap: 10px;
  padding: 18px 10px 14px; border-radius: 18px; text-align: center;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
  animation: pop-in 0.45s var(--spring) both;
}
.tile .avatar-box { width: 64px; height: 64px; }
.tile .name { font-weight: 600; font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .tag { font: 500 11px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); min-height: 11px; }
.tile.me { border-color: rgba(185, 255, 59, 0.35); background: rgba(185, 255, 59, 0.05); }
.tile.away { opacity: 0.45; }
.tile .crown {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(255, 194, 75, 0.16); color: var(--amber);
}
.tile .crown .icon { width: 14px; height: 14px; }
.tile.empty {
  border-style: dashed; background: none; color: var(--faint); align-content: center;
  font-size: 13px; min-height: 142px; animation: none;
}
@keyframes pop-in { from { opacity: 0; transform: scale(0.8); } }

.setting { display: grid; gap: 10px; }
.setting > span { font-weight: 550; font-size: 15px; }
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; border-radius: 16px; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line);
}
.segmented button {
  height: 42px; border-radius: 12px; font: 500 14px var(--mono); color: var(--muted);
  transition: background 0.2s, color 0.2s, transform 0.2s var(--ease);
}
.segmented button:hover:not(:disabled) { color: var(--text); }
.segmented button[aria-checked='true'] {
  background: var(--surface-3); color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
}
.segmented button:disabled { cursor: default; }
.segmented.readonly button:not([aria-checked='true']) { opacity: 0.4; }
.settings-card .btn.big { margin-top: 6px; }

/* ---- game ------------------------------------------------------------------ */

.view-game {
  height: var(--app-h);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) max(var(--pad), env(safe-area-inset-right)) max(var(--pad), env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left));
  overflow: hidden;
  /* Height of the drawing tools plus the gap above them; set by the client while you draw. */
  --toolbar-h: 0px;
}

.gamebar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 12px 0; flex: none;
}
.gamebar-side { display: flex; align-items: center; gap: 12px; min-width: 0; }
.gamebar-side.end { justify-content: flex-end; gap: 8px; }

.word { display: grid; justify-items: center; gap: 7px; min-width: 0; text-align: center; }
.word-label { font: 600 11px/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.word-text {
  font: 700 clamp(20px, 2.6vw, 30px)/1 var(--display); letter-spacing: -0.02em;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.word-text.known { color: var(--lime); text-transform: lowercase; }
.slots { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 5px; font: 600 clamp(18px, 2.4vw, 26px)/1 var(--mono); }
.slot {
  width: 0.95em; height: 1.25em; display: grid; place-items: center;
  border-bottom: 3px solid rgba(255, 255, 255, 0.45); border-radius: 1px; text-transform: lowercase;
}
.slot.shown { border-color: var(--lime); color: var(--lime); }
.slot.fresh { animation: letter-in 0.5s var(--spring); }
.slot.gap { border: 0; width: 0.5em; }
.slot.dash { border: 0; }
.slots sup { font: 500 11px var(--mono); color: var(--faint); align-self: flex-start; margin-left: 4px; }
@keyframes letter-in { from { transform: translateY(-10px) scale(1.5); opacity: 0; } }

.timer { position: relative; width: 46px; height: 46px; flex: none; display: grid; place-items: center; color: var(--lime); }
.timer svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 3.5; }
.timer .track { stroke: var(--line); }
.timer .progress { stroke: currentColor; stroke-linecap: round; stroke-dasharray: 100; transition: stroke-dashoffset 0.25s linear, stroke 0.3s; }
.timer span { font: 600 15px/1 var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
.timer.warn { color: var(--amber); }
.timer.danger { color: var(--red); }
.timer.danger span { color: var(--red); animation: beat 1s infinite; }
.timer.idle { opacity: 0.35; }
@keyframes beat { 0%, 100% { transform: scale(1); } 12% { transform: scale(1.28); } }

.game-grid {
  flex: 1; min-height: 0;
  display: grid; gap: 14px;
  grid-template-columns: 250px minmax(0, 1fr) 320px;
}

.players-panel { padding: 10px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
#game-players { display: grid; gap: 6px; }
.player {
  position: relative; display: grid; grid-template-columns: 18px 38px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 9px 12px 9px 8px; border-radius: 16px; border: 1px solid transparent;
  transition: background 0.3s, border-color 0.3s, opacity 0.3s;
}
.player .rank { font: 500 12px var(--mono); color: var(--faint); text-align: center; }
.player .avatar-box { width: 38px; height: 38px; }
.player .who { min-width: 0; display: grid; gap: 1px; }
.player .name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .score { font: 500 12.5px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .status { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: transparent; }
.player .status .icon { width: 14px; height: 14px; }
.player.me { background: rgba(255, 255, 255, 0.045); border-color: var(--line); }
.player.artist { background: rgba(139, 108, 255, 0.14); border-color: rgba(139, 108, 255, 0.4); }
.player.artist .status { background: var(--violet); color: #fff; }
.player.guessed { background: var(--lime-soft); border-color: rgba(185, 255, 59, 0.32); }
.player.guessed .status { background: var(--lime); color: var(--on-accent); animation: pop-in 0.4s var(--spring); }
.player.away { opacity: 0.4; }
.player .gain {
  position: absolute; right: 44px; top: 50%; pointer-events: none;
  font: 700 14px var(--mono); color: var(--lime);
  animation: gain 1.6s var(--ease) forwards;
}
@keyframes gain { 0% { opacity: 0; transform: translateY(0); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-34px); } }

/* The canvas is as large as fits both the width and the height left over by the toolbar. */
.stage { container-type: size; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.canvas-wrap {
  position: relative; flex: none;
  width: min(100cqw, (100cqh - var(--toolbar-h)) * 4 / 3);
  aspect-ratio: 4 / 3;
  container-type: inline-size;
  border-radius: 22px; overflow: hidden;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14), 0 40px 80px -30px rgba(0, 0, 0, 0.9), 0 0 120px -40px rgba(139, 108, 255, 0.5);
  transition: box-shadow 0.4s;
}
.drawing-now .canvas-wrap { box-shadow: 0 0 0 3px var(--lime), 0 40px 80px -30px rgba(0, 0, 0, 0.9), 0 0 120px -30px rgba(185, 255, 59, 0.45); }
#board { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.drawing-now #board { cursor: crosshair; }
.brush-cursor {
  position: absolute; left: 0; top: 0; pointer-events: none; border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.75); box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.85);
  transform: translate(-50%, -50%);
}

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 5%;
  background: rgba(10, 10, 16, 0.9);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  animation: fade 0.3s both; text-align: center; overflow: auto;
}
@keyframes fade { from { opacity: 0; } }
.overlay-inner { display: grid; justify-items: center; gap: clamp(8px, 2.6cqw, 20px); width: 100%; animation: rise 0.5s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
.overlay h3 { margin: 0; font: 700 clamp(22px, 4.6cqw, 40px)/1.05 var(--display); letter-spacing: -0.03em; }
.overlay .sub { color: var(--muted); font-size: clamp(13px, 2cqw, 16px); }
.overlay .big-avatar { width: clamp(64px, 14cqw, 112px); height: clamp(64px, 14cqw, 112px); animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(3deg); } }
.dots::after { content: ''; animation: dots 1.4s steps(4, end) infinite; }
@keyframes dots { 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: min(100%, 640px); }
.choice {
  display: grid; gap: 8px; padding: clamp(14px, 3.4cqw, 28px) 10px; border-radius: 18px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  font: 700 clamp(16px, 3cqw, 24px)/1.1 var(--display); letter-spacing: -0.02em;
  transition: transform 0.25s var(--spring), background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.25s;
  animation: pop-in 0.45s var(--spring) both;
}
.choice:nth-child(2) { animation-delay: 0.06s; }
.choice:nth-child(3) { animation-delay: 0.12s; }
.choice small { font: 500 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.choice:hover { transform: translateY(-4px) rotate(-1deg); background: var(--lime); color: var(--on-accent); border-color: transparent; box-shadow: 0 16px 40px -14px rgba(185, 255, 59, 0.8); }
.choice:hover small { color: rgba(11, 13, 5, 0.6); }
.countdown { width: min(100%, 320px); height: 5px; border-radius: 9px; background: var(--surface-2); overflow: hidden; }
.countdown i { display: block; height: 100%; width: 100%; background: var(--lime); border-radius: inherit; transform-origin: left; }

.reveal-word { font: 800 clamp(34px, 9cqw, 76px)/1 var(--display); letter-spacing: -0.04em; color: var(--lime); text-transform: lowercase; text-shadow: 0 0 60px rgba(185, 255, 59, 0.4); }
.gains { display: grid; gap: 6px; width: min(100%, 360px); }
.gains li {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px; border-radius: 12px; background: var(--surface); text-align: left;
  animation: rise 0.4s var(--ease) both;
}
.gains .avatar-box { width: 28px; height: 28px; }
.gains .name { font-weight: 550; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gains .pts { font: 600 14px var(--mono); color: var(--lime); }
.gains .pts.zero { color: var(--faint); }

.toolbar { flex: none; padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; border-radius: 20px; max-width: 100%; }
.swatches { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 5px; }
.swatch {
  width: 26px; height: 26px; border-radius: 9px; border: 1px solid rgba(255, 255, 255, 0.16);
  transition: transform 0.2s var(--spring), box-shadow 0.2s;
}
.swatch:hover { transform: scale(1.15); }
.swatch[aria-checked='true'] { transform: scale(1.12); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #fff; }
.tool-row { display: flex; align-items: center; justify-content: center; gap: 6px; }
.sizes { display: flex; align-items: center; gap: 4px; }
.size, .tool {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--muted);
  transition: background 0.2s, color 0.2s, transform 0.2s var(--ease);
}
.size:hover, .tool:hover { background: var(--surface-2); color: var(--text); }
.size i { display: block; border-radius: 50%; background: currentColor; }
.size[aria-checked='true'], .tool[aria-pressed='true'] { background: var(--lime); color: var(--on-accent); }
.tool:active { transform: scale(0.92); }
.tool.danger:hover { background: rgba(255, 92, 108, 0.18); color: var(--red); }
.divider { width: 1px; height: 22px; background: var(--line-strong); margin: 0 4px; }

.chat { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 5px; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
#messages li { font-size: 14.5px; line-height: 1.4; overflow-wrap: anywhere; animation: msg-in 0.25s var(--ease) both; }
#messages li:first-child { margin-top: auto; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.msg b { font-weight: 600; margin-right: 6px; }
.msg.hidden { opacity: 0.62; }
.msg.hidden::before { content: 'guessed'; font: 500 10px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--lime); margin-right: 6px; }
.sys { color: var(--faint); font-size: 13px !important; }
.sys.good {
  color: var(--lime); font-weight: 550; font-size: 14px !important;
  background: var(--lime-soft); border-radius: 10px; padding: 6px 10px; margin: 2px 0;
}
.sys.good span { font-family: var(--mono); opacity: 0.8; margin-left: 4px; }
.sys.warn { color: var(--amber); }
.sys.info { color: var(--muted); }
.sys.info b { color: var(--text); font-weight: 600; }
#chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); flex: none; }
#chat-input { height: 46px; border-radius: 13px; }
.send {
  width: 46px; height: 46px; flex: none; border-radius: 13px; display: grid; place-items: center;
  background: var(--lime); color: var(--on-accent); transition: transform 0.2s var(--spring), background 0.2s;
}
.send:hover { transform: translateY(-2px); background: #c8ff63; }
.send:active { transform: scale(0.92); }

/* ---- final scoreboard ------------------------------------------------------ */

.final {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  display: grid; place-items: center; padding: 24px var(--pad);
  background: rgba(8, 8, 13, 0.93);
  -webkit-backdrop-filter: blur(22px); backdrop-filter: blur(22px);
  animation: fade 0.4s both;
}
.final-inner { width: min(100%, 560px); display: grid; gap: 22px; justify-items: center; text-align: center; }
.final .eyebrow { color: var(--lime); }
.final h2 { font: 800 clamp(34px, 7vw, 60px)/1 var(--display); letter-spacing: -0.04em; }
.final .actions { width: 100%; }
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 10px; width: 100%; margin-top: 8px; }
.podium .place { display: grid; justify-items: center; gap: 8px; animation: rise 0.6s var(--ease) both; }
.podium .place:nth-child(1) { animation-delay: 0.25s; }
.podium .place:nth-child(2) { animation-delay: 0.5s; }
.podium .place:nth-child(3) { animation-delay: 0.1s; }
.podium .avatar-box { width: clamp(52px, 13vw, 76px); height: clamp(52px, 13vw, 76px); }
.podium .first .avatar-box { width: clamp(68px, 17vw, 100px); height: clamp(68px, 17vw, 100px); }
.podium .name { font-weight: 650; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .score { font: 500 13px var(--mono); color: var(--muted); }
.podium .step {
  width: 100%; border-radius: 16px 16px 6px 6px; display: grid; place-items: start center; padding-top: 12px;
  font: 800 30px var(--display); color: rgba(255, 255, 255, 0.85);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--line); border-bottom: 0;
}
.podium .first .step { height: 124px; background: linear-gradient(180deg, var(--lime), rgba(185, 255, 59, 0.08)); color: var(--on-accent); border-color: transparent; }
.podium .second .step { height: 88px; }
.podium .third .step { height: 62px; }
.ranking { width: 100%; display: grid; gap: 6px; }
.ranking li {
  display: grid; grid-template-columns: 24px 32px minmax(0, 1fr) auto; align-items: center; gap: 12px; text-align: left;
  padding: 8px 14px 8px 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
}
.ranking .avatar-box { width: 32px; height: 32px; }
.ranking .rank { font: 500 12px var(--mono); color: var(--faint); text-align: center; }
.ranking .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .score { font: 500 13px var(--mono); color: var(--muted); }

/* ---- toasts, banner, confetti ---------------------------------------------- */

.toasts { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  padding: 12px 18px; border-radius: 14px; font-weight: 550; font-size: 14.5px;
  background: #1c1c28; border: 1px solid var(--line-strong); box-shadow: 0 20px 50px -15px rgba(0, 0, 0, 0.8);
  animation: toast-in 0.4s var(--spring) both;
}
.toast.good { background: var(--lime); color: var(--on-accent); border-color: transparent; }
.toast.bad { border-color: rgba(255, 92, 108, 0.5); }
.toast.out { animation: toast-out 0.3s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(0.9); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.96); } }

.banner {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 60;
  padding: 9px 16px; border-radius: 99px; font: 500 13px var(--mono);
  background: var(--amber); color: #1c1300; box-shadow: 0 12px 30px -10px rgba(255, 194, 75, 0.6);
}
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 70; }

/* ---- touch screens --------------------------------------------------------- */

/* Fingers need bigger targets than a mouse pointer does. */
@media (pointer: coarse) {
  .swatch { width: 34px; height: 34px; border-radius: 11px; }
  .size, .tool { width: 44px; height: 44px; border-radius: 13px; }
  .icon-btn { width: 44px; height: 44px; }
  .segmented button { height: 46px; }
  .choice:hover { transform: none; }
}

/* ---- tablets in landscape, small laptops ----------------------------------- */

/* Two columns: the drawing gets most of the screen, players and chat share the side. */
@media (min-width: 861px) and (max-width: 1279px) and (min-height: 541px) {
  .game-grid {
    grid-template-columns: minmax(0, 1fr) clamp(250px, 28vw, 320px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'stage players' 'stage chat';
  }
  .stage { grid-area: stage; }
  .players-panel { grid-area: players; max-height: 32vh; padding: 8px; }
  .chat { grid-area: chat; }
  #game-players { gap: 4px; }
  .player { grid-template-columns: 16px 32px minmax(0, 1fr) auto; padding: 6px 10px 6px 6px; border-radius: 13px; }
  .player .avatar-box { width: 32px; height: 32px; }
  .player .who { grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 8px; }
}

/* ---- phones, tablets in portrait ------------------------------------------- */

@media (max-width: 860px) {
  .lobby-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'invite' 'players' 'settings'; }
  .how { grid-template-columns: minmax(0, 1fr); width: min(100%, 460px); }
}

/* The compact game: used on anything narrow, and on phones lying on their side. */
@media (max-width: 860px), (max-height: 540px) and (orientation: landscape) and (min-width: 560px) {
  .view-game { padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  /* The word gets a row of its own, so that long words fit. */
  .gamebar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'side end' 'word word'; padding: 8px 0; gap: 6px 8px; }
  .gamebar-side { grid-area: side; }
  .gamebar-side.end { grid-area: end; }
  .word { grid-area: word; gap: 5px; min-height: 44px; align-content: center; }
  .slots { font-size: 17px; gap: 4px; }
  .gamebar .wordmark, .gamebar [data-action='copy'] { display: none; }
  .gamebar .icon-btn { width: 40px; height: 40px; border-radius: 12px; }
  .timer { width: 40px; height: 40px; }
  .pill { padding: 7px 9px; font-size: 11.5px; }

  /* One column: drawing, tools (for the artist), a strip of players, then the chat. */
  .game-grid { display: flex; flex-direction: column; gap: 8px; }
  .stage { container-type: inline-size; flex: none; order: 1; gap: 8px; width: 100%; }
  /* At most half the visible height, so the chat stays on screen, also above a phone keyboard. */
  .canvas-wrap { width: min(100cqw, var(--app-h) * 0.5 * 4 / 3); border-radius: 16px; }
  .toolbar { width: min(100%, 480px); padding: 8px; gap: 8px; border-radius: 16px; }
  .swatches { gap: 4px; }
  .swatch { width: 100%; height: auto; aspect-ratio: 1; border-radius: 7px; }
  /* All nine buttons share one row and shrink together on the narrowest phones. */
  .tool-row { gap: 2px; }
  .sizes { display: contents; }
  .size, .tool { flex: 0 1 44px; min-width: 26px; width: auto; height: 40px; }
  .divider { margin: 0 2px; flex: none; }

  .overlay { padding: 10px; }
  .gains { gap: 4px; }
  .gains li { grid-template-columns: 24px minmax(0, 1fr) auto; padding: 3px 10px 3px 4px; }
  .gains .avatar-box { width: 24px; height: 24px; }

  .players-panel { order: 2; flex: none; max-height: none; padding: 6px; border-radius: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  #game-players { display: flex; gap: 6px; }
  .player { grid-template-columns: 28px auto; gap: 7px; padding: 5px 10px 5px 5px; border-radius: 12px; flex: none; }
  .player .rank, .player .status { display: none; }
  .player .avatar-box { width: 28px; height: 28px; }
  .player .name { font-size: 12.5px; max-width: 84px; }
  .player .score { font-size: 11px; }
  .player .gain { right: 6px; top: 0; }

  .chat { order: 3; flex: 1; min-height: 96px; border-radius: 16px; }
  #messages { padding: 10px 12px 4px; }
  #chat-form { padding: 8px; }
  #chat-input, .send { height: 44px; }
  .send { width: 44px; }
  /* iOS zooms the page when a focused input is smaller than 16px. */
  input { font-size: 16px; }
}

/* A phone with its keyboard open: only the drawing and the chat matter. */
.short .players-panel, .short .toolbar { display: none; }
.short .canvas-wrap { width: min(100cqw, var(--app-h) * 0.42 * 4 / 3); }
.short .word { min-height: 0; }

/* Small drawings have no room for the whole score list. */
@media (max-width: 560px), (max-height: 540px) and (orientation: landscape) and (min-width: 560px) {
  .gains li:nth-child(n + 5) { display: none; }
  .choices { gap: 8px; }
}

@media (max-width: 420px) {
  .share { flex-wrap: wrap; }
  .share input { flex: 1 0 100%; }
  .share .btn.primary { flex: 1; }
}

/* ---- phones in landscape --------------------------------------------------- */

/* Not much height: the drawing fills the left, everything else stacks on the right. */
@media (max-height: 540px) and (orientation: landscape) and (min-width: 560px) {
  .view-home { justify-content: flex-start; }
  .hero .wordmark { font-size: clamp(56px, 22vh, 96px); }
  .tagline br { display: none; }

  .gamebar { grid-template-columns: 1fr auto 1fr; grid-template-areas: 'side word end'; padding: 6px 0; }
  .word { min-height: 0; gap: 4px; }
  .word-text { font-size: 19px; }
  .slots { font-size: 15px; }
  .gamebar .icon-btn, .timer { width: 36px; height: 36px; }

  .game-grid {
    display: grid; gap: 6px 10px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: 'canvas players' 'canvas tools' 'canvas chat';
  }
  /* The stage steps aside, so the drawing and its tools can sit in different columns. */
  .stage { display: contents; }
  .canvas-wrap { grid-area: canvas; align-self: start; width: min(58vw, (var(--app-h) - 62px) * 4 / 3); border-radius: 14px; }
  .toolbar { grid-area: tools; width: 100%; padding: 6px; gap: 6px; border-radius: 14px; }
  .swatch { aspect-ratio: 1.6; border-radius: 6px; }
  .size, .tool { height: 32px; }
  .players-panel { grid-area: players; border-radius: 14px; padding: 4px; }
  .chat { grid-area: chat; min-height: 0; border-radius: 14px; }
  #messages { padding: 6px 10px 2px; }
  #chat-form { padding: 6px; }
  #chat-input, .send { height: 38px; }
  .send { width: 38px; }

  .final { place-items: start center; padding-top: 12px; }
  .final-inner { gap: 12px; }
  .podium .first .step { height: 64px; }
  .podium .second .step { height: 46px; }
  .podium .third .step { height: 34px; }
  .podium .step { padding-top: 4px; font-size: 22px; }
}

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