/* Layout: toybox lobby (stacked sections, sticker tiles) + one-screen game stage that fits the viewport.
   Sticker style: ink outlines, hard offset shadows that press in on tap. */
:root {
  --bg: #e9eef6; --surface: #ffffff; --surface-2: #f3f6fb; --ink: #141829; --ink-soft: #586079; --line: #141829; --shade: #141829;
  --pop: #ff5470; --cobalt: #3b6cff; --butter: #ffc93c; --mint: #1fbf8f; --grape: #8b5cf6; --clay: #e07a3f;
  --good: #14a271; --bad: #e23d5b;
  --display: 'Bricolage Grotesque', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
  --body: 'Onest', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --r: 18px; --r-sm: 12px; --bw: 2.5px; --lift: 4px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #10132a; --surface: #1b1f3d; --surface-2: #232849; --ink: #eef1fb; --ink-soft: #a2a9cc; --line: #050716; --shade: #050716;
  --pop: #ff6a83; --cobalt: #5b84ff; --butter: #ffd25c; --mint: #2fd3a2; --grape: #9d74ff; --clay: #ef8c52; color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #10132a; --surface: #1b1f3d; --surface-2: #232849; --ink: #eef1fb; --ink-soft: #a2a9cc; --line: #050716; --shade: #050716;
  --pop: #ff6a83; --cobalt: #5b84ff; --butter: #ffd25c; --mint: #2fd3a2; --grape: #9d74ff; --clay: #ef8c52; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { background: var(--bg); color: var(--ink); }
body { font: 15px/1.5 var(--body); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 3px; }
h1, h2, h3 { font-family: var(--display); line-height: 1.05; margin: 0; text-wrap: balance; letter-spacing: -0.02em; }
p { margin: 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.tone-mint { --tone: var(--mint); } .tone-cobalt { --tone: var(--cobalt); } .tone-pop { --tone: var(--pop); }
.tone-butter { --tone: var(--butter); } .tone-grape { --tone: var(--grape); } .tone-clay { --tone: var(--clay); }

/* ---------- buttons ---------- */
.btn {
  border: var(--bw) solid var(--line); background: var(--surface); border-radius: var(--r-sm);
  padding: 10px 16px; font-weight: 700; box-shadow: 0 var(--lift) 0 var(--shade);
  transition: transform .08s ease, box-shadow .08s ease; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 calc(var(--lift) + 1px) 0 var(--shade); }
.btn:active { transform: translateY(var(--lift)); box-shadow: 0 0 0 var(--shade); }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: 0 var(--lift) 0 var(--shade); }
.btn.primary { background: var(--pop); color: #fff; }
.btn.big { padding: 14px 20px; font-size: 16px; width: 100%; }
.btn.small { padding: 6px 12px; font-size: 13px; --lift: 3px; }
.btn.ghost { border-color: transparent; box-shadow: none; background: transparent; color: var(--ink-soft); }
.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 12px; border: var(--bw) solid var(--line); background: var(--surface);
  font-size: 18px; font-weight: 800; display: grid; place-items: center; box-shadow: 0 3px 0 var(--shade);
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }
.tag { font: 700 11px/1 var(--body); text-transform: uppercase; letter-spacing: .08em; padding: 5px 8px; border-radius: 999px; background: var(--surface-2); border: 2px solid var(--line); white-space: nowrap; }
.code-input {
  font: 700 18px var(--mono); letter-spacing: .2em; text-transform: uppercase; width: 9.5ch; min-width: 0;
  padding: 9px 12px; border: var(--bw) solid var(--line); border-radius: var(--r-sm); background: var(--surface);
}
.code-row { display: flex; gap: 8px; align-items: center; }

/* ---------- lobby ---------- */
.lobby { max-width: 1120px; margin: 0 auto; padding-block: 12px 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 34px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font: 800 26px var(--display); letter-spacing: -0.03em; }
.brand svg { width: 40px; height: 40px; animation: bob 3.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px) rotate(-4deg); } }
.top-right { display: flex; gap: 10px; align-items: center; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.intro h1 { font-size: clamp(40px, 7vw, 76px); font-weight: 800; letter-spacing: -0.045em; }
.intro h1 em { font-style: normal; color: var(--pop); -webkit-text-stroke: 0; }
.join-box { background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r); padding: 10px 10px 10px 16px; box-shadow: 0 var(--lift) 0 var(--shade); }
.join-box label { font-weight: 700; white-space: nowrap; }
.section-title { font-size: 22px; font-weight: 800; margin-bottom: 14px; display: flex; align-items: baseline; gap: 4px; }
.section-title .n { color: var(--ink-soft); font-size: 16px; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.tile {
  text-align: left; padding: 0; overflow: hidden; border: var(--bw) solid var(--line); border-radius: var(--r);
  background: var(--surface); box-shadow: 0 6px 0 var(--shade); transition: transform .12s ease, box-shadow .12s ease; display: flex; flex-direction: column;
}
.tile:hover { transform: translateY(-3px) rotate(-.4deg); box-shadow: 0 9px 0 var(--shade); }
.tile:active { transform: translateY(6px); box-shadow: 0 0 0 var(--shade); }
.tile-art { background: var(--tone); border-bottom: var(--bw) solid var(--line); aspect-ratio: 16 / 9; display: grid; place-items: center; padding: 14px; position: relative; overflow: hidden; }
.tile-art::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 20% 15%, #ffffff55, transparent 45%); }
.tile-art svg { width: 82%; height: 100%; position: relative; transition: transform .25s cubic-bezier(.3, 1.6, .5, 1); }
.tile:hover .tile-art svg { transform: scale(1.06) rotate(1.5deg); }
.tile-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.tile-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.tile h3 { font-size: 21px; font-weight: 800; }
.tile p { color: var(--ink-soft); font-size: 14px; }

.here-list, .match-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.here-card, .match-card {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: var(--bw) solid var(--line); border-radius: var(--r);
  background: var(--surface); box-shadow: 0 var(--lift) 0 var(--shade); text-align: left; min-width: 0;
}
.match-card:active { transform: translateY(var(--lift)); box-shadow: none; }
.match-card.hot { background: color-mix(in srgb, var(--butter) 35%, var(--surface)); }
.here-text, .match-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.here-text b, .match-text b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.here-text small, .match-text small { color: var(--ink-soft); font-size: 12.5px; }
.mini-art { width: 54px; height: 38px; flex: none; display: block; }
.mini-art svg { width: 100%; height: 100%; }
.empty { max-width: 60ch; }
.avatar { display: inline-grid; place-items: center; border-radius: 50%; border: 2px solid var(--line); color: #fff; font-weight: 800; font-size: 13px; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--ink-soft); font-size: 12.5px; border-top: 2px dashed color-mix(in srgb, var(--ink-soft) 40%, transparent); padding-top: 16px; }

/* ---------- modal + toast ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--shade) 55%, transparent); display: grid; place-items: center; padding: 16px; animation: fade .15s ease; }
.modal.out { opacity: 0; transition: opacity .2s; }
.modal-card { width: min(460px, 100%); max-height: 90%; overflow: auto; background: var(--surface); border: var(--bw) solid var(--line); border-radius: 22px; padding: 22px; box-shadow: 0 8px 0 var(--shade); display: flex; flex-direction: column; gap: 14px; animation: pop .22s cubic-bezier(.3, 1.5, .5, 1); }
.modal-card h2 { font-size: 26px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.pick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: var(--bw) solid var(--line); border-radius: var(--r-sm); background: color-mix(in srgb, var(--tone) 22%, var(--surface)); box-shadow: 0 3px 0 var(--shade); text-align: left; font-size: 14px; }
.pick:active { transform: translateY(3px); box-shadow: none; }
#toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(440px, calc(100% - 32px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); border-radius: 14px; padding: 10px 14px; font-weight: 600; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; box-shadow: 0 6px 20px #0004; animation: rise .25s cubic-bezier(.3, 1.4, .5, 1); max-width: 100%; }
.toast.out { opacity: 0; transform: translateY(8px); transition: .25s; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.invite { background: var(--surface); color: var(--ink); border: var(--bw) solid var(--line); box-shadow: 0 6px 0 var(--shade); }
.toast-actions { display: flex; gap: 8px; }
.toast .btn { color: var(--ink); }
.toast .btn.primary { color: #fff; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }

/* ---------- game screen ---------- */
.game-screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg);
  padding-block: calc(8px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  gap: 10px;
}
.gbar { display: flex; align-items: center; gap: 8px; min-height: 44px; position: relative; }
.gtitle { display: flex; flex-direction: column; min-width: 0; margin-right: auto; line-height: 1.15; }
.gname { font: 800 19px var(--display); white-space: nowrap; }
.gstatus { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gplayers { display: flex; align-items: center; gap: 6px; min-width: 0; }
.vs { font: 800 11px var(--display); color: var(--ink-soft); }
.pchip { position: relative; display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 700; max-width: 150px; transition: background .2s, transform .2s; }
.pchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-soft); opacity: .35; flex: none; }
.pchip.online .dot, .pchip.you .dot { background: var(--good); opacity: 1; }
.pchip.turn { background: var(--butter); color: #141829; transform: translateY(-1px); box-shadow: 0 3px 0 var(--shade); }
.emote-bar { position: absolute; z-index: 20; top: calc(56px + env(safe-area-inset-top, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); display: flex; gap: 6px; background: var(--surface); border: var(--bw) solid var(--line); border-radius: 16px; padding: 6px; box-shadow: 0 5px 0 var(--shade); animation: pop .18s; }
.emote-bar button { border: 0; background: var(--surface-2); border-radius: 10px; width: 42px; height: 42px; font-size: 20px; font-weight: 800; }
.emote-pop { position: absolute; top: 110%; left: 50%; transform: translateX(-50%); background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 4px 10px; font-size: 22px; font-weight: 800; z-index: 30; animation: emote 2.2s ease forwards; pointer-events: none; white-space: nowrap; }
@keyframes emote { 0% { transform: translate(-50%, 6px) scale(.5); opacity: 0; } 12% { transform: translate(-50%, 0) scale(1.15); opacity: 1; } 20% { transform: translate(-50%, 0) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -8px); } }
.stage-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.stage { flex: 1; min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; position: relative; }
.overlay { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 8px; overflow: auto; background: color-mix(in srgb, var(--bg) 55%, transparent); backdrop-filter: blur(3px); animation: fade .2s; }
.card { background: var(--surface); border: var(--bw) solid var(--line); border-radius: 22px; padding: 22px; box-shadow: 0 8px 0 var(--shade); width: min(560px, 100%); display: flex; flex-direction: column; gap: 14px; animation: pop .25s cubic-bezier(.3, 1.5, .5, 1); }
.card.center { align-items: center; text-align: center; width: min(420px, 100%); }
.card h2 { font-size: 28px; font-weight: 800; }
.setup-head { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.setup-head .tag { background: var(--tone); color: #141829; }
.setup-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.setup-col { display: flex; flex-direction: column; gap: 10px; padding: 14px; border: 2px dashed color-mix(in srgb, var(--ink-soft) 55%, transparent); border-radius: 16px; min-width: 0; }
.setup-col h3 { font-size: 17px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: var(--bw) solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 9px 4px; font-weight: 700; font-size: 14px; }
.seg button + button { border-left: 2px solid var(--line); }
.seg button.on { background: var(--butter); color: #141829; }
.friend-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.friend { display: flex; align-items: center; gap: 8px; text-align: left; }
.friend > span:not(.avatar) { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); }
.code-big { font: 800 40px var(--mono); letter-spacing: .14em; padding: 6px 16px 6px 22px; border: var(--bw) dashed var(--line); border-radius: 14px; background: var(--surface-2); user-select: all; }
.pulse { width: 18px; height: 18px; border-radius: 50%; background: var(--good); animation: pulse 1.4s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); } 100% { box-shadow: 0 0 0 22px transparent; } }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--pop); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.countdown { font: 800 140px/1 var(--display); color: var(--pop); -webkit-text-stroke: 4px var(--line); animation: count .7s ease-out; }
@keyframes count { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } }
.result h2 { font-size: 40px; }
/* ---------- results with flair ---------- */
.fx-layer { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }
.overlay.result-bg.tone-win { background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--butter) 30%, transparent), color-mix(in srgb, var(--bg) 70%, transparent) 70%); }
.overlay.result-bg.tone-lose { background: color-mix(in srgb, #1b2238 45%, transparent); backdrop-filter: blur(4px) grayscale(.5); }
.result.fancy { gap: 10px; padding: 26px 22px 22px; margin-top: 52px; overflow: visible; position: relative; }
.result.fancy.win { animation: res-in .6s cubic-bezier(.2, 1.6, .4, 1) both; border-color: var(--line); box-shadow: 0 8px 0 var(--shade), 0 0 0 6px color-mix(in srgb, var(--butter) 55%, transparent), 0 24px 60px rgba(0,0,0,.25); }
.result.fancy.lose { animation: res-drop .7s cubic-bezier(.3, 1.3, .5, 1) both; }
.result.fancy.draw { animation: pop .35s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes res-in { 0% { transform: scale(.4) rotate(-8deg); opacity: 0; } 60% { transform: scale(1.06) rotate(1.5deg); opacity: 1; } 100% { transform: none; } }
@keyframes res-drop { 0% { transform: translateY(-60px); opacity: 0; } 55% { transform: translateY(6px); opacity: 1; } 70% { transform: translateY(0) rotate(-1.4deg); } 82% { transform: rotate(1deg); } 100% { transform: none; } }
.res-medal { position: relative; width: 104px; height: 104px; margin: -70px auto 0; display: grid; place-items: center; }
.res-emoji { position: relative; z-index: 1; width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; font-size: 50px; line-height: 1; background: var(--surface); border: var(--bw) solid var(--line); box-shadow: 0 5px 0 var(--shade); }
.win .res-emoji { background: radial-gradient(circle at 35% 30%, #fff6c9, var(--butter)); animation: res-bounce .9s .25s cubic-bezier(.3, 1.8, .5, 1) both, res-float 2.6s 1.2s ease-in-out infinite; }
.lose .res-emoji { background: var(--surface-2); animation: res-sag 1s .3s ease both; }
.draw .res-emoji { background: conic-gradient(var(--surface-2) 50%, var(--butter) 0); }
.res-rays { position: absolute; inset: -46px; border-radius: 50%; background: repeating-conic-gradient(color-mix(in srgb, var(--butter) 75%, transparent) 0 9deg, transparent 9deg 22.5deg); mask: radial-gradient(circle, #000 30%, transparent 70%); -webkit-mask: radial-gradient(circle, #000 30%, transparent 70%); animation: spin 9s linear infinite, fade .8s; }
.lose .res-rays, .draw .res-rays { display: none; }
@keyframes res-bounce { 0% { transform: scale(0) rotate(-30deg); } 100% { transform: none; } }
@keyframes res-float { 50% { transform: translateY(-5px) rotate(4deg); } }
@keyframes res-sag { 0% { transform: translateY(-14px); } 40% { transform: translateY(4px) rotate(-6deg); } 70% { transform: rotate(3deg); } 100% { transform: none; } }
.res-title { font-size: clamp(34px, 9vw, 46px) !important; line-height: 1.05; letter-spacing: -.5px; margin-top: 4px; }
.res-title span { display: inline-block; }
.win .res-title span { color: var(--good); animation: res-letter .55s calc(.35s + var(--i) * 45ms) cubic-bezier(.2, 1.9, .4, 1) both, res-wave 2.4s calc(1.4s + var(--i) * 80ms) ease-in-out infinite; text-shadow: 0 3px 0 color-mix(in srgb, var(--good) 25%, transparent); }
.lose .res-title span { color: var(--bad); animation: res-fall .5s calc(.3s + var(--i) * 35ms) ease-out both; }
.draw .res-title span { animation: res-letter .45s calc(.2s + var(--i) * 40ms) ease-out both; }
@keyframes res-letter { 0% { transform: translateY(30px) scale(.3); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes res-wave { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-6px); } }
@keyframes res-fall { 0% { transform: translateY(-24px) rotate(-12deg); opacity: 0; } 70% { transform: translateY(3px); opacity: 1; } 100% { transform: none; } }
.res-quote { font-size: 17px; font-weight: 700; margin: 0; max-width: 32ch; animation: fade .5s .7s both; }
.res-sub { margin: 0; font-size: 14px; animation: fade .5s .85s both; }
.res-badge { font-weight: 800; font-size: 14px; padding: 6px 14px; border-radius: 999px; border: 2px solid var(--line); background: var(--butter); color: #141829; box-shadow: 0 3px 0 var(--shade); animation: res-bounce .5s 1s cubic-bezier(.3, 1.8, .5, 1) both; }
.lose .res-badge { background: var(--surface-2); color: var(--ink); }
.res-actions { margin-top: 6px; animation: fade .4s 1s both; }
@media (prefers-reduced-motion: reduce) { .result.fancy *, .result.fancy { animation: none !important; } }
.result.win h2 { color: var(--good); }
.result.lose h2 { color: var(--bad); }
.result-burst { width: 64px; height: 64px; border-radius: 50%; border: var(--bw) solid var(--line); background: conic-gradient(var(--pop), var(--butter), var(--mint), var(--cobalt), var(--grape), var(--pop)); animation: spin 4s linear infinite, pop .4s cubic-bezier(.3, 1.8, .5, 1); }
.result.lose .result-burst { background: var(--surface-2); animation: pop .4s; }
.result.draw .result-burst { background: conic-gradient(var(--surface-2) 50%, var(--butter) 0); }

/* shared canvas-game frame */
.board-canvas { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.game-hud { position: absolute; left: 50%; transform: translateX(-50%); top: 6px; display: flex; gap: 8px; align-items: center; pointer-events: none; z-index: 2; }
.score-pill { font: 800 18px var(--display); background: var(--surface); border: 2px solid var(--line); border-radius: 999px; padding: 4px 14px; box-shadow: 0 3px 0 var(--shade); font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .tile-body { padding: 10px 12px 12px; }
  .tile h3 { font-size: 17px; }
  .tile p { font-size: 12.5px; }
  .tile .tag { display: none; }
  .setup-cols { grid-template-columns: 1fr; }
  .pchip { max-width: 104px; padding-right: 8px; }
  .gplayers .vs { display: none; }
  .gname { font-size: 16px; }
  .card { padding: 16px; }
  .card h2 { font-size: 23px; }
}
@media (max-width: 460px) {
  .lobby { gap: 26px; }
  .join-box { width: 100%; }
  .join-box .code-input { flex: 1; width: auto; }
  .pchip:not(.you) span { max-width: 60px; }
  .pchip.you span { display: none; }
  .pchip.you { padding-right: 3px; }
  .gbar { gap: 6px; }
  .icon-btn { width: 36px; height: 36px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }

/* ---------- invites (Vercel build) ---------- */
.hero-actions { display: flex; flex-direction: column; gap: 12px; align-items: stretch; min-width: min(100%, 380px); }
.invite-cta { position: relative; text-align: left; display: grid; gap: 2px; padding: 16px 56px 16px 18px; border: var(--bw) solid var(--line); border-radius: var(--r);
  background: var(--pop); color: #fff; box-shadow: 0 var(--lift) 0 var(--shade); transition: transform .08s, box-shadow .08s; }
.invite-cta b { font: 800 22px/1.1 var(--display); letter-spacing: -0.02em; }
.invite-cta small { font-size: 13px; opacity: .92; }
.invite-cta .arrow { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); font-size: 26px; font-weight: 800; }
.invite-cta:hover { transform: translateY(-1px); box-shadow: 0 calc(var(--lift) + 1px) 0 var(--shade); }
.invite-cta:active { transform: translateY(var(--lift)); box-shadow: none; }
.name-chip { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 5px; border: var(--bw) solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 700; font-size: 13px; box-shadow: 0 3px 0 var(--shade); max-width: 160px; }
.name-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-input { width: 100%; font: 700 20px var(--body); padding: 12px 14px; border: var(--bw) solid var(--line); border-radius: var(--r-sm); background: var(--surface); margin-top: 12px; }
.link-box { width: 100%; max-width: 420px; font: 600 13px var(--mono); padding: 10px 12px; border: 2px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink); text-align: center; }
.row.center { justify-content: center; }
a.btn { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
@media (max-width: 640px) { .hero-actions { width: 100%; } .top-right { gap: 6px; } .name-chip { max-width: 110px; } }
@media (max-width: 520px) {
  .gplayers .pchip.you, .gplayers .vs { display: none; }
  .gtitle { min-width: 0; overflow: hidden; flex: 1; }
  .gname, .gstatus { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ---------- site chrome: nav, footer, content pages ---------- */
.top-nav { display: flex; gap: 4px; margin-right: auto; margin-left: 18px; }
.top-nav a { padding: 8px 12px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--ink-soft); text-decoration: none; }
.top-nav a:hover { color: var(--ink); background: var(--surface); }
.top-nav a[aria-current="page"] { color: var(--ink); }
.site-foot { border-top: 2px solid color-mix(in srgb, var(--ink-soft) 25%, transparent); padding-top: 28px; margin-top: 10px; font-size: 14px; }
.foot-cols { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 24px; }
.foot-cols h4 { margin: 0 0 10px; font: 800 12px var(--body); text-transform: uppercase; letter-spacing: .1em; color: var(--ink-soft); }
.foot-cols a, .foot-link { display: block; color: var(--ink); text-decoration: none; padding: 3px 0; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.foot-cols a:hover, .foot-link:hover { color: var(--pop); }
.foot-brand p { margin-top: 8px; max-width: 260px; }
.brand.small { font-size: 20px; } .brand.small svg { width: 30px; height: 30px; }
.foot-bottom { display: flex; justify-content: space-between; gap: 12px; margin-top: 26px; padding: 14px 0 6px; border-top: 1px solid color-mix(in srgb, var(--ink-soft) 20%, transparent); color: var(--ink-soft); font-size: 12.5px; }
body.page { max-width: 1120px; margin: 0 auto; padding: 12px max(16px, env(safe-area-inset-left)) 40px; }
.page-top { margin-bottom: 18px; }
.doc { max-width: 720px; margin: 0 auto 50px; background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r); box-shadow: 0 var(--lift) 0 var(--shade); padding: clamp(22px, 5vw, 48px); line-height: 1.65; }
.doc h1 { font-size: clamp(32px, 5vw, 46px); margin-bottom: 12px; }
.doc h2 { font-size: 22px; margin: 30px 0 8px; }
.doc h3 { font-size: 17px; margin: 20px 0 4px; }
.doc p, .doc li { color: var(--ink); } .doc p + p { margin-top: 10px; }
.doc .lede { font-size: 18px; color: var(--ink-soft); }
.doc ul, .doc ol { padding-left: 22px; } .doc li { margin: 6px 0; }
.doc a { color: var(--cobalt); }
@media (max-width: 760px) {
  .top { flex-wrap: wrap; } .top-nav { order: 3; width: 100%; margin: 0; overflow-x: auto; } .top-nav a { padding: 6px 10px; white-space: nowrap; }
  .foot-cols { grid-template-columns: 1fr 1fr; } .foot-brand { grid-column: 1 / -1; }
}
.music-btn.off { opacity: .5; text-decoration: line-through; }
.icon-btn { font-size: 17px; }
.menu-list { display: grid; gap: 8px; margin-top: 14px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: var(--bw) solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); font-weight: 700; text-align: left; }
.switch { width: 46px; height: 26px; border-radius: 999px; background: #c5cad8; border: 2px solid var(--line); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2px solid var(--line); transition: transform .2s; }
.switch-row[aria-checked="true"] .switch { background: var(--mint); }
.switch-row[aria-checked="true"] .switch::after { transform: translateX(20px); }
@media (max-width: 560px) { .gbar .music-btn, .gbar .sfx-btn { display: none; } }
.np-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 4px 4px 14px; }
.np { font-weight: 700; font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.next-wrap { position: relative; display: inline-flex; }
.np-toast { position: absolute; top: calc(100% + 8px); right: 0; white-space: nowrap; background: #141829; color: #fff; font: 700 12px var(--body); padding: 6px 10px; border-radius: 999px; opacity: 0; pointer-events: none; transform: translateY(-4px); z-index: 20; }
.np-toast.show { animation: np-show 2.4s ease forwards; }
@keyframes np-show { 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-4px); } }
@media (max-width: 560px) { .gbar .next-wrap { display: none; } }
/* ---------- quick chat ---------- */
.chat-wrap { position: relative; display: inline-flex; }
.chat-btn.on { background: var(--butter); }
.chat-panel { position: fixed; right: 12px; top: 0; bottom: 0; margin: auto 0; height: fit-content; max-height: calc(100dvh - 140px); overflow-y: auto; overflow-x: hidden; z-index: 40; width: min(320px, calc(100vw - 24px)); background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r); box-shadow: 0 6px 0 var(--shade), 0 18px 40px rgba(0,0,0,.2); padding: 12px; display: grid; gap: 10px; animation: chat-in .18s ease-out; }
@keyframes chat-in { from { opacity: 0; translate: 24px 0; } to { opacity: 1; translate: 0 0; } }
.chat-head { display: flex; justify-content: space-between; align-items: center; }
.chat-x { border: 0; background: none; font-size: 22px; line-height: 1; padding: 0 4px; color: var(--ink-soft); }
.chat-emoji { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.chat-emoji button { border: 2px solid transparent; background: var(--surface-2); border-radius: 12px; height: 42px; font-size: 22px; transition: transform .1s; }
.chat-emoji button:hover { transform: scale(1.12); border-color: var(--line); }
.chat-phrases { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-phrases button { border: 2px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 11px; font-weight: 700; font-size: 13px; box-shadow: 0 2px 0 var(--shade); }
.chat-phrases button:hover { background: var(--butter); }
.chat-panel.cooling .chat-emoji button, .chat-panel.cooling .chat-phrases button { opacity: .4; pointer-events: none; }
.chat-cool { font-size: 12.5px; font-weight: 700; color: var(--pop); text-align: center; }
.chat-log { display: grid; gap: 2px; font-size: 12.5px; color: var(--ink-soft); max-height: 96px; overflow: auto; }
.chat-log:empty { display: none; }
.chat-log p { margin: 0; } .chat-log b { color: var(--ink); }
.chat-mute { padding: 8px 12px; font-size: 13px; }
.chat-bubble { position: absolute; top: calc(100% + 10px); left: 50%; transform: translateX(-50%); z-index: 35; background: var(--surface); color: var(--ink); border: 2px solid var(--line); border-radius: 16px; padding: 6px 12px; font: 800 14px var(--body); white-space: nowrap; box-shadow: 0 4px 0 var(--shade); pointer-events: none; animation: bubble 3.4s ease forwards; }
.chat-bubble::before { content: ''; position: absolute; top: -8px; left: 50%; margin-left: -7px; border: 7px solid transparent; border-top: 0; border-bottom-color: var(--line); }
.chat-bubble.mine { background: var(--butter); color: #141829; }
.chat-bubble.emoji { font-size: 28px; padding: 2px 10px; animation-duration: 2.4s; }
@keyframes bubble { 0% { opacity: 0; transform: translate(-50%, 6px) scale(.6); } 8% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 14% { transform: translate(-50%, 0) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -6px); } }
.chat-wrap > .chat-bubble { left: auto; right: 0; transform: none; }
@media (max-width: 560px) { .chat-panel { right: 6px; width: 158px; padding: 8px; gap: 6px; max-height: calc(100dvh - 150px); } .chat-head b { font-size: 13px; } .chat-panel > * { min-width: 0; } .chat-emoji { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; } .chat-emoji button { height: 30px; font-size: 16px; border-radius: 8px; padding: 0; min-width: 0; } .chat-phrases { gap: 4px; } .chat-phrases button { padding: 4px 8px; font-size: 11.5px; border-width: 1.5px; } .chat-mute { padding: 5px 8px; font-size: 11.5px; gap: 6px; } .chat-mute .switch { transform: scale(.75); transform-origin: right center; flex: none; } .chat-log { font-size: 11.5px; } }
