/* Hangman: the same dark, glassy look as Sketch, with pink as its accent. */

@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;
  --accent: #ff5fa2;
  --good: #b9ff3b;
  --accent-soft: rgba(255, 95, 162, 0.14);
  --violet: #8b6cff;
  --pink: #ff5fa2;
  --cyan: #4fd8ff;
  --amber: #ffc24b;
  --red: #ff5c6c;
  --on-accent: #1d0611;
  --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(--accent); outline-offset: 3px; }
::selection { background: var(--accent); 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(--accent); }

.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(--accent); color: var(--on-accent); border-color: transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 10px 30px -12px rgba(255, 95, 162, 0.7);
}
.btn.primary:hover { background: #ff85b9; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 14px 40px -10px rgba(255, 95, 162, 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(--accent); box-shadow: 0 0 0 4px var(--accent-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 {
  position: relative;
  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; }
.hub-link {
  position: absolute; top: max(16px, env(safe-area-inset-top)); left: max(var(--pad), env(safe-area-inset-left));
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px 9px 10px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  font-size: 14px; font-weight: 550; text-decoration: none; transition: color 0.2s, background 0.2s, transform 0.2s var(--ease);
}
.hub-link:hover { color: var(--text); background: var(--surface-2); transform: translateX(-2px); }
.hub-link .icon { width: 16px; height: 16px; }
.hero .wordmark {
  position: relative; display: inline-block;
  font-size: clamp(60px, 15.5vw, 160px);
  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(--accent); 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(255, 95, 162, 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(--accent-soft); color: var(--accent); font-weight: 550; font-size: 15px;
  border: 1px solid rgba(255, 95, 162, 0.25);
}
.invite-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 95, 162, 0.6); } 100% { box-shadow: 0 0 0 10px rgba(255, 95, 162, 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(--accent); background: var(--accent-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(--accent), #ff9a5f 55%, var(--amber));
  -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(255, 95, 162, 0.35); background: rgba(255, 95, 162, 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 everything below the scene plus the gap above it; measured by the client. */
  --play-h: 320px;
}

.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(--accent); }
.timer { position: relative; width: 46px; height: 46px; flex: none; display: grid; place-items: center; color: var(--accent); }
.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.setter { background: rgba(139, 108, 255, 0.14); border-color: rgba(139, 108, 255, 0.4); }
.player.setter .status { background: var(--violet); color: #fff; }
.player.turn { background: var(--accent-soft); border-color: rgba(255, 95, 162, 0.32); }
.player.turn .status { background: var(--accent); 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(--good);
  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 scene is as large as fits both the width and the height left over by what is below it. */
.stage { container-type: size; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.scene {
  position: relative; flex: none;
  width: max(150px, min(100cqw, (100cqh - var(--play-h)) * 1.2));
  aspect-ratio: 6 / 5;
  container-type: inline-size;
  border-radius: 26px; overflow: hidden;
  background: radial-gradient(120% 90% at 72% 0%, #2d2670 0%, #18153c 45%, #0d0c1f 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 40px 80px -30px rgba(0, 0, 0, 0.9), 0 0 120px -40px rgba(139, 108, 255, 0.5);
}
/* The sky turns red as the mistakes add up. */
.scene::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(90% 80% at 60% 45%, rgba(255, 50, 80, 0.4), transparent 72%);
  opacity: var(--danger, 0); transition: opacity 0.8s;
}
.scene-svg { position: relative; z-index: 1; display: block; width: 100%; height: 100%; }

.scene-svg .star { fill: #fff; animation: hk-twinkle 2.6s ease-in-out infinite alternate; }
.scene-svg .star:nth-child(2n) { animation-delay: -1.1s; }
.scene-svg .star:nth-child(3n) { animation-delay: -1.9s; }
.scene-svg .moon { fill: #f3eccb; opacity: 0.9; }
.scene-svg .crater { fill: #d9cf9f; opacity: 0.7; }
.scene-svg .hill { fill: #221d4d; }
.scene-svg .hill-top { fill: none; stroke: rgba(255, 255, 255, 0.16); stroke-width: 2; }
.scene-svg .tuft { fill: none; stroke: #4c4396; stroke-width: 3; stroke-linecap: round; }
.scene-svg .wood { fill: none; stroke: url(#hk-wood); stroke-width: 15; stroke-linecap: round; }
.scene-svg .wood.thin { stroke-width: 10; }
.scene-svg .rope { fill: none; stroke: #eadfc4; stroke-width: 5; stroke-linecap: round; }
.scene-svg .limb { fill: none; stroke: #f4f1ea; stroke-width: 11; stroke-linecap: round; }
.scene-svg .hand { fill: #f4f1ea; }
.scene-svg .shoe { fill: var(--accent); }
.scene-svg .tie { fill: var(--accent); }
.scene-svg .ink { fill: #1a1626; }
.scene-svg .line { fill: none; stroke: #1a1626; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes hk-twinkle { from { opacity: 0.15; } to { opacity: 0.9; } }

/* Each mistake switches on one step. A step that has just appeared is drawn in. */
.step { visibility: hidden; }
.step.on { visibility: visible; }
.step .draw { stroke-dasharray: 1; }
.step .pop, .hk-eye, .hk-brow { transform-box: fill-box; transform-origin: center; }
.step.fresh .draw { animation: hk-draw 0.45s var(--ease) both; }
.step.fresh .pop { animation: hk-pop 0.5s 0.2s var(--spring) both; }
.step.fresh.hk-head .pop { animation-delay: 0s; }
@keyframes hk-draw { from { stroke-dashoffset: 1; } }
@keyframes hk-pop { from { transform: scale(0); } }

/* He hangs from the end of the rope and sways around the point where it is tied. */
#hk-swing { transform-origin: 290px 62px; animation: hk-sway 3.6s ease-in-out infinite alternate; }
.jolt #hk-swing { animation: hk-jolt 0.9s ease-out; }
[data-mood='panic'] #hk-swing { animation-duration: 1.3s; }
@keyframes hk-sway { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }
@keyframes hk-jolt {
  0% { transform: rotate(0); } 15% { transform: rotate(10deg); } 40% { transform: rotate(-7deg); }
  65% { transform: rotate(4deg); } 85% { transform: rotate(-2.5deg); } 100% { transform: rotate(-2deg); }
}

/* His face: one mouth per mood, and eyes that are swapped out when he is overjoyed or gone. */
.hk-mouth, .hk-joy, .hk-x, .hk-tongue, .hk-sweat { display: none; }
[data-mood='calm'] .m-calm, [data-mood='uneasy'] .m-uneasy, [data-mood='worried'] .m-worried,
[data-mood='panic'] .m-panic, [data-mood='happy'] .m-happy, [data-mood='dead'] .m-dead { display: inline; }
[data-mood='happy'] .hk-eyes, [data-mood='dead'] .hk-eyes { display: none; }
[data-mood='happy'] .hk-joy, [data-mood='dead'] .hk-x, [data-mood='dead'] .hk-tongue { display: inline; }
[data-mood='worried'] .hk-sweat, [data-mood='panic'] .hk-sweat { display: inline; }
.hk-eye { animation: hk-blink 4.6s infinite; }
.hk-pupil { transform: translate(calc(var(--px, 0) * 1px), calc(var(--py, 0) * 1px)); transition: transform 0.12s; }
[data-mood='panic'] .hk-eye { animation: none; transform: scale(1.2); }
[data-mood='panic'] .hk-face { animation: hk-shake 0.1s linear infinite alternate; }
.hk-brow { opacity: 0; transition: transform 0.3s, opacity 0.3s; }
[data-mood='uneasy'] .hk-brow, [data-mood='worried'] .hk-brow, [data-mood='panic'] .hk-brow { opacity: 1; }
[data-mood='uneasy'] .hk-brow.l { transform: rotate(-10deg); }
[data-mood='uneasy'] .hk-brow.r { transform: rotate(10deg); }
[data-mood='worried'] .hk-brow.l { transform: translateY(-1px) rotate(-19deg); }
[data-mood='worried'] .hk-brow.r { transform: translateY(-1px) rotate(19deg); }
[data-mood='panic'] .hk-brow.l { transform: translateY(-4px) rotate(-27deg); }
[data-mood='panic'] .hk-brow.r { transform: translateY(-4px) rotate(27deg); }
.hk-sweat path { fill: #8fd6ff; animation: hk-drip 1.1s ease-in infinite; }
.hk-sweat path:nth-child(2) { animation-delay: -0.55s; }
@keyframes hk-blink { 0%, 93%, 100% { transform: scaleY(1); } 96.5% { transform: scaleY(0.08); } }
@keyframes hk-shake { from { transform: translateX(-1.3px); } to { transform: translateX(1.3px); } }
@keyframes hk-drip { from { transform: translateY(-2px); opacity: 1; } to { transform: translateY(16px); opacity: 0; } }

/* Arms turn around the shoulder, legs around the hip. */
.hk-armL, .hk-armR { transform-origin: 290px 182px; transition: transform 0.5s var(--ease); }
.hk-legL, .hk-legR { transform-origin: 290px 240px; transition: transform 0.5s var(--ease); }
[data-mood='panic'] .hk-armL { animation: hk-flail-l 0.26s ease-in-out infinite alternate; }
[data-mood='panic'] .hk-armR { animation: hk-flail-r 0.3s ease-in-out infinite alternate; }
[data-mood='panic'] .hk-legL { animation: hk-kick-l 0.34s ease-in-out infinite alternate; }
[data-mood='panic'] .hk-legR { animation: hk-kick-r 0.28s ease-in-out infinite alternate; }
[data-mood='dead'] .hk-armL { transform: rotate(-32deg); }
[data-mood='dead'] .hk-armR { transform: rotate(32deg); }
[data-mood='dead'] .hk-legL { transform: rotate(-15deg); }
[data-mood='dead'] .hk-legR { transform: rotate(15deg); }
@keyframes hk-flail-l { from { transform: rotate(5deg); } to { transform: rotate(75deg); } }
@keyframes hk-flail-r { from { transform: rotate(-75deg); } to { transform: rotate(-5deg); } }
@keyframes hk-kick-l { from { transform: rotate(-10deg); } to { transform: rotate(18deg); } }
@keyframes hk-kick-r { from { transform: rotate(-18deg); } to { transform: rotate(10deg); } }

/* A right guess: a little hop of relief. */
.cheer #hk-hank { animation: hk-cheer 0.5s var(--ease); }
@keyframes hk-cheer { 40% { transform: translateY(-9px); } }

/* Saved: the rope lets go, he lands, grows back whatever was missing and dances. */
.saved #hk-swing { animation: none; }
.saved.had-head .step[data-step='rope'] .draw { transform-origin: 290px 62px; transform: scaleY(0.4); transition: transform 0.2s; }
.saved #hk-drop { animation: hk-drop 0.6s cubic-bezier(0.5, 0, 1, 0.7) both; }
.saved:not(.had-head) #hk-drop { animation: hk-arrive 0.8s var(--spring) both; }
.saved #hk-hank { transform-origin: 290px 300px; animation: hk-dance 0.38s 0.65s ease-in-out infinite alternate; }
.saved #hk-hank .step { visibility: visible; }
.saved #hk-hank .step:not(.on) > * { animation: hk-late 0.35s 0.6s both; }
.saved .hk-armL { animation: hk-wave-l 0.3s 0.6s ease-in-out infinite alternate; }
.saved .hk-armR { animation: hk-wave-r 0.34s 0.6s ease-in-out infinite alternate; }
.saved .hk-legL { animation: hk-kick-l 0.38s 0.65s ease-in-out infinite alternate; }
.saved .hk-legR { animation: hk-kick-r 0.38s 0.65s ease-in-out infinite alternate; }
@keyframes hk-drop { 0% { transform: translateY(0); } 55% { transform: translateY(50px); } 75% { transform: translateY(38px); } 100% { transform: translateY(50px); } }
@keyframes hk-arrive { from { transform: translate(240px, 50px); } to { transform: translate(0, 50px); } }
@keyframes hk-dance { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-14px) rotate(6deg); } }
@keyframes hk-late { from { opacity: 0; } }
@keyframes hk-wave-l { from { transform: rotate(60deg); } to { transform: rotate(120deg); } }
@keyframes hk-wave-r { from { transform: rotate(-120deg); } to { transform: rotate(-60deg); } }

/* Hanged: a slow swing, and a ghost that leaves through the top of the picture. */
.hanged #hk-swing { animation: hk-swing-dead 2.4s ease-in-out infinite alternate; }
#hk-ghost { opacity: 0; }
.hanged #hk-ghost { animation: hk-ghost 6.5s 1.1s ease-out forwards; }
.hanged .gh-in { animation: hk-ghost-sway 1.5s ease-in-out infinite alternate; }
.hanged .gh-hand { transform-origin: 22px 6px; animation: hk-ghost-wave 0.4s ease-in-out infinite alternate; }
.gh-body { fill: #fff; opacity: 0.92; }
.gh-halo { fill: none; stroke: #ffd84d; stroke-width: 4; }
@keyframes hk-swing-dead { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
@keyframes hk-ghost {
  0% { opacity: 0; transform: translate(0, 0) scale(0.5); } 10% { opacity: 1; transform: translate(30px, -22px) scale(1); }
  80% { opacity: 1; } 100% { opacity: 0; transform: translate(96px, -120px) scale(1); }
}
@keyframes hk-ghost-sway { from { transform: translateX(-9px) rotate(-5deg); } to { transform: translateX(9px) rotate(5deg); } }
@keyframes hk-ghost-wave { from { transform: rotate(-20deg); } to { transform: rotate(25deg); } }

/* The bird sits on the beam once there is one, and has opinions. */
#hk-crow { transform: translate(215px, 55px); transition: transform 0.7s var(--spring); }
.no-beam #hk-crow { transform: translate(58px, 357px); }
.crow-in { animation: hk-bob 2.2s ease-in-out infinite alternate; }
.crow-body { fill: url(#hk-crow-fill); }
.crow-dark { fill: #4a3ab8; }
.crow-beak { fill: #ffb43c; }
.crow-leg { fill: none; stroke: #ffb43c; stroke-width: 3; stroke-linecap: round; }
.crow-beak.lo { transform-origin: 25px -36px; transition: transform 0.12s; }
.crow-wing { transform-box: fill-box; transform-origin: 50% 10%; }
.caw .crow-in { animation: hk-hop 0.5s var(--ease); }
.caw .crow-beak.lo { transform: rotate(24deg); }
.hanged .crow-in { animation: hk-laugh 0.14s linear infinite alternate; }
.hanged .crow-beak.lo { transform: rotate(24deg); }
.saved #hk-crow { animation: hk-flyaway 1.7s 0.4s ease-in forwards; }
.saved .crow-wing { animation: hk-flap 0.11s linear infinite alternate; }
@keyframes hk-bob { from { transform: rotate(-2deg); } to { transform: translateY(-1.5px) rotate(2deg); } }
@keyframes hk-hop { 35% { transform: translateY(-16px) rotate(-8deg); } 70% { transform: translateY(0); } 85% { transform: translateY(-4px); } }
@keyframes hk-laugh { from { transform: translateY(0) rotate(-5deg); } to { transform: translateY(-4px) rotate(5deg); } }
@keyframes hk-flyaway { to { transform: translate(-90px, -110px) rotate(-25deg); opacity: 0; } }
@keyframes hk-flap { from { transform: scaleY(1); } to { transform: scaleY(-0.9); } }

/* Speech bubbles are HTML on top of the picture, sized with it. */
.bubble {
  position: absolute; z-index: 2; max-width: 50%; padding: 0.5em 0.8em; border-radius: 1.1em;
  background: #fff; color: #17142e; font: 650 clamp(11.5px, 3.5cqw, 17px)/1.25 var(--body); text-wrap: balance;
  box-shadow: 0 10px 26px -8px rgba(0, 0, 0, 0.65);
  opacity: 0; pointer-events: none; transform: scale(0.5); transition: opacity 0.15s, transform 0.3s var(--spring);
}
.bubble.show { opacity: 1; transform: scale(1); }
.bubble::after { content: ''; position: absolute; width: 13px; height: 13px; background: inherit; transform: rotate(45deg); border-radius: 3px; }
.bubble.hank { left: 46%; bottom: 76.5%; transform-origin: 25% 100%; }
.bubble.hank::after { left: 22%; bottom: -5px; }
.bubble.crow { right: 60%; top: 3%; max-width: 38%; transform-origin: 100% 60%; }
.bubble.crow::after { right: -5px; top: 50%; margin-top: -6px; }
.no-beam .bubble.crow { right: auto; left: 4%; top: auto; bottom: 24%; transform-origin: 20% 100%; }
.no-beam .bubble.crow::after { right: auto; left: 18%; top: auto; bottom: -5px; margin: 0; }

/* Below the scene: hint, lives, the word, and whatever the moment calls for. */
.play { flex: none; width: min(100%, 700px); display: grid; gap: 12px; justify-items: center; }
.play-top { width: 100%; min-height: 30px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hint {
  font: 550 13px/1 var(--mono); letter-spacing: 0.02em; color: var(--accent);
  padding: 8px 12px; border-radius: 99px; background: var(--accent-soft); border: 1px solid rgba(255, 95, 162, 0.25);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.hint:empty { visibility: hidden; }
.lives { display: flex; gap: 5px; flex: none; }
.lives i {
  width: 11px; height: 11px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 95, 162, 0.7); transition: background 0.3s, box-shadow 0.3s, transform 0.3s var(--spring);
}
.lives i.lost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); transform: scale(0.8); }

.letters {
  container-type: inline-size; width: 100%; min-height: 40px;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 20px;
  --tile: clamp(22px, calc(100cqw / var(--cols, 10) - 6px), 54px);
}
.letter-word { display: flex; gap: 6px; }
.letter { width: var(--tile); height: calc(var(--tile) * 1.16); perspective: 500px; }
.letter-in { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.6s var(--spring); transition-delay: calc(var(--d, 0) * 70ms); }
.letter.open .letter-in { transform: rotateX(180deg); }
.letter-front, .letter-back {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: calc(var(--tile) * 0.24);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  font: 800 calc(var(--tile) * 0.6)/1 var(--display); text-transform: uppercase;
}
/* The player who chose the word sees its letters faintly on the closed tiles. */
.letter-front { background: rgba(255, 255, 255, 0.07); box-shadow: inset 0 0 0 1px var(--line-strong), inset 0 -3px 0 rgba(255, 255, 255, 0.1); color: rgba(255, 255, 255, 0.2); }
.letter-back { transform: rotateX(180deg); background: #f6f3ec; color: #17142e; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16), 0 6px 16px -6px rgba(0, 0, 0, 0.6); }
.letter.missed .letter-back { background: var(--red); color: #2c070c; }
.letter.dash { display: grid; place-items: center; font: 800 calc(var(--tile) * 0.6)/1 var(--display); color: var(--muted); width: calc(var(--tile) * 0.5); }
.letters.win .letter { animation: tile-hop 0.5s calc(var(--i, 0) * 45ms + 0.4s) var(--ease); }
@keyframes tile-hop { 40% { transform: translateY(-12px); } }

.keys-wrap { width: 100%; display: grid; gap: 10px; }
.keyboard { display: grid; gap: 6px; }
.key-row { display: flex; justify-content: center; gap: 6px; }
.key {
  flex: 1 1 0; max-width: 54px; min-width: 0; height: 50px; border-radius: 13px;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line), inset 0 -3px 0 rgba(255, 255, 255, 0.06);
  font: 650 17px/1 var(--mono); text-transform: uppercase; color: var(--text);
  transition: transform 0.12s var(--ease), background 0.2s, color 0.2s, opacity 0.2s;
}
.key:disabled { cursor: default; }
.keyboard:not(.mine) .key:not(.hit):not(.miss) { opacity: 0.45; }
.keyboard.mine .key:not(:disabled) { background: var(--surface-3); }
.keyboard.mine .key:not(:disabled):hover { background: var(--accent); color: var(--on-accent); transform: translateY(-3px); }
.keyboard.mine .key:not(:disabled):active { transform: translateY(1px); }
.key.hit { background: var(--good); color: #0b0d05; box-shadow: none; }
.key.miss { background: rgba(255, 92, 108, 0.1); color: rgba(255, 92, 108, 0.65); box-shadow: none; text-decoration: line-through; }
.key.fresh.hit { animation: key-hit 0.5s var(--spring); }
.key.fresh.miss { animation: shake 0.4s; }
@keyframes key-hit { 40% { transform: scale(1.3) rotate(-6deg); } }
.keys-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }
.status { color: var(--muted); font-size: 14.5px; font-weight: 550; min-width: 0; }
.status.mine { color: var(--accent); }
.btn.small { height: 40px; padding: 0 16px; font-size: 14.5px; border-radius: 12px; flex: none; }
.solve { display: flex; align-items: center; gap: 8px; }
.solve input, .own-word input { height: 44px; border-radius: 12px; }
.solve .btn.small, .own-word .btn.small { height: 44px; }

.picker { width: 100%; display: grid; gap: 12px; }
.picker-title { font: 700 clamp(18px, 2.4vw, 22px)/1.1 var(--display); letter-spacing: -0.02em; text-align: center; }
.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.choice {
  display: grid; gap: 7px; padding: 16px 8px; border-radius: 16px; text-align: center; overflow-wrap: anywhere;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong);
  font: 700 clamp(15px, 2.2vw, 20px)/1.1 var(--display); letter-spacing: -0.02em;
  transition: transform 0.25s var(--spring), background 0.2s, 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(--accent); color: var(--on-accent); box-shadow: 0 16px 40px -14px rgba(255, 95, 162, 0.8); }
.choice:hover small { color: rgba(29, 6, 17, 0.6); }
.own-word { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto; gap: 8px; }
.countdown { justify-self: center; 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(--accent); border-radius: inherit; transform-origin: left; }

.waiting { display: grid; justify-items: center; gap: 12px; padding: 12px 0; text-align: center; }
.waiting .avatar-box { width: 72px; height: 72px; animation: bob 2.2s ease-in-out infinite; }
.waiting h3 { margin: 0; font: 700 clamp(18px, 2.6vw, 24px)/1.1 var(--display); letter-spacing: -0.02em; }
.waiting p { color: var(--muted); font-size: 14.5px; }
@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: '...'; } }

.result { width: 100%; display: grid; justify-items: center; gap: 12px; text-align: center; animation: rise 0.5s var(--ease) both; }
.result h3 { margin: 0; font: 800 clamp(22px, 3.4vw, 32px)/1.05 var(--display); letter-spacing: -0.03em; }
.result.saved h3 { color: var(--good); }
.result.hanged h3 { color: var(--red); }
.result p { color: var(--muted); font-size: 14.5px; }
.gains { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.gains li {
  display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 5px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); animation: rise 0.4s var(--ease) both;
}
.gains .avatar-box { width: 26px; height: 26px; }
.gains .name { font-weight: 550; font-size: 14px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gains .pts { font: 600 14px var(--mono); color: var(--good); }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
@keyframes fade { from { opacity: 0; } }

.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; }
.sys { color: var(--faint); font-size: 13px !important; }
.sys.good {
  color: var(--good); font-weight: 550; font-size: 14px !important;
  background: rgba(185, 255, 59, 0.12); 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.bad { color: var(--red); }
.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(--accent); color: var(--on-accent); transition: transform 0.2s var(--spring), background 0.2s;
}
.send:hover { transform: translateY(-2px); background: #ff85b9; }
.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(--accent); }
.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(--accent), rgba(255, 95, 162, 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(--accent); 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) {
  .icon-btn { width: 44px; height: 44px; }
  .segmented button { height: 46px; }
  .choice:hover, .keyboard.mine .key:not(:disabled):hover { transform: none; }
}

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

/* Two columns: the game 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); }
  .view-home { padding-top: 76px; }
}

/* 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)); }
  /* Whose turn it is gets a row of its own. */
  .gamebar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'side end' 'word word'; padding: 8px 0 4px; gap: 4px 8px; }
  .gamebar-side { grid-area: side; }
  .gamebar-side.end { grid-area: end; }
  .word { grid-area: word; gap: 4px; min-height: 38px; align-content: center; }
  .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: the scene, the word and keyboard, 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%; }
  .scene { width: min(100cqw, var(--app-h) * 0.3 * 1.2); border-radius: 18px; }
  .play { gap: 8px; }
  .play-top { min-height: 26px; }
  .hint { font-size: 12px; padding: 7px 10px; }
  .letters { gap: 8px 14px; --tile: clamp(18px, calc(100cqw / var(--cols, 10) - 4px), 44px); }
  .letter-word { gap: 4px; }
  .keyboard, .key-row { gap: 4px; }
  .key { height: 46px; border-radius: 10px; font-size: 16px; }
  .keys-wrap { gap: 8px; }
  .status { font-size: 13.5px; }
  .choices { gap: 6px; }
  .choice { padding: 12px 6px; border-radius: 13px; }
  .own-word { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .own-word .btn { grid-column: 1 / -1; }
  .waiting { padding: 4px 0; }
  .waiting .avatar-box { width: 52px; height: 52px; }

  .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; }

  /* The chat may shrink to just its input; the game itself matters more here. */
  .chat { order: 3; flex: 1; min-height: 58px; border-radius: 16px; }
  #messages { padding: 8px 12px 4px; }
  #chat-form { padding: 6px; }
  #chat-input, .send { height: 44px; }
  .send { width: 44px; }
  /* iOS zooms the page when a focused input is smaller than 16px. */
  input { font-size: 16px; }
}

/* Tablets in portrait have height to spare: a bigger scene and bigger keys. */
@media (min-width: 600px) and (max-width: 860px) and (min-height: 800px) {
  .scene { width: min(100cqw, var(--app-h) * 0.4 * 1.2); border-radius: 22px; }
  .key { height: 54px; font-size: 18px; }
  .play { gap: 12px; }
}

/* Small phones: every row gives up a little. */
@media (max-width: 860px) and (max-height: 720px) {
  .scene { width: min(100cqw, var(--app-h) * 0.27 * 1.2); }
  .key { height: 40px; }
  .players-panel { display: none; }
  .word { min-height: 32px; }
}

/* A phone with its keyboard open: only the word and the thing being typed matter. */
.short .scene, .short .players-panel, .short .keyboard, .short .play-top { display: none; }
.short .word { min-height: 0; }

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

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

/* Not much height: the scene fills the left, the word, keyboard and chat stack 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: 3px; }
  .word-text { font-size: 18px; }
  .gamebar .icon-btn, .timer { width: 36px; height: 36px; }

  .game-grid {
    display: grid; gap: 6px 12px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'scene play' 'scene chat';
  }
  /* The stage steps aside, so the scene and the rest can sit in different columns. */
  .stage { display: contents; }
  .scene { grid-area: scene; align-self: start; width: min(46vw, (var(--app-h) - 62px) * 1.2); border-radius: 16px; }
  .play { grid-area: play; width: 100%; gap: 6px; }
  .play-top { min-height: 22px; }
  .hint { padding: 5px 9px; }
  .letters { min-height: 0; --tile: clamp(16px, calc(100cqw / var(--cols, 10) - 4px), 34px); }
  .key { height: 34px; font-size: 15px; }
  .keys-foot { min-height: 34px; }
  .btn.small { height: 34px; }
  .players-panel { display: none; }
  .chat { grid-area: chat; min-height: 0; border-radius: 14px; }
  #messages { padding: 4px 10px 0; }
  #chat-form { padding: 5px; }
  #chat-input, .send { height: 36px; }
  .send { width: 36px; }
  .picker { gap: 6px; }
  .picker-title { font-size: 16px; }
  .choice { padding: 8px 6px; }
  .own-word { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto; }
  .own-word .btn { grid-column: auto; }
  .solve input, .own-word input, .solve .btn.small, .own-word .btn.small { height: 36px; }

  .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; }
}
