/* ========================================
   Habitat Heroes Helpful Heroes Coloring Book — styles.css
   Mobile-first, cross-platform compatible
   ======================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  /* Prevent blue flash on tap (iOS & Android Chrome) */
  -webkit-tap-highlight-color: transparent;
}

:root {
  --brand-green:  #2e7d32;
  --brand-yellow: #f9a825;
  --border-radius: 12px;
  /* Minimum tap target size (Apple HIG & Material Design both recommend 44px) */
  --tap-min: 44px;
}

html {
  /* Prevent rubber-band scroll from interfering with drawing on iOS */
  overscroll-behavior: none;
  /* Fill iPhone notch area with body background */
  background: #f0f4f8;
  /*
    Prevent horizontal scroll at the html level.
    Setting overflow-x: hidden only on body is not enough — some browsers
    promote scrolling to the html element, allowing horizontal drift even
    when body: overflow-x: hidden is set.
  */
  overflow-x: hidden;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #f0f4f8;
  color: #222;
  overflow-x: hidden;
  /* Prevent iOS momentum scroll from stealing touches away from the canvas */
  overscroll-behavior: none;
  /* Safe-area padding for notched iPhones (Dynamic Island, home-bar) */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---- Header ---- */
header {
  background: var(--brand-green);
  color: #fff;
  text-align: center;
  /* Extra top padding for Dynamic Island / status bar on iOS */
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

header h1 {
  font-size: clamp(1.3rem, 5vw, 2rem);
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 1px 2px 4px rgba(0,0,0,0.3);
}

header .subtitle {
  font-size: clamp(0.75rem, 3vw, 1rem);
  color: var(--brand-yellow);
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ---- Message Banner ---- */
#page-message-banner {
  background: var(--brand-yellow);
  text-align: center;
  padding: 7px 16px;
}

#page-message {
  font-size: clamp(0.8rem, 3vw, 1.1rem);
  font-weight: 700;
  color: #222;
  font-style: italic;
}

/* ---- Page Navigation (Prev / Counter / Next) ---- */
#page-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 7px 10px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.nav-arrow-btn {
  min-height: 50px;
  padding: 0 24px;
  border: 3px solid var(--brand-green);
  border-radius: 26px;
  background: #fff;
  color: var(--brand-green);
  font-size: clamp(1rem, 3.5vw, 1.15rem);
  font-weight: 900;
  cursor: pointer;
  letter-spacing: 0.5px;
  /* Eliminates 300ms click delay on iOS/Android */
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.nav-arrow-btn:hover,
.nav-arrow-btn:active {
  background: var(--brand-green);
  color: #fff;
}

.nav-arrow-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#page-counter {
  font-size: clamp(0.8rem, 3vw, 0.95rem);
  font-weight: 700;
  color: #444;
  min-width: 100px;
  text-align: center;
  white-space: nowrap;
}

/* ---- Canvas Wrapper ---- */
#canvas-wrapper {
  position: relative;
  width: calc(100% - 16px);      /* 8px breathing room each side */
  max-width: 700px;
  margin: 8px auto;
  background: #fff;
  border: 3px solid #ccc;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  /*
    Prevent ALL browser touch handling on this element so pointer events
    fire reliably on both Chrome/Android and Safari/iOS.
  */
  touch-action: none;
  /* Prevent text/image selection during drag on iOS */
  -webkit-user-select: none;
  user-select: none;
}

/*
  Aspect-ratio 4:3 fallback for iOS 14 and older Android WebViews.
  The ::before pseudo-element holds the height via padding-top.
  Modern browsers override it via @supports.
*/
#canvas-wrapper::before {
  content: '';
  display: block;
  padding-top: 75%; /* 3/4 = 75% → enforces 4:3 ratio */
}

@supports (aspect-ratio: 4 / 3) {
  #canvas-wrapper {
    aspect-ratio: 4 / 3;
  }
  #canvas-wrapper::before {
    display: none;
  }
}

/* Page image — fills the wrapper, bottom-most layer */
#scene-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  touch-action: none;
  display: block;
}

/* SVG overlay — sits above image, used only for question banner */
#scene-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

/* Drawing canvas — sits over SVG, transparent background */
#coloring-canvas {
  position: absolute;
  inset: 0;
  /* CSS display size = 100% of wrapper; actual pixel resolution set by JS × dpr */
  width: 100%;
  height: 100%;
  cursor: crosshair;
  background: transparent;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  /*
    Semi-transparent coloring effect: the canvas itself renders at 60% opacity
    so painted pixels appear at 60% opacity and the line-art PNG shows through.
    Using CSS opacity (not ctx.globalAlpha) means painting over the same area
    multiple times never darkens past 60% — the pixel data stays fully opaque,
    only the element-level composite step reduces it. The eraser (destination-out)
    removes pixels normally; those transparent holes reveal the PNG at 100%.
  */
  opacity: 0.6;
}

/* Hero images — sit on top of everything, no touch interception */
#hero-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  touch-action: none;
}

.hero-img {
  position: absolute;
  bottom: 0;
  height: 55%;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.25));
  /* Prevent long-press "Save Image" sheet on iOS */
  -webkit-user-drag: none;
  pointer-events: none;
}

/* ---- Toolbar ---- */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border-top: 2px solid #e0e0e0;
  max-width: 700px;
  margin: 0 auto;
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  /* Safe-area left/right for landscape iPhones */
  padding-left:  max(10px, env(safe-area-inset-left,  0px));
  padding-right: max(10px, env(safe-area-inset-right, 0px));
}

.tool-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tool-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #999;
  letter-spacing: 0.5px;
}

/* ── Color palette ── */
#color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  max-width: 230px;
}

.color-swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.22);
  transition: transform 0.12s, border-color 0.12s;
}

.color-swatch:active   { transform: scale(1.18); }
.color-swatch.active   { border-color: #222 !important; transform: scale(1.2); }

/* ── Brush size buttons ── */
#brush-sizes {
  display: flex;
  gap: 6px;
}

.brush-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: 50%;
  border: 2px solid #bbb;
  background: #f5f5f5;
  font-weight: 900;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.brush-btn:active,
.brush-btn.active {
  background: var(--brand-green);
  color: #fff;
  border-color: var(--brand-green);
}

/* ── Tool mode buttons (Brush / Fill) ── */
#tool-btns {
  display: flex;
  gap: 6px;
}

.tool-mode-btn {
  min-width: var(--tap-min);
  height: var(--tap-min);
  border-radius: 10px;
  border: 2px solid #bbb;
  background: #f5f5f5;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  padding: 0 10px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.tool-mode-btn:active,
.tool-mode-btn.active {
  background: var(--brand-green);
  color: #fff;
  border-color: var(--brand-green);
}

#canvas-wrapper.fill-mode #coloring-canvas {
  cursor: cell;
}

/* ── Eraser button ── */
#eraser-btn {
  width: 52px;
  height: var(--tap-min);
  border-radius: 10px;
  border: 2px solid #bbb;
  background: #f5f5f5;
  font-size: 1.4rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.12s, border-color 0.12s;
}

#eraser-btn:active,
#eraser-btn.active {
  background: #ddd;
  border-color: #666;
}

/* ── Clear / Reset button ── */
#clear-btn {
  min-height: var(--tap-min);
  padding: 0 18px;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.15s;
}

#clear-btn:active { background: #c0392b; }

/* ---- Reward Star Zone ---- */
#reward-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 5px 16px;
  background: #fffde7;
  border-top: 2px solid var(--brand-yellow);
  border-bottom: 2px solid var(--brand-yellow);
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}

.reward-star-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
  line-height: 0;
  transition: transform 0.15s;
}

.reward-star-btn:active { transform: scale(1.25); }

#reward-star-poly {
  transition: fill 0.35s, stroke 0.35s;
}

.reward-star-btn.starred #reward-star-poly {
  fill: #f9a825;
  stroke: #e67e22;
}

#reward-text-area {
  line-height: 1.5;
}

#reward-question-text {
  font-size: clamp(0.82rem, 3vw, 0.95rem);
  font-weight: 800;
  color: #333;
}

#reward-tap-text {
  font-size: clamp(0.72rem, 2.5vw, 0.82rem);
  font-weight: 700;
  color: #e67e22;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#reward-feedback-text {
  font-size: clamp(0.82rem, 3vw, 0.95rem);
  font-weight: 900;
  color: #2e7d32;
  background: #e8f5e9;
  padding: 4px 12px;
  border-radius: 20px;
  border: 2px solid #4caf50;
  white-space: nowrap;
}

/* ---- Footer ---- */
footer {
  text-align: center;
  padding: 8px 16px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  font-size: 0.72rem;
  color: #999;
}

/* ════════════════════════════════════════
   REWARD ANIMATION OVERLAY
   ════════════════════════════════════════ */

/* Full-canvas overlay — sits above canvas + SVG, below hero layer */
#reward-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 248, 180, 0.82);
  pointer-events: none;        /* clicks pass through when hidden */
  opacity: 0;
  transition: opacity 0.35s ease;
}
#reward-overlay:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}
#reward-overlay.reward-hiding {
  opacity: 0;
  pointer-events: none;
}

/* ── Sparkles ── */
#reward-sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.sparkle {
  position: absolute;
  line-height: 1;
  animation: sparklePop var(--dur, 0.9s) var(--delay, 0s) ease-out both;
  will-change: transform, opacity;
}
@keyframes sparklePop {
  0%   { opacity: 0; transform: scale(0) rotate(0deg) translateY(0); }
  45%  { opacity: 1; transform: scale(1.4) rotate(25deg) translateY(-8px); }
  100% { opacity: 0; transform: scale(0.6) rotate(50deg) translateY(-28px); }
}

/* ── Page-specific scene element (SVG/shapes in the middle of overlay) ── */
#reward-anim-scene {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Hero image bounces up from the bottom ── */
.reward-hero {
  position: absolute;
  bottom: 0;
  height: 58%;
  width: auto;
  animation: heroPopUp 0.55s 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
  will-change: transform, opacity;
}
.reward-hero.side-right { right: 4%; }
.reward-hero.side-left  { left:  4%; }
@keyframes heroPopUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Text message ── */
#reward-overlay-msg {
  position: relative;
  z-index: 2;
  text-align: center;
  animation: msgBounceIn 0.5s 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
  will-change: transform, opacity;
}
@keyframes msgBounceIn {
  from { transform: scale(0.5) translateY(12px); opacity: 0; }
  to   { transform: scale(1)   translateY(0);    opacity: 1; }
}
#reward-overlay-text {
  display: block;
  font-family: var(--font-heading, 'Arial Rounded MT Bold', Arial, sans-serif);
  font-size: clamp(1.5rem, 6vw, 2.5rem);
  font-weight: 900;
  color: #2e7d32;
  text-shadow: 0 2px 0 rgba(255,255,255,0.7), 0 3px 10px rgba(0,0,0,0.12);
  padding: 10px 20px;
  background: rgba(255,255,255,0.72);
  border-radius: 16px;
  border: 3px solid #f9c74f;
}

/* ════════════════════
   PAGE 1 — Bed scene
   ════════════════════ */
.p1-bed-wrap {
  position: absolute;
  bottom: 22%;
  left: 50%;
  transform: translateX(-50%);
  width: min(260px, 55%);
}
.p1-blanket {
  animation: blanketSmooth 0.9s 0.15s ease-out both;
  transform-origin: left center;
}
@keyframes blanketSmooth {
  from { transform: scaleX(0.88) translateY(6px); opacity: 0.5; }
  to   { transform: scaleX(1)    translateY(0);   opacity: 1; }
}
.p1-pillow {
  animation: pillowSettle 0.7s 0.35s ease-out both;
  transform-origin: center bottom;
}
@keyframes pillowSettle {
  0%   { transform: rotate(-8deg) translateX(-6px); opacity: 0.6; }
  60%  { transform: rotate(3deg)  translateX(2px);  opacity: 1; }
  100% { transform: rotate(0deg)  translateX(0);    opacity: 1; }
}

/* ════════════════════════
   Shared draw-stroke util
   (p2-check, p7-check)
   ════════════════════════ */
@keyframes drawStroke {
  to { stroke-dashoffset: 0; }
}

/* ════════════════════════════════════════
   PAGE 2 — Trash cleanup scene
   ════════════════════════════════════════ */
.p2-wrap {
  position: absolute;
  bottom: 28%;
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 50%);
}
.p2-bag {
  transform-box: fill-box;
  transform-origin: center;
  animation: p2BagFade 0.55s 0.1s ease-in both;
}
@keyframes p2BagFade {
  0%   { opacity: 1; transform: scale(1);    }
  100% { opacity: 0; transform: scale(0.25); }
}
.p2-lid {
  transform-box: fill-box;
  transform-origin: center top;
  animation: p2LidBounce 0.45s 0.65s ease-out both;
}
@keyframes p2LidBounce {
  0%   { transform: translateY(0);    }
  38%  { transform: translateY(-13px);}
  72%  { transform: translateY(3px);  }
  100% { transform: translateY(0);    }
}
.p2-check {
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: drawStroke 0.5s 0.85s ease-out forwards;
}

/* ════════════════════════════════════════
   PAGE 3 — Toys put away scene
   ════════════════════════════════════════ */
.p3-wrap {
  position: absolute;
  bottom: 26%;
  left: 50%;
  transform: translateX(-50%);
  width: min(220px, 52%);
}
.p3-toy-1 {
  transform-box: fill-box;
  transform-origin: center;
  animation: p3ToyVanish 0.45s 0.1s ease-in both;
}
.p3-toy-2 {
  transform-box: fill-box;
  transform-origin: center;
  animation: p3ToyVanish 0.45s 0.3s ease-in both;
}
.p3-toy-3 {
  transform-box: fill-box;
  transform-origin: center;
  animation: p3ToyVanish 0.45s 0.5s ease-in both;
}
@keyframes p3ToyVanish {
  0%   { opacity: 1; transform: scale(1);    }
  55%  { opacity: 0.5; transform: scale(0.5);}
  100% { opacity: 0; transform: scale(0.1); }
}
.p3-lid {
  transform-box: fill-box;
  animation: p3LidClose 0.5s 0.85s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
@keyframes p3LidClose {
  0%   { transform: translateY(-22px); }
  65%  { transform: translateY(3px);   }
  100% { transform: translateY(0);     }
}

/* ════════════════════════════════════════
   PAGE 4 — Carry / lift scene
   ════════════════════════════════════════ */
.p4-wrap {
  position: absolute;
  bottom: 28%;
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 50%);
}
.p4-bag {
  transform-box: fill-box;
  animation: p4BagLift 0.65s 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
@keyframes p4BagLift {
  0%   { transform: translateY(18px);  opacity: 0.7; }
  60%  { transform: translateY(-16px); opacity: 1;   }
  100% { transform: translateY(-8px);  opacity: 1;   }
}
.p4-arr1 { animation: p4ArrPop 0.5s 0.25s ease-out both; }
.p4-arr2 { animation: p4ArrPop 0.5s 0.4s  ease-out both; }
@keyframes p4ArrPop {
  0%   { opacity: 0; transform: translateY(10px);  }
  45%  { opacity: 1; transform: translateY(-6px);  }
  100% { opacity: 0.85; transform: translateY(0);  }
}
.p4-star {
  transform-box: fill-box;
  transform-origin: center;
  animation: p4StarPop 0.6s 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
@keyframes p4StarPop {
  0%   { transform: scale(0) rotate(-30deg); opacity: 0; }
  68%  { transform: scale(1.3) rotate(8deg); opacity: 1; }
  100% { transform: scale(1)   rotate(0);    opacity: 1; }
}

/* ════════════════════════════════════════
   PAGE 5 — Sharing scene
   ════════════════════════════════════════ */
.p5-wrap {
  position: absolute;
  bottom: 26%;
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 50%);
}
.p5-heart {
  transform-box: fill-box;
  transform-origin: center;
  animation: p5HeartIn 0.65s 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
@keyframes p5HeartIn {
  0%   { transform: scale(0); opacity: 0; }
  68%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}
.p5-h1 { animation: floatUp 1s 0.35s ease-out both; }
.p5-h2 { animation: floatUp 1s 0.5s  ease-out both; }
.p5-h3 { animation: floatUp 1s 0.25s ease-out both; }
.p5-h4 { animation: floatUp 1s 0.6s  ease-out both; }
.p5-h5 { animation: floatUp 1s 0.45s ease-out both; }

/* ════════════════════════════════════════
   PAGE 6 — Help someone scene
   ════════════════════════════════════════ */
.p6-wrap {
  position: absolute;
  bottom: 26%;
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 50%);
}
.p6-glow {
  transform-box: fill-box;
  transform-origin: center;
  animation: p6GlowPulse 1.2s 0.15s ease-in-out both;
}
@keyframes p6GlowPulse {
  0%   { opacity: 0; transform: scale(0.75); }
  50%  { opacity: 1; transform: scale(1.06); }
  100% { opacity: 0.55; transform: scale(1); }
}
.p6-book {
  transform-box: fill-box;
  animation: p6BookRise 0.6s 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
@keyframes p6BookRise {
  0%   { transform: translateY(28px); opacity: 0.4; }
  68%  { transform: translateY(-8px); opacity: 1;   }
  100% { transform: translateY(0);    opacity: 1;   }
}
.p6-sp1 { animation: sparkPop 0.55s 0.55s ease-out both; }
.p6-sp2 { animation: sparkPop 0.55s 0.7s  ease-out both; }
.p6-sp3 { animation: sparkPop 0.65s 0.85s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; }

/* ════════════════════════════════════════
   PAGE 7 — Tidy up scene
   ════════════════════════════════════════ */
.p7-wrap {
  position: absolute;
  bottom: 24%;
  left: 50%;
  transform: translateX(-50%);
  width: min(220px, 52%);
}
.p7-check {
  stroke-dasharray: 180;
  stroke-dashoffset: 180;
  animation: drawStroke 0.7s 0.25s ease-out forwards;
}

/* ════════════════════════════════════════
   PAGE 8 — Kindness scene
   ════════════════════════════════════════ */
.p8-wrap {
  position: absolute;
  bottom: 22%;
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 50%);
}
.p8-heart {
  transform-box: fill-box;
  transform-origin: center;
  animation: p8HeartIn 0.7s 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
@keyframes p8HeartIn {
  0%   { transform: scale(0); opacity: 0;    }
  65%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}
.p8-h1 { animation: floatUp 1s 0.45s ease-out both; }
.p8-h2 { animation: floatUp 1s 0.6s  ease-out both; }
.p8-h3 { animation: floatUp 1s 0.3s  ease-out both; }
.p8-h4 { animation: floatUp 1s 0.7s  ease-out both; }
.p8-h5 { animation: floatUp 1s 0.55s ease-out both; }

/* ════════════════════════════════════════
   PAGE 9 — Teamwork badge scene
   ════════════════════════════════════════ */
.p9-wrap {
  position: absolute;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 50%);
}
.p9-rays {
  transform-box: fill-box;
  transform-origin: center;
  animation: raysBurst 0.75s 0.05s ease-out both;
}
.p9-badge {
  transform-box: fill-box;
  transform-origin: center;
  animation: badgePop 0.6s 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

/* ════════════════════════════════════════
   PAGE 10 — Pride / Hero medal scene
   ════════════════════════════════════════ */
.p10-wrap {
  position: absolute;
  bottom: 18%;
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 50%);
}
.p10-rays {
  transform-box: fill-box;
  transform-origin: center;
  animation: raysBurst 0.9s 0.05s ease-out both;
}
.p10-medal {
  transform-box: fill-box;
  transform-origin: center;
  animation: badgePop 0.65s 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

/* ── Shared keyframes (p5/p8 hearts, p6 sparks, p9/p10 badge) ── */
@keyframes floatUp {
  0%   { opacity: 0; transform: translateY(0)    scale(0.5); }
  38%  { opacity: 1; transform: translateY(-14px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-32px) scale(0.65); }
}
@keyframes sparkPop {
  0%   { opacity: 0; transform: scale(0.3);  }
  60%  { opacity: 1; transform: scale(1.2);  }
  100% { opacity: 1; transform: scale(1);    }
}
@keyframes raysBurst {
  0%   { opacity: 0; transform: scale(0.45) rotate(-18deg); }
  60%  { opacity: 1; transform: scale(1.06) rotate(4deg);   }
  100% { opacity: 0.88; transform: scale(1) rotate(0deg);   }
}
@keyframes badgePop {
  0%   { transform: scale(0)    rotate(-14deg); opacity: 0; }
  68%  { transform: scale(1.12) rotate(4deg);  opacity: 1; }
  100% { transform: scale(1)    rotate(0);      opacity: 1; }
}

/* ---- Responsive tweaks ---- */

/* Very narrow phones (≤400px wide) — squeeze palette slightly */
@media (max-width: 400px) {
  .color-swatch    { width: 34px; height: 34px; }
  #color-palette   { max-width: 200px; gap: 4px; }
  .brush-btn       { width: 40px; height: 40px; font-size: 0.9rem; }
  #toolbar         { gap: 6px; }
  .nav-arrow-btn   { padding: 0 12px; font-size: 0.8rem; }
  #page-counter    { min-width: 80px; font-size: 0.78rem; }
}

/* ---- Portrait orientation ---- */
/*
  Strategy: body is a flex column; every chrome strip is flex-shrink:0.
  The canvas wrapper is flex: 0 0 auto with an explicit 4:3 aspect-ratio
  driven by viewport width.  JS (fitWrapper) measures actual chrome heights
  and reduces the wrapper size if needed so the total page never scrolls.
*/
@media (orientation: portrait) {
  html {
    overflow-x: hidden;
    height: 100%;
  }

  body {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-x: hidden;
  }

  /* Tighten chrome strips */
  header {
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    padding-bottom: 3px;
    flex-shrink: 0;
  }
  header h1         { font-size: clamp(1.05rem, 5vw, 1.5rem); }
  header .subtitle  { font-size: clamp(0.62rem, 2.5vw, 0.82rem); }

  #page-message-banner { padding: 4px 12px; flex-shrink: 0; }
  #page-message        { font-size: clamp(0.7rem, 2.8vw, 0.9rem); }

  #page-nav      { padding: 4px 8px; gap: 8px; flex-shrink: 0; }
  .nav-arrow-btn { min-height: 38px; padding: 0 14px; font-size: 0.8rem; }
  #page-counter  { font-size: 0.8rem; min-width: 90px; }

  /*
    Canvas wrapper: sized by viewport WIDTH, keeping 4:3 ratio.
    Width  = viewport width − 16 px margins, capped at 480 px.
    Height = width × ¾  (enforced by aspect-ratio).

    JS (fitWrapper in script.js) also adjusts these inline when the
    measured chrome leaves too little room.
  */
  #canvas-wrapper {
    flex: 0 0 auto;
    width: min(calc(100vw - 16px), 480px);
    aspect-ratio: 4 / 3;
    max-height: calc(100vh  - 300px);
    max-height: calc(100svh - 300px);
    align-self: center;
    margin: 5px auto;
  }

  /* ::before height-hack not needed — aspect-ratio handles it. */
  #canvas-wrapper::before { display: none !important; }

  /* Reward zone compact in portrait */
  #reward-zone {
    padding: 4px 10px;
    gap: 8px;
  }
  #reward-question-text { font-size: 0.8rem; }
  #reward-tap-text      { font-size: 0.72rem; }

  /* Compact toolbar at the bottom */
  #toolbar {
    flex-shrink: 0;
    padding: 5px 8px;
    padding-left:  max(8px, env(safe-area-inset-left,  0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
    gap: 5px;
    border-radius: 0;
    max-width: 100%;
  }

  /* Palette: 6 swatches per row on a 360 px screen */
  .color-swatch  { width: 34px; height: 34px; }
  #color-palette { max-width: 280px; gap: 4px; }

  .brush-btn { width: 40px; height: 40px; font-size: 0.85rem; }

  footer {
    flex-shrink: 0;
    padding: 3px 16px;
    padding-bottom: calc(3px + env(safe-area-inset-bottom, 0px));
    font-size: 0.65rem;
  }
}

/* Extra-compact: portrait phones ≤ 600 px tall (iPhone SE, older Androids) */
@media (orientation: portrait) and (max-height: 600px) {
  /* Drop the quote banner — saves ~27 px */
  #page-message-banner { display: none; }
  /* Shrink reward zone */
  #reward-zone { padding: 3px 8px; gap: 6px; }
  .reward-star-btn svg { width: 40px; height: 40px; }

  /* Tighter canvas: JS will measure and override inline if still too tall */
  #canvas-wrapper {
    max-height: calc(100vh  - 220px);
    max-height: calc(100svh - 220px);
  }

  #page-nav      { padding: 3px 8px; }
  .nav-arrow-btn { min-height: 34px; font-size: 0.74rem; padding: 0 10px; }
  #page-counter  { font-size: 0.74rem; min-width: 80px; }

  .color-swatch  { width: 30px; height: 30px; }
  #color-palette { max-width: 248px; }
  .brush-btn     { width: 36px; height: 36px; font-size: 0.78rem; }
  #eraser-btn    { width: 46px; min-height: 36px; height: 36px; font-size: 1.2rem; }
  #clear-btn     { min-height: 36px; font-size: 0.85rem; padding: 0 12px; }
  .tool-mode-btn { min-width: 36px; height: 36px; font-size: 0.78rem; padding: 0 8px; }
}

/* Landscape phones — reduce canvas margin to keep toolbar visible */
@media (max-height: 500px) and (orientation: landscape) {
  header            { padding-top: 4px; padding-bottom: 2px; }
  header h1         { font-size: 1.1rem; }
  header .subtitle  { font-size: 0.65rem; }
  #page-message-banner { padding: 4px 16px; }
  #page-nav         { padding: 4px 10px; gap: 8px; }
  .nav-arrow-btn    { min-height: 36px; font-size: 0.78rem; padding: 0 12px; }
  #page-counter     { font-size: 0.78rem; }
  #canvas-wrapper   { margin: 4px auto; }
  #toolbar          { padding: 5px 10px; gap: 6px; }
}
