/* ============ Design tokens ============ */
:root {
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Fredoka', 'Inter', ui-rounded, system-ui, sans-serif;
  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;
  --primary: #6c5ce7;
  --primary-2: #a66bff;
  --primary-ink: #fff;
  --accent: #ff7a8a;
  --ok: #16a34a;
  --ok-bg: rgba(34, 197, 94, 0.14);
  --warn: #e11d48;
  --info: #4f46e5;
  --close: #b45309;
  --close-bg: rgba(245, 158, 11, 0.16);
  --gold: #f5b301;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --topbar: 64px;
}
[data-theme='light'] {
  color-scheme: light;
  --bg: #f3f0ff;
  --bg-2: #ffeef3;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --surface-2: rgba(108, 92, 231, 0.07);
  --border: rgba(40, 30, 90, 0.1);
  --text: #1f1a3d;
  --muted: #6e6a93;
  --shadow: 0 1px 2px rgba(40, 30, 90, 0.06), 0 10px 30px -10px rgba(60, 40, 140, 0.18);
  --shadow-lg: 0 30px 60px -20px rgba(60, 40, 140, 0.35);
  --blob1: #c9bfff;
  --blob2: #ffc6d9;
  --blob3: #b8f0e6;
}
[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0e0c1d;
  --bg-2: #160f26;
  --surface: rgba(30, 26, 56, 0.72);
  --surface-solid: #1d1936;
  --surface-2: rgba(166, 146, 255, 0.09);
  --border: rgba(200, 190, 255, 0.1);
  --text: #eeecff;
  --muted: #9d98c7;
  --ok: #4ade80;
  --warn: #fb7185;
  --info: #a5b4fc;
  --close: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 30px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, 0.7);
  --blob1: #3b2a8f;
  --blob2: #6b1f4f;
  --blob3: #0f4f4a;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(160deg, var(--bg), var(--bg-2));
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { width: 1em; height: 1em; flex: none; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 60%, transparent); outline-offset: 2px; }

.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.bg::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%237c6cf0' stroke-opacity='.18' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M20 30q10-14 20 0t20 0'/%3E%3Ccircle cx='120' cy='34' r='10'/%3E%3Cpath d='M30 110l14 14m0-14l-14 14'/%3E%3Cpath d='M110 110l10-16l10 16z'/%3E%3C/g%3E%3C/svg%3E");
}
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.7; animation: float 22s var(--ease) infinite alternate; }
.b1 { width: 46vmax; height: 46vmax; background: var(--blob1); top: -18vmax; left: -12vmax; }
.b2 { width: 38vmax; height: 38vmax; background: var(--blob2); bottom: -16vmax; right: -10vmax; animation-delay: -7s; }
.b3 { width: 26vmax; height: 26vmax; background: var(--blob3); top: 40%; left: 55%; animation-delay: -13s; opacity: 0.45; }
@keyframes float { to { transform: translate(6vmax, 4vmax) scale(1.08); } }

.card, .panel {
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  padding: 0.75em 1.1em; border-radius: var(--r-md); font-weight: 600;
  transition: transform 0.15s var(--ease), box-shadow 0.2s, background 0.2s, opacity 0.2s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: scale(0.97); }
a.btn { text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn.primary {
  color: var(--primary-ink);
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 8px 22px -8px color-mix(in srgb, var(--primary) 80%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 12px 28px -8px color-mix(in srgb, var(--primary) 90%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.25); transform: translateY(-1px); }
.btn.secondary { background: var(--surface-2); color: var(--primary); border: 1px solid color-mix(in srgb, var(--primary) 22%, transparent); }
[data-theme='dark'] .btn.secondary { color: #c4b9ff; }
.btn.secondary:hover { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.btn.locked { opacity: 0.6; filter: grayscale(0.6); }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.xl { font-family: var(--display); font-size: 1.35rem; padding: 0.7em 1em; border-radius: 18px; }
.btn.lg { font-size: 1.08rem; padding: 0.8em 1.6em; }
.btn.sm { font-size: 0.85rem; padding: 0.5em 0.8em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  color: var(--muted); transition: background 0.2s, color 0.2s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .off { display: none; }
body.muted .icon-btn .on { display: none; }
body.muted .icon-btn .off { display: inline; }

/* ============ Home ============ */
.home { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; padding: 0 20px calc(24px + env(safe-area-inset-bottom)); }
.home-top { width: 100%; max-width: 1080px; display: flex; justify-content: space-between; align-items: center; padding: calc(16px + env(safe-area-inset-top)) 0 0; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 42px; height: 42px; filter: drop-shadow(0 6px 12px rgba(108, 92, 231, 0.35)); }
.wordmark { font-family: var(--display); font-weight: 700; font-size: 1.7rem; letter-spacing: -0.01em; }
.top-actions { display: flex; gap: 4px; }
.hero { text-align: center; margin: 4vh 0 3vh; animation: rise 0.6s var(--ease) both; }
.hero h1 { font-family: var(--display); font-size: clamp(2rem, 5.2vw, 3.6rem); line-height: 1.05; margin: 0 0 0.35em; letter-spacing: -0.015em; }
.hl { background: linear-gradient(120deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; position: relative; }
.hl::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -0.12em; height: 0.18em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 12' preserveAspectRatio='none'%3E%3Cpath d='M2 8q25-8 50-2t50 0t50-2t46 2' fill='none' stroke='%23ff7a8a' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E") center/100% 100% no-repeat;
}
.sub { color: var(--muted); font-size: 1.08rem; margin: 0; }
.home-grid { width: 100%; max-width: 1080px; display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 22px; align-items: start; }
.play-card { padding: 24px; display: flex; flex-direction: column; gap: 14px; animation: rise 0.6s 0.08s var(--ease) both; }
.side-card { padding: 18px; min-height: 100%; animation: rise 0.6s 0.16s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.invite-banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--r-md); background: var(--ok-bg); color: var(--ok); font-weight: 500; }
.invite-banner svg { width: 20px; height: 20px; }

.avatar-editor { position: relative; display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; padding: 10px; border-radius: var(--r-lg); background: var(--surface-2); }
.av-col { display: grid; gap: 6px; }
.av-arrow { width: 36px; height: 36px; border-radius: 10px; font-size: 1.5rem; line-height: 1; color: var(--muted); background: var(--surface-solid); box-shadow: var(--shadow); transition: transform 0.15s var(--spring), color 0.2s; }
.av-arrow:hover { color: var(--primary); transform: scale(1.08); }
.av-stage { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.av-preview svg { width: 120px; height: 120px; display: block; }
.av-preview.bump svg { animation: bump 0.35s var(--spring); }
@keyframes bump { 40% { transform: scale(1.1) rotate(-4deg); } }
.av-swatches { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; max-width: 200px; }
.av-swatches button { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; box-shadow: 0 0 0 1px var(--border); transition: transform 0.15s var(--spring); }
.av-swatches button[aria-pressed='true'] { border-color: var(--surface-solid); box-shadow: 0 0 0 2px var(--text); transform: scale(1.15); }
.av-random { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 10px; color: var(--muted); display: grid; place-items: center; }
.av-random:hover { color: var(--primary); background: var(--surface-solid); }
.av-random svg { width: 20px; height: 20px; }
.av-random.spin svg { animation: spin 0.5s var(--ease); }
@keyframes spin { to { transform: rotate(360deg); } }

.field input, .join-form input {
  width: 100%; padding: 0.85em 1em; border-radius: var(--r-md); border: 1.5px solid var(--border);
  background: var(--surface-solid); font-size: 1.05rem; font-weight: 500; transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus, .join-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.join-form { display: flex; gap: 6px; }
.join-form input { text-transform: uppercase; letter-spacing: 0.15em; font-weight: 700; text-align: center; padding: 0.6em 0.4em; font-size: 1rem; min-width: 0; }
.btn svg { width: 1.15em; height: 1.15em; }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: var(--r-md); background: var(--surface-2); margin-bottom: 14px; }
.tab { flex: 1; padding: 0.55em 0.6em; border-radius: 10px; font-weight: 600; font-size: 0.92rem; color: var(--muted); transition: background 0.2s, color 0.2s; }
.tab.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.how { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.how li { display: flex; gap: 14px; align-items: flex-start; padding: 12px; border-radius: var(--r-md); background: var(--surface-2); }
.how-ico { font-size: 1.6rem; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-solid); flex: none; }
.how b { font-family: var(--display); font-size: 1.1rem; font-weight: 600; }
.how p { margin: 2px 0 0; color: var(--muted); font-size: 0.93rem; line-height: 1.45; }
.list { display: grid; gap: 8px; margin-bottom: 10px; }
.list .row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2); }
.list .row .grow { flex: 1; min-width: 0; }
.list .row .title { font-weight: 600; }
.list .row .meta { color: var(--muted); font-size: 0.85rem; }
.list .rank { font-family: var(--display); font-weight: 700; width: 28px; text-align: center; color: var(--muted); }
.list .rank.r1 { color: var(--gold); }
.list .empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.code-chip { font-family: var(--display); font-weight: 700; letter-spacing: 0.1em; padding: 4px 10px; border-radius: 8px; background: var(--surface-solid); }
.home-foot { margin-top: auto; padding-top: 28px; color: var(--muted); font-size: 0.85rem; }

/* ============ Room ============ */
.room { position: fixed; inset: 0; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: calc(var(--topbar) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 14px 0; flex: none;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 8px; }
.tb-right { justify-content: flex-end; }
.round-pill { font-family: var(--display); font-weight: 600; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); white-space: nowrap; font-size: 0.95rem; }
.round-pill:empty { display: none; }
.tb-center { text-align: center; min-width: 0; }
.status-text { font-family: var(--display); font-weight: 600; font-size: 1.15rem; color: var(--muted); }
.word-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); font-weight: 700; }
.word-big { font-family: var(--display); font-weight: 700; font-size: clamp(1.25rem, 2.6vw, 1.8rem); letter-spacing: 0.04em; color: var(--primary); line-height: 1.1; }
[data-theme='dark'] .word-big { color: #c4b9ff; }
.word-big.ok { color: var(--ok); }
.blanks { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 5px 6px; align-items: flex-end; }
.blank { width: 0.95em; font-family: var(--display); font-weight: 700; font-size: clamp(1.3rem, 2.6vw, 1.75rem); text-align: center; border-bottom: 3px solid currentColor; line-height: 1.15; color: var(--text); }
.blank.sp { border: 0; width: 0.6em; }
.blank.sym { border: 0; }
.blank.rev { color: var(--primary); animation: pop 0.5s var(--spring); }
.blanks sup { font-size: 0.85rem; color: var(--muted); font-weight: 700; margin-left: 6px; align-self: flex-start; }
@keyframes pop { 0% { transform: scale(0.3); opacity: 0; } 100% { transform: none; opacity: 1; } }

.timer { position: relative; width: 46px; height: 46px; display: grid; place-items: center; }
.timer svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 4; }
.timer .track { stroke: var(--border); }
.timer .prog { stroke: var(--primary); stroke-linecap: round; stroke-dasharray: 119.4; transition: stroke 0.3s; }
.timer.low .prog { stroke: var(--warn); }
.timer.low #timer-num { color: var(--warn); animation: beat 1s infinite; }
#timer-num { font-family: var(--display); font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.18); } }

.conn-banner { position: fixed; top: calc(var(--topbar) + env(safe-area-inset-top) + 6px); left: 50%; transform: translateX(-50%); z-index: 50; padding: 8px 16px; border-radius: 999px; background: var(--warn); color: #fff; font-weight: 600; font-size: 0.9rem; box-shadow: var(--shadow); }

.room-grid {
  flex: 1; min-height: 0; display: grid; gap: 14px;
  grid-template-columns: 250px minmax(0, 1fr) 310px;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
}
.panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; font-family: var(--display); font-weight: 600; font-size: 1.05rem; }
.panel-head .count { color: var(--muted); font-size: 0.9rem; }
.mobile-tabs { display: none; }

/* players */
.players { list-style: none; margin: 0; padding: 4px 8px 10px; overflow-y: auto; display: grid; gap: 6px; align-content: start; }
.player {
  position: relative; display: grid; grid-template-columns: 22px 44px 1fr auto; align-items: center; gap: 8px;
  padding: 7px 10px 7px 6px; border-radius: var(--r-md); transition: background 0.3s, transform 0.3s var(--spring); cursor: default;
}
.player:hover { background: var(--surface-2); }
.player.me .p-name::after { content: ' (you)'; color: var(--muted); font-weight: 500; }
.player.guessed { background: var(--ok-bg); }
.player.drawing { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.player.off { opacity: 0.45; }
.player.flash { animation: flash 0.8s var(--ease); }
@keyframes flash { 30% { transform: scale(1.04); box-shadow: 0 0 0 3px var(--ok); } }
.p-rank { font-family: var(--display); font-weight: 700; color: var(--muted); text-align: center; font-size: 0.95rem; }
.p-av { position: relative; width: 44px; height: 44px; }
.p-av svg.avatar { width: 44px; height: 44px; }
.p-badge { position: absolute; right: -4px; bottom: -2px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-solid); box-shadow: var(--shadow); color: var(--primary); }
.p-badge svg { width: 12px; height: 12px; }
.p-crown { position: absolute; left: -4px; top: -6px; color: var(--gold); width: 18px; height: 18px; transform: rotate(-18deg); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25)); }
.p-main { min-width: 0; }
.p-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.95rem; }
.p-score { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 0.82rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.p-gain { font-family: var(--display); font-weight: 700; color: var(--ok); font-size: 0.95rem; }
.p-votes { font-size: 0.72rem; color: var(--warn); font-weight: 700; }
.p-more { opacity: 0; width: 26px; height: 26px; border-radius: 8px; color: var(--muted); font-weight: 700; letter-spacing: 1px; }
.player:hover .p-more, .p-more:focus-visible { opacity: 1; }
.p-more:hover { background: var(--surface-solid); }
@media (hover: none) { .p-more { opacity: 0.7; } }

.menu { position: fixed; z-index: 80; min-width: 170px; padding: 6px; border-radius: var(--r-md); background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: pop-in 0.16s var(--ease); }
.menu button { display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: 8px; font-weight: 500; }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--warn); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.95) translateY(-4px); } }

/* stage */
.stage { display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 0; min-width: 0; position: relative; }
.board-area { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.board {
  position: relative; aspect-ratio: 4 / 3;
  width: min(100%, calc((100dvh - var(--topbar) - 120px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 4 / 3));
  border-radius: var(--r-lg); overflow: hidden; background: #fff;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.board.can-draw { cursor: none; }
.board.can-draw.tool-fill { cursor: crosshair; }
.board.can-draw.tool-shape { cursor: crosshair; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 14px; overflow-y: auto;
  padding: 24px; text-align: center; color: #fff;
  background: radial-gradient(ellipse at center, rgba(40, 24, 110, 0.82), rgba(18, 10, 50, 0.9));
  backdrop-filter: blur(3px); animation: fade 0.3s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.overlay > * { flex: none; }
.ov-title { font-family: var(--display); font-weight: 700; font-size: clamp(1.3rem, 3vw, 2rem); margin: 0; }
.ov-sub { opacity: 0.8; margin: 0; font-size: 0.98rem; }
.ov-word { font-family: var(--display); font-weight: 700; font-size: clamp(1.8rem, 5vw, 3rem); color: #ffe66d; animation: pop 0.6s var(--spring); text-shadow: 0 4px 20px rgba(255, 230, 109, 0.35); }
.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.choice {
  font-family: var(--display); font-weight: 600; font-size: clamp(1.05rem, 2vw, 1.35rem); color: #2b2350;
  padding: 0.7em 1.2em; border-radius: 16px; background: #fff; box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.6);
  transition: transform 0.2s var(--spring), box-shadow 0.2s; animation: pop 0.45s var(--spring) both;
}
.choice:nth-child(2) { animation-delay: 0.06s; }
.choice:nth-child(3) { animation-delay: 0.12s; }
.choice:nth-child(4) { animation-delay: 0.18s; }
.choice:nth-child(5) { animation-delay: 0.24s; }
.choice:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 16px 30px -12px rgba(0, 0, 0, 0.7); }
.choice small { display: block; font-family: var(--font); font-size: 0.7rem; color: #8a84b5; font-weight: 600; letter-spacing: 0.06em; }
.chooser svg.avatar { width: 96px; height: 96px; animation: wobble 1.6s ease-in-out infinite; }
@keyframes wobble { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg) translateY(-4px); } }
.dots::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.gains { display: grid; gap: 6px; width: min(340px, 100%); max-height: 45%; overflow: auto; }
.gain { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.1); animation: rise 0.4s var(--ease) both; }
.gain svg.avatar { width: 30px; height: 30px; }
.gain .n { flex: 1; text-align: left; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gain .v { font-family: var(--display); font-weight: 700; color: #7dffa8; }
.gain .v.zero { color: rgba(255, 255, 255, 0.45); }
.ov-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.ov-actions .btn { background: rgba(255, 255, 255, 0.14); color: #fff; }
.ov-actions .btn:hover { background: rgba(255, 255, 255, 0.24); }
.ov-actions .btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }

.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; width: clamp(80px, 13vw, 130px); animation: rise 0.6s var(--spring) both; }
.pod svg.avatar { width: clamp(48px, 7vw, 76px); height: clamp(48px, 7vw, 76px); }
.pod .nm { font-weight: 700; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.92rem; }
.pod .sc { font-size: 0.8rem; opacity: 0.8; }
.pod .step { width: 100%; border-radius: 12px 12px 0 0; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 1.6rem; color: rgba(255, 255, 255, 0.95); }
.pod.p1 { animation-delay: 0.3s; } .pod.p1 .step { height: clamp(60px, 11vh, 110px); background: linear-gradient(180deg, #ffd34d, #f5a300); }
.pod.p2 { animation-delay: 0.15s; } .pod.p2 .step { height: clamp(42px, 8vh, 80px); background: linear-gradient(180deg, #dfe6f2, #a7b4c8); }
.pod.p3 .step { height: clamp(30px, 6vh, 60px); background: linear-gradient(180deg, #ffb27d, #d9773b); }
.gallery { display: flex; gap: 8px; overflow-x: auto; max-width: 100%; padding: 4px; }
.gallery figure { margin: 0; flex: none; width: 120px; }
.gallery img { width: 120px; aspect-ratio: 4/3; border-radius: 8px; display: block; background: #fff; cursor: pointer; transition: transform 0.2s var(--spring); }
.gallery img:hover { transform: scale(1.05); }
.gallery figcaption { font-size: 0.72rem; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reactions { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.reaction { position: absolute; bottom: 10px; font-size: 2rem; animation: drift 2.2s var(--ease) forwards; }
@keyframes drift { 0% { transform: translateY(0) scale(0.4); opacity: 0; } 15% { opacity: 1; transform: translateY(-20px) scale(1.1); } 100% { transform: translateY(-260px) scale(1); opacity: 0; } }
.react-bar { display: flex; gap: 8px; }
.react-btn { font-size: 1.35rem; width: 50px; height: 42px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); transition: transform 0.2s var(--spring); }
.react-btn:hover { transform: scale(1.12); }
.react-btn:disabled { opacity: 0.4; transform: none; }

/* toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 14px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow);
  backdrop-filter: blur(18px); max-width: 100%; animation: rise 0.35s var(--ease);
}
.tool-group { display: flex; align-items: center; gap: 4px; }
.tool { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: var(--muted); transition: background 0.15s, color 0.15s, transform 0.15s var(--spring); }
.tool svg { width: 21px; height: 21px; }
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.active { background: var(--primary); color: #fff; box-shadow: 0 6px 14px -6px var(--primary); }
.tool.danger:hover { color: var(--warn); }
.tool:disabled { opacity: 0.35; }
.size { width: 34px; height: 38px; border-radius: 10px; display: grid; place-items: center; }
.size i { display: block; border-radius: 50%; background: var(--text); }
.size:hover { background: var(--surface-2); }
.size.active { background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--primary); }
.palette { display: grid; grid-template-columns: repeat(12, 22px); grid-auto-rows: 22px; gap: 3px; }
.swatch { width: 22px; height: 22px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); transition: transform 0.12s var(--spring); }
.swatch:hover { transform: scale(1.18); z-index: 1; }
.swatch.active { box-shadow: 0 0 0 2px var(--surface-solid), 0 0 0 4px var(--primary); transform: scale(1.08); z-index: 2; }
.swatch.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); position: relative; overflow: hidden; }
.swatch.custom input { position: absolute; inset: -4px; opacity: 0; cursor: pointer; width: 30px; height: 30px; }

/* lobby */
.lobby {
  width: 100%; max-width: 760px; margin: auto; overflow-y: auto; padding: 22px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow);
  backdrop-filter: blur(18px); display: flex; flex-direction: column; gap: 18px; animation: rise 0.4s var(--ease);
}
.lobby-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.eyebrow { font-size: 0.75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; }
.room-code { font-family: var(--display); font-weight: 700; font-size: 2.4rem; letter-spacing: 0.16em; line-height: 1.1; background: linear-gradient(120deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.invite-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.settings label, .seg-field { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.settings .wide, .seg-field { grid-column: 1 / -1; }
.settings small { font-weight: 500; }
.settings select, .settings textarea {
  padding: 0.6em 0.75em; border-radius: var(--r-sm); border: 1.5px solid var(--border); background: var(--surface-solid);
  font-size: 0.95rem; font-weight: 600; color: var(--text); resize: vertical;
}
.settings select:focus, .settings textarea:focus { outline: none; border-color: var(--primary); }
.settings :disabled { opacity: 0.75; cursor: not-allowed; }
.seg { display: flex; padding: 4px; gap: 4px; border-radius: var(--r-md); background: var(--surface-2); }
.seg button { flex: 1; padding: 0.5em; border-radius: 10px; font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.seg button.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.seg button:disabled { cursor: not-allowed; }
.switch { display: flex; position: relative; font-weight: 600; flex-direction: row !important; align-items: center; gap: 10px !important; cursor: pointer; color: var(--text) !important; font-size: 0.92rem !important; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.knob { width: 42px; height: 24px; border-radius: 999px; background: var(--border); position: relative; transition: background 0.2s; flex: none; }
.knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--spring); }
.switch input:checked + .knob { background: var(--primary); }
.switch input:checked + .knob::after { transform: translateX(18px); }
.switch input:focus-visible + .knob { outline: 3px solid color-mix(in srgb, var(--primary) 60%, transparent); }
.switch input:disabled + .knob { opacity: 0.6; }
.lobby-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 16px; }
.lobby-status { flex: 1; color: var(--muted); font-weight: 500; min-width: 160px; }
.bot-toggle { margin-right: auto; }

/* chat */
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 8px; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.msg { padding: 5px 9px; border-radius: 10px; line-height: 1.4; font-size: 0.93rem; overflow-wrap: anywhere; animation: msg-in 0.25s var(--ease); }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.msg b { font-weight: 650; }
.msg.sys { color: var(--muted); font-weight: 600; font-size: 0.86rem; }
.msg.ok { color: var(--ok); background: var(--ok-bg); font-weight: 650; }
.msg.warn { color: var(--warn); font-weight: 600; font-size: 0.86rem; }
.msg.info { color: var(--info); font-weight: 600; font-size: 0.86rem; }
.msg.close { color: var(--close); background: var(--close-bg); font-weight: 600; }
.msg.g { background: var(--ok-bg); }
.msg.g b { color: var(--ok); }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; min-width: 0; padding: 0.75em 1em; border-radius: var(--r-md); border: 1.5px solid var(--border); background: var(--surface-solid); font-size: 1rem; }
.chat-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent); }
.chat-form input.shake { animation: shake 0.35s; border-color: var(--warn); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.send { width: 46px; border-radius: var(--r-md); background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; display: grid; place-items: center; }
.send svg { width: 20px; height: 20px; }

/* toasts */
.toasts { position: fixed; z-index: 90; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { padding: 10px 18px; border-radius: 999px; background: var(--surface-solid); color: var(--text); font-weight: 600; box-shadow: var(--shadow-lg); border: 1px solid var(--border); animation: toast-in 0.35s var(--spring); }
.toast.ok { background: var(--ok); color: #fff; border: 0; }
.toast.err { background: var(--warn); color: #fff; border: 0; }
.toast.out { animation: toast-out 0.3s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.9); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; }

/* ============ Responsive ============ */
@media (max-width: 1180px) {
  .room-grid { grid-template-columns: 210px minmax(0, 1fr) 270px; gap: 10px; padding-inline: 10px; }
  .palette { grid-template-columns: repeat(12, 20px); grid-auto-rows: 20px; }
  .swatch { width: 20px; height: 20px; }
}
@media (max-width: 900px) {
  :root { --topbar: 56px; }
  .home-grid { grid-template-columns: 1fr; }
  .hero { margin: 3vh 0 2vh; }
  .hide-sm { display: none !important; }
  .topbar { padding-inline: 8px; gap: 6px; grid-template-columns: auto 1fr auto; }
  .round-pill { font-size: 0.8rem; padding: 4px 9px; }
  .room-grid {
    grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0, 1fr); gap: 8px; padding: 0 8px calc(8px + env(safe-area-inset-bottom));
  }
  .stage { grid-row: 1; gap: 8px; }
  .board-area { flex: none; }
  .board { width: min(100%, calc((100dvh - var(--topbar) - 300px) * 4 / 3)); min-width: min(100%, 300px); border-radius: 16px; }
  .mobile-tabs { grid-row: 2; display: flex; gap: 4px; padding: 4px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); }
  .mobile-tabs button { flex: 1; padding: 7px; border-radius: 10px; font-weight: 600; color: var(--muted); font-size: 0.9rem; display: flex; align-items: center; justify-content: center; gap: 6px; }
  .mobile-tabs button.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
  .badge { min-width: 18px; height: 18px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 0.7rem; display: inline-grid; place-items: center; padding: 0 5px; }
  .players-panel, .chat-panel { grid-row: 3; border-radius: 16px; }
  .room-grid[data-mtab='chat'] .players-panel { display: none; }
  .room-grid[data-mtab='players'] .chat-panel { display: none; }
  .panel-head { display: none; }
  .players { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); padding: 8px; }
  .toolbar { gap: 6px; padding: 6px 8px; border-radius: 16px; }
  .tool { width: 34px; height: 34px; }
  .tool svg { width: 19px; height: 19px; }
  .size { width: 28px; height: 34px; }
  .palette { grid-template-columns: repeat(12, minmax(0, 22px)); grid-auto-rows: 20px; gap: 3px; width: 100%; justify-content: center; order: 5; }
  .swatch { width: 100%; height: 20px; }
  .lobby { padding: 16px; gap: 14px; max-height: none; }
  .room[data-phase='lobby'] .room-grid { grid-template-rows: auto auto minmax(220px, 1fr); overflow-y: auto; }
  .room-code { font-size: 1.9rem; }
  .settings { grid-template-columns: repeat(2, 1fr); }
  .overlay { padding: 12px; gap: 10px; }
  .gains { max-height: 40%; }
  .gallery figure, .gallery img { width: 90px; }
  .react-bar { position: absolute; right: 6px; top: 6px; flex-direction: column; z-index: 3; }
  .react-btn { width: 40px; height: 36px; font-size: 1.1rem; background: var(--surface-solid); }
}
@media (max-width: 420px) {
  .row-2 { grid-template-columns: 1fr; }
  .blank { font-size: 1.15rem; width: 0.85em; }
  .word-big { font-size: 1.1rem; }
  .status-text { font-size: 0.95rem; }
  .timer { width: 40px; height: 40px; }
  .icon-btn { width: 34px; height: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ============ Backup-domain redirect gate ============ */
.gate { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; background: rgba(18, 12, 48, 0.55); backdrop-filter: blur(8px); animation: fade 0.25s var(--ease); }
.gate-card { width: min(420px, 100%); padding: 28px 24px; text-align: center; display: grid; gap: 14px; justify-items: center; background: var(--surface-solid); animation: pop-in 0.3s var(--spring); }
.gate-ring { position: relative; width: 72px; height: 72px; display: grid; place-items: center; }
.gate-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.gate-ring circle { fill: none; stroke-width: 4; }
.gate-ring .track { stroke: var(--border); }
.gate-ring .prog { stroke: var(--primary); stroke-linecap: round; stroke-dasharray: 119.4; }
.gate-ring.stopped { display: none; }
.gate-num { font-family: var(--display); font-weight: 700; font-size: 1.6rem; }
.gate-title { font-family: var(--display); font-size: 1.35rem; line-height: 1.25; margin: 0; }
.gate-sub { color: var(--muted); margin: 0; font-size: 0.95rem; }
.gate-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.gate-form { display: grid; gap: 10px; width: 100%; }
.gate-form input { padding: 0.8em 1em; border-radius: var(--r-md); border: 1.5px solid var(--border); background: var(--surface-solid); font-size: 1rem; text-align: center; }
.gate-form input:focus { outline: none; border-color: var(--primary); }
.gate-form input.shake { animation: shake 0.35s; border-color: var(--warn); }
.gate-err { color: var(--warn); font-weight: 600; font-size: 0.9rem; }
