/* ============================================================================
 * ASHTAR KATKOOT - ANIMAL FRIENDS
 * ----------------------------------------------------------------------------
 * Scoped entirely under `.af-root`, so nothing here can reach the story
 * adventures, the album, the Adventure Cards map or the 100 challenge stages.
 *
 * Built for a 390 x 844 portrait phone AND for shorter screens: every column
 * is `flex` with `min-height: 0` and only the intended one region scrolls, so
 * nothing can overlap or be pushed off the bottom at any height.
 * ============================================================================ */

.af-root {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: inherit;
  color: #2a1408;
  --af-ink: #2a1408;
}

/* ---------- the storybook sky ---------- */
.af-sky {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 70% at 50% -10%, #ffe6a8 0%, #ffc46b 28%, #f79a52 52%, #7c4bb0 100%);
  overflow: hidden;
}
.af-sun {
  position: absolute;
  top: -16%;
  left: 50%;
  width: 58vmin;
  height: 58vmin;
  margin-left: -29vmin;
  border-radius: 50%;
  background: radial-gradient(circle, #fffbe8 0%, #ffe27a 45%, #ffca55 70%, #ffb43c00 72%);
  animation: af-sun 7s ease-in-out infinite;
}
@keyframes af-sun { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

.af-star {
  position: absolute;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #fff;
  opacity: .75;
  animation: af-twinkle 2.6s ease-in-out infinite;
}
@keyframes af-twinkle { 0%, 100% { opacity: .18; transform: scale(.7); } 50% { opacity: .9; transform: scale(1.15); } }

.af-hill { position: absolute; left: -20%; width: 140%; border-radius: 50% 50% 0 0; }
.af-hill-a { bottom: -16%; height: 46%; background: linear-gradient(180deg, #4f9a4a, #2f6b39); }
.af-hill-b { bottom: -24%; height: 42%; background: linear-gradient(180deg, #3f8240, #24502c); }

/* ---------- the one scrolling column ---------- */
.af-scroll {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.4vh, 14px);
  padding: calc(clamp(8px, 2vh, 16px) + env(safe-area-inset-top)) 14px
           calc(clamp(8px, 2vh, 16px) + env(safe-area-inset-bottom));
}

/* ---------- the three friends, above Katkoot ---------- */
.af-portraits { display: flex; gap: clamp(8px, 3vw, 18px); justify-content: center; flex: 0 0 auto; }
.af-portrait {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: clamp(70px, 23vw, 108px);
}
.af-portrait-ring {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  padding: 3px;
  background: conic-gradient(from 210deg, #ffe9a8, #ffb84d, #ff8a3d, #ffd76b, #ffe9a8);
  box-shadow: 0 5px 0 #7a3c12, 0 8px 14px #0004, inset 0 0 0 2px #fff8;
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
/* The album PNGs have a clean WHITE plate, not a transparent one (verified:
   palette PNG, no alpha channel). Multiply drops that white out against the
   warm plate below, so the existing approved art reads as a cut-out without
   a new image being invented. */
.af-portrait-img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: contain;
  display: block;
  mix-blend-mode: multiply;
  background: radial-gradient(circle at 50% 55%, #fff6e2 0%, #ffe2b4 70%, #ffcf90 100%);
}
.af-portrait.is-soon { opacity: .8; }
.af-portrait.is-soon .af-portrait-img { filter: saturate(.6) brightness(.97); }
.af-portrait.is-done .af-portrait-ring { transform: scale(1.06); }

.af-tick {
  position: absolute;
  top: -2px; left: -2px;
  width: clamp(19px, 6vw, 28px);
  height: clamp(19px, 6vw, 28px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(11px, 3.6vw, 17px);
  font-weight: 900;
  color: #063;
  background: linear-gradient(180deg, #7bf39b, #21b866);
  border: 2px solid #fff;
  box-shadow: 0 3px 0 #0d7a3f;
  opacity: 0;
  transform: scale(.3);
  transition: transform .4s cubic-bezier(.34, 1.56, .64, 1), opacity .2s;
}
.af-portrait.is-done .af-tick { opacity: 1; transform: scale(1); }

.af-portrait-name {
  font-size: clamp(8px, 2.6vw, 12px);
  font-weight: 900;
  letter-spacing: .03em;
  color: #fff;
  text-shadow: 0 2px 0 #6b3a10, 0 0 8px #0006;
  direction: ltr;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Katkoot ---------- */
.af-katkoot { flex: 0 1 auto; min-height: 0; display: grid; place-items: center; }
.af-katkoot-img {
  width: auto;
  height: clamp(150px, 34vh, 300px);
  max-width: min(78%, 300px);
  object-fit: contain;
  filter: drop-shadow(0 10px 16px #0005);
  animation: af-bob 3.4s ease-in-out infinite;
}
@keyframes af-bob { 0%, 100% { transform: translateY(0) rotate(-.6deg); } 50% { transform: translateY(-8px) rotate(.6deg); } }

.af-hint {
  margin: 0;
  font-size: clamp(13px, 4vw, 18px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 0 #7a3c12;
}

/* ---------- buttons ---------- */
/* Fixed to the bottom of the flex column, never inside the scrolling region,
   so they cannot be pushed under anything and are always reachable. */
.af-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; width: 100%; }
.af-actions-fixed {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  padding: clamp(6px, 1.4vh, 12px) 14px calc(clamp(6px, 1.4vh, 12px) + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #ffffff00, #0000001a);
}
.af-btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: clamp(10px, 2.8vw, 15px) clamp(16px, 5vw, 28px);
  min-height: 48px;
  font: inherit;
  font-size: clamp(14px, 4.2vw, 19px);
  font-weight: 900;
  cursor: pointer;
  transition: transform .14s, box-shadow .14s, filter .2s;
  touch-action: manipulation;
  /* the stacking fix: controls always sit above any decorative layer */
  position: relative;
  z-index: 4;
}
.af-btn:active { transform: translateY(3px); }
.af-btn:disabled { cursor: default; filter: saturate(.3) brightness(1.08); opacity: .5; }

.af-btn-start {
  color: #3a1c00;
  background: linear-gradient(180deg, #ffe07a, #ffb02e 60%, #f58a12);
  box-shadow: 0 5px 0 #a6530a, 0 10px 18px #0004;
  animation: af-pulse 1.8s ease-in-out infinite;
}
.af-btn-start:disabled { animation: none; }
.af-btn-start.is-ready { animation: af-pulse 1s ease-in-out infinite; }
@keyframes af-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }

.af-btn-next { color: #fff; background: linear-gradient(180deg, #58c47f, #2b9a58); box-shadow: 0 5px 0 #1a6b3c, 0 10px 18px #0004; }
.af-btn-ghost { color: #fff; background: linear-gradient(180deg, #7d90ad, #4d5f7d); box-shadow: 0 4px 0 #33415a; }

/* ==========================================================================
 * THE APPROVED ANIMAL PROFILE LAYOUT
 *
 * The savannah image in animal-profile-background.png is the whole design and
 * is used unchanged. Nothing is drawn over it to imitate what it already
 * contains: no plate, no blob, no ring, no badge.
 *
 * EVERYTHING BELOW IS POSITIONED IN PERCENT OF THE SCREEN, not by flex, because
 * the animal has to stand on a fixed feature of the picture.
 *
 *   MEASURED ON THE APPROVED IMAGE (941 x 1672):
 *     the flat stone platform's top surface sits at image y ~1250 of 1672;
 *     at 390 x 844 with cover (scale 844/1672 = 0.5048) that is
 *     screen y = 1250 x 0.5048 = 631, i.e. 74.8% of the screen height.
 *
 *   So the artwork box ends at 76% and is BOTTOM aligned, which puts the
 *   lion's feet on the stone. The box is width:auto/height:auto with max-*
 *   constraints, so the 640 x 640 plate scales down uniformly. object-fit:
 *   contain is kept as a belt-and-braces guarantee that it is never stretched
 *   and never cropped.
 *
 * The name panel sits at the top over the open sky, the letter tiles sit below
 * the lion's feet over the bare sand, and nothing overlaps the animal.
 * ========================================================================== */
.af-animal {
  padding: 0;
  background: #1d4a2b url(assets/animal-rescue/animal-profile-background.png) center center / cover no-repeat;
}
.af-profile-stack {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ONE ELEGANT NAME PANEL - dark, rounded, about 40% opaque, light text.
   The sky behind it is bright, so the panel is what guarantees contrast
   whatever the weather in the picture does. */
.af-profile-panel {
  position: absolute;
  top: 3.2%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  min-width: min(60%, 228px);
  max-width: 86%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: clamp(7px, 1.7vh, 14px) clamp(18px, 6vw, 30px);
  border-radius: 24px;
  background: rgba(10, 34, 51, .40);
  border: 2px solid rgba(255, 255, 255, .32);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.af-profile-name {
  margin: 0;
  font-size: clamp(32px, 10.4vw, 46px);
  font-weight: 1000;
  letter-spacing: .07em;
  direction: ltr;
  line-height: 1;
  color: #ffffff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .55);
}
.af-profile-meaning {
  margin: 0;
  font-size: clamp(15px, 4.8vw, 22px);
  font-weight: 900;
  line-height: 1.15;
  color: #e7f4ff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .55);
}
.af-profile-cheer { color: #ffe6b0; }

/* THE ANIMAL. Top 15%, bottom 24% => the box ends at 76%, which is the stone. */
.af-profile-stage {
  position: absolute;
  top: 15%;
  bottom: 24%;
  left: 0; right: 0;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.af-profile-art {
  width: auto;
  height: auto;
  max-width: min(80%, 300px);
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .30));
  animation: af-pop .5s cubic-bezier(.34, 1.56, .64, 1);
  user-select: none;
  -webkit-user-drag: none;
}
@keyframes af-pop { from { transform: scale(.72); opacity: 0; } to { transform: none; opacity: 1; } }

/* THE LETTER TILES. Large, high-contrast and below the lion's feet, over bare
   sand. They exist only while the spelling recording plays, and the highlight
   follows that recording's own measured onsets. */
.af-profile-letters {
  position: absolute;
  bottom: 7%;
  left: 0; right: 0;
  z-index: 3;
  display: flex;
  gap: clamp(6px, 2.4vw, 12px);
  direction: ltr;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}
.af-letter {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: clamp(42px, 14vw, 62px);
  height: clamp(52px, 17vw, 76px);
  border-radius: 15px;
  font-size: clamp(24px, 7.6vw, 36px);
  font-weight: 1000;
  color: #fff8e7;
  background: linear-gradient(180deg, #3b6f8f, #1d4258);
  border: 3px solid #ffd76a;
  box-shadow: 0 5px 0 #10293a, 0 10px 18px rgba(0, 0, 0, .32);
  text-shadow: 0 2px 3px rgba(0, 0, 0, .45);
  transition: transform .14s ease, background .14s, color .14s, box-shadow .14s;
}
.af-letter.is-past {
  background: linear-gradient(180deg, #ffd76a, #f0a93c);
  border-color: #fff3c9;
  color: #3a2200;
  text-shadow: none;
}
.af-letter.is-on {
  transform: translateY(-7px) scale(1.14);
  background: linear-gradient(180deg, #fff6c9, #ffc23c);
  border-color: #ffffff;
  color: #40240a;
  text-shadow: none;
  box-shadow: 0 9px 0 #b46a00, 0 0 26px rgba(255, 207, 92, .85);
}

/* --------------------------------------------------------------------------
 * BUILD THE WORD - FRIENDS-MODE WRONG LETTER.
 *
 * style.css styles .kg1-option.wrong but has no rule at all for
 * .kg1-build-tile.wrong, so on the Build the Word board the wrong class was
 * invisible. The friends flow adds its OWN class, af-wrong, declared here and
 * nowhere else, so this styling cannot reach the 100 challenge stages, which
 * never receive it. Decoration only; it never receives a tap.
 * ------------------------------------------------------------------------ */
.kg1-build-tile.af-wrong {
  animation: af-wrong-shake .38s ease-in-out;
  border-color: #ff5c6a !important;
  background: linear-gradient(180deg, #ffd0d6, #ff9aa6) !important;
  color: #7a0d18 !important;
  box-shadow: 0 5px 0 #a52535 !important;
}
@keyframes af-wrong-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px) rotate(-3deg); }
  50% { transform: translateX(6px) rotate(2deg); }
  75% { transform: translateX(-4px); }
}

/* ==========================================================================
 * THE SECTION-COMPLETION SCREEN
 *
 * Reached once, after the LAST animal's final activity and its praise settle.
 * It reuses the approved savannah background and the Katkoot celebration
 * picture the project already ships - no new artwork, no new colour, no
 * circle, no badge, no decoration. One rounded translucent card in the same
 * language as the approved name panel, and one button.
 * ========================================================================== */
.af-section-done {
  padding: 0;
  background: #1d4a2b url(assets/animal-rescue/animal-profile-background.png) center center / cover no-repeat;
}
.af-section-done .af-done-wrap {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vh, 18px);
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 20px);
}
.af-section-done .af-done-katkoot {
  width: auto;
  height: clamp(110px, 26vh, 210px);
  max-width: min(60%, 220px);
  object-fit: contain;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .32));
}
.af-section-done .af-done-title {
  margin: 0;
  padding: clamp(8px, 1.8vh, 16px) clamp(20px, 7vw, 34px);
  border-radius: 24px;
  background: rgba(10, 34, 51, .40);
  border: 2px solid rgba(255, 255, 255, .32);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  font-size: clamp(24px, 7.6vw, 38px);
  font-weight: 1000;
  color: #ffffff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .55);
}
.af-section-done .af-done-sub {
  margin: 0;
  font-size: clamp(14px, 4.4vw, 20px);
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
}
.af-section-done .af-done-actions { width: min(88%, 340px); }

.af-done-wrap { display: flex; flex-direction: column; align-items: center; gap: clamp(7px, 2vh, 16px); width: 100%; max-width: 400px; }
.af-done-katkoot { width: auto; height: clamp(120px, 28vh, 230px); max-width: min(70%, 240px); object-fit: contain; filter: drop-shadow(0 8px 12px #0004); }
.af-done-title { margin: 0; font-size: clamp(22px, 7vw, 34px); font-weight: 1000; color: #fff; text-shadow: 0 3px 0 #a4500f, 0 5px 12px #0005; }
.af-done-stars { display: flex; gap: 5px; }
.af-done-star { font-size: clamp(24px, 7vw, 36px); color: #ffffff88; text-shadow: 0 2px 0 #0002; }
.af-done-star.is-on { color: #ffd83d; text-shadow: 0 3px 0 #a86a00, 0 0 16px #ffd83d; }
.af-done-sub { margin: 0; font-size: clamp(13px, 4vw, 18px); font-weight: 900; color: #5c2c06; text-shadow: 0 1px 0 #fff9; }

.af-root.is-hidden { display: none; }

/* ---------- short screens: 390 x 640 and shorter ---------- */
@media (max-height: 700px) {
  .af-katkoot-img { height: clamp(110px, 26vh, 190px); }
  .af-profile-art { width: min(82%, 268px); }
  .af-profile-name { font-size: clamp(28px, 9.4vw, 40px); }
  .af-btn { min-height: 44px; }
  
}
@media (max-height: 560px) {
  .af-katkoot-img { height: clamp(90px, 22vh, 150px); }
  .af-profile-art { width: min(74%, 234px); }
  .af-profile-name { font-size: clamp(25px, 8.6vw, 36px); }
  .af-profile-meaning { font-size: clamp(13px, 4.4vw, 18px); }
}

@media (prefers-reduced-motion: reduce) {
  .af-root *, .af-root *::before, .af-root *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
/* ============================================================================
 * THE INTRO SCREEN
 *
 * The approved image carries Katkoot and the three portraits already, so this
 * draws NOTHING on top of it - no circles, no checkmarks, no frames, no
 * second Katkoot.
 *
 * width:100% + height:auto keeps the file's own 941x1672 aspect exactly, so
 * nothing is stretched. It is anchored to the TOP and shown whole: `cover`
 * would crop 85 image px off each side and clip the outer portrait circles.
 * The plain grass below the image is where the controls live.
 * ========================================================================== */
.af-intro { background: #5b973d; }
.af-intro-bg {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.af-intro-controls {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  min-height: clamp(92px, 17vh, 164px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
}
.af-intro-hint {
  margin: 0;
  font-size: clamp(12px, 3.6vw, 16px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 4px #1d4a12;
}
.af-btn-replay { background: linear-gradient(180deg, #ffffffdd, #e9f6dc); color: #244d13; box-shadow: 0 4px 0 #3f6b26; }
.af-btn-replay:disabled { filter: saturate(.4) brightness(1.02); opacity: .6; }

/* While a REAL curriculum activity is running, the friends overlay steps out
   of the way entirely so the game's own board is the whole screen. */
.af-root.is-yielding { display: none; }

.af-profile-cheer { color: #0f5b2a; }

/* ==========================================================================
 * THE FRIENDS PROGRESS PILL
 *
 * It lives outside the friends overlay, because that overlay steps aside while
 * a real activity runs. It sits in the board's own reserved top band, so it
 * covers no prompt, no picture, no letter tile, no airplane canvas and no
 * touch target. It disappears the moment the run ends.
 * ========================================================================== */
[data-af-pill] {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 96;
  max-width: min(92vw, 340px);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(10, 34, 51, .62);
  border: 2px solid rgba(255, 255, 255, .34);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
  font-size: clamp(11px, 3.2vw, 14px);
  font-weight: 900;
  color: #ffffff;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  pointer-events: none;
  user-select: none;
}
