/* ============================================================================
 * ASHTAR KATKOOT - ADVENTURE 6: "PANDA & ANT - THE LOST BALL"
 *
 * A narrated story. There are no cards, no buttons to answer with, and nothing in
 * this file is clickable except the exit control, the audio-blocked recovery
 * control and the ending button.
 *
 * ----------------------------------------------------------------------------
 * THE ONE COMPOSITION DECISION, AND WHY IT IS MADE THIS WAY
 * ----------------------------------------------------------------------------
 * All eleven chapter-6 illustrations are 941x1672 - a ratio of 0.563. The target
 * phone, 390x844, is 0.462. The picture is therefore RELATIVELY WIDER than the
 * screen, so filling by height crops 85px of width in total, 42.5px each side of a
 * centred crop.
 *
 * Every scene is now FULL-SCREEN `object-fit: cover`: one image, filling the screen,
 * no letterbox and no blurred copy behind it. The 85px is not spread evenly - which
 * 85px matters differs per picture - so `object-position` is set per image from the
 * `CROP` map in `animal-adventure6.js`. The PNGs are never rescaled to a different
 * shape, so no character is stretched; only the window over them moves.
 *
 * This was verified by rendering all eleven crops at 390x844 and inspecting them. If
 * an illustration ever cannot be cropped without losing a character or the red ball,
 * the correct answer is to report that image, not to distort it.
 * ========================================================================== */

#app .a6-root {
  position: absolute;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  overscroll-behavior: contain;
  background: #1d3325;
  color: #14324a;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#app .a6-root[hidden] { display: none; }

/* ------------------------------------------------------------------------ *
 * THE SCENE LAYERS
 *
 * Two layers, A and B, crossfaded. `is-on` is the visible one; the other is
 * loaded and decoded while the current scene is still on screen, so a scene
 * change can never expose an empty frame.
 * ------------------------------------------------------------------------ */
#app .a6-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 280ms ease-out;
  pointer-events: none;          /* a story scene never wants a tap */
}
#app .a6-layer.is-on { opacity: 1; }

/* THE ILLUSTRATION: FULL-SCREEN `cover`.
   *
   * The blurred backdrop is gone. It existed only to fill the bands that `contain`
   * leaves on a 0.563 image in a 0.462 screen; with `cover` there is no band, and a
   * blurred copy behind a sharp one only muddied the picture.
   *
   * `object-position` comes from the per-image `CROP` map in the module, so the crop
   * that keeps the red ball or the ant is data that travels with the adventure. The
   * file is never rescaled to a different shape, so nothing is stretched. */
#app .a6-fit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
}

@media (prefers-reduced-motion: reduce) {
  #app .a6-layer { transition: none; }
}

/* ------------------------------------------------------------------------ *
 * THE CHALKBOARD TEACHING SCENE
 *
 * ONE template for both PANDA and ANT, identical geometry - that is the whole
 * requirement, so there is deliberately no per-animal rule anywhere below.
 *
 * Geometry is the same proportions Adventure 5 uses for its board lesson, so the
 * teacher and the board do not jump size when the scene changes.
 * ------------------------------------------------------------------------ */
#app .a6-board-scene {
  position: absolute;
  inset: 0;
  z-index: 4;
  background:
    radial-gradient(120% 90% at 50% 12%, #4e7a52 0%, #2f4f36 55%, #1d3325 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
#app .a6-board-scene[hidden] { display: none; }

/* THE BOARD BOX.
   One positioned rectangle that is exactly the board image's own box. Everything the
   board shows - the animal, the word - is placed as a PERCENTAGE of THIS box, using
   the writing area measured from the board PNG's own pixels:

       board.png is 640x444; the dark-green writing field is
       x 75..564 and y 29..314, i.e. 11.7%..88.1% across and 6.5%..70.7% down.

   Percentages are used instead of pixel offsets because the board's on-screen size
   changes with the viewport. An earlier version positioned the animal and the word in
   `vh`/`vmin` against a differently-sized board, which is why the animal overflowed
   the frame and the word ended up BELOW it on the green wall. */
#app .a6-board-box {
  position: absolute;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%);
  width: 92vmin;
  max-width: 98%;
  aspect-ratio: 640 / 444;          /* the board image's own shape, undistorted */
}
#app .a6-board-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* The animal and its word, INSIDE the measured writing area.
   `overflow: hidden` is a backstop: if a viewport is so short that the content would
   spill, it is clipped at the board's edge rather than drawn over the wooden frame. */
#app .a6-board-face {
  position: absolute;
  left: 11.7%;
  width: 76.4%;
  top: 7.5%;
  height: 62%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1%;
  overflow: hidden;
  pointer-events: none;
}
#app .a6-face-art {
  /* The animal keeps its square proportions and never exceeds the writing area. */
  flex: 1 1 auto;
  min-height: 0;
  width: auto;
  height: 100%;
  max-width: 74%;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .45));
}
#app .a6-face-word {
  flex: 0 0 auto;
  /* CHALK, NOT INK. The board's field is a mid green, and the word used to be dark
     green on it - the worst possible contrast, and unreadable on a phone in daylight.
     A warm chalk white with a soft dark shadow keeps it legible without pretending
     the board is white. */
  color: #fff8e2;
  text-shadow: 0 2px 5px rgba(6, 34, 16, .85), 0 0 1px rgba(6, 34, 16, .9);
  font-size: 8.6vmin;
  line-height: 1;
  font-weight: 900;
  letter-spacing: .04em;
  /* The English word is ALWAYS left-to-right and never reordered by the page's
     Arabic direction. */
  direction: ltr;
  unicode-bidi: isolate;
  text-align: center;
  margin-bottom: 4%;
}

/* The teacher stands beside the board, large, and never over the animal or the word.
 *
 * He is anchored BOTTOM-left and sized so his head rises to just under the English
 * word. At the smaller size he first had, the portrait screen left a dead band
 * roughly 260px tall between the word and the top of his head - the lesson read as
 * two unrelated objects floating on a green field. His height is therefore driven
 * by the space he has to fill, not by a fixed width: 60vmin wide makes him ~360px
 * tall on a 390x844 screen, which closes that band while keeping him clear of the
 * board's centre column. */
#app .a6-teacher {
  position: absolute;
  bottom: 0;
  left: -2%;
  width: 60vmin;
  max-width: 66%;
  height: auto;
  max-height: 56vh;
  object-fit: contain;
  object-position: bottom left;
  pointer-events: none;
  filter: drop-shadow(0 1.4vmin 2vmin rgba(0, 0, 0, .32));
}

/* ------------------------------------------------------------------------ *
 * CONTROLS
 * ------------------------------------------------------------------------ */

/* THE EXIT. The only control during the story. */
#app .a6-exit {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  z-index: 6;
  min-width: 72px;
  min-height: 44px;              /* a real touch target */
  padding: 0 16px;
  border: 0;
  border-radius: 22px;
  background: rgba(255, 253, 246, .93);
  color: #123c2c;
  font: inherit;
  font-size: 4.4vmin;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .28);
  cursor: pointer;
}

/* THE AUDIO-BLOCKED RECOVERY CONTROL. One label, one button. It is shown ONLY
   when a clip genuinely failed, and pressing it re-requests the same cue. */
#app .a6-audiowait {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
  z-index: 7;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
#app .a6-audiowait-btn {
  pointer-events: auto;
  min-height: 56px;              /* comfortably above 44px */
  padding: 0 26px;
  border: 0;
  border-radius: 28px;
  background: linear-gradient(180deg, #ffdd8a, #f3b93f);
  color: #3a2506;
  font: inherit;
  font-size: 5vmin;
  font-weight: 900;
  box-shadow: 0 3px 0 rgba(120, 80, 10, .38), 0 6px 16px rgba(0, 0, 0, .3);
  cursor: pointer;
}

/* THE ENDING CARD. It sits over the final illustration, which is still on screen. */
#app .a6-ending {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 30px);
  transform: translateX(-50%);
  z-index: 6;
  width: min(92%, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-radius: 20px;
  background: rgba(255, 253, 246, .95);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .34);
  text-align: center;
}
#app .a6-ending-ar {
  direction: rtl;
  color: #123c2c;
  font-size: 5.4vmin;
  font-weight: 800;
  line-height: 1.5;
}
#app .a6-ending-btn {
  min-height: 52px;
  padding: 0 24px;
  border: 0;
  border-radius: 26px;
  background: linear-gradient(180deg, #43b169, #2f8f52);
  color: #fff;
  font: inherit;
  font-size: 4.8vmin;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(20, 70, 40, .4);
}

/* A narrow or short screen must still show the whole teaching scene, so the
   board and the teacher shrink together rather than overlapping the word. */
@media (max-height: 620px) {
  #app .a6-board-box { top: 6vh; width: 96vmin; }
  #app .a6-face-word { font-size: 7vmin; }
  #app .a6-teacher { max-height: 40vh; width: 54vmin; }
}