/* SAICRAFT 2.1 learning in the world: answer chips over blocks, dot arrays, coins, Word Runes, the Stall Purse,
   the Treasure Map, the Spark bar and Shrine Power icons. Linked just before style.css; phone rules are the
   media queries at the end. Keyframes start with lrn so they never clash with style.css. */

/* ---------- answer chips beside a block (world-quiz.js) ---------- */
/* Above the HUD (12), below the touch controls (20), the quiz (25), modals (30) and toasts (35). */
.wq-layer { position:absolute; inset:0; z-index:14; pointer-events:none; overflow:hidden; }
.quiz-open .wq-layer, .game-paused .wq-layer { visibility:hidden; }
/* The outer element is positioned every frame; only the inner .anchor-box animates (gotcha 3). */
.wq-anchor { position:absolute; left:0; top:0; will-change:transform; pointer-events:auto; }
.wq-box { display:flex; flex-direction:column; align-items:center; gap:10px; padding:12px 14px; border-radius:18px; background:#14243bf2; border:3px solid var(--line); color:#fff; box-shadow:0 6px 0 rgba(0,0,0,.3), 0 0 0 3px #ffd23f99, 0 0 26px #ffd23f66; animation:lrnPop .28s cubic-bezier(.2,1.5,.4,1); }
.wq-box.won { animation:lrnWin .7s ease-out forwards; }
.wq-picture { position:relative; display:flex; align-items:center; gap:10px; }
.wq-say { width:40px; height:40px; flex:none; border-radius:50%; border:3px solid var(--line); background:#3d9bff; color:#fff; font-size:18px; cursor:pointer; box-shadow:0 3px 0 rgba(0,0,0,.35); }
.wq-text { font:24px var(--display); }
.wq-price { display:inline-flex; align-items:center; gap:4px; font:26px var(--display); }
.wq-price .ico { width:26px; height:26px; }
.wq-chips { display:flex; gap:10px; }
.wq-chip { min-width:66px; min-height:60px; padding:6px 12px; border-radius:16px; border:3px solid var(--line); background:#fff; color:#1a2030; font:30px var(--display); line-height:1; box-shadow:0 5px 0 rgba(0,0,0,.35); cursor:pointer; touch-action:manipulation; transition:transform .08s, box-shadow .08s, opacity .2s; }
.wq-chip:active { transform:translateY(3px); box-shadow:0 2px 0 rgba(0,0,0,.35); }
.wq-chip:disabled { cursor:default; }
.wq-chip:disabled:not(.right):not(.wrong):not(.show-right) { opacity:.45; }
.wq-chip.right { background:#8ff06b; color:#173d0c; animation:lrnBounce .4s; }
.wq-chip.wrong { background:#ff8f9a; color:#4a0b13; animation:lrnShake .45s; }
.wq-chip.show-right { animation:lrnShowRight .3s .35s forwards; }

/* ---------- dot arrays (learning-aids.js) ---------- */
.dot-array { display:flex; flex-direction:column; gap:5px; padding:8px 42px 8px 8px; border-radius:10px; background:#0b1626; }
.dot-row { position:relative; display:flex; gap:5px; align-items:center; }
.arr-dot { width:18px; height:18px; border-radius:50%; background:#ffd23f; box-shadow:inset 0 -2px 0 #c58a00; }
.dots-small .arr-dot { width:12px; height:12px; }
.dots-small .dot-row, .dots-small { gap:3px; }
.dots-tiny .arr-dot { width:8px; height:8px; box-shadow:none; }
.dots-tiny .dot-row, .dots-tiny { gap:2px; }
.dot-count { position:absolute; left:100%; margin-left:6px; font:17px var(--display); color:#b6f03c; opacity:0; white-space:nowrap; }
/* Skip counting: each row lights in turn and shows its running total. */
.counting .dot-row .arr-dot { animation:lrnDotLit .3s calc(var(--i) * .45s) forwards; }
.counting .dot-count { animation:lrnCountIn .3s calc(var(--i) * .45s) forwards; }

/* ---------- coins (learning-aids.js, purse-ui.js) ---------- */
.coin-row { display:inline-flex; flex-wrap:wrap; align-items:center; gap:2px; }
.coin-tile { position:relative; display:inline-grid; place-items:center; flex:none; }
.coin-tile .ico { width:100%; height:100%; filter:drop-shadow(0 2px 0 rgba(0,0,0,.35)); }
.coin-tile b { position:absolute; inset:0; display:grid; place-items:center; font-family:var(--display); color:#4a2c00; -webkit-text-stroke:3px #fff1b0; paint-order:stroke fill; }
.coin-ten { width:46px; height:46px; }
.coin-ten b { font-size:19px; }
.coin-one { width:32px; height:32px; }
.coin-one b { font-size:17px; }
.coin-times { font:20px var(--display); margin:0 4px; }

/* ---------- spark and gem chips ---------- */
.spark-orb { display:inline-block; width:16px; height:16px; border-radius:50%; background:radial-gradient(circle at 35% 35%, #f4ffb0, #b6f03c 45%, #5fae12); box-shadow:0 0 8px #c8ff4a; vertical-align:-2px; }
.spark-chip, .gem-chip, .brain-chip { display:inline-flex; align-items:center; gap:5px; padding:4px 11px; border-radius:999px; background:#0007; color:#fff; font:18px var(--display); }
.gem-chip .ico { width:18px; height:18px; }

/* ---------- Word Runes (rune-ui.js) ---------- */
.rune-stone { color:#fff; border:4px solid #353a46; border-radius:18px; background:repeating-linear-gradient(115deg, #ffffff08 0 10px, transparent 10px 26px), linear-gradient(180deg, #848c9b, #5b6271); box-shadow:inset 0 3px 0 #ffffff2a, inset 0 -6px 0 #0003, 0 8px 0 #0005; padding:14px; }
.rune-panel { display:grid; gap:10px; width:min(620px, calc(100vw - 64px)); }
.rune-wallet { display:flex; gap:8px; justify-content:flex-end; flex-wrap:wrap; }
.rune-row { display:grid; grid-template-columns:52px minmax(0, 1fr) repeat(3, minmax(78px, auto)); gap:8px; align-items:center; padding:8px; border-radius:14px; background:#0003; }
.rune-tool { font-size:34px; text-align:center; line-height:1; }
.rune-name { font:19px var(--display); text-shadow:0 2px 0 #0006; }
.rune-offer { position:relative; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; min-height:66px; padding:6px; border-radius:12px; border:3px solid var(--line); background:#4a4f5c; color:#fff; cursor:pointer; box-shadow:0 4px 0 #0006; font-family:var(--body); touch-action:manipulation; }
.rune-offer:active { transform:translateY(2px); box-shadow:0 2px 0 #0006; }
.rune-offer.ready { background:linear-gradient(180deg, #c09bff, #7a4fe0); box-shadow:0 4px 0 #0006, 0 0 14px #c9a3ff; animation:lrnGlow 1.6s ease-in-out infinite; }
.rune-offer.owned { background:linear-gradient(180deg, #8ff06b, #2f8a19); }
.rune-offer.later { opacity:.45; }
.rune-roman { font:20px var(--display); line-height:1; }
.rune-tick { font:24px var(--display); line-height:1; }
.rune-cost { display:flex; flex-wrap:wrap; justify-content:center; gap:6px; font:14px var(--display); }
.rune-cost > span { display:inline-flex; align-items:center; gap:2px; }
.rune-cost .spark-orb { width:12px; height:12px; }
.cost-gem .ico { width:14px; height:14px; }
.rune-lock { position:absolute; top:-9px; right:-9px; width:22px; height:22px; }
.rune-lock .ico { width:22px; height:22px; }
.rune-tablet { display:grid; gap:14px; justify-items:center; width:min(560px, calc(100vw - 64px)); }
.rune-head { display:flex; align-items:center; gap:10px; font:22px var(--display); text-shadow:0 2px 0 #0006; }
.rune-head .rune-tool { font-size:32px; }
.rune-say { width:44px; height:44px; border-radius:50%; border:3px solid var(--line); background:#3d9bff; color:#fff; font-size:20px; cursor:pointer; box-shadow:0 3px 0 #0006; }
/* One line for any word: each letter cell shrinks with the word's length (--n) and the screen. */
.rune-word { --cell:min(42px, calc((min(560px, 100vw - 64px) - 64px) / var(--n, 8) - 6px)); display:flex; flex-wrap:nowrap; justify-content:center; gap:6px; padding:10px 12px; border-radius:14px; background:#0002; }
/* Carved letters: dark above, light below, like letters cut into stone. */
.rune-letter { width:var(--cell); height:58px; display:grid; place-items:center; font:calc(var(--cell) * .86) var(--display); color:#dfe4ee; text-shadow:0 -2px 0 #0007, 0 2px 0 #ffffff40; }
.rune-gap { width:calc(var(--cell) + 8px); height:58px; padding:0; border-radius:10px; border:3px dashed #ffd23f; background:#0005; color:#3b2205; font:calc(var(--cell) * .8) var(--display); cursor:pointer; animation:lrnGapPulse 1.4s ease-in-out infinite; }
.rune-gap.filled { border:3px solid #4a2c0c; background:repeating-linear-gradient(90deg, #d09c5e 0 7px, #bf8a4c 7px 10px); box-shadow:inset 0 3px 0 #ffffff55; animation:none; }
.rune-gap.fixed { border:3px solid #2f8a19; background:#8ff06b; color:#173d0c; animation:lrnBounce .5s; }
.letter-tile { width:60px; height:60px; padding:0; border-radius:10px; border:3px solid #4a2c0c; background:repeating-linear-gradient(90deg, #d09c5e 0 7px, #bf8a4c 7px 10px); color:#3b2205; font:36px var(--display); box-shadow:inset 0 3px 0 #ffffff55, 0 5px 0 #4a2c0c; cursor:pointer; touch-action:manipulation; }
.letter-tile:active { transform:translateY(3px); box-shadow:inset 0 3px 0 #ffffff55, 0 2px 0 #4a2c0c; }
.letter-tile.used { visibility:hidden; }
.rune-tiles { display:flex; flex-wrap:wrap; justify-content:center; gap:10px; }
.rune-actions { display:flex; gap:12px; }
.rune-actions .btn { min-width:64px; font-size:26px; }
.rune-done { font:28px var(--display); color:#f1e6ff; text-shadow:0 0 14px #a463ff, 0 2px 0 #0006; animation:lrnBounce .5s; }
.rune-tablet.right .rune-word { animation:lrnEnchant 1.2s ease-out; }
.rune-tablet.wrong .rune-word { animation:lrnShake .45s; }

/* ---------- Stall Purse (purse-ui.js) ---------- */
.purse { display:grid; gap:12px; justify-items:center; width:min(480px, calc(100vw - 64px)); padding:14px; border-radius:18px; border:4px solid #2a1a0a; background:linear-gradient(180deg, #6a4521, #3d2712); color:#fff; box-shadow:inset 0 3px 0 #ffffff22, 0 8px 0 #0005; }
.purse-head { display:flex; align-items:center; gap:12px; }
.purse-item { font-size:44px; line-height:1; }
.price-tag { display:inline-flex; align-items:center; gap:6px; padding:6px 14px; border-radius:12px; border:3px solid var(--line); background:#fff3c4; color:#5a3600; font:30px var(--display); box-shadow:0 4px 0 #0005; }
.price-tag .ico { width:30px; height:30px; }
.purse-say { width:44px; height:44px; border-radius:50%; border:3px solid var(--line); background:#3d9bff; color:#fff; font-size:20px; cursor:pointer; }
.purse-counter { width:100%; min-height:78px; display:flex; flex-wrap:wrap; align-items:center; justify-content:center; gap:4px; padding:10px; border-radius:14px; border:3px solid #2a1a0a; background:repeating-linear-gradient(90deg, #8a5a2b 0 18px, #7d5126 18px 20px); box-shadow:inset 0 4px 0 #0004; }
.purse-counter.shake { animation:lrnShake .45s; }
.purse-counter .coin-tile { cursor:pointer; }
.counter-hint { font-size:28px; opacity:.55; }
.purse-wallet { display:flex; gap:16px; }
.coin-pile { display:flex; align-items:center; gap:6px; padding:8px 14px; border-radius:16px; border:3px solid var(--line); background:linear-gradient(180deg, #fff1b0, #ffd23f); color:#5a3600; font:22px var(--display); box-shadow:0 5px 0 #0006; cursor:pointer; touch-action:manipulation; }
.coin-pile:active { transform:translateY(3px); box-shadow:0 2px 0 #0006; }
.coin-pile:disabled { opacity:.45; cursor:default; }
.purse-actions { display:flex; gap:12px; }
.purse-actions .btn { min-width:64px; font-size:26px; }
.purse-actions .btn:disabled { filter:grayscale(.7); opacity:.6; }
.purse-fill { animation:lrnGlow 1.4s ease-in-out infinite; }
.purse-sum { font:30px var(--display); text-shadow:0 2px 0 #0006; }
.purse-change { display:flex; align-items:center; gap:8px; padding:8px 12px; border-radius:14px; background:#0003; animation:lrnChangeIn .5s ease-out; }
.change-label { font-size:28px; }
.purse-prize { display:flex; align-items:center; gap:12px; }
.purse-prize .purse-sticker { font-size:56px; line-height:1; filter:drop-shadow(0 4px 0 #0005); animation:lrnSticker .7s cubic-bezier(.2,1.6,.4,1); }

/* ---------- Treasure Map (treasure-map.js) ---------- */
.treasure-card { display:grid; gap:8px; width:min(440px, calc(100vw - 64px)); padding:14px 16px; border-radius:14px; border:3px solid #8a6630; background:radial-gradient(ellipse at 30% 20%, #fff6dc, #f1dcaa 60%, #d6b674); color:#4a2e0e; box-shadow:0 8px 0 #0004, inset 0 0 34px #a0742e66; }
.treasure-head { display:flex; align-items:center; justify-content:space-between; font-size:30px; }
.treasure-say { width:44px; height:44px; border-radius:50%; border:3px solid #4a2e0e; background:#fff8e6; font-size:20px; cursor:pointer; }
.treasure-svg { width:100%; height:auto; display:block; }
.tm-rose circle { fill:#fff8e6; stroke:#8a6630; stroke-width:3; }
.tm-needle { fill:#8a6630; }
.tm-needle-n { fill:#d8362f; }
.tm-dir { font:15px var(--display); fill:#4a2e0e; text-anchor:middle; }
.tm-dir.tm-north { fill:#d8362f; font-size:19px; }
.tm-grid line { stroke:#8a663066; stroke-width:1.5; }
.tm-path { fill:none; stroke:#d8362f; stroke-width:4; stroke-dasharray:8 6; stroke-linecap:round; stroke-linejoin:round; }
.tm-start { fill:#2f8a19; stroke:#fff; stroke-width:2; }
.tm-x { font:24px var(--display); fill:#d8362f; text-anchor:middle; }
.tm-n { font:17px var(--display); fill:#4a2e0e; text-anchor:middle; }
.treasure-legs { display:flex; flex-wrap:wrap; justify-content:center; gap:12px; }
.tm-leg { display:inline-flex; align-items:center; gap:6px; padding:6px 12px; border-radius:12px; border:2px solid #8a6630; background:#fff8e6; font:22px var(--display); }
.tm-leg b { font-size:32px; line-height:1; }
.treasure-actions { display:flex; justify-content:center; }
.treasure-actions .btn { min-width:64px; font-size:26px; }
/* The minimap's N arrow pulses while a treasure map is out (add this class to a span round "N ↑"; inline-block,
   because a transform does nothing on a plain inline span). Not for SVG nodes positioned by a transform attribute. */
.treasure-north-pulse { display:inline-block; transform-origin:50% 50%; animation:lrnNorth 1s ease-in-out infinite; }

/* ---------- Spark bar and Shrine Power icons (spark.js, powers.js) ---------- */
.spark-bar { display:flex; align-items:center; gap:6px; width:min(360px, 70vw); pointer-events:auto; }
.spark-level { min-width:30px; height:30px; padding:0 4px; display:grid; place-items:center; border-radius:15px; border:2px solid var(--line); background:#2f8a19; color:#eaffd0; font:17px var(--display); text-shadow:0 1px 0 #0008; box-shadow:0 0 10px #8ff06b88; }
.spark-track { flex:1; height:11px; border-radius:6px; border:2px solid var(--line); background:#0b1f0a; overflow:hidden; }
.spark-track i { display:block; height:100%; background:linear-gradient(90deg, #b6f03c, #8ff06b); box-shadow:0 0 8px #c8ff4a; transition:width .3s; }
.power-icons { display:flex; gap:8px; pointer-events:auto; }
/* The ring shrinks as the power runs out (--left 1 → 0). */
.power-icon { --left:1; position:relative; width:44px; height:44px; display:grid; place-items:center; border-radius:50%; background:conic-gradient(#ffd23f calc(var(--left) * 360deg), #ffffff26 0); }
.power-icon::before { content:''; position:absolute; inset:4px; border-radius:50%; background:#14243b; }
.power-emoji { position:relative; font-size:22px; line-height:1; }
.power-lvl { position:absolute; right:-5px; bottom:-5px; padding:1px 4px; border-radius:8px; border:2px solid var(--line); background:#a463ff; color:#fff; font:11px var(--display); }
.power-icon.ending { animation:lrnBlink .8s ease-in-out infinite; }
.power-hearts { position:absolute; top:calc(100% + 2px); left:0; right:0; display:flex; justify-content:center; gap:1px; }
.gold-heart-ico { width:11px; height:11px; }

/* ---------- keyframes ---------- */
@keyframes lrnPop { from { transform:scale(.6); opacity:0; } to { transform:scale(1); opacity:1; } }
@keyframes lrnWin { 0% { transform:scale(1); } 30% { transform:scale(1.12); box-shadow:0 0 0 4px #8ff06b, 0 0 40px #8ff06b; } 100% { transform:scale(.7); opacity:0; } }
@keyframes lrnShake { 0%, 100% { transform:translateX(0); } 20% { transform:translateX(-8px); } 40% { transform:translateX(7px); } 60% { transform:translateX(-5px); } 80% { transform:translateX(3px); } }
@keyframes lrnBounce { 0% { transform:scale(1); } 40% { transform:scale(1.18); } 100% { transform:scale(1); } }
@keyframes lrnShowRight { to { background:#8ff06b; color:#173d0c; opacity:1; } }
@keyframes lrnDotLit { to { background:#8ff06b; box-shadow:0 0 6px #8ff06b; } }
@keyframes lrnCountIn { from { opacity:0; transform:translateX(-6px); } to { opacity:1; transform:none; } }
@keyframes lrnGlow { 0%, 100% { filter:brightness(1); } 50% { filter:brightness(1.18); } }
@keyframes lrnGapPulse { 0%, 100% { border-color:#ffd23f; } 50% { border-color:#fff3c4; } }
@keyframes lrnEnchant { 0% { box-shadow:0 0 0 #a463ff00; } 40% { box-shadow:0 0 34px #c9a3ff; background:#a463ff55; } 100% { box-shadow:0 0 0 #a463ff00; } }
@keyframes lrnChangeIn { from { transform:translateY(-14px); opacity:0; } to { transform:none; opacity:1; } }
@keyframes lrnSticker { from { transform:scale(0) rotate(-40deg); } to { transform:scale(1) rotate(0); } }
@keyframes lrnNorth { 0%, 100% { transform:scale(1); } 50% { transform:scale(1.35); color:#ffd23f; } }
@keyframes lrnBlink { 0%, 100% { opacity:1; } 50% { opacity:.45; } }

@media (prefers-reduced-motion: reduce) {
  .wq-box, .rune-offer.ready, .rune-gap, .purse-fill, .treasure-north-pulse, .power-icon.ending { animation:none; }
}

/* ---------- phones (touch mode at ≤700 wide or ≤600 tall) ---------- */
@media (max-width:700px), (max-height:600px) {
  .wq-box { gap:8px; padding:9px 10px; }
  .wq-chips { gap:8px; }
  .wq-chip { min-width:56px; min-height:52px; font-size:26px; padding:4px 10px; }
  .wq-say { width:36px; height:36px; font-size:16px; }
  .arr-dot { width:15px; height:15px; }
  .dots-small .arr-dot { width:10px; height:10px; }
  .dots-tiny .arr-dot { width:6px; height:6px; }
  .dot-array { padding-right:32px; }
  .dot-count { font-size:13px; }
  .rune-row { grid-template-columns:40px repeat(3, minmax(0, 1fr)); }
  .rune-name { display:none; }
  .rune-tool { font-size:28px; }
  .rune-offer { min-height:58px; }
  .rune-letter { height:46px; }
  .rune-gap { height:48px; }
  .letter-tile { width:52px; height:52px; font-size:30px; }
  .rune-tablet, .rune-panel, .purse { gap:10px; padding:10px; }
  .purse-item { font-size:36px; }
  .price-tag { font-size:26px; padding:4px 10px; }
  .purse-counter { min-height:64px; padding:6px; }
  .coin-ten { width:38px; height:38px; }
  .coin-one { width:28px; height:28px; }
  .coin-pile { font-size:19px; padding:6px 10px; }
  .treasure-card { padding:10px 12px; }
  .tm-leg { font-size:18px; }
  .tm-leg b { font-size:26px; }
}
/* Short landscape phones: the tablet and purse lay their parts side by side so nothing scrolls. */
@media (max-height:500px) and (orientation:landscape) {
  .rune-tablet { width:min(720px, calc(100vw - 64px)); }
  .rune-word { padding:6px 8px; }
  .rune-letter { height:40px; }
  .rune-gap { height:42px; }
  .letter-tile { width:46px; height:46px; font-size:26px; }
  .purse { width:min(640px, calc(100vw - 64px)); grid-template-columns:1fr 1fr; align-items:center; }
  .purse-head, .purse-actions { grid-column:1 / -1; }
  .purse.done { grid-template-columns:1fr; }
}
