@font-face {
  font-family: 'Fredoka'; font-style: normal; font-weight: 300 700; font-display: swap;
  src: url(/fonts/fredoka-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Fredoka'; font-style: normal; font-weight: 300 700; font-display: swap;
  src: url(/fonts/fredoka-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #eef1fb;
  --bg2: #f8f0ff;
  --card: #ffffff;
  --text: #1c2340;
  --muted: #6a7393;
  --line: #e0e5f3;
  --accent: #3478f6;
  --accent-edge: #1f56c4;
  --go: #19b05f;
  --go-edge: #0f8546;
  --good: #109658;
  --bad: #e0244a;
  --board-bg: #c9d2e8;
  --board-edge: #aab6d6;
  --cell: #f5f7fd;
  --btn-edge: #d5dcee;
  --shadow: 0 2px 4px rgba(30, 40, 90, .05), 0 10px 28px rgba(30, 40, 90, .10);
  --radius: 20px;
  --tile: 48px;
  --font: 'Fredoka', ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1222;
    --bg2: #1a1533;
    --card: #1b2138;
    --text: #edf0fb;
    --muted: #949cba;
    --line: #2c3456;
    --accent: #4d8bff;
    --accent-edge: #2a5fcc;
    --go: #22c06c;
    --go-edge: #138548;
    --good: #3fd28c;
    --bad: #ff5d7d;
    --board-bg: #0a0e1b;
    --board-edge: #05070f;
    --cell: #232b47;
    --btn-edge: #10152a;
    --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--muted) 18%, transparent) 1px, transparent 0) 0 0 / 22px 22px,
    linear-gradient(160deg, var(--bg), var(--bg2));
  background-color: var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 17px/1.4 var(--font);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input, a.btn { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
h1, h2 { margin: 0; font-weight: 700; }
b, strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.center { text-align: center; }
.boot { display: grid; place-items: center; height: 100vh; font: 700 2rem var(--font); letter-spacing: .3em; color: var(--muted); }

/* ---------- buttons & form controls ---------- */
.btn {
  --edge: var(--btn-edge);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 48px; padding: 0 18px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--card); color: var(--text);
  font-weight: 600; text-decoration: none; white-space: nowrap;
  box-shadow: 0 4px 0 var(--edge);
  transition: transform .08s, box-shadow .08s, background .15s, opacity .15s, filter .15s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.btn.primary { --edge: var(--accent-edge); background: var(--accent); border-color: transparent; color: #fff; }
.btn.alt { --edge: var(--go-edge); background: var(--go); border-color: transparent; color: #fff; }
.btn.big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.btn:disabled { opacity: .45; filter: saturate(.6); }
@media (hover: hover) { .btn:hover:not(:disabled) { filter: brightness(1.06); } }
.link { background: none; border: 0; color: var(--accent); padding: 8px; font-weight: 600; }
.icon {
  width: 46px; height: 46px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); font-size: 1.3rem; line-height: 1; display: inline-grid; place-items: center; padding: 0;
  box-shadow: 0 3px 0 var(--btn-edge); transition: transform .08s, box-shadow .08s, opacity .15s;
}
.icon:disabled { opacity: .38; }
.icon:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--btn-edge); }
.chip { border: 2px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 12px; font-size: .88rem; font-weight: 600; min-height: 36px; }
.chip:active { transform: scale(.95); }

input:not([type=checkbox]) {
  width: 100%; min-height: 48px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); padding: 0 14px; font-size: 17px; font-weight: 500; /* ≥16px stops iOS zoom-on-focus */
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.field { display: grid; gap: 6px; }
.field > span { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.seg { display: flex; background: var(--bg); border: 2px solid var(--line); border-radius: 14px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; min-height: 40px; border-radius: 10px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 2px 0 var(--btn-edge), 0 2px 8px rgba(0,0,0,.06); }
.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: grid; gap: 14px; }
.btns { display: grid; gap: 10px; }
.row2 { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.row2 .btn { flex: 1 1 140px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--c); flex: none; box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.avatar {
  flex: none; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 12px;
  background: linear-gradient(140deg, color-mix(in srgb, var(--c) 65%, white), var(--c) 60%, color-mix(in srgb, var(--c) 80%, black));
  color: #fff; font-weight: 700; font-size: 1.05rem; text-shadow: 0 1px 0 rgba(0,0,0,.25); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
}
.avatar.empty { background: transparent; border: 2px dashed color-mix(in srgb, var(--c) 55%, transparent); box-shadow: none; }

/* ---------- logo ---------- */
.logo { display: flex; justify-content: center; gap: 6px; font-size: 2.3rem; font-weight: 700; }
.logo span {
  display: grid; place-items: center; width: 1.4em; height: 1.4em; border-radius: .3em;
  background: linear-gradient(140deg, color-mix(in srgb, var(--c) 60%, white), var(--c) 55%, color-mix(in srgb, var(--c) 78%, black));
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.22);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), inset 0 3px 0 rgba(255,255,255,.25), 0 5px 12px color-mix(in srgb, var(--c) 35%, transparent);
  transform: rotate(calc((var(--i) - 2.5) * 2.5deg));
}
.logo.intro span { animation: letterDrop .7s cubic-bezier(.25, 1.6, .45, 1) both, wobble 3.2s ease-in-out infinite; animation-delay: calc(var(--i) * 80ms), calc(1s + var(--i) * 160ms); }
@keyframes letterDrop { from { transform: translateY(-120px) rotate(-30deg); opacity: 0; } }
@keyframes wobble { 0%, 85%, 100% { transform: rotate(calc((var(--i) - 2.5) * 2.5deg)); } 90% { transform: translateY(-6px) rotate(calc((var(--i) - 2.5) * -4deg)); } }

/* ---------- home ---------- */
.screen-home, .screen-lobby { min-height: var(--vh, 100dvh); position: relative; }
.floaters { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.floater {
  position: absolute; left: var(--x); top: var(--y); width: calc(70px * var(--s)); height: calc(70px * var(--s)); opacity: .22;
  animation: drift var(--d) ease-in-out infinite alternate;
}
.floater svg { width: 100%; height: 100%; }
@keyframes drift { from { transform: translate(0, 0) rotate(0deg); } to { transform: translate(18px, -34px) rotate(var(--r)); } }
.home {
  position: relative; z-index: 1;
  max-width: 440px; margin: 0 auto; display: grid; gap: 16px;
  padding: calc(30px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
}
.hero { display: grid; gap: 10px; margin-bottom: 6px; }
.tagline { text-align: center; margin: 4px 0 0; font-size: 1.12rem; font-weight: 500; color: var(--muted); animation: fade .8s .6s both; }
.tagline-sub { text-align: center; margin: -6px 0 0; font-style: italic; color: var(--muted); opacity: .75; animation: fade 1s 1.4s both; }
.me-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 16px; border-radius: 999px;
  background: var(--card); border: 2px solid var(--line); box-shadow: var(--shadow);
}
.me-row > span:first-child { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.me-row input { border: 0; min-height: 40px; padding: 0 4px; font-weight: 600; background: transparent; box-shadow: none !important; }
.me-row .pen { color: var(--muted); padding-right: 8px; }
.cta { display: grid; gap: 12px; }
.btn.huge { min-height: 76px; border-radius: 22px; justify-content: flex-start; padding: 0 20px; gap: 14px; font-size: 1.2rem; box-shadow: 0 6px 0 var(--edge); }
.btn.huge:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--edge); }
.btn.primary.huge { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.02); } }
.cta-ico { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: rgba(255,255,255,.22); font-size: 1.3rem; flex: none; }
.cta-txt { display: grid; text-align: left; line-height: 1.2; }
.cta-txt b { font-weight: 700; font-size: 1.25rem; }
.cta-txt small { font-size: .85rem; opacity: .88; font-weight: 500; }
.join { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 10px 10px 16px; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); }
.join-label { font-weight: 600; color: var(--muted); white-space: nowrap; }
.join input { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; min-width: 0; }
.opts { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 4px 16px; }
.opts summary { cursor: pointer; list-style: none; min-height: 46px; display: flex; align-items: center; gap: 6px; font-weight: 600; }
.opts summary::-webkit-details-marker { display: none; }
.opts summary::after { content: '▾'; margin-left: auto; color: var(--muted); transition: transform .2s; }
.opts[open] summary::after { transform: rotate(180deg); }
.opts-body { display: grid; gap: 14px; padding: 4px 0 14px; }
#optSum { font-weight: 500; font-size: .88rem; }
.links { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px; }

/* ---------- top bar ---------- */
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 10px; position: relative; z-index: 2;
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 8px calc(10px + var(--safe-l));
}
.tb-center { flex: 1; min-width: 0; text-align: center; font-size: 1.12rem; }
.tb-right { min-width: 46px; display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-left: auto; }
.status { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--c); margin-right: 8px; vertical-align: 0; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 30%, transparent); }
.myturn .turn-dot { animation: pulse 1.2s infinite; }
.myturn .status { color: color-mix(in srgb, var(--accent) 60%, var(--text)); }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--c) 0%, transparent); } }

/* ---------- lobby ---------- */
.lobby {
  position: relative; z-index: 1;
  max-width: 520px; margin: 0 auto; display: grid; gap: 14px;
  padding: 4px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
}
.invite { text-align: center; }
.bigcode { display: flex; justify-content: center; gap: 10px; }
.bigcode span {
  display: grid; place-items: center; width: 58px; height: 66px; border-radius: 16px; font-size: 2.2rem; font-weight: 700;
  color: #fff; background: linear-gradient(140deg, color-mix(in srgb, var(--c) 60%, white), var(--c) 55%, color-mix(in srgb, var(--c) 78%, black));
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), 0 4px 10px color-mix(in srgb, var(--c) 30%, transparent);
  text-shadow: 0 2px 0 rgba(0,0,0,.2);
  animation: letterDrop .6s cubic-bezier(.25, 1.6, .45, 1) both; animation-delay: calc(var(--i) * 90ms);
}
.url { font-weight: 500; color: var(--muted); word-break: break-all; }
.invite-btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.invite-btns .btn { flex: 1 1 140px; }
.seats { gap: 4px; }
.seat { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 4px 2px; border-bottom: 2px solid var(--line); animation: rise .3s both; }
.seat:last-of-type { border-bottom: 0; }
.sname { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.sname i { color: var(--muted); font-weight: 400; }
.sact { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tag { font-style: normal; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); margin-left: 4px; vertical-align: 2px; text-transform: uppercase; letter-spacing: .04em; }
.tag.me { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.tag.off { color: var(--bad); }
.lobby-start { display: grid; gap: 8px; justify-items: center; }
.waiting { text-align: center; margin: 8px 0; }
.dots::after { content: '…'; display: inline-block; animation: dots 1.4s steps(4) infinite; width: 0; overflow: hidden; vertical-align: bottom; text-align: left; }
@keyframes dots { to { width: 1.2em; } }

/* ---------- game ---------- */
.screen-game {
  height: var(--vh, 100dvh); overflow: hidden; overflow: clip; display: grid;
  grid-template-columns: 100%;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  grid-template-areas: "top" "players" "board" "controls" "tray";
  padding-bottom: var(--safe-b);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.players { grid-area: players; display: flex; gap: 6px; padding: 0 calc(8px + var(--safe-r)) 6px calc(8px + var(--safe-l)); }
.pchip {
  position: relative; flex: 1 1 0; min-width: 0; border-radius: 14px; padding: 5px 8px 6px 10px;
  background: var(--card); border: 2px solid var(--line); overflow: hidden;
  transition: box-shadow .25s, border-color .25s, transform .25s;
}
.pchip::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.pchip.turn { border-color: var(--c); transform: translateY(-2px); box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 55%, transparent), 0 6px 18px color-mix(in srgb, var(--c) 30%, transparent); }
.pchip.done { background: color-mix(in srgb, var(--good) 10%, var(--card)); }
.pname { display: flex; align-items: center; gap: 3px; font-weight: 600; font-size: .86rem; white-space: nowrap; }
.pn { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pchip.mine .pn { color: color-mix(in srgb, var(--c) 72%, var(--text)); }
.pstats { display: flex; gap: 6px; font-size: .8rem; white-space: nowrap; overflow: hidden; font-variant-numeric: tabular-nums; }
.pstats .ok { color: var(--good); font-weight: 600; }
.pstatus { flex: none; font-size: .75rem; margin-left: auto; }
.think { display: inline-flex; gap: 2px; }
.think i { width: 5px; height: 5px; border-radius: 50%; background: var(--c); animation: think 1s infinite; }
.think i:nth-child(2) { animation-delay: .15s; }
.think i:nth-child(3) { animation-delay: .3s; }
@keyframes think { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }
@media (max-width: 599px) { .screen-game:not(.wide) .pchip:not(.mine) .corners { display: none; } }
.pbar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: color-mix(in srgb, var(--c) 18%, transparent); }
.pbar i { display: block; height: 100%; background: var(--c); transition: width .25s linear; }

.board-wrap { grid-area: board; position: relative; display: grid; place-items: center; padding: 0 6px; }
#board { display: block; touch-action: none; border-radius: 16px; filter: drop-shadow(0 8px 20px rgba(30, 40, 90, .18)); overflow: visible; }
.board-wrap.thump #board { animation: thump .3s ease-out; }
@keyframes thump { 30% { transform: scale(.985); } }
#board .board-bg { fill: var(--board-bg); stroke: var(--board-edge); stroke-width: .08; }
#board .cell { fill: var(--cell); }
#board .tints { pointer-events: none; }
#board .blk.last > rect:first-child { stroke: #fff; stroke-width: .07; }
#board .blk.drop { animation: drop .45s cubic-bezier(.2, 1.5, .4, 1) both; transform-box: fill-box; transform-origin: center; }
@keyframes drop { 0% { transform: translateY(-1.4px) scale(1.35); opacity: 0; } 55% { opacity: 1; } }
#board .spark { animation: spark .6s ease-out both; transform-box: fill-box; transform-origin: center; }
@keyframes spark { 0% { opacity: 0; } 15% { opacity: 1; transform: translate(0, 0); } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.3); } }
#board .ring { stroke-width: .1; animation: ringOut .6s .1s ease-out both; transform-box: fill-box; transform-origin: center; }
@keyframes ringOut { from { opacity: .9; } to { opacity: 0; transform: scale(1.7); } }
#board .lift { filter: drop-shadow(0 .25px .2px rgba(0,0,0,.3)); }
#board .lift.ok .gcell { animation: ghost 1.1s ease-in-out infinite; }
@keyframes ghost { 50% { fill-opacity: .62; } }
#board .gcell { stroke-width: .08; fill-opacity: .88; }
#board .lift.bad .gcell { fill-opacity: .5; stroke-dasharray: .18 .12; }
#board .after { stroke-dasharray: .12 .08; opacity: .85; }
#board .spot { pointer-events: none; }
#board .spot .pulse { animation: spotPulse 1.2s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spotPulse { from { transform: scale(.7); opacity: 1; } to { transform: scale(1.45); opacity: 0; } }
#board .dot { opacity: .75; }
#board .start.mine path { animation: spin 5s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #board *, .logo span, .floater, .btn.primary.huge { animation: none !important; }
}

.controls { grid-area: controls; display: grid; gap: 6px; padding: 8px calc(8px + var(--safe-r)) 6px calc(8px + var(--safe-l)); }
.hint { text-align: center; font-size: .92rem; font-weight: 500; min-height: 1.35em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color .2s; }
.hint.good { color: var(--good); font-weight: 600; }
.hint.badtxt { color: var(--bad); }
#tipline { text-align: center; margin-top: -4px; }
.ctl-btns { display: flex; gap: 6px; justify-content: center; }
.ctl-btns .place { flex: 1; max-width: 220px; --edge: var(--go-edge); background: var(--go); color: #fff; border-color: transparent; font-size: 1.08rem; }
.ctl-btns .place.ready { animation: ready 1s ease-in-out infinite; }
@keyframes ready { 50% { box-shadow: 0 4px 0 var(--edge), 0 0 0 6px color-mix(in srgb, var(--go) 25%, transparent); } }
.spectator .controls .ctl-btns, .spectator #tipline { display: none; }

.tray {
  grid-area: tray; min-height: 0; overflow-x: auto; overflow-y: hidden;
  display: grid; grid-auto-flow: column; grid-auto-columns: var(--tile); grid-template-rows: repeat(2, var(--tile));
  gap: 6px; align-content: start; justify-content: safe center;
  padding: 4px calc(8px + var(--safe-r)) 8px calc(8px + var(--safe-l));
  touch-action: pan-x; overscroll-behavior: contain; scrollbar-width: thin;
}
.tile {
  position: relative; width: var(--tile); height: var(--tile); padding: 4px; border-radius: 12px;
  background: var(--card); border: 2px solid var(--line); touch-action: pan-x; box-shadow: 0 3px 0 var(--btn-edge);
  transition: transform .12s, box-shadow .12s, border-color .15s, opacity .25s;
}
.tile svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.tile.sel { border-color: var(--accent); box-shadow: 0 3px 0 var(--accent-edge), 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); transform: translateY(-3px) scale(1.04); }
.tile.used { opacity: .12; filter: grayscale(1); box-shadow: none; transform: scale(.85); }
.tile.nofit { opacity: .45; }
.tile.nofit::after { content: '✕'; position: absolute; right: 1px; top: -1px; font-size: .7rem; font-weight: 700; color: var(--bad); }
.tile:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--btn-edge); }

/* wide: board on the left at full height, everything else in a side panel */
.screen-game.wide {
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr);
  grid-template-areas: "board top" "board players" "board controls" "board tray";
}
.wide .board-wrap { align-self: center; padding: 8px 4px 8px calc(8px + var(--safe-l)); }
.wide .topbar { padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 6px 8px; }
.wide .players { flex-wrap: wrap; padding: 0 calc(12px + var(--safe-r)) 4px 8px; }
.wide .pchip { flex: 1 1 calc(50% - 6px); }
.wide .controls { padding: 6px calc(12px + var(--safe-r)) 8px 8px; }
.wide .tray {
  grid-auto-flow: row; grid-template-rows: none; grid-template-columns: repeat(auto-fill, var(--tile));
  overflow-x: hidden; overflow-y: auto; touch-action: pan-y; justify-content: center; align-content: start;
  padding: 6px calc(12px + var(--safe-r)) 12px 8px;
}
.wide .tile { touch-action: pan-y; }

/* stage: players | board | pieces — the board is the centrepiece */
.col-l, .col-r { display: contents; }
.screen-game.stage {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "left board right";
}
.stage .col-l, .stage .col-r { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.stage .col-l { grid-area: left; }
.stage .col-r { grid-area: right; }
.stage .players { flex: 1; min-height: 0; }
.stage .tray { flex: 1; min-height: 0; }
.stage .board-wrap { padding: 8px; }
.stage .topbar { flex-wrap: wrap; align-content: start; padding: calc(14px + var(--safe-t)) 8px 10px calc(16px + var(--safe-l)); }
.stage .tb-center { order: 3; flex-basis: 100%; text-align: left; font-size: 1.35rem; padding-top: 6px; }
.stage .status { white-space: normal; }
.stage .players { flex-direction: column; flex-wrap: nowrap; gap: 8px; overflow-y: auto; padding: 4px 8px 16px calc(16px + var(--safe-l)); }
.stage .pchip { flex: none; padding: 10px 12px 12px 16px; border-radius: 16px; }
.stage .pname { font-size: 1.05rem; }
.stage .pstats { font-size: .92rem; gap: 10px; }
.stage .controls { align-content: start; padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) 6px 8px; }
.stage .hint { white-space: normal; }
.stage .tray { padding: 8px calc(16px + var(--safe-r)) 16px 8px; }
@media (max-height: 520px) {
  .screen-game .topbar { padding-top: calc(4px + var(--safe-t)); padding-bottom: 4px; }
  .screen-game .topbar .icon { width: 40px; height: 40px; }
  .wide .players { flex-wrap: nowrap; }
  .wide .pchip { flex: 1 1 0; padding: 4px 6px 5px 9px; }
  .wide .pchip:not(.mine) .corners { display: none; }
  .wide .ctl-btns .icon { width: 42px; height: 42px; }
  .wide .ctl-btns .btn { min-height: 42px; }
  #tipline { display: none; }
  .screen-game.wide { --tile: 50px; }
}
@media (max-width: 360px) { .ctl-btns .icon { width: 42px; } }
@media (hover: hover) { .tile:hover:not(:disabled):not(.sel) { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); transform: translateY(-2px); } }

/* reactions */
.bubbles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bubble { position: absolute; bottom: 20%; display: grid; justify-items: center; gap: 2px; animation: floatUp 2.6s ease-out forwards; }
.bubble .be { font-size: 2.8rem; filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)); }
.bubble .bn { font-size: .78rem; font-weight: 600; background: var(--c); color: #fff; border-radius: 999px; padding: 1px 9px; }
@keyframes floatUp { 0% { transform: translateY(30px) scale(.6); opacity: 0; } 12% { transform: translateY(0) scale(1.15); opacity: 1; } 80% { opacity: 1; } 100% { transform: translateY(-160px) scale(1); opacity: 0; } }

/* moments: "Your turn!", "LOCKED IN!" */
.moment { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; pointer-events: none; }
.moment-inner {
  display: grid; justify-items: center; gap: 2px; padding: 14px 28px; border-radius: 24px;
  background: var(--c); color: #fff; text-align: center; text-shadow: 0 2px 0 rgba(0,0,0,.18);
  box-shadow: 0 8px 0 color-mix(in srgb, var(--c) 70%, black), 0 20px 50px rgba(0,0,0,.3);
  animation: momentIn .45s cubic-bezier(.2, 1.6, .4, 1) both;
}
.moment b { font-size: 1.9rem; font-weight: 700; letter-spacing: .02em; }
.moment.out .moment-inner { animation: momentOut .4s ease-in both; }
.moment.turn .moment-inner { padding: 10px 24px; }
.moment.turn b { font-size: 1.5rem; }
.moment.locked { background: rgba(10, 14, 30, .25); }
.moment.locked b { font-size: 2.4rem; }
.moment.locked small { font-size: 1rem; font-weight: 500; opacity: .95; max-width: 260px; }
.moment .lock { font-size: 3.4rem; animation: lockPop .6s .2s cubic-bezier(.2, 1.8, .4, 1) both; }
@keyframes momentIn { from { transform: scale(.3) rotate(-8deg); opacity: 0; } }
@keyframes momentOut { to { transform: scale(1.3); opacity: 0; } }
@keyframes lockPop { from { transform: scale(0) rotate(-40deg); } }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* results */
.results { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(10, 14, 30, .5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade .25s; }
.results.mini { inset: auto 0 calc(12px + var(--safe-b)) 0; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; pointer-events: none; }
.results.mini .btn { pointer-events: auto; }
.results .sheet { width: min(440px, 100%); animation: pop .5s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.trophy { text-align: center; font-size: 3.6rem; line-height: 1; margin-top: -4px; animation: trophy 1.6s .3s ease-in-out infinite; }
@keyframes trophy { 0%, 100% { transform: translateY(0) rotate(0); } 25% { transform: translateY(-6px) rotate(-8deg); } 75% { transform: translateY(-6px) rotate(8deg); } }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 16px; background: var(--bg); border: 2px solid var(--line); animation: slideIn .4s calc(.25s + var(--k) * .12s) cubic-bezier(.2, 1.3, .4, 1) both; }
.rank li.mine { border-color: var(--c); }
.rank li:first-child { background: color-mix(in srgb, var(--c) 16%, var(--card)); }
@keyframes slideIn { from { transform: translateX(-30px); opacity: 0; } }
.medal { width: 1.6em; text-align: center; font-size: 1.3rem; font-weight: 700; }
.rname { flex: 1; font-weight: 600; min-width: 0; display: grid; }
.rname, .rname small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rname small { font-weight: 500; color: var(--muted); font-size: .8rem; }
.rstat { text-align: right; white-space: nowrap; display: grid; }
.rstat b { font-size: 1.15rem; }
.rstat small { color: var(--muted); font-size: .78rem; }

/* modal sheets */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; justify-items: center; background: rgba(10, 14, 30, .5); animation: fade .16s; padding: 12px; padding-bottom: calc(12px + var(--safe-b)); }
.modal.closing { opacity: 0; transition: opacity .16s; }
.sheet {
  width: min(480px, 100%); max-height: calc(var(--vh, 100dvh) - 24px); overflow: auto; background: var(--card); border-radius: 26px;
  padding: 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); animation: rise .25s cubic-bezier(.2, 1.2, .3, 1);
}
.sheet h2 { text-align: center; font-size: 1.45rem; }
@media (min-width: 640px) { .modal { align-items: center; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } }
.rules { font-size: .98rem; }
.rules ol { padding-left: 1.2em; display: grid; gap: 8px; margin: 10px 0; }
.rules p { margin: 0; }
.rules .tip { margin-top: 10px; padding: 10px 12px; background: var(--bg); border-radius: 12px; font-size: .92rem; }
.menu { display: grid; gap: 8px; }
.menu-code { text-align: center; font-weight: 700; letter-spacing: .2em; font-size: 1.3rem; }
.mi { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg); font-weight: 500; text-align: left; }
.mi input { width: 20px; height: 20px; accent-color: var(--accent); }
.mi.danger { color: var(--bad); }
.menu .logo { font-size: 1.3rem; }
.emojis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.emojis button { font-size: 2.1rem; min-height: 66px; border-radius: 16px; border: 2px solid var(--line); background: var(--bg); transition: transform .1s; }
.emojis button:active { transform: scale(.88); }
.copybox { font-size: 14px; }

/* tutorial */
.tut { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; overflow: hidden; min-width: 0; }
.tut-track { display: flex; transition: transform .35s cubic-bezier(.3, 1.2, .4, 1); touch-action: pan-y; }
.tut-card { flex: 0 0 100%; min-width: 0; display: grid; gap: 8px; justify-items: center; text-align: center; padding: 4px 6px; }
.tut-card h2 { font-size: 1.6rem; }
.tut-card p { margin: 0; color: var(--muted); font-size: 1.02rem; max-width: 340px; min-height: 4.2em; }
.tut-card p b { color: var(--text); }
.tut-art { height: 170px; display: grid; place-items: center; }
.tut-art .duo { display: flex; gap: 14px; }
.mini { height: 160px; overflow: visible; }
.duo .mini { height: 130px; }
.mini .mbg { fill: var(--board-bg); }
.mini .mcell { fill: var(--cell); }
.mini text { font-family: system-ui, sans-serif; }
.tut-dots { display: flex; justify-content: center; gap: 8px; }
.tut-dots i { width: 9px; height: 9px; border-radius: 99px; background: var(--line); cursor: pointer; transition: width .25s, background .25s; }
.tut-dots i.on { width: 26px; background: var(--accent); }
.tut-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tut-nav .btn { flex: 1; max-width: 220px; }
#tutRules { justify-self: center; }
.a-slide { animation: aSlide 3s cubic-bezier(.3, 1.3, .5, 1) infinite; }
@keyframes aSlide { 0%, 10% { transform: translate(2.5px, 2.5px); opacity: .4; } 45%, 100% { transform: translate(0, 0); opacity: 1; } }
.a-check { animation: aCheck 3s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes aCheck { 0%, 48% { opacity: 0; transform: scale(.2); } 58%, 92% { opacity: 1; transform: scale(1); } 100% { opacity: 0; } }
.a-drop { animation: aDrop 3s cubic-bezier(.3, 1.5, .5, 1) infinite; }
.a-drop.bad rect:first-child { fill: #ef4444; }
@keyframes aDrop { 0%, 10% { transform: translateY(-1.5px); opacity: 0; } 45%, 100% { transform: translateY(0); opacity: 1; } }
.a-dot { animation: aDot 4s infinite; transform-box: fill-box; transform-origin: center; }
.a-dot.d1 { animation-delay: .6s; }
@keyframes aDot { 0%, 20% { opacity: 1; transform: scale(1); } 10% { transform: scale(1.4); } 35%, 100% { opacity: 0; } }
.a-fill { animation: aFill 4s cubic-bezier(.3, 1.5, .5, 1) infinite; }
.a-fill.f1 { animation-delay: .6s; }
@keyframes aFill { 0%, 22% { transform: translateY(-1.5px); opacity: 0; } 34%, 92% { transform: translateY(0); opacity: 1; } 100% { opacity: 0; } }
.a-lock { animation: aLock 4s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes aLock { 0%, 55% { opacity: 0; transform: scale(.2) rotate(-30deg); } 66%, 92% { opacity: 1; transform: scale(1) rotate(0); } 100% { opacity: 0; } }
.a-ring { animation: spotPulse 1.2s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.a-bulb { animation: aBulb 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes aBulb { 50% { transform: translateY(-.25px) rotate(10deg); } }

/* toast + connection banner */
#toast {
  position: fixed; left: 50%; top: calc(64px + var(--safe-t)); z-index: 40; transform: translate(-50%, -20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: .95rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s cubic-bezier(.2, 1.5, .4, 1); max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#conn {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); z-index: 50; transform: translate(-50%, 30px);
  background: #c0262d; color: #fff; padding: 10px 16px; border-radius: 16px; font-weight: 600; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; display: grid; gap: 4px; justify-items: center; text-align: center; max-width: calc(100% - 32px);
}
#conn.show { opacity: 1; transform: translate(-50%, 0); }
#conn small { font-weight: 400; opacity: .9; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; margin-right: 8px; vertical-align: -1px; }

/* ---------- glimpses: the voyeur layer ---------- */
#board .peek { pointer-events: none; animation: peekFlicker 3.4s infinite; transition: opacity .3s; }
#board .peek.gone { opacity: 0 !important; animation: none; }
#board .peek g rect { opacity: .55; }
#board .pk-edge { stroke-width: .05; stroke-dasharray: .1 .14; opacity: .75; }
#board .pk-eye { opacity: .9; }
@keyframes peekFlicker {
  0% { opacity: .8; } 9% { opacity: .35; } 11% { opacity: .75; } 37% { opacity: .55; }
  40% { opacity: .12; } 44% { opacity: .65; } 68% { opacity: .4; } 84% { opacity: .8; } 100% { opacity: .8; }
}
#board.heat-on .placed { opacity: .3; transition: opacity .4s; }
#board .heatmap { animation: fade .8s; }
.whisper {
  position: absolute; transform: translate(-50%, -130%); pointer-events: none; z-index: 3;
  font-style: italic; font-size: .92rem; color: var(--c); white-space: nowrap; letter-spacing: .02em;
  background: color-mix(in srgb, var(--card) 85%, transparent); padding: 3px 11px; border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,.14); animation: whisper 2.8s ease-out forwards;
}
@keyframes whisper { 0% { opacity: 0; transform: translate(-50%, -100%); filter: blur(3px); } 15% { opacity: .95; filter: blur(0); } 75% { opacity: .85; } 100% { opacity: 0; transform: translate(-50%, -200%); filter: blur(2px); } }
.heart { display: inline-block; color: var(--c); font-size: .95rem; line-height: 1; animation: heartbeat var(--beat, 1.3s) ease-in-out infinite; }
@keyframes heartbeat { 0%, 100% { transform: scale(1); } 14% { transform: scale(1.4); } 28% { transform: scale(1); } 42% { transform: scale(1.22); } 60% { transform: scale(1); } }
.eye {
  display: inline-flex; align-items: center; gap: 4px; height: 38px; padding: 0 11px; border-radius: 999px;
  background: var(--card); border: 2px solid var(--line); color: var(--muted); font-size: 1rem;
}
.eye::before { content: '👁'; display: inline-block; animation: blink 5s infinite; }
.eye b { font-weight: 600; font-size: .9rem; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
.peekbtn { border-style: dashed; }
.a-peek { animation: peekFlicker 2.6s infinite; }
.stage .ctl-btns { flex-wrap: wrap; }
.stage .ctl-btns .place { flex: 1 1 100%; max-width: none; }
.tray.spec { display: block; overflow: auto; }
.keyhole { margin: 8px auto; max-width: 420px; text-align: center; font-style: italic; color: var(--muted); line-height: 1.5; }
.keyhole::before { content: '👁'; display: block; font-style: normal; font-size: 1.8rem; animation: blink 5s infinite; }

/* ---------- corner pin, rotate handle, nope ---------- */
#board .pin { pointer-events: none; }
#board .pin circle { animation: pinPulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pinPulse { 50% { transform: scale(1.18); opacity: .7; } }
#board .rot-handle { filter: drop-shadow(0 .06px .12px rgba(0,0,0,.35)); animation: handleIn .25s cubic-bezier(.2, 1.6, .4, 1) both; transform-box: fill-box; }
#board .rot-handle text { font-family: system-ui, sans-serif; font-weight: 700; pointer-events: none; }
@keyframes handleIn { from { opacity: 0; } }
#board .lift.nope { animation: nope .35s ease-in-out; }
@keyframes nope { 20% { transform: translateX(-.18px); } 40% { transform: translateX(.18px); } 60% { transform: translateX(-.12px); } 80% { transform: translateX(.08px); } }
