:root {
  --bg-0: #070b1f;
  --bg-1: #111a3d;
  --ink: #f2f4ff;
  --ink-2: rgb(242 244 255 / 0.66);
  --ink-3: rgb(242 244 255 / 0.42);
  --cx: #ff6b5b;
  --co: #2ec4b6;
  --glass: rgb(255 255 255 / 0.07);
  --glass-2: rgb(255 255 255 / 0.12);
  --shadow: 0 0 0 1px rgb(255 255 255 / 0.08), 0 8px 24px rgb(0 0 0 / 0.35), 0 2px 6px rgb(0 0 0 / 0.25);
  --ease: cubic-bezier(0.2, 0, 0, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(120% 90% at 50% 20%, var(--bg-1) 0%, var(--bg-0) 70%) fixed, var(--bg-0);
  color: var(--ink);
  font: 15px/1.4 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
h1, h2 { text-wrap: balance; margin: 0; }
p { text-wrap: pretty; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }

/* Buttons */
.btn {
  appearance: none; border: 0; cursor: pointer;
  min-height: 44px; padding: 0 20px; border-radius: 22px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 15px/1 inherit; color: var(--ink); text-decoration: none;
  background: var(--glass-2);
  box-shadow: var(--shadow);
  transition-property: scale, background-color, opacity;
  transition-duration: 150ms;
  transition-timing-function: var(--ease);
}
.btn:hover { background: rgb(255 255 255 / 0.16); }
.btn:active { scale: 0.96; }
.btn:focus-visible, .chip:focus-visible, .toggle:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid #9fb2ec; outline-offset: 2px; }
.btn.primary { background: var(--ink); color: var(--bg-0); }
.btn.primary:hover { background: #fff; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.18); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: 18px; position: relative; }
.btn.small::after { content: ""; position: absolute; inset: -4px 0; }

/* Home */
.home { position: fixed; inset: 0; z-index: 5; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.home-inner {
  width: 100%; max-width: 440px; margin: 0 auto;
  /* The cube spins in the space above the content. */
  padding: calc(max(16px, env(safe-area-inset-top)) + min(38vh, 340px)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
.home-head { text-align: center; animation: rise 500ms var(--ease) both; }
.home-head h1 { font-size: 36px; font-weight: 700; letter-spacing: -0.02em; }
.home-head p { margin: 6px 0 0; }
.card {
  padding: 16px; border-radius: 24px;
  background: rgb(10 15 40 / 0.62); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  animation: rise 500ms var(--ease) both; animation-delay: 80ms;
}
.card fieldset:last-of-type { margin-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; color: var(--ink-2); }
.field input {
  width: 100%; min-height: 44px; padding: 0 14px; border: 0; border-radius: 12px; font: inherit; font-size: 16px;
  background: var(--glass-2); color: var(--ink);
}
.size-note { margin: 8px 2px 0; min-height: 18px; }
.home-actions { display: flex; flex-direction: column; gap: 10px; animation: rise 500ms var(--ease) both; animation-delay: 160ms; }
.btn.big { min-height: 52px; border-radius: 26px; font-size: 16px; width: 100%; }
.home-actions .btn.primary { background: var(--me, var(--ink)); color: #0b0f24; }
.home-actions .btn.primary:hover { background: color-mix(in srgb, var(--me, #fff) 88%, #fff); }
.center { text-align: center; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 10px; background: var(--me, var(--ink)); color: #0b0f24; font-variant-numeric: tabular-nums; }
.games { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.game-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-radius: 16px; background: rgb(255 255 255 / 0.04); }
.game-row.mine { background: color-mix(in srgb, var(--me, #fff) 14%, transparent); }
.game-row a { color: var(--ink); text-decoration: none; min-height: 44px; display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.game-row .g-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-row .g-sub { font-size: 12px; color: var(--ink-2); }
.game-row.mine .g-sub { color: var(--ink); }
.game-row .g-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.game-row .g-actions { display: flex; gap: 4px; align-items: center; }
.game-row .g-confirm { display: flex; gap: 6px; align-items: center; grid-column: 1 / -1; justify-content: flex-end; animation: rise 200ms var(--ease) both; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--ink-3); cursor: pointer;
  width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center;
  transition-property: color, background-color, scale; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.icon-btn:hover { color: var(--ink); background: var(--glass); }
.icon-btn:active { scale: 0.96; }
.icon-btn svg { width: 18px; height: 18px; }
.linkish { appearance: none; border: 0; background: none; color: var(--ink-2); cursor: pointer; padding: 0; min-height: 44px; font: inherit; }
.linkish:hover { color: var(--ink); }
.home-signin { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 10px; }
.home-signin .signin > .muted { display: none; } /* the prompt above already says it */
.more summary { cursor: pointer; font-weight: 600; min-height: 28px; display: flex; align-items: center; color: var(--ink-2); }
.more[open] summary { margin-bottom: 14px; }
.home-toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.home-toggles .toggle { padding: 0 14px; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.12); }
.home-links { margin: 0; text-align: center; font-size: 13px; }
.home-links a { color: var(--ink-2); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.home-links a:hover { color: var(--ink); }

/* Share panel (host waiting for a friend) */
.share { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 460px; padding: 10px; border-radius: 22px; background: rgb(14 20 48 / 0.85); box-shadow: var(--shadow); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.share-label { padding-left: 6px; }
.share-row { display: flex; gap: 6px; align-items: center; }
.share-row input { flex: 1; min-width: 0; min-height: 36px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--glass-2); color: var(--ink); font: 500 13px/1 inherit; }

/* Computer level */
.level { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); min-height: 44px; }
.level select { appearance: none; border: 0; border-radius: 12px; min-height: 32px; padding: 0 10px; background: var(--glass); color: var(--ink); font: 500 13px/1 inherit; cursor: pointer; }
.level-seg { margin: 0 0 14px; text-align: left; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* HUD */
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; display: flex; flex-direction: column; justify-content: space-between; }
.hud > * { pointer-events: auto; }
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  width: 100%; max-width: 760px; margin: 0 auto;
}
.player {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 8px 12px; border-radius: 20px; background: var(--glass);
  box-shadow: var(--shadow); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transition-property: background-color, box-shadow; transition-duration: 200ms; transition-timing-function: var(--ease);
}
.player.right { justify-content: flex-end; text-align: right; }
[data-mark="X"] { --c: var(--cx); }
[data-mark="O"] { --c: var(--co); }
.player.active { box-shadow: 0 0 0 1.5px var(--c), 0 8px 24px color-mix(in srgb, var(--c) 25%, transparent); }
.chip-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c) 45%, #fff), var(--c) 60%); }
.pinfo { display: flex; flex-direction: column; min-width: 0; }
.pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prole { font-size: 11px; color: var(--ink-3); letter-spacing: 0.08em; }
.score { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-left: auto; display: inline-block; }
.player.right .score { margin-left: 0; margin-right: auto; }
.score.bump { animation: bump 700ms var(--ease); }
@keyframes bump { 0% { scale: 1; } 30% { scale: 1.6; color: #fff; } 100% { scale: 1; } }

.center-pill { display: flex; flex-direction: column; align-items: center; text-align: center; }
.round { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.turn { font-weight: 600; font-size: 13px; white-space: nowrap; }

.toasts { position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 72px); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  max-width: min(360px, calc(100vw - 32px)); padding: 10px 14px; border-radius: 18px 18px 18px 6px;
  background: rgb(20 28 64 / 0.85); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow); font-weight: 500;
  animation: toast-in 300ms var(--ease) both;
  transition-property: opacity, translate; transition-duration: 250ms; transition-timing-function: var(--ease);
}
.toast.mine { border-radius: 18px 18px 6px 18px; }
.toast .who { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }
.toast .who { color: var(--c); }
.toast.out { opacity: 0; translate: 0 -6px; }
@keyframes toast-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }

.bottom {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 0 16px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgb(7 11 31 / 0.85), transparent);
  pointer-events: none;
}
.bottom > * { pointer-events: auto; }
.status { margin: 0; font-weight: 500; text-align: center; color: var(--ink-2); min-height: 21px; text-wrap: balance; }
.action-row { display: flex; gap: 12px; align-items: center; justify-content: center; min-height: 44px; flex-wrap: wrap; }
.signin { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#apple-sign-in-button { min-height: 44px; min-width: 200px; }
.chat { display: flex; flex-direction: column; gap: 8px; align-items: center; width: 100%; max-width: 560px; }
.chips { display: flex; gap: 8px; overflow-x: auto; max-width: 100%; padding: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; appearance: none; border: 0; cursor: pointer; color: var(--ink);
  min-height: 36px; padding: 0 14px; border-radius: 18px; background: var(--glass);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.1); font: 500 14px/1 inherit; position: relative;
  transition-property: scale, background-color; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.chip::after { content: ""; position: absolute; inset: -4px 0; }
.chip:hover { background: var(--glass-2); }
.chip:active { scale: 0.96; }
.meta-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; max-width: 560px; font-size: 13px; }
.spread { display: flex; align-items: center; gap: 8px; color: var(--ink-2); min-height: 44px; }
.spread input { width: 110px; accent-color: #9fb2ec; }
.links { display: flex; gap: 14px; }
.links a { color: var(--ink-2); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; white-space: nowrap; }
.links a:hover { color: var(--ink); }
.legal { margin: 0; font-size: 7.7px; color: var(--ink-3); }   /* 70% of the old 11px */

dialog {
  border: 0; border-radius: 24px; padding: 24px; width: min(360px, calc(100vw - 32px));
  background: #121a3e; color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); backdrop-filter: blur(4px); }
dialog h2 { font-size: 20px; }
dialog p { margin: 6px 0 16px; }
dialog input {
  width: 100%; min-height: 44px; padding: 0 14px; border: 0; border-radius: 12px; font: inherit;
  background: var(--glass-2); color: var(--ink); margin-bottom: 16px;
}
dialog .btn { width: 100%; }

/* Buttons: variants */
.btn.danger { background: #c2413a; color: #fff; }
.btn.danger:hover { background: #d24a42; }
.btn.icon { width: 36px; padding: 0; }
.btn.icon svg { width: 18px; height: 18px; }

/* Resign with inline confirm */
.resign { display: inline-flex; align-items: center; }
.resign-confirm { display: inline-flex; align-items: center; gap: 8px; animation: rise 200ms var(--ease) both; }

/* Tools: spread + toggles */
.tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toggle {
  appearance: none; border: 0; cursor: pointer; font: 500 13px/1 inherit;
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 10px;
  border-radius: 22px; background: transparent; color: var(--ink-3);
  transition-property: color, background-color, scale; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.toggle svg { width: 18px; height: 18px; }
.toggle:hover { color: var(--ink-2); }
.toggle:active { scale: 0.96; }
.toggle[aria-pressed="true"] { color: var(--ink); background: var(--glass); }
.toggle[aria-pressed="false"] .wave { opacity: 0; }

/* Replay bar */
.replay { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 460px; padding: 6px; border-radius: 26px; background: rgb(14 20 48 / 0.8); box-shadow: var(--shadow); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.replay input { flex: 1; min-width: 0; accent-color: #9fb2ec; min-height: 36px; }
.replay-count { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 4.5ch; text-align: right; }

/* Colour swatches + size segments (dialogs) */
fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
legend { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; color: var(--ink-2); margin-bottom: 8px; padding: 0; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.swatch { position: relative; display: grid; place-items: center; height: 40px; cursor: pointer; border-radius: 50%; }
.swatch::before {
  content: ""; width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--sw) 45%, #fff), var(--sw) 60%, color-mix(in srgb, var(--sw) 70%, #000));
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.1);
  transition-property: box-shadow, scale; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.swatch:has(input:checked)::before { box-shadow: 0 0 0 2px #121a3e, 0 0 0 4px var(--sw); scale: 1.06; }
.swatch:has(input:focus-visible)::before { outline: 2px solid #9fb2ec; outline-offset: 5px; }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg-track { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 16px; background: var(--glass); }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg-opt span {
  display: grid; place-items: center; min-height: 40px; border-radius: 12px; font-weight: 600; font-size: 14px;
  color: var(--ink-2); font-variant-numeric: tabular-nums;
  transition-property: background-color, color; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.seg-opt input:checked + span { background: var(--glass-2); color: var(--ink); box-shadow: var(--shadow); }
.seg-opt input:focus-visible + span { outline: 2px solid #9fb2ec; outline-offset: 1px; }

/* End-of-round card — always dark, always readable */
.result-backdrop {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: rgb(3 5 16 / 0.5);
  opacity: 0; transition-property: opacity; transition-duration: 180ms; transition-timing-function: var(--ease);
}
.result-backdrop.open { opacity: 1; }
.result-card {
  --c: #c9d3f5;
  position: relative; width: min(400px, 100%); padding: 28px 24px 20px; border-radius: 32px; text-align: center;
  background: radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--c) 22%, transparent), transparent 70%), #0d1330;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.1), 0 24px 60px rgb(0 0 0 / 0.55), 0 4px 12px rgb(0 0 0 / 0.3);
  color: var(--ink);
  translate: 0 8px; scale: 0.97;
  transition-property: translate, scale; transition-duration: 220ms; transition-timing-function: var(--ease);
}
.result-backdrop.open .result-card { translate: 0 0; scale: 1; }
.result-card:has(.result-orb[data-mark="X"]) { --c: var(--cx); }
.result-card:has(.result-orb[data-mark="O"]) { --c: var(--co); }
.result-orb { width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 50%; position: relative; }
.result-orb[data-mark="X"], .result-orb[data-mark="O"] {
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c) 40%, #fff), var(--c) 55%, color-mix(in srgb, var(--c) 65%, #000));
  box-shadow: 0 8px 24px color-mix(in srgb, var(--c) 40%, transparent);
}
.result-orb[data-mark="draw"] { background: none; }
.result-orb[data-mark="draw"]::before, .result-orb[data-mark="draw"]::after {
  content: ""; position: absolute; top: 6px; width: 40px; height: 40px; border-radius: 50%;
}
.result-orb[data-mark="draw"]::before { left: -8px; background: radial-gradient(circle at 35% 30%, #fff8, var(--cx) 60%); }
.result-orb[data-mark="draw"]::after { right: -8px; background: radial-gradient(circle at 35% 30%, #fff8, var(--co) 60%); }
.result-card h2 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.result-how { margin: 6px 0 18px; color: var(--ink-2); }
.result-score {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 12px 8px; border-radius: 20px; background: rgb(255 255 255 / 0.05);
}
.result-score > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rs-num { font-size: 36px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result-score > div:first-child .rs-num { color: var(--cx); }
.result-score > div:last-child .rs-num { color: var(--co); }
.rs-name { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rs-dash { color: var(--ink-3); font-size: 22px; }
.result-next { list-style: none; margin: 16px 0 18px; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--ink-2); }
.result-next li { display: grid; grid-template-columns: 18px 1fr; gap: 8px; text-wrap: pretty; }
.result-next li::before { content: "•"; text-align: center; color: var(--ink-3); }
.result-next li[data-icon="wait"]::before { content: "⏳"; font-size: 12px; }
.result-next li[data-icon="wave"]::before { content: "👋"; font-size: 12px; }
.result-next li[data-icon="again"]::before { content: "↻"; }
.result-next li[data-icon="flag"]::before { content: "⚑"; }
.result-actions { display: flex; flex-direction: column; gap: 8px; }
.result-actions .btn.primary { width: 100%; background: var(--c); color: #0b0f24; }
.result-actions .btn.primary:hover { background: color-mix(in srgb, var(--c) 88%, #fff); }
.result-secondary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.result-secondary:has(> [hidden]) { grid-template-columns: 1fr; }

@media (max-width: 520px) {
  .score { font-size: 22px; }
  .player { padding: 6px 10px; gap: 6px; }
  .pname { font-size: 14px; }
  .topbar { gap: 6px; padding-inline: 12px; }
  .round { font-size: 11px; }
  .meta-row { flex-wrap: wrap; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .home-head, .card, .home-actions, .toast, .score.bump, .resign-confirm, .g-confirm { animation: none; }
  .result-card { translate: 0 0; scale: 1; }
}

/* Invite card — slides up from the bottom on phones, centred on wider screens */
.invite-backdrop {
  position: fixed; inset: 0; z-index: 31; display: grid; align-items: end; justify-items: center;
  padding: 0 10px max(10px, env(safe-area-inset-bottom));
  background: rgb(3 5 16 / 0.55);
  opacity: 0; transition-property: opacity; transition-duration: 200ms; transition-timing-function: var(--ease);
}
.invite-backdrop.open { opacity: 1; }
.invite-card {
  width: min(440px, 100%); padding: 14px 24px 16px; border-radius: 32px; text-align: left; color: var(--ink);
  background: radial-gradient(90% 50% at 0% 0%, color-mix(in srgb, var(--cx) 24%, transparent), transparent 70%), #0d1330;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.1), 0 -12px 50px rgb(0 0 0 / 0.5);
  translate: 0 40px; transition-property: translate; transition-duration: 300ms; transition-timing-function: var(--ease);
}
.invite-backdrop.open .invite-card { translate: 0 0; }
.invite-grip { display: block; width: 40px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: rgb(255 255 255 / 0.25); }
@media (min-width: 640px) { .invite-backdrop { align-items: center; } .invite-card { padding-top: 24px; } .invite-grip { display: none; } }
.invite-card h2 { margin: 0 0 6px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; text-wrap: balance; }
.invite-card > .muted { margin: 0 0 18px; text-wrap: pretty; }
.invite-link {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 0 16px; border-radius: 16px;
  background: var(--glass); border: 0; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.1);
  color: var(--ink); font: 500 14px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; cursor: pointer; text-align: left;
}
.invite-link svg { width: 20px; height: 20px; flex: none; color: var(--cx); }
.invite-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-link:active { scale: 0.98; }
.invite-actions { display: flex; gap: 10px; margin: 12px 0 20px; }
.invite-actions .btn { flex: 1; min-height: 48px; }
.invite-steps { list-style: none; counter-reset: step; margin: 0 0 8px; padding: 0; display: grid; gap: 14px; }
.invite-steps li { counter-increment: step; display: grid; grid-template-columns: 26px 1fr; column-gap: 12px; }
.invite-steps li::before {
  content: counter(step); grid-row: span 2; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; background: color-mix(in srgb, var(--cx) 28%, transparent);
}
.invite-steps b { font-size: 15px; font-weight: 600; }
.invite-steps span { font-size: 13px; color: var(--ink-2); text-wrap: pretty; }
.invite-done { width: 100%; min-height: 44px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }
.pname.editable { cursor: pointer; text-decoration: underline dotted rgb(255 255 255 / 0.35); text-underline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { .invite-card { translate: 0 0; transition: none; } }

/* ── Quiet game toolbar + popovers ── */
.toolbar { display: flex; justify-content: center; gap: 6px; margin-top: 4px; }
.tool {
  position: relative; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer; text-decoration: none;
  transition-property: background-color, color, scale; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.tool svg { width: 22px; height: 22px; }
.tool:hover { background: var(--glass); color: var(--ink); }
.tool:active { scale: 0.96; }
.tool:focus-visible { outline: 2px solid #9fb2ec; outline-offset: 1px; }
.tool[aria-pressed="true"] { color: var(--ink); background: var(--glass); }
#soundToggle[aria-pressed="false"] .wave { opacity: 0; }
#soundToggle[aria-pressed="false"]::after {
  content: ""; position: absolute; width: 22px; height: 1.6px; background: currentColor; rotate: -45deg; border-radius: 1px;
}
.tool[hidden] { display: none; }

.pop {
  position: fixed; inset: auto auto 96px 50%; translate: -50% 0; margin: 0;
  border: 0; padding: 8px; border-radius: 22px; color: var(--ink);
  background: #0d1330; box-shadow: 0 0 0 1px rgb(255 255 255 / 0.1), 0 18px 50px rgb(0 0 0 / 0.55);
  max-width: min(420px, calc(100vw - 32px));
  opacity: 0; scale: 0.96; transition-property: opacity, scale, display, overlay;
  transition-duration: 160ms; transition-timing-function: var(--ease); transition-behavior: allow-discrete;
}
.pop:popover-open { opacity: 1; scale: 1; }
@starting-style { .pop:popover-open { opacity: 0; scale: 0.96; } }
.chat-pop .chat { margin: 0; }
.chat-pop .chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 4px; }

.menu-pop { width: 280px; display: none; flex-direction: column; gap: 2px; }
.menu-pop:popover-open { display: flex; }
.menu-row, .menu-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 0 12px;
  border-radius: 14px; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 15px;
  text-align: left; text-decoration: none; cursor: pointer;
  transition-property: background-color; transition-duration: 120ms; transition-timing-function: var(--ease);
}
.menu-item:hover, .menu-row.toggle:hover { background: var(--glass); }
.menu-row[hidden], .menu-item[hidden] { display: none; }
.menu-row.resign { flex-wrap: wrap; padding: 0; }
.menu-row.resign .menu-item { width: 100%; }
.menu-row .resign-confirm { padding: 6px 12px 10px; flex-wrap: wrap; }
.danger-text { color: #ff8f84; }
.menu-sep { height: 1px; margin: 4px 8px; background: rgb(255 255 255 / 0.08); }
.menu-row.spread input { width: 120px; }
.menu-row select { background: var(--glass); color: var(--ink); border: 0; border-radius: 10px; padding: 6px 8px; font: inherit; }
.switch { width: 38px; height: 22px; border-radius: 11px; background: rgb(255 255 255 / 0.16); position: relative; flex: none;
  transition-property: background-color; transition-duration: 150ms; transition-timing-function: var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition-property: translate; transition-duration: 150ms; transition-timing-function: var(--ease); }
.menu-row.toggle[aria-pressed="true"] .switch { background: var(--cx); }
.menu-row.toggle[aria-pressed="true"] .switch::after { translate: 16px 0; }
@media (prefers-reduced-motion: reduce) { .pop { transition: none; } }

/* Pieces style picker inside the ⋯ menu */
.seg-compact { margin: 0; }
.seg-compact .seg-track { display: flex; gap: 2px; padding: 2px; border-radius: 12px; }
.seg-compact .seg-opt span { min-height: 40px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
#homePieces { margin-top: 4px; }

/* ───────── Home carousel: one game per page (mirrors the iOS home) ───────── */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hc { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; }
.hc[hidden] { display: none; }
.hc-top {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 14px; z-index: 3; display: flex; gap: 2px; padding: 3px;
  border-radius: 26px; background: var(--glass); box-shadow: var(--shadow); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
#hcSound[aria-pressed="false"] .wave { opacity: 0; }
#hcSound[aria-pressed="false"]::after { content: ""; position: absolute; width: 22px; height: 1.6px; background: currentColor; rotate: -45deg; border-radius: 1px; }
.hc-track {
  flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain; scrollbar-width: none; outline: none;
}
.hc-track::-webkit-scrollbar { display: none; }
.hc-page {
  flex: 0 0 100%; min-width: 0; scroll-snap-align: start; scroll-snap-stop: always; overflow-y: auto; overscroll-behavior-y: contain;
  display: flex; flex-direction: column; align-items: center;
  padding: max(56px, calc(env(safe-area-inset-top) + 48px)) 16px 140px; scrollbar-width: none;
}
.hc-page::-webkit-scrollbar { display: none; }
.hc-hero { width: 100%; height: 42dvh; min-height: 200px; flex: none; }
.hc-canvas { width: 100%; height: 100%; display: block; }
.hc-panel { width: 100%; max-width: 600px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.hc-panel h1 { margin: 0; font-size: 42px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; text-wrap: balance; }
.hc-tag { margin: 0 0 8px; color: var(--ink-2); text-wrap: pretty; }
.hc-size { margin: 0; }
.hc-row { display: grid; grid-template-columns: 1fr; gap: 10px; }
.hc-row:has(> :nth-child(2)) { grid-template-columns: 1fr 1fr; }
.hc-row .btn.big { width: 100%; text-decoration: none; }
.btn.hc-solo { background: var(--me); color: #0b0f24; }
.btn.hc-solo:hover { background: color-mix(in srgb, var(--me) 88%, #fff); }
.hc-daily { flex-direction: column; gap: 1px; line-height: 1.15; background: color-mix(in srgb, var(--me) 38%, rgb(255 255 255 / 0.06)); }
.hc-daily:hover { background: color-mix(in srgb, var(--me) 48%, rgb(255 255 255 / 0.08)); }
.hc-daily span { white-space: nowrap; }
.hc-daily small { font-size: 12px; font-weight: 500; opacity: 0.8; font-variant-numeric: tabular-nums; }
.hc-links { margin: 2px 0 0; display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 20px; font-size: 14px; }
.hc-links a { color: var(--ink-2); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.hc-links a:hover { color: var(--ink); }

.hc-foot {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 28px 16px max(10px, env(safe-area-inset-bottom)); pointer-events: none;
  background: linear-gradient(to top, rgb(7 11 31 / 0.9) 40%, transparent);
}
.hc-foot > * { pointer-events: auto; }
.hc-dots { display: flex; gap: 8px; }
.hc-dots button {
  position: relative; width: 7px; height: 7px; padding: 0; border: 0; border-radius: 4px; cursor: pointer; background: rgb(255 255 255 / 0.25);
  transition-property: width, background-color; transition-duration: 250ms; transition-timing-function: var(--ease);
}
.hc-dots button::after { content: ""; position: absolute; inset: -18px -6px; }
.hc-dots button[aria-current="true"] { width: 18px; background: rgb(255 255 255 / 0.9); }
.hc-games {
  position: relative; display: inline-flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 18px; border: 0; border-radius: 24px;
  color: var(--ink); font: 600 14px/1 inherit; cursor: pointer; background: var(--glass-2); box-shadow: var(--shadow);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transition-property: scale, background-color; transition-duration: 150ms; transition-timing-function: var(--ease);
}
.hc-games[hidden] { display: none; }
.hc-games:active { scale: 0.96; }
.hc-games svg { width: 20px; height: 20px; }
.hc-games.urgent { background: color-mix(in srgb, var(--me) 30%, rgb(20 28 64 / 0.85)); }
.hc-games.urgent::after {
  content: ""; position: absolute; top: -2px; right: -2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--me); box-shadow: 0 0 0 2px var(--bg-0);
}
.hc-count { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.hc-turn { font-size: 12px; font-weight: 700; padding: 4px 8px; border-radius: 10px; background: var(--me); color: #0b0f24; font-variant-numeric: tabular-nums; }
.hc-turn[hidden] { display: none; }
.hc-sheet { width: min(560px, 100%); display: flex; flex-direction: column; max-height: min(680px, calc(100dvh - 40px)); }
.hc-sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.hc-sheet-head h2 { margin: 0; }
.hc-sheet .games { overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.hc-sheet .linkish { align-self: center; margin-top: 8px; }
.hc-settings { width: min(460px, calc(100vw - 32px)); }
.hc-settings form { display: flex; flex-direction: column; gap: 14px; }
.hc-settings h2 { margin: 0; }
.hc-settings .field { display: flex; flex-direction: column; gap: 6px; }
.hc-settings .home-links { text-align: left; }

/* ───────── Wide screens (iPad, unfolded foldables, desktop): side-by-side, like iOS ─────────
   wide = width ≥ 700px and width > height × 0.9 */
@media (min-width: 700px) and (min-aspect-ratio: 9/10) {
  .hc-page { flex-direction: row; align-items: center; gap: 32px; padding: 72px 40px 120px; }
  .hc-hero { flex: 1; height: 100%; min-height: 0; }
  .hc-panel { flex: none; width: min(440px, 42vw); text-align: left; }
  .hc-panel h1 { font-size: 48px; }
  .hc-links { justify-content: flex-start; }
  .hc-foot { background: none; }

  /* Game pages: board on the left, scoreboard / status / controls in a right-hand panel. */
  .hud, body .wc-play {
    left: auto; right: 0; width: min(420px, 38vw); padding: 0 0 0 0;
    background: linear-gradient(to left, rgb(7 11 31 / 0.82), rgb(7 11 31 / 0.55));
    box-shadow: -1px 0 0 rgb(255 255 255 / 0.06);
  }
  .hud .topbar { grid-template-columns: 1fr 1fr; padding: max(16px, env(safe-area-inset-top)) 16px 0; }
  .hud .center-pill { grid-column: 1 / -1; grid-row: 2; }
  .hud .bottom { background: none; }
  .hud .toasts, .wc-play .toasts { position: absolute; top: 120px; }
  .wc-top, .wc-bottom { max-width: none; }
  .wc-top { padding-top: max(16px, env(safe-area-inset-top)); }
  body .wc-play .menu-pop, body .wc-play .chat-pop, body .hud .menu-pop, body .hud .chat-pop { inset: auto 16px 110px auto; translate: 0 0; }
}
/* Not wide: keep the stacked layout but cap the control columns. */
@media not ((min-width: 700px) and (min-aspect-ratio: 9/10)) {
  .wc-top, .wc-bottom { max-width: 600px; }
  .bottom > .action-row, .bottom > .toolbar, .bottom > .status { max-width: 640px; }
}
.result-card { max-width: 560px; }
