/* Fruit Triple — static English remake
   Palette: deep orchard green, warm cream, sunflower yellow.
   The orchard photo behind the game is bright and busy, so every surface
   that carries text or a control is opaque and edge-defined: nothing
   important sits on a translucent panel. */

:root {
  --paper: #f6f2e6;
  --paper-deep: #e9e3d2;
  --surface: #ffffff;
  --ink: #10222c;
  --ink-soft: #24424f;
  --muted: #4a6572;
  --line: #ccdad7;
  --line-strong: #9fbab6;
  --teal: #0d7a80;
  --teal-dark: #075a5f;
  --teal-soft: #dcf0ee;
  --yellow: #f2b705;
  --yellow-soft: #fff2cf;
  --coral: #cf4634;
  --green: #1f8a4c;
  --shadow-sm: 0 6px 18px rgba(8, 44, 28, .12);
  --shadow-md: 0 18px 45px rgba(8, 44, 28, .20);
  --shadow-lg: 0 28px 70px rgba(8, 44, 28, .28);
  --tile-w: 62px;
  --tile-h: 70px;
  --step-y: 66px;
  --tile-edge: #1e7f4c;         /* the visible 3D side under each board tile — deep orchard green */
  --tile-edge-deep: #115c37;   /* pressed / covered tiles sit a shade deeper */
  --board-w: 540px;
  --board-h: 420px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  /* A full-viewport orchard scene sits under the whole game, like the
     illustrated backdrops in modern casual puzzle games. */
  background-color: var(--paper);
  background-image: url('web-assets/images/orchard-bg.webp');
  background-position: center center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  /* The game is a single fixed-height screen — the page never scrolls, so
     no browser scrollbar ever appears. */
  overflow-y: hidden;
  scrollbar-width: none;
}
body::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* The orchard art is loud. A soft vignette pushes the eye toward the play
   panel and keeps the saturated greens from fighting the UI. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(115% 88% at 50% 40%, rgba(255,255,255,0) 42%, rgba(9, 42, 26, .30) 100%),
    linear-gradient(180deg, rgba(9, 42, 26, .22) 0%, rgba(9, 42, 26, 0) 22%);
}

button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid rgba(18, 135, 140, 0.35); outline-offset: 3px; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin-top: 0; }

[hidden] { display: none !important; }

.app-shell {
  position: relative;
  z-index: 1;
  /* One fixed-height screen: the game fills the viewport and the page never
     scrolls, so no browser scrollbar is ever rendered. */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  isolation: isolate;
  overflow: hidden;
}

/* The orchard art replaces the old ambient gradient blobs. */
.ambient { display: none; }
/* ---------- Header ----------
   An opaque cream bar with a hard green underline: against the bright sky
   of the orchard art, a translucent header would wash out the small caps. */
.site-header {
  position: relative;
  z-index: 5;
  width: 100%;
  margin: 0;
  padding: 16px max(24px, calc((100% - 1180px) / 2)) 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 0 0 24px 24px;
  border-bottom: 3px solid #14603f;
  box-shadow: 0 10px 26px rgba(8, 40, 26, .34);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 13px;
  background: linear-gradient(150deg, #1a8f55, #0c5c37);
  box-shadow: 0 6px 16px rgba(9, 60, 38, .38), inset 0 1px 0 rgba(255,255,255,.35);
  flex: none;
}
.brand-mark span {
  position: absolute;
  width: 19px; height: 19px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 0 rgba(7, 45, 28, .32);
}
.brand-mark span:nth-child(1) { left: 8px; top: 7px; background: #ef4444; }
.brand-mark span:nth-child(2) { left: 15px; top: 13px; background: var(--yellow); }
.brand-mark span:nth-child(3) { left: 8px; top: 19px; background: #8b5cf6; }

.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text strong { font-size: 16px; letter-spacing: .12em; font-weight: 800; color: var(--ink); white-space: nowrap; }
.brand-text small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
}

.header-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn, .round-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  padding: 0;
  border: 2px solid var(--line-strong);
  border-radius: 13px;
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(16, 60, 48, .16);
  transition: transform .18s ease, background .18s ease, border-color .18s ease, color .18s ease;
}
.icon-btn:hover, .round-btn:hover {
  transform: translateY(-2px);
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal-dark);
}
.icon-btn svg, .round-btn svg, .tool-btn svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn[aria-pressed="false"] { color: #7f939b; }
.icon-btn[aria-pressed="false"] .sound-wave { display: none; }
.icon-btn.is-on { color: var(--teal-dark); border-color: var(--teal); background: var(--teal-soft); }

.ghost-btn {
  border: 2px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 17px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(16, 60, 48, .16);
  transition: transform .18s ease, background .18s ease, border-color .18s ease, color .18s ease;
}
.ghost-btn:hover {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal-dark);
  transform: translateY(-1px);
}
.header-levels { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; }
.header-levels svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ---------- Screens ---------- */
.screen { display: none; }
.screen.is-active { display: block; animation: screen-in .42s ease both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* The game screen owns the whole space between the header and the viewport
   bottom, so the board can size itself to whatever room is left. */
#gameScreen.is-active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

main {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Level picker (dialog) ---------- */
.level-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.level-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  border: 2px solid #c3d5d2;
  border-radius: 20px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.level-card:hover:not(:disabled) { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--teal); }
.level-card:disabled { cursor: not-allowed; opacity: .62; background: #f2f5f4; box-shadow: none; }
.level-index {
  flex: none;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 17px;
  font-weight: 850;
}
.level-card:disabled .level-index { background: #e4eae8; color: #87999c; }
.level-text { display: block; min-width: 0; flex: 1 1 auto; }
.level-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 6px;
}
.level-head strong { font-size: 15px; letter-spacing: -.015em; color: var(--ink); }
.level-tag {
  padding: 3px 8px;
  border-radius: 999px;
  background: #e7f1ef;
  color: var(--teal-dark);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.level-card:disabled .level-tag { background: #e4eae8; color: #87999c; }
.level-blurb {
  display: block;
  margin-bottom: 9px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.55;
}
.level-card:disabled .level-blurb { color: var(--muted); }
.level-stats { display: flex; flex-wrap: wrap; gap: 5px; }
.level-stats i {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: #fafcfb;
  color: var(--ink-soft);
  font-size: 9.5px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
}
.level-stats .level-badge {
  border-color: transparent;
  background: var(--yellow-soft);
  color: #8a5f00;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* ---------- Game ----------
   The panel is the one calm, opaque surface in front of the orchard art:
   a solid cream card, a hard white rim and a deep green shadow ring so it
   never blends into the busy grass behind it. */
.game-shell {
  width: min(720px, 100%);
  /* Pulled right up under the header bar. */
  margin: 8px auto 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  border: 2px solid #fff;
  border-radius: 30px;
  background: linear-gradient(180deg, #fffdf7 0%, #ffffff 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow:
    0 0 0 3px rgba(9, 66, 42, .30),
    0 30px 70px rgba(7, 38, 24, .46),
    inset 0 1px 0 rgba(255,255,255,.95);
}

.game-topbar { display: flex; align-items: center; gap: 14px; }
.level-meta { display: flex; flex-direction: column; gap: 3px; margin-right: auto; min-width: 0; }
.level-meta span { color: var(--teal-dark); font-size: 10px; font-weight: 900; letter-spacing: .17em; white-space: nowrap; }
.level-meta strong {
  font-size: 18px;
  letter-spacing: -.02em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-stats { display: flex; align-items: center; gap: 10px; }
.stat {
  min-width: 70px;
  padding: 7px 12px;
  border-radius: 12px;
  background: #eef4f2;
  border: 1.5px solid var(--line-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9);
  text-align: center;
}
.stat span { display: block; color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .14em; }
.stat strong { display: block; margin-top: 2px; font-size: 16px; font-variant-numeric: tabular-nums; color: var(--ink); }
.stat-score strong { color: var(--teal-dark); }

.progress-row { display: flex; align-items: center; gap: 12px; margin: 18px 0 14px; }
.progress-track {
  flex: 1; height: 11px;
  border-radius: 999px;
  background: #dde8e6;
  border: 1.5px solid var(--line-strong);
  overflow: hidden;
}
#progressBar {
  width: 0; height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0d7a80, #2fae7a);
  transition: width .4s cubic-bezier(.2,.8,.2,1);
}
#progressText { color: var(--ink-soft); font-size: 11.5px; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* The board pane absorbs whatever vertical room is left between the progress
   bar and the basket, so the whole game fits one screen without scrolling. */
.board-wrap {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 190px;
  border-radius: 24px;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, rgba(13,122,128,.22) 1px, transparent 1.7px) 0 0 / 20px 20px,
    linear-gradient(160deg, #e4efeb 0%, #f6f0dd 100%);
  border: 2px solid #adc6c2;
  box-shadow: inset 0 2px 14px rgba(9, 66, 42, .14);
  padding: 10px;
}
/* The tutorial is a single loose 3x3 layer — no need for a tall stack pane. */
.board-wrap.is-tutorial { flex: 1 1 auto; }
/* The board lives in its own pane. Sealed crates dock beside it instead of
   floating above it, so no fruit is ever hidden by a crate. */
.board-stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}
.board {
  position: absolute;
  left: 50%; top: 50%;
  width: var(--board-w);
  height: var(--board-h);
  transform: translate(-50%, -50%);
}

/* Fruit accents — every tile wears a rim in its own colour, so two similar
   fruits never blur into one another on a crowded board. The rim is the
   only thing that changes colour; the fruit art itself stays untouched.
   Hues follow the icon's dominant pixels, except for watermelon: its icon
   is a red slice with a bold green rind, and the green rim keeps the
   tutorial trio (green / red / purple) unmistakable. */
[data-fruit="cherries"]   { --accent: #c2183c; }
[data-fruit="banana"]     { --accent: #e0a400; }
[data-fruit="tangerine"]  { --accent: #f97316; }
[data-fruit="watermelon"] { --accent: #12a150; }
[data-fruit="apple"]      { --accent: #9e1b1b; }
[data-fruit="grapes"]     { --accent: #7c3aed; }
[data-fruit="kiwi"]       { --accent: #7cb342; }
[data-fruit="strawberry"] { --accent: #e01e37; }
[data-fruit="chestnut"]   { --accent: #8b5e34; }
[data-fruit="lime"]       { --accent: #a3e635; }
[data-fruit="peach"]      { --accent: #f0a868; }
[data-fruit="pineapple"]  { --accent: #d18f00; }
[data-fruit="avocado"]    { --accent: #4d7c0f; }
[data-fruit="coconut"]    { --accent: #7c4a24; }
[data-fruit="pear"]       { --accent: #c2c814; }
[data-fruit="greenapple"] { --accent: #22c55e; }
[data-fruit="melon"]      { --accent: #86b85b; }
[data-fruit="olive"]      { --accent: #6b7f2a; }

.tile {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-h);
  padding: 0;
  border: 2px solid var(--accent, #1f8a4c);
  border-radius: calc(var(--tile-w) * .19);
  background: linear-gradient(180deg, #ffffff 0%, #f6fbf9 100%);
  box-shadow: 0 5px 0 var(--tile-edge), 0 13px 20px rgba(11, 82, 51, .34);
  cursor: pointer;
  z-index: var(--z, 1);
  transition: left .34s cubic-bezier(.22,.9,.25,1), top .34s cubic-bezier(.22,.9,.25,1),
              transform .18s ease, filter .2s ease, opacity .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1.5px solid rgba(12, 70, 55, .22);
  border-radius: calc(var(--tile-w) * .13);
  pointer-events: none;
}
.tile-icon {
  width: 88%; height: 88%;
  object-fit: contain;
  margin: auto;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(10, 70, 42, .24));
  transition: transform .34s cubic-bezier(.2,.9,.3,1.3), opacity .2s ease;
}
/* Every fruit is visible at all times. A tile that is covered by another tile
   is dimmed and disabled — the stack itself is the lock. */
.tile.is-free:hover { transform: translateY(-4px); filter: brightness(1.04); }
.tile.is-free:active { transform: translateY(1px); box-shadow: 0 2px 0 var(--tile-edge-deep), 0 5px 10px rgba(11, 82, 51, .30); }
.tile.is-blocked {
  cursor: not-allowed;
  border-color: #9cb3ad;
  /* Buried cards keep a duller version of the deep green edge, so the stack
     recedes into the board while the pickable cards stay the richest thing
     on it. */
  --tile-edge: #35795c;
  --tile-edge-deep: #275f48;
}
.tile.is-blocked .tile-icon { opacity: .34; filter: grayscale(.65); transform: scale(.86); }
.tile.is-blocked::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(9, 48, 32, .22);
  box-shadow: 0 3px 0 var(--tile-edge-deep), 0 7px 0 var(--tile-edge), 0 13px 20px rgba(11, 82, 51, .34);
  pointer-events: none;
}
.tile.is-hidden { opacity: 0; pointer-events: none; transform: scale(.7); }
.tile.is-dealt { animation: deal-in .5s cubic-bezier(.18,.9,.28,1.2) backwards; animation-delay: var(--delay, 0s); }
@keyframes deal-in {
  from { opacity: 0; transform: translate(-26px,-40px) scale(.5) rotate(-8deg); }
  to { opacity: 1; transform: none; }
}
.tile.just-unlocked { animation: unlock-pop .42s ease; }
@keyframes unlock-pop { 40% { transform: scale(1.12) rotate(-3deg); filter: brightness(1.1); } }
.tile.shake { animation: shake .34s ease; }
@keyframes shake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }

/* ---------- Sealed crates ----------
   Independent of the overlap graph: always tappable, always one card deep.
   The dark stack and the coin lid read as "unknown" next to the bright fruit.
   On desktop the crates stack in a vertical rail whose height follows the
   board pane: each crate takes an equal share of the column, so five or six
   of them always fit without spilling over the rail. */
.box-dock {
  flex: 0 0 auto;
  width: clamp(58px, 13%, 84px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 24px 4px 8px;
  border-radius: 16px;
  background: rgba(30, 24, 62, .10);
  border: 2px dashed rgba(30, 24, 62, .34);
  position: relative;
  z-index: 2;
}
.box-dock-label {
  position: absolute;
  top: 7px; left: 0; right: 0;
  color: #38325e;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .05em;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 0 rgba(255,255,255,.85);
}
.mystery-box {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  width: auto;
  height: auto;
  max-width: 72px;
  max-height: 84px;
  aspect-ratio: 1 / 1.12;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(155deg, #4b4778 0%, #2c294d 55%, #211f3d 100%);
  box-shadow: 0 5px 0 #17152c, 0 12px 20px rgba(25,22,58,.45), inset 0 1px 0 rgba(255,255,255,.16);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .18s ease, filter .2s ease, opacity .28s ease;
  -webkit-tap-highlight-color: transparent;
}
/* Five or six boxes: tighten the gaps so all of them stay inside the rail. */
.box-dock.is-dense { gap: 6px; }

.mystery-box::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1.5px solid rgba(255,255,255,.24);
  border-radius: 10px;
  pointer-events: none;
}
.mystery-box::after {
  content: "";
  position: absolute;
  inset: auto 10% 7% 10%;
  height: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  box-shadow: 0 -7px 0 rgba(255,255,255,.07);
  pointer-events: none;
}
.box-face {
  width: 76%;
  height: 76%;
  object-fit: contain;
  pointer-events: none;
  /* A halo in the fruit's own colour ties the crate to the fruit it holds. */
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.42)) drop-shadow(0 0 6px var(--accent, rgba(255,255,255,.5)));
}
.mystery-box.is-dealt { animation: deal-in .5s cubic-bezier(.18,.9,.28,1.2) backwards; animation-delay: var(--delay, 0s); }
.mystery-box:hover { transform: translateY(-4px) rotate(-2deg); filter: brightness(1.08); }
.mystery-box:active { transform: translateY(1px); }
.mystery-box.is-flipping .box-face { animation: box-flip .42s ease; }
@keyframes box-flip {
  0% { transform: rotateY(0) scale(1); opacity: 1; }
  48% { transform: rotateY(90deg) scale(.7); opacity: .18; }
  100% { transform: rotateY(0) scale(1); opacity: 1; }
}
.mystery-box.is-empty { opacity: 0; pointer-events: none; transform: scale(.55) rotate(9deg); }

.tray-section { margin-top: 18px; }
.tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 2px 8px;
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 900;
  letter-spacing: .14em;
}
.tray-header small { margin-left: 6px; color: var(--muted); font-size: 10px; letter-spacing: .06em; font-weight: 700; }
#trayCount { color: var(--teal-dark); font-variant-numeric: tabular-nums; }
#trayCount.is-danger { color: var(--coral); }

.tray {
  display: grid;
  grid-template-columns: repeat(var(--tray-size, 8), minmax(0, 1fr));
  gap: 7px;
  padding: 11px;
  border-radius: 18px;
  background: #e9f1ef;
  border: 2px solid var(--line-strong);
  box-shadow: inset 0 2px 8px rgba(9, 66, 42, .10);
  transition: border-color .2s ease, background .2s ease;
}
.tray.is-danger { background: #fdeeea; border-color: var(--coral); }
.tray-slot {
  position: relative;
  aspect-ratio: 1 / 1.12;
  min-width: 0;
  border-radius: 11px;
  border: 2px dashed #9fb8b3;
  background: rgba(255,255,255,.72);
  display: grid;
  place-items: center;
}
.tray-tile {
  width: 100%; height: 100%;
  padding: 0;
  border: 2px solid var(--accent, #1f8a4c);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 3px 0 #1e7f4c, 0 6px 10px rgba(11, 82, 51, .28);
  display: grid;
  place-items: center;
  cursor: default;
}
.tray-tile img { width: 86%; height: 86%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 1px 2px rgba(10, 70, 42, .22)); }
.tray-tile.is-pending { opacity: 0; }
.tray-tile.is-new { animation: tray-drop .32s cubic-bezier(.2,.9,.25,1.3); }
@keyframes tray-drop { from { opacity: 0; transform: translateY(-22px) scale(.7); } to { opacity: 1; transform: none; } }
.tray-tile.is-merging { animation: merge-away .28s ease forwards; }
@keyframes merge-away { to { opacity: 0; transform: scale(.25) rotate(12deg); } }

.toolbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.tool-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 50px;
  padding: 8px 6px;
  border: 2px solid var(--line-strong);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(16, 60, 48, .16);
  transition: transform .16s ease, border-color .16s ease, background .16s ease, color .16s ease;
}
.tool-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--teal-dark);
}
.tool-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.tool-btn svg { width: 18px; height: 18px; flex: none; stroke-width: 2.1; }
.tool-count {
  position: absolute;
  top: -7px; right: -6px;
  min-width: 21px; height: 21px;
  display: grid; place-items: center;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--yellow);
  color: #5c3f00;
  font-size: 10.5px;
  font-weight: 900;
  box-shadow: 0 2px 6px rgba(154,107,0,.35);
}
.tool-btn-quiet { background: #f4f8f7; border-style: dashed; border-color: #a8c0bb; }

.game-hint {
  margin: 13px 4px 2px;
  color: var(--ink-soft);
  font-size: 11.5px;
  line-height: 1.55;
  font-weight: 600;
  text-align: center;
}

/* ---------- Fly animation / toast ---------- */
.fly-layer { position: fixed; inset: 0; pointer-events: none; z-index: 80; }
.fly-tile {
  position: fixed;
  width: var(--tile-w); height: var(--tile-h);
  border-radius: calc(var(--tile-w) * .19);
  background: #fff;
  border: 2px solid var(--accent, #1f8a4c);
  box-shadow: 0 8px 20px rgba(11, 82, 51, .32);
  display: grid; place-items: center;
  transition: left .42s cubic-bezier(.3,.75,.25,1), top .42s cubic-bezier(.3,.75,.25,1),
              width .42s ease, height .42s ease, transform .42s ease, opacity .42s ease;
}
.fly-tile img { width: 78%; height: 78%; object-fit: contain; }
.score-pop {
  position: fixed;
  z-index: 90;
  color: var(--teal-dark);
  font-size: 19px;
  font-weight: 900;
  text-shadow: 0 2px 0 #fff, 0 0 12px #fff;
  animation: score-pop .85s ease-out forwards;
  pointer-events: none;
}
@keyframes score-pop { 0% { opacity: 0; transform: translateY(6px) scale(.75); } 25% { opacity: 1; transform: translateY(-8px) scale(1.1); } 100% { opacity: 0; transform: translateY(-52px) scale(1); } }

.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  z-index: 95;
  transform: translate(-50%, 18px);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  font-weight: 800;
  box-shadow: 0 0 0 2px rgba(255,255,255,.85), var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 40, 28, .58);
  backdrop-filter: blur(5px);
  animation: fade-in .2s ease both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(460px, 100%);
  max-height: min(86vh, 720px);
  overflow: hidden;
  padding: 34px 32px 30px;
  border-radius: 26px;
  background: #fff;
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(9, 66, 42, .28), var(--shadow-lg);
  text-align: center;
  animation: modal-in .32s cubic-bezier(.2,.9,.25,1.15) both;
}
.modal.is-wide { width: min(680px, 100%); }
.modal.is-wide .level-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(18px) scale(.94); } to { opacity: 1; transform: none; } }
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
}
.modal-close:hover { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-dark); }
.modal-close svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.modal-icon {
  flex: none;
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 29px;
  font-weight: 900;
}
.modal-icon svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.modal-icon.is-warn { background: #fff0e9; color: var(--coral); }
.modal-icon.is-star { background: var(--yellow-soft); color: #b58000; }
.modal h2 { flex: none; margin: 0 0 8px; font-size: 25px; letter-spacing: -.03em; color: var(--ink); }
.modal > p { flex: none; margin: 0 auto 18px; max-width: 360px; color: var(--ink-soft); font-size: 13px; line-height: 1.65; }
/* The body scrolls on its own so the action buttons never scroll out of reach. */
.modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-bottom: 20px; padding-right: 6px; }
.rules-list { margin: 0; padding: 0; list-style: none; text-align: left; }
.rules-list li {
  display: flex;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px dashed var(--line-strong);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
}
.rules-list li:last-child { border-bottom: 0; }
/* Only the step badge is a chip. Inline <b> inside a sentence has to stay
   inline text — styling every <b> turned emphasis words into fixed-size
   blocks that broke the line flow and overlapped the paragraph. */
.rules-list li > b {
  flex: none;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 850;
}
.rules-list li > span { min-width: 0; }
.rules-list li > span b {
  display: inline;
  width: auto; height: auto;
  background: none;
  border-radius: 0;
  color: var(--ink);
  font-size: inherit;
  font-weight: 800;
}
.modal-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.modal-stats div { padding: 12px 6px; border-radius: 14px; background: #eef4f2; border: 1.5px solid var(--line-strong); }
.modal-stats strong { display: block; font-size: 18px; font-variant-numeric: tabular-nums; color: var(--ink); }
.modal-stats span { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.modal-actions { flex: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; }
.modal-actions button {
  min-width: 116px;
  padding: 12px 17px;
  border-radius: 13px;
  border: 2px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(16, 60, 48, .14);
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.modal-actions button:hover { transform: translateY(-2px); background: var(--teal-soft); border-color: var(--teal); color: var(--teal-dark); }
.modal-actions button.btn-primary { background: var(--teal); border-color: var(--teal-dark); color: #fff; }
.modal-actions button.btn-primary:hover { background: var(--teal-dark); color: #fff; }
.modal-actions button:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- Responsive ---------- */
@media (max-width: 620px) {
  /* The phone layout is planned around one goal: the board gets every pixel
     it can. Deep levels render 7-9 tile units across and need ~7 vertical
     units of stack, so a few dozen pixels of chrome can halve the tile size.
     Every strip below is tightened, but nothing is removed — the rules live
     in the How to play dialog. Desktop is untouched. */
  .site-header { width: 100%; padding: 5px 8px 4px; border-radius: 0 0 14px 14px; border-bottom-width: 2px; }
  main { width: calc(100% - 16px); }
  .brand { gap: 7px; }
  .brand-mark { width: 30px; height: 30px; border-radius: 10px; }
  .brand-mark span { width: 14px; height: 14px; border-radius: 5px; }
  .brand-mark span:nth-child(1) { left: 5px; top: 5px; }
  .brand-mark span:nth-child(2) { left: 10px; top: 9px; }
  .brand-mark span:nth-child(3) { left: 5px; top: 13px; }
  .brand-text small { display: none; }
  .brand-text strong { font-size: 12px; letter-spacing: .08em; }
  .header-actions { gap: 5px; }
  .icon-btn, .round-btn { width: 30px; height: 30px; border-radius: 9px; }
  .icon-btn svg, .round-btn svg, .tool-btn svg { width: 16px; height: 16px; }
  .header-help { display: none; }
  .header-levels { padding: 6px 8px; font-size: 10px; gap: 4px; }
  .header-levels svg { width: 12px; height: 12px; }
  .level-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .modal.is-wide .level-list { grid-template-columns: 1fr; }
  .level-card { padding: 11px; gap: 8px; }
  .level-index { width: 34px; height: 34px; font-size: 13px; border-radius: 10px; }
  .level-head strong { font-size: 12px; }
  .level-blurb { font-size: 10px; margin-bottom: 6px; }
  .level-tag { font-size: 8px; padding: 2px 6px; }
  .level-stats i { font-size: 8px; padding: 2px 6px; }
  .level-badge { display: none; }

  .game-shell { padding: 8px; border-radius: 16px; margin-top: 3px; }
  .game-topbar { gap: 6px; }
  .level-meta { gap: 1px; }
  .level-meta span { font-size: 8px; letter-spacing: .1em; }
  .level-meta strong { font-size: 13px; }
  .stat { min-width: 48px; padding: 3px 5px; border-radius: 9px; }
  .stat span { font-size: 7.5px; letter-spacing: .08em; }
  .stat strong { font-size: 13px; margin-top: 0; }
  .top-stats { gap: 4px; }
  .progress-row { margin: 5px 0 4px; gap: 7px; }
  .progress-track { height: 7px; }
  #progressText { font-size: 9.5px; }

  .board-wrap { flex-direction: column; flex: 1 1 auto; min-height: 150px; border-radius: 14px; padding: 5px; gap: 5px; }
  /* Narrow screens: park the crates in a horizontal rail under the board.
     The caption sits above the crates, so 17px of top padding keeps it clear
     while the rail itself stays only 55px tall. */
  .box-dock {
    flex: 0 0 55px;
    width: 100%;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
    padding: 17px 4px 3px;
    border-radius: 10px;
  }
  .box-dock-label { top: 1px; font-size: 8px; letter-spacing: .06em; }
  .mystery-box { flex: 0 0 auto; width: 30px; max-width: none; height: auto; max-height: none; }
  .box-dock.is-dense { gap: 3px; }
  .box-dock.is-dense .mystery-box { width: 25px; max-width: none; }

  .tray-section { margin-top: 5px; }
  .tray-header { margin: 0 1px 3px; font-size: 9.5px; letter-spacing: .08em; }
  .tray-header small { font-size: 8px; margin-left: 3px; }
  .tray { gap: 3px; padding: 4px; border-radius: 12px; }
  .tray-slot { aspect-ratio: 1 / .8; border-radius: 6px; }
  .tray-tile { border-radius: 6px; }
  .toolbar { gap: 4px; margin-top: 6px; }
  .tool-btn { min-height: 36px; flex-direction: column; gap: 1px; font-size: 9px; padding: 3px 2px; border-radius: 9px; }
  .tool-btn svg { width: 14px; height: 14px; }
  .tool-count { top: -5px; right: -3px; min-width: 16px; height: 16px; font-size: 9px; padding: 0 3px; }
  .game-hint { display: none; }
  .modal { padding: 30px 20px 24px; }
}

@media (max-width: 380px) {
  .brand-text strong { font-size: 11px; }
  .header-levels span { display: none; }
  .header-levels { padding: 6px 8px; }
  .level-list { grid-template-columns: 1fr; }
  .stat { min-width: 42px; padding: 2px 4px; }
  .stat span { font-size: 7px; letter-spacing: .06em; }
  .stat strong { font-size: 12px; }
  .level-meta strong { font-size: 12px; }
  .tool-btn { font-size: 8px; }
}

/* ---------- Short viewports ----------
   The game is one fixed screen, so on a squat window the chrome has to give
   way to the board: the hint line folds away and the gaps tighten. */
@media (max-height: 760px) {
  .game-hint { display: none; }
  .progress-row { margin: 12px 0 10px; }
  .tray-section { margin-top: 12px; }
  .toolbar { margin-top: 11px; }
}
@media (max-height: 620px) {
  .site-header { padding-top: 10px; padding-bottom: 9px; }
  .game-shell { margin-top: 5px; padding: 12px; }
  .game-topbar { gap: 10px; }
  .board-wrap { min-height: 160px; }
  .tray { padding: 8px; }
  .tray-slot { aspect-ratio: 1 / 1; }
  .tool-btn { min-height: 42px; }
  .toolbar { margin-top: 9px; }
}

/* The generic short-viewport rules above are tuned for desktop windows. On a
   phone they must not hand the tightened strips their height back, or the
   board shrinks again on exactly the devices that need it most. */
@media (max-width: 620px) and (max-height: 760px) {
  .progress-row { margin: 5px 0 4px; }
  .tray-section { margin-top: 5px; }
  .toolbar { margin-top: 6px; }
}
@media (max-width: 620px) and (max-height: 620px) {
  .site-header { padding-top: 4px; padding-bottom: 3px; }
  .game-shell { margin-top: 2px; padding: 6px; }
  .game-topbar { gap: 5px; }
  .board-wrap { min-height: 130px; }
  .tray { padding: 3px; }
  .tray-slot { aspect-ratio: 1 / .72; }
  .tool-btn { min-height: 32px; }
  .toolbar { margin-top: 4px; }
}

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