/* Offline Arcade — shared styles (no external assets) */
:root {
  --bg: #0d1020;
  --panel: #161a2e;
  --panel-2: #1e2340;
  --line: #2b3157;
  --text: #eef0ff;
  --muted: #98a0c8;
  --p1: #ff5c7a;
  --p2: #3fc5ff;
  --accent: #ffd166;
  --good: #5be49b;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  color: var(--text);
  font-family: ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1100px 600px at 0% -10%, #2a1f55 0, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #0f3550 0, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.p1 { color: var(--p1); }
.p2 { color: var(--p2); }
.accent { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
kbd {
  display: inline-block; padding: 1px 6px; border-radius: 6px; font: 600 12px/1.6 ui-monospace, monospace;
  background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; color: var(--text);
}

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); text-decoration: none;
  cursor: pointer; font-weight: 600; font-size: 14px; transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: #4a5290; background: #262c52; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--p1), #ff8a5c); border-color: transparent; color: #1a0d14; }
.btn.secondary { background: linear-gradient(135deg, var(--p2), #6d8bff); border-color: transparent; color: #06141f; }

/* ---------- Home ---------- */
.home { max-width: 1100px; margin: 0 auto; padding: 36px 16px 48px; }
.hero { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.hero h1 { font-size: clamp(34px, 6vw, 58px); margin: 0; letter-spacing: -.02em; line-height: 1.05; }
.hero h1 span {
  background: linear-gradient(90deg, var(--p1), var(--accent), var(--p2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { margin: 0; color: var(--muted); font-size: 17px; max-width: 640px; line-height: 1.5; }
.badge {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: rgba(91, 228, 155, .12); color: var(--good); border: 1px solid rgba(91, 228, 155, .35);
  font-size: 13px; font-weight: 700;
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 10px var(--good); }
.filters { display: flex; gap: 8px; margin-top: 24px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; margin-top: 16px; }
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.card:hover { transform: translateY(-3px); border-color: #454d88; }
.card .emoji { font-size: 40px; line-height: 1; }
.card h2 { margin: 0; font-size: 20px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; flex: 1; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: #262b4d; color: var(--muted); }
.card .actions { display: flex; gap: 8px; margin-top: 4px; }
.card .actions .btn { flex: 1; justify-content: center; }
.home footer { color: var(--muted); font-size: 13px; margin-top: 36px; text-align: center; line-height: 1.7; }

/* ---------- Game page chrome ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 14px 16px; max-width: 1100px; margin: 0 auto;
}
.topbar h1 { margin: 0; font-size: 22px; flex: 1; min-width: 170px; white-space: nowrap; }
.back { text-decoration: none; color: var(--muted); font-weight: 700; padding: 8px 10px; border-radius: 10px; }
.back:hover { color: var(--text); background: var(--panel-2); }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg-btn {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer;
  color: var(--muted); font-weight: 700; font-size: 14px;
}
.seg-btn.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px #3d4580; }
.diff { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font: inherit; font-size: 14px;
}
.board-bar { max-width: 1100px; margin: 0 auto; padding: 0 16px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.scores { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; justify-content: center; }
.score {
  min-width: 96px; text-align: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px 14px;
}
.score .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 800; }
.score .value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score.p1 { border-color: rgba(255, 92, 122, .5); }
.score.p2 { border-color: rgba(63, 197, 255, .5); }
.score.accent { border-color: rgba(255, 209, 102, .5); }
.score.p1 .label { color: var(--p1); }
.score.p2 .label { color: var(--p2); }
.score.accent .label { color: var(--accent); }
.reset-scores { align-self: center; background: none; border: 0; color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; }
.status { min-height: 26px; font-size: 17px; font-weight: 600; text-align: center; }
.stage { display: flex; justify-content: center; align-items: flex-start; padding: 14px 16px; }
.help { max-width: 760px; margin: 0 auto; padding: 6px 16px 32px; color: var(--muted); font-size: 14px; text-align: center; line-height: 1.7; }

.overlay {
  position: fixed; inset: 0; background: rgba(5, 7, 16, .6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; animation: fade .2s;
}
.overlay.hidden { display: none; }
.modal {
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px; text-align: center; min-width: min(360px, 100%); box-shadow: var(--shadow);
  animation: pop .25s cubic-bezier(.2, 1.4, .4, 1);
}
.modal h2 { margin: 0 0 8px; font-size: 30px; }
.modal p { margin: 0 0 20px; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Tic-Tac-Toe ---------- */
.ttt { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(420px, 90vw, calc(100vh - 260px)); aspect-ratio: 1; }
.ttt-cell {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; font-weight: 900;
  font-size: min(96px, 18vw, calc((100vh - 260px) / 4)); cursor: pointer; display: flex; align-items: center; justify-content: center;
  line-height: 1; padding: 0; transition: background .15s;
}
.ttt-cell:hover { background: var(--panel-2); }
.ttt-cell.p1, .ttt-cell.p2 { cursor: default; }
.ttt-cell.p1 span, .ttt-cell.p2 span { animation: pop .22s; display: inline-block; }
.ttt-cell.win { background: rgba(255, 209, 102, .14); border-color: var(--accent); }

/* ---------- Connect Four ---------- */
.c4 {
  --s: min(64px, 11vw, calc((100vh - 290px) / 6));
  display: grid; grid-template-columns: repeat(7, var(--s)); gap: 7px; padding: 12px; border-radius: 18px;
  background: linear-gradient(180deg, #2c3cb0, #1d2a7e); box-shadow: var(--shadow), inset 0 2px 0 rgba(255, 255, 255, .15);
}
.c4-cell { width: var(--s); height: var(--s); border-radius: 50%; background: #0b0e1d; box-shadow: inset 0 3px 6px rgba(0, 0, 0, .6); cursor: pointer; position: relative; }
.c4-cell.hover { background: #1a2042; }
.c4-cell .disc { position: absolute; inset: 4px; border-radius: 50%; }
.c4-cell.p1 .disc { background: radial-gradient(circle at 35% 30%, #ffb0c0, var(--p1) 55%, #c4314f); }
.c4-cell.p2 .disc { background: radial-gradient(circle at 35% 30%, #b8ecff, var(--p2) 55%, #1a86b8); }
.c4-cell.drop .disc { animation: c4drop .38s ease-in; }
.c4-cell.win .disc { box-shadow: 0 0 0 4px var(--accent), 0 0 18px var(--accent); }
@keyframes c4drop {
  0% { transform: translateY(calc(var(--fall) * (-100% - 15px))); }
  75% { transform: translateY(0); }
  88% { transform: translateY(-8%); }
  100% { transform: translateY(0); }
}

/* ---------- Reversi ---------- */
.rv {
  --s: min(56px, 10.5vw, calc((100vh - 290px) / 8));
  display: grid; grid-template-columns: repeat(8, var(--s)); gap: 3px; padding: 8px; background: #0a3d2a;
  border-radius: 14px; box-shadow: var(--shadow);
}
.rv-cell { width: var(--s); height: var(--s); background: #14774f; border: 0; border-radius: 6px; position: relative; cursor: default; padding: 0; }
.rv-cell.hint { cursor: pointer; }
.rv-cell.hint::after { content: ''; position: absolute; inset: 38%; border-radius: 50%; background: rgba(255, 255, 255, .25); transition: inset .1s; }
.rv-cell.hint:hover::after { inset: 28%; background: rgba(255, 255, 255, .45); }
.rv-cell .disc { position: absolute; inset: 10%; border-radius: 50%; }
.rv-cell.b .disc { background: radial-gradient(circle at 35% 30%, #5a5a66, #111 62%); box-shadow: 0 3px 4px rgba(0, 0, 0, .5); }
.rv-cell.w .disc { background: radial-gradient(circle at 35% 30%, #fff, #d2d2dc 62%); box-shadow: 0 3px 4px rgba(0, 0, 0, .45); }
.rv-cell.flip .disc { animation: rvflip .35s; }
.rv-cell.placed .disc { animation: pop .22s; }
.rv-cell.last::before { content: ''; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); top: 4px; right: 4px; z-index: 1; }
@keyframes rvflip { 50% { transform: scaleX(.05); } }

/* ---------- Dots & Boxes ---------- */
.dots { --cell: min(70px, 13vw, calc((100vh - 320px) / 5)); --dot: 14px; display: grid; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.dots .dot { width: var(--dot); height: var(--dot); border-radius: 50%; background: #cfd5ff; z-index: 3; position: relative; }
.dots .ln { border: 0; padding: 0; background: transparent; cursor: pointer; position: relative; z-index: 2; }
.dots .ln::before { content: ''; position: absolute; border-radius: 4px; background: #2e355f; transition: background .15s; }
.dots .ln.h::before { left: -2px; right: -2px; top: 50%; height: 6px; transform: translateY(-50%); }
.dots .ln.v::before { top: -2px; bottom: -2px; left: 50%; width: 6px; transform: translateX(-50%); }
.dots .ln.h::after { content: ''; position: absolute; left: 0; right: 0; top: -12px; bottom: -12px; }
.dots .ln.v::after { content: ''; position: absolute; top: 0; bottom: 0; left: -12px; right: -12px; }
.dots .ln:hover::before { background: #6b73b4; }
.dots .ln.on { cursor: default; }
.dots .ln.on.p1::before { background: var(--p1); }
.dots .ln.on.p2::before { background: var(--p2); }
.dots .ln.last::before { box-shadow: 0 0 0 2px var(--accent), 0 0 12px var(--accent); }
.dots .box { display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: calc(var(--cell) * .38); border-radius: 6px; margin: 4px; }
.dots .box.p1 { background: rgba(255, 92, 122, .2); color: var(--p1); animation: pop .25s; }
.dots .box.p2 { background: rgba(63, 197, 255, .2); color: var(--p2); animation: pop .25s; }

/* ---------- Canvas games ---------- */
.canvas-wrap { position: relative; width: min(900px, 100%, calc((100vh - 250px) * var(--ar, 1.6))); }
canvas.game {
  width: 100%; height: auto; display: block; border-radius: 16px; border: 1px solid var(--line);
  background: #0a0d1a; box-shadow: var(--shadow); touch-action: none; user-select: none; -webkit-user-select: none;
}

/* ---------- Memory ---------- */
.mem { display: grid; gap: 10px; perspective: 900px; }
.mem-card { width: var(--s); height: var(--s); border: 0; padding: 0; background: transparent; cursor: pointer; }
.mem-card .inner { position: relative; width: 100%; height: 100%; transition: transform .4s; transform-style: preserve-3d; }
.mem-card.up .inner { transform: rotateY(180deg); }
.mem-card .face {
  position: absolute; inset: 0; border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; align-items: center; justify-content: center;
}
.mem-card .back {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .12) 0 18%, transparent 19%),
    linear-gradient(135deg, #3a2f7a, #1f4a7a);
  border: 1px solid #4b56a0;
}
.mem-card:hover .back { border-color: var(--accent); }
.mem-card .front { background: #f4f1ff; transform: rotateY(180deg); font-size: calc(var(--s) * .55); }
.mem-card.done { cursor: default; }
.mem-card.done .front { background: #e2fff0; }
.mem-card.done.p1 .front { box-shadow: inset 0 0 0 4px var(--p1); background: #ffe8ed; }
.mem-card.done.p2 .front { box-shadow: inset 0 0 0 4px var(--p2); background: #e3f6ff; }
.mem-card.miss .front { box-shadow: inset 0 0 0 4px #ff8a5c; }

@media (max-width: 560px) {
  .topbar h1 { font-size: 19px; }
  .score { min-width: 80px; padding: 5px 10px; }
  .score .value { font-size: 22px; }
}

/* ---------- Arcade (2000s) ---------- */
canvas.game.arcade {
  background: #05060d; border: 2px solid #3a2f7a;
  box-shadow: 0 0 0 4px #120f2a, 0 0 50px rgba(140, 90, 255, .3), var(--shadow);
}
.canvas-wrap.crt::after {
  content: ''; position: absolute; inset: 2px; border-radius: 14px; pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0) 0 2px, rgba(0, 0, 0, .22) 2px 3px),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 62%, rgba(0, 0, 0, .5) 100%);
}
.arcade-name .modal { border-color: var(--accent); box-shadow: 0 0 40px rgba(255, 209, 102, .25), var(--shadow); }
.neon-title {
  font-family: "Arial Black", Impact, system-ui, sans-serif; font-style: italic; letter-spacing: .02em;
  color: var(--accent); text-shadow: 0 0 12px rgba(255, 209, 102, .7);
}
.arcade-name input {
  font: 900 44px "Courier New", ui-monospace, monospace; width: 5.2ch; text-align: center; text-transform: uppercase;
  letter-spacing: .25em; padding: 8px 0 8px .25em; background: #05060d; color: var(--accent);
  border: 2px solid var(--accent); border-radius: 12px; outline: none; box-shadow: 0 0 18px rgba(255, 209, 102, .35) inset;
}
.arcade-name .hint { margin: 12px 0 18px; font-size: 13px; }
.card.arcade-card {
  background: linear-gradient(180deg, #24124a, #120b2a); border-color: #5a3aa8;
  box-shadow: 0 0 0 1px rgba(176, 107, 255, .15), 0 0 30px rgba(176, 107, 255, .18), var(--shadow);
}
.card.arcade-card h2 {
  font-family: "Arial Black", Impact, system-ui, sans-serif; font-style: italic; letter-spacing: .01em;
  background: linear-gradient(180deg, #fff, #ffd166 48%, #ff5c7a 52%, #fff); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.card.arcade-card .tag { background: #2e1a5c; color: #d9c8ff; }
.badge.new { background: rgba(255, 92, 122, .14); color: var(--p1); border-color: rgba(255, 92, 122, .4); }
.badge.new .dot { background: var(--p1); box-shadow: 0 0 10px var(--p1); }
.section-title { display: flex; align-items: center; gap: 10px; margin: 34px 0 0; font-size: 22px; }
.section-title small { font-size: 14px; color: var(--muted); font-weight: 500; }

/* ---------- Quiz Blitz ---------- */
.quiz { width: min(820px, 100%); }
.qz-intro, .qz-play {
  position: relative; border-radius: 22px; padding: 26px clamp(16px, 4vw, 34px); overflow: hidden;
  background:
    radial-gradient(600px 260px at 50% -40px, rgba(120, 140, 255, .35), transparent 70%),
    radial-gradient(400px 300px at 0% 100%, rgba(176, 107, 255, .25), transparent 70%),
    radial-gradient(400px 300px at 100% 100%, rgba(63, 197, 255, .2), transparent 70%),
    linear-gradient(180deg, #120d3a, #070b26);
  border: 1px solid #3d3a8a; box-shadow: 0 0 50px rgba(90, 80, 255, .25), var(--shadow);
}
.qz-intro { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.qz-logo { display: flex; flex-direction: column; line-height: .92; transform: skewX(-8deg); }
.qz-logo span {
  font: italic 900 clamp(46px, 10vw, 84px) "Arial Black", Impact, system-ui, sans-serif; letter-spacing: .02em;
  background: linear-gradient(180deg, #fff 0%, #ffd166 45%, #b36b00 52%, #ffe9a8 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 209, 102, .45)) drop-shadow(0 4px 0 #2a1460);
}
.qz-logo span + span { background-image: linear-gradient(180deg, #fff 0%, #3fc5ff 45%, #1a4fb8 52%, #bfe9ff 100%); filter: drop-shadow(0 0 14px rgba(63, 197, 255, .5)) drop-shadow(0 4px 0 #2a1460); }
.qz-logo.small span { font-size: clamp(36px, 7vw, 56px); }
.qz-sub { color: #c9cdf5; font-weight: 600; margin: 0; }
.qz-how { text-align: left; color: #c9cdf5; line-height: 1.8; margin: 4px 0; padding-left: 20px; max-width: 560px; }
.qz-start { font-size: 18px; padding: 13px 26px; }
.qz-hint { color: var(--muted); font-size: 13px; }
.qz-hs { width: min(320px, 100%); background: rgba(0, 0, 0, .25); border: 1px solid #3d3a8a; border-radius: 14px; padding: 10px 16px; }
.qz-hs h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); }
.qz-hs div { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; font: 700 15px "Courier New", ui-monospace, monospace; padding: 2px 0; }
.qz-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 700; color: #c9cdf5; }
.qz-cat { padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, .08); border: 1px solid #3d3a8a; font-size: 14px; }
.qz-pts b { font-size: 20px; color: #fff; }
.qz-timer { position: relative; height: 12px; margin: 16px 0 6px; border-radius: 999px; background: rgba(0, 0, 0, .4); border: 1px solid #3d3a8a; }
.qz-bar { height: 100%; width: 100%; border-radius: 999px; background: linear-gradient(90deg, #5be49b, #3fc5ff); box-shadow: 0 0 12px rgba(63, 197, 255, .6); transition: width .1s linear; }
.qz-bar.hot { background: linear-gradient(90deg, #ff5c7a, #ff9f43); box-shadow: 0 0 14px rgba(255, 92, 122, .8); }
.qz-secs { position: absolute; right: 0; top: 16px; font: 900 15px "Courier New", ui-monospace, monospace; color: #fff; }
.qz-question {
  margin: 26px 0 20px; padding: 22px 28px; text-align: center; font-size: clamp(19px, 2.7vw, 26px); font-weight: 800; line-height: 1.3;
  background: linear-gradient(180deg, #1b1f6b, #0b0f3d); border: 2px solid #8f9cff; border-radius: 18px;
  box-shadow: 0 0 22px rgba(120, 140, 255, .45), inset 0 0 30px rgba(0, 0, 0, .4);
}
.qz-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.qz-ans {
  display: flex; align-items: center; gap: 12px; text-align: left; padding: 15px 18px; border-radius: 999px; cursor: pointer;
  background: linear-gradient(180deg, #1b1f6b, #0b0f3d); border: 2px solid #5b66c9; color: #fff; font-size: 17px; font-weight: 700;
  transition: transform .08s, border-color .15s, background .2s, opacity .2s; min-height: 58px;
}
.qz-ans b { color: var(--accent); font-size: 18px; min-width: 20px; }
.qz-ans:not(:disabled):hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 0 16px rgba(255, 209, 102, .35); }
.qz-ans:disabled { cursor: default; }
.qz-ans.idle { opacity: .75; }
.qz-ans.p1:not(:disabled) { border-color: var(--p1); }
.qz-ans.p2:not(:disabled) { border-color: var(--p2); }
.qz-ans.gone { opacity: .15; }
.qz-ans.correct { background: linear-gradient(180deg, #2fd17e, #138a4c); border-color: #b9ffd8; animation: qzflash .45s 2; opacity: 1; }
.qz-ans.correct b { color: #fff; }
.qz-ans.wrong { background: linear-gradient(180deg, #ff6b6b, #a61e3a); border-color: #ffc2cc; opacity: 1; }
@keyframes qzflash { 50% { filter: brightness(1.5); } }
.qz-msg { min-height: 30px; margin: 16px 0 6px; text-align: center; font-size: 17px; font-weight: 700; color: #c9cdf5; }
.qz-msg.good { color: #8affc1; }
.qz-msg.bad { color: #ffb3c0; }
.qz-foot { display: flex; justify-content: center; gap: 14px; }
.qz-foot.duo { justify-content: space-between; }
.qz-buzzer {
  flex: 1; max-width: 260px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px; border-radius: 18px; cursor: pointer;
  background: rgba(0, 0, 0, .3); border: 2px solid currentColor; font-weight: 800; transition: transform .08s, box-shadow .2s, opacity .2s;
}
.qz-buzzer.p1 { color: var(--p1); }
.qz-buzzer.p2 { color: var(--p2); }
.qz-buzzer:active { transform: scale(.97); }
.qz-buzzer .qz-bname { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; }
.qz-buzzer .qz-bscore { font-size: 32px; color: #fff; font-variant-numeric: tabular-nums; }
.qz-buzzer .qz-bkey { font-size: 12px; opacity: .85; }
.qz-buzzer.lit { background: currentColor; box-shadow: 0 0 34px currentColor; animation: pop .25s; }
.qz-buzzer.lit span { color: #0b0820 !important; }
.qz-buzzer.locked { opacity: .35; }
.qz-final { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.qz-final > div { min-width: 140px; padding: 14px 18px; border-radius: 16px; background: rgba(0, 0, 0, .3); border: 1px solid #3d3a8a; font: 900 40px "Courier New", ui-monospace, monospace; color: #fff; }
.qz-final > div.p1 { border-color: var(--p1); }
.qz-final > div.p2 { border-color: var(--p2); }
.qz-final > div.accent { border-color: var(--accent); }
.qz-final small { display: block; font: 800 12px system-ui, sans-serif; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
@media (max-width: 600px) {
  .qz-answers { grid-template-columns: 1fr; }
  .qz-question { margin: 18px 0 14px; padding: 16px; }
}
.btn:disabled { opacity: .4; cursor: default; }

/* =========================================================
   Mobile & touch
   ========================================================= */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, a, select { -webkit-tap-highlight-color: transparent; }
.canvas-wrap { width: min(900px, 100%, calc((100dvh - var(--chrome, 250px)) * var(--ar, 1.6))); }
body.has-pad { --chrome: 400px; }
.stage, .pads { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* on-screen gamepad */
.pads { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; max-width: 900px; margin: 0 auto; padding: 4px 14px 10px; }
.pads.solo .pad { flex: 1; justify-content: space-between; }
.pad { display: flex; align-items: flex-end; gap: 12px; }
.dpad { --b: 58px; display: grid; grid-template-columns: repeat(3, var(--b)); grid-template-rows: repeat(3, var(--b)); gap: 4px; }
.pads.duo .dpad { --b: 46px; }
.dpad .d-up { grid-area: 1 / 2; } .dpad .d-left { grid-area: 2 / 1; } .dpad .d-right { grid-area: 2 / 3; } .dpad .d-down { grid-area: 3 / 2; }
.acts { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.pad-btn {
  border: 2px solid #3d4580; background: linear-gradient(180deg, #262c52, #161a2e); color: var(--text);
  border-radius: 14px; font: 800 20px system-ui, sans-serif; padding: 0; cursor: pointer;
  touch-action: none; box-shadow: 0 4px 0 #0a0c1a, 0 6px 14px rgba(0, 0, 0, .35); transition: transform .05s, background .1s;
}
.pad-btn.act { width: 86px; height: 86px; border-radius: 50%; font-size: 15px; letter-spacing: .04em; }
.pad-btn.act.small { width: 60px; height: 60px; font-size: 13px; }
.pads.duo .pad-btn.act { width: 62px; height: 62px; font-size: 12px; }
.pads.duo .pad-btn.act.small { width: 50px; height: 50px; font-size: 11px; }
.pad-btn.on { transform: translateY(3px); box-shadow: 0 1px 0 #0a0c1a; background: #343c70; }
.pad.p1 .pad-btn { border-color: rgba(255, 92, 122, .7); }
.pad.p2 .pad-btn { border-color: rgba(63, 197, 255, .7); }
.pad.p1 .pad-btn.on { background: rgba(255, 92, 122, .45); }
.pad.p2 .pad-btn.on { background: rgba(63, 197, 255, .45); }
.pad:not(.p1):not(.p2) .pad-btn.act { border-color: rgba(255, 209, 102, .7); color: var(--accent); }
.pad-toggle.active { border-color: var(--accent); color: var(--accent); }

/* phones, portrait */
@media (max-width: 640px) {
  .topbar { padding: 8px 10px; gap: 6px 8px; }
  .topbar h1 { font-size: 17px; min-width: 0; flex: 1; }
  .back { padding: 6px 6px; font-size: 14px; }
  .controls { width: 100%; gap: 6px; }
  .controls .btn { padding: 7px 9px; font-size: 13px; }
  .seg-btn { padding: 6px 9px; font-size: 13px; }
  .select { padding: 6px 6px; font-size: 13px; }
  .diff > span { display: none; }
  .board-bar { gap: 6px; padding: 0 8px; }
  .scores { gap: 6px; }
  .score { min-width: 68px; padding: 3px 8px; border-radius: 10px; }
  .score .label { font-size: 9.5px; }
  .score .value { font-size: 19px; }
  .status { font-size: 14px; min-height: 20px; }
  .stage { padding: 8px 6px; }
  .help { font-size: 12.5px; padding: 4px 12px 24px; }
  .home { padding: 22px 14px 40px; }
  .grid { gap: 12px; }
  .card { padding: 14px; }
  .modal { padding: 22px 16px; }
  .modal h2 { font-size: 24px; }
  canvas.game { border-radius: 10px; }
  .canvas-wrap.crt::after { border-radius: 8px; }
  body.has-pad .help { display: none; }
  .ttt, .c4, .rv, .dots { max-width: 100%; }
  .dots { padding: 10px; --cell: min(52px, 12.5vw); }
}

/* phones, landscape: game in the middle, controls float on the sides */
@media (orientation: landscape) and (max-height: 520px) {
  body { --chrome: 120px; }
  body.has-pad { --chrome: 96px; }
  .topbar { padding: 4px 12px; gap: 6px 10px; flex-wrap: nowrap; }
  .topbar h1 { font-size: 16px; }
  .controls { flex-wrap: nowrap; gap: 6px; }
  .controls .btn, .seg-btn, .select { padding: 5px 8px; font-size: 12px; }
  .diff > span { display: none; }
  .board-bar { flex-direction: row; justify-content: center; gap: 12px; }
  .score { padding: 1px 8px; min-width: 60px; }
  .score .label { font-size: 9px; }
  .score .value { font-size: 16px; }
  .reset-scores { display: none; }
  .status { font-size: 13px; min-height: 0; }
  .stage { padding: 4px 6px; }
  .help { display: none; }
  .pads { position: fixed; left: 0; right: 0; bottom: max(8px, env(safe-area-inset-bottom)); padding: 0 max(12px, env(safe-area-inset-left)); pointer-events: none; max-width: none; z-index: 20; }
  .pads .pad-btn { pointer-events: auto; opacity: .82; }
  .pads.solo .pad { justify-content: space-between; }
  .dpad { --b: 50px; }
  .pads.duo .dpad { --b: 42px; }
  .ttt { width: min(420px, calc(100dvh - 130px)); }
  .c4 { --s: min(56px, calc((100dvh - 150px) / 6)); }
  .rv { --s: min(50px, calc((100dvh - 140px) / 8)); }
  .dots { --cell: min(60px, calc((100dvh - 170px) / 5)); padding: 10px; }
}

/* installed-app (standalone) niceties */
.standalone .back { padding-left: 4px; }

/* =========================================================
   Home: offline status + install banner
   ========================================================= */
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 6px; }
.offline-chip { font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); }
.offline-chip.ok { color: var(--good); border-color: rgba(91, 228, 155, .45); background: rgba(91, 228, 155, .1); }
.offline-chip.busy { color: var(--accent); border-color: rgba(255, 209, 102, .45); }
.install-banner {
  position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 40; display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 16px; background: linear-gradient(180deg, #262c52, #161a2e); border: 1px solid #4a5290; box-shadow: var(--shadow);
  animation: pop .3s; max-width: 560px; margin: 0 auto;
}
.install-banner .ib-text { flex: 1; font-size: 14px; line-height: 1.35; }
.install-banner .ib-text b { display: block; font-size: 15px; }
.install-banner .x { background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; padding: 4px 6px; }

/* =========================================================
   Install / "Play on your phone" page
   ========================================================= */
.install { max-width: 880px; margin: 0 auto; padding: 22px 16px 60px; }
.install .back { display: inline-block; margin-bottom: 8px; }
.install h1 { font-size: clamp(28px, 6vw, 44px); margin: 4px 0 6px; letter-spacing: -.02em; }
.install .lead { color: var(--muted); font-size: 16px; line-height: 1.55; margin: 0 0 20px; max-width: 680px; }
.ic { background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.ic h2 { margin: 0 0 10px; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.ic h2 .n { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #1a1406; font-size: 15px; flex: none; }
.ic p, .ic li { color: #c9cdf5; line-height: 1.6; font-size: 15px; }
.ic ol { padding-left: 22px; margin: 8px 0 0; }
.ic li { margin: 4px 0; }
.status-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.status-big { font-size: 18px; font-weight: 800; }
.status-big.ok { color: var(--good); }
.status-big.warn { color: var(--accent); }
.status-big.bad { color: var(--p1); }
.progress { height: 10px; border-radius: 999px; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); overflow: hidden; margin: 10px 0 4px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--good), var(--p2)); transition: width .25s; }
.qr-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.qr-box { background: #fff; border-radius: 14px; padding: 12px; width: 212px; height: 212px; flex: none; display: flex; align-items: center; justify-content: center; }
.qr-box svg { width: 100%; height: 100%; display: block; }
.url-box { font: 700 15px ui-monospace, Menlo, monospace; word-break: break-all; padding: 10px 12px; background: rgba(0, 0, 0, .3); border: 1px solid var(--line); border-radius: 10px; margin: 8px 0 10px; }
.tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 10px; }
.tab-panel[hidden] { display: none; }
.ios-share { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; }
.kbd-ish { display: inline-block; padding: 1px 8px; border-radius: 7px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; font-size: 13px; color: var(--text); white-space: nowrap; }
.callout { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 209, 102, .08); border: 1px solid rgba(255, 209, 102, .35); color: #f3e3b4; font-size: 14px; line-height: 1.5; }
.callout.good { background: rgba(91, 228, 155, .08); border-color: rgba(91, 228, 155, .35); color: #c6f5dc; }
.host-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-top: 10px; }
.host-grid > div { background: rgba(0, 0, 0, .22); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 14px; color: #c9cdf5; line-height: 1.5; }
.host-grid b { color: var(--text); }
.host-grid code, .ic code { font: 600 12.5px ui-monospace, Menlo, monospace; background: rgba(0, 0, 0, .35); padding: 2px 6px; border-radius: 6px; color: var(--accent); word-break: break-all; }
details.faq { border-top: 1px solid var(--line); padding: 10px 0; }
details.faq summary { cursor: pointer; font-weight: 700; color: var(--text); }
details.faq p { margin: 8px 0 0; }
[hidden] { display: none !important; }
@media (orientation: landscape) and (max-height: 520px) {
  body.has-pad { --chrome: 150px; }
}

/* ---------- Quiz Blitz: topic downloads ---------- */
.qz-dl { width: min(560px, 100%); text-align: left; background: rgba(0, 0, 0, .25); border: 1px solid #4b56a0; border-radius: 16px; padding: 16px; margin-top: 6px; }
.qz-dl h3 { margin: 0 0 4px; font-size: 17px; }
.qz-dl-sub { margin: 0 0 12px; color: #c9cdf5; font-size: 14px; line-height: 1.5; }
.qz-dl-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.qz-dl-row input {
  flex: 1; min-width: 0; font: 600 16px system-ui, sans-serif; padding: 11px 12px; border-radius: 10px;
  border: 1px solid #5b66c9; background: #0b0f3d; color: #fff; outline: none;
}
.qz-dl-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 209, 102, .2); }
.qz-dl-row .qz-go { flex: 1; justify-content: center; min-width: 170px; }
.qz-dl-note { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.qz-dl-msg { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.qz-dl-msg.good { background: rgba(91, 228, 155, .1); border: 1px solid rgba(91, 228, 155, .4); color: #c6f5dc; }
.qz-dl-msg.bad { background: rgba(255, 92, 122, .1); border: 1px solid rgba(255, 92, 122, .4); color: #ffc9d3; }
.qz-packs { margin-top: 14px; border-top: 1px solid #3d3a8a; padding-top: 10px; }
.qz-packs-h { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 800; margin-bottom: 6px; }
.qz-pack { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(61, 58, 138, .5); }
.qz-pack:last-child { border-bottom: 0; }
.qz-pack-e { font-size: 26px; width: 34px; text-align: center; }
.qz-pack-t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.qz-pack-t b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qz-pack-t small { color: var(--muted); font-size: 12px; }
.qz-pack .btn { padding: 7px 10px; }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, .25); border-top-color: #1a0d14; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.qz-fact { margin: 10px auto 0; max-width: 620px; padding: 10px 14px; border-radius: 12px; background: rgba(255, 209, 102, .1); border: 1px solid rgba(255, 209, 102, .35); color: #f6e7b8; font-size: 15px; font-weight: 600; line-height: 1.45; text-align: left; }
.qz-next { margin-top: 10px; }

/* ---------- Quiz Blitz: fixed layout (no shifting between questions / on reveal) ---------- */
.qz-question { height: 132px; margin: 22px 0 16px; padding: 14px 24px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.qz-ans { height: 60px; min-height: 0; overflow: hidden; }
.qz-ans .qz-fit { display: block; line-height: 1.2; }
.qz-feedback { margin: 14px 0 10px; }
.qz-msg { height: 50px; margin: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; line-height: 1.25; }
.qz-fact { display: none; height: 88px; margin: 6px auto 0; padding: 8px 14px; align-items: center; overflow: hidden; }
.qz-play.with-facts .qz-fact { display: flex; visibility: hidden; }
.qz-play.with-facts .qz-fact.show { visibility: visible; }
.qz-fit { display: block; max-width: 100%; }
.qz-foot { min-height: 52px; align-items: center; justify-content: center; gap: 12px; }
.qz-foot.duo { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; }
.qz-foot.duo .qz-buzzer { max-width: none; }
.qz-next { visibility: hidden; min-width: 110px; justify-content: center; }
.qz-next.show { visibility: visible; animation: pop .2s; }
@media (max-width: 600px) {
  .qz-question { height: 118px; margin: 14px 0 12px; padding: 10px 14px; }
  .qz-ans { height: 52px; padding: 10px 16px; font-size: 16px; }
  .qz-answers { gap: 9px; }
  .qz-msg { height: 46px; font-size: 15px; }
  .qz-fact { height: 84px; font-size: 14px; }
  .qz-foot.duo .qz-next { min-width: 0; padding: 9px 12px; }
  .qz-buzzer { padding: 10px 6px; }
}
.qz-fact { overflow-y: auto; overscroll-behavior: contain; }
.qz-fact .qz-fit { margin: auto 0; }

/* =========================================================
   Game layout v2: one fixed screen, no layout shift.
   Top bar and score strip have fixed heights; the stage gets the rest
   and exposes its size as --sw / --sh (set by js/common.js) so each game fits.
   ========================================================= */
body.game-page {
  height: 100vh; height: 100dvh; overflow: hidden;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
}
body.game-page .topbar {
  display: flex; flex-wrap: nowrap; align-items: center; gap: 6px;
  height: 52px; padding: 0 12px; width: 100%; max-width: 1100px; margin: 0 auto;
}
.topbar h1 { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 20px; white-space: nowrap; overflow: hidden; }
.topbar .t-name { overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex: none; width: 38px; height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font: 700 18px system-ui, sans-serif; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: #262c52; border-color: #4a5290; }
.topbar .back.icon-btn { padding: 0; color: var(--text); }
.topbar .seg { flex: none; }
.seg-btn .sm { display: none; }
.menu-wrap { position: relative; flex: none; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 230px;
  display: flex; flex-direction: column; gap: 2px; padding: 6px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid #3d4580; border-radius: 14px; box-shadow: var(--shadow);
}
.menu[hidden] { display: none !important; }
.menu-item { text-align: left; background: none; border: 0; color: var(--text); padding: 10px 12px; border-radius: 10px; font: 600 15px system-ui, sans-serif; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: #262c52; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; font: 600 14px system-ui, sans-serif; color: var(--muted); }

/* score strip: scores on the left never move; status text fills the rest and is clipped, never wrapped */
body.game-page .board-bar {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 12px;
  height: 48px; padding: 0 12px; width: 100%; max-width: 1100px; margin: 0 auto; overflow: hidden;
}
body.game-page .scores { flex-wrap: nowrap; justify-content: flex-start; gap: 6px; }
body.game-page .score { width: 84px; min-width: 0; padding: 3px 6px; border-radius: 10px; overflow: hidden; }
body.game-page .score .label { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.game-page .score .value { font-size: 19px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.game-page .status { min-height: 0; height: 22px; line-height: 22px; font-size: 15px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

body.game-page .stage { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px 12px 12px; overflow: hidden; }
body.game-page .stage.scroll { overflow-y: auto; align-items: flex-start; overscroll-behavior: contain; }
body.game-page .help { display: none; }

/* every game sizes itself from the measured stage */
body.game-page .canvas-wrap { width: min(1100px, var(--sw), calc(var(--sh) * var(--ar, 1.6))); }
body.game-page .ttt { width: min(460px, var(--sw), var(--sh)); }
body.game-page .ttt-cell { font-size: calc(min(460px, var(--sw), var(--sh)) / 4.2); }
body.game-page .c4 { --s: min(72px, calc((var(--sw) - 66px) / 7), calc((var(--sh) - 59px) / 6)); }
body.game-page .rv { --s: min(64px, calc((var(--sw) - 37px) / 8), calc((var(--sh) - 37px) / 8)); }
body.game-page .dots { --cell: min(80px, calc((min(var(--sw), var(--sh)) - 124px) / 5)); padding: 18px; }
body.game-page .quiz { margin: 0 auto; }

/* help panel */
.help-modal { width: min(560px, 100%); text-align: left; max-height: min(82dvh, 680px); display: flex; flex-direction: column; }
.help-modal h2 { font-size: 24px; }
.help-body { overflow-y: auto; color: #c9cdf5; line-height: 1.7; font-size: 15px; margin-bottom: 18px; overscroll-behavior: contain; }
.help-body ul { margin: 6px 0; padding-left: 20px; }
.help-ov { z-index: 70; }

/* phones */
@media (max-width: 640px) {
  .seg-btn .lg { display: none; }
  .seg-btn .sm { display: inline; }
  body.game-page .topbar { height: 46px; padding: 0 8px; gap: 5px; }
  .icon-btn { width: 34px; height: 34px; font-size: 16px; }
  .topbar h1 { font-size: 16px; gap: 6px; }
  body.game-page .board-bar { height: 42px; gap: 8px; padding: 0 8px; }
  body.game-page .score { width: 70px; padding: 2px 5px; }
  body.game-page .score .label { font-size: 9px; }
  body.game-page .score .value { font-size: 16px; }
  body.game-page .status { font-size: 13px; }
  body.game-page .stage { padding: 4px 6px 8px; }
  body.game-page .dots { padding: 10px; --cell: min(80px, calc((min(var(--sw), var(--sh)) - 108px) / 5)); }
}
/* phones sideways: slimmer bars; touch pads float at the sides, so keep the game between them */
@media (orientation: landscape) and (max-height: 520px) {
  body.game-page .topbar { height: 40px; padding: 0 10px; }
  .icon-btn { width: 32px; height: 32px; font-size: 15px; }
  .seg-btn .lg { display: none; }
  .seg-btn .sm { display: inline; }
  body.game-page .board-bar { height: 34px; }
  body.game-page .score { width: 96px; padding: 1px 6px; display: flex; align-items: baseline; gap: 4px; }
  body.game-page .score .label { font-size: 8px; }
  body.game-page .score .value { font-size: 14px; }
  body.game-page .stage { padding: 2px 8px 6px; }
  body.game-page.has-pad .stage { padding-left: 196px; padding-right: 196px; }
}

/* Tic-Tac-Toe: fixed rows, so marks never resize cells */
body.game-page .ttt { grid-template-rows: repeat(3, minmax(0, 1fr)); }
body.game-page .ttt-cell { min-height: 0; overflow: hidden; line-height: 1; }
/* install page: reserve space for live status so nothing jumps when it fills in */
#st-title { min-height: 1.6em; }
#st-text { min-height: 3.2em; }
#st-progress[hidden] { display: block !important; visibility: hidden; }
#status-card .hero-actions { min-height: 42px; }
.offline-chip { min-width: 15.5em; text-align: center; }

/* "New version ready" pill: floats over the page, never moves the layout */
.update-toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 58px); z-index: 90;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border-radius: 999px;
  background: linear-gradient(180deg, #262c52, #161a2e); border: 1px solid var(--accent); box-shadow: 0 0 24px rgba(255, 209, 102, .25), var(--shadow);
  font-weight: 700; font-size: 15px; white-space: nowrap; animation: fade .25s;
}
.update-toast .btn { padding: 7px 14px; }
.update-toast .x { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; padding: 2px 8px; }
.menu-version { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; margin-top: 4px; padding-top: 12px; }

/* ---------- Nothing hidden: fit, wrap or scroll instead of clipping ---------- */
/* long numbers / labels shrink inside the same fixed-size box */
body.game-page .score.long .value { font-size: 15px; }
body.game-page .score.long-label .label { letter-spacing: 0; }
/* pop-ups: centred when they fit, start at the top and scroll when they don't (e.g. keyboard open) */
.overlay { overflow-y: auto; align-items: flex-start; justify-content: flex-start; overscroll-behavior: contain; }
.overlay > .modal { margin: auto; }
/* game area: scrolls (instead of clipping) if a game is ever larger than the space */
body.game-page .stage { overflow: auto; }
/* menus never run off a short screen */
.menu { max-height: calc(100dvh - 64px); overflow-y: auto; overscroll-behavior: contain; }

/* portrait phones: status gets its own full-width line (up to 2 lines) under the score boxes */
@media (max-width: 640px) and (orientation: portrait) {
  body.game-page .board-bar { grid-template-columns: minmax(0, 1fr); grid-template-rows: 40px 34px; row-gap: 2px; height: 78px; justify-items: center; }
  body.game-page .scores { justify-content: center; }
  body.game-page .status {
    height: 34px; line-height: 17px; font-size: 13px; text-align: center; white-space: normal; text-overflow: clip;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; width: 100%;
  }
  body.game-page .score.long .value { font-size: 13px; }
}
/* phones sideways: label above the number so "Hi-Score 40000" fits */
@media (orientation: landscape) and (max-height: 520px) {
  body.game-page .score { width: 74px; display: block; padding: 1px 6px; }
  body.game-page .score .label { font-size: 8px; line-height: 1.1; }
  body.game-page .score .value { font-size: 14px; line-height: 1.15; }
  body.game-page .score.long .value { font-size: 12px; }
}
