:root {
  /* Neon: hot pink vs electric cyan, electric yellow highlights. */
  --bg: #0a0014;
  --card: #1a0b2e;
  --line: #3a1f5c;
  --text: #ffffff;
  --muted: #b9a7d9;
  --p1: #ff2d95;
  --p2: #00e5ff;
  --accent: #ffee00;
  --lime: #39ff14;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
/* Room for the native ad banner, which is drawn over the bottom of the page. */
body { box-sizing: border-box; padding-bottom: var(--ad-h, 0px); }

button, input { font: inherit; color: inherit; }

.screen {
  display: none;
  min-height: calc(100dvh - var(--ad-h, 0px));
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}
.screen.active { display: flex; }
.hidden { display: none !important; }
.center { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.muted { color: var(--muted); margin: 0; }

/* ---------- home ---------- */
.logo {
  font-size: clamp(44px, 14vw, 72px);
  font-weight: 900;
  letter-spacing: -2px;
  margin: 24px 0 0;
  line-height: 1;
  text-align: center;
}
.logo span { color: var(--p1); margin-left: 6px; }
.logo em { color: var(--p2); font-style: normal; margin-left: 6px; }
.logo b { color: var(--accent); animation: dots 1.4s steps(4) infinite; display: inline-block; overflow: hidden; vertical-align: bottom; width: 1.1em; }
@keyframes dots { 0% { width: 0; } 100% { width: 1.1em; } }
.tagline { color: var(--muted); margin: 0 0 8px; text-align: center; }

.card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.label { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

.formats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: 100%; }
.formats button {
  border: 2px solid var(--line);
  background: transparent;
  border-radius: 12px;
  padding: 10px 0;
  font-weight: 800;
  cursor: pointer;
}
.formats button.wide { grid-column: 1 / -1; }
.formats button.selected { border-color: var(--accent); color: var(--accent); background: #ffd23f14; }
.formats button:disabled { opacity: .5; cursor: default; }
.formats.small button { padding: 6px 0; font-size: 14px; }

.tabs { display: flex; width: 100%; background: var(--card); border-radius: 14px; padding: 4px; border: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 10px; font-weight: 700; color: var(--muted); cursor: pointer; }
.tab.selected { background: var(--line); color: var(--text); }

input {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  outline: none;
}
input:focus { border-color: var(--accent); }
input.p1:focus { border-color: var(--p1); }
input.p2:focus { border-color: var(--p2); }
#code { text-transform: uppercase; text-align: center; letter-spacing: 4px; font-weight: 800; width: 96px; flex: none; }

.row { display: flex; gap: 8px; width: 100%; }
.row > .btn { flex: 1; }

.btn {
  border: 2px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .08s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #1a1400; border-color: var(--accent); }
.btn.big { font-size: 22px; padding: 16px 40px; white-space: nowrap; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.is-ready { background: #3ddc84; border-color: #3ddc84; color: #002b12; }

.link { background: none; border: 0; color: var(--muted); text-decoration: none; cursor: pointer; padding: 8px; font-weight: 700; }
.hint { font-size: 13px; color: var(--muted); margin: 0; text-align: center; line-height: 1.6; }
kbd { background: var(--line); border-radius: 6px; padding: 1px 7px; font-weight: 800; color: var(--text); }
.error { color: var(--p1); min-height: 1.2em; margin: 0; text-align: center; }

.back {
  position: absolute; top: 16px; left: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 18px;
}

/* ---------- lobby ---------- */
#lobby .center { margin-top: 64px; }
.room-code { font-size: 64px; font-weight: 900; letter-spacing: 10px; color: var(--accent); }
.lobby-players { display: flex; gap: 12px; width: 100%; }
.lobby-player {
  flex: 1; text-align: center; padding: 16px 8px; border-radius: 16px;
  border: 2px dashed var(--line); background: var(--card); font-weight: 800;
}
.lobby-player.p1 { border-color: var(--p1); border-style: solid; }
.lobby-player.p2 { border-color: var(--p2); border-style: solid; }
.lobby-player small { display: block; font-weight: 600; color: var(--muted); margin-top: 6px; }
.lobby-player small.ok { color: #3ddc84; }
.spinner {
  width: 56px; height: 56px; border-radius: 50%;
  border: 6px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; margin-top: 64px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- game ---------- */
#game { max-width: none; padding: 0; gap: 0; height: 100dvh; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.pad {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
}
.pad.top { background: radial-gradient(circle at 50% 60%, #ff5a6e33, #ff5a6e0d 70%); }
.pad.bottom { background: radial-gradient(circle at 50% 40%, #2ec4f133, #2ec4f10d 70%); }
.pad.top .pad-count { color: var(--p1); }
.pad.bottom .pad-count { color: var(--p2); }
.pad.flipped .pad-inner { transform: rotate(180deg); }
.pad-inner { text-align: center; pointer-events: none; }
.pad-name { font-weight: 800; font-size: 18px; color: var(--muted); }
.pad-count { font-size: clamp(80px, 22vh, 180px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.pad-hint { font-size: 14px; color: var(--muted); min-height: 1.2em; }
.pad.bump .pad-count { animation: bump .12s ease-out; }
@keyframes bump { 0% { transform: scale(1.12); } 100% { transform: scale(1); } }
.pad.won { box-shadow: inset 0 0 0 6px var(--accent); }

.ripple {
  position: absolute; width: 90px; height: 90px; margin: -45px 0 0 -45px;
  border-radius: 50%; background: #ffffff40; pointer-events: none;
  animation: ripple .45s ease-out forwards;
}
@keyframes ripple { from { transform: scale(.2); opacity: 1; } to { transform: scale(2.4); opacity: 0; } }

.hud {
  width: 100%;
  padding: 10px 16px;
  background: var(--card);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 4px 12px;
  z-index: 2;
}
.hud-round { font-size: 13px; color: var(--muted); font-weight: 700; }
.hud-big { font-size: 32px; font-weight: 900; text-align: center; min-width: 120px; font-variant-numeric: tabular-nums; }
.hud-big.go { color: var(--accent); }
.hud-score { font-size: 13px; color: var(--muted); font-weight: 700; text-align: right; }
.timebar { grid-column: 1 / -1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
#timebar-fill { height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
.back.over { top: auto; bottom: calc(16px + env(safe-area-inset-bottom)); left: 16px; z-index: 3; opacity: .6; }

/* ---------- results ---------- */
#results { justify-content: center; }
.winner { font-size: 40px; font-weight: 900; text-align: center; margin: 0; }
.winner.p1 { color: var(--p1); }
.winner.p2 { color: var(--p2); }
.rounds { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rounds th, .rounds td { padding: 10px 8px; text-align: center; border-bottom: 1px solid var(--line); }
.rounds th { color: var(--muted); font-size: 13px; font-weight: 700; }
.rounds th.p1 { color: var(--p1); }
.rounds th.p2 { color: var(--p2); }
.rounds td.win { color: var(--accent); font-weight: 900; }
.rounds tfoot td { font-weight: 900; border-bottom: 0; }

/* ---------- leaderboard ---------- */
#leaders h2 { margin: 24px 0 0; }
.lb { width: 100%; list-style: none; padding: 0; margin: 0; counter-reset: lb; }
.lb li {
  counter-increment: lb;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.lb li::before { content: counter(lb); width: 24px; color: var(--muted); font-weight: 800; }
.lb li:nth-child(1)::before { content: "🥇"; }
.lb li:nth-child(2)::before { content: "🥈"; }
.lb li:nth-child(3)::before { content: "🥉"; }
.lb .n { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.lb .t { font-weight: 900; color: var(--accent); }
.lb .r { color: var(--muted); font-size: 13px; width: 70px; text-align: right; }
.lb .empty::before { content: ""; width: 0; }
.small-print { font-size: 12px; text-align: center; }

/* ---------- last 5 games ---------- */
#history-record { text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 700; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history li { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.history .badge {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-weight: 900; font-size: 14px;
  background: var(--line); color: var(--muted);
}
.history .badge.W { background: #3ddc84; color: #002b12; }
.history .badge.L { background: var(--p1); color: #2b0007; }
.history .who { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .score { font-weight: 800; }
.history .fmt { width: 52px; text-align: right; color: var(--muted); font-size: 13px; }

/* ---------- account bar ---------- */
.account {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px;
}
.me-stars { font-weight: 900; color: var(--accent); }
.me-name {
  font-weight: 800; flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: none; border: 0; padding: 4px 0; cursor: pointer;
}
.me-name::after { content: " ✎"; color: var(--muted); font-weight: 600; font-size: 13px; }
.me-rank { font-weight: 700; }
.account .link { padding: 4px; }

/* ---------- toasts, banner ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom) + var(--ad-h, 0px)); transform: translateX(-50%);
  max-width: min(92vw, 480px); padding: 12px 16px; border-radius: 12px; z-index: 50;
  background: #3a1520; border: 1px solid var(--p1); color: var(--text); font-weight: 600; text-align: center;
  box-shadow: 0 8px 24px #0008; animation: toast-in .2s ease-out;
}
.toast.ok { background: #10301f; border-color: #3ddc84; }
.toast.info { background: var(--card); border-color: var(--line); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
.net-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  padding: calc(6px + env(safe-area-inset-top)) 16px 6px; text-align: center; font-size: 13px; font-weight: 700;
  background: #5c4400; color: #fff3c4;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 30; background: #000a;
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: min(100%, 380px); background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 20px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.modal h3 { margin: 0; font-size: 20px; }
.modal p { margin: 0; color: var(--muted); }
.modal-timer { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.modal-timer div { height: 100%; background: var(--accent); transform-origin: left; }
.btn.danger { background: var(--p1); border-color: var(--p1); color: #2b0007; }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 10px; }

/* ---------- friends ---------- */
#friends h2 { margin: 24px 0 0; }
#btn-friends { display: flex; align-items: center; justify-content: center; gap: 8px; }
.pill { font-size: 12px; font-weight: 800; background: #3ddc8426; color: #3ddc84; border-radius: 99px; padding: 2px 8px; }
.dot-badge { font-size: 12px; font-weight: 900; background: var(--p1); color: #fff; border-radius: 99px; min-width: 20px; padding: 1px 6px; }
.people { list-style: none; margin: 0; padding: 0; width: 100%; }
.people li { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.people .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.people li.online .dot { background: #3ddc84; box-shadow: 0 0 8px #3ddc84; }
.people .n { font-weight: 800; }
.people .s { flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .acts { display: flex; gap: 6px; }
.people li.pending { opacity: .75; }
.people .empty { justify-content: center; border: 0; }
#requests-card .people li:last-child { border-bottom: 0; }

/* ---------- lobby / results / rankings additions ---------- */
.lobby-player .stars { display: block; color: var(--accent); font-size: 14px; margin-top: 4px; }
.star-change { font-size: 22px; font-weight: 900; margin: -6px 0 0; color: var(--muted); }
.star-change.up { color: #3ddc84; }
.star-change.down { color: var(--p1); }
.formats.six { grid-template-columns: repeat(6, 1fr); }
.lb li.me { background: #ffd23f14; border-radius: 10px; }
.lb .n.is-online::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; margin-left: 6px; vertical-align: middle; }

/* ---------- players online ---------- */
.online-count { margin: 0; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.online-count::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.online-count.ok { color: var(--text); }
.online-count.ok::before { background: #3ddc84; box-shadow: 0 0 8px #3ddc84; }
.online-count.bad { color: var(--p1); }
.online-count.bad::before { background: var(--p1); }

/* ---------- guests ---------- */
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.pill.guest { background: var(--line); color: var(--muted); }
#claim-card { border-color: var(--accent); }

/* ---------- land grab ---------- */
.land { display: none; position: absolute; inset: 0; z-index: 0; background: #18455a; }
#game.land-mode .land { display: block; }
.land-top { height: 50%; background: #572533; transition: height .08s ease-out; }
#game.land-mode .pad { background: transparent; z-index: 1; }
#game.land-mode .hud { position: relative; z-index: 2; background: #1a1a2ee6; }
#game.land-mode .pad-count, #game.land-mode .timebar { display: none; }
/* Land Grab icon: a square split between the two players' colours. */
.land-icon {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border-radius: 3px; background: linear-gradient(var(--p1) 0 50%, var(--p2) 50% 100%);
}

/* ---------- chat ---------- */
.chat { gap: 8px; padding: 12px; }
.chat-log { max-height: 220px; min-height: 60px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.chat-log:empty::before { content: "Say hi 👋 — tap a message below."; color: var(--muted); font-size: 13px; text-align: center; margin: auto; }
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.them { align-self: flex-start; align-items: flex-start; }
.msg .bubble { padding: 8px 12px; border-radius: 14px; line-height: 1.35; word-break: break-word; white-space: pre-wrap; }
.msg.me .bubble { background: #2ec4f1; color: #00202b; border-bottom-right-radius: 4px; }
.msg.them .bubble { background: var(--line); color: var(--text); border-bottom-left-radius: 4px; }
.msg.big .bubble { background: none; font-size: 34px; padding: 0 4px; line-height: 1.1; }
.msg .meta { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.emoji-row { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.emoji-row::-webkit-scrollbar { display: none; }
.emoji-row button { flex: none; border: 0; background: transparent; font-size: 22px; padding: 4px 6px; border-radius: 10px; cursor: pointer; }
.emoji-row button:active { background: var(--line); transform: scale(1.15); }
/* Quick-chat phrases: one scrolling row of small chips. */
.phrase-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.phrase-row::-webkit-scrollbar { display: none; }
.phrase-row button {
  flex: none; border: 1px solid var(--line); background: var(--bg); color: inherit; font: inherit; font-size: 14px; font-weight: 700;
  padding: 7px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.phrase-row button:active { background: var(--line); transform: scale(1.05); }
#room-view .chat, #results .chat { width: 100%; }

/* ---------- compact layout ---------- */
/* Round picker: a tall Land Grab on the left, lengths in two rows beside it. */
.formats.picker { grid-template-columns: .8fr repeat(3, 1fr); grid-auto-rows: 44px; gap: 6px; }
.formats.picker button { padding: 0; font-size: 16px; white-space: nowrap; display: flex; align-items: center; justify-content: center; }
.formats.picker .grab { grid-row: span 2; flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.1; }
/* Land Grab: an infinity sign (no time limit) in the two players' colours. */
.formats.picker .grab .inf {
  font-size: 40px; line-height: 1; font-weight: 900;
  background: linear-gradient(90deg, var(--p1) 0 50%, var(--p2) 50% 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.formats.picker .any { font-size: 14px; }

/* Less vertical space on the home screen. */
#home { gap: 10px; padding-top: calc(10px + env(safe-area-inset-top)); }
#home .logo { font-size: clamp(34px, 11vw, 52px); margin: 2px 0 0; }
#home .tagline { margin: -4px 0 0; font-size: 13px; }
#home .card { padding: 12px; gap: 10px; }
#home .label { font-size: 11px; }
#home .tab { padding: 8px; }
#home .btn { padding: 10px 14px; }
#home input { padding: 10px; }
.account { padding: 4px 12px; }
.history { gap: 4px; }
.history .badge { width: 24px; height: 24px; font-size: 13px; }
#lobby .center { margin-top: 48px; gap: 12px; }
#panel-online .row .btn { white-space: nowrap; padding: 10px 8px; font-size: 14px; }
#panel-online #code { width: 78px; letter-spacing: 3px; }

/* ---------- legal links (home) ---------- */
.legal { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
.legal a, .legal .link { color: var(--muted); font-size: 12px; padding: 4px; }

/* ---------- neon game screen ---------- */
#game { background: var(--bg); }
.pad.top { background: linear-gradient(160deg, #ff2d95 0%, #ff4d4d 55%, #ff9a00 100%); }
.pad.bottom { background: linear-gradient(200deg, #00e5ff 0%, #2d7bff 55%, #9b2cff 100%); }
.pad.top .pad-count, .pad.bottom .pad-count {
  color: #fff;
  text-shadow: 0 0 22px rgba(255, 255, 255, .8), 0 4px 0 rgba(0, 0, 0, .25);
}
.pad-name, .pad-hint { color: rgba(255, 255, 255, .9); text-shadow: 0 1px 2px rgba(0, 0, 0, .35); }
.pad.won { box-shadow: inset 0 0 0 6px var(--accent), inset 0 0 80px rgba(255, 238, 0, .7); }
.ripple { background: rgba(255, 255, 255, .55); }
.hud { background: #0a0014; border-color: rgba(255, 238, 0, .35); }
.hud-big { color: var(--accent); text-shadow: 0 0 14px rgba(255, 238, 0, .7); }
.hud-big.go { color: var(--lime); text-shadow: 0 0 16px rgba(57, 255, 20, .8); }
#timebar-fill { background: linear-gradient(90deg, var(--lime), var(--accent), #ff9a00); }
.land { background: linear-gradient(200deg, #00e5ff, #2d7bff 55%, #9b2cff); }
.land-top { background: linear-gradient(160deg, #ff2d95, #ff4d4d 55%, #ff9a00); }

/* ---------- 3-2-1: giant number shrinking into the centre ---------- */
.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 6; overflow: hidden; }
.countdown span {
  font-weight: 900; font-size: 62vmin; line-height: 1; color: var(--c);
  text-shadow: 0 0 40px var(--c), 0 0 6px #fff, 0 10px 0 rgba(0, 0, 0, .35);
  animation: count-shrink .95s cubic-bezier(.2, .75, .3, 1) forwards;
}
.countdown span.go { font-size: 30vmin; animation: count-pop .7s ease-out forwards; }
@keyframes count-shrink {
  0% { transform: scale(3.4); opacity: .9; }
  60% { opacity: 1; }
  100% { transform: scale(.3); opacity: 0; }
}
@keyframes count-pop {
  0% { transform: scale(.3); opacity: 0; }
  30% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1.7); opacity: 0; }
}

/* ---------- celebration canvas + sad loser ---------- */
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 45; }
.pad.sad::after {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: rgba(28, 34, 54, .82); animation: sad-in .5s ease-out;
}
.sad-face {
  position: absolute; left: 50%; top: 50%; z-index: 2; font-size: min(28vmin, 150px); line-height: 1;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .6));
  animation: sad-in .5s ease-out, droop 1.8s ease-in-out .5s infinite;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
}
.pad.flipped .sad-face { --rot: 180deg; }
@keyframes sad-in { from { opacity: 0; } }
@keyframes droop {
  0%, 100% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) translateY(0) rotate(0deg); }
  50% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) translateY(12px) rotate(-7deg); }
}
.winner.lost { color: #9fb4d8; }
.winner.won { text-shadow: 0 0 22px currentColor; }

/* ---------- sound on/off ---------- */
.sound-toggle {
  width: 36px; height: 36px; flex: none; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: 18px; line-height: 1; cursor: pointer; padding: 0;
  display: grid; place-items: center;
}
.sound-toggle.off { opacity: .6; }
.sound-toggle.over {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 7;
  width: 44px; height: 44px; font-size: 22px; background: rgba(10, 0, 20, .55);
  border-color: rgba(255, 255, 255, .35); backdrop-filter: blur(4px);
}

/* ===================== layout: nothing scrolls ===================== */
/* Pages never scroll; only list boxes inside a page do, without a visible bar. */
html, body { height: 100%; overflow: hidden; }
* { scrollbar-width: none; }
*::-webkit-scrollbar { display: none; }
.screen { height: calc(100dvh - var(--ad-h, 0px)); min-height: 0; overflow: hidden; }
.scroll-area { flex: 1; min-height: 0; width: 100%; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.chat-log { overscroll-behavior: contain; }

/* Header for sub-screens: back button sits below the notch / Dynamic Island. */
.screen:has(> .topbar) { padding-top: calc(8px + env(safe-area-inset-top)); }
.topbar { width: 100%; display: flex; align-items: center; gap: 10px; flex: none; }
.topbar h2 { flex: 1; margin: 0; font-size: 20px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { width: 40px; flex: none; }
.topbar .back { position: static; flex: none; }
.back { display: grid; place-items: center; color: var(--text); padding: 0; }
.back svg { width: 22px; height: 22px; }
#lobby .center { margin-top: 0; flex: 1; justify-content: center; }

/* ===================== buttons ===================== */
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn.small svg { width: 16px; height: 16px; flex: none; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:active { color: var(--text); }
.btn.danger-outline { border-color: var(--p1); color: var(--p1); background: transparent; }
.mini-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; width: 100%; }
#home .mini-row .btn { padding: 8px 12px; }

/* Monochrome speaker icon. */
.sound-toggle { color: var(--text); }
.sound-toggle svg { width: 20px; height: 20px; }
.sound-toggle.over svg { width: 24px; height: 24px; }
.sound-toggle.off { color: var(--muted); opacity: 1; }

/* ===================== matchmaking ===================== */
.queue { gap: 18px; }
.queue h2 { margin: 0; }
.queue-timer { font-size: 64px; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; text-shadow: 0 0 18px rgba(255, 238, 0, .5); }

/* ===================== results ===================== */
#results .actions { display: flex; flex-direction: column; align-items: stretch; gap: 10px; width: 100%; }
#results .actions .btn.small { align-self: center; }

/* ===================== leaderboards ===================== */
.seg { display: flex; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; flex: none; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 10px; font-weight: 800; color: var(--muted); cursor: pointer; }
.seg button.selected { background: var(--line); color: var(--text); }
.formats.lengths { grid-template-columns: repeat(5, 1fr); flex: none; }
.lb li.skeleton { height: 46px; border: 0; border-radius: 12px; margin-bottom: 6px; padding: 0;
  background: linear-gradient(90deg, var(--card) 0%, var(--line) 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.1s linear infinite; }
.lb li.skeleton::before { content: none; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.lb-empty { list-style: none; text-align: center; padding: 40px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); }
.lb-empty::before { content: none !important; }
.lb-empty .big { font-size: 44px; }
.lb-empty strong { color: var(--text); font-size: 17px; }
#leaders .small-print { flex: none; margin: 0; }

/* ===================== about ===================== */
.about-card { gap: 10px; }
.about-head { display: flex; align-items: center; gap: 12px; }
.about-head img { border-radius: 12px; }
.about-head strong { display: block; font-size: 18px; }
.about-text { font-size: 13px; line-height: 1.55; }
.about-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.select { user-select: all; -webkit-user-select: all; color: var(--text); }
.mini-row { flex-wrap: nowrap; }
.mini-row .btn { flex: 1 1 0; min-width: 0; white-space: nowrap; }
a.btn { color: var(--text); text-decoration: none; }
.btn.small { white-space: nowrap; }
.about-buttons .btn { width: 100%; }
.queue h2 { text-align: center; }
#results .actions .btn { white-space: nowrap; }
/* Create room · CODE · Join always fit on narrow phones. */
#panel-online .row .btn { flex: 1 1 0; min-width: 0; padding: 10px 6px; }
#panel-online #code { width: 74px; flex: none; letter-spacing: 2px; padding-left: 4px; padding-right: 4px; }
#panel-online #btn-create { flex: 1.8 1 0; }
#panel-online .row .btn { font-size: 13.5px; }

/* ---------- Home button (bottom centre of sub-screens) ---------- */
/* Fixed outside the screens, so screen scaling never affects tapping it. */
.home-dock {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 25;
  bottom: calc(14px + env(safe-area-inset-bottom) + var(--ad-h, 0px));
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 22px; border-radius: 999px;
  background: var(--card); border-color: rgba(255, 255, 255, .25); color: var(--text); font-size: 15px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
.home-dock:active { transform: translateX(-50%) scale(.96); }
.home-dock svg { width: 18px; height: 18px; }
.home-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.home-btn svg { width: 16px; height: 16px; flex: none; }
/* Keep content clear of the floating button. */
#friends, #lobby, #leaders, #about { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar h2 { text-align: center; }
/* The connection notice never blocks taps underneath it. */
.net-banner { pointer-events: none; }
/* Enough room for the Home button even when a screen is shrunk to fit. */
#friends, #lobby, #leaders, #about { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
/* Room screen stays compact on short phones (room code, players, chat). */
#lobby .room-code { font-size: clamp(40px, 7.5vh, 64px); letter-spacing: 8px; }
#lobby .lobby-player { padding: 10px 8px; }
#lobby .chat-log { max-height: min(220px, 18vh); min-height: 48px; }
/* While typing (keyboard up) the Home button would sit on top of the input. */
body:has(input:focus) .home-dock { display: none; }

/* ---------- share / invite ---------- */
#btn-share-home { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
#btn-share-home svg { width: 16px; height: 16px; }
.friends-row #btn-friends { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; }
.invite-btn { width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex: none; }
.invite-btn svg { width: 18px; height: 18px; }
/* Top bar: name first; the two round icons stay compact. */
#account .me-stars, #account .me-rank { white-space: nowrap; flex: none; }
