/* Game Room — mobile-first */
/* touch-action: manipulation kills the double-tap-to-zoom gesture (which eats
   fast tap-tap move input on phones) while keeping pinch zoom and scrolling. */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--page);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
}

/* ---------- Themes ---------- */
body[data-theme="wood"] {
  --page: radial-gradient(120% 100% at 50% 0%, #3a2212 0%, #241207 55%, #170a03 100%);
  --panel: rgba(255, 244, 224, 0.07);
  --ink: #f3e7d3;
  --ink-dim: #c9b394;
  --accent: #e8a33d;
  --accent-ink: #2a1505;
  --sq-l: #ecd0a2;
  --sq-d: #a05a2a;
  --sq-border: #5b3417;
  --grain-opacity: 0.35;
  --pw1: #ffffff; --pw-mid: #e8e5dc; --pw2: #9aa3af; /* ivory-silver pieces */
  --pb1: #666876; --pb-mid: #292a31; --pb2: #050507; /* polished black pieces */
  --edge-w: #464e58;
  --edge-b: #d2d0c8;
  --shine-w: rgba(255,255,255,0.78);
  --shine-b: rgba(255,255,255,0.28);
  --pr1: #e2604e; --pr2: #8e1c10;   /* red discs (checkers + connect 4) */
  --edge-r: #3f0d07;
  --py1: #ffd75e; --py2: #c9920a;   /* yellow discs (connect 4) */
  --edge-y: #6b4d00;
  --c4-hole: rgba(22, 11, 4, 0.55);
  --hl-ring: #f7a94f;
  --hl-last: rgba(246, 198, 69, 0.35);
  --hl-check: rgba(224, 49, 49, 0.55);
  --danger: #e05c47;
}
body[data-theme="mono"] {
  --page: linear-gradient(180deg, #101014 0%, #1b1b21 100%);
  --panel: rgba(255, 255, 255, 0.06);
  --ink: #f2f2f5;
  --ink-dim: #a8a8b2;
  --accent: #dfe3ea;
  --accent-ink: #16161a;
  --sq-l: #f4f4f4;
  --sq-d: #2e2e33;
  --sq-border: #000;
  --grain-opacity: 0;
  --pw1: #ffffff; --pw-mid: #eeeeee; --pw2: #c7c7ca; /* white pieces */
  --pb1: #424249; --pb-mid: #17171b; --pb2: #000000; /* black pieces */
  --edge-w: #17171a;
  --edge-b: #f0f0f2;
  --shine-w: rgba(255,255,255,0.8);
  --shine-b: rgba(255,255,255,0.24);
  --pr1: #e14b38; --pr2: #8c150a;   /* red discs (checkers + connect 4) */
  --edge-r: #340a05;
  --py1: #ffdf66; --py2: #cf9a0c;   /* yellow discs (connect 4) */
  --edge-y: #5c4200;
  --c4-hole: rgba(0, 0, 0, 0.6);
  /* Saturated blue so highlights stay visible on BOTH the near-white light
     squares and the near-black dark squares of the mono board (a white ring
     vanished on the light cells). */
  --hl-ring: #4c8dff;
  --hl-last: rgba(120, 170, 255, 0.35);
  --hl-check: rgba(235, 70, 70, 0.6);
  --danger: #e05c47;
}
body[data-theme="pastel-sky"] {
  --page: linear-gradient(160deg, #edf7fb 0%, #d8ecf5 55%, #c9e0eb 100%);
  --panel: rgba(255,255,255,0.62); --ink: #243944; --ink-dim: #58717d;
  --accent: #82bfd2; --accent-ink: #17323d; --sq-l: #f8f3df; --sq-d: #9fcbd6;
  --sq-border: #6999a8; --grain-opacity: 0; --pw1:#fff; --pw-mid:#eef4f5; --pw2:#bdcdd2;
  --pb1:#607d88; --pb-mid:#334d57; --pb2:#172a31; --edge-w:#47616b; --edge-b:#eef7f8;
  --shine-w:rgba(255,255,255,.8); --shine-b:rgba(255,255,255,.3);
  --pr1:#ef8f8f; --pr2:#c95d68; --edge-r:#77343b; --py1:#f9db8f; --py2:#d5ad54; --edge-y:#765c24;
  --c4-hole:rgba(75,116,130,.28); --hl-ring:#277f9d; --hl-last:rgba(39,127,157,.25);
  --hl-check:rgba(220,75,85,.38); --danger:#b83c4b;
}
body[data-theme="pastel-peach"] {
  --page: linear-gradient(160deg, #fff4ec 0%, #f7dfd5 55%, #ead2e4 100%);
  --panel: rgba(255,255,255,0.6); --ink: #4c3542; --ink-dim: #7f6170;
  --accent: #e8a8a0; --accent-ink: #492c31; --sq-l: #fff1d7; --sq-d: #d8a4bb;
  --sq-border: #a87389; --grain-opacity: 0; --pw1:#fff; --pw-mid:#f8ecea; --pw2:#d8c2c8;
  --pb1:#765c6a; --pb-mid:#4b3541; --pb2:#241820; --edge-w:#654b58; --edge-b:#fff4f0;
  --shine-w:rgba(255,255,255,.82); --shine-b:rgba(255,255,255,.28);
  --pr1:#ee8b82; --pr2:#c95157; --edge-r:#743239; --py1:#f6d88c; --py2:#d2aa50; --edge-y:#705722;
  --c4-hole:rgba(105,67,86,.24); --hl-ring:#a84f78; --hl-last:rgba(168,79,120,.22);
  --hl-check:rgba(215,68,75,.35); --danger:#b83c4b;
}

/* ---------- Screens ---------- */
.screen { width: 100%; max-width: 560px; padding: 12px 10px calc(14px + env(safe-area-inset-bottom)); }
#home, #errScreen { display: flex; align-items: center; justify-content: center; min-height: 100dvh; position: relative; }
.home-card { text-align: center; padding: 6px 16px; max-width: 420px; width: 100%; }
.home-card h1 { font-size: 1.65rem; letter-spacing: 0.5px; margin: 6px 0 4px; }
.tagline { color: var(--ink-dim); line-height: 1.4; margin-bottom: 12px; font-size: 0.92rem; }
.finePrint { color: var(--ink-dim); font-size: 0.78rem; margin-top: 10px; line-height: 1.4; }
.home-logo { width: 52px; height: 52px; margin: 0 auto; }
.home-logo svg { width: 100%; height: 100%; }
.themeToggle { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; }
.gamePick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.gameBtn { justify-content: flex-start; gap: 8px; padding: 9px 9px; font-size: clamp(.78rem, 3.4vw, 1rem); min-height: 52px; min-width: 0; }
.gameBtn.wide { grid-column: 1 / -1; justify-content: center; }
.gIcon { width: 26px; height: 26px; flex: none; display: inline-flex; }
.gIcon svg { width: 100%; height: 100%; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid rgba(255,255,255,0.16); border-radius: 12px;
  background: var(--panel); color: var(--ink);
  font-size: 0.95rem; font-weight: 600; padding: 11px 16px; min-height: 44px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.big { font-size: 1.15rem; padding: 14px 28px; width: 100%; }
.btn.small { min-height: 36px; padding: 7px 12px; font-size: 0.85rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(224, 92, 71, 0.4); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ---------- Game layout ---------- */
#game { display: flex; flex-direction: column; gap: 8px; }
.bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border-radius: 10px; padding: 7px 10px; min-height: 40px;
}
.who { font-weight: 700; font-size: 0.9rem; }
/* .btn.homeBtn (not .homeBtn) so it out-specifies .btn.ghost's transparent bg */
.btn.homeBtn {
  flex: none; min-height: 32px; padding: 4px 13px; font-size: 1.05rem; margin-left: 6px;
  background: #2fb457; border-color: #38c463; color: #fff;
}
.btn.gameRoomBtn {
  flex: none; min-height: 36px; padding: 7px 12px; white-space: nowrap;
  background: #2fb457; border-color: #38c463; color: #fff;
}
.btn.gameRoomBtn:active { background: #279a4a; }
.btn.homeBtn:active { background: #279a4a; }
@media (max-width: 360px) {
  #oppBar { gap: 6px; padding-inline: 8px; }
  #oppBar .howToBtn {
    width: 36px; min-width: 36px; padding: 7px; gap: 0; font-size: 0;
  }
  #oppBar .howToBtn > span { font-size: .85rem; }
}
#btnResume { width: 100%; margin-bottom: 8px; min-height: 40px; padding: 8px 14px; font-size: 0.9rem; }
/* The "share the whole app" button — gradient is brander-themable */
.shareApp {
  appearance: none; width: 100%; margin-top: 8px; min-height: 44px; border: none; border-radius: 12px;
  color: #fff; font: inherit; font-weight: 800; font-size: 1rem; cursor: pointer; padding: 10px 16px;
  background: linear-gradient(135deg, var(--share-from, #ff5f6d) 0%, var(--share-to, #8b5cf6) 100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.shareApp:active { transform: scale(0.97); }
.shareGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shareGrid a, .shareGrid button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.16); border-radius: 12px;
  padding: 10px 4px; color: var(--ink); font: inherit; font-size: 0.78rem; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.shareGrid a:active, .shareGrid button:active { transform: scale(0.95); }
.shareGrid .sIcon { font-size: 1.35rem; line-height: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #777; flex: none; }
.dot.on { background: #3fca6b; }
.caps { display: flex; flex-wrap: wrap; align-items: center; gap: 0; flex: 1; min-height: 20px; }
.caps svg { width: 20px; height: 20px; margin-right: -6px; }
.material { color: var(--ink-dim); font-size: 0.8rem; font-weight: 700; }

/* ---------- Board ---------- */
#boardWrap {
  position: relative; width: 100%;
  max-width: min(100%, calc(100dvh - 250px));
  margin: 0 auto;
  border: 6px solid var(--sq-border); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
#board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1 / 1;
}
.grain {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  opacity: var(--grain-opacity); mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.009 0.06' numOctaves='4' seed='11'/><feColorMatrix type='matrix' values='0 0 0 0 0.45 0 0 0 0 0.28 0 0 0 0 0.12 0 0 0 0.8 0'/></filter><rect width='420' height='420' filter='url(%23g)'/></svg>");
  background-size: 420px 420px;
}
.square { position: relative; display: flex; align-items: center; justify-content: center; user-select: none; touch-action: manipulation; }
.square.l { background: var(--sq-l); }
.square.d { background: var(--sq-d); }
/* Tic-tac-toe: 3x3, uniform squares with thick dividers */
#board.ttt { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }
.square.t { background: var(--sq-l); border: 2px solid var(--sq-border); }
/* Connect 4: 7x6 frame with punched holes; discs drop in above them */
#board.c4 {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  aspect-ratio: 7 / 6;
}
.square.c4cell { background: var(--sq-d); }
.square.c4cell::before {
  content: ""; position: absolute; inset: 9%; border-radius: 50%;
  background: var(--c4-hole); z-index: 0;
}
.square.c4cell .piece { width: 84%; height: 84%; }
.square.win::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--hl-ring); opacity: 0.3;
}
.square .piece {
  position: relative; z-index: 2; width: 91%; height: 91%;
  filter: drop-shadow(0 2px 1px rgba(0,0,0,0.42)) drop-shadow(0 4px 4px rgba(0,0,0,0.22));
}
.square.last::before, .square.chk::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
}
.square.last::before { background: var(--hl-last); }
.square.chk::before { background: var(--hl-check); }
/* Chess-only last-move outline. The setting is local to each player's board. */
.square.last-move {
  box-shadow: inset 0 0 0 3px var(--hl-ring), inset 0 0 12px var(--hl-last);
}
/* Legal-move targets & the selected piece: a bright ring around the square,
   not a fill — color is user-adjustable via the --hl-ring swatch. */
.square.mv::after, .square.cap::after, .square.sel::after {
  content: ""; position: absolute; z-index: 3; inset: 2px; border-radius: 5px;
  border: 3px solid var(--hl-ring); pointer-events: none;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.35), inset 0 0 4px rgba(0, 0, 0, 0.25);
}
.square.sel::after { border-style: solid; opacity: 0.95; }
.square.sel::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--hl-ring); opacity: 0.18;
}
/* Round-game highlight tint in the (picker-adjustable) color — tic-tac-toe
   last move + win cells. Plain-square cells only; c4 uses a ring (its ::before
   is the disc hole). */
.square.hl::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--hl-ring); opacity: 0.34;
}
/* Connect 4: bolder picker-colored ring around the last drop + winning four */
.square.c4cell.mv::after {
  inset: 6%; border-width: 4px; border-radius: 50%;
  box-shadow: 0 0 7px var(--hl-ring);
}
/* Coordinates on edge squares */
.square .coordF, .square .coordR {
  position: absolute; z-index: 2; font-size: clamp(8px, 2.4vw, 11px); font-weight: 700; opacity: 0.75; pointer-events: none;
}
.square .coordF { right: 3px; bottom: 1px; }
.square .coordR { left: 3px; top: 2px; }
.square.l .coordF, .square.l .coordR { color: var(--sq-d); }
.square.d .coordF, .square.d .coordR { color: var(--sq-l); }

/* ---------- Pieces ---------- */
.piece.w { --body: url(#grad-w); --edge: var(--edge-w); --shine: var(--shine-w); }
.piece.b { --body: url(#grad-b); --edge: var(--edge-b); --shine: var(--shine-b); }
.piece.r { --body: url(#grad-r); --edge: var(--edge-r); }
.piece.y { --body: url(#grad-y); --edge: var(--edge-y); }
.piece .p-fill { fill: var(--body); stroke: var(--edge); stroke-width: 2.8; stroke-linejoin: round; }
.piece .p-line { fill: none; stroke: var(--edge); stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
.piece .p-dot { fill: var(--edge); stroke: none; }
.piece .p-shine { fill: none; stroke: var(--shine, transparent); stroke-width: 2.3; stroke-linecap: round; }

/* ---------- Status & moves ---------- */
#statusLine { text-align: center; font-weight: 700; min-height: 22px; font-size: 0.95rem; }
#statusLine .sub { color: var(--ink-dim); font-weight: 500; }
#drawBanner {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.15); border-radius: 10px; padding: 8px 10px; font-size: 0.9rem;
}
#rematchRow { display: flex; justify-content: center; }
#rematchRow .btn { min-width: 60%; }

/* ---------- Hangman ---------- */
.hmCard {
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px;
  padding: 14px 12px; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.hmCard h2 { font-size: 1.1rem; }
.hmCard input[type="text"], .hmCard input[type="number"], .hmCard select, .hmCard textarea {
  width: 100%; background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px; color: var(--ink); font: inherit; padding: 11px 12px;
}
.hmCard .btn { width: 100%; }
.hmEntryField { display: block; width: 100%; text-align: left; font-size: .85rem; font-weight: 600; }
.hmEntryField input, .hmEntryField select, .hmEntryField textarea { display: block; margin-top: 5px; }
.hmCard textarea { resize: vertical; min-height: 88px; }
.hmGenerator { width: 100%; padding: 12px; border: 1px solid var(--ink-dim); border-radius: 10px; }
.hmCard .hmGeneratorToggle {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 8px; min-height: 48px; background: #236b45; color: #fff; border-color: #236b45;
}
.hmCard .hmGeneratorToggle:hover { background: #1b5737; }
.hmGeneratorToggle[aria-expanded="true"] span { transform: rotate(180deg); }
.hmCollectionField { margin-bottom: 10px; }
.hmGeneratorFields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hmGeneratorFields label { min-width: 0; text-align: left; font-size: .8rem; font-weight: 600; }
.hmGeneratorFields input, .hmGeneratorFields select { margin-top: 5px; min-width: 0; }
.hmGenerator .finePrint { margin: 8px 0; text-align: left; }
.hmGeneratorStatus:empty { display: none; }
.hmGeneratorStatus { width: 100%; text-align: left; }
.hmClueChoice { display: flex; gap: 10px; align-items: center; width: 100%; min-height: 44px; text-align: left; font-size: .9rem; cursor: pointer; }
.hmClueChoice input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
#hmArea { display: flex; flex-direction: column; gap: 8px; }
.hmClue { color: var(--ink-dim); font-size: 0.85rem; text-align: center; }
.hmClue b { color: var(--ink); }
.hmMask { display: flex; flex-wrap: nowrap; gap: 3px; justify-content: center; width: 100%; overflow: hidden; }
.hmMask .hmCh {
  flex: 1 1 0; min-width: 0; max-width: 30px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-bottom: 3px solid var(--ink-dim); font-size: 1.35rem; font-weight: 800; text-transform: uppercase;
}
.hmMask.long .hmCh { height: 32px; font-size: 1rem; border-bottom-width: 2px; }
.hmMask.extraLong { gap: 2px; }
.hmMask.extraLong .hmCh { height: 29px; font-size: .82rem; }
.hmMask .hmSpace { flex: 0 0 12px; }
.hmMask.small .hmCh { max-width: 20px; height: 26px; font-size: 0.95rem; border-bottom-width: 2px; }
/* Revealed letters glow in the picker-adjustable highlight color */
.hmMask .hmCh.found { color: var(--hl-ring); border-bottom-color: var(--hl-ring); }
.hmGallowsRow { display: flex; align-items: center; gap: 12px; }
#hmGallows { width: 96px; height: 115px; }
#hmGallowsOpp { width: 56px; height: 67px; }
#hmGallows path, #hmGallows circle, #hmGallowsOpp path, #hmGallowsOpp circle {
  stroke: var(--ink); stroke-width: 4; stroke-linecap: round; fill: none;
}
.hmLives { color: var(--ink-dim); font-size: 0.85rem; font-weight: 700; }
.hmLives b { color: var(--ink); }
#hmKeys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; width: 100%; }
#hmKeys button {
  min-height: 40px; border-radius: 9px; border: 1px solid rgba(255,255,255,0.16);
  background: var(--panel); color: var(--ink); font-weight: 800; font-size: 1rem;
  text-transform: uppercase; cursor: pointer;
}
#hmKeys button:active { transform: scale(0.94); }
#hmKeys button:disabled { opacity: 0.25; pointer-events: none; }
#hmKeys button.hit { background: rgba(63, 202, 107, 0.25); border-color: rgba(63,202,107,0.4); }
#hmKeys button.miss { background: rgba(224, 92, 71, 0.22); border-color: rgba(224,92,71,0.4); }
.hmMine { opacity: 0.92; }
#solveRow { width: 100%; }
#solveRow input { flex: 1; }
#solveRow .btn { width: auto; }
.hmSetupField { display: block; width: 100%; text-align: left; font-size: 0.9rem; font-weight: 600; }
.hmSetupField select, .hmSetupField input[type="range"] {
  width: 100%; margin-top: 6px; accent-color: var(--accent);
  background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px; color: var(--ink); font: inherit; padding: 10px 12px;
}
.hmSetupField input[type="range"] { padding: 0; border: none; background: none; }
.hmSetupField select { min-height: 44px; }
.hmDifficulty { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.hmDifficulty label { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid rgba(255,255,255,.16); border-radius: 10px; cursor: pointer; }
.hmDifficulty input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.hmDifficulty span { display: flex; flex-direction: column; text-align: left; }
.hmDifficulty small { color: var(--ink-dim); font-size: .72rem; line-height: 1.25; }
@media (max-width: 390px) {
  .hmDifficulty { grid-template-columns: 1fr; }
}
#moveList {
  display: flex; gap: 4px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none;
  font-size: 0.85rem; color: var(--ink-dim); min-height: 26px; white-space: nowrap;
}
#moveList::-webkit-scrollbar { display: none; }
#moveList .mv { flex: none; }
#moveList .num { opacity: 0.6; margin-right: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: stretch; }
.actions .btn { flex: 1; max-width: 130px; }
.actions #btnTheme { flex: none; max-width: none; }
.actions #btnLastMove { flex: 1 1 132px; max-width: 154px; }
.hlSwatch {
  appearance: none; -webkit-appearance: none; flex: none; width: 46px; min-height: 44px; padding: 6px;
  border: 1px solid rgba(255,255,255,0.16); border-radius: 12px; background: var(--panel); cursor: pointer;
}
.hlSwatch::-webkit-color-swatch-wrapper { padding: 0; }
.hlSwatch::-webkit-color-swatch { border: none; border-radius: 7px; }
.hlSwatch::-moz-color-swatch { border: none; border-radius: 7px; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px);
}
.sheet {
  width: 100%; max-width: 480px; background: var(--page); border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  border: 1px solid rgba(255,255,255,0.12); border-bottom: none;
}
@media (min-width: 520px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 18px; border-bottom: 1px solid rgba(255,255,255,0.12); }
}
.sheet h2 { font-size: 1.2rem; }
.sheet p { color: var(--ink-dim); font-size: 0.9rem; line-height: 1.5; }
.sheetRow { display: flex; gap: 8px; justify-content: center; }
.sheetRow .btn { flex: 1; }
.linkBox {
  background: rgba(0,0,0,0.35); border: 1px dashed rgba(255,255,255,0.25); border-radius: 10px;
  padding: 10px; font-family: Consolas, monospace; font-size: 0.72rem; word-break: break-all; color: var(--ink);
  user-select: all;
}
.sideRow { display: flex; gap: 10px; justify-content: center; }
.sideRow .sideBtn {
  flex: 1; max-width: 170px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.2); border-radius: 14px;
  padding: 14px 10px; cursor: pointer; color: var(--ink); font: inherit;
}
.sideRow .sideBtn:active { transform: scale(0.96); }
.sideRow .sideBtn svg { width: 64px; height: 64px; }
.setupToggle {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 12px;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.16); border-radius: 10px;
  cursor: pointer;
}
.setupToggle input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.setupToggle span { display: flex; flex-direction: column; text-align: left; }
.setupToggle small { color: var(--ink-dim); font-size: .74rem; line-height: 1.3; }
.playerCountRow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.playerCountRow .btn { flex-direction: column; }
.playerCountRow small { display: block; font-size: .7rem; font-weight: 500; opacity: .78; }
.sideRow .sideBtn b { font-size: 0.95rem; }
.sideRow .sideBtn small { color: var(--ink-dim); font-size: 0.75rem; line-height: 1.3; }
.promoRow { display: flex; gap: 8px; justify-content: center; }
.promoRow button {
  width: 72px; height: 72px; border-radius: 14px; border: 1px solid rgba(255,255,255,0.2);
  background: var(--panel); cursor: pointer; padding: 6px;
}
.promoRow button:active { transform: scale(0.95); }
.promoRow svg { width: 100%; height: 100%; }

/* ---------- Sponsor / ad footer ---------- */
.sponsor {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px;
  padding: 10px 12px; margin-top: 10px; text-align: center;
}
.sponsor .sp-tagline { color: var(--ink-dim); font-size: 0.82rem; }
.sponsor .sp-tagline b { color: var(--ink); font-size: 0.95rem; display: block; margin-top: 2px; }
.sponsor .sp-banner { display: block; max-width: 100%; line-height: 0; }
.sponsor .sp-banner img { max-width: 100%; max-height: 90px; border-radius: 10px; }
.sponsor .sp-call { min-width: 60%; }
/* External coupon rotator frame — display-only, nothing inside is clickable */
.sponsor .sp-coupon {
  width: 100%; border: 0; border-radius: 10px; display: block;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.2);
}
/* Classic paper-coupon look — deliberately theme-independent, nothing clickable */
.sponsor .sp-couponCard {
  width: 100%; box-sizing: border-box; text-align: center;
  background: #fff8ec; border: 3px dashed #b3352b; border-radius: 10px;
  padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; align-items: center;
}
.sp-couponCard .sp-cTitle { font-family: Georgia, 'Times New Roman', serif; font-size: 1.3rem; font-weight: 700; color: #b3352b; line-height: 1.15; }
.sp-couponCard .sp-cDetails { font-size: 0.82rem; color: #7a4a1f; }
.sp-couponCard .sp-cCode { font-size: 0.9rem; font-weight: 800; letter-spacing: 2px; color: #b3352b; border: 1.5px solid #b3352b; border-radius: 6px; padding: 2px 10px; margin-top: 2px; }
.sp-couponCard .sp-cExp { font-size: 0.72rem; font-style: italic; color: #7a4a1f; margin-top: 2px; }
.sponsor .sp-adbox { width: 100%; overflow: hidden; display: flex; justify-content: center; }
.sponsor .sp-adbox:empty { display: none; }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 99;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.9rem;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

/* Wider screens: cap board, center column */
@media (min-width: 560px) {
  .screen { padding-top: 20px; }
}
/* Short phones: drop the decorative logo so all games + sponsor stay on screen */
@media (max-height: 780px) {
  .home-logo { display: none; }
  .home-card h1 { margin-top: 0; }
}
