/* ============================================================================
 * ASHTAR KATKOOT - ADVENTURE 7, PHASE 1: "RABBIT - THE CARROT BASKET"
 *
 * A narrated story. Nothing here is clickable except the exit control, the
 * audio-blocked start control and the end-of-phase button.
 *
 * ----------------------------------------------------------------------------
 * THE COMPOSITION
 * ----------------------------------------------------------------------------
 * All five illustrations are PORTRAIT but they are not all the same shape:
 * `rabbit-mom-talk` is 0.463 (almost exactly the 390x844 screen's 0.462),
 * three are 0.563, and `rabbit-goodbye` is 0.750 - the widest, where a centred
 * `cover` crops 243px of width. All five were rendered at 390x844 and inspected
 * before the crop values were chosen; the values live in `CROP` in the module, and
 * every one of them is `50% 50%` because in each picture the subject sits inside
 * the surviving middle. The PNGs are never rescaled to another shape, so no
 * character is ever stretched.
 * ========================================================================== */

#app .a7-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 .a7-root[hidden] { display: none; }

/* ------------------------------------------------------------------------ *
 * THE SCENE LAYERS - two, crossfaded. `is-on` is the visible one; the other
 * decodes while the current scene is still up, so a change never exposes an
 * empty frame. A conversation scene commits ONCE and plays several clips under
 * it, so the picture is not crossfaded onto itself between lines.
 * ------------------------------------------------------------------------ */
#app .a7-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 280ms ease-out;
  pointer-events: none;          /* a story scene never wants a tap */
}
#app .a7-layer.is-on { opacity: 1; }

#app .a7-fit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
}

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

/* ------------------------------------------------------------------------ *
 * THE CHALKBOARD
 *
 * ONE template for every teaching scene, identical geometry - there is
 * deliberately no per-animal rule below.
 *
 * The writing area comes from board.png's own pixels: 640x444 overall, dark-green
 * field at x 75..564, y 29..314, i.e. 11.7-88.1% across and 6.5-70.7% down. The
 * art and the word are positioned as PERCENTAGES of that field, so "inside the
 * board" is arithmetic rather than a hand-tuned offset that breaks when the
 * viewport changes.
 * ------------------------------------------------------------------------ */
#app .a7-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 .a7-board-scene[hidden] { display: none; }

#app .a7-board-box {
  position: absolute;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%);
  width: 92vmin;
  max-width: 98%;
  aspect-ratio: 640 / 444;          /* the board's own shape, undistorted */
}
#app .a7-board-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#app .a7-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;              /* clipped at the board, never over the frame */
  pointer-events: none;
}
#app .a7-face-art {
  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 .a7-face-word {
  flex: 0 0 auto;
  /* CHALK, NOT INK. The board field is a mid green; dark green text on it is the
     worst possible contrast and unreadable in daylight. */
  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, whatever the page's direction. */
  direction: ltr;
  unicode-bidi: isolate;
  text-align: center;
  margin-bottom: 4%;
}

/* Teacher Katkoot stands beside the board, large, and covers neither the animal
   nor the word. He is anchored bottom-left and sized to the space he has to
   fill, so no dead band opens up between him and the word. */
#app .a7-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 .a7-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 START / AUDIO-BLOCKED CONTROL. Shown when a clip genuinely cannot play.
   Its press is the user gesture the browser needs; it re-requests the SAME cue
   and never skips forward. */
#app .a7-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 .a7-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 END-OF-PHASE CARD. Phase 1 is not a finished adventure: there is no
   carrot activity yet, so nothing is scored and this card says so. */
#app .a7-phase-end {
  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 .a7-phase-end-ar {
  direction: rtl;
  color: #123c2c;
  font-size: 5.4vmin;
  font-weight: 800;
  line-height: 1.5;
}
#app .a7-phase-end-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 short screen still has to show the whole teaching scene, so the board and
   the teacher shrink together rather than overlapping the word. */
@media (max-height: 620px) {
  #app .a7-board-box { top: 6vh; width: 96vmin; }
  #app .a7-face-word { font-size: 7vmin; }
  #app .a7-teacher { max-height: 40vh; width: 54vmin; }
}