/* ---------- themes ----------
   Every color comes from these variables. :root is the default theme (Parlor); the
   others are selected with <html data-theme="...">. Any element with data-theme gets that
   palette, which is how the theme picker's swatches preview each one. */
:root {
  --font: "Libre Franklin", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

/* Parlor: warm paper, maple tiles, classic red/pink/blue bonus squares. */
:root, [data-theme="parlor"] {
  color-scheme: light;
  --bg: #fbf7f0; --surface: #fffdf9; --surface-2: #f5eee3; --panel: #f1e8da;
  --ink: #2b2118; --muted: #7d6f61; --line: #e7ddcf; --scrim: rgba(43,33,24,.4);
  --sq: #efe5d4; --star: #cdbfa8;
  --tile: #e8d1a2; --tile-new: #f4bf5c; --tile-rack: #f2d9a4; --tile-rack-edge: #c49a55;
  --tile-ink: #3a2a17; --blank-ink: #9c7d52; --shelf: #e3d4bd;
  --dl-bg: #d6e7f1; --dl-ink: #3c6b8c;
  --tl-bg: #b7d1e5; --tl-ink: #255476;
  --dw-bg: #f4d3cd; --dw-ink: #a3473b;
  --tw-bg: #e6aa9c; --tw-ink: #842b1e;
  --good: #7fb85e; --good-ink: #1f4512; --good-edge: #5e9440; --good-soft: #e3f0d7;
  --good-strong: #5c9a3c; --good-strong-edge: #3d6f24;
  --bad: #b5402f; --bad-soft: #f2cfc6; --bad-ink: #6e1f14;
  --play: #2e6e6a; --accent: #4f9a94; --accent-soft: #dcece8;
  --gold: #eab84a; --gold-ink: #5a3c05;
  --avatar: #f0d6a6; --avatar-ink: #6b4b12; --chip: #eee4d4; --track: #ece2d2;
  --disabled: #b3a798; --disabled-ink: #b0a493;
  --wheel-a: #f8f2e8; --wheel-b: #efe5d5; --wheel-tile: #fffdf9; --wheel-ink: #3a2a17; --wheel-edge: #dccdb5;
  --slot-active: #d9c9ad; --slot-future: #f5efe5;
}

/* Garden: sage paper, forest-green tiles, straw/mint/terracotta/plum bonus squares. */
[data-theme="garden"] {
  color-scheme: light;
  --bg: #f5f8f3; --surface: #ffffff; --surface-2: #eef3ec; --panel: #e8efe5;
  --ink: #1d2a22; --muted: #63736a; --line: #dbe4d8; --scrim: rgba(20,35,26,.4);
  --sq: #e5ece1; --star: #b9c8bd;
  --tile: #3d7a5c; --tile-new: #1f4f39; --tile-rack: #26604a; --tile-rack-edge: #163b2c;
  --tile-ink: #f5f2e7; --blank-ink: #b6d8c4; --shelf: #d5dfd1;
  --dl-bg: #f3e6c5; --dl-ink: #876623;
  --tl-bg: #d3e8df; --tl-ink: #2c6a57;
  --dw-bg: #f5d8cb; --dw-ink: #a2513a;
  --tw-bg: #e8d0e1; --tw-ink: #85406e;
  --good: #a3d16b; --good-ink: #2a4a0e; --good-edge: #7fae4b; --good-soft: #e5f2d8;
  --good-strong: #7cb346; --good-strong-edge: #557f2c;
  --bad: #b8483a; --bad-soft: #f2d2cb; --bad-ink: #6e2016;
  --play: #26604a; --accent: #6aa58a; --accent-soft: #dbeae2;
  --gold: #e3b448; --gold-ink: #553905;
  --avatar: #d9e9c9; --avatar-ink: #2f5a1c; --chip: #e3eae0; --track: #e0e8dd;
  --disabled: #a3afa6; --disabled-ink: #a3afa6;
  --wheel-a: #f3f7f1; --wheel-b: #e6ede3; --wheel-tile: #ffffff; --wheel-ink: #1f4f39; --wheel-edge: #cfdacb;
  --slot-active: #b9d3c4; --slot-future: #f1f5ef;
}

/* Midnight: dark slate, honey-gold tiles, jewel-tone bonus squares. */
[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #14161c; --surface: #1d2029; --surface-2: #252937; --panel: #1b1e27;
  --ink: #ecebf3; --muted: #9aa0b4; --line: #2d3241; --scrim: rgba(0,0,0,.55);
  --sq: #242836; --star: #3d4357;
  --tile: #d9a84c; --tile-new: #ffd27a; --tile-rack: #f0c062; --tile-rack-edge: #a87c27;
  --tile-ink: #1d1708; --blank-ink: #7a5a1c; --shelf: #2a2f3d;
  --dl-bg: #23324f; --dl-ink: #8fb2ff;
  --tl-bg: #1d3f3a; --tl-ink: #6fd8ba;
  --dw-bg: #45263b; --dw-ink: #f294c6;
  --tw-bg: #4d2a2a; --tw-ink: #ff8f7e;
  --good: #7bd389; --good-ink: #0e3216; --good-edge: #4ea85d; --good-soft: #1e3a26;
  --good-strong: #4fb064; --good-strong-edge: #2f7a40;
  --bad: #ff7468; --bad-soft: #4a2526; --bad-ink: #ffb3ab;
  --play: #6c8cff; --accent: #6c8cff; --accent-soft: #262e48;
  --gold: #f2b950; --gold-ink: #2b1d02;
  --avatar: #3a3350; --avatar-ink: #d8cffc; --chip: #2a2f3d; --track: #2a2f3d;
  --disabled: #3a4052; --disabled-ink: #5d6478;
  --wheel-a: #1d2029; --wheel-b: #232735; --wheel-tile: #2a2f3e; --wheel-ink: #ffd27a; --wheel-edge: #151821;
  --slot-active: #4a5578; --slot-future: #1b1e27;
}

/* New York: the original look, after the reference screenshots. */
[data-theme="ny"] {
  color-scheme: light;
  --bg: #ffffff; --surface: #ffffff; --surface-2: #f7f7f5; --panel: #f1f0ee;
  --ink: #1d1d1f; --muted: #6e6e73; --line: #e4e4e4; --scrim: rgba(0,0,0,.35);
  --sq: #eeedea; --star: #c9c6bf;
  --tile: #4c74c4; --tile-new: #34538d; --tile-rack: #33548f; --tile-rack-edge: #22396a;
  --tile-ink: #ffffff; --blank-ink: #dfe8ff; --shelf: #d9d8d6;
  --dl-bg: #f2ead2; --dl-ink: #86652f;
  --tl-bg: #e0e7d4; --tl-ink: #5a6941;
  --dw-bg: #dde3f0; --dw-ink: #44558e;
  --tw-bg: #ebdfee; --tw-ink: #9b3ea8;
  --good: #8dc25a; --good-ink: #2f5a17; --good-edge: #6f9e44; --good-soft: #e6f2da;
  --good-strong: #5d9a35; --good-strong-edge: #3f6e22;
  --bad: #c0463c; --bad-soft: #f6d3ce; --bad-ink: #6d1d16;
  --play: #2f5bb5; --accent: #7ea3ec; --accent-soft: #e2e7f2;
  --gold: #f5c842; --gold-ink: #5b4300;
  --avatar: #f0d9a8; --avatar-ink: #6b4b12; --chip: #e9e9e9; --track: #ececec;
  --disabled: #9a9a9a; --disabled-ink: #a3a3a3;
  --wheel-a: #f6f5f2; --wheel-b: #efede8; --wheel-tile: #ffffff; --wheel-ink: #34538d; --wheel-edge: #d6d4cf;
  --slot-active: #c9d4ec; --slot-future: #f5f4f1;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overflow: hidden; }
button { font: inherit; color: inherit; }

#app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
}

/* ---------- header ---------- */
header { flex: none; padding: 6px 14px 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; height: 36px; }
.topbar h1 { font-size: 15px; font-weight: 800; letter-spacing: .02em; margin: 0; }
.pill {
  border: 0; background: var(--panel); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; font-weight: 700; min-width: 86px; cursor: pointer;
}
.pill.subtle { background: transparent; text-align: right; color: var(--muted); cursor: default; }

.scorebar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-top: 8px; }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; }
.player.you { background: var(--accent-soft); }
.player.best { justify-content: flex-end; text-align: right; color: var(--muted); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--avatar); font-size: 12px; font-weight: 800; color: var(--avatar-ink);
}
.player.best .avatar { background: var(--chip); color: var(--muted); font-size: 18px; }
.pts { font-size: 22px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.name { font-size: 13px; font-weight: 600; white-space: nowrap; }
.player.best .pts { color: var(--muted); }

.bag { position: relative; width: 58px; height: 58px; display: grid; place-items: center; }
.bag svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.bag circle { fill: none; stroke-width: 4; }
.bag .track { stroke: var(--track); }
.bag .ring { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 119.4; transition: stroke-dashoffset .5s ease; }
.bag span {
  width: 36px; height: 30px; border-radius: 10px 10px 14px 14px; background: var(--gold);
  display: grid; place-items: center; font-weight: 800; font-size: 15px; color: var(--gold-ink);
}

#status {
  text-align: center; font-size: 16px; font-weight: 500; padding: 12px 4px 12px;
  border-bottom: 1px solid var(--line); min-height: 46px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#status b { font-weight: 800; }
#status.bad { color: var(--bad); }

/* ---------- board ---------- */
#viewport { flex: 1; min-height: 0; position: relative; overflow: hidden; touch-action: none; }
#board {
  position: absolute; left: 0; top: 0; transform-origin: 0 0;
  display: grid; grid-template-columns: repeat(15, var(--cell)); grid-auto-rows: var(--cell);
  gap: var(--gap); padding: var(--pad);
}
#board.animate { transition: transform .45s cubic-bezier(.22, .8, .24, 1); }

.cell {
  position: relative; border-radius: calc(var(--cell) * .14) calc(var(--cell) * .14) calc(var(--cell) * .22) calc(var(--cell) * .14);
  background: var(--sq); display: grid; place-items: center;
  font-weight: 700; font-size: calc(var(--cell) * .36); letter-spacing: -.02em;
}
.cell.DL { background: var(--dl-bg); color: var(--dl-ink); }
.cell.TL { background: var(--tl-bg); color: var(--tl-ink); }
.cell.DW { background: var(--dw-bg); color: var(--dw-ink); }
.cell.TW { background: var(--tw-bg); color: var(--tw-ink); }
.cell.center::after { content: "★"; position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--cell) * .5); color: var(--star); }
.cell.center.DW::after { color: var(--dw-ink); opacity: .55; }
.cell.center.DW .plabel { display: none; }
.cell.hover { box-shadow: inset 0 0 0 calc(var(--cell) * .07) var(--accent); }

.tile {
  position: absolute; inset: 0; z-index: 1; isolation: isolate; color: var(--tile-ink);
  --r: calc(var(--cell) * .16);
}
.tile::before {
  content: ""; position: absolute; z-index: -1; left: 0; top: 0; right: 0; bottom: 0;
  background: var(--tile); border-radius: var(--r);
}
.tile.jr::before { right: calc(var(--gap) * -1); border-top-right-radius: 0; border-bottom-right-radius: 0; }
.tile.jb::before { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.tile.jl::before { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.tile.jt::before { border-top-left-radius: 0; border-top-right-radius: 0; }
/* Bridge the gap to the tile below. It only reaches into the corner gap (jd) when the
   diagonal tile is also filled, so an L-shaped join doesn't grow a stray square. */
.tile.jb::after {
  content: ""; position: absolute; z-index: -1; left: 0; right: 0; top: 100%; height: var(--gap);
  background: var(--tile);
}
.tile.jb.jd::after { right: calc(var(--gap) * -1); }
.tile.recent.jb::after { background: var(--tile-new); }
.tile.pending { cursor: grab; z-index: 2; }
.tile.pending::before {
  background: var(--tile-new);
  border-radius: calc(var(--cell) * .2) calc(var(--cell) * .08) calc(var(--cell) * .08) calc(var(--cell) * .08);
}
.tile.preview::before { background: var(--good-strong); }
.tile.preview { color: #fff; }
.tile.recent::before { background: var(--tile-new); }
.tile.dragging { opacity: .25; }
.tile .L, .rtile .L, .ghost .L {
  position: absolute; left: 19%; bottom: 9%; line-height: 1;
  font-weight: 800; font-size: calc(var(--cell) * .54); letter-spacing: -.02em;
}
.tile .v, .rtile .v, .ghost .v {
  position: absolute; top: 11%; right: 14%; font-size: calc(var(--cell) * .22); font-weight: 700; line-height: 1;
}
.tile.blank .L { color: var(--blank-ink); }

/* green "valid play" outline around every word formed (SVG union of word rectangles) */
.frame {
  position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none;
  animation: fade .25s ease-out;
}
.frame svg { position: absolute; left: 0; top: 0; overflow: visible; }
.frame .check, .frame .score { position: absolute; }
.frame .check {
  margin: calc(var(--cell) * -.3) 0 0 calc(var(--cell) * -.3);
  width: calc(var(--cell) * .62); height: calc(var(--cell) * .62); background: var(--good);
  border-radius: calc(var(--cell) * .12); transform: rotate(45deg); display: grid; place-items: center;
  box-shadow: 0 2px 0 rgba(0,0,0,.12);
}
.frame .check::after {
  content: ""; width: 34%; height: 18%; border-left: calc(var(--cell) * .07) solid var(--good-ink);
  border-bottom: calc(var(--cell) * .07) solid var(--good-ink); transform: rotate(-90deg) translate(10%, -10%);
}
.frame .score {
  transform: translate(-58%, -58%);
  min-width: calc(var(--cell) * .66); height: calc(var(--cell) * .66); padding: 0 calc(var(--cell) * .1);
  border-radius: 999px; background: var(--good); color: var(--good-ink); display: grid; place-items: center;
  font-weight: 800; font-size: calc(var(--cell) * .34);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- rack + actions ---------- */
#controls { flex: none; }
#rack {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 10px 8px 10px;
  touch-action: none; position: relative;
  background: linear-gradient(to bottom, transparent calc(100% - 26px), var(--shelf) calc(100% - 26px));
}
.slot { aspect-ratio: 1; position: relative; }
.rtile {
  /* Positioned by JS (transform) over the .slot placeholders so moves between slots animate. */
  --cell: var(--rack-cell, 52px);
  position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell);
  border-radius: 16%; background: var(--tile-rack); color: var(--tile-ink); cursor: grab;
  box-shadow: inset 0 -5px 0 var(--tile-rack-edge), 0 2px 3px rgba(0,0,0,.15);
  transition: transform .22s cubic-bezier(.22, .8, .24, 1), margin-top .15s ease;
}
.rtile .L { bottom: 13%; }
.rtile.selected { margin-top: -8px; box-shadow: inset 0 -5px 0 var(--tile-rack-edge), 0 8px 14px rgba(0,0,0,.25); }
.rtile.dragging { opacity: 0; }

.ghost {
  position: fixed; z-index: 100; pointer-events: none; color: var(--tile-ink);
  background: var(--tile-new); box-shadow: 0 10px 22px rgba(0,0,0,.3);
  border-radius: 20% 8% 8% 8%;
  transition: width .12s ease, height .12s ease;
  transform: translate(-50%, -50%);
}

#actions {
  display: grid; grid-template-columns: 1fr 1fr 1.6fr; align-items: center; gap: 6px;
  background: var(--panel); padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
}
#actions button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 15px; font-weight: 600; cursor: pointer; padding: 4px; }
#actions .ico { font-size: 22px; line-height: 1; height: 24px; }
#actions button:disabled { color: var(--disabled-ink); }
button.play {
  border: 0; border-radius: 999px; background: var(--play); color: #fff !important; font-size: 20px !important; font-weight: 600;
  height: 56px; justify-content: center; cursor: pointer; transition: background .2s;
}
#actions button.play, button.play { background: var(--play); }
#actions button.play:disabled, button.play:disabled { background: var(--disabled); cursor: default; }

/* ---------- results sheet ---------- */
#results {
  flex: none; max-height: 48dvh; overflow-y: auto; background: var(--surface); border-top: 1px solid var(--line);
  padding: 4px 14px calc(14px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 24px rgba(0,0,0,.06);
  animation: sheet .35s cubic-bezier(.22, .8, .24, 1);
}
@keyframes sheet { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.res-played {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 17px; margin-bottom: 12px;
}
.res-played b { font-weight: 800; }
button.next {
  flex: none; border: 0; border-radius: 999px; background: var(--play); color: #fff;
  font-size: 16px; font-weight: 700; padding: 10px 18px; cursor: pointer;
}
.res-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.rank-badge {
  flex: none; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 20px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; background: var(--good); color: var(--good-ink);
}
.rank-badge.meh { background: var(--gold); color: var(--gold-ink); }
.rank-badge.low { background: var(--bad-soft); color: var(--bad-ink); }
.res-title { font-size: 18px; font-weight: 800; }
.res-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
#resList { list-style: none; margin: 0; padding: 0; }
#resList li {
  display: grid; grid-template-columns: 34px 1fr auto auto; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 10px; cursor: pointer;
}
#resList li + li { margin-top: 2px; }
#resList li:nth-child(odd) { background: var(--surface-2); }
#resList li.active { box-shadow: inset 0 0 0 2px var(--accent); }
#resList li.yours { background: var(--good-soft); box-shadow: inset 0 0 0 2px var(--good); }
#resList li.gap { background: none; cursor: default; padding: 0 10px; color: var(--muted); grid-template-columns: 1fr; text-align: center; }
#resList .rk { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
#resList .wd { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
#resList .mini {
  width: 22px; height: 22px; border-radius: 5px; background: var(--tile); color: var(--tile-ink); font-weight: 700; font-size: 13px;
  display: grid; place-items: center;
}
#resList .mini.new { background: var(--tile-new); }
#resList .mini.blank { color: var(--blank-ink); font-style: italic; }
#resList .you-tag { font-size: 11px; font-weight: 800; color: var(--good-ink); background: var(--good); border-radius: 999px; padding: 2px 7px; margin-left: 4px; }
#resList .bingo-tag { font-size: 11px; font-weight: 800; color: var(--gold-ink); background: var(--gold); border-radius: 999px; padding: 2px 7px; margin-left: 4px; }
#resList .co { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
#resList .sc { font-weight: 800; font-size: 17px; min-width: 32px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- blank picker ---------- */
#picker { position: fixed; inset: 0; z-index: 200; background: var(--scrim); display: grid; place-items: center; padding: 16px; }
#picker[hidden], #results[hidden] { display: none; }
.picker-card { background: var(--surface); border-radius: 18px; padding: 18px; width: min(100%, 380px); text-align: center; animation: pop .2s ease-out; }
.picker-title { font-weight: 800; margin-bottom: 12px; }
#pickerGrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
#pickerGrid button { aspect-ratio: 1; border: 0; border-radius: 10px; background: var(--tile-rack); color: var(--tile-ink); font-weight: 700; font-size: 20px; cursor: pointer; }
button.link { border: 0; background: none; color: var(--muted); margin-top: 12px; font-weight: 600; cursor: pointer; padding: 8px 16px; }

@media (min-width: 600px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* ---------- account ---------- */
.account-btn {
  border: 0; background: var(--panel); border-radius: 999px; min-width: 86px; height: 32px; padding: 0 12px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 13px; font-weight: 700;
}
.account-btn:has(.acct-avatar) { min-width: 0; padding: 0; background: none; justify-content: flex-end; width: 86px; }
.acct-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: var(--avatar); color: var(--avatar-ink); font-size: 12px; font-weight: 800; }
img.avatar { object-fit: cover; padding: 0; }

.modal { position: fixed; inset: 0; z-index: 150; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-card {
  position: relative; background: var(--surface); width: min(100%, 560px); max-height: 88dvh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  animation: sheet .3s cubic-bezier(.22, .8, .24, 1);
}
.modal-x { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 28px; line-height: 1; color: var(--muted); cursor: pointer; padding: 6px 10px; }

.acct-who { display: flex; align-items: center; gap: 14px; margin: 4px 0 16px; padding-right: 30px; }
.acct-pic { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: var(--avatar); color: var(--avatar-ink); font-weight: 800; }
.acct-name { font-size: 19px; font-weight: 800; }
.acct-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }

.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px; height: 50px; border-radius: 999px;
  border: 1px solid #dadce0; background: #fff; color: #1f1f1f; font-weight: 600; font-size: 16px; text-decoration: none;
  margin-bottom: 16px;
}
.google-btn svg { width: 20px; height: 20px; }
.guest-btn { width: 100%; height: 50px; border-radius: 999px; border: 0; background: var(--panel); font-weight: 700; font-size: 16px; cursor: pointer; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.stat-grid div { background: var(--surface-2); border-radius: 12px; padding: 10px 6px; text-align: center; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-grid b { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-grid span { font-size: 12px; color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
.history { list-style: none; margin: 0 0 8px; padding: 0; }
.history li { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.history li.muted { color: var(--muted); border: 0; }
.h-main { display: flex; align-items: baseline; gap: 8px; font-size: 17px; }
.h-score { font-weight: 800; }
.h-rank { margin-left: auto; font-size: 13px; font-weight: 800; color: var(--bad-ink); background: var(--bad-soft); border-radius: 999px; padding: 2px 8px; }
.h-rank.top { color: var(--good-ink); background: var(--good); }
.h-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }

.welcome-card { text-align: center; }
.welcome-card h2 { margin: 14px 0 8px; font-size: 22px; font-weight: 800; }
.welcome-card p { color: var(--muted); margin: 0 0 20px; line-height: 1.45; }
.welcome-tiles { display: flex; justify-content: center; gap: 5px; margin-top: 6px; }
.welcome-tiles span {
  width: 40px; height: 40px; border-radius: 8px; background: var(--tile-rack); color: var(--tile-ink); font-weight: 800; font-size: 22px;
  display: grid; place-items: center; box-shadow: inset 0 -4px 0 var(--tile-rack-edge);
}

/* ---------- mode menu ---------- */
.topbar { position: relative; }
.pill .caret { font-size: 10px; margin-left: 2px; color: var(--muted); }
.mode-menu {
  position: absolute; left: 0; top: 40px; z-index: 120; width: 250px; padding: 6px;
  background: var(--surface); border-radius: 14px; box-shadow: 0 12px 32px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.05);
  animation: pop .15s ease-out; transform-origin: top left;
}
.mode-menu[hidden] { display: none; }
.mode-menu button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  border: 0; background: none; border-radius: 10px; padding: 10px 12px; cursor: pointer; text-align: left;
}
.mode-menu button:hover { background: var(--surface-2); }
.mode-menu button b { font-size: 15px; font-weight: 800; }
.mode-menu button span { font-size: 13px; color: var(--muted); }
.mode-menu button.current { background: var(--accent-soft); }

/* ---------- bingo mode ---------- */
#bingo { display: none; }
#app.mode-bingo #bingo {
  display: flex; flex: 1; min-height: 0; flex-direction: column; align-items: center;
  padding: 6px 16px calc(14px + env(safe-area-inset-bottom));
}
#app.mode-bingo .scorebar,
#app.mode-bingo #viewport,
#app.mode-bingo #controls,
#app.mode-bingo #results { display: none !important; }

.bingo-timer { font-size: 15px; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 4px; }
.bingo-wheel {
  position: relative; width: min(100%, 360px, 46dvh); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, var(--wheel-a) 0 62%, var(--wheel-b) 62.5% 100%);
  touch-action: none; flex: none; margin: 14px 0 18px;
}
.bl {
  --cell: calc(min(100vw - 32px, 360px, 46dvh) * .2);
  position: absolute; width: 20%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 16%; background: var(--wheel-tile); color: var(--wheel-ink); cursor: pointer;
  box-shadow: 0 3px 0 var(--wheel-edge), 0 4px 10px rgba(0,0,0,.08);
  transition: left .3s cubic-bezier(.22, .8, .24, 1), top .3s cubic-bezier(.22, .8, .24, 1), background .12s, color .12s, transform .12s;
  z-index: 1;
}
.bl .L { position: absolute; left: 19%; bottom: 13%; font-weight: 800; font-size: calc(var(--cell) * .56); line-height: 1; }
.bl .v { position: absolute; top: 11%; right: 14%; font-size: calc(var(--cell) * .22); font-weight: 700; line-height: 1; opacity: .7; }
/* Solved: the wheel letters turn green along with the dock. */
.bingo-wheel.done .bl { background: var(--good-strong); color: #fff; box-shadow: 0 3px 0 var(--good-strong-edge); }

.bingo-slots {
  position: relative; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; width: min(100%, 400px);
  touch-action: none;
}
.bslot { aspect-ratio: 1; border-radius: 9px; background: var(--sq); }
/* Dock tiles are positioned over the slots by JS (transform) so rearranging animates. */
.btile {
  position: absolute; left: 0; top: 0; border-radius: 16%; color: var(--tile-ink); cursor: grab;
  background: var(--tile-rack); box-shadow: inset 0 -4px 0 var(--tile-rack-edge), 0 2px 3px rgba(0,0,0,.15);
  transition: transform .22s cubic-bezier(.22, .8, .24, 1), background .2s;
  animation: tile-in .15s ease-out;
}
.btile .L { position: absolute; left: 19%; bottom: 13%; font-weight: 800; font-size: calc(var(--cell) * .56); line-height: 1; }
.btile .v { position: absolute; top: 11%; right: 14%; font-size: calc(var(--cell) * .22); font-weight: 700; line-height: 1; }
.btile.dragging { opacity: 0; animation: none; }
.btile.dropped { animation: tile-in .15s ease-out; }
.btile.solved { background: var(--good); color: var(--good-ink); box-shadow: inset 0 -4px 0 var(--good-edge); animation: tile-flip .35s ease-out both; cursor: default; }
.btile.revealed { background: var(--shelf); color: var(--muted); box-shadow: none; animation: tile-flip .35s ease-out both; cursor: default; }
/* Use the individual scale/rotate properties: `transform` is reserved for slot positioning. */
@keyframes tile-in { from { scale: .8; opacity: 0; } to { scale: 1; opacity: 1; } }
@keyframes tile-flip { from { rotate: x 90deg; } to { rotate: x 0deg; } }
.bl.docked { opacity: .18; pointer-events: none; box-shadow: none; }
.bingo-result { min-height: 48px; text-align: center; margin-top: 12px; font-size: 16px; }
.bingo-result .sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.bingo-actions { display: grid; grid-template-columns: 1fr 1fr 1.6fr; gap: 6px; width: 100%; margin-top: auto; align-items: center; }
.bingo-actions button:not(.play) {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 15px; font-weight: 600; cursor: pointer; padding: 4px;
}
.bingo-actions .ico { font-size: 22px; line-height: 1; height: 24px; }
.bingo-actions button:disabled { color: var(--disabled-ink); }
#bingoNext:not(.ready), #ladderNext:not(.ready) { background: var(--disabled); }

/* ---------- 7 to 3 mode ---------- */
#ladder { display: none; }
#app.mode-ladder #ladder {
  display: flex; flex: 1; min-height: 0; flex-direction: column; align-items: center;
  padding: 6px 16px calc(14px + env(safe-area-inset-bottom));
}
#app.mode-ladder .scorebar,
#app.mode-ladder #viewport,
#app.mode-ladder #controls,
#app.mode-ladder #results { display: none !important; }

.ladder-rows {
  --lt: min(calc((min(100vw, 560px) - 32px - 36px) / 7), 50px);
  --cell: var(--lt);
  display: flex; flex-direction: column; gap: 12px; margin: 16px 0 6px; touch-action: none;
}
.lrow { position: relative; display: flex; justify-content: center; gap: 6px; }
.lslot, .ltile { width: var(--lt); height: var(--lt); border-radius: 16%; flex: none; }
.lslot { background: var(--sq); }
.lrow.active .lslot { box-shadow: inset 0 0 0 2px var(--slot-active); }
.lrow.future .lslot { background: var(--slot-future); }
.ltile {
  position: relative; color: var(--tile-ink); cursor: grab;
  background: var(--tile-rack); box-shadow: inset 0 -4px 0 var(--tile-rack-edge), 0 2px 3px rgba(0,0,0,.12);
}
.ltile .L { position: absolute; left: 19%; bottom: 13%; font-weight: 800; font-size: calc(var(--cell) * .56); line-height: 1; }
.ltile .v { position: absolute; top: 11%; right: 14%; font-size: calc(var(--cell) * .22); font-weight: 700; line-height: 1; }
.lrow.done .ltile { background: var(--good); color: var(--good-ink); box-shadow: inset 0 -4px 0 var(--good-edge); cursor: default; }
.lrow.source .ltile.used { opacity: .18; box-shadow: none; cursor: default; }
/* `backwards` (not `both`): a held end state would pin opacity and hide the faded "used" style. */
.lrow.fresh .ltile { animation: tile-in .25s ease-out backwards; }
/* Placed tiles are positioned over the active row's slots by JS (transform). */
.ltile.placed { position: absolute; left: 0; top: 0; transition: transform .22s cubic-bezier(.22, .8, .24, 1); animation: tile-in .15s ease-out; }
.ltile.placed.dragging { opacity: 0; animation: none; }
.ltile.placed.dropped { animation: tile-in .15s ease-out; }

/* ---------- privacy, consent ---------- */
.welcome-privacy { font-size: 13px; margin-top: -8px !important; }
.welcome-privacy a, .consent a, .acct-links a { color: var(--play); }
.acct-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin-top: 8px; font-size: 14px; }
.acct-links .link { margin: 0; padding: 8px 0; font-size: 14px; }
.acct-links a { padding: 8px 0; font-weight: 600; text-decoration: none; }
.link.danger { color: var(--bad); }

.consent {
  position: fixed; z-index: 140; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  max-width: 536px; margin: 0 auto; background: var(--surface); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 12px 36px rgba(0,0,0,.2), 0 0 0 1px rgba(0,0,0,.05); animation: sheet .3s cubic-bezier(.22, .8, .24, 1);
}
.consent[hidden] { display: none; }
.consent p { margin: 0 0 12px; font-size: 14px; line-height: 1.45; }
.consent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.consent-actions button { height: 44px; border-radius: 999px; border: 0; font: inherit; font-weight: 700; font-size: 15px; cursor: pointer; }
.consent-deny { background: var(--panel); color: var(--ink); }
.consent-allow { background: var(--play); color: #fff; }

/* ---------- theme picker ---------- */
.theme-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.theme-opt {
  border: 0; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.swatch {
  position: relative; width: 100%; aspect-ratio: 1.15; border-radius: 12px; overflow: hidden; display: block;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.theme-opt.current .swatch { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch i { position: absolute; display: grid; place-items: center; font-style: normal; }
.swatch .sw-bg { inset: 0; background: var(--bg); }
.swatch .sw-tile {
  left: 12%; top: 16%; width: 40%; aspect-ratio: 1; border-radius: 16%; background: var(--tile-rack); color: var(--tile-ink);
  box-shadow: inset 0 -3px 0 var(--tile-rack-edge); font-weight: 800; font-size: 18px;
}
.swatch .sw-tw, .swatch .sw-dw, .swatch .sw-tl { width: 22%; aspect-ratio: 1; border-radius: 22%; }
.swatch .sw-tw { right: 12%; top: 16%; background: var(--tw-bg); }
.swatch .sw-dw { right: 12%; bottom: 14%; background: var(--dw-bg); }
.swatch .sw-tl { left: 12%; bottom: 14%; background: var(--tl-bg); width: 40%; aspect-ratio: auto; height: 22%; border-radius: 6px; background: var(--play); }
.theme-name { font-size: 13px; font-weight: 700; }
.theme-opt.current .theme-name { color: var(--accent); }
