/* ============================================================================
 * ASHTAR KATKOOT - ADVENTURE 8: "CAMEL & THE LOST OASIS" (story + chalkboard)
 *
 * This is the `a8-` prefix of Adventure 7's proven 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 names changed.
 *
 * Nothing here is clickable except the exit control, the audio-blocked start control and
 * the completion button.
 *
 * ----------------------------------------------------------------------------
 * THE COMPOSITION
 * ----------------------------------------------------------------------------
 * All ten illustrations are portrait and all ten are the same shape to within a pixel
 * (ratio 0.563-0.564). At 390x844 a centred `cover` scales by height and crops about 43px
 * from each side; every subject sits inside the surviving middle, so every `CROP` value in
 * the module is `50% 50%`. The PNGs are never rescaled to a different aspect ratio, so no
 * character is ever stretched.
 * ========================================================================== */

#app .a8-root {
  position: absolute;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  overscroll-behavior: contain;
  background: #2a2416;
  color: #14324a;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#app .a8-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 .a8-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 280ms ease-out;
  pointer-events: none;          /* a story scene never wants a tap */
}
#app .a8-layer.is-on { opacity: 1; }

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

@media (prefers-reduced-motion: reduce) {
  #app .a8-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 .a8-board-scene {
  position: absolute;
  inset: 0;
  z-index: 4;
  /* Warmer than Adventure 7's green: this board stands in a desert chapter, and the
     ground colour behind it now agrees with the story instead of contradicting it. */
  background:
    radial-gradient(120% 90% at 50% 12%, #7d6234 0%, #55411f 55%, #2a2416 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
#app .a8-board-scene[hidden] { display: none; }

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

#app .a8-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 .a8-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 .a8-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 .a8-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 .a8-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: #3a2b12;
  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 .a8-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 .a8-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 .a8-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 .a8-phase-end-ar {
  direction: rtl;
  color: #3a2b12;
  font-size: 5.4vmin;
  font-weight: 800;
  line-height: 1.5;
}
#app .a8-phase-end-btn {
  min-height: 52px;              /* a real Android touch target */
  padding: 0 24px;
  border: 0;
  border-radius: 26px;
  background: linear-gradient(180deg, #d79a3c, #b3762a);
  color: #fff;
  font: inherit;
  font-size: 4.8vmin;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(90, 56, 16, .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 .a8-board-box { top: 6vh; width: 96vmin; }
  #app .a8-face-word { font-size: 7vmin; }
  #app .a8-teacher { max-height: 40vh; width: 54vmin; }
}