/* ============================================================================
 * ASHTAR KATKOOT - ADVENTURE 9: "FOX & DONKEY - THE SAFE PATH" (story + chalkboard)
 *
 * This is the `a9-` prefix of the proven Adventure 8 stylesheet. The geometry, the
 * percentages and the comments are deliberately IDENTICAL: the chalkboard is a proven
 * layout and re-deriving it for a new prefix would only create a way for the two to drift.
 *
 * Only the root background changes: this chapter is a green woodland rather than a desert,
 * so the colour behind the chalkboard now agrees with the story instead of contradicting it.
 *
 * ----------------------------------------------------------------------------
 * THE COMPOSITION
 * ----------------------------------------------------------------------------
 * Twelve illustrations are ratio 0.563 and one - the book - is 0.667. At 390x844 a centred
 * `cover` crops ~43px from each side of a 0.563 picture and ~86px from each side of the
 * 0.667 one. Both were rendered at 390x844 and INSPECTED before the crop values were
 * chosen; they 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
 * a different aspect ratio, so no character is ever stretched.
 * ========================================================================== */

#app .a9-root {
  position: absolute;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  overscroll-behavior: contain;
  background: #23381f;
  color: #14324a;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#app .a9-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 cue-LIST scene commits ONCE and plays several clips under it,
 * so the picture is not crossfaded onto itself between lines.
 * ------------------------------------------------------------------------ */
#app .a9-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 280ms ease-out;
  pointer-events: none;          /* a story scene never wants a tap */
}
#app .a9-layer.is-on { opacity: 1; }

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

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

/* ------------------------------------------------------------------------ *
 * THE CHALKBOARD
 *
 * ONE template for every teaching scene, identical geometry - there is
 * deliberately no per-animal rule below, so a second animal costs nothing here.
 *
 * 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 .a9-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 .a9-board-scene[hidden] { display: none; }

#app .a9-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 .a9-board-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#app .a9-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 .a9-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 .a9-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. */
#app .a9-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 .a9-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: #1e3a20;
  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 .a9-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 .a9-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 COMPLETION CARD. Shown only after the ending narration has genuinely ended, drawn over
   the still-visible final illustration. */
#app .a9-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 .a9-phase-end-ar {
  direction: rtl;
  color: #1e3a20;
  font-size: 5.4vmin;
  font-weight: 800;
  line-height: 1.5;
}
#app .a9-phase-end-btn {
  min-height: 52px;              /* a real Android touch target */
  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 .a9-board-box { top: 6vh; width: 96vmin; }
  #app .a9-face-word { font-size: 7vmin; }
  #app .a9-teacher { max-height: 40vh; width: 54vmin; }
}