/* Maths+Dice — one design, three colour themes.
   Everything on the game screen is sized from --s (one "design pixel"), which shrinks
   to whichever is tighter: the screen's width or its height. That is what keeps the
   whole game on screen with no scrolling, from a small iPhone SE to a tablet. */

@font-face { font-family: "Montserrat"; font-weight: 600; font-display: swap; src: url("/fonts/montserrat-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Montserrat"; font-weight: 800; font-display: swap; src: url("/fonts/montserrat-latin-800-normal.woff2") format("woff2"); }

:root {
  --add: #2563eb; --sub: #dc2626; --mul: #16a34a; --div: #8b5cf6; --gold: #d4af37;
  --app-w: min(100vw, 480px);
  --app-h: 100vh;
  --s: min(calc(var(--app-w) / 400), calc(var(--app-h) / 790));
  --font: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: calc(var(--s) * 16);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}
@supports (height: 100dvh) { :root { --app-h: 100dvh; } }

/* ---------- Themes ---------- */
:root, [data-theme="midnight"] {
  --bg: #05070b; --bg2: #0d1424; --panel: #111a2e; --panel2: #18233d; --line: #24314f;
  --text: #f4f6fb; --muted: #97a3bf; --accent: #ffd34d; --accent-ink: #231a00;
  --tile: #fbfbf8; --tile-ink: #0b0d12; --result: #ffe9a8; --result-ink: #2b2100;
  --good: #22c55e; --bad: #f43f5e; --glow: rgba(255, 211, 77, .45);
  --bg-art: radial-gradient(120% 60% at 50% 0%, #17223d 0%, transparent 70%), radial-gradient(90% 50% at 50% 100%, #0f1a33 0%, transparent 70%);
}
[data-theme="felt"] {
  --bg: #062016; --bg2: #0b3022; --panel: #0e3a29; --panel2: #134832; --line: #1f5b41;
  --text: #f3f1e7; --muted: #a9c3b4; --accent: #e9c46a; --accent-ink: #2a1d00;
  --tile: #fffdf6; --tile-ink: #101010; --result: #f6e3b4; --result-ink: #3a2600;
  --good: #4ade80; --bad: #fb7185; --glow: rgba(233, 196, 106, .45);
  --bg-art: radial-gradient(110% 70% at 50% 35%, #0f4a33 0%, transparent 75%);
}
[data-theme="daylight"] {
  --bg: #eef1f7; --bg2: #ffffff; --panel: #ffffff; --panel2: #f3f5fa; --line: #d8deea;
  --text: #121826; --muted: #5b667d; --accent: #1d4ed8; --accent-ink: #ffffff;
  --tile: #ffffff; --tile-ink: #0b0d12; --result: #fff1c2; --result-ink: #3a2a00;
  --good: #16a34a; --bad: #dc2626; --glow: rgba(29, 78, 216, .3);
  --bg-art: radial-gradient(120% 60% at 50% 0%, #ffffff 0%, transparent 70%);
}

/* ---------- Page frame: never scrolls ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--bg); background-image: var(--bg-art); color: var(--text);
  font-family: var(--font); font-weight: 600; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

.app {
  position: relative; height: var(--app-h); width: var(--app-w); margin: 0 auto;
  display: flex; flex-direction: column;
  padding: max(env(safe-area-inset-top), calc(var(--s) * 10)) calc(var(--s) * 16) max(env(safe-area-inset-bottom), calc(var(--s) * 12));
  gap: calc(var(--s) * 10);
}

/* ---------- Top bar ---------- */
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; gap: calc(var(--s) * 6); align-items: center; height: calc(var(--s) * 46); }
.wordmark { margin: 0; font-weight: 800; font-size: calc(var(--s) * 17); letter-spacing: .06em; display: flex; align-items: center; gap: calc(var(--s) * 4); white-space: nowrap; }
.wm-ops { display: inline-flex; gap: 0; font-size: calc(var(--s) * 14); }
.c-add { color: var(--add); } .c-sub { color: var(--sub); } .c-mul { color: var(--mul); } .c-div { color: var(--div); }
.top-actions { display: flex; justify-content: flex-end; gap: calc(var(--s) * 8); }
.icon-btn {
  position: relative; width: calc(var(--s) * 44); height: calc(var(--s) * 44); border-radius: calc(var(--s) * 14);
  background: var(--panel); border: 1px solid var(--line); display: grid; place-items: center;
}
.icon-btn svg { width: calc(var(--s) * 22); height: calc(var(--s) * 22); }
.streak-count {
  position: absolute; top: calc(var(--s) * -6); right: calc(var(--s) * -6); min-width: calc(var(--s) * 22); height: calc(var(--s) * 22);
  padding: 0 calc(var(--s) * 5); border-radius: 99px; background: #f97316; color: #fff; font-size: calc(var(--s) * 12); font-weight: 800;
  display: grid; place-items: center; box-shadow: 0 0 0 2px var(--bg);
}
.daily-btn.done { border-color: var(--good); }
.level-chip { justify-self: start; display: flex; align-items: center; gap: calc(var(--s) * 7); height: calc(var(--s) * 44); padding: 0 calc(var(--s) * 10) 0 calc(var(--s) * 5); border-radius: calc(var(--s) * 14); background: var(--panel); border: 1px solid var(--line); }
.level-badge {
  width: calc(var(--s) * 32); height: calc(var(--s) * 32); border-radius: calc(var(--s) * 10); display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #ff8a00)); color: var(--accent-ink); font-weight: 800; font-size: calc(var(--s) * 15);
}
.level-badge.big { width: calc(var(--s) * 56); height: calc(var(--s) * 56); font-size: calc(var(--s) * 24); border-radius: calc(var(--s) * 16); flex: none; }
.level-bar { width: calc(var(--s) * 26); height: calc(var(--s) * 6); border-radius: 9px; background: var(--line); overflow: hidden; }
.level-bar.big { width: 100%; height: calc(var(--s) * 10); }
.level-bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #ff8a00); transition: width .8s var(--ease-out); }

/* ---------- Status bar ---------- */
.statusbar { display: flex; align-items: center; justify-content: space-between; height: calc(var(--s) * 34); }
.mode-chip { height: 100%; padding: 0 calc(var(--s) * 14); border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-size: calc(var(--s) * 14); font-weight: 800; }
.mode-chip.daily { background: linear-gradient(120deg, #f97316, #ec4899); border-color: transparent; color: #fff; }
.mode-chip.explore { background: linear-gradient(120deg, #0ea5e9, #8b5cf6); border-color: transparent; color: #fff; }
.timer { font-size: calc(var(--s) * 22); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.timer.hidden { visibility: hidden; }
.hint-dots { display: flex; gap: calc(var(--s) * 5); min-width: calc(var(--s) * 60); justify-content: flex-end; }
.hint-dots i { width: calc(var(--s) * 11); height: calc(var(--s) * 11); border-radius: 50%; background: var(--accent); box-shadow: 0 0 calc(var(--s) * 8) var(--glow); }
.hint-dots i.used { background: var(--line); box-shadow: none; }

/* ---------- Board ---------- */
.board {
  flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
  border-radius: calc(var(--s) * 26); background: linear-gradient(180deg, var(--panel), var(--bg2)); border: 1px solid var(--line);
  padding: calc(var(--s) * 10) calc(var(--s) * 12); position: relative; overflow: hidden; container-type: size;
}
.target { display: flex; flex-direction: column; align-items: center; gap: calc(var(--s) * 6); }
.label { font-size: calc(var(--s) * 12); letter-spacing: .22em; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.target-row { display: flex; align-items: center; gap: calc(var(--s) * 8); }
.target-die {
  --size: min(calc(var(--s) * 66), 13cqh);
  width: var(--size); height: var(--size); border-radius: calc(var(--size) * .2); display: grid; place-items: center;
  font-weight: 800; font-size: calc(var(--size) * .46); color: #fff;
  box-shadow: inset 0 calc(var(--s) * -4) 0 rgba(0, 0, 0, .25), inset 0 calc(var(--s) * 3) 0 rgba(255, 255, 255, .25), 0 calc(var(--s) * 6) calc(var(--s) * 14) rgba(0, 0, 0, .35);
}
.target-die.tens { background: linear-gradient(150deg, #ef4444, #b91c1c); }
.target-die.units { background: linear-gradient(150deg, #3b82f6, #1d4ed8); }
.target-plus, .target-eq { font-size: calc(var(--s) * 22); color: var(--muted); font-weight: 800; }
.target-number { font-size: min(calc(var(--s) * 60), 12cqh); line-height: 1; font-weight: 800; color: var(--accent); min-width: 1.3em; text-align: center; font-variant-numeric: tabular-nums; }
.target.win .target-number { color: var(--good); animation: pop .6s var(--ease-out); }
.target.miss { animation: shake .45s; }
.target.miss .target-number { color: var(--bad); }

.tray {
  --tsize: min(calc(var(--s) * 112), 24cqh, 27cqw);
  --gap: calc(var(--s) * 14);
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: var(--gap);
  width: calc(var(--tsize) * var(--cols, 3) + var(--gap) * (var(--cols, 3) - 1));
  min-height: calc(var(--tsize) * 2 + var(--gap));
}
.tile {
  position: relative; width: var(--tsize); height: var(--tsize); border-radius: calc(var(--tsize) * .2);
  transition: transform .18s var(--ease-out), filter .18s; perspective: calc(var(--tsize) * 6);
}
.tile.selected { transform: translateY(calc(var(--s) * -8)) scale(1.06); }
.tile.selected::after {
  content: ""; position: absolute; inset: calc(var(--s) * -5); border-radius: calc(var(--tsize) * .26);
  border: calc(var(--s) * 3) solid var(--accent); box-shadow: 0 0 calc(var(--s) * 18) var(--glow); pointer-events: none;
}
.tile .order {
  position: absolute; top: calc(var(--s) * -10); left: calc(var(--s) * -10); z-index: 3; width: calc(var(--s) * 24); height: calc(var(--s) * 24);
  border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: calc(var(--s) * 13); font-weight: 800; display: grid; place-items: center;
}
.tile.hinted { animation: hint-pulse 1.1s ease-in-out 3; }
.tile.shake { animation: shake .4s; }

/* Dice are true 3D cubes so they can tumble when rolled */
.cube { position: absolute; inset: 0; transform-style: preserve-3d; }
.face {
  position: absolute; inset: 0; border-radius: calc(var(--tsize) * .2); backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: radial-gradient(120% 120% at 30% 20%, #fff 0%, var(--tile) 55%, #e2e2dc 100%);
  box-shadow: inset 0 calc(var(--s) * -5) calc(var(--s) * 6) rgba(0, 0, 0, .12), inset 0 calc(var(--s) * 3) calc(var(--s) * 3) rgba(255, 255, 255, .9);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 16%;
}
.cube.at-rest .face:not(.front) { display: none; }
.tile:not(.result) .cube.at-rest { filter: drop-shadow(0 calc(var(--s) * 6) calc(var(--s) * 8) rgba(0, 0, 0, .35)); }
.face.front { transform: translateZ(calc(var(--tsize) / 2)); }
.cube.at-rest .face.front { transform: none; }
.face.back { transform: rotateY(180deg) translateZ(calc(var(--tsize) / 2)); }
.face.right { transform: rotateY(90deg) translateZ(calc(var(--tsize) / 2)); }
.face.left { transform: rotateY(-90deg) translateZ(calc(var(--tsize) / 2)); }
.face.top { transform: rotateX(90deg) translateZ(calc(var(--tsize) / 2)); }
.face.bottom { transform: rotateX(-90deg) translateZ(calc(var(--tsize) / 2)); }
.pip { width: 78%; aspect-ratio: 1; border-radius: 50%; place-self: center; background: radial-gradient(circle at 35% 30%, #4a4f5c, var(--tile-ink) 60%); box-shadow: inset 0 calc(var(--s) * 1) calc(var(--s) * 1) rgba(0, 0, 0, .6); }
.p1 { grid-area: 1 / 1; } .p2 { grid-area: 1 / 2; } .p3 { grid-area: 1 / 3; }
.p4 { grid-area: 2 / 1; } .p5 { grid-area: 2 / 2; } .p6 { grid-area: 2 / 3; }
.p7 { grid-area: 3 / 1; } .p8 { grid-area: 3 / 2; } .p9 { grid-area: 3 / 3; }

.tile.result .num {
  position: absolute; inset: 0; border-radius: inherit; display: grid; place-items: center;
  background: linear-gradient(160deg, color-mix(in srgb, var(--result) 75%, #fff), var(--result)); color: var(--result-ink);
  font-weight: 800; font-size: calc(var(--tsize) * .42); font-variant-numeric: tabular-nums;
  box-shadow: inset 0 calc(var(--s) * -5) 0 rgba(0, 0, 0, .14), 0 calc(var(--s) * 6) calc(var(--s) * 12) rgba(0, 0, 0, .3);
}
.tile.result .num.long { font-size: calc(var(--tsize) * .33); }
.tile.final .num { background: linear-gradient(160deg, #86efac, var(--good)); color: #052e14; }
.tile.final.wrong .num { background: linear-gradient(160deg, #fda4af, var(--bad)); color: #4c0519; }

.working {
  list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: calc(var(--s) * 6);
  min-height: calc(var(--s) * 28); max-width: 100%;
}
.working li { padding: calc(var(--s) * 5) calc(var(--s) * 10); border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); font-size: calc(var(--s) * 13); color: var(--muted); white-space: nowrap; animation: fade-in .3s; }
.working li b { color: var(--text); }
.working.hidden { visibility: hidden; }

.prompt { margin: 0; text-align: center; font-size: calc(var(--s) * 16); min-height: calc(var(--s) * 22); color: var(--muted); }
.prompt b { color: var(--text); }
.prompt.bad { color: var(--bad); }
.prompt.good { color: var(--good); }

/* ---------- Operators & actions ---------- */
.ops { display: grid; grid-template-columns: repeat(4, 1fr); gap: calc(var(--s) * 10); }
.op {
  height: calc(var(--s) * 66); border-radius: var(--radius); font-size: calc(var(--s) * 38); font-weight: 800; color: #fff; line-height: 1;
  box-shadow: inset 0 calc(var(--s) * -5) 0 rgba(0, 0, 0, .25), inset 0 calc(var(--s) * 2) 0 rgba(255, 255, 255, .25);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.op:active { transform: translateY(calc(var(--s) * 2)); box-shadow: inset 0 calc(var(--s) * -2) 0 rgba(0, 0, 0, .25); }
.op-add { background: linear-gradient(160deg, #3b82f6, var(--add)); }
.op-sub { background: linear-gradient(160deg, #ef4444, var(--sub)); }
.op-mul { background: linear-gradient(160deg, #22c55e, var(--mul)); }
.op-div { background: linear-gradient(160deg, #a78bfa, var(--div)); }
.op.active { outline: calc(var(--s) * 4) solid var(--accent); outline-offset: calc(var(--s) * 2); transform: translateY(calc(var(--s) * -3)); }
.op.hinted { animation: hint-pulse 1.1s ease-in-out 3; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: calc(var(--s) * 10); }
.action {
  height: calc(var(--s) * 54); border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--s) * 2); font-size: calc(var(--s) * 12); font-weight: 800;
}
.action svg { width: calc(var(--s) * 20); height: calc(var(--s) * 20); }
.action:disabled { opacity: .4; }
.action.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.action.attention { animation: hint-pulse 1.4s ease-in-out infinite; }

/* ---------- Sheets (dialogs) ---------- */
dialog.sheet {
  width: min(100vw - 24px, 440px); max-height: calc(var(--app-h) - 32px); padding: 0; border: 1px solid var(--line);
  border-radius: 24px; background: var(--panel); color: var(--text); overflow: hidden;
}
dialog.sheet[open] { animation: sheet-in .28s var(--ease-out); display: flex; flex-direction: column; }
dialog.sheet::backdrop { background: rgba(2, 4, 10, .6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.sheet-body { padding: 20px; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 14px; user-select: text; -webkit-user-select: text; }
.sheet h2 { margin: 0; font-size: 22px; font-weight: 800; }
.sheet p { margin: 0; line-height: 1.45; color: var(--muted); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.close { width: 36px; height: 36px; border-radius: 12px; background: var(--panel2); font-size: 16px; }
.btn { height: 50px; border-radius: 14px; font-weight: 800; font-size: 16px; padding: 0 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--panel2); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.sheet-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.link-btn { color: var(--accent); font-weight: 800; padding: 6px 0; text-align: left; }
[data-theme="daylight"] .link-btn { color: #1d4ed8; }
.fine { font-size: 13px; }
.section-title { margin: 6px 0 0; font-size: 15px; font-weight: 800; display: flex; justify-content: space-between; }
.section-title small { color: var(--muted); font-weight: 600; }

.setting { display: flex; flex-direction: column; gap: 8px; }
.setting-label { font-size: 13px; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.segmented button { height: 40px; border-radius: 10px; font-size: 14px; font-weight: 800; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatches button { height: 54px; border-radius: 14px; font-size: 13px; font-weight: 800; border: 2px solid transparent; }
.swatches button[aria-checked="true"] { border-color: var(--accent); }
.sw-midnight { background: linear-gradient(140deg, #17223d, #05070b); color: #fff; }
.sw-felt { background: linear-gradient(140deg, #0f4a33, #062016); color: #f3f1e7; }
.sw-daylight { background: linear-gradient(140deg, #ffffff, #e3e8f2); color: #121826; }
.toggle { display: flex; justify-content: space-between; align-items: center; min-height: 44px; font-size: 16px; }
.toggle input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; margin: 0; cursor: pointer; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease-out); }
.toggle input:checked { background: var(--good); }
.toggle input:checked::after { transform: translateX(20px); }
.menu-links { display: flex; flex-direction: column; border-top: 1px solid var(--line); padding-top: 6px; }
.version { font-size: 12px !important; text-align: center; opacity: .7; }

/* Win sheet */
.win-sheet .sheet-body { text-align: center; align-items: stretch; }
.win-kicker { font-size: 15px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; color: var(--good) !important; }
.win-time { font-size: 54px !important; line-height: 1; font-variant-numeric: tabular-nums; }
.xp-gain { background: var(--panel2); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.xp-line { display: flex; justify-content: space-between; font-weight: 800; }
.xp-line span:last-child { color: var(--accent); }
[data-theme="daylight"] .xp-line span:last-child { color: #b45309; }
.level-up { color: var(--accent) !important; font-weight: 800; animation: pop .6s var(--ease-out); }
.unlocked { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.unlocked li { display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 12px; border-radius: 14px; background: linear-gradient(120deg, color-mix(in srgb, var(--accent) 22%, transparent), transparent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); animation: pop .5s var(--ease-out) both; }
.unlocked li .ach-icon { font-size: 26px; }
.unlocked li small { display: block; color: var(--muted); font-weight: 600; }

/* Family rooms */
body.in-room .level-chip .level-bar { display: none; }
body.in-room .level-chip { padding-right: calc(var(--s) * 5); }
.pending-dot { position: absolute; top: calc(var(--s) * -4); right: calc(var(--s) * -4); width: calc(var(--s) * 14); height: calc(var(--s) * 14); border-radius: 50%; background: #f97316; box-shadow: 0 0 0 2px var(--bg); }
.record-line { margin: 0; font-size: calc(var(--s) * 13); color: var(--muted); min-height: 1.2em; }
.record-line b { color: var(--accent); }
[data-theme="daylight"] .record-line b { color: #b45309; }
.win-record { font-weight: 800; color: var(--text) !important; }
.win-record.new { color: var(--accent) !important; animation: pop .6s var(--ease-out); }
[data-theme="daylight"] .win-record.new { color: #b45309 !important; }
.room-box { background: var(--panel2); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.room-box p { font-size: 14px; }
.link-row { display: flex; gap: 8px; align-items: center; }
.link-row code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; user-select: all; -webkit-user-select: all; }
.link-row .btn { height: 40px; font-size: 14px; flex: none; }
.text-input { width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font: inherit; padding: 0 14px; font-size: 17px; user-select: text; -webkit-user-select: text; }
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.family-body { display: flex; flex-direction: column; gap: 12px; }
.family-body h3 { margin: 4px 0 0; font-size: 15px; font-weight: 800; }
.family-body .note { font-size: 13px; color: var(--muted); margin: 0; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 9px 10px; border-radius: 12px; background: var(--panel2); font-size: 15px; }
.row.me { outline: 2px solid var(--accent); }
.row .rank { color: var(--muted); font-weight: 800; text-align: center; }
.row .val { font-variant-numeric: tabular-nums; font-weight: 800; }
.row small { color: var(--muted); font-size: 12px; }
.champion { padding: 12px; border-radius: 14px; background: linear-gradient(120deg, color-mix(in srgb, var(--accent) 25%, transparent), transparent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); font-size: 15px; }
.game-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 10px; border-radius: 12px; background: var(--panel2); }
.game-row .who { font-weight: 800; font-size: 14px; }
.game-row .who small { color: var(--muted); font-weight: 600; margin-left: 6px; }
.game-row .what { grid-column: 1; font-size: 13px; color: var(--muted); }
.game-row .what b { color: var(--text); font-variant-numeric: tabular-nums; }
.game-row .btn { grid-column: 2; grid-row: 1 / span 2; height: 38px; font-size: 13px; padding: 0 12px; }
.mini-dice { font-weight: 800; letter-spacing: .08em; color: var(--text); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 14px; }

/* Routes found */
.routes-sub { font-weight: 800; }
.routes-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.routes-list li { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 10px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); }
.routes-list li.new { border-color: var(--good); animation: pop .5s var(--ease-out); }
.route-num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.route-steps { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.route-steps i { font-style: normal; font-size: 13px; color: var(--muted); white-space: nowrap; }
.route-steps i:not(:last-child)::after { content: " →"; opacity: .5; }
.route-steps b { color: var(--text); }
.routes-list small { color: var(--muted); font-size: 11px; }

/* Profile */
.profile-level { display: flex; gap: 14px; align-items: center; }
.profile-level > div { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.profile-level small { color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--panel2); border-radius: 14px; padding: 10px 6px; text-align: center; }
.stat b { display: block; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.ach-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ach { background: var(--panel2); border-radius: 14px; padding: 10px 4px; text-align: center; font-size: 11px; line-height: 1.25; }
.ach .ach-icon { font-size: 26px; display: block; margin-bottom: 4px; }
.ach.locked { opacity: .4; }
.ach.locked .ach-icon { filter: grayscale(1); }

/* Daily */
.daily-sub { font-weight: 800; }
.daily-streak { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.daily-streak > div { background: var(--panel2); border-radius: 14px; padding: 10px 4px; }
.daily-streak b { display: block; font-size: 26px; font-weight: 800; }
.daily-streak > div:first-child b { color: #f97316; }
.daily-streak small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar span { aspect-ratio: 1; border-radius: 8px; background: var(--panel2); display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.calendar span.done { background: var(--good); color: #052e14; font-weight: 800; }
.calendar span.today { outline: 2px solid var(--accent); }
.calendar span.future { opacity: .3; }

/* Help */
.goal { font-size: 17px; color: var(--text) !important; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: flex; flex-direction: column; gap: 12px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 34px 1fr; column-gap: 12px; }
.steps li::before { content: counter(s); grid-row: span 2; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; }
.steps span { color: var(--muted); font-size: 14px; }

/* Toasts & effects */
.toasts { position: fixed; left: 50%; top: max(env(safe-area-inset-top), 12px); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .35); font-size: 15px; animation: toast-in .3s var(--ease-out); }
.toast.leaving { animation: toast-out .3s forwards; }
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.ghost { position: fixed; z-index: 41; pointer-events: none; }
.confetti { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; }

@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes hint-pulse { 0%, 100% { filter: none; } 50% { filter: drop-shadow(0 0 12px var(--accent)) brightness(1.15); } }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px) scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-12px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* Very short screens (landscape phones, split view): tighten the gaps. */
@media (max-height: 560px) { .working { display: none; } }
