/* =====================================================================
   Garden Detective — AnimalSake
   Resource page + Canvas 2D hidden-object game widget.
   House style mirrors chameleon-colour-quest-game. The garden, leaves,
   case-file paper and confetti are procedural Canvas; only the caterpillar
   species photos are real images (the documented asset exception).
   ===================================================================== */

:root {
  --as-bg:     #fdf6e9;
  --as-card:   #fff8ec;
  --as-brown:  #4b2f20;
  --as-orange: #ff5a00;
  --as-green:  #5aa545;
  --as-yellow: #f8e7c2;
  --as-blue:   #2e9fe6;
  --as-sky:    #bfe9ff;
  --as-purple: #8b5cf6;
  --as-shadow: 0 12px 30px rgba(75, 47, 32, 0.14);

  --as-brown-soft:  #6f5b4a;
  --as-orange-deep: #e54f00;
  --as-green-deep:  #468539;
  --as-line:        #efe0c8;
  --as-card-soft:   #fffdf8;
  --radius:    22px;
  --radius-sm: 14px;
  --maxw: 980px;
  --font: "Baloo 2", "Quicksand", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--as-brown);
  background:
    radial-gradient(1200px 520px at 50% -160px, #ffe9c9 0%, rgba(255,233,201,0) 70%),
    var(--as-bg);
  line-height: 1.55;
  font-size: 17px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.12; margin: 0; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
strong { color: var(--as-orange-deep); }
a { color: var(--as-orange-deep); text-decoration: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 13px 24px;
  font-family: var(--font); font-weight: 700; font-size: 16px; color: #fff;
  cursor: pointer; text-decoration: none;
  transition: transform .12s ease, background-color .15s ease, box-shadow .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn--lg { padding: 16px 32px; font-size: 18px; }
.btn--sm { padding: 9px 14px; font-size: 14px; }
.btn--primary { background: var(--as-green); box-shadow: 0 8px 18px rgba(90,165,69,.32); }
.btn--primary:hover { background: var(--as-green-deep); }
.btn--orange { background: var(--as-orange); box-shadow: 0 8px 18px rgba(255,90,0,.28); }
.btn--orange:hover { background: var(--as-orange-deep); }
.btn--ghost { background: var(--as-card-soft); color: var(--as-brown); border: 2px solid var(--as-line); }
.btn--ghost:hover { background: #fff; border-color: #e3cfa8; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }

:focus-visible { outline: 3px solid var(--as-blue); outline-offset: 3px; border-radius: 6px; }

/* ---------- Page chrome ---------- */
.wordmark { display: inline-flex; align-items: baseline; gap: 6px; font-weight: 800; font-size: 26px; }
.wordmark__paw { font-size: 22px; }
.wordmark__a { color: var(--as-brown); }
.wordmark__b { color: var(--as-orange); }
.site-nav a { font-weight: 700; color: var(--as-brown); }
.site-nav a:hover { color: var(--as-orange-deep); }

.page { max-width: var(--maxw); margin: 0 auto; padding: 8px 20px 48px; }
.resource { display: flex; flex-direction: column; gap: 26px; }

/* ---------- Intro ---------- */
.eyebrow {
  display: inline-block; font-weight: 700; font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--as-orange); background: #fff; border: 2px solid var(--as-line); border-radius: 999px;
  padding: 5px 14px; margin-bottom: 12px;
}
.intro h1 { font-size: 40px; color: var(--as-brown); margin-bottom: 12px; }
.lede { font-size: 20px; color: var(--as-brown); max-width: 62ch; margin-bottom: 18px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 10px; }
.meta-pill { display: inline-flex; align-items: center; gap: 7px; background: var(--as-card); border: 2px solid var(--as-line); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px; color: var(--as-brown); }

/* =====================================================================
   Game widget
   ===================================================================== */
.game-shell { position: relative; border-radius: var(--radius); overflow: hidden; }

.hud {
  display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap;
  background: var(--as-card); border: 2px solid var(--as-line);
  border-radius: var(--radius); box-shadow: var(--as-shadow); padding: 12px 16px; margin-bottom: 12px;
}
.hud__title { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; color: var(--as-brown); }
.hud__logo { font-size: 22px; }
.hud__stats { display: flex; gap: 8px; flex-wrap: wrap; }
.hud__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; color: var(--as-brown); background: var(--as-yellow); border-radius: 999px; padding: 7px 13px; white-space: nowrap; }
.chip--warn { background: #ffd9c4; color: var(--as-orange-deep); }

/* play area = garden canvas + case-file panel side by side */
.play-area { display: grid; grid-template-columns: 1fr 300px; gap: 12px; align-items: start; }

.canvas-wrap { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--as-shadow); border: 2px solid var(--as-line); background: var(--as-sky); }
.game-canvas { display: block; width: 100%; height: auto; aspect-ratio: 960 / 600; touch-action: manipulation; background: var(--as-sky); cursor: pointer; }
.canvas-hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  background: rgba(255,248,236,.9); color: var(--as-brown-soft); border: 1px solid var(--as-line);
  border-radius: 999px; padding: 5px 14px; font-size: 13px; font-weight: 600; pointer-events: none;
  white-space: nowrap; max-width: 92%;
}

/* case-file panel (paper card) */
.casefile {
  position: relative; background: var(--as-yellow);
  border: 2px solid var(--as-line); border-radius: var(--radius);
  box-shadow: var(--as-shadow); padding: 14px 16px 16px; min-height: 200px;
  background-image:
    radial-gradient(rgba(75,47,32,.05) 1px, transparent 1.4px);
  background-size: 9px 9px;
}
.casefile__tab {
  display: inline-block; font-weight: 800; font-size: 14px; color: #fff;
  background: var(--as-orange); border-radius: 999px; padding: 6px 14px; margin-bottom: 12px;
  box-shadow: 0 4px 10px rgba(255,90,0,.24);
}
.casefile__body { font-size: 15px; }
.casefile__row { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.casefile__k { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--as-brown-soft); }
.casefile__v { font-size: 17px; font-weight: 700; color: var(--as-brown); }
.casefile__cluehead { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--as-brown-soft); margin-bottom: 6px; }
.casefile__clues { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.casefile__clues li {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--as-card-soft); border: 1px solid var(--as-line); border-left: 5px solid var(--as-green);
  border-radius: 10px; padding: 8px 10px; font-weight: 600; font-size: 14.5px; color: var(--as-brown);
}
.casefile__clues li .clue-ico { font-size: 17px; line-height: 1.2; flex: none; }
.casefile__note { font-size: 12.5px; color: var(--as-brown-soft); line-height: 1.45; }

/* =====================================================================
   Overlays (scoped to game-shell)
   ===================================================================== */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 420px at 50% -10%, #ffe9c9 0%, rgba(255,233,201,0) 60%), rgba(253,246,233,0.96);
  border-radius: var(--radius); overflow-y: auto;
}
.overlay[hidden] { display: none; }
.overlay__card { width: min(540px, 100%); background: var(--as-card); border: 2px solid var(--as-line); border-radius: 26px; box-shadow: var(--as-shadow); padding: 32px 28px; text-align: center; }
.overlay__card--wide { width: min(640px, 100%); }
.overlay__emoji { font-size: 56px; line-height: 1; margin-bottom: 6px; }
.overlay__title { font-size: 34px; color: var(--as-brown); margin-bottom: 10px; }
.overlay__sub { font-size: 18px; color: var(--as-brown); margin-bottom: 18px; }
.overlay__actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }

.mini-panel { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 0 0 22px; }
.mini-panel li { background: var(--as-yellow); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; }
.mini-panel strong { color: var(--as-brown); }

.howto-list { text-align: left; display: flex; flex-direction: column; gap: 10px; margin: 4px 0 22px; }
.howto-list li { background: var(--as-card-soft); border: 2px solid var(--as-line); border-left: 6px solid var(--as-green); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 15px; }

/* per-case solved card */
.solve-card { margin: 0 0 16px; }
.solve-card__img {
  display: block; width: 100%; max-width: 320px; margin: 0 auto;
  aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm);
  border: 3px solid var(--as-card-soft); box-shadow: var(--as-shadow); background: var(--as-sky);
}
.solve-card__cap { margin-top: 10px; }
.solve-card__becomes {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--as-purple); color: #fff; font-weight: 700; font-size: 15px;
  border-radius: 999px; padding: 7px 16px; box-shadow: 0 6px 14px rgba(139,92,246,.3);
}
.solve-card__becomes::before { content: "🦋"; }

.field-note { font-size: 17px; color: var(--as-brown); background: var(--as-card-soft); border: 2px solid var(--as-line); border-left: 6px solid var(--as-purple); border-radius: var(--radius-sm); padding: 16px 18px; margin-bottom: 20px; text-align: left; }

.rank-line { font-size: 18px; margin-bottom: 14px; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0 auto 16px; max-width: 540px; }
.result-grid li { background: var(--as-card-soft); border: 1px solid var(--as-line); border-radius: 12px; padding: 10px 8px; text-align: center; }
.result-grid .rk { display: block; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--as-brown-soft); margin-bottom: 4px; }
.result-grid .rv { font-size: 22px; font-weight: 800; color: var(--as-brown); }

.learned-head { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--as-brown-soft); margin: 4px 0 10px; }
.learned-list { display: flex; flex-direction: column; gap: 8px; text-align: left; margin: 0 auto 18px; max-width: 540px; }
.learned-list li {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--as-card-soft); border: 1px solid var(--as-line); border-left: 5px solid var(--as-green);
  border-radius: 12px; padding: 10px 12px; font-size: 14.5px; color: var(--as-brown);
}
.learned-list li .lico { font-size: 20px; line-height: 1.1; flex: none; }
.learned-list li strong { color: var(--as-brown); }

.highscore { font-weight: 700; color: var(--as-green-deep); margin-bottom: 18px; }

.medallion { width: 88px; height: 88px; margin: 0 auto 12px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffd25e, #ff9e1b 70%); display: grid; place-items: center; box-shadow: 0 10px 22px rgba(255,158,27,.4), inset 0 -6px 12px rgba(180,90,0,.25); border: 4px solid #fff3d6; }
.medallion__star { color: #fff; font-size: 42px; text-shadow: 0 2px 4px rgba(160,80,0,.35); }

/* =====================================================================
   Below-game content + related
   ===================================================================== */
.learn-below__title { font-size: 22px; color: var(--as-brown); margin-bottom: 14px; }
.learn-below__list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.learn-below__list li { display: flex; align-items: center; gap: 10px; background: var(--as-yellow); border-radius: var(--radius-sm); padding: 14px 16px; font-weight: 600; font-size: 15px; }
.learn-below__list li span { font-size: 24px; }

.related__title { font-size: 24px; color: var(--as-brown); margin-bottom: 16px; }
.related-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.related-card { display: flex; align-items: center; gap: 12px; background: var(--as-card); border: 2px solid var(--as-line); border-radius: var(--radius-sm); padding: 16px 18px; font-weight: 700; font-size: 16px; color: var(--as-brown); box-shadow: 0 4px 10px rgba(75,47,32,.07); transition: transform .12s ease, border-color .15s ease; }
.related-card:hover { transform: translateY(-2px); border-color: var(--as-orange); color: var(--as-orange-deep); }
.related-card__emoji { font-size: 26px; }

/* =====================================================================
   Responsive — stack the case file under the canvas on narrow screens
   ===================================================================== */
@media (max-width: 820px) {
  .play-area { grid-template-columns: 1fr; }
  .hud-clues-btn { display: inline-flex; }            /* show the Clues toggle */
  .casefile.is-collapsed { display: none; }
}

@media (max-width: 760px) {
  body { font-size: 16px; }
  .page { padding: 4px 14px 36px; }
  .resource { gap: 20px; }
  .intro h1 { font-size: 30px; }
  .lede { font-size: 17px; }
  .learn-below__list { grid-template-columns: 1fr; }

  .hud { padding: 10px 12px; gap: 8px 10px; }
  .hud__title { font-size: 17px; }
  .hud__actions { margin-left: auto; }

  .overlay__title { font-size: 28px; }
  .overlay__card { padding: 26px 20px; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
  .canvas-hint { font-size: 12px; padding: 4px 11px; }
}

@media (max-width: 380px) {
  .intro h1 { font-size: 26px; }
  .casefile__v { font-size: 16px; }
}

/* =====================================================================
   Reduced motion
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn, .related-card { transition: none; }
  .btn:hover, .related-card:hover { transform: none; }
}

/* =====================================================================
   Embed mode (?embed=1) — render bare game-shell only
   ===================================================================== */
body.embed { background: none; min-height: 0; }
body.embed
body.embed .page { padding: 0; max-width: none; }
body.embed .resource { gap: 0; }
body.embed .game-shell { border-radius: 0; }
/* Fit the whole shell to the iframe so it never scrolls or clips. */
body.embed { margin: 0; overflow: hidden; }
body.embed .resource { margin: 0; }
body.embed .game-shell { height: 100vh; display: flex; flex-direction: column; }
body.embed .canvas-wrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
body.embed .game-canvas { width: auto; height: 100%; max-width: 100%; }


/* =====================================================================
   Embed mode (?embed=1) - show ONLY the game-shell, hide page chrome.
   Mirrors mara-river-crossing. ======================================= */
html.embed { background: transparent; overflow: hidden; }
html.embed body { background: transparent; min-height: 0; margin: 0; overflow: hidden; }
html.embed
html.embed .resource { gap: 0; margin: 0; }
html.embed .page { padding: 0; }
html.embed .game-shell { margin: 0 auto; height: 100vh; display: flex; flex-direction: column; }
html.embed .canvas-wrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
html.embed .game-canvas { width: auto; height: 100%; max-width: 100%; }
