:root {
  --ink: #2c3e2d;
  --panel: rgba(255, 250, 240, 0.94);
  --accent: #e8890c;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* svh = Safari toolbar-visible height; 2 rows + gap + bench must fit board-wrap */
  --app-h: 100svh;
  --bottle-w: clamp(48px, 14vw, 110px);
  --bottle-h: clamp(120px, 26svh, 280px);
  --ctrl-h: 48px;
  --chrome-gap: 8px;
  /* V3 ui/button-pill.svg has baked "Next Garden" text — do not edit Nova files;
     use V2 blank pill for stretchable backgrounds. */
  --pill: url("../assets/nova/bloom-pour-artwork/assets/button-pill.svg");
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;
  max-height: 100svh;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

body {
  background-color: #7ec8a0;
  min-height: 100%;
  min-height: 100dvh;
  max-height: 100svh;
  position: relative;
}

/* ---- Soft-3D scene layers (Nova V5 — individual layers only, never promo mockups) ---- */
.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background: #6bb88a; /* matching edge fill for wide screens — no blur panels */
}
.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 60% at 70% 8%, rgba(255, 220, 160, 0.22), transparent 55%),
    linear-gradient(180deg, rgba(255, 236, 200, 0.08) 0%, transparent 35%, rgba(40, 60, 40, 0.1) 100%);
}
.layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  pointer-events: none;
}
/* Portrait garden bg: cover-fit phones 320–430; wide screens scale/cover + solid side fill (no blur) */
.layer-garden-bg {
  z-index: 1;
  background-size: cover;
  background-position: center 40%;
}
.layer-chapter-tint {
  z-index: 2;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: soft-light;
  opacity: 0.55;
  background: transparent;
}
.layer-chapter-tint { opacity: 0.85; }
.scene.chapter-1 .layer-chapter-tint { background: linear-gradient(180deg, rgba(255,200,120,0.55), rgba(120,200,140,0.28) 55%, rgba(80,160,100,0.12)); }
.scene.chapter-2 .layer-chapter-tint { background: linear-gradient(180deg, rgba(140,200,255,0.58), rgba(160,230,200,0.32) 50%, rgba(100,180,160,0.12)); }
.scene.chapter-3 .layer-chapter-tint { background: linear-gradient(180deg, rgba(255,160,80,0.62), rgba(255,210,130,0.35) 48%, rgba(200,140,60,0.14)); }
.scene.chapter-4 .layer-chapter-tint { background: linear-gradient(180deg, rgba(170,120,230,0.58), rgba(90,70,150,0.32) 52%, rgba(60,40,100,0.16)); }
.scene.chapter-5 .layer-chapter-tint { background: linear-gradient(180deg, rgba(60,80,140,0.55), rgba(30,45,90,0.38) 45%, rgba(15,25,50,0.22)); }
/* Chapter-specific bottle glass grading (colour grading only — no new art) */
.scene.chapter-1 .bottle-glass, .app.chapter-1 .bottle-glass { filter: sepia(0.12) saturate(1.05); }
.scene.chapter-2 .bottle-glass, .app.chapter-2 .bottle-glass { filter: hue-rotate(-8deg) saturate(1.08) brightness(1.02); }
.scene.chapter-3 .bottle-glass { filter: sepia(0.22) saturate(1.15) brightness(1.04); }
.scene.chapter-4 .bottle-glass { filter: hue-rotate(18deg) saturate(1.1) brightness(0.97); }
.scene.chapter-5 .bottle-glass { filter: hue-rotate(200deg) saturate(0.9) brightness(0.92); }
.scene.chapter-1 .row-plank img, .app.chapter-1 .row-plank img { filter: drop-shadow(0 3px 8px rgba(40,30,10,0.4)) sepia(0.15); }
.scene.chapter-2 .row-plank img, .app.chapter-2 .row-plank img { filter: drop-shadow(0 3px 8px rgba(40,30,10,0.4)) hue-rotate(-6deg); }
.scene.chapter-3 .row-plank img { filter: drop-shadow(0 3px 8px rgba(40,30,10,0.4)) sepia(0.25) brightness(1.05); }
.scene.chapter-4 .row-plank img { filter: drop-shadow(0 3px 8px rgba(40,30,10,0.4)) hue-rotate(12deg) brightness(0.95); }
.scene.chapter-5 .row-plank img { filter: drop-shadow(0 3px 8px rgba(40,30,10,0.4)) brightness(0.85) saturate(0.85); }
.chapter-badge {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 11;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,250,240,0.82);
  color: #1e3a2f;
  box-shadow: 0 1px 4px rgba(20,40,30,0.15);
  pointer-events: none;
}
.scene.chapter-5 ~ .app .chapter-badge,
.app.chapter-night .chapter-badge { background: rgba(40,50,80,0.75); color: #e8f0ff; }

/* Corner flower clusters — decorative only, never intercept taps */
.layer-corner {
  z-index: 7;
  pointer-events: none !important;
  background-size: contain;
  background-repeat: no-repeat;
  width: min(42vw, 220px);
  height: min(36vw, 190px);
  inset: auto;
  opacity: 0.92;
  filter: drop-shadow(0 4px 8px rgba(20,40,30,0.25));
}
.layer-corner-left {
  left: -2%;
  bottom: -1%;
  background-position: left bottom;
}
.layer-corner-right {
  right: -2%;
  bottom: -1%;
  background-position: right bottom;
}
@media (min-width: 900px) {
  .layer-corner { width: 260px; height: 220px; }
}

.milestone-prop {
  position: absolute;
  z-index: 4;
  width: min(22vw, 110px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(30,50,40,0.25));
  pointer-events: none;
  opacity: 0.85;
}
#prop-fountain { left: 4%; bottom: 22%; }
#prop-greenhouse { right: 3%; bottom: 20%; width: min(28vw, 140px); }

.sparkle-layer { position: absolute; inset: 0; z-index: 8; pointer-events: none; }

.scene.sway .layer-corner-left {
  animation: swayFast 10s ease-in-out infinite alternate;
}
.scene.sway .layer-corner-right {
  animation: swaySlow 12s ease-in-out infinite alternate;
}
.scene.sway .milestone-prop {
  animation: swayProp 11s ease-in-out infinite alternate;
}
@keyframes swaySlow {
  from { transform: translate3d(-0.6%, 0, 0); }
  to { transform: translate3d(0.6%, 0, 0); }
}
@keyframes swayFast {
  from { transform: translate3d(-1.2%, 0, 0); }
  to { transform: translate3d(1.2%, 0, 0); }
}
@keyframes swayProp {
  from { transform: translate3d(0, 0, 0) rotate(-0.6deg); }
  to { transform: translate3d(0, -1%, 0) rotate(0.6deg); }
}

#game { position: relative; height: var(--app-h); max-height: 100svh; }

.app {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  height: var(--app-h);
  max-height: 100svh;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: 4px 8px calc(6px + var(--safe-bottom));
  overflow-x: hidden;
  overflow-y: hidden;
}

header {
  text-align: center;
  padding: 2px 4px 0;
  flex-shrink: 0;
}
header h1 {
  font-size: clamp(1.05rem, 4.5vw, 1.55rem);
  font-weight: 700;
  color: #1e3a2f;
  text-shadow: 0 1px 0 rgba(255,255,255,0.55);
}
header .tag {
  font-size: clamp(0.8125rem, 2.8vw, 0.9rem); /* ≥13px readable */
  opacity: 0.9;
}

.top-bar {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 4px 0;
  flex-shrink: 0;
}
.top-bar button.nav,
.panel .nav.back {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  background-color: var(--panel);
  background-image: var(--pill);
  background-size: 100% 100%;
  box-shadow: 0 1px 4px rgba(40,60,40,0.12);
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}

.controls {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  justify-content: center;
  padding: 2px 0;
  flex-shrink: 0;
  position: relative;
  z-index: 12;
  background: transparent;
}
.controls button,
.controls button.ctrl-icon {
  appearance: none;
  border: none;
  border-radius: 999px;
  height: var(--ctrl-h);
  width: var(--ctrl-h);
  min-width: 48px;
  min-height: 48px; /* touch target */
  padding: 0;
  font-size: 0;
  font-weight: 600;
  color: var(--ink);
  background-color: var(--panel);
  background-image: var(--pill);
  background-size: 100% 100%;
  box-shadow: 0 2px 6px rgba(40, 60, 40, 0.12);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  position: relative;
}
.controls button img.icon {
  width: 20px;
  height: 20px;
  pointer-events: none;
}
.controls button:active { transform: scale(0.96); }
.controls button:disabled { opacity: 0.45; cursor: default; }
.controls button.toggle[aria-pressed="true"] {
  filter: none;
  background-color: #e8fff8;
  box-shadow: 0 0 0 2px #2ec4a0, 0 2px 6px rgba(40, 60, 40, 0.12);
  opacity: 1;
}
.controls button.toggle[aria-pressed="false"],
.controls button.toggle.is-off {
  opacity: 0.48;
  filter: grayscale(0.45);
  background-color: rgba(255,250,240,0.72);
  box-shadow: inset 0 1px 3px rgba(40,60,40,0.12);
}
/* Clear OFF slash over icon */
.controls button.toggle.is-off::after,
.controls button.toggle[aria-pressed="false"]::after {
  content: "";
  position: absolute;
  inset: 18% 12%;
  background: linear-gradient(
    to top right,
    transparent calc(50% - 1.5px),
    #c0392b calc(50% - 1.5px),
    #c0392b calc(50% + 1.5px),
    transparent calc(50% + 1.5px)
  );
  pointer-events: none;
  border-radius: 2px;
}
.controls.celebrate button,
.win-card .controls.celebrate button {
  width: auto !important;
  min-width: 120px;
  height: auto;
  min-height: 44px;
  padding: 10px 18px !important;
  font-size: 0.85rem !important;
}
.controls.celebrate button::after,
.win-card .controls.celebrate button::after { content: none !important; }
.controls.celebrate button.toggle.is-off::after { content: none !important; }

.caption {
  text-align: center;
  min-height: 1.2em;
  font-size: clamp(0.875rem, 2.8vw, 1rem); /* ≥14px */
  padding: 2px 6px;
  color: #3d5a45;
  flex-shrink: 0;
  line-height: 1.25;
}
.caption.guide { font-weight: 600; color: #b35a00; }
.caption-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
  min-height: 0;
}
.caption-row .btn-skip-tutorial {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 44px;
  min-width: 44px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(40,60,40,0.12);
  cursor: pointer;
  flex-shrink: 0;
}
.caption-row.hidden-tutorial .btn-skip-tutorial { display: none; }
.caption-row.is-idle { min-height: 0; height: 0; overflow: hidden; padding: 0; margin: 0; }
.caption-row.is-idle .caption { display: none; }

.board-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  position: relative;
  min-height: 0;
  /* Grow into leftover space; bottles scale via --bottle-h (svh) so both rows fit */
  height: auto;
  max-height: none;
  overflow: visible;
  z-index: 5;
  margin-bottom: 2px;
}
/* Barely-there veil — bottles rely on outline + liquid contrast, not a panel */
.puzzle-haze {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  width: min(96%, 440px);
  height: 70%;
  z-index: 1;
  pointer-events: none;
  border-radius: 40% 40% 28% 28% / 30% 30% 45% 45%;
  background:
    radial-gradient(ellipse at 50% 60%,
      rgba(255, 250, 240, 0.10) 0%,
      rgba(255, 246, 230, 0.04) 40%,
      transparent 68%);
  box-shadow: none;
  filter: none;
  opacity: 0.55;
}

/* Per-row wooden table plank (nova-02) — bottles sit on the surface */
.board-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  flex: 0 0 auto;
}
.row-bottles {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: flex-end;
  column-gap: clamp(6px, 2vw, 12px);
  width: 100%;
  position: relative;
  z-index: 3;
}
.row-plank {
  position: relative;
  width: min(100%, calc(var(--per-row, 4) * var(--bottle-w) + (var(--per-row, 4) - 1) * 12px + 28px));
  height: clamp(28px, 5.5svh, 44px);
  margin-top: -14px;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
  border-radius: 4px;
}
.row-plank img {
  display: block;
  width: 100%;
  height: 140%;
  object-fit: cover;
  object-position: center 18%;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 3px 8px rgba(40, 30, 10, 0.4));
}
/* Legacy single shelf (removed from DOM) */
.bench-shelf { display: none !important; }
/* Under-board dark planter trays — removed; collection lives in Garden panel */
.garden-beds { display: none !important; height: 0 !important; max-height: 0 !important; overflow: hidden !important; margin: 0 !important; padding: 0 !important; }

.board {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  row-gap: clamp(6px, 1.4vw, 12px);
  column-gap: 0;
  justify-content: flex-end;
  align-items: center;
  align-content: flex-end;
  padding: 4px 4px 2px;
  max-width: 100%;
  width: 100%;
  position: relative;
  z-index: 5;
  flex: 0 1 auto;
  min-height: 0;
}

.bottle {
  position: relative;
  width: var(--bottle-w);
  height: var(--bottle-h);
  min-width: 44px; /* touch target */
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
  touch-action: manipulation;
  transition: transform 0.18s ease;
  z-index: 5;
  /* Outline + depth so bottles read on bright sky and dark foliage */
  filter:
    drop-shadow(0 0 1.2px rgba(255,255,255,0.95))
    drop-shadow(0 0 2.5px rgba(255,255,255,0.55))
    drop-shadow(0 5px 8px rgba(20, 30, 20, 0.42));
}
.bottle-contact {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -3px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(20, 16, 8, 0.45) 0%, rgba(20, 16, 8, 0.12) 55%, transparent 72%);
  pointer-events: none;
  z-index: 1;
}
.bottle-inner {
  /* Inset past rounded glass cap + base curve (SVG rx≈29/360 ≈ 8%; bottom needs ~15%+) */
  position: absolute;
  left: 16%;
  right: 16%;
  top: 18%;
  bottom: 16%;
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
  border-radius: 3px 3px 14px 14px;
  /* Extra mask so segment backgrounds cannot paint past the toe */
  clip-path: inset(0 0 0 0 round 3px 3px 14px 14px);
  z-index: 2;
  pointer-events: none;
}
.bottle-glass {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  object-fit: fill;
}
.bottle-halo {
  position: absolute;
  inset: -6%;
  width: 112%;
  height: 112%;
  left: -6%;
  top: -6%;
  pointer-events: none;
  z-index: 4;
  object-fit: fill;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.bottle.selected { transform: translateY(-10px); }
.bottle.selected .bottle-halo,
.bottle.hint-src .bottle-halo,
.bottle.hint-dst .bottle-halo { opacity: 1; }
.bottle.hint-src { filter: drop-shadow(0 0 6px #ffd166); }
.bottle.hint-dst { filter: drop-shadow(0 0 6px #06d6a0); }
.bottle.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.seg {
  width: 100%;
  position: relative;
  /* Equal slices of the well — --cap set on #board (default 4) */
  flex: 0 0 calc(100% / var(--cap, 4));
  height: calc(100% / var(--cap, 4));
  max-height: calc(100% / var(--cap, 4));
  box-sizing: border-box;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.seg .sym {
  width: 55%;
  height: 55%;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.25));
  z-index: 1;
}
.bottle-empty-pad { flex: 1 1 auto; min-height: 0; }

.guide-hand {
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fff7, #ffb703cc);
  border: 2px solid #fff;
  box-shadow: 0 0 12px #ffb703;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
}
.guide-hand.visible {
  opacity: 1;
  animation: guidePulse 1.4s ease-in-out infinite;
}
@keyframes guidePulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.12); opacity: 1; }
}

/* ---- Solid win / milestone panels (separate from board) ---- */
.win-panel,
.milestone-card {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 50, 40, 0.35);
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.win-panel.show,
.milestone-card.show {
  opacity: 1;
  pointer-events: auto;
}
.win-panel[hidden],
.milestone-card[hidden] { display: none !important; }

.win-card {
  background: #fffaf0;
  border-radius: 20px;
  padding: 20px 18px 16px;
  max-width: 320px;
  width: 92%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(20, 40, 30, 0.28);
  border: 2px solid rgba(30, 58, 47, 0.08);
}
.win-flower {
  width: min(140px, 40vw);
  height: min(140px, 40vw);
  object-fit: contain;
  margin: 0 auto 8px;
  display: block;
  transform: scale(0.2);
  opacity: 0;
}
.win-flower.milestone-art {
  width: min(200px, 58vw);
  height: min(240px, 42vh);
  max-height: 260px;
  margin: 4px auto 12px;
}
.win-flower.bloom-in {
  animation: flowerBloom 0.75s cubic-bezier(0.34, 1.45, 0.64, 1) forwards;
}
.win-flower.bloom-in.instant {
  animation: none;
  transform: scale(1);
  opacity: 1;
}
@keyframes flowerBloom {
  0% { transform: scale(0.2); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.win-card .msg {
  font-size: clamp(1.05rem, 4vw, 1.35rem);
  font-weight: 700;
  color: #1e3a2f;
}
.win-card .flower-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: #c45c26;
  margin-top: 4px;
}
.win-card .sub {
  font-size: 0.9rem;
  margin-top: 4px;
  opacity: 0.85;
}
.win-card .controls {
  margin-top: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.win-card .controls.celebrate button {
  min-height: 44px;
  min-width: 120px;
  padding: 0 18px;
  font-size: 0.95rem;
}

/* ---- Panels: levels + gallery ---- */
.panel {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: rgba(255, 250, 240, 0.97);
  backdrop-filter: blur(6px);
  display: none;
  flex-direction: column;
  padding: 10px 8px calc(10px + var(--safe-bottom));
  padding-left: max(8px, env(safe-area-inset-left, 0px));
  padding-right: max(8px, env(safe-area-inset-right, 0px));
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  overflow: hidden; /* inner regions scroll — avoids Safari flex/aspect crush */
  min-height: 0;
}
.panel.show { display: flex; }
.panel h2 {
  text-align: center;
  margin-bottom: 6px;
  font-size: 1.15rem;
  flex: 0 0 auto;
}
.garden-status {
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.85;
  margin-bottom: 8px;
  flex: 0 0 auto;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
}
.level-grid button {
  appearance: none;
  border: 2px solid rgba(30,58,47,0.15);
  border-radius: 12px;
  padding: 10px 4px;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}
.level-grid button:disabled { opacity: 0.4; cursor: default; }
.level-grid button.done { border-color: #2ec4a0; background: #e8fff8; }
.level-grid button.current { border-color: var(--accent); box-shadow: 0 0 0 2px #ffe0a8; }

.milestone-bar {
  max-width: 100%;
  width: 100%;
  margin: 4px auto 12px;
  padding: 0 2px;
}
.milestone-bar .bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(30,58,47,0.12);
  overflow: hidden;
}
.milestone-bar .bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #7bc96f, #2ec4a0);
  border-radius: 999px;
  transition: width 0.35s ease;
}
.milestone-bar .bar-markers {
  position: relative;
  height: 22px;
  margin-top: -16px;
}
.milestone-bar .marker {
  position: absolute;
  top: 0;
  font-size: 14px;
  opacity: 0.35;
  transform: translateX(-50%);
}
.milestone-bar .marker.on { opacity: 1; filter: drop-shadow(0 0 3px #2ec4a0); }
.milestone-bar .marker.m5 { left: 50%; }
.milestone-bar .marker.m10 { left: 100%; }
.milestone-bar .bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  opacity: 0.7;
  margin-top: 2px;
}

/* Scroll region for gallery — grows with content; panel header/Back stay put */
.garden-collection-scroll {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 2px 8px;
}
.garden-bed-section {
  margin: 0 0 14px;
  width: 100%;
}
.garden-bed-heading {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.75;
  margin: 4px 2px 8px;
  text-align: left;
}
.garden-grid {
  display: grid;
  /* Phones ≤400px: 3 cols so names stay readable */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 10px 8px;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  /* Do NOT flex-shrink or max-height this grid — that crushed aspect-ratio rows */
  align-content: start;
}
.garden-slot {
  border-radius: 12px;
  background: rgba(255,255,255,0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  border: 1px solid rgba(30,58,47,0.12);
  padding: 8px 4px 6px;
  gap: 4px;
  min-width: 0;
  min-height: 44px;
  height: auto;
  overflow: visible;
}
.garden-slot.featured {
  border-color: rgba(155, 93, 229, 0.55);
  background: rgba(255, 250, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(155, 93, 229, 0.35), 0 4px 12px rgba(155, 93, 229, 0.14);
}
.garden-slot .flower-art {
  width: 72%;
  max-width: 72px;
  height: auto;
  aspect-ratio: 1;
  flex: 0 0 auto;
  object-fit: contain;
  display: block;
}
.garden-slot .flower-art.silhouette {
  filter: brightness(0) opacity(0.28);
}
.garden-slot .slot-label {
  font-size: clamp(0.58rem, 2.9vw, 0.72rem);
  font-weight: 600;
  text-align: center;
  line-height: 1.25;
  max-width: 100%;
  width: 100%;
  overflow: visible;
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  padding: 0 2px;
  flex: 0 0 auto;
  min-height: 2.5em; /* room for 2 wrapped lines without clip */
}
.garden-slot.locked { opacity: 0.7; }
.panel .close-row {
  flex: 0 0 auto;
  margin-top: 0;
  display: flex;
  justify-content: center;
  padding-top: 10px;
  padding-bottom: 2px;
}
.milestone-bar {
  flex: 0 0 auto;
}



/* ---- V4 garden beds (under bottles) ---- */
.garden-beds {
  flex: 0 0 auto;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 4px 4px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.garden-bed {
  position: relative;
  min-height: 72px;
  padding: 10px 8px 8px;
  border-radius: 14px 14px 10px 10px;
  overflow: visible;
}
.bed-soil {
  position: absolute;
  inset: 28% 2% 0;
  border-radius: 8px 8px 12px 12px;
  background:
    linear-gradient(180deg, #6b4a2e 0%, #4a3220 55%, #3a2818 100%);
  box-shadow:
    inset 0 3px 6px rgba(255, 220, 160, 0.15),
    inset 0 -4px 8px rgba(0, 0, 0, 0.35),
    0 4px 10px rgba(30, 40, 20, 0.28);
}
.bed-soil::before {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  top: -6px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(ellipse, #5c3f28 0%, transparent 70%);
  opacity: 0.85;
}
.bed-leaves {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.bed-leaves::before,
.bed-leaves::after {
  content: "";
  position: absolute;
  bottom: 18%;
  width: 18px;
  height: 28px;
  background: radial-gradient(ellipse at 40% 60%, #4a8f4a 0%, #2d6a3a 70%, transparent 71%);
  border-radius: 60% 40% 50% 50%;
  opacity: 0.7;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}
.bed-leaves::before { left: 2%; transform: rotate(-25deg); }
.bed-leaves::after { right: 2%; transform: rotate(28deg) scaleX(-1); }

.bed-slots {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, auto);
  gap: 2px 4px;
  align-items: end;
  justify-items: center;
  min-height: 64px;
}
.plant-slot {
  position: relative;
  width: 100%;
  max-width: 48px;
  height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  grid-column: calc(var(--col) + 1);
  grid-row: calc(var(--row) + 1);
}
.plant-slot.empty .pot { opacity: 0.55; }
.plant-slot .pot {
  position: relative;
  width: 22px;
  height: 16px;
  z-index: 1;
  flex-shrink: 0;
}
.pot-rim {
  position: absolute;
  left: -2px;
  right: -2px;
  top: 0;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(180deg, #d4a078, #b07850);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  z-index: 2;
}
.pot-body {
  position: absolute;
  left: 0;
  right: 0;
  top: 3px;
  bottom: 0;
  background: linear-gradient(180deg, #c4785a 0%, #8b4a32 100%);
  clip-path: polygon(6% 0, 94% 0, 100% 100%, 0 100%);
  border-radius: 0 0 3px 3px;
}
.pot-shadow {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -3px;
  height: 5px;
  background: radial-gradient(ellipse, rgba(20, 30, 15, 0.35), transparent 70%);
  z-index: 0;
}
.plant-flower {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%) scale(1);
  width: 36px;
  height: 40px;
  object-fit: contain;
  z-index: 3;
  filter: drop-shadow(0 2px 3px rgba(30, 50, 30, 0.28));
  pointer-events: none;
  transform-origin: 50% 100%;
}
.plant-flower.settled {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
.plant-flower.bloom-in {
  animation: plantBloom 0.7s ease-out forwards;
}

.plant-flower.bloom-in.instant {
  animation: none;
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
/* L10 rainbow bloom — larger, centred featured slot */
.plant-slot.featured {
  max-width: 72px;
  height: 72px;
  z-index: 4;
}
.plant-slot.featured .pot {
  width: 32px;
  height: 22px;
}
.plant-slot.featured .plant-flower {
  width: 56px;
  height: 62px;
  bottom: 14px;
  filter: drop-shadow(0 3px 6px rgba(30, 50, 30, 0.32))
          drop-shadow(0 0 10px rgba(255, 200, 120, 0.35));
}
.plant-slot.featured .plant-flower.bloom-in {
  animation: plantBloomFeatured 0.95s ease-out forwards;
}
.plant-slot.featured .plant-flower.bloom-in.instant {
  animation: none;
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
@keyframes plantBloomFeatured {
  0% { opacity: 0; transform: translateX(-50%) scale(0.15) translateY(12px); }
  55% { opacity: 1; transform: translateX(-50%) scale(1.18) translateY(-4px); }
  78% { transform: translateX(-50%) scale(0.96) translateY(1px); }
  100% { opacity: 1; transform: translateX(-50%) scale(1) translateY(0); }
}

@keyframes plantBloom {
  0% { opacity: 0; transform: translateX(-50%) scale(0.2) translateY(8px); }
  60% { opacity: 1; transform: translateX(-50%) scale(1.12) translateY(-2px); }
  100% { opacity: 1; transform: translateX(-50%) scale(1) translateY(0); }
}

/* Bottle soft ground contact */
.bottle {
  filter: drop-shadow(0 6px 8px rgba(40, 50, 30, 0.22));
}
.bottle.selected {
  filter: drop-shadow(0 8px 12px rgba(232, 137, 12, 0.35));
}

@media (prefers-reduced-motion: reduce) {
  .bottle, .seg, .win-panel, .milestone-card, .guide-hand, .bottle-halo {
    transition: none !important;
    animation: none !important;
  }
  .bottle.shake { animation: none; }
  .guide-hand.visible { opacity: 1; }
  .scene.sway .layer-distant,
  .scene.sway .layer-foreground,
  .scene.sway .milestone-prop {
    animation: none !important;
  }
  .win-flower.bloom-in {
    animation: none !important;
    transform: scale(1);
    opacity: 1;
  }
  .plant-flower.bloom-in,
  .plant-slot.featured .plant-flower.bloom-in {
    animation: none !important;
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
  .milestone-bar .bar-fill { transition: none; }
}

/* Compact / short viewports — shrink chrome, keep bottles + text readable.
   Bottle size is primarily set by JS fitBoard(); these are fallbacks. */
@media (max-width: 360px), (max-height: 700px) {
  :root {
    --bottle-w: clamp(48px, 12vw, 72px);
    --bottle-h: clamp(110px, 28svh, 180px);
    --ctrl-h: 48px;
  }
  .app { padding: 2px 6px calc(4px + var(--safe-bottom)); }
  header { padding: 0 4px; }
  header h1 { font-size: 1.0rem; }
  header .tag { font-size: 0.8125rem; }
  .top-bar { padding: 2px 0; gap: 4px; }
  .top-bar button.nav { min-height: 44px; padding: 6px 14px; font-size: 0.78rem; }
  .controls { gap: 4px; padding: 1px 0; }
  .controls button { min-height: 48px; min-width: 48px; }
  .controls button img.icon { width: 20px; height: 20px; }
  .caption { min-height: 1em; padding: 1px 4px; font-size: 0.875rem; }
  .board-wrap { height: auto; max-height: none; overflow: visible; }
  .row-plank { height: 22px; margin-top: -10px; }
  .board {
    row-gap: 6px;
    padding: 2px 2px 0;
    max-width: 100%;
  }
  .layer-corner { opacity: 0.55; width: min(28vw, 120px); height: min(24vw, 100px); }
  .layer-foreground { clip-path: inset(82% 0 0 0); }
  #prop-fountain, #prop-greenhouse { bottom: 8%; opacity: 0.7; }
  .garden-grid { gap: 10px 8px; max-width: 100%; }
  .garden-slot { padding: 8px 4px 6px; min-height: 44px; }
  .garden-slot .flower-art { max-width: 64px; width: 72%; }
  .garden-slot .slot-label { font-size: clamp(0.55rem, 3.1vw, 0.68rem); }
  .garden-slot.featured {
    box-shadow: 0 0 0 2px rgba(155, 93, 229, 0.55), 0 4px 12px rgba(155, 93, 229, 0.18);
  }
  .chapter-badge { font-size: 0.6rem; padding: 3px 8px; top: 4px; right: 4px; }
}

/* CrazyGames short 16:9 iframes — collapse chrome aggressively */
@media (max-height: 520px) and (min-aspect-ratio: 14/10) {
  :root { --ctrl-h: 48px; }
  header h1 { font-size: 0.92rem; line-height: 1.1; }
  header .tag { font-size: 0.8125rem; }
  .top-bar { padding: 0; }
  .top-bar button.nav { min-height: 44px; padding: 4px 12px; }
  .controls { padding: 0; }
  .caption-row:not(.is-idle) { margin: 0; }
  .layer-corner { display: none; }
  .milestone-prop { display: none; }
  .puzzle-haze { opacity: 0.35; height: 60%; }
  .row-plank { height: 16px; margin-top: -8px; }
  .board { row-gap: 4px; padding: 0; }
}

@media (min-width: 401px) {
  .garden-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 720px) {
  .app { max-width: 720px; padding-top: 16px; }
  :root {
    --bottle-w: clamp(64px, 8vw, 110px);
    --bottle-h: clamp(170px, 28svh, 280px);
  }
  .board-wrap { max-height: none; height: auto; }
  .row-plank { height: 40px; margin-top: -16px; }
  .board { padding-bottom: 0; max-width: min(100%, calc(5 * var(--bottle-w) + 4 * 16px + 24px)); }
  .garden-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    max-width: 520px;
    gap: 12px 10px;
  }
  .garden-slot.featured {
    box-shadow: 0 0 0 2px rgba(155, 93, 229, 0.5), 0 6px 16px rgba(155, 93, 229, 0.16);
  }
}


/* Mid portrait phones 375–430 tall */
@media (min-width: 361px) and (max-width: 430px) and (min-height: 667px) {
  :root {
    --bottle-w: clamp(52px, 14vw, 78px);
    --bottle-h: clamp(140px, 26svh, 210px);
  }
  .row-plank { height: 30px; margin-top: -13px; }
}

/* ---- 50-level select + garden scroll ---- */
.level-select-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  max-height: none; /* flex child fills remaining panel height */
  width: 100%;
  padding: 0 2px 8px;
}
.level-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
}
.level-bed-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.75;
  margin-top: 4px;
}
.level-bed-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
.level-bed-grid button {
  appearance: none;
  border: 2px solid rgba(30,58,47,0.15);
  border-radius: 12px;
  padding: 10px 4px;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}
.level-bed-grid button:disabled { opacity: 0.4; cursor: default; }
.level-bed-grid button.done { border-color: #2ec4a0; background: #e8fff8; }
.level-bed-grid button.current { border-color: var(--accent); box-shadow: 0 0 0 2px #ffe0a8; }
.level-bed-grid button.featured-level { border-color: #9b5de5; }
@media (max-width: 360px), (max-height: 700px) {
  .level-select-scroll { /* flex fills panel; no vh cap */ }
  .level-bed-grid button { min-height: 40px; padding: 8px 2px; font-size: 0.85rem; }
  .garden-collection-scroll { padding-bottom: 4px; }
}


/* ---- V5 win bloom frame / sparkles / reward glow ---- */
.win-flower-frame {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
  padding: 14px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255,255,255,0.95), rgba(255,248,230,0.75));
  box-shadow:
    0 0 0 3px rgba(232, 180, 80, 0.55),
    0 0 24px rgba(255, 200, 80, 0.45),
    0 10px 28px rgba(40, 30, 10, 0.2);
}
.win-flower-frame.featured {
  padding: 18px;
  box-shadow:
    0 0 0 4px rgba(180, 100, 255, 0.55),
    0 0 0 8px rgba(255, 180, 80, 0.35),
    0 0 36px rgba(255, 120, 200, 0.5),
    0 12px 32px rgba(40, 20, 60, 0.25);
  background:
    radial-gradient(circle at 50% 35%, #fff, rgba(255, 240, 255, 0.9) 55%, rgba(255, 230, 200, 0.7));
}
.win-flower-frame.milestone {
  animation: milestoneShimmer 2.4s ease-in-out infinite;
}
@keyframes milestoneShimmer {
  0%, 100% { filter: hue-rotate(0deg) saturate(1); }
  50% { filter: hue-rotate(25deg) saturate(1.25); }
}
.win-flower-frame .win-flower {
  margin: 0;
  width: min(160px, 44vw);
  height: min(200px, 48vw);
}
.win-flower-frame.featured .win-flower {
  width: min(200px, 52vw);
  height: min(250px, 58vw);
}
.win-sparkles {
  position: absolute;
  inset: -8%;
  pointer-events: none;
  overflow: visible;
}
.sparkle {
  position: absolute;
  left: var(--sx);
  top: var(--sy);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #ffe08a 40%, transparent 70%);
  box-shadow: 0 0 8px 2px rgba(255, 220, 120, 0.85);
  animation: sparklePop var(--sd, 0.7s) ease-out var(--sdelay, 0s) forwards;
  opacity: 0;
}
@keyframes sparklePop {
  0% { transform: scale(0.2); opacity: 0; }
  35% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.4) translateY(-18px); opacity: 0; }
}

.garden-slot.earned {
  box-shadow: 0 0 0 2px rgba(232, 180, 80, 0.45), 0 4px 14px rgba(40, 80, 40, 0.12);
  background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,248,230,0.9));
}
.garden-slot.earned.featured {
  box-shadow:
    0 0 0 2px rgba(180, 100, 255, 0.55),
    0 0 16px rgba(255, 160, 220, 0.45),
    0 6px 16px rgba(60, 30, 80, 0.15);
  background: linear-gradient(180deg, #fff, rgba(255, 240, 255, 0.95));
}
.garden-slot.earned .flower-art {
  filter: drop-shadow(0 2px 4px rgba(40, 60, 30, 0.25));
}
.plant-slot.featured .plant-flower {
  filter: drop-shadow(0 0 10px rgba(255, 180, 80, 0.75)) drop-shadow(0 0 18px rgba(180, 100, 255, 0.45));
}

@media (prefers-reduced-motion: reduce) {
  .scene.sway .layer-corner-left,
  .scene.sway .layer-corner-right,
  .scene.sway .milestone-prop { animation: none !important; }
  .win-flower-frame.milestone { animation: none !important; }
  .sparkle { animation: none !important; opacity: 0.7; }
}


/* ==== V7 quality pass: pour animation, feedback, contrast ==== */
.board-wrap { isolation: isolate; }
.pour-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  overflow: visible;
}
.pour-clone {
  position: absolute;
  transform-origin: 50% 18%;
  will-change: transform;
  filter:
    drop-shadow(0 0 1.2px rgba(255,255,255,0.95))
    drop-shadow(0 8px 14px rgba(20, 30, 20, 0.45));
  z-index: 22;
}
.pour-clone .bottle-halo { opacity: 1; }
.pour-stream {
  position: absolute;
  z-index: 21;
  width: 10px;
  border-radius: 6px;
  transform-origin: 50% 0%;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(255,255,255,0.45);
}
.pour-splash {
  position: absolute;
  z-index: 23;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -14px;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(255,255,255,0.95) 0%, rgba(255,220,120,0.55) 40%, transparent 70%);
  opacity: 0;
  transform: scale(0.3);
}
.pour-splash.pop {
  animation: splashPop 0.45s ease-out forwards;
}
@keyframes splashPop {
  0% { opacity: 0; transform: scale(0.2); }
  35% { opacity: 1; transform: scale(1.25); }
  100% { opacity: 0; transform: scale(0.6) translateY(-10px); }
}
.bottle.pouring-src { visibility: hidden; }
.bottle.pour-target-glow .bottle-halo { opacity: 0.85; }
.bottle.is-complete {
  filter:
    drop-shadow(0 0 1.2px rgba(255,255,255,0.95))
    drop-shadow(0 0 10px rgba(255, 210, 80, 0.65))
    drop-shadow(0 5px 8px rgba(20, 30, 20, 0.42));
}
.bottle.is-complete .bottle-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 12px rgba(255, 230, 140, 0.45);
  pointer-events: none;
  z-index: 2;
}
.seg.contrast-boost {
  box-shadow: inset 0 0 0 1.5px rgba(20, 40, 30, 0.45);
  filter: contrast(1.12) saturate(1.15);
}
.seg.contrast-boost::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    transparent 0 3px,
    rgba(0,0,0,0.08) 3px 4px
  );
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: 0.55;
}
.seg[data-colour="emerald"].contrast-boost {
  background-color: #0f8f6e !important;
}
.seg[data-colour="topaz"].contrast-boost {
  background-color: #d97706 !important;
}
.guide-hand {
  width: 36px;
  height: 36px;
}
.guide-hand.guide-arrow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -10px;
  width: 0;
  height: 0;
  margin-left: -8px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 12px solid #ffb703;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}
.app.compact-chrome header h1 { font-size: 0.95rem; }
.app.compact-chrome .layer-corner { opacity: 0.4; }

@media (prefers-reduced-motion: reduce) {
  .pour-clone, .pour-stream, .pour-splash { transition: none !important; animation: none !important; }
  .pour-splash.pop { opacity: 0.7; transform: none; }
}


.app.chapter-3 .bottle-glass { filter: sepia(0.18) saturate(1.12) brightness(1.03); }
.app.chapter-4 .bottle-glass { filter: hue-rotate(12deg) saturate(1.1); }
.app.chapter-5 .bottle-glass { filter: hue-rotate(-20deg) saturate(0.92) brightness(0.95); }
.app.chapter-3 .row-plank img { filter: drop-shadow(0 3px 8px rgba(40,30,10,0.4)) sepia(0.25) saturate(1.1); }
.app.chapter-4 .row-plank img { filter: drop-shadow(0 3px 8px rgba(40,30,10,0.45)) hue-rotate(10deg); }
.app.chapter-5 .row-plank img { filter: drop-shadow(0 3px 8px rgba(10,20,40,0.55)) brightness(0.9); }


/* Ultra-short landscape (e.g. iPhone 844×390): keep bottles clear of toolbar */
@media (max-height: 400px) and (orientation: landscape) {
  .app.compact-chrome header { padding-top: 2px; padding-bottom: 0; }
  .app.compact-chrome .top-bar { padding: 0; gap: 4px; }
  .app.compact-chrome .controls { padding: 0; gap: 4px; margin: 0; }
  .app.compact-chrome .controls button { min-height: 44px; min-width: 44px; }
  .app.compact-chrome .board-wrap { padding-top: 4px; overflow: hidden; }
  .app.compact-chrome .chapter-badge { display: none; }
  .app.compact-chrome .caption-row.is-idle { display: none; }
}
.board-wrap { overflow: hidden; }
