/* ============================================================================
   FlowLine Puzzle — style.css
   Mobile-first. One palette, driven entirely by CSS custom properties.
   ==========================================================================*/

/* ------------------------------------------------------------------ reset */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  /* Kills double-tap zoom everywhere without a JS touchend suppressor, which
     would also cancel the compatibility click and eat rapid taps. */
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  transition: background-color .35s ease, color .35s ease;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }

/* ------------------------------------------------------------------ tokens
   One palette. These used to be the dark theme's values with light layered on
   top as an override, plus a neon variant — but the theme was never player-
   selectable, so both alternatives shipped as bytes that could never render. */
:root {
  /* Flat near-white ground. Kept a shade off pure white so the white cards,
     level tiles and tab bar separate from it. */
  --bg: #F7F9FC;
  --surface: rgba(255, 255, 255, .82);
  --surface-solid: #FFFFFF;
  --surface-2: rgba(20, 26, 45, .05);
  --border: rgba(20, 26, 45, .10);
  --border-strong: rgba(20, 26, 45, .18);
  --text: #131A2C;
  --muted: rgba(19, 26, 44, .62);
  --faint: rgba(19, 26, 44, .40);
  --faint-text: rgba(19, 26, 44, .64);
  --accent: #4F46E5;
  --danger: #E11D48;
  --gold: #E9A400;
  --shadow-lg: 0 22px 55px rgba(24, 32, 60, .18);
  --shadow-md: 0 10px 26px rgba(24, 32, 60, .12);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;

  /* Casual-game solids. Deliberately theme-independent: the wordmark, action
     buttons and level tiles keep the same identity in every theme. */
  --c-blue:   #3B8BF4;  --c-blue-dk:   #2C6FD0;  --c-blue-soft: #E8F1FE;
  --c-green:  #45B658;  --c-green-dk:  #359247;
  --c-amber:  #F5B932;  --c-amber-dk:  #D2971B;
  --c-gold:   #FFC107;
  --c-ink:    #37474F;
  --c-grey:   #9AA5B1;

  /* Little flow segments that flank the logo — the game's own motif, inline as
     data URIs so they cost no request and take the same colours in every
     theme. */
  --deco-left: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 100'%3E%3Cg fill='none' stroke-linecap='round' stroke-width='5'%3E%3Cpath d='M12 44 L44 20' stroke='%233B93F6'/%3E%3Cpath d='M14 84 L46 62' stroke='%23F5843C'/%3E%3C/g%3E%3Ccircle cx='12' cy='44' r='6' fill='%233B93F6'/%3E%3Ccircle cx='44' cy='20' r='6' fill='%233B93F6'/%3E%3Ccircle cx='14' cy='84' r='6' fill='%23F5843C'/%3E%3Ccircle cx='46' cy='62' r='6' fill='%23F5843C'/%3E%3C/svg%3E");
  --deco-right: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 100'%3E%3Cg fill='none' stroke-linecap='round' stroke-width='5'%3E%3Cpath d='M16 20 L48 44' stroke='%23A855F7'/%3E%3Cpath d='M14 62 L46 84' stroke='%2343C463'/%3E%3C/g%3E%3Ccircle cx='16' cy='20' r='6' fill='%23A855F7'/%3E%3Ccircle cx='48' cy='44' r='6' fill='%23A855F7'/%3E%3Ccircle cx='14' cy='62' r='6' fill='%2343C463'/%3E%3Ccircle cx='46' cy='84' r='6' fill='%2343C463'/%3E%3C/svg%3E");

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Height of the Facebook banner strip.

     Always reserved, on EVERY host, whether an ad ever arrives or not.
     Facebook only fills a banner inside its own mobile app, but the strip is
     part of the layout everywhere: space that appeared when an ad loaded would
     shove the screen upward under the player's thumb, and space that exists
     only on some hosts makes the game two different shapes. Where there is no
     ad it simply stays empty.

     Everything that clears the bottom of the screen adds this ONE token; two
     separate numbers drift apart and you get either dead space or content
     underneath the ad. 56px rather than the nominal 50dp because what the ad
     OCCUPIES is more than what it measures — it is drawn above the
     home-indicator inset, it carries its own chrome, and
     env(safe-area-inset-bottom) reports 0 inside some webviews. */
  --banner-h: 56px;

  /* Breathing room ABOVE the strip, kept separate from its height. Clearing
     the ad by a hairline is not the same as looking right: the tab bar ended
     up sitting flush against it, which reads as the menu being stuck under the
     banner even when it is technically clear of it. Flat, NOT tied to
     --safe-bottom: every clearance sums that inset separately already, so
     keying the gap off it too counts the same strip twice. */
  --banner-gap: 24px;
}

/* ------------------------------------------------------------------ icons
   Lucide sprite (assets/icons/LICENSE). Strokes with currentColor, so an icon
   simply takes the colour of the control it sits in. */
/* An icon is a coloured box masked to the glyph shape — not an inline <svg>.
 *
 * Inline SVG asks the layout engine to reconcile a viewBox with a CSS box and
 * to honour preserveAspectRatio, and engines disagree about that: on a real
 * phone the glyph sat off-centre in its button while measuring dead-centre in
 * every desktop engine available here, so no amount of centring CSS could
 * reach it. A mask is drawn by the image path — `contain` and `center`, one
 * rule, no negotiation — which is the same path the other games in this
 * collection use for their button art.
 *
 * currentColor still drives the colour, so the existing palette is untouched. */

.ico {
  width: 1em; height: 1em;
  display: block; flex: none;
  pointer-events: none;
  background-color: currentColor;
  -webkit-mask-image: var(--ico);
          mask-image: var(--ico);
  -webkit-mask-repeat: no-repeat;
          mask-repeat: no-repeat;
  -webkit-mask-position: center;
          mask-position: center;
  -webkit-mask-size: contain;
          mask-size: contain;
}

/* ------------------------------------------------------------------- app */
.app, .overlay, .toast {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Portrait-only phone viewport. On a phone this fills the screen; on any
   wider display it becomes a centred phone-shaped frame rather than
   stretching a portrait layout across a desktop monitor. */
.app {
  position: relative;
  height: 100%;
  height: 100vh;    /* fallback first — an engine without dvh keeps this one */
  height: 100dvh;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 10px + var(--banner-h) + var(--banner-gap));
  opacity: 0;
  transform: translateY(14px) scale(.985);
  transition: opacity .3s ease, transform .3s cubic-bezier(.22,1,.36,1);
}
.screen.is-active { display: flex; }
.screen.is-shown  { opacity: 1; transform: none; }
/* An outgoing screen keeps display:flex for 320ms while it fades. Without
   this it paints over the incoming screen and swallows the first tap. */
.screen:not(.is-shown) { pointer-events: none; }

.screen-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* both-edges, not plain `stable`: the 6px styled scrollbar below is a
     classic (space-taking) one, and reserving its gutter on the right only
     pushed every column off centre — PLAY/LEVELS and the level grid sat 16px
     from the left edge and 22px from the right. Reserving it on both sides
     keeps the no-jump guarantee and keeps the column centred. */
  scrollbar-gutter: stable both-edges;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 8px;
}
.screen-scroll::-webkit-scrollbar { width: 6px; background: transparent; }
.screen-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ------------------------------------------------------------------- home
   Bright casual-game treatment: white cards on a soft field, a multicolour
   wordmark, chunky two-line action buttons and a bottom tab bar. */

.screen--home { padding: 0; }

/* The bottom safe-area inset was being applied twice on any screen that both
   inherits .screen's padding AND hosts a .tabbar — and .screen--home cancels
   that padding, so the same persistent tab bar sat at two different heights
   depending on which screen was showing. Give the bar sole ownership of the
   inset on the screens that carry it. */
.screen--home,
#screen-levels { padding-bottom: 0; }

/* --- top bar --------------------------------------------------------- */
.home-top {
  flex: 0 0 auto;
  /* center, not flex-start: the settings plate is 46px tall and the star pill
     ~35px, so top-aligning them left the settings icon sitting 6px low. */
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 4px;
  gap: 12px;
}

.top-btn {
  display: grid; justify-items: center; gap: 4px;
  border-radius: 16px;
}
.top-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.top-btn-ico {
  width: 46px; height: 46px;
  display: grid; align-items: center; justify-items: center;
  border-radius: 15px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--muted);
  transition: transform .14s ease;
}
.top-btn:active .top-btn-ico { transform: scale(.92); }
.top-btn-ico .ico { width: 22px; height: 22px; }
.coin-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px 6px 12px;
  border-radius: 99px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
.coin-ico { display: block; color: var(--gold); }
.coin-ico .ico { width: 21px; height: 21px; color: var(--gold); }
.coin-value {
  font-size: 16px; font-weight: 800; letter-spacing: -.2px;
  font-variant-numeric: tabular-nums;
}
/* The home menu is laid out to fit the viewport rather than scroll. Everything
   except the preview board takes its natural height; the board is the one
   flexible element, so it absorbs whatever space is left and shrinks on short
   phones instead of pushing PLAY below the fold. overflow-y stays auto from
   .screen-scroll as a last resort — cutting content off would be worse than
   scrolling if a device is shorter than the buttons themselves. */
.home-scroll {
  /* The bottom padding matters: .big-btn carries a 5px hard drop-shade that
     sits outside its border box, so without clearance LEVELS reads as though
     it is tucked under the tab bar.
     20px here and no top margin on the tab bar below, rather than 12px + 8px:
     the same 20px gap, but a scroller clips whatever overflows it, and at 12px
     LEVELS' soft shadow was sliced off in a hard grey line across the screen
     whenever the menu fills its scroller — 360x640, 390x844, 360x780 and
     Facebook's 376x717 player among them. Now the scroller ends where the tab
     bar begins, so the shadow fades out first. */
  padding: 0 16px 20px;
  display: flex;
  flex-direction: column;
}
#screen-home .tabbar { margin-top: 0; }
.home-scroll > .wordmark-wrap,
.home-scroll > .home-tag,
.home-scroll > .home-actions { flex: 0 0 auto; }

/* Spread the leftover height instead of pooling it under the buttons.
 *
 * A tall window — Facebook's desktop player is around 1160px — left the home
 * screen stacked at the top with several hundred pixels of nothing above the
 * tab bar, which reads as the game not filling its space.
 *
 * These two spacers absorb whatever is left over, equally, above and below.
 * `justify-content: center` would do the same thing in one line but is unsafe
 * on a scroller: when the content is TALLER than the box, centring pushes the
 * top out of reach and no scrolling brings it back. Spacers cannot do that —
 * they shrink to nothing before the content is touched, so a short phone still
 * scrolls normally. */
.home-scroll::before,
.home-scroll::after {
  content: '';
  flex: 1 1 0;
  min-height: 0;
}

/* --- wordmark -------------------------------------------------------- */
.wordmark-wrap {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  margin: 0;
  /* Reserve the flanks so the pipes never sit on top of the logo. */
  padding: 6px 58px 2px;
}

/* Little flow segments flanking the logo. Sized off the logo's own height so
   they stay in proportion with it on every screen instead of being a fixed
   px block next to something that scales. */
.deco {
  position: absolute; top: 50%;
  width: 46px; height: 78px;
  transform: translateY(-50%);
  background-repeat: no-repeat; background-position: center;
  background-size: contain;
  opacity: .95; pointer-events: none;
}
.deco--left  { left: 0;  background-image: var(--deco-left); }
.deco--right { right: 0; background-image: var(--deco-right); }

/* Below this the flanks cost more than they add: they were squeezing the logo
   itself down to 126px on a 280px screen. The logo is the thing that has to
   read; the flourishes are not. */
@media (max-width: 359px) {
  .deco { display: none; }
  .wordmark-wrap { padding-left: 0; padding-right: 0; }
}
/* Bounded on BOTH axes: width keeps it off the edges on a wide phone, height
   stops it eating the menu on a short one. A replaced element honours both at
   once and keeps its own aspect ratio, so no cropping and no distortion. The
   width/height attributes on the <img> reserve the space before it decodes,
   so the menu below never jumps. */
.wordmark-img {
  display: block;
  width: auto; height: auto;
  max-width: min(320px, 100%);
  /* Measured against the height the menu ACTUALLY has, not the raw viewport.
     With a banner reserved at the bottom there is ~66px less to work with, and
     a logo pinned to 14vh does not know that — it stays put while everything
     around it compresses, so it quietly becomes the biggest thing on screen.
     Subtracting the strip keeps it a title rather than a billboard. */
  max-height: calc((100vh - var(--banner-h) - var(--banner-gap)) * 0.14);
  max-height: calc((100dvh - var(--banner-h) - var(--banner-gap)) * 0.14);
}

.home-tag {
  margin-top: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 14.5px; font-weight: 600;
}

/* --- preview board --------------------------------------------------- */
.preview-card {
  /* Capped, not grown. As a flex-grow item it swallowed every spare pixel and
     ended up as 57% of the menu — it is a decorative sample of the game, not
     the game. A definite height also lets the canvas below stay square. */
  /* Grows into the space the menu has left over, up to a cap. Fixed-height it
     pushed the surplus into one dead band above the tab bar; uncapped it grew
     to swallow 57% of the screen. The cap is the compromise. */
  flex: 1 1 auto;
  max-height: min(38vh, 340px);
  min-height: 84px;
  /* No auto margin: an `auto` here collected every spare pixel into one gap
     between the tagline and the board. The menu now stacks tight from the top
     and the surplus falls below the buttons, where it reads as breathing room
     above the tab bar instead of a hole in the middle of the screen. */
  margin: 12px 0 14px;
  display: flex; align-items: center; justify-content: center;
  padding: 10px;
  border-radius: var(--radius-xl);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
.preview-canvas {
  /* Height-driven off the card's definite height, with the width following to
     keep it square. Setting an explicit height AND a max-width previously beat
     the aspect ratio and produced a 260×335 rectangle. */
  display: block;
  height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

/* --- big action buttons ---------------------------------------------- */
.home-actions { display: grid; gap: 10px; }

/* Short phones (iPhone SE and friends). Everything on the home screen loses a
   little height so the two action buttons stay above the fold rather than
   turning the menu into a scroller. */
@media (max-height: 680px) {
  /* The banner strip costs 80px of a screen that may only be 568px tall, so
     the menu has to give some of it back rather than start scrolling. The ad's
     own 56px is untouchable — an ad drawn over the tab bar is the bug this all
     started from — so the breathing room above it is what shrinks. */
  :root { --banner-gap: 12px; }
  /* The logo is sized as a share of the VIEWPORT, but it sits inside a
     scroller that is much shorter than the viewport once the top bar, tab bar
     and banner strip have taken their cut — and the shorter the screen, the
     wider that gap. 14% of a 568px phone is 21% of the menu it lands in, so
     the share comes down with the screen. */
  .wordmark-img {
    max-height: calc((100vh - var(--banner-h) - var(--banner-gap)) * 0.12);
    max-height: calc((100dvh - var(--banner-h) - var(--banner-gap)) * 0.12);
  }
  .wordmark-wrap { padding-top: 2px; padding-bottom: 0; }
  .home-tag { margin-top: 6px; font-size: 13.5px; }
  .preview-card { max-height: min(24vh, 200px); padding: 8px; }
  .home-actions { gap: 8px; }
  .big-btn { min-height: 56px; }
}
@media (max-height: 600px) {
  :root { --banner-gap: 8px; }
  .home-tag { display: none; }          /* the wordmark already says it */
  .big-btn { min-height: 52px; }
  .preview-card { max-height: min(22vh, 150px); min-height: 64px; }
}

.big-btn {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  min-height: 66px;
  padding: 0 16px;
  border-radius: 18px;
  color: #fff;
  text-align: left;
  box-shadow: 0 5px 0 var(--btn-shade), 0 10px 22px rgba(0, 0, 0, .16);
  transition: transform .12s ease, box-shadow .12s ease, filter .2s ease;
  touch-action: manipulation;
}
/* Every :hover in this file sits behind (hover: hover) and (pointer: fine),
   each one in place so the cascade order against :active is unchanged.
   Phone browsers and webviews keep :hover on the last control tapped until
   the next tap somewhere else, so a bare :hover left a grey plate stuck
   behind UNDO, RESTART, Replay and every tab after it was used. A mouse
   (Facebook's desktop player) keeps the hover feedback. */
@media (hover: hover) and (pointer: fine) { .big-btn:hover { filter: brightness(1.05); } }
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--btn-shade), 0 4px 12px rgba(0, 0, 0, .16);
}
.big-btn:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }

.big-btn-ico {
  width: 44px; height: 44px; flex: none;
  display: grid; align-items: center; justify-items: center;
  border-radius: 13px;
  background: rgba(255, 255, 255, .22);
}
.big-btn-ico .ico { width: 24px; height: 24px; }
.big-btn--play .big-btn-ico .ico { color: #fff; }

.big-btn-text { display: grid; gap: 1px; min-width: 0; }
.big-btn-text b {
  font-size: 19px; font-weight: 800; letter-spacing: .4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.big-btn-text small {
  font-size: 11.5px; font-weight: 650; letter-spacing: .7px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .82);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.big-btn--play   { background: var(--c-green);  --btn-shade: var(--c-green-dk); }
.big-btn--levels { background: var(--c-blue);   --btn-shade: var(--c-blue-dk); }

/* --- bottom tab bar --------------------------------------------------- */
.tabbar {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  margin: 8px 12px calc(var(--safe-bottom) + 10px + var(--banner-h) + var(--banner-gap));
  padding: 8px 4px;
  border-radius: 22px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
/* Level select keeps .screen's 16px side padding, Home does not — so the same
   tab bar was 32px narrower on Levels and visibly changed width when switching
   tabs. Pull it back out to Home's 12px inset. */
#screen-levels .tabbar { margin-left: -4px; margin-right: -4px; }

.tab-item {
  position: relative;
  display: grid; justify-items: center; gap: 5px;
  padding: 6px 2px;
  border-radius: 14px;
  min-height: 56px;
  transition: transform .14s ease, background-color .2s ease;
}
@media (hover: hover) and (pointer: fine) { .tab-item:hover { background: var(--surface-2); } }
.tab-item:active { transform: scale(.94); }
.tab-item:focus-visible { outline: 3px solid var(--c-blue); outline-offset: 1px; }
.tab-item.is-active .tab-ico { color: var(--c-blue); }
.tab-item.is-active .tab-label { color: var(--c-blue); }
.tab-ico { display: block; }
.tab-ico .ico { width: 25px; height: 25px; }
.tab-label {
  font-size: 10px; font-weight: 700; letter-spacing: .2px;
  color: var(--muted); text-align: center; line-height: 1.15;
}


/* ---------------------------------------------------------------- buttons */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15.5px; font-weight: 650; letter-spacing: .2px;
  transition: transform .14s ease, background-color .2s ease, box-shadow .2s ease, border-color .2s ease;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
@media (hover: hover) and (pointer: fine) { .btn:hover { background: var(--surface-2); border-color: var(--border-strong); } }
.btn:active { transform: scale(.965); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn--wide { width: 100%; }
.btn--sm { min-height: 40px; font-size: 13.5px; padding: 0 14px; border-radius: var(--radius-md); }
.btn .ico { width: 1.15em; height: 1.15em; }
.btn--ghost { gap: 6px; }
.btn--ghost .ico { width: 1.05em; height: 1.05em; opacity: .85; }

.btn--primary {
  background: var(--c-blue);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 0 var(--c-blue-dk);
}
@media (hover: hover) and (pointer: fine) { .btn--primary:hover { filter: brightness(1.06); background: var(--c-blue); } }
.btn--primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--c-blue-dk); }
.btn--ghost { background: transparent; font-weight: 600; font-size: 14px; }
@media (hover: hover) and (pointer: fine) { .btn--ghost:hover { background: var(--surface); } }
.btn--danger { background: color-mix(in srgb, var(--danger) 16%, transparent); border-color: color-mix(in srgb, var(--danger) 42%, transparent); color: var(--danger); }
@media (hover: hover) and (pointer: fine) { .btn--danger:hover { background: color-mix(in srgb, var(--danger) 26%, transparent); } }
.btn[disabled], .btn.is-disabled { opacity: .42; pointer-events: none; }

.icon-btn {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 17px; line-height: 1;
  transition: transform .14s ease, background-color .2s ease;
}
@media (hover: hover) and (pointer: fine) { .icon-btn:hover { background: var(--surface-2); } }
.icon-btn:active { transform: scale(.92); }
.icon-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.icon-btn .ico { width: 20px; height: 20px; }
.icon-btn--close .ico { width: 17px; height: 17px; }

/* ----------------------------------------------------------------- topbar */
/* Three columns with EQUAL outer tracks, so the middle one is centred on the
   bar itself. As a flex row the title only centred within the space left over,
   and the things flanking it are not the same width — a 44px back button on
   one side and a 59px star pill on the other put the title 8px off centre. */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 10px;
  padding: 4px 0 12px;
  flex: 0 0 auto;
}
.topbar > :first-child { justify-self: start; }
.topbar > :last-child  { justify-self: end; }
.topbar-title {
  text-align: center;
  font-size: 19px; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase; color: var(--text);
}

/* circular chrome buttons, as in the reference */
.round-btn {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; align-items: center; justify-items: center;
  border-radius: 50%;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--muted);
  transition: transform .14s ease, background-color .2s ease;
}
@media (hover: hover) and (pointer: fine) { .round-btn:hover { background: var(--surface-2); } }
.round-btn:active { transform: scale(.92); }
.round-btn:focus-visible { outline: 3px solid var(--c-blue); outline-offset: 2px; }
.round-btn .ico { width: 21px; height: 21px; }

/* Centring for the icon-only controls that cannot fail.
 *
 * The glyph was landing off-centre inside its circle on a real phone while
 * measuring dead-centre in every desktop engine — which means the centring was
 * resting on something the phone's engine does not honour. So it no longer
 * rests on anything: absolute positioning with zero insets and auto margins
 * centres a box of known size in every engine that has ever shipped
 * position:absolute. No grid, no flex, no transform, no shorthand, nothing
 * left to parse wrongly.
 *
 * The alignment properties on the buttons themselves are kept — they still do
 * the work wherever they are honoured, and they cost nothing where they are
 * not. This is the floor underneath them. */
.round-btn,
.top-btn-ico,
.icon-btn { position: relative; }

.round-btn .ico,
.top-btn-ico .ico,
.icon-btn .ico {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  margin: auto;
}

.game-titles { display: grid; justify-items: center; gap: 1px; }
.game-level {
  font-size: 18px; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase;
}
.game-diff {
  font-size: 13.5px; font-weight: 700;
  color: var(--c-blue);
}

/* ------------------------------------------------------------------- hud */
.hud-row {
  display: flex; justify-content: center;
  margin-bottom: 12px; flex: 0 0 auto;
}

.hud {
  /* Centred pill sized to its content, not a full-width bar. */
  position: relative;
  display: flex; align-items: center;
  min-width: 250px;
  padding: 10px 6px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
}
/* min-width: max-content, with the 76px floor moved onto the value below.
   A flat 76px let flex share the pill out equally regardless of what was in
   it, so a timer past an hour ("1:23:45") was squeezed into 67px and ran over
   the divider beside it. Now a column can never be narrower than its own
   text; at everyday values every column is still exactly 76px. */
.hud-item { flex: 1; text-align: center; min-width: 76px; min-width: max-content; padding: 0 6px; }
.hud-sep { width: 1px; align-self: stretch; background: var(--border); }
.hud-label {
  display: block; font-size: 9.5px; font-weight: 700;
  letter-spacing: 1.1px; text-transform: uppercase; color: var(--c-grey);
}
.hud-value {
  display: block; font-size: 19px; font-weight: 800;
  font-variant-numeric: tabular-nums; letter-spacing: -.3px;
  color: var(--c-blue);
  min-width: 64px; white-space: nowrap;
}
.hud-value.is-bump { animation: bump .34s cubic-bezier(.22,1,.36,1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }
.hud-value.is-warn { animation: warnBump 1.5s cubic-bezier(.22,1,.36,1); }
@keyframes warnBump {
  0%   { transform: scale(1); }
  18%  { transform: scale(1.3); color: var(--c-amber); }
  70%  { transform: scale(1); color: var(--c-amber); }
  100% { transform: scale(1); }
}

.count-badge {
  min-width: 20px; height: 20px; padding: 0 5px;
  display: inline-grid; align-items: center; justify-items: center;
  border-radius: 99px;
  background: var(--c-blue); color: #fff;
  font-size: 11px; font-weight: 800;
}
.count-badge.is-empty { background: var(--surface-2); color: var(--faint-text); }

/* How much of the board is filled. Every cell must be covered to finish, so
   this is the one number that says how close the board really is. */
.hud-fill {
  position: absolute; left: 12px; right: 12px; bottom: 6px;
  height: 3px; border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.hud-fill > span {
  display: block; height: 100%; width: 0;
  border-radius: 99px;
  background: var(--c-blue);
  transition: width .25s ease, background-color .25s ease;
}
/* Every pair joined but cells still empty — the state that looks finished
   but is not. Gold matches the cells the board highlights. */
.hud-fill.is-almost > span { background: var(--c-amber); }
.hud { padding-bottom: 14px; }

/* --------------------------------------------------------- segmented tabs */
.seg {
  display: flex; gap: 4px;
  margin-bottom: 14px; flex: 0 0 auto;
  overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.seg::-webkit-scrollbar { display: none; }

/* Fade whichever edge still has bands behind it, so the strip reads as "there
   is more" instead of looking like the list simply ends. Both classes are set
   from ui.js; on screens where all five fit, neither applies and nothing is
   dimmed. Fading a fixed side would grey out the selected band the moment the
   strip is scrolled to that end. */
.seg.can-scroll-right:not(.can-scroll-left) {
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
          mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
}
.seg.can-scroll-left:not(.can-scroll-right) {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 26px, #000 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 26px, #000 100%);
}
.seg.can-scroll-left.can-scroll-right {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
}

.tab {
  /* size to content and let the strip scroll — five bands do not fit if the
     tabs are forced to share the width equally. The padding is as tight as it
     can go while still fitting all five across a 414px phone. */
  flex: 0 0 auto; min-height: 40px; padding: 0 11px;
  border-radius: 99px;
  font-size: 12.5px; font-weight: 800; letter-spacing: .3px;
  text-transform: uppercase;
  color: var(--c-grey); white-space: nowrap;
  transition: background-color .2s ease, color .2s ease;
}
@media (hover: hover) and (pointer: fine) { .tab:hover { color: var(--text); } }
.tab.is-active { background: var(--c-blue); color: #fff; }
.tab:focus-visible { outline: 3px solid var(--c-blue); outline-offset: 2px; }

/* --------------------------------------------------------------- gating */
.band-gate {
  display: grid; justify-items: center; gap: 4px;
  padding: 18px 16px; margin-bottom: 12px;
  border-radius: 16px;
  background: var(--surface-solid);
  border: 1px dashed var(--border-strong);
  text-align: center;
}
.band-gate[hidden] { display: none; }
.band-gate .ico { width: 26px; height: 26px; color: var(--c-grey); margin-bottom: 2px; }
.band-gate b { font-size: 15px; font-weight: 800; }
.band-gate small { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
/* The "never re-locks" footnote had no rule, so it rendered at the inherited
   15px — bigger than the explanation above it — and in the 376x717 Facebook
   desktop player it cost a locked band a whole row of tiles. */
.band-gate em { font-size: 11.5px; color: var(--faint-text); line-height: 1.35; }

/* On a short phone the gate banner is what squeezes the grid down to a single
   row. Trimming it keeps two rows of levels visible without scrolling. */
@media (max-height: 620px) {
  .band-gate { padding: 11px 14px; margin-bottom: 8px; }
  .band-gate .ico { width: 20px; height: 20px; margin-bottom: 0; }
  .band-gate b { font-size: 13.5px; }
  .band-gate small { font-size: 11.5px; line-height: 1.35; }
}

/* ------------------------------------------------------------ level grid */
/* A scroller clips whatever overflows it, shadows included, and the grid
   filled it edge to edge — so every tile's drop shadow was cut off in a hard
   vertical line down both sides of the grid. Run the scroller out to the
   screen edges, as Home's does, and pad the grid back in to the same 16px. */
.levels-scroll {
  margin-left: -16px; margin-right: -16px;
  padding-left: 16px; padding-right: 16px;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.level-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  border-radius: 14px;
  background: var(--surface-solid);
  border: 2px solid var(--tile-accent, var(--border));
  box-shadow: var(--shadow-md);
  font-weight: 800; font-size: 19px;
  color: var(--tile-accent, var(--text));
  transition: transform .14s ease, box-shadow .2s ease;
}
@media (hover: hover) and (pointer: fine) { .level-tile:hover { transform: translateY(-2px); } }
.level-tile:active { transform: scale(.94); }
.level-tile:focus-visible { outline: 3px solid var(--c-blue); outline-offset: 2px; }
.level-tile.is-locked {
  background: var(--surface-2);
  border-color: transparent;
  box-shadow: none;
  color: var(--c-grey);
}
@media (hover: hover) and (pointer: fine) { .level-tile.is-locked:hover { transform: none; } }
.level-tile.is-current { background: var(--tile-accent); color: #fff; border-color: transparent; }
.level-tile.is-current .tile-star.off { color: rgba(255, 255, 255, .45); }

.tile-stars { display: flex; gap: 2px; align-items: center; height: 11px; }
.tile-star { display: block; width: 10px; height: 10px; color: var(--c-gold); }
.tile-star .ico { width: 10px; height: 10px; }
.tile-star.off { color: #D8DEE7; }
.tile-lock { display: block; color: var(--c-grey); }
.tile-lock .ico { width: 18px; height: 18px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 18px 0 6px; }
.pager .btn .ico { width: 15px; height: 15px; }
.pager-info { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 66px; text-align: center; }

/* ----------------------------------------------------------------- board */
.board-wrap {
  position: relative;
  /* The board is square at every aspect ratio. `width: 100%` used to win over
     the aspect ratio whenever height was the tighter constraint, which drew a
     620x337 board clipped off the bottom of a short viewport — the rotate gate
     hid that case rather than solving it. Letting flex hand over the leftover
     height and deriving the width from the ratio keeps it square either way. */
  flex: 0 1 auto;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: min(620px, 100%);
  max-height: 100%;
  margin: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 8px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
}
/* Sideways, height is the tighter constraint and a width-driven square runs
   off the bottom. Flex hands over the leftover height instead and the ratio
   derives the width, so the board stays square either way.

   Keyed on orientation, not on height: a short PORTRAIT phone (320x568) is
   still width-constrained, and a max-height rule caught it too and drew a
   270x318 board. */
@media (orientation: landscape) {
  .board-wrap {
    flex: 1 1 auto;
    /* Not 0: with the rotate gate gone, a landscape phone left roughly
       70-125px of height for the board, which is below a usable touch
       target. Floor it and let the screen scroll rather than shrink it
       into something nobody can play. */
    min-height: min(240px, 62vh);
    align-self: center;
    width: auto;
  }
  #screen-game { overflow-y: auto; }
}

/* A landscape phone cannot fit the completion card at full size; compact it
   so the scroller is a fallback rather than the normal experience. */
@media (max-height: 560px) {
  .sheet--complete .star { font-size: 46px; }
  .complete-medal { width: 56px; height: 56px; margin: -40px auto 4px; }
  .sheet { padding: 16px 18px 14px; }
  .sheet-actions { gap: 8px; }
}

.board-canvas {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
/* Sits ON the board's bottom edge, half over the frame and half in the gap
   above the action bar, rather than wholly inside the board. Inside, it was
   drawn over the bottom row of cells — dots included — and the tutorial tips
   covered the very cells each lesson asks the player to fill.
   width: max-content because `left: 50%` otherwise caps a shrink-to-fit box
   at HALF the board's width: every message wrapped into a narrow 3–4 line
   bubble even with room for one or two lines.
   No z-index on purpose: on the tightest phones a two-line message reaches
   the top few px of the action bar, and the hint-count badge should stay
   drawn over it, not under it. */
.board-toast {
  position: absolute; left: 50%; bottom: 0; transform: translate(-50%, calc(50% + 10px));
  width: max-content;
  padding: 8px 15px; border-radius: 99px;
  background: var(--c-ink); border: 0;
  font-size: 13px; font-weight: 650; color: #fff;
  box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  max-width: 92%; text-align: center;
}
.board-toast.is-shown { opacity: 1; transform: translate(-50%, 50%); }
/* On a short phone (360x640) the board ends 22px above the action bar, and a
   two-line tip (48px, so 24px below the edge) ran 3px under the hint-count
   badge. A slightly tighter pill (44px) lifted 3px clears the badge and
   reaches only 1px further into the board's bottom row — lifting the
   full-size pill instead would cover most of a 14x14 board's last row. */
@media (max-height: 680px) {
  .board-toast { padding-top: 6px; padding-bottom: 6px; line-height: 1.2; transform: translate(-50%, calc(50% + 7px)); }
  .board-toast.is-shown { transform: translate(-50%, calc(50% - 3px)); }
}

/* ---------------------------------------------------------------- actions
   Plain icon + label, as in the reference — no filled button plates. */
.game-footer {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 16px 0 6px;
  flex: 0 0 auto;
}
.act {
  position: relative;
  display: grid; justify-items: center; gap: 7px;
  padding: 6px 2px;
  border-radius: 16px;
  transition: transform .14s ease, background-color .2s ease;
  touch-action: manipulation;
}
@media (hover: hover) and (pointer: fine) { .act:hover { background: var(--surface-2); } }
.act:active { transform: scale(.93); }
.act:focus-visible { outline: 3px solid var(--c-blue); outline-offset: 2px; }
.act-ico { display: block; color: var(--c-ink); }
.act-ico .ico { width: 28px; height: 28px; }
.act--hint .act-ico { color: var(--c-gold); }
.act-label {
  font-size: 10.5px; font-weight: 800; letter-spacing: 1.1px;
  text-transform: uppercase; color: var(--c-grey);
}
.act .count-badge { position: absolute; top: -2px; right: 50%; margin-right: -30px; }

/* --------------------------------------------------------------- overlays */
.overlay {
  position: absolute; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom) + var(--banner-h) + var(--banner-gap));
  backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px);
  /* Scrim tuned for the light ground: dark enough to sit the sheet forward,
     light enough that the board stays readable behind it. */
  background: rgba(28, 36, 62, .40);
  opacity: 0; transition: opacity .26s ease;
}
.overlay.is-shown { opacity: 1; }
.overlay[hidden] { display: none; }
/* A closing overlay stays displayed for 280ms; keep it out of hit-testing so
   the first tap after Resume / closing Settings is not eaten. */
.overlay:not(.is-shown) { pointer-events: none; }
.overlay--small { align-items: center; }

.sheet {
  width: 100%; max-width: 440px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  /* Plain 20px. The overlay around the sheet already reserves the banner
     strip and the home-indicator inset; adding them here as well left ~80px
     of dead white at the foot of every panel, cut Statistics off mid-row and
     pushed the Level Complete medal off the top of a 360x640 screen. */
  padding: 24px 20px 20px;
  box-shadow: var(--shadow-lg);
  transform: translateY(26px) scale(.97);
  transition: transform .32s cubic-bezier(.22,1,.36,1);
  max-height: 100%;
  display: flex; flex-direction: column;
}
.overlay.is-shown .sheet { transform: none; }
.sheet--small { max-width: 330px; text-align: center; overflow: visible; }
.sheet-badge {
  width: 62px; height: 62px;
  margin: -46px auto 10px;
  display: grid; align-items: center; justify-items: center;
  border-radius: 50%;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--c-gold);
}
.sheet-badge .ico { width: 30px; height: 30px; }
.sheet--small .sheet-sub { margin-bottom: 18px; color: var(--muted); }
.btn--text {
  background: none; border: 0; box-shadow: none;
  color: var(--c-grey); font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px; font-size: 13px;
}
@media (hover: hover) and (pointer: fine) { .btn--text:hover { background: none; color: var(--text); } }
.sheet--tall { max-height: 100%; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.sheet-head .sheet-title { flex: 1; margin: 0; text-align: left; }
.sheet-title {
  font-size: 20px; font-weight: 800; letter-spacing: .6px;
  text-align: center; text-transform: uppercase;
}
.sheet-sub { margin-top: 6px; text-align: center; color: var(--muted); font-size: 14px; }
.sheet-actions { display: grid; gap: 10px; margin-top: 22px; }
.sheet-body { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-right: 2px; }
.sheet-body::-webkit-scrollbar { width: 5px; }
.sheet-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ------------------------------------------------------------- completion */
.sheet--complete { text-align: center; overflow: visible; }
.complete-medal {
  width: 74px; height: 74px;
  margin: -52px auto 6px;
  display: grid; align-items: center; justify-items: center;
  border-radius: 50%;
  background: linear-gradient(160deg, #FFD35C, #F0A81E);
  box-shadow: 0 6px 18px rgba(240, 168, 30, .45);
  color: #fff;
}
.complete-medal .ico { width: 34px; height: 34px; color: #fff; }
.moves-pill {
  display: inline-block; margin: 4px auto 0;
  padding: 7px 18px; border-radius: 99px;
  background: var(--c-blue-soft); color: var(--c-blue);
  font-size: 13px; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase;
}
.complete-title { color: var(--text); font-size: 23px; letter-spacing: .5px; }
/* Replay / Home under Next Level. The class had no rule, so the pair shrank
   to two loose content-width pills that did not line up with anything. */
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stars-row { display: flex; justify-content: center; gap: 10px; margin-bottom: 10px; }
.star {
  font-size: 46px; color: #DDE3EC;
  transform: scale(.5); opacity: .35;
  transition: transform .42s cubic-bezier(.34,1.56,.64,1), opacity .3s ease, color .3s ease, text-shadow .3s ease;
}
.star.is-earned { color: var(--c-gold); opacity: 1; transform: scale(1); text-shadow: 0 6px 18px rgba(255, 193, 7, .5); }

.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
.result-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 10px;
  display: flex; flex-direction: column; gap: 3px;
}
.result-item span { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.3px; color: var(--faint-text); }
.result-item strong { font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; }
.result-note { margin-top: 12px; font-size: 13px; color: var(--c-blue); font-weight: 600; min-height: 18px; }

/* --------------------------------------------------------------- settings */
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--border);
}
.setting-row label { font-size: 15px; font-weight: 600; }
.setting-note { margin-top: 12px; font-size: 11.5px; color: var(--faint-text); text-align: center; }
.setting-note:empty { display: none; }
/* Breathing room between the last toggle and the destructive action. */
.sheet-body > .btn--danger { margin-top: 20px; }

.switch {
  position: relative; width: 52px; height: 30px; flex: 0 0 52px;
  border-radius: 99px; background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background-color .24s ease, border-color .24s ease;
}
.switch span {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 99px;
  background: var(--text); opacity: .7;
  transition: transform .26s cubic-bezier(.22,1,.36,1), background-color .24s ease, opacity .24s ease;
}
.switch[aria-checked="true"] { background: var(--c-blue); border-color: transparent; }
.switch[aria-checked="true"] span { transform: translateX(22px); background: #fff; opacity: 1; }
.switch:focus-visible { outline: 3px solid var(--c-blue); outline-offset: 2px; }
/* The pill stays 52x30 because that is the shape it should be, but 30px tall
   is well under the 44px minimum every mobile guideline sets — a miss just
   feels like the switch is broken. Grow the hit area outwards without moving
   a pixel of the visible control. */
.switch::after {
  content: '';
  position: absolute;
  /* Vertical only. The pill is already 52px wide, so it clears the 44px
     minimum sideways on its own — and growing it sideways pushed it past the
     sheet's content edge, which was enough to raise a horizontal scrollbar
     across the bottom of the Settings panel. */
  inset: -8px 0;             /* 46px tall, 52px wide */
  border-radius: 99px;
}


/* ------------------------------------------------------------------ stats */
.stat-list { display: grid; gap: 2px; }
.stat-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 4px; border-bottom: 1px solid var(--border);
  font-size: 14.5px;
}
.stat-row span { color: var(--muted); }
.stat-row strong { font-weight: 750; font-variant-numeric: tabular-nums; }
.completion { margin-top: 20px; }
/* The completion bar had no rule: its fill is an inline span, so the width
   ui.js sets did nothing and the bar never drew — only a stray "0.0%
   complete" in body text was left. Same treatment as the HUD fill bar. */
.completion .bar {
  height: 8px; border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.completion .bar > span {
  display: block; height: 100%; width: 0;
  border-radius: 99px;
  background: var(--c-blue);
}
.progress-sub {
  margin-top: 8px; text-align: center;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
}
/* Ten rows plus the bar ran ~10px taller than the sheet can be in Facebook's
   376x717 desktop player, so the last line was sliced in half at the foot of
   the panel. Short screens tighten the rows instead; tall ones are untouched. */
@media (max-height: 760px) {
  .stat-row { padding-top: 10px; padding-bottom: 10px; }
  .completion { margin-top: 14px; }
}
@media (max-height: 660px) {
  .stat-row { padding-top: 9px; padding-bottom: 9px; }
  #modal-stats .sheet-head { margin-bottom: 10px; }
}

/* ------------------------------------------------------------------ toast */
/* Centred on the tab bar's own band: the bar is 74px tall and its bottom
   margin is the same on Home and Levels (safe + 10px + banner + gap), so its
   middle is 47px above the banner gap on both.
   The old fixed 112px landed on whatever happened to be there — the Levels
   pager (hidden outright at 376x717 and 360x780), the LEVELS button on a
   short Home, and the board's bottom row and board toast during play.
   The translate(…, 50%) centres a one- or two-line toast on that line.
   pointer-events: none, so the tabs under it still take taps for its 2s. */
.toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 47px + var(--banner-h) + var(--banner-gap));
  transform: translate(-50%, calc(50% + 14px));
  /* max-content: with left:50% a shrink-to-fit box is capped at half the
     screen, so a one-line message wrapped to three lines with an orphan. */
  width: max-content;
  z-index: 90; max-width: min(88vw, 400px);
  padding: 12px 20px; border-radius: 99px;
  background: var(--surface-solid); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 600; text-align: center;
  text-wrap: balance;      /* no lone "4" on the second line */
  opacity: 0; pointer-events: none;
  transition: opacity .26s ease, transform .26s cubic-bezier(.22,1,.36,1);
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 50%); }
.toast[hidden] { display: none; }
/* During play there is no tab bar, and the bottom of the screen is the board,
   its own toast and the action bar — a hint bought with stars or a video
   raised both toasts at once, one on top of the other ("Gree[+1 hint] you").
   Over the read-only Moves/Time/Best pill instead: it is 59px tall at
   safe-top + 70px on every phone, so this centres the toast on it. */
#screen-game.is-shown ~ .toast {
  bottom: auto; top: calc(var(--safe-top) + 100px);
  transform: translate(-50%, calc(-50% + 14px));
}
#screen-game.is-shown ~ .toast.is-shown { transform: translate(-50%, -50%); }
/* A hint that finishes the board opens Level Complete while its toast is still
   up, and at the top it sat on the medal and the star row. While the sheet is
   open, put it under the sheet, just above the reserved banner strip.
   Same specificity as the rule above, so it wins on source order. */
#overlay-complete.is-shown ~ .toast {
  top: auto; bottom: calc(var(--safe-bottom) + var(--banner-h) + 4px);
  transform: translate(-50%, 14px);
}
#overlay-complete.is-shown ~ .toast.is-shown { transform: translate(-50%, 0); }
/* On Home and Levels the toast sits on the tab bar. A pill narrower than the
   bar left half-covered tabs showing either side ("Hom[Progress reset]Play"),
   so cover the bar's whole icon-and-label row instead. */
#screen-home.is-shown ~ .toast, #screen-levels.is-shown ~ .toast {
  width: calc(100% - 32px); max-width: none;
  padding-top: 14px; padding-bottom: 14px;
}

/* --------------------------------------------------------------- confetti */
.confetti-canvas {
  position: absolute; inset: 0; z-index: 80;
  /* A canvas is a replaced element: inset:0 alone leaves it at its
     intrinsic 300x150, so the size has to be stated outright. */
  width: 100%; height: 100%;
  pointer-events: none; opacity: 0;
  transition: opacity .2s ease;
}
.confetti-canvas.is-active { opacity: 1; }

/* --------------------------------------------------------------- portrait
   The base layout above is the only layout — it is tuned for a phone and
   never widens. Anything bigger than a phone gets that same layout inside a
   phone-shaped frame, so what you see on a desktop is exactly what ships on
   a device, at the same size. */
@media (min-width: 480px) and (min-height: 621px) and (hover: hover) and (pointer: fine) {
  /* NOTHING SPECIAL FOR A BIG SCREEN.
   *
   * This block used to draw a phone here — rounded corners, a hairline border,
   * a 10px black ring — so a desktop window showed the game as a handset
   * mockup, and Facebook's own player ended up with a fake phone inside a real
   * frame. Removing the frame still left width and height caps behind, which
   * is the same mistake in a quieter form: margins of dead background the
   * player never asked for.
   *
   * So there is no override at all now. .app keeps its base rule — full width,
   * full height — and the game fills whatever it is given, exactly as it does
   * on a phone. Only the pointer affordances below are desktop-specific,
   * because a phone has no hover. */
  .btn:hover { transform: translateY(-1px); }
  .btn:active { transform: scale(.965); }
}

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