/* AlleyCats - one stylesheet.
   Layout: a single phone-width column. The board is the hero; everything around it stays quiet.
   Every color is a token, defined for light first and redefined for dark below. */

@font-face { font-family: 'Grandstander'; src: url('../fonts/grandstander.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Nunito'; src: url('../fonts/nunito.woff2') format('woff2'); font-weight: 200 1000; font-display: swap; }

:root {
  /* page */
  --bg: #F3F1FA;            /* morning fog */
  --bg-2: #E8E4F4;
  --surface: #FFFFFF;
  --ink: #2A2440;           /* plum ink */
  --ink-soft: #6A6386;
  --line: rgba(42, 36, 64, .12);
  --lip: rgba(42, 36, 64, .2);
  --accent: #F9A62B;        /* tabby orange */
  --accent-deep: #C9780A;
  --accent-soft: #FFE9C4;
  --accent-ink: #2A2440;
  --heart: #F0527A;
  --good: #2FA36B;
  --good-soft: #D5F2E2;
  --danger: #D8436A;
  --shadow: 0 10px 28px rgba(42, 36, 64, .14);
  --shadow-sm: 0 2px 8px rgba(42, 36, 64, .08);
  --back: rgba(30, 24, 54, .55);
  /* board */
  --board-line: #2A2440;
  --grid: rgba(42, 36, 64, .2);
  --x-ink: rgba(42, 36, 64, .6);
  --shape-ink: rgba(42, 36, 64, .1);
  --glow: rgba(255, 255, 255, .5);
  --fade: saturate(.3) brightness(1.1);
  /* region palette: ten colors (a 10x10 board uses all of them). Lime and coral were chosen
     by measured distance from the other eight, in both themes. */
  --r0: #F8A9B8; --r1: #FBC27A; --r2: #F4E38A; --r3: #A6E0B4;
  --r4: #8EDCDD; --r5: #9FC6F8; --r6: #C6B3F6; --r7: #D5CBBE;
  --r8: #C9E66E; --r9: #F08A72;
  /* home scene */
  --orb: #FFC94D; --moon: 0; --roofs: #DCD6EE; --window: #FFF6D6; --fence: #C7BFE0; --scene-cat: #2A2440; --scene-eye: #FFE27A;
  /* praise word */
  --praise-fill: #FFE27A; --praise-edge: #2A2440;
  /* type */
  --font-display: 'Grandstander', 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* safe areas (the preview host already pads the page, so the preview build zeroes these) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15132A; --bg-2: #1D1A36; --surface: #25223F; --ink: #EFECFB; --ink-soft: #A9A3C8;
    --line: rgba(239, 236, 251, .14); --lip: rgba(0, 0, 0, .45);
    --accent: #FFC94D; --accent-deep: #B8860B; --accent-soft: #4A3E1E; --accent-ink: #2A2440;
    --heart: #FF6B8E; --good: #4CC98A; --good-soft: #1F4434; --danger: #FF6B8E;
    --shadow: 0 10px 28px rgba(0, 0, 0, .45); --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3); --back: rgba(6, 5, 16, .7);
    --board-line: #0B0A17; --grid: rgba(11, 10, 23, .4); --x-ink: rgba(255, 255, 255, .85); --shape-ink: rgba(255, 255, 255, .13);
    --glow: rgba(255, 255, 255, .28); --fade: saturate(.3) brightness(.7);
    --r0: #B9516C; --r1: #BD7A30; --r2: #A0902F; --r3: #3F9462; --r4: #2F9096; --r5: #4373BD; --r6: #7759C7; --r7: #7D7369; --r8: #6F9A22; --r9: #C24A32;
    --orb: #FFE9A8; --moon: 1; --roofs: #221E44; --window: #FFD76A; --fence: #2F2A58; --scene-cat: #0B0A17; --scene-eye: #FFE27A;
    --praise-fill: #FFE27A; --praise-edge: #0B0A17;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15132A; --bg-2: #1D1A36; --surface: #25223F; --ink: #EFECFB; --ink-soft: #A9A3C8;
  --line: rgba(239, 236, 251, .14); --lip: rgba(0, 0, 0, .45);
  --accent: #FFC94D; --accent-deep: #B8860B; --accent-soft: #4A3E1E; --accent-ink: #2A2440;
  --heart: #FF6B8E; --good: #4CC98A; --good-soft: #1F4434; --danger: #FF6B8E;
  --shadow: 0 10px 28px rgba(0, 0, 0, .45); --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3); --back: rgba(6, 5, 16, .7);
  --board-line: #0B0A17; --grid: rgba(11, 10, 23, .4); --x-ink: rgba(255, 255, 255, .85); --shape-ink: rgba(255, 255, 255, .13);
  --glow: rgba(255, 255, 255, .28); --fade: saturate(.3) brightness(.7);
  --r0: #B9516C; --r1: #BD7A30; --r2: #A0902F; --r3: #3F9462; --r4: #2F9096; --r5: #4373BD; --r6: #7759C7; --r7: #7D7369; --r8: #6F9A22; --r9: #C24A32;
  --orb: #FFE9A8; --moon: 1; --roofs: #221E44; --window: #FFD76A; --fence: #2F2A58; --scene-cat: #0B0A17; --scene-eye: #FFE27A;
  --praise-fill: #FFE27A; --praise-edge: #0B0A17;
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 500 16px/1.45 var(--font-body);
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
  touch-action: manipulation; overscroll-behavior: none;
}
h1, h2, h3, p, dl, dd, ol, ul, fieldset { margin: 0; padding: 0; }
ol, ul { list-style: none; }
fieldset { border: 0; min-width: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.icon { width: 24px; height: 24px; flex: none; }

#app {
  height: 100%; max-width: 480px; margin: 0 auto;
  padding-top: var(--safe-top); display: flex; flex-direction: column;
}
/* The 16px side gutter lives on the scrolling view, so shadows have room and are not clipped. */
#view { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-inline: 16px; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
#view::-webkit-scrollbar { display: none; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding-block: 10px calc(14px + var(--safe-bottom)); }
.scroll { flex: 1; min-height: 0; overflow-y: auto; margin-inline: -16px; padding-inline: 16px; padding-bottom: 8px; }
.ad-slot { min-height: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 12px 18px; border: 0; border-radius: 16px;
  font: 700 18px/1.1 var(--font-display); color: var(--ink); background: var(--surface);
  box-shadow: 0 4px 0 var(--lip), var(--shadow-sm);
  transition: transform .06s ease, box-shadow .06s ease; text-align: left;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--lip); }
.btn:disabled { opacity: .6; }
.btn-primary { background: var(--accent); color: var(--accent-ink); --lip: var(--accent-deep); }
.btn-ghost { background: transparent; box-shadow: none; color: var(--ink-soft); min-height: 44px; }
.btn-ghost:active { transform: none; box-shadow: none; background: var(--line); }
.btn-wide { width: 100%; text-align: center; }
.btn-small { min-height: 40px; padding: 8px 14px; font-size: 15px; border-radius: 12px; box-shadow: 0 3px 0 var(--lip); gap: 6px; }
.btn-small .icon { width: 18px; height: 18px; }
.btn-danger { color: var(--danger); }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: 0 3px 0 var(--lip), var(--shadow-sm);
  transition: transform .06s ease, box-shadow .06s ease;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--lip); }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--bg-2); }
.seg button { border: 0; background: transparent; padding: 7px 12px; min-height: 36px; border-radius: 9px; font: 700 14px/1 var(--font-display); color: var(--ink-soft); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.chip { display: inline-block; padding: 3px 9px; border-radius: 999px; font: 700 12px/1.2 var(--font-display); letter-spacing: .02em; background: var(--bg-2); color: var(--ink-soft); }
.chip.grade-1 { background: var(--r3); color: #1C3A27; }
.chip.grade-2 { background: var(--r5); color: #16294A; }
.chip.grade-3 { background: var(--r1); color: #4A2C08; }
.chip.grade-4 { background: var(--r0); color: #4A1322; }
:root[data-theme="dark"] .chip[class*="grade-"] { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip[class*="grade-"] { color: #fff; } }

/* ---------- top bar ---------- */
.bar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; flex: none; }
.bar-title { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.bar-title strong { font: 700 20px/1.1 var(--font-display); }
.bar-right { display: flex; justify-content: flex-end; }

/* ---------- home ---------- */
.home { gap: 14px; }
.home-top { display: flex; justify-content: space-between; align-items: center; flex: none; }
.chip-btn { display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 4px 14px 4px 5px; border: 0; border-radius: 999px; background: var(--surface); box-shadow: 0 3px 0 var(--lip), var(--shadow-sm); font: 700 15px/1 var(--font-display); max-width: 70%; }
.chip-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar-svg { border-radius: 50%; flex: none; }
.avatar-svg.small { width: 34px; height: 34px; }
.avatar-svg.big { width: 104px; height: 104px; box-shadow: 0 5px 0 var(--lip); }
.home .credit { margin-top: auto; }
.hero { flex: none; display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 20px; border-radius: 24px; overflow: hidden; background: linear-gradient(var(--bg-2), var(--bg)); }
.wordmark { font: 800 clamp(46px, 15vw, 64px)/.95 var(--font-display); letter-spacing: -.015em; color: var(--ink); }
.tagline { font: 700 15px/1.3 var(--font-display); color: var(--ink-soft); margin-top: 6px; }
.scene { display: block; width: 100%; height: auto; margin-top: 2px; }
.scene-orb { fill: var(--orb); }
.scene-orb-cut { fill: var(--bg-2); opacity: var(--moon); }
.scene-roofs { fill: var(--roofs); }
.scene-windows { fill: var(--window); }
.scene-fence { fill: var(--fence); }
.scene-cat { fill: var(--scene-cat); stroke: var(--scene-cat); }
.scene-eyes { fill: var(--scene-eye); }
.menu { display: flex; flex-direction: column; gap: 12px; flex: none; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn-big { min-height: 72px; font-size: 26px; justify-content: flex-start; padding-inline: 22px; }
.btn-big .icon { width: 30px; height: 30px; }
.btn-big small, .btn-card small { margin-left: auto; font: 700 14px/1.2 var(--font-display); opacity: .8; text-align: right; }
.btn-card { justify-content: flex-start; min-height: 60px; }
.btn-card small { display: inline-flex; align-items: center; gap: 4px; }
.btn-card small .icon { width: 16px; height: 16px; }
.btn-card small.fresh { color: var(--accent-deep); opacity: 1; }
.btn-card small.done { color: var(--good); opacity: 1; }
.progress-line { flex: none; display: flex; flex-direction: column; gap: 6px; }
.progress-line p { font-size: 13px; color: var(--ink-soft); text-align: center; }
.meter { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.meter i { display: block; height: 100%; min-width: 8px; border-radius: 99px; background: var(--accent); }
.credit { flex: none; text-align: center; font-size: 12px; color: var(--ink-soft); }

/* ---------- play ---------- */
.play { gap: 10px; }
.status { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 34px; }
.hearts { display: inline-flex; gap: 4px; color: var(--heart); }
.hearts .icon { width: 28px; height: 28px; }
.heart { display: inline-flex; transition: color .2s, transform .2s; }
.heart.lost { color: var(--line); transform: scale(.86); }
.heart.breaking { animation: heartbreak .6s ease-out; }
.hearts.mini .icon { width: 20px; height: 20px; }
.stats .hearts { grid-column: auto; }
.hearts { grid-column: 1; justify-self: start; }
.timer { grid-column: 2; font: 800 19px/1 var(--font-body); font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.found { grid-column: 3; justify-self: end; display: inline-flex; align-items: center; gap: 6px; font: 800 19px/1 var(--font-body); font-variant-numeric: tabular-nums; }
.found .icon { width: 20px; height: 20px; color: var(--accent-deep); }
.stage { position: relative; flex: 1 1 auto; min-height: 220px; display: grid; place-items: center; }
.tapmode { flex: none; display: flex; align-items: center; justify-content: center; gap: 10px; font: 700 14px/1 var(--font-display); color: var(--ink-soft); }
.tapmode .seg button { min-width: 64px; }
.tools { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tool { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 58px; border: 0; border-radius: 16px; background: var(--surface); color: var(--ink); font: 700 13px/1 var(--font-display); box-shadow: 0 4px 0 var(--lip), var(--shadow-sm); transition: transform .06s ease, box-shadow .06s ease; }
.tool:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--lip); }
.tool .badge { position: absolute; top: 6px; right: 22%; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font: 800 12px/1 var(--font-display); }
.tool.spent { color: var(--ink-soft); }
.tool.spent .badge { background: var(--bg-2); color: var(--ink-soft); }

/* ---------- board ---------- */
.board {
  position: relative; width: var(--board-size, 300px); height: var(--board-size, 300px);
  padding: 4px; border-radius: 16px; background: var(--board-line); box-shadow: var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; outline: none;
}
.board:focus-visible { box-shadow: 0 0 0 4px var(--accent), var(--shadow); }
.cells { display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr); width: 100%; height: 100%; border-radius: 12px; overflow: hidden; }
.cell { position: relative; background: var(--c); min-width: 0; min-height: 0; }
.cell > span { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.shape { color: var(--shape-ink); visibility: hidden; }
.show-shapes .shape { visibility: visible; }
.shape-svg { width: 64%; height: 64%; }
.mark { color: var(--x-ink); opacity: 0; transform: scale(.3) rotate(-20deg); transition: opacity .08s, transform .14s cubic-bezier(.3, 1.7, .5, 1); }
.is-x .mark { opacity: 1; transform: none; }
.is-cat .mark, .is-cat .shape { visibility: hidden; }
.x-svg { width: 54%; height: 54%; }
.cat-svg { width: 90%; height: 90%; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .16)); }
/* A cat a Hint placed carries a small dot in the Hint button's color, so it reads as "this one was given". */
.is-given .pet::after { content: ''; position: absolute; top: 5%; right: 5%; width: 21%; height: 21%; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--board-line); }
.cell.faded { filter: var(--fade); }
.cell.cursor { z-index: 2; }
.board:focus-visible .cell.cursor { outline: 3px solid var(--accent); outline-offset: -3px; }

.lines { position: absolute; inset: 4px; width: calc(100% - 8px); height: calc(100% - 8px); pointer-events: none; overflow: visible; }
.lines path, .lines rect { fill: none; vector-effect: non-scaling-stroke; }
.lines .thin { stroke: var(--grid); stroke-width: 1; }
.lines .thick { stroke: var(--board-line); stroke-width: 3.5; stroke-linecap: round; }
.lines .frame-back { stroke: var(--board-line); stroke-width: 9; }
.lines .frame { stroke: #fff; stroke-width: 5; }
.board .cell { transition: filter .25s ease; }
.board.has-frame .cell:not(.framed) { filter: brightness(.68) saturate(.6); }

.cell.pop .pet { animation: pop .5s cubic-bezier(.2, 1.8, .4, 1); }
.cell.pop::before { content: ''; position: absolute; inset: -30%; border-radius: 50%; background: radial-gradient(closest-side, rgba(255, 255, 255, .95), rgba(255, 255, 255, 0) 70%); animation: burst .55s ease-out forwards; pointer-events: none; z-index: 1; }
.cell.wiggle .pet { animation: wiggle .42s ease-in-out; }
.cell.shake { animation: shake .42s ease-in-out; z-index: 2; }
.cell.shake::after { content: ''; position: absolute; inset: 0; background: var(--heart); animation: flash .45s ease-out forwards; pointer-events: none; }
.cell.tip::after { content: ''; position: absolute; inset: 14%; border-radius: 28%; border: 3px solid var(--accent); box-shadow: 0 0 0 2px var(--board-line); animation: tip 1.05s ease-in-out 2; pointer-events: none; }
.cell.target::after, .cell.target-cat::after { content: ''; position: absolute; inset: 8%; border-radius: 26%; border: 4px solid #fff; box-shadow: 0 0 0 2px var(--board-line), 0 0 14px 4px rgba(255, 255, 255, .8); animation: target 1s ease-in-out infinite; pointer-events: none; }
.cell.shine::before { content: ''; position: absolute; inset: 0; background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .8) 50%, transparent 70%); background-size: 260% 100%; animation: shine .6s var(--d, 0ms) ease-out both; pointer-events: none; z-index: 1; }

.praise {
  position: absolute; left: 50%; top: 40%; z-index: 6; pointer-events: none; white-space: nowrap;
  font: 800 clamp(30px, 10vw, 46px)/1 var(--font-display); color: var(--praise-fill);
  -webkit-text-stroke: 7px var(--praise-edge); paint-order: stroke fill;
  animation: praise 1.25s cubic-bezier(.2, .9, .3, 1) forwards;
}
.praise.at-point { font-size: clamp(22px, 7vw, 32px); -webkit-text-stroke-width: 6px; }
.praise-great { color: #fff; }
.praise-bad { color: #FF8FA8; }
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ---------- levels ---------- */
.chapter { margin-bottom: 22px; }
.chapter header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.chapter h2 { font: 800 22px/1.1 var(--font-display); }
.chapter header p { font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tile { position: relative; aspect-ratio: 1; border: 0; border-radius: 14px; display: grid; place-items: center; background: var(--surface); color: var(--ink); font: 800 17px/1 var(--font-body); font-variant-numeric: tabular-nums; box-shadow: 0 3px 0 var(--lip); }
.tile:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--lip); }
.tile .icon { position: absolute; right: 5px; bottom: 5px; width: 14px; height: 14px; }
.tile.done { background: var(--good-soft); }
.tile.done .icon { color: var(--good); }
.tile.perfect { background: var(--accent-soft); }
.tile.perfect .icon { color: var(--accent-deep); }
.tile.locked { background: transparent; box-shadow: inset 0 0 0 2px var(--line); color: var(--ink-soft); }
.tile.locked span { opacity: .55; }
.tile.current { box-shadow: 0 3px 0 var(--accent-deep), 0 0 0 3px var(--accent); }

/* ---------- cards, rows, lists ---------- */
.card { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-sm); overflow: hidden; }
.notice { padding: 14px 16px; border-radius: 14px; background: var(--bg-2); color: var(--ink-soft); font-size: 14px; margin-bottom: 12px; }
.notice.warn { background: var(--accent-soft); color: var(--ink); }
.settings h2 { font: 800 13px/1 var(--font-display); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin: 18px 4px 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px; border: 0; background: transparent; text-align: left; border-top: 1px solid var(--line); }
.card > .row:first-child { border-top: 0; }
.row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-text b { font: 700 16px/1.25 var(--font-display); }
.row-text small { font-size: 13px; color: var(--ink-soft); line-height: 1.3; }
.row-seg { flex-wrap: wrap; }
.row-stack { flex-direction: column; align-items: stretch; }
.row-link .icon { color: var(--ink-soft); width: 20px; height: 20px; }
.row-note { color: var(--ink-soft); font-size: 14px; }
.row-about { justify-content: flex-start; }
.about-cat { width: 48px; height: 48px; flex: none; }
.code-line { display: flex; gap: 8px; align-items: center; }
.code-line code { flex: 1; min-width: 0; padding: 9px 10px; border-radius: 10px; background: var(--bg-2); font: 600 12px/1.3 ui-monospace, 'SF Mono', Menlo, Consolas, monospace; overflow-wrap: anywhere; user-select: all; }
.code-line input { flex: 1; min-width: 0; height: 40px; padding: 0 10px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg); }
.confirm { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.confirm p { flex: 1 1 100%; font-size: 14px; }
.reset-row > .btn { align-self: flex-start; }
.switch { appearance: none; -webkit-appearance: none; flex: none; width: 52px; height: 32px; margin: 0; border-radius: 99px; background: var(--lip); position: relative; cursor: pointer; transition: background .15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch:checked { background: var(--good); }
.switch:checked::after { transform: translateX(20px); }

.tabs { align-self: center; flex: none; }
.tabs button { min-width: 110px; }
.lb-list { display: flex; flex-direction: column; gap: 6px; }
.lb-list li { display: grid; grid-template-columns: 34px 34px 1fr auto; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 14px; background: var(--surface); }
.lb-list li.me { box-shadow: inset 0 0 0 2px var(--accent); }
.lb-list .rank { font: 800 16px/1 var(--font-body); text-align: center; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.lb-list .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 16px/1.2 var(--font-display); }
.lb-list .who em { font: 700 11px/1 var(--font-display); font-style: normal; padding: 2px 6px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); }
.lb-list .val { font: 800 17px/1 var(--font-body); font-variant-numeric: tabular-nums; }
.local { padding: 16px; }
.local h3 { font: 800 17px/1.2 var(--font-display); margin-bottom: 10px; }
.stats { display: grid; gap: 0; }
.stats > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.stats > div:first-child { border-top: 0; }
.stats dt { color: var(--ink-soft); font-size: 15px; }
.stats dd { font: 800 18px/1 var(--font-body); font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 8px; }
.tag { font: 700 11px/1 var(--font-display); padding: 3px 7px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); }

/* ---------- profile ---------- */
.profile-form { display: flex; flex-direction: column; gap: 16px; padding-top: 6px; }
.profile-form h1 { font: 800 32px/1.05 var(--font-display); text-align: center; text-wrap: balance; }
.avatar-preview { display: grid; place-items: center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .avatars legend { font: 800 13px/1 var(--font-display); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 4px; }
.field input { height: 54px; padding: 0 16px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); font: 700 20px/1 var(--font-display); }
.field input:focus { outline: none; border-color: var(--accent); }
.field input.bad { border-color: var(--danger); }
.field .help { font-size: 13px; color: var(--ink-soft); }
.field .error { font-size: 14px; font-weight: 700; color: var(--danger); }
.avatar-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
@media (max-width: 380px) { .avatar-grid { grid-template-columns: repeat(4, 1fr); } }
.avatar-pick { padding: 3px; border: 0; border-radius: 50%; background: transparent; aspect-ratio: 1; display: grid; }
.avatar-pick .avatar-svg { width: 100%; height: 100%; }
.avatar-pick.on { box-shadow: 0 0 0 3px var(--accent); }

/* ---------- tutorial ---------- */
.tutorial { justify-content: center; }
.tut-key { display: flex; flex-direction: column; gap: 16px; align-items: stretch; margin-block: auto; }
.tut-hello { display: grid; place-items: center; }
.tut-cat { width: 84px; height: 84px; }
.tut-key h1, .tut-done h1 { font: 800 30px/1.08 var(--font-display); text-align: center; text-wrap: balance; }
.rules { display: flex; flex-direction: column; gap: 10px; }
.rule { display: grid; grid-template-columns: 88px 1fr; align-items: center; gap: 14px; padding: 10px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-sm); }
.rule p { font: 700 19px/1.2 var(--font-display); }
.mini-board { display: block; width: 100%; height: auto; }
.rules-compact { flex-direction: row; gap: 8px; flex: none; }
.rules-compact .rule { flex: 1; min-width: 0; grid-template-columns: 1fr; justify-items: center; gap: 6px; padding: 8px 6px; text-align: center; border-radius: 14px; }
.rules-compact .rule-pic { width: 54px; }
.rules-compact .rule p { font-size: 12.5px; line-height: 1.2; }
.tut-play { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.coach { flex: none; display: grid; grid-template-columns: 58px 1fr; gap: 10px; align-items: center; min-height: 96px; }
.coach-cat { width: 58px; height: 58px; }
.coach-bubble { position: relative; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-sm); }
.coach-bubble::before { content: ''; position: absolute; left: -7px; top: 50%; width: 16px; height: 16px; margin-top: -8px; background: var(--surface); transform: rotate(45deg); border-radius: 3px; }
.coach-text { position: relative; font: 700 17px/1.3 var(--font-display); }
.coach-nudge { position: relative; font: 700 15px/1.3 var(--font-display); color: var(--danger); }
.coach-bubble.bump { animation: bump .35s ease-out; }
.tut-hearts { flex: none; display: flex; justify-content: center; gap: 4px; color: var(--heart); }
.tut-hearts .icon { width: 30px; height: 30px; }
.tut-hearts.wobble { animation: wiggle .45s ease-in-out; }
.tut-stage { min-height: 200px; }
.tut-done { flex: none; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.tut-done p { color: var(--ink-soft); font-size: 16px; }

/* ---------- modals and toasts ---------- */
#modals:empty, #toasts:empty { display: none; }
.modal-back { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px 16px; background: var(--back); animation: fadein .18s ease-out; overflow-y: auto; }
.modal { position: relative; width: 100%; max-width: 380px; padding: 22px 20px 18px; border-radius: 26px; background: var(--bg); box-shadow: var(--shadow); animation: rise .28s cubic-bezier(.2, 1.3, .4, 1); display: flex; flex-direction: column; gap: 12px; overflow: hidden; }
.modal h2 { font: 800 30px/1.05 var(--font-display); text-align: center; text-wrap: balance; }
.modal > div { display: flex; flex-direction: column; gap: 12px; }
.modal p { text-align: center; }
.modal .note { color: var(--ink-soft); font-size: 14px; }
.win-cats { display: flex; justify-content: center; align-items: flex-end; gap: 2px; }
.win-cat { width: 96px; height: 96px; animation: hop .7s cubic-bezier(.3, 1.6, .5, 1) both; }
.win-cat.side { width: 62px; height: 62px; animation-delay: .12s; }
.perfect { display: flex; align-items: center; justify-content: center; gap: 6px; font: 700 15px/1.2 var(--font-display); color: var(--accent-deep); }
.perfect .icon { width: 18px; height: 18px; }
.win .stats, .daily-done .stats { padding: 4px 14px; border-radius: 16px; background: var(--surface); }
.fail-cat { width: 92px; height: 92px; align-self: center; }
.big-time { font: 800 24px/1.1 var(--font-display); font-variant-numeric: normal; }
.howto { display: flex; flex-direction: column; gap: 10px; }
.howto h3 { font: 800 13px/1 var(--font-display); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin: 10px 4px 0; text-align: left; }
.howto .rule { grid-template-columns: 76px 1fr; }
.howto .rule p { text-align: left; font-size: 16px; line-height: 1.25; }
.howto .how-lead { text-align: left; margin: 0 4px; color: var(--ink-soft); font-size: 15px; line-height: 1.35; }
.how-list { list-style: none; display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-sm); }
.how-list li { position: relative; padding-left: 16px; font-size: 16px; line-height: 1.3; text-align: left; }
.how-list li::before { content: ''; position: absolute; left: 0; top: .5em; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.howto-screen .scroll { display: flex; flex-direction: column; gap: 14px; padding-bottom: 16px; }
.btn-howto { min-height: 52px; }
/* In the game the page opens as a dialog: the text scrolls, the OK button stays in reach. */
.rules-modal .howto { max-height: min(60vh, 520px); overflow-y: auto; margin-inline: -8px; padding: 2px 8px 6px; }
.rules-modal .rule { grid-template-columns: 72px 1fr; }
.rules-modal .rule p { text-align: left; font-size: 17px; }

#toasts { position: fixed; left: 0; right: 0; bottom: calc(92px + var(--safe-bottom)); z-index: 60; display: flex; justify-content: center; padding-inline: 16px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 440px; padding: 11px 16px; border-radius: 16px; background: var(--ink); color: var(--bg); font: 700 15px/1.3 var(--font-display); box-shadow: var(--shadow); animation: rise .22s ease-out; }
.toast-btn { border: 0; border-radius: 10px; padding: 7px 12px; background: var(--accent); color: var(--accent-ink); font: 800 14px/1 var(--font-display); }

/* ---------- motion ---------- */
@keyframes pop { 0% { transform: scale(0) rotate(-25deg); } 100% { transform: none; } }
@keyframes burst { 0% { transform: scale(.2); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg); } 75% { transform: rotate(9deg); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9%); } 40% { transform: translateX(9%); } 60% { transform: translateX(-6%); } 80% { transform: translateX(6%); } }
@keyframes flash { 0% { opacity: .75; } 100% { opacity: 0; } }
@keyframes tip { 0%, 100% { transform: scale(.82); opacity: .45; } 50% { transform: scale(1); opacity: 1; } }
@keyframes target { 0%, 100% { transform: scale(.9); opacity: .75; } 50% { transform: scale(1); opacity: 1; } }
@keyframes shine { 0% { background-position: 130% 0; opacity: 1; } 100% { background-position: -40% 0; opacity: 0; } }
@keyframes praise { 0% { transform: translate(-50%, -30%) scale(.4); opacity: 0; } 18% { transform: translate(-50%, -60%) scale(1.12); opacity: 1; } 30% { transform: translate(-50%, -60%) scale(1); } 75% { opacity: 1; } 100% { transform: translate(-50%, -150%) scale(1); opacity: 0; } }
@keyframes heartbreak { 0% { transform: scale(1.5) rotate(0); color: var(--heart); } 40% { transform: scale(1.2) rotate(-14deg); color: var(--heart); } 100% { transform: scale(.86); } }
@keyframes fadein { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(18px); opacity: 0; } }
@keyframes hop { 0% { transform: translateY(26px) scale(.6); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.04); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* short screens: let the game page scroll instead of crushing the board */
@media (max-height: 560px) { .stage { min-height: 260px; } }
/* short phones: tighten the home screen so everything fits without scrolling */
@media (max-height: 700px) {
  .home { gap: 10px; }
  .hero { padding-top: 12px; }
  .wordmark { font-size: 44px; }
  .menu { gap: 10px; }
  .menu-row { gap: 10px; }
  .btn-big { min-height: 62px; font-size: 24px; }
  .btn-card { min-height: 54px; }
}
