/* ============================================================================
   KG1 ANIMAL V2 — scoped styles
   ----------------------------------------------------------------------------
   EVERY rule below is gated on the .kg1-animal-v2 root class, which the V2
   controller puts on #app only while a V2 stage is on screen. When the class
   is absent these styles cannot match anything, so no other world, grade or
   lesson can be affected.

   Deliberately NOT in this file:
   - no transform:scale() for image sizing (images are normalised with real
     layout geometry: fixed box + width/height + object-fit:contain)
   - no overrides of shared .kg1-* legacy classes
   - no global element selectors outside the .kg1-animal-v2 scope

   Target viewport: 390 x 844 portrait, no vertical scrolling.
   Zones, top to bottom:
     A  existing safe top controls (global #exitStage / #sound) - reserved
     B  written instruction + progress
     C  target English word (mandatory, visible before any tap)
     D  picture choices (2 x 2, identical containers)
     E  bottom safe area
   ========================================================================== */

/* ---------- root / shell ------------------------------------------- */
#app.kg1-animal-v2 .animal-v2-screen{
  position:fixed;
  inset:0;
  z-index:22;
  display:flex;
  flex-direction:column;
  /* Zone A: clear the global 48px top controls (they sit at top:14px). */
  padding:calc(72px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
  background:linear-gradient(160deg,#0a2a4d 0%,#123a63 55%,#0d2f52 100%);
  overflow:hidden;
  -webkit-tap-highlight-color:transparent;
}
#app.kg1-animal-v2 .animal-v2-screen.hidden{display:none!important}

/* While V2 is up the shared safe controls must stay reachable above the
   V2 surface. Scoped so nothing else is affected. */
#app.kg1-animal-v2 #exitStage,
#app.kg1-animal-v2 #sound{z-index:26!important}

/* Legacy stage furniture belongs to the plane mechanic - never shown in V2. */
#app.kg1-animal-v2 #targetPreview,
#app.kg1-animal-v2 #fire,
#app.kg1-animal-v2 #helpStage{display:none!important}

/* ---------- zone B: written instruction + progress ----------------- */
#app.kg1-animal-v2 .animal-v2-head{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  color:#cfe6ff;
  font-weight:900;
  font-size:clamp(12px,3.6vw,16px);
  line-height:1.2;
  padding:0 4px 8px;
}
#app.kg1-animal-v2 .animal-v2-head .animal-v2-kind{
  color:#ffd76a;
  text-align:start;
}
#app.kg1-animal-v2 .animal-v2-head .animal-v2-progress{
  flex:0 0 auto;
  color:#fff;
  background:#1d4f80;
  border-radius:999px;
  padding:4px 11px;
  font-size:clamp(11px,3.2vw,14px);
}

/* ---------- zone C: the mandatory written English target ------------ */
#app.kg1-animal-v2 .animal-v2-target{
  flex:0 0 auto;
  text-align:center;
  padding:6px 0 10px;
}
#app.kg1-animal-v2 .animal-v2-target .animal-v2-target-label{
  display:block;
  color:#9fc6ef;
  font-size:clamp(11px,3.2vw,14px);
  font-weight:800;
  margin-bottom:2px;
}
#app.kg1-animal-v2 .animal-v2-target .animal-v2-word{
  display:inline-block;
  font-family:system-ui,-apple-system,"Segoe UI",sans-serif;
  font-size:clamp(38px,12.5vw,58px);
  line-height:1.05;
  font-weight:1000;
  letter-spacing:.06em;
  color:#fff;
  background:#12406e;
  border:3px solid #ffd76a;
  border-radius:18px;
  padding:6px 20px 8px;
  text-shadow:0 3px 0 #0a2748;
  /* Guaranteed visible before any interaction. */
  word-break:keep-all;
  overflow-wrap:normal;
}

/* ---------- zone D: picture choices -------------------------------- */
/* min-height:0 on the flex child is what prevents any vertical overflow. */
#app.kg1-animal-v2 .animal-v2-grid{
  flex:1 1 auto;
  min-height:0;
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  grid-auto-rows:minmax(0,1fr);
  gap:12px;
}

#app.kg1-animal-v2 .animal-v2-tile{
  min-width:0;
  min-height:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:8px;
  border:4px solid #e0b135;
  border-radius:22px;
  background:#fffdf3;
  box-shadow:0 6px 0 #ae7316;
  cursor:pointer;
  font:inherit;
  transition:transform .08s ease, box-shadow .08s ease, border-color .12s ease, background .12s ease;
}
#app.kg1-animal-v2 .animal-v2-tile:active:not(:disabled){
  transform:translateY(3px);
  box-shadow:0 3px 0 #ae7316;
}
#app.kg1-animal-v2 .animal-v2-tile:disabled{cursor:default}

/* Normalised image container: identical geometry for every source image,
   regardless of its intrinsic pixel dimensions. */
#app.kg1-animal-v2 .animal-v2-thumb{
  display:flex;
  align-items:center;
  justify-content:center;
  width:100%;
  max-width:100%;
  aspect-ratio:1/1;
  max-height:100%;
  margin:auto;
}
#app.kg1-animal-v2 .animal-v2-thumb img{
  display:block;
  width:100%;
  height:100%;
  max-width:100%;
  max-height:100%;
  object-fit:contain;
}
#app.kg1-animal-v2 .animal-v2-thumb.is-fallback img{display:none}
#app.kg1-animal-v2 .animal-v2-tile-word{
  font-size:clamp(15px,4.6vw,22px);
  font-weight:1000;
  color:#173c56;
  text-align:center;
  line-height:1.1;
}

/* feedback */
#app.kg1-animal-v2 .animal-v2-tile.is-wrong{
  border-color:#e2564d;
  background:#ffe9e6;
  box-shadow:0 6px 0 #a5342d;
  opacity:.72;
}
#app.kg1-animal-v2 .animal-v2-tile.is-correct{
  border-color:#3fae5a;
  background:#e6fbe9;
  box-shadow:0 6px 0 #2b7c3e;
  animation:animalV2Pop .32s ease-out;
}
@keyframes animalV2Pop{
  0%{transform:scale(.96)}
  55%{transform:scale(1.04)}
  100%{transform:scale(1)}
}

/* ---------- zone E: child-controlled listen + bottom safe space ---- */
#app.kg1-animal-v2 .animal-v2-foot{
  flex:0 0 auto;
  display:flex;
  justify-content:center;
  padding:10px 0 0;
}
#app.kg1-animal-v2 .animal-v2-listen{
  min-height:46px;
  padding:0 20px;
  border:3px solid #1d4f80;
  border-radius:999px;
  background:#fff;
  color:#12406e;
  font-weight:1000;
  font-size:clamp(13px,3.8vw,17px);
  cursor:pointer;
  box-shadow:0 4px 0 #1d4f80;
}
#app.kg1-animal-v2 .animal-v2-listen:active{transform:translateY(2px);box-shadow:0 2px 0 #1d4f80}

/* ==================================================================== *
   UNIFIED COMPLETION CARD V2
   One template for all ten stages. Only data changes.
   No speech is connected to this component.
   ==================================================================== */
#app.kg1-animal-v2 .animal-v2-complete{
  position:fixed;
  inset:0;
  z-index:30;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  background:rgba(4,18,38,.72);
  backdrop-filter:blur(3px);
}
#app.kg1-animal-v2 .animal-v2-complete.hidden{display:none!important}

#app.kg1-animal-v2 .animal-v2-card{
  width:100%;
  max-width:340px;
  max-height:100%;
  overflow:auto;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:10px;
  padding:16px 16px 18px;
  border:5px solid #d9ad31;
  border-radius:28px;
  background:#fffdf3;
  box-shadow:0 8px 0 #9c6615;
  text-align:center;
  animation:animalV2CardIn .26s ease-out;
}
@keyframes animalV2CardIn{
  from{opacity:0;transform:translateY(14px)}
  to{opacity:1;transform:translateY(0)}
}

#app.kg1-animal-v2 .animal-v2-stars{
  display:flex;
  gap:6px;
  font-size:clamp(22px,7vw,30px);
  line-height:1;
}
#app.kg1-animal-v2 .animal-v2-stars .is-off{opacity:.32}

/* Fixed art box: identical for every animal, contain-fit, never clipped. */
#app.kg1-animal-v2 .animal-v2-art{
  width:min(58vw,200px);
  aspect-ratio:1/1;
  max-height:34vh;
  display:flex;
  align-items:center;
  justify-content:center;
  background:#fff;
  border:3px solid #e0b135;
  border-radius:20px;
  padding:6px;
  overflow:hidden;
}
#app.kg1-animal-v2 .animal-v2-art img{
  display:block;
  width:100%;
  height:100%;
  max-width:100%;
  max-height:100%;
  object-fit:contain;
}
#app.kg1-animal-v2 .animal-v2-art.is-empty{display:none}

#app.kg1-animal-v2 .animal-v2-card-label{
  font-size:clamp(26px,8.4vw,36px);
  line-height:1.05;
  font-weight:1000;
  letter-spacing:.05em;
  color:#173c56;
  word-break:keep-all;
}
#app.kg1-animal-v2 .animal-v2-card-caption{
  font-size:clamp(13px,3.8vw,17px);
  font-weight:800;
  color:#b45a13;
  min-height:1em;
}

#app.kg1-animal-v2 .animal-v2-card-actions{
  width:100%;
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:9px;
  margin-top:2px;
}
#app.kg1-animal-v2 .animal-v2-card-actions button{
  min-width:0;
  min-height:48px;
  padding:8px 6px;
  border-radius:16px;
  border:3px solid #1d4f80;
  background:#fff;
  color:#12406e;
  font-weight:1000;
  font-size:clamp(12px,3.5vw,16px);
  cursor:pointer;
  box-shadow:0 4px 0 #1d4f80;
  white-space:nowrap;
}
#app.kg1-animal-v2 .animal-v2-card-actions button:active{transform:translateY(2px);box-shadow:0 2px 0 #1d4f80}
#app.kg1-animal-v2 .animal-v2-card-actions button[data-v2="next"]{
  background:#ffd76a;
  border-color:#a5761a;
  color:#3a2a05;
  box-shadow:0 4px 0 #a5761a;
}
#app.kg1-animal-v2 .animal-v2-card-actions button[data-v2="listen"]{
  background:#e8f4ff;
}

/* ---------- very short viewports: keep it scroll-free -------------- */
@media (max-height:700px){
  #app.kg1-animal-v2 .animal-v2-target{padding:2px 0 6px}
  #app.kg1-animal-v2 .animal-v2-target .animal-v2-word{
    font-size:clamp(30px,10vw,44px);
    padding:4px 16px 6px;
  }
  #app.kg1-animal-v2 .animal-v2-grid{gap:9px}
  #app.kg1-animal-v2 .animal-v2-art{width:min(46vw,150px);max-height:24vh}
  #app.kg1-animal-v2 .animal-v2-listen{min-height:40px}
}
