/* Galago — the Sanctuary (five living biomes) + the care/feeding interaction.
   Builds on the .tile card system in components.css. */

/* Icon system (src/ui/icons.js) — inherits currentColor + biome theming. */
.icon { display: inline-block; vertical-align: middle; flex: 0 0 auto; }
.icon-wrap { display: inline-flex; align-items: center; }

/* ---- Home hub + shared chrome ---- */
.home-hero { display: flex; gap: var(--sp-5); align-items: center; flex-wrap: wrap; margin: var(--sp-2) 0 var(--sp-4); }
.home-greeting { font-weight: 800; color: var(--c-brand-ink); }
/* Sandy's speech: her name surfaces as a small caption over the greeting bubble. */
.sandy-says { display: flex; flex-direction: column; gap: 2px; }
.sandy-says .speaker {
  font-size: var(--fs-sm, 13px);
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--biome-deep, #c47a2c);
  text-transform: uppercase;
}
.adventure-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.nav-tile { align-items: flex-start; }
.nav-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--biome-deep, var(--c-brand-ink));
  background: color-mix(in srgb, var(--biome, var(--c-brand)) 24%, #fff);
  margin-bottom: 8px;
}
.back-btn { display: inline-flex; align-items: center; gap: 4px; }
.hint-btn { display: inline-flex; align-items: center; gap: 6px; }
.pause-btn { display: inline-flex; align-items: center; justify-content: center; }
.paw-chip .paw { display: inline-flex; color: var(--c-paw); }

/* On-photo chrome buttons (Back, topbar ghosts, hint) get the translucent "chip"
   fill so their dark label stays legible over the habitat photo — matching the
   paw-chip. Replaces the old transparent .btn.ghost (low-contrast on a photo). */
.topbar .btn.ghost,
.btn.ghost.back-btn,
.btn.ghost.hint-btn,
.btn.ghost.pause-btn {
  background: rgba(255, 251, 244, 0.8);
  -webkit-backdrop-filter: blur(6px) saturate(1.05);
  backdrop-filter: blur(6px) saturate(1.05);
  border: 1px solid rgba(255, 255, 255, 0.55);
  color: var(--c-ink);
  box-shadow: 0 6px 18px rgba(35, 18, 4, 0.18);
}

/* ============================================================
   Glass surfaces over the living-habitat photo backdrop (base.css ::after).
   Hub / map / sanctuary cards become frosted panels so the biome reads through,
   while their text sits on a light surface and stays legible. The Play screen
   keeps its own solid question card (.q-card isn't a .tile), so it's untouched.
   ============================================================ */
.tile,
.card,
.paw-chip {
  /* Higher opacity + a lighter blur: on the menus these glass surfaces sit over a
     perpetually-animating WebGL backdrop, and a large-radius backdrop-filter that
     re-samples a live canvas every frame is the most expensive idle GPU pattern on
     iPad Safari. 0.82 alpha keeps text legible while blur(5) cuts the per-frame cost. */
  background: rgba(255, 251, 244, 0.82);
  -webkit-backdrop-filter: blur(5px) saturate(1.1);
  backdrop-filter: blur(5px) saturate(1.1);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 12px 30px rgba(35, 18, 4, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}
/* keep the biome accent edge (the all-sides glass border above would flatten it) */
.tile { border-top: 8px solid var(--biome, var(--c-brand)); }

/* Headings / intros sit directly on the photo → white with a soft shadow so they
   read on both bright (desert) and dark (night) habitats. Screen body content
   that needs a surface lives on the glass cards above. */
.screen > h1 {
  color: #fff8ef;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.45);
}
.screen > p,
.sanctuary-intro {
  color: rgba(255, 250, 242, 0.96);
  text-shadow: 0 1px 9px rgba(0, 0, 0, 0.55);
}
.home-greeting { color: #fff8ef; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); }

.sanctuary-intro {
  /* sits directly on the biome photo → inherit the near-white + shadow treatment
     from `.screen > p, .sanctuary-intro` above; a dark ink colour here was illegible
     on the darker biomes (night, rainforest). */
  max-width: 56ch;
  margin: 0 0 var(--sp-4);
}

/* 3 + 2 centered: flex-wrap so the last row's two cards center under the top three. */
.sanctuary-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-4);
}

.sanctuary-card {
  flex: 0 1 clamp(240px, 30%, 320px);
  align-items: stretch;
  gap: var(--sp-3);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
}
.biome-name {
  color: var(--biome-deep, var(--c-ink-soft));
  font-weight: var(--fw-bold);
}

.creature-art {
  width: 100%;
  height: 150px;
  margin: 0 auto;
}
/* the box-fit creature-img fills the art box (full creature, shadow included) */
.creature-art .creature-img { width: 100%; height: 100%; }

/* Pre-rendered creature portraits (parts.js creatureArt). BOX-FIT model: the box
   sets BOTH width and height per context and the art is `object-fit:contain`, so
   the creature always scales to FIT its box — never overflows, never clips its
   baked ground shadow, regardless of the source image's aspect. Each context just
   sets the box size below. */
.creature-img { display: flex; align-items: center; justify-content: center; overflow: visible; }
/* max-based fit: the art scales DOWN to fit the box (definite W+H per context) but
   never forces a dimension, so it never overflows — and the width-driven contexts
   (play creature) still work because max-height against an auto-height box is a
   no-op there. Robust across flex/grid % quirks. */
.creature-img > img,
.creature-img > svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
}
.creature-img > .creature-portrait { filter: drop-shadow(0 8px 11px rgba(20, 12, 4, 0.28)); }

/* world / level tile thumbnail — full tile width, fixed height, sits above title */
.tile-creature { width: 100%; height: 108px; margin-bottom: 4px; }

/* "Choose a World" — 3 across, last 2 centered, with roomy cards so each creature
   + its baked shadow have horizontal space (no side clipping). */
.worlds-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-4);
}
.worlds-grid .tile { flex: 0 1 clamp(260px, 31%, 340px); }
.worlds-grid .tile-creature { height: 120px; }

/* locked world / sanctuary art slot: a single muted lock where the creature would be */
.tile-creature.locked-art { display: grid; place-items: center; color: var(--c-ink-soft); opacity: 0.5; }

/* hub hero (Home Sandy, Summary) — constrained box, static (no bounce) */
.creature-img.hero {
  width: clamp(140px, 22vw, 184px);
  height: clamp(150px, 24vw, 196px);
}
.creature-img.hero > .creature-portrait { filter: drop-shadow(0 14px 18px rgba(30, 16, 4, 0.38)); }
.home-hero .creature-img.hero { flex: 0 0 auto; }

/* Level-select world hero (creature + name + blurb) */
.world-hero { display: flex; gap: var(--sp-4); align-items: center; flex-wrap: wrap; margin: var(--sp-2) 0 var(--sp-4); }
.world-hero .creature-img.hero { flex: 0 0 auto; width: clamp(116px, 26vw, 176px); height: clamp(130px, 26vw, 190px); }
.world-hero-text { flex: 1 1 240px; min-width: 0; }
.world-hero h1 { margin: 0 0 4px; color: #fff8ef; text-shadow: 0 2px 14px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.45); }
.world-hero p { margin: 0; color: rgba(255, 250, 242, 0.96); text-shadow: 0 1px 9px rgba(0, 0, 0, 0.55); }

/* tile meta rows (stars / locked) with inline icons */
.coming-soon, .star-line { display: inline-flex; align-items: center; gap: 5px; }
.coming-soon { color: var(--c-ink-soft); }
.star-line { color: var(--biome-deep, #b9791f); font-weight: var(--fw-bold); }
.star-line .icon { color: #f3b53a; }

/* Summary — celebratory unlock announcement (new level, or new world + animal friend). */
.unlock-banner {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  max-width: min(440px, 92vw);
  padding: 12px 20px;
  border-radius: var(--r-lg, 18px);
  background: rgba(255, 251, 244, 0.92);
  color: var(--c-ink);
  box-shadow: 0 10px 26px rgba(35, 18, 4, 0.22);
  text-align: left;
}
.unlock-banner .icon { color: var(--biome-deep, #e0951e); flex: 0 0 auto; }
.unlock-title { font-weight: 800; }
.unlock-sub { font-size: var(--fs-sm); color: var(--c-ink-soft); margin-top: 1px; }
.unlock-banner.is-world {
  background: linear-gradient(180deg, #fff7ea, #ffe7bd);
  border: 1px solid rgba(255, 255, 255, 0.6);
}
@media (prefers-reduced-motion: no-preference) {
  .unlock-banner { animation: pop 520ms var(--ease-spring, ease-out); }
}

/* not-yet-met card: a centered lock instead of the creature */
.creature-art.not-met { display: grid; place-items: center; color: var(--c-ink-soft); opacity: 0.55; }

/* ---- state badge ---- */
.state-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
  padding: 4px 10px;
  border-radius: var(--r-pill);
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.06);
  color: var(--c-ink);
}
.state-badge[data-state='cared'] { background: #ffe9bf; color: #8a5a12; }
.state-badge[data-state='released'] { background: #ffd9e2; color: #9a2f4f; }
.state-badge[data-state='thriving'] { background: #c9f0d2; color: #1f7a3f; }

.care-line {
  min-height: 2.4em;
}
.meet-hint {
  font-style: italic;
}

/* ---- actions ---- */
.card-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-top: auto;
}
.card-actions .btn { flex: 1 1 auto; min-height: var(--tap-min); }
.feed-btn.is-broke { opacity: 0.5; }

.treats-line {
  min-height: 1.2em;
  color: var(--biome-deep, var(--c-ink-soft));
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
}

/* ---- in-card transient hint (e.g. "earn more paws") ---- */
.care-hint {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: #9a4a12;
  background: #ffe9bf;
  border-radius: var(--r-md, 10px);
  padding: 6px 10px;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity var(--dur-fast) var(--ease-out), max-height var(--dur-fast) var(--ease-out);
}
.care-hint.show { opacity: 1; max-height: 4em; }

/* ---- flying treat + joy pop (appended to <body>, position fixed) ---- */
.care-treat {
  position: fixed;
  z-index: 60;
  font-size: 26px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  will-change: transform, opacity;
}
.care-pop {
  position: fixed;
  z-index: 60;
  font-weight: 800;
  font-size: 20px;
  color: #e08a1e;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7);
  pointer-events: none;
  will-change: transform, opacity;
}

@media (prefers-reduced-motion: reduce) {
  .care-treat, .care-pop { display: none; }
}

/* ============================================================
   Living-biome view (/biome/:wid) — immersive "Visit"
   ============================================================ */
/* The biome view is full-bleed with position:fixed children (canvas, HUD, vignette).
   The global .screen entry animation uses transform: translateY, which would make
   this element the containing block for those fixed children — sizing the canvas to
   the content-max column, then snapping to full-screen when the transform clears
   (the "small → expand" jump). Override with an opacity-only fade: no transform, so
   the fixed children always size to the viewport from frame one. */
.biome-screen {
  position: relative;
  min-height: 100%;
  animation: biome-in var(--dur-med) var(--ease-out);
}
@keyframes biome-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Cinematic vignette over the 3D scene — clear centre (creature), gently darkened
   edges for a premium framed look. Sits above the canvas, below the HUD. */
.biome-screen::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 78% 78% at 50% 44%, transparent 56%, rgba(18, 11, 7, 0.34) 100%);
}

.biome-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* flat cute creature shown only when a biome has no 3D model yet */
.biome-dom-creature {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: clamp(180px, 34vw, 320px);
  height: clamp(180px, 34vw, 320px);
  z-index: 1;
  pointer-events: none;
  display: grid;
  place-items: center;
}
.biome-dom-creature svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 16px 22px rgba(20, 12, 4, 0.4));
}

.biome-hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(12px, 3vh, 24px);
  pointer-events: none; /* the creature behind stays draggable everywhere... */
}
/* ...only the actual controls catch input, so you can grab and spin the creature
   even over the title text and the happiness bar. */
.biome-hud .btn,
.biome-hud-top .biome-paws { pointer-events: auto; }
/* A soft scrim rising from the foot of the screen keeps the docked controls legible
   over a bright biome without a panel covering the creature. */
.biome-hud::before {
  content: '';
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 34vh;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(20, 12, 4, 0) 0%, rgba(20, 12, 4, 0.38) 100%);
}

.biome-top { display: flex; flex-direction: column; gap: 0; }
.biome-hud-top { display: flex; align-items: center; gap: 12px; }
.biome-paws .paw-chip { background: rgba(255, 255, 255, 0.85); }

/* Title group — name + state, centred just below the nav bar. */
.biome-title { text-align: center; margin-top: clamp(6px, 2.4vh, 18px); }
.biome-creature-name {
  color: #fff6e9;
  margin: 0 0 4px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
.biome-state {
  color: #fff3df;
  font-weight: var(--fw-bold);
  margin: 0;
  min-height: 2.6em; /* reserve height so copy-length changes don't shift layout */
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

/* Bottom control dock — happiness, treats, and the action pills, docked at the foot
   of the screen (bench presentation) rather than a panel over the creature. */
.biome-dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 2px);
}
.biome-happy { width: min(360px, 80vw); height: 14px; margin: 0; }
.biome-dock .treats-line { color: #ffe9c4; text-shadow: 0 1px 5px rgba(0, 0, 0, 0.55); }
.biome-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
}
/* Care pills — the bench's calm lavender on every action, sized down + uniform so the
   row stays compact. SVG icons inherit currentColor; no emoji. Wins over .btn / .btn.big
   by equal specificity + later source order. */
.biome-actions .btn {
  background: #c4b5f2;
  color: #2a1c3b;
  border: none;
  border-radius: 999px;
  padding: 11px 20px;
  min-height: 48px; /* >= 44pt iOS floor for the most touch-heavy care surface */
  font-size: 15px;
  font-weight: 800;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.22);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.biome-actions .btn:active { transform: scale(0.96); }
.biome-actions .btn .icon { width: 1.05em; height: 1.05em; vertical-align: middle; }
.biome-feed.is-broke { opacity: 0.55; }
/* the paw cost, set off from the label by a hairline divider */
.biome-feed .feed-cost {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding-left: 9px;
  border-left: 1px solid rgba(42, 28, 59, 0.28);
}
/* trailing heart/leaf that closes the cared / thriving copy */
.biome-state .state-emote { width: 1em; height: 1em; vertical-align: -2px; margin-left: 5px; }
.biome-dock .treats-line .icon { width: 1em; height: 1em; vertical-align: -2px; margin-right: 4px; }

/* Reset = a quiet ghost pill (overrides the lavender for this one utility control). */
.biome-actions .biome-reset {
  background: rgba(255, 255, 255, 0.14);
  color: #fff6e9;
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.32);
}

/* ============================================================
   Admin / profile console (/admin)
   ============================================================ */
.admin-status {
  color: rgba(255, 250, 242, 0.96);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
  font-weight: var(--fw-bold);
  margin: 0 0 var(--sp-3);
}
.admin-rows { display: flex; flex-direction: column; gap: var(--sp-2); }
.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: rgba(255, 251, 244, 0.74);
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--r-md, 12px);
  box-shadow: 0 8px 22px rgba(35, 18, 4, 0.18);
}
.admin-pname { font-weight: 800; }
.admin-meta { font-size: var(--fs-sm); color: var(--c-ink-soft); }
.admin-actions { display: flex; gap: var(--sp-2); flex: none; }
.admin-actions .btn { min-height: 40px; padding: 6px 14px; font-size: var(--fs-sm); }
.admin-danger { background: #f6dcd9; color: #9a2f2f; }
.btn.armed, .admin-danger.armed { background: #e8654f; color: #fff; }
.admin-token { margin-top: var(--sp-5); }
.admin-token summary {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: rgba(255, 250, 242, 0.96);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}
.admin-token-row { display: flex; gap: var(--sp-2); margin: var(--sp-2) 0; }
.admin-token-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--r-sm, 10px);
  border: 1px solid var(--c-line, #ddc8a8);
  background: rgba(255, 255, 255, 0.92);
}
.admin-token-note { font-size: var(--fs-sm); color: rgba(255, 250, 242, 0.9); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5); }

.biome-banner {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translate(-50%, 0);
  z-index: 5;
  background: rgba(255, 246, 233, 0.96);
  color: var(--c-ink, #3b2415);
  font-weight: 800;
  font-size: clamp(18px, 3.4vw, 26px);
  padding: 12px 22px;
  border-radius: var(--r-pill, 999px);
  box-shadow: 0 10px 28px rgba(60, 30, 10, 0.3);
}

/* ============================================================
   Short landscape (iPad Mini 7 ≈ 1133×744 and similar): compact the hub screens so
   the owner's 3 + 2 grids fit the fold instead of pushing the bottom row off-screen.
   Keyed on a short viewport height so the spacious look is preserved on taller
   screens (iPad Air/Pro, desktop). Only touches vertical rhythm — layout unchanged.
   ============================================================ */
@media (orientation: landscape) and (max-height: 820px) {
  .screen { gap: var(--sp-3); }

  /* World Map + Level Select: smaller hero + thumbnails + tighter tiles */
  .home-hero,
  .world-hero { margin: var(--sp-1) 0 var(--sp-2); }
  .world-hero .creature-img.hero { width: 124px; height: 138px; }
  .worlds-grid .tile { padding: var(--sp-3) var(--sp-4); }
  .worlds-grid .tile-creature { height: 84px; }

  /* Sanctuary cards: the richest cards — shrink the portrait, drop the gated
     "fun facts coming soon" placeholder, and tighten the Visit button + gaps. */
  .sanctuary-intro { margin-bottom: var(--sp-2); }
  .sanctuary-grid { gap: var(--sp-3); }
  .sanctuary-card { padding: var(--sp-3) var(--sp-4); gap: var(--sp-2); }
  .sanctuary-card .creature-art { height: 64px; }
  .sanctuary-card .care-line { min-height: 0; }
  .sanctuary-card .treats-line { min-height: 0; }
  .sanctuary-card .tile-facts { display: none; }
  .sanctuary-card .card-actions .btn.big {
    min-height: 48px;
    font-size: var(--fs-md);
    padding: var(--sp-2) var(--sp-5);
  }
}
