/* =========================================================================
   TERRA BLOOM — style.css
   Organic nature look: deep forest night, sunlight & blossom accents,
   soft rounded shapes, bundled rounded fonts. No neon, no flicker.
   (Legacy class names --cyan/--magenta/... were remapped to the nature
   palette: --leaf/--blossom/--honey/--mint/--berry — same roles.)
   ========================================================================= */

/* ---- Bundled rounded fonts (offline — no CDN, works from file://) ------ */
@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka-var.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("fonts/nunito-var.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  --leaf:    #90e06c;   /* fresh leaf green — main accent            */
  --blossom: #ff9fc4;   /* soft petal pink — secondary accent        */
  --honey:   #ffd24d;   /* sunlight — primary actions / highlights   */
  --mint:    #6ef0a8;   /* new sprout green — success / level info   */
  --berry:   #ff6157;   /* ripe berry — danger                       */
  --bark:    #5d4430;   /* warm wood brown — borders / depth         */
  --cream:   #f4edda;   /* parchment text                            */
  --bg:      #08130c;   /* deep forest night                         */
  --panel:   rgba(11, 26, 16, 0.94);
  --panel-line: rgba(144, 224, 108, 0.34);
  --font-disp: "Fredoka", "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  --font-body: "Nunito", "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--cream);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* Forest-night backdrop: moonlight through the canopy */
body {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(160, 220, 120, 0.10), transparent 55%),
    radial-gradient(ellipse at 12% 100%, rgba(110, 240, 168, 0.05), transparent 50%),
    radial-gradient(ellipse at 88% 92%, rgba(255, 210, 77, 0.05), transparent 50%),
    var(--bg);
}

/* Soft canopy vignette (replaces the old CRT scanlines) */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 50% 42%,
    transparent 52%,
    rgba(2, 8, 4, 0.55) 100%
  );
  z-index: 50;
}

#stage {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* landscape playfield (850x478) + HUD + bar + footer must fit vertically */
  width: min(96vw, calc((100vh - 150px) * 850 / 478));
}

/* ============================ HUD ============================ */

#hud {
  display: flex;
  align-items: stretch;
  gap: 6px;
  flex-wrap: wrap;
}

.hud-box {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 6px 13px;
  border: 1px solid rgba(144, 224, 108, 0.22);
  border-radius: 999px;
  background: rgba(12, 28, 17, 0.72);
  white-space: nowrap;
}

.hud-box.grow { flex: 1; }

.hud-label {
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1.5px;
  color: rgba(214, 236, 200, 0.72);
}
.hud-label.dim { opacity: 0.55; }

.hud-value {
  font-family: var(--font-disp);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.hud-value.cyan    { color: var(--leaf); }
.hud-value.magenta { color: var(--blossom); }
.hud-value.yellow  { color: var(--honey); }
.hud-value.green   { color: var(--mint); font-size: 12px; letter-spacing: 1px; }

.heart {
  color: var(--blossom);
  text-shadow: 0 1px 6px rgba(255, 159, 196, 0.45);
  font-size: 14px;
  margin-right: 2px;
}
.heart.lost {
  color: rgba(255, 159, 196, 0.25);
  text-shadow: none;
}

.hud-btn {
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1.5px;
  color: rgba(214, 236, 200, 0.85);
  background: rgba(12, 28, 17, 0.72);
  border: 1px solid rgba(144, 224, 108, 0.22);
  border-radius: 999px;
  padding: 0 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.hud-btn:hover { color: #10240f; background: var(--leaf); border-color: var(--leaf); }

/* capture progress bar — a growing vine */
#barTrack {
  height: 7px;
  border: none;
  border-radius: 999px;
  background: rgba(12, 28, 17, 0.85);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
#barFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4c9e46, var(--leaf) 55%, var(--honey));
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(144, 224, 108, 0.45);
  transition: width 0.25s ease-out;
}

/* ======================== PLAYFIELD ========================== */

#playfieldWrap {
  position: relative;
  width: 100%;
  aspect-ratio: 850 / 478;
  border: 2px solid rgba(93, 68, 48, 0.9);   /* warm wood frame */
  outline: 1px solid rgba(144, 224, 108, 0.28);
  border-radius: 14px;
  box-shadow:
    0 10px 34px rgba(0, 0, 0, 0.55),
    0 0 22px rgba(144, 224, 108, 0.12),
    inset 0 0 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  background: #000;
  touch-action: none; /* the canvas owns every gesture while playing */
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

/* ========================= BANNER ============================ */

#banner {
  position: absolute;
  top: 34%;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}
#banner.show { animation: bannerPop 2.2s ease-out forwards; }

#banner .b-title {
  font-family: var(--font-disp);
  font-size: clamp(28px, 6vw, 54px);
  font-weight: 600;
  letter-spacing: 4px;
  color: #fffdf2;
  text-shadow:
    0 2px 0 rgba(63, 42, 24, 0.85),
    0 4px 18px rgba(0, 0, 0, 0.6),
    0 0 26px rgba(144, 224, 108, 0.5);
}
#banner .b-sub {
  margin-top: 8px;
  font-family: var(--font-disp);
  font-size: clamp(11px, 2vw, 16px);
  font-weight: 500;
  letter-spacing: 3px;
  color: var(--honey);
  text-shadow: 0 1px 0 rgba(63, 42, 24, 0.8), 0 0 14px rgba(255, 210, 77, 0.45);
}

@keyframes bannerPop {
  0%   { opacity: 0; transform: scale(0.85); }
  12%  { opacity: 1; transform: scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1.04); }
}

/* ========================= SCREENS =========================== */

#screens { position: absolute; inset: 0; z-index: 10; }
/* no screen visible (playing): the empty overlay must never eat touches
   aimed at the board — real hit-testing lands here otherwise */
#screens.off { pointer-events: none; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* no backdrop-filter here: a full-playfield live blur re-renders EVERY
     frame while the canvas beneath repaints — measured as the single
     biggest idle-state CPU sink (menus burned ~2.5x the CPU of gameplay).
     A slightly deeper tint reads the same. */
  background:
    radial-gradient(ellipse at 50% 30%, rgba(22, 48, 26, 0.55), rgba(3, 9, 5, 0.88) 75%);
}
.screen.hidden { display: none; }

/* decorative floating leaves on the start screen (desktop only — the
   float animation is transform-only, 3 elements, and disabled on touch
   devices to keep phone CPUs idle) */
.screen .deco {
  position: absolute;
  width: 34px;
  height: 34px;
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}
.screen .deco svg { width: 100%; height: 100%; }
.screen .deco.d1 { top: 12%; left: 10%; animation: leafDrift 9s ease-in-out infinite; }
.screen .deco.d2 { top: 20%; right: 12%; animation: leafDrift 11s ease-in-out infinite reverse; }
.screen .deco.d3 { bottom: 14%; left: 16%; width: 26px; height: 26px; animation: leafDrift 13s ease-in-out infinite 2s; }
.screen .deco.d4 { bottom: 20%; right: 15%; width: 28px; height: 28px; animation: leafDrift 10s ease-in-out infinite reverse 1s; }
body.touch .screen .deco { display: none; }

@keyframes leafDrift {
  0%, 100% { transform: translate(0, 0) rotate(-8deg); }
  50%      { transform: translate(10px, -14px) rotate(10deg); }
}

.panel {
  position: relative;
  width: min(86%, 480px);
  max-height: 92%;
  overflow: auto;
  padding: 30px 30px 26px;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(144, 224, 108, 0.07), transparent 60%),
    var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 26px;
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.5),
    0 0 30px rgba(144, 224, 108, 0.10),
    inset 0 1px 0 rgba(244, 237, 218, 0.07);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

/* a little sun-and-leaf crest above the title (a flex item, so it never
   gets clipped by the panel's overflow:auto) */
.panel::before {
  content: "";
  flex: 0 0 auto;
  order: -3;              /* always the first item, even when phone rules hoist buttons */
  width: 30px;
  height: 30px;
  margin-top: -4px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 34 34'%3E%3Ccircle cx='17' cy='17' r='10' fill='%23ffd24d'/%3E%3Cpath d='M17 3 C 20 8 20 12 17 15 C 14 12 14 8 17 3 Z' fill='%234c9e46'/%3E%3Cpath d='M17 31 C 14 26 14 22 17 19 C 20 22 20 26 17 31 Z' fill='%234c9e46'/%3E%3C/svg%3E") no-repeat center / contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
  pointer-events: none;
}

.title {
  font-family: var(--font-disp);
  font-size: clamp(38px, 9vw, 62px);
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--cream);
  line-height: 1.04;
  text-shadow:
    0 3px 0 rgba(63, 42, 24, 0.9),
    0 6px 20px rgba(0, 0, 0, 0.55);
}
.title span {
  color: var(--leaf);
  text-shadow:
    0 3px 0 rgba(30, 62, 22, 0.95),
    0 6px 22px rgba(144, 224, 108, 0.35);
}
/* gentle "growing" breathe instead of the old neon flicker */
.title { animation: sway 4.5s ease-in-out infinite; }
@keyframes sway {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50%      { transform: scale(1.015) rotate(-0.4deg); }
}

.subtitle {
  font-family: var(--font-disp);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 2.5px;
  color: var(--blossom);
  opacity: 0.95;
}
.subtitle.big { font-size: 27px; letter-spacing: 2px; font-weight: 600; }
.subtitle.green { color: var(--mint); }
.subtitle.red { color: var(--berry); }
.subtitle.yellow { color: var(--honey); }

.howto {
  text-align: left;
  font-size: 12.5px;
  line-height: 1.8;
  color: rgba(244, 237, 218, 0.88);
  border: 1px solid rgba(144, 224, 108, 0.18);
  background: rgba(8, 20, 12, 0.55);
  border-radius: 14px;
  padding: 12px 15px;
}
.howto b { letter-spacing: 0.5px; }
.cyan { color: var(--leaf); }
.magenta { color: var(--blossom); }
.red { color: var(--berry); }
.yellow { color: var(--honey); }
.green { color: var(--mint); }

/* ========================= BUTTONS =========================== */
/* pill "seed" buttons: filled sun for primary, moss outline for rest */

.btn {
  font-family: var(--font-disp);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--cream);
  background: rgba(24, 52, 30, 0.85);
  border: 1px solid rgba(144, 224, 108, 0.4);
  border-radius: 999px;
  padding: 11px 24px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(244, 237, 218, 0.08);
  transition: transform 0.12s ease-out, background 0.15s, box-shadow 0.15s, border-color 0.15s;
  width: 100%;
  max-width: 320px;
}
.btn:hover, .btn:focus-visible {
  background: rgba(38, 78, 44, 0.95);
  border-color: var(--leaf);
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(144, 224, 108, 0.28), inset 0 1px 0 rgba(244, 237, 218, 0.1);
  outline: none;
}
.btn:active { transform: translateY(1px); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }

.btn.primary {
  background: linear-gradient(180deg, #ffe27a, var(--honey) 55%, #f0b62e);
  border-color: #ffdf7e;
  color: #3a2a08;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 0 #a67c14, 0 6px 18px rgba(255, 210, 77, 0.3);
}
.btn.primary:hover, .btn.primary:focus-visible {
  background: linear-gradient(180deg, #ffea96, var(--honey) 55%, #f0b62e);
  transform: translateY(-1px);
  box-shadow: 0 6px 0 #a67c14, 0 10px 24px rgba(255, 210, 77, 0.4);
}
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #a67c14; }

.stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0;
}
.stat {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  letter-spacing: 1px;
  padding: 7px 14px;
  border-bottom: 1px solid rgba(144, 224, 108, 0.14);
}
.stat span:last-child { font-family: var(--font-disp); font-weight: 600; color: var(--leaf); }
.stat span.yellow { color: var(--honey) !important; }
.stat span.magenta { color: var(--blossom) !important; }

/* fully revealed picture on the level-clear / victory screens */
#clearImageWrap, #winImageWrap {
  width: 100%;
  padding: 7px;
  border: 1px solid rgba(144, 224, 108, 0.3);
  border-radius: 16px;
  background: rgba(8, 20, 12, 0.6);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.45);
}
#clearImageWrap.noimg, #winImageWrap.noimg { display: none; }
#clearImage, #winImage {
  display: block;
  width: 100%;
  height: min(26vh, 210px);
  object-fit: contain;
  border-radius: 11px;
  background: #000;
}
#clearImageCaption, #winImageCaption {
  margin-top: 7px;
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 2px;
  color: var(--leaf);
  text-transform: uppercase;
}

/* NEW RECORD badge on the victory screen */
.record {
  font-family: var(--font-disp);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--honey);
  border: 1px solid rgba(255, 210, 77, 0.55);
  border-radius: 999px;
  padding: 6px 16px;
  background: rgba(58, 42, 8, 0.35);
  animation: recordPulse 1.1s ease-in-out infinite;
}
@keyframes recordPulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 8px rgba(255, 210, 77, 0.2); }
  50%      { transform: scale(1.06); box-shadow: 0 0 18px rgba(255, 210, 77, 0.4); }
}

.small { font-size: 11.5px; letter-spacing: 0.8px; }
.dim { color: rgba(214, 236, 200, 0.55); }

/* ========================= FOOTER ============================ */

#hint {
  text-align: center;
  font-size: 11px;
  letter-spacing: 1px;
  color: rgba(214, 236, 200, 0.5);
}

/* =========================================================================
   SMALL-SCREEN / MOBILE LAYOUT
   Fires on narrow screens (portrait phones) AND short screens (landscape
   phones — an 844x390 viewport never matched the old width-only query, so
   it rendered the desktop stage rule and wasted half the screen). The
   board owns the display: HUD becomes one compact strip, the capture bar
   shrinks, the footer is dropped, and overlay panels (start/pause/clear…)
   escape the tiny board and cover the whole viewport.
   ========================================================================= */
@media (max-width: 640px), (max-height: 500px) {

  /* board fills the viewport: only the fixed HUD strip + progress bar +
     playfield border are reserved (~42px) */
  #stage {
    width: min(97vw, calc((100vh - 42px) * 850 / 478));
    gap: 4px;
    margin-top: 26px;   /* clears the fixed HUD strip (body re-centers) */
  }
  @supports (height: 100dvh) {
    #stage { width: min(97vw, calc((100dvh - 42px) * 850 / 478)); }
  }

  #hint { display: none; }

  /* --- HUD becomes a fixed screen-top strip (like a status bar) ----------
     It must NOT be board-anchored: in portrait the board is a small
     centered band and the overlay panels cover the viewport — an in-flow
     strip would float mid-screen on top of panel text. Fixed at the top
     edge it stays out of the way, always tappable (z > screens' dim). */
  #hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
    max-width: 720px;
    z-index: 30;
    justify-content: center;
    padding: 3px 4px;
    gap: 2px;
  }
  .hud-box {
    padding: 3px 6px;
    gap: 3px;
    border-radius: 999px;
    background: rgba(12, 28, 17, 0.6);
    box-shadow: none;
  }
  /* high score lives on the title + game-over panels: the strip needs the
     width for gameplay stats on a 600px landscape board */
  #hud .hud-top { display: none !important; }
  .hud-label { font-size: 8px; letter-spacing: 0.5px; }
  .hud-label.dim { display: none; }       /* "/ TARGET" wastes width */
  .hud-value { font-size: 10px; }
  .hud-value.green { font-size: 10px; letter-spacing: 1px; }
  .heart { font-size: 12px; }
  .hud-btn { font-size: 9px; letter-spacing: 1px; padding: 6px 8px; }
  /* JS-embedded HUD buttons (MORE GAMES / MUSIC) carry inline styles —
     !important CSS beats inline, so they shrink to match the strip */
  #hud > button {
    font-size: 9px !important;
    letter-spacing: 1px !important;
    padding: 6px 8px !important;
  }
  /* music toggle is the least critical chip: hide it on phones (sound
     toggle stays; music also lives in the pause menu + N key) */
  #hud .hud-music { display: none !important; }

  #barTrack { height: 4px; }
  #playfieldWrap {
    border-width: 1px;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  }

  /* overlay screens cover the whole phone viewport instead of a 200px-tall
     letterboxed board */
  .screen { position: fixed; z-index: 40; }
  /* the rotation nudge is gameplay chrome — park it under the screens' dim
     so it never paints over panel text while an overlay is open.
     (#playfieldWrap prefix beats the LATER base rule's equal specificity) */
  #playfieldWrap #rotateHint { z-index: 5; }
  .panel {
    width: min(92%, 480px);
    max-height: 90%;
    padding: 22px 18px 18px;
    gap: 10px;
    border-radius: 20px;
  }
  .howto { font-size: 11px; line-height: 1.6; padding: 10px 12px; }
  .btn { padding: 12px 18px; font-size: 13px; }
  .subtitle.big { font-size: 20px; letter-spacing: 1.5px; }
}

/* ultra-short landscape (e.g. iPhone SE, 568x320): drop the portal chip too */
@media (max-height: 350px) and (max-width: 700px) {
  #hud .hud-more { display: none !important; }
  #hud > button { font-size: 8px !important; padding: 5px 6px !important; }
  .hud-btn { font-size: 8px; padding: 5px 6px; }
  .heart { font-size: 11px; }
}

/* ========================== MOBILE / TOUCH ========================== */

/* cheaper page chrome: the full-screen vignette overlay + radial gradients
   are two extra composited layers phones repaint every frame — drop them. */
body.touch::after { display: none; }
body.touch {
  background: var(--bg);
}

/* virtual joystick — docked at the bottom-left of the board while idle
   (always visible on touch devices so the controls are discoverable),
   jumps under the finger while steering */
#joyBase {
  position: fixed;
  width: 116px;
  height: 116px;
  margin: -58px 0 0 -58px;
  border-radius: 50%;
  border: 2px solid rgba(144, 224, 108, 0.45);
  background: rgba(12, 28, 17, 0.35);
  box-shadow: 0 0 18px rgba(144, 224, 108, 0.25), inset 0 0 22px rgba(144, 224, 108, 0.1);
  pointer-events: none;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.12s;
}
#joyBase.on { opacity: 1; }
#joyBase.rest {
  opacity: 0.55;
  border-color: rgba(144, 224, 108, 0.32);
  box-shadow: 0 0 12px rgba(144, 224, 108, 0.16), inset 0 0 16px rgba(144, 224, 108, 0.07);
}
#joyBase.rest #joyKnob { background: rgba(144, 224, 108, 0.16); }
#joyKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(144, 224, 108, 0.3);
  border: 2px solid var(--leaf);
  box-shadow: 0 0 16px rgba(144, 224, 108, 0.45);
  transform: translate(-50%, -50%);
}

/* one-time "how to steer" nudge floating above the docked pad */
#joyHint {
  position: fixed;
  transform: translate(-50%, 0);
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  white-space: nowrap;
  color: var(--leaf);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.35s;
  animation: joyPulse 1.4s ease-in-out infinite;
}
#joyHint.show { opacity: 0.9; }
@keyframes joyPulse {
  0%, 100% { opacity: 0.65; }
  50%      { opacity: 0.95; }
}

/* portrait nudge — non-blocking strip over the playfield (pointer-events: none) */
#rotateHint {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 55;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border: 1px solid rgba(255, 210, 77, 0.45);
  border-radius: 999px;
  background: rgba(12, 28, 17, 0.88);
  color: var(--honey);
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1.5px;
  pointer-events: none;
  white-space: nowrap;
}
#rotateHint.show { display: flex; }
.rh-icon {
  width: 14px;
  height: 9px;
  border: 2px solid var(--honey);
  border-radius: 2px;
  transform: rotate(90deg);
  animation: rh-spin 1.6s ease-in-out infinite;
}
@keyframes rh-spin {
  0%, 100% { transform: rotate(90deg); }
  55% { transform: rotate(0deg); }
}

/* =========================================================================
   TASK 15 — two-phase level clear chip
   Non-blocking "TAP / CLICK TO CONTINUE" over the fully revealed picture.
   z:6 sits above the canvas + banner but UNDER any .screen overlay dim.
   ========================================================================= */
#clearTap {
  position: absolute;
  left: 50%;
  bottom: 9%;
  transform: translateX(-50%);
  z-index: 6;
  display: none;
  padding: 10px 20px;
  border: 1px solid rgba(255, 210, 77, 0.5);
  border-radius: 999px;
  background: rgba(12, 28, 17, 0.88);
  color: var(--honey);
  font-family: var(--font-disp);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  white-space: nowrap;
  animation: tapPulse 1.3s ease-in-out infinite;
}
#clearTap.show { display: block; }
@keyframes tapPulse {
  0%, 100% { transform: translateX(-50%) scale(1);    opacity: 0.9; }
  50%      { transform: translateX(-50%) scale(1.05); opacity: 1; }
}

/* collapsible HOW TO PLAY section (start panel) */
#howtoBox.hidden { display: none; }
/* .open MUST come after .hidden — same specificity, so the later rule wins.
 * Without this the box stays display:none and the button looks dead. */
#howtoBox.open { display: block; animation: howtoIn 0.28s ease both; }
/* opacity-only: a translateY here shifts the rect that scrollIntoView
 * measures, leaving the box a few px short of fully visible */
@keyframes howtoIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.howto-btn { max-width: 320px; }

/* =========================================================================
   14-e — TOUCH CONTROL PICKER (joystick vs arrows, left vs right)
   Hidden on desktop; a compact settings card on touch devices.
   ========================================================================= */
.ctl-settings { display: none; }
body.touch .ctl-settings {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  width: 100%;
  max-width: 340px;
  padding: 10px 12px;
  border: 1px solid rgba(144, 224, 108, 0.18);
  border-radius: 14px;
  background: rgba(8, 20, 12, 0.5);
}
.ctl-cap {
  font-family: var(--font-disp);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--leaf);
}
.ctl-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.ctl-sep { width: 1px; height: 20px; background: rgba(144, 224, 108, 0.3); }
.ctl-opt {
  font-family: var(--font-disp);
  font-size: 10px;
  letter-spacing: 1px;
  font-weight: 500;
  color: rgba(214, 236, 200, 0.85);
  background: rgba(8, 20, 12, 0.6);
  border: 1px solid rgba(144, 224, 108, 0.3);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  min-width: 44px;
  min-height: 30px;
}
.ctl-opt.on {
  color: #10240f;
  background: var(--leaf);
  border-color: var(--leaf);
  box-shadow: 0 2px 10px rgba(144, 224, 108, 0.4);
}
.ctl-note { font-size: 9px; letter-spacing: 0.5px; color: rgba(214, 236, 200, 0.5); }

/* =========================================================================
   14-e — ARROW PAD (d-pad)
   A 3x3 grid of four hold-to-move buttons; positioned by JS in the free
   side band (landscape) or near the bottom on the chosen side (portrait).
   ========================================================================= */
#dpad {
  position: fixed;
  transform: translate(-50%, -50%);
  display: none;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
  z-index: 60;
  touch-action: none;
}
#dpad.small {
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
}
.dbtn {
  appearance: none;
  font-family: var(--font-disp);
  border: 2px solid rgba(144, 224, 108, 0.45);
  border-radius: 16px;
  background: rgba(12, 28, 17, 0.55);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(244, 237, 218, 0.06);
  color: var(--leaf);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
#dpad.small .dbtn { font-size: 15px; }
.dbtn span { pointer-events: none; }
.dbtn.press {
  background: var(--leaf);
  color: #10240f;
  box-shadow: 0 0 18px rgba(144, 224, 108, 0.5);
}
.d-up    { grid-column: 2; grid-row: 1; }
.d-left  { grid-column: 1; grid-row: 2; }
.d-right { grid-column: 3; grid-row: 2; }
.d-down  { grid-column: 2; grid-row: 3; }
.d-dot   {
  grid-column: 2; grid-row: 2;
  align-self: center; justify-self: center;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: rgba(144, 224, 108, 0.4);
}

/* 14-e — joystick band mode: a slightly smaller pad centered in the freed
   side band instead of docked at the board corner */
#joyBase.band {
  width: 92px;
  height: 92px;
  margin: -46px 0 0 -46px;
}
#joyBase.band #joyKnob { width: 38px; height: 38px; }

/* =========================================================================
   14-e — LANDSCAPE BOARD SHIFT
   With a pad parked on one side, the board slides to the opposite edge so
   the pad owns the freed band (the user's reference layout: pad left,
   board right). Only fires on short/landscape screens where a band exists.
   ========================================================================= */
@media (orientation: landscape) and (max-height: 500px) {
  body.touch.side-left #stage {
    margin-left: auto;
    margin-right: 4px;
  }
  body.touch.side-right #stage {
    margin-right: auto;
    margin-left: 4px;
  }
  /* arrows mode additionally guarantees its band width; joystick mode
     reuses whatever space the shift frees up naturally */
  body.touch.ctl-arrows.side-left #stage {
    width: min(calc(100vw - 196px), calc((100vh - 42px) * 850 / 478));
  }
  body.touch.ctl-arrows.side-right #stage {
    width: min(calc(100vw - 196px), calc((100vh - 42px) * 850 / 478));
  }
  @supports (height: 100dvh) {
    body.touch.ctl-arrows.side-left #stage,
    body.touch.ctl-arrows.side-right #stage {
      width: min(calc(100vw - 196px), calc((100dvh - 42px) * 850 / 478));
    }
  }
}

/* =========================================================================
   TASK 15 — PHONE PANEL ORDERING + SHORT-SCREEN COMPACTION
   Primary actions lead every panel so nothing important sits below the
   fold; long content (howto, pickers) is compacted so overlays fit without
   scrolling on 844x390 landscape phones.
   ========================================================================= */
@media (max-width: 640px), (max-height: 500px) {
  /* hoist the title + tagline + primary buttons above the collapsible help */
  #startScreen .panel .title       { order: -2; }
  #startScreen .panel .subtitle    { order: -2; }
  #startScreen .panel .btn.primary,
  #startScreen .panel .btn         { order: -1; }
  #pauseScreen .panel .subtitle    { order: -2; }
  #pauseScreen .panel .btn.primary,
  #pauseScreen .panel .btn         { order: -1; }

  /* short screens: tighten everything so the panel fits without scrolling */
  .panel { gap: 7px; padding: 14px 16px 12px; }
  .panel::before { display: none; }   /* crest is a luxury short phones can't afford */
  .title { font-size: clamp(30px, 8vw, 44px); letter-spacing: 2px; }
  .subtitle { font-size: 9px; letter-spacing: 2px; }
  .subtitle.big { font-size: 17px; letter-spacing: 1.5px; }
  .btn { padding: 10px 14px; font-size: 12px; max-width: 300px; }
  #howtoBox.open .howto { font-size: 10px; line-height: 1.5; padding: 8px 10px; max-height: 34vh; overflow: auto; }
  .ctl-settings { padding: 8px 10px; gap: 5px; }
  .ctl-note { display: none; }
  .ctl-opt { padding: 7px 9px; min-height: 0; }
  .small { font-size: 9px; letter-spacing: 0.5px; }
}
