/* =====================================================================
   Times Table Quest — fantasy / medieval theme
   Parchment, wood, royal blue, crimson and gold. Dark theme = the castle at night.
   ===================================================================== */
:root {
  --bg: #f4e9cf;
  --bg2: #ead8ac;
  --card: #fffaf0;
  --card2: #f7ecd2;
  --ink: #3a2614;
  --muted: #7a6248;
  --primary: #2f5bb7;
  --primary-hi: #4a78d6;
  --primary-dark: #1f3f86;
  --gold: #e0a82e;
  --gold-hi: #ffd86b;
  --gold-dark: #9a6d0e;
  --gold-soft: #fff1c4;
  --crimson: #b8323a;
  --crimson-dark: #84202a;
  --good: #2f9a54;
  --good-dark: #1f733d;
  --good-soft: #dcf3df;
  --bad: #d0453c;
  --bad-soft: #fbe0dc;
  --line: #dcc596;
  --wood: #9a6438;
  --wood-dark: #5e3b1e;
  --bubble: #fffaf0;
  --op: #b8323a;
  --pattern: rgba(150, 100, 30, .07);
  --shadow: rgba(70, 45, 10, .18);
  --display: 'MedievalSharp', 'Fredoka', Georgia, serif;
}
/* Dark theme: follows the system setting, unless the viewer explicitly picked light (data-theme). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1724; --bg2: #271f30; --card: #2b2337; --card2: #342a42;
    --ink: #f6ead2; --muted: #c4b08e;
    --primary: #4f76e8; --primary-hi: #6f8fff; --primary-dark: #2c4bb0;
    --gold: #f0bf4c; --gold-dark: #e0b040; --gold-soft: #4a3a1a;
    --crimson: #e05a62; --good: #4cc274; --good-dark: #2f8a50; --good-soft: #1d4430;
    --bad: #f06a60; --bad-soft: #54282a; --line: #4d3f55; --bubble: #352b42;
    --op: #ff8a8f; --pattern: rgba(240, 190, 80, .05); --shadow: rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1724; --bg2: #271f30; --card: #2b2337; --card2: #342a42;
  --ink: #f6ead2; --muted: #c4b08e;
  --primary: #4f76e8; --primary-hi: #6f8fff; --primary-dark: #2c4bb0;
  --gold: #f0bf4c; --gold-dark: #e0b040; --gold-soft: #4a3a1a;
  --crimson: #e05a62; --good: #4cc274; --good-dark: #2f8a50; --good-soft: #1d4430;
  --bad: #f06a60; --bad-soft: #54282a; --line: #4d3f55; --bubble: #352b42;
  --op: #ff8a8f; --pattern: rgba(240, 190, 80, .05); --shadow: rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  font-family: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  background:
    repeating-linear-gradient(45deg, transparent 0 26px, var(--pattern) 26px 28px),
    repeating-linear-gradient(-45deg, transparent 0 26px, var(--pattern) 26px 28px),
    radial-gradient(circle at 8% 12%, var(--bg2) 0 110px, transparent 111px),
    radial-gradient(circle at 94% 28%, var(--bg2) 0 80px, transparent 81px),
    radial-gradient(circle at 18% 92%, var(--bg2) 0 140px, transparent 141px),
    radial-gradient(circle at 85% 85%, var(--bg2) 0 60px, transparent 61px),
    var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font-family: inherit; color: inherit; }
#app {
  max-width: 780px; margin: 0 auto; padding-block: 8px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 62px; }
.logo {
  flex: 1; margin: 0; text-align: center; font: 400 clamp(22px, 5.4vw, 32px) var(--display);
  letter-spacing: .02em; white-space: nowrap;
}
.logo-b { color: var(--crimson); text-shadow: 0 2px 0 var(--gold-hi); }
.who {
  display: flex; align-items: center; gap: 6px; max-width: 40%;
  padding: 3px 14px 3px 3px; border-radius: 999px; cursor: pointer;
  background: var(--card); border: 2px solid var(--line); font-weight: 600; font-size: 16px;
  box-shadow: 0 3px 0 var(--line);
}
.who span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .mini { width: 38px; height: 38px; flex: none; }
.who .mini svg { width: 100%; height: 100%; overflow: visible; }
.icon-btn {
  width: 46px; height: 46px; flex: none; border-radius: 50%; cursor: pointer;
  background: var(--card); border: 2px solid var(--line); font-size: 20px; box-shadow: 0 3px 0 var(--line);
}
.coins-chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none; cursor: pointer;
  padding: 6px 14px 6px 8px; border-radius: 999px; font-size: 20px; color: #5a3a00;
  background: linear-gradient(#ffe896, #f0b93a); border: 2px solid #b8860b;
  box-shadow: 0 3px 0 #9a6d0e, inset 0 2px 0 rgba(255, 255, 255, .6);
}
.coins-chip b { font-weight: 700; min-width: 1.6em; text-align: left; font-variant-numeric: tabular-nums; }
.coins-chip .coin { display: inline-block; }
/* A little market tent on the coins, so it's clear tapping them opens the market. */
.coin-tent { width: 30px; height: 30px; margin: -10px -4px -6px -2px; flex: none; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .2));
  transform-origin: 50% 100%; animation: tentBob 4s ease-in-out infinite; }
.coin-tent svg { width: 100%; height: 100%; display: block; overflow: visible; }
@keyframes tentBob { 0%, 80%, 100% { transform: none; } 86% { transform: rotate(-8deg); } 93% { transform: rotate(6deg); } }
.coins-chip.bump { animation: chipBump .5s ease; }
.coins-chip.bump .coin { animation: coinSpin .7s ease; }
@keyframes chipBump { 40% { transform: scale(1.15); } }
@keyframes coinSpin { 50% { transform: rotateY(180deg) scale(1.2); } }
@media (max-width: 520px) {
  .topbar.has-player .logo { visibility: hidden; font-size: 0; }
  .who { max-width: 52%; }
}

/* ---------- Screens & headings ---------- */
.screen { display: none; }
.screen.active { display: block; animation: enter .35s ease; }
@keyframes enter { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
h2 {
  text-align: center; font: 400 clamp(26px, 6vw, 36px) var(--display); margin: 16px 0; text-wrap: balance;
}
h2::before, h2::after { content: '⚜'; color: var(--gold); font-size: .6em; vertical-align: middle; margin: 0 .5em; }
.row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 26px; }
.screen-head { display: flex; align-items: center; gap: 12px; }
.screen-head h2 { flex: 1; margin: 12px 0; padding-right: 96px; }
@media (max-width: 520px) { .screen-head h2 { padding-right: 0; font-size: 24px; } .screen-head h2::before, .screen-head h2::after { display: none; } }

/* ---------- Buttons ---------- */
.btn {
  font-weight: 700; font-size: 21px; border-radius: 16px; padding: 13px 28px; cursor: pointer;
  color: #fff; background: linear-gradient(var(--primary-hi), var(--primary));
  border: 3px solid var(--gold); text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
  box-shadow: 0 6px 0 var(--primary-dark), inset 0 2px 0 rgba(255, 255, 255, .3);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn.ghost {
  background: var(--card); color: var(--ink); border: 3px solid var(--line); text-shadow: none;
  box-shadow: 0 6px 0 var(--line);
}
.btn.small { font-size: 17px; padding: 8px 16px; box-shadow: 0 4px 0 var(--line); border-width: 2px; }
.btn.primary.small { box-shadow: 0 4px 0 var(--primary-dark); }

/* ---------- Buddies & speech bubbles ---------- */
.mascot { width: 130px; height: 130px; flex: none; }
.mascot svg { width: 100%; height: 100%; display: block; overflow: visible; }
.mascot.small { width: 92px; height: 92px; }
.mascot.big { width: 190px; height: 190px; }
.mascot.idle svg { animation: float 3s ease-in-out infinite; }
.mood-cheer { animation: bounce .6s ease; }
.mood-oops { animation: wobble .5s ease; }
@keyframes float { 50% { transform: translateY(-6px); } }
@keyframes bounce { 30% { transform: translateY(-16px) scale(1.05); } 60% { transform: translateY(0) scale(.97); } }
@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }

.buddy { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 14px 0 24px; }
.buddy.compact { margin: 8px 0 10px; }
.bubble {
  position: relative; max-width: 400px; padding: 13px 18px; border-radius: 20px;
  background: var(--bubble); border: 3px solid var(--line); font-size: clamp(18px, 4.5vw, 22px); font-weight: 600;
  box-shadow: 0 6px 16px var(--shadow);
}
.bubble::before {
  content: ''; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  border: 10px solid transparent; border-right: 12px solid var(--line); border-left: 0;
}
.bubble.pop { animation: bubblePop .35s ease; }
@keyframes bubblePop { from { transform: scale(.85); opacity: .4; } to { transform: none; opacity: 1; } }

/* SVG details that move */
.twinkle { animation: twinkle 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes twinkle { 0%, 100% { opacity: .15; transform: scale(.4); } 50% { opacity: 1; transform: scale(1.1); } }
.blink { animation: blink 4.5s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes blink { 0%, 95%, 100% { transform: none; } 97% { transform: scaleY(.1); } }
.glow-crystal, .glow-gem, .glow-moon, .glow-runes, .glow-shell, .glow-soft, .spout { animation: glowPulse 2.2s ease-in-out infinite; }
@keyframes glowPulse { 50% { opacity: .55; } }
.jingle { animation: jingle .9s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 0; }
@keyframes jingle { 25% { transform: rotate(14deg); } 75% { transform: rotate(-14deg); } }
.orbit { animation: spin 7s linear infinite; transform-box: view-box; transform-origin: 60px 22px; }
.orbit-tower { animation: spin 7s linear infinite; transform-box: view-box; transform-origin: 40px 30px; }
@keyframes spin { to { transform: rotate(360deg); } }
.flutter { animation: flap .18s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes flap { to { transform: scaleX(.55); } }
.flame { transform-box: view-box; animation: flicker .45s ease-in-out infinite alternate; }
@keyframes flicker { to { transform: scale(1.1, .88); } }
.bob { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
.sway, .sway-slow { transform-box: fill-box; transform-origin: 50% 100%; animation: sway 3.2s ease-in-out infinite; }
.sway-slow { animation-duration: 6s; }
@keyframes sway { 25% { transform: rotate(2.5deg); } 75% { transform: rotate(-2.5deg); } }
.flag { transform-box: fill-box; transform-origin: 0 50%; animation: flagWave 1.3s ease-in-out infinite; }
@keyframes flagWave { 50% { transform: scaleX(.78) skewY(6deg); } }
.ripple { animation: glowPulse 3s ease-in-out infinite; }
.fountain { transform-box: fill-box; transform-origin: 50% 100%; animation: fountain 1.1s ease-in-out infinite; }
@keyframes fountain { 50% { transform: scaleY(1.12); opacity: .7; } }

/* ---------- Profiles (heraldic shields) ---------- */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.profile-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 26px 10px 30px; cursor: pointer; font-size: 20px; font-weight: 700;
  background: var(--card); border: 4px solid var(--gold);
  border-radius: 22px 22px 50% 50% / 22px 22px 34% 34%;
  box-shadow: 0 6px 0 var(--gold-dark), 0 10px 20px var(--shadow);
  animation: popIn .45s ease both; overflow: hidden;
}
.profile-card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 46px;
  background: repeating-linear-gradient(90deg, var(--c, var(--crimson)) 0 22px, color-mix(in srgb, var(--c, var(--crimson)) 75%, #fff) 22px 44px);
  opacity: .85;
}
.profile-card:hover { transform: translateY(-3px) rotate(-1deg); transition: transform .15s; }
.profile-main { all: unset; position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; width: 100%; }
.profile-main:focus-visible { outline: 3px solid var(--primary); border-radius: 12px; }
.profile-card .mascot { width: 100px; height: 100px; }
.pname { font-size: 21px; font-weight: 700; text-align: center; word-break: break-word; }
.pstats { font-size: 14px; color: var(--muted); font-weight: 600; }
.profile-del {
  position: absolute; z-index: 1; top: 6px; right: 8px; width: 30px; height: 30px; border-radius: 50%;
  border: none; background: rgba(255, 255, 255, .7); color: #6e4a26; font-size: 15px; cursor: pointer;
}
.profile-del:hover { background: var(--bad-soft); color: var(--bad); }
.profile-card.add { justify-content: center; border-style: dashed; color: var(--muted); min-height: 190px; box-shadow: none; }
/* ---------- Secret spells: playing on more than one device (js/sync.js) ---------- */
.profile-spell {
  position: absolute; z-index: 1; top: 6px; left: 8px; width: 30px; height: 30px; border-radius: 50%;
  border: none; background: rgba(255, 255, 255, .7); font-size: 16px; cursor: pointer;
}
.profile-spell:hover { background: var(--gold-soft); }
.profile-card.add.spell .plus { font-size: 46px; }
.spell-show { display: flex; justify-content: center; gap: 8px; margin: 6px 0 4px; }
.spell-pic {
  display: flex; align-items: center; justify-content: center; width: 54px; height: 54px; font-size: 32px;
  border-radius: 14px; background: var(--card); border: 3px solid var(--gold); box-shadow: 0 3px 0 var(--gold-dark);
}
.spell-words { text-align: center; font-weight: 600; color: var(--muted); margin: 6px 0 0; }
.spell-slots { display: flex; justify-content: center; gap: 8px; margin: 4px 0 18px; }
.spell-slot {
  display: flex; align-items: center; justify-content: center; width: 56px; height: 56px; font-size: 32px;
  border-radius: 14px; border: 3px dashed var(--line); background: var(--card2);
}
.spell-slot.on { border-style: solid; border-color: var(--gold); background: var(--card); animation: popIn .25s ease; }
.spell-slots.checking .spell-slot { animation: glowPulse .8s ease-in-out infinite; }
.spell-slots.wrong { animation: shake .4s; }
.spell-slots.wrong .spell-slot { border-color: var(--bad); background: var(--bad-soft); }
.spell-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: min(380px, 100%); margin: 0 auto 8px; }
.spell-key {
  aspect-ratio: 1; font-size: clamp(26px, 8vw, 36px); border-radius: 16px; cursor: pointer;
  border: 3px solid var(--line); background: var(--card); box-shadow: 0 4px 0 var(--line);
}
.spell-key:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
@media (max-width: 380px) { .spell-slot, .spell-pic { width: 48px; height: 48px; font-size: 28px; } }
.profile-card.add::before { display: none; }
.plus { font-size: 54px; line-height: 1; color: var(--gold); }
@keyframes popIn { from { opacity: 0; transform: scale(.85) translateY(10px); } to { opacity: 1; transform: none; } }

/* New player */
.name-label, .sub-heading { display: block; text-align: center; font-size: 22px; font-weight: 600; margin: 18px 0 10px; }
.name-input {
  display: block; width: min(360px, 100%); margin: 0 auto; padding: 14px 18px; border-radius: 16px;
  border: 3px solid var(--line); background: var(--card); color: var(--ink);
  font: 600 24px 'Fredoka', 'Trebuchet MS', sans-serif; text-align: center;
}
.name-input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 30%, transparent); }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.mascot-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.mascot-option {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 16px 4px 12px;
  border-radius: 20px; background: var(--card); border: 3px solid var(--line); cursor: pointer;
  box-shadow: 0 5px 0 var(--line); transition: transform .12s;
}
.mascot-option:hover { transform: translateY(-3px); }
.mascot-option .mascot { width: 90px; height: 90px; }
.mascot-option.selected { border-color: var(--gold); background: var(--gold-soft); box-shadow: 0 5px 0 var(--gold-dark), 0 0 0 4px color-mix(in srgb, var(--gold) 30%, transparent); }
.mname { font: 400 20px var(--display); }
.mkind { font-size: 14px; color: var(--muted); font-weight: 600; }

/* ---------- Home: status, daily quest, house & garden, signposts ---------- */
.status-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 10px; }
.stat {
  display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px;
  padding: 8px 12px; border-radius: 14px; background: var(--card); border: 2px solid var(--line);
  box-shadow: 0 4px 0 var(--line); font-weight: 600; font-size: 15px; line-height: 1.2; text-align: left;
}
.stat b { font-size: 22px; color: var(--crimson); margin-right: 2px; }
.stat small { grid-column: 2; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat-icon { grid-row: span 2; font-size: 26px; }
@media (max-width: 520px) {
  .status-row { gap: 6px; }
  .stat { padding: 6px 8px; font-size: 12.5px; column-gap: 5px; }
  .stat b { font-size: 18px; }
  .stat small { font-size: 11px; }
  .stat-icon { font-size: 20px; }
}
.daily-card {
  position: relative; display: flex; align-items: center; gap: 12px; margin: 4px 10px 14px; padding: 10px 16px;
  border-radius: 6px; background: linear-gradient(#fff6dc, #f3e2b6); color: #3a2614;
  border-top: 2px solid #d9bf85; border-bottom: 2px solid #d9bf85; box-shadow: 0 6px 14px var(--shadow);
  animation: popIn .5s ease both;
}
.daily-card::before, .daily-card::after {
  content: ''; position: absolute; top: -6px; bottom: -6px; width: 14px; border-radius: 7px;
  background: linear-gradient(90deg, #8a5a32, #c99a5a, #8a5a32);
}
.daily-card::before { left: -10px; } .daily-card::after { right: -10px; }
.scroll-icon { font-size: 34px; animation: wobble 2.4s ease-in-out infinite; }
.daily-text { flex: 1; display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.daily-text b { font: 400 20px var(--display); }
.daily-text span { font-weight: 600; }
.daily-text small { color: #7a6248; font-weight: 600; }

.garden-wrap {
  border-radius: 26px; overflow: hidden; border: 4px solid var(--wood);
  box-shadow: 0 10px 24px var(--shadow); background: linear-gradient(#62bb4f, #4ea83f);
}
.scene {
  position: relative; container-type: inline-size; aspect-ratio: 16 / 10; overflow: hidden;
  background: #9ccaf0; user-select: none; -webkit-user-select: none;
}
@media (max-width: 600px) { .scene { aspect-ratio: 4 / 3; } }
.scene-bg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.house { position: absolute; z-index: 3; }
.house-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.item {
  position: absolute; transform: translateX(-50%); background: none; border: 0; padding: 0; margin: 0;
  cursor: pointer; line-height: 0;
}
.home-item { z-index: 4; }
.item svg { width: 100%; height: auto; display: block; overflow: visible; }
.item:focus-visible { outline: 3px solid var(--gold-hi); border-radius: 8px; }
.item.tapped svg { animation: jiggle .6s ease; }
@keyframes jiggle { 20% { transform: scale(1.12, .9); } 45% { transform: scale(.95, 1.08); } 70% { transform: scale(1.04, .97); } }
.item.super svg { animation: jiggle .6s ease, superGlow 2s ease; }
@keyframes superGlow { 30% { filter: drop-shadow(0 0 12px #fff3a8) brightness(1.15); } }
.item.glow-up svg { filter: drop-shadow(0 0 10px #ffd27a); transition: filter .4s; }
.i-chest .lid { transform-box: fill-box; transform-origin: 0% 100%; transition: transform .3s ease; }
.i-chest.tapped .lid:not(.open-lid) { transform: rotate(-28deg); }
.swing-rig { transform-box: view-box; transform-origin: 112px 76px; }
.item.swinging .swing-rig { animation: swingRig 2s ease-in-out infinite; }
@keyframes swingRig { 25% { transform: rotate(-14deg); } 75% { transform: rotate(14deg); } }
.w-door-l, .w-door-r { transform-box: fill-box; transition: transform .3s ease; }
.w-door-l { transform-origin: 0% 50%; } .w-door-r { transform-origin: 100% 50%; }
.i-wardrobe.tapped .w-door-l, .i-wardrobe.tapped .w-door-r { transform: scaleX(.55); }
/* The stone tower: tap it and the buddy goes in and waves from the top window. */
.tower-spot { position: absolute; left: 0; bottom: 0; width: 15.5%; height: 108%; z-index: 3;
  background: none; border: 0; padding: 0; cursor: pointer; }
.tower-spot:focus-visible { outline: 3px solid var(--gold-hi); border-radius: 8px; }
.tower-peek { position: absolute; z-index: 2; overflow: hidden; pointer-events: none;
  border-radius: 50% 50% 0 0 / 38% 38% 0 0; }
.peek-buddy { position: absolute; left: -10%; width: 120%; bottom: 0; transform: translateY(105%);
  transition: transform .5s cubic-bezier(.3, 1.4, .5, 1); }
.peek-buddy svg { width: 100%; height: auto; display: block; }
.tower-peek.up .peek-buddy { transform: translateY(22%); animation: peekWave 1s ease-in-out .5s 3; }
@keyframes peekWave { 0%, 100% { rotate: 0deg; } 25% { rotate: -8deg; } 75% { rotate: 8deg; } }
/* Into the tower. While it's inside, the real buddy is hidden and a stand-in (same size, same spot) walks
   in through the arched doorway at full size, then shrinks fast while climbing the stairs, so it never
   bumps its head. The clip-path is the doorway arch plus the room to its right (house x 22–200,
   y 150–336), so whatever goes behind the tower wall is hidden. On the way down it's the same, reversed. */
.actor.in-tower { opacity: 0; pointer-events: none; }
.tower-inside { position: absolute; z-index: 5; pointer-events: none;
  clip-path: polygon(0% 100%, 0% 51.1%, 1.43% 46%, 5.34% 42.2%, 10.67% 40.9%, 16.01% 42.2%, 19.9% 46%, 21.35% 51.1%,
    23.6% 51.1%, 23.6% 0%, 100% 0%, 100% 100%); }
.climb-buddy { position: absolute; left: 49.44%; bottom: 0; transform: translateX(-50%); transform-origin: 50% 100%; opacity: 0; }
.climb-body.flip { transform: scaleX(-1); }
.climb-buddy svg { width: 100%; height: auto; display: block; overflow: visible; transform-origin: 50% 100%; }
.tower-inside.up .climb-buddy, .tower-inside.down .climb-buddy { opacity: 1; }
.tower-inside.up .climb-body { transform: scaleX(-1); }
.tower-inside.up .climb-buddy { animation: climbStairs 3.2s linear forwards; }
.tower-inside.down .climb-buddy { animation: climbStairs 3.2s linear reverse forwards; }
.tower-inside.up svg, .tower-inside.down svg { animation: waddle .45s ease-in-out infinite; }
.tower-inside.up .foot, .tower-inside.down .foot { transform-box: fill-box; transform-origin: center; animation: step .45s ease-in-out infinite; }
.tower-inside .foot.fr { animation-delay: -.22s; }
/* Positions: walk in along the floor, then up the 6 steps (shrinking), then on up into the dark. */
@keyframes climbStairs {
  0%   { left: 49.44%; bottom: 0%;    transform: translateX(-50%) scale(1); }
  25%  { left: 20.8%;  bottom: 0%;    transform: translateX(-50%) scale(1); }
  35%  { left: 19.38%; bottom: 6.45%; transform: translateX(-50%) scale(.8); }
  45%  { left: 15.45%; bottom: 12.9%; transform: translateX(-50%) scale(.56); }
  55%  { left: 11.52%; bottom: 19.4%; transform: translateX(-50%) scale(.42); }
  65%  { left: 7.58%;  bottom: 25.8%; transform: translateX(-50%) scale(.35); }
  75%  { left: 3.65%;  bottom: 32.3%; transform: translateX(-50%) scale(.32); }
  85%  { left: 0.84%;  bottom: 38.7%; transform: translateX(-50%) scale(.32); }
  100% { left: -3.1%;  bottom: 56%;   transform: translateX(-50%) scale(.32); }
}

/* Background animation */
.smoke { transform-box: fill-box; transform-origin: 50% 50%; opacity: 0; animation: smoke 3.9s ease-out infinite; }
@keyframes smoke { 0% { opacity: 0; transform: translate(0, 0) scale(.5); } 15% { opacity: .75; }
  100% { opacity: 0; transform: translate(14px, -60px) scale(1.8); } }
.drift { animation: drift linear infinite; }
@keyframes drift { from { transform: translateX(-450px); } to { transform: translateX(1150px); } }
.sun-rays { transform-box: view-box; animation: spin 60s linear infinite; }
.birds { animation: birds 34s linear infinite; }
@keyframes birds { from { transform: translateX(-500px); } to { transform: translateX(1100px); } }
.butterfly { animation: butterfly 10s ease-in-out infinite; }
@keyframes butterfly {
  0%, 100% { transform: translate(0, 0); } 25% { transform: translate(70px, -40px); }
  50% { transform: translate(130px, 15px); } 75% { transform: translate(50px, 45px); }
}
.butterfly .wings { transform-box: fill-box; transform-origin: center; animation: flap .2s ease-in-out infinite alternate; }
.firefly { animation: firefly 4s ease-in-out infinite; }
@keyframes firefly { 0%, 100% { transform: translateY(0); opacity: .2; } 50% { transform: translateY(-34px); opacity: 1; } }

/* Buddy and friends in the scene */
.actor {
  position: absolute; transform: translateX(-50%); background: none; border: 0; padding: 0; margin: 0;
  cursor: pointer; line-height: 0;
}
.actor-body { display: block; transition: transform .25s; }
.actor-body.flip { transform: scaleX(-1); }
.actor svg { width: 100%; height: auto; display: block; overflow: visible; }
.actor .actor-body svg { transform-origin: 50% 100%; }
.actor.walking .actor-body svg { animation: waddle .45s ease-in-out infinite; }
.actor.walking .foot { transform-box: fill-box; transform-origin: center; animation: step .45s ease-in-out infinite; }
.actor.walking .foot.fr { animation-delay: -.22s; }
@keyframes waddle { 0%, 100% { transform: rotate(-4deg) translateY(0); } 50% { transform: rotate(4deg) translateY(-4%); } }
@keyframes step { 50% { transform: translateY(-30%); } }
.actor.move-hop.walking .actor-body svg { animation: hop .5s ease-in-out infinite; }
@keyframes hop { 50% { transform: translateY(-35%) scale(.95, 1.05); } }
.actor.move-roll.walking .actor-body svg { transform-origin: 50% 60%; animation: roll .7s linear infinite; }
@keyframes roll { to { transform: rotate(360deg); } }
.actor.move-crawl.walking .actor-body svg { animation: crawl 1s ease-in-out infinite; }
@keyframes crawl { 50% { transform: scaleX(1.1) scaleY(.92); } }
.actor.move-fly .actor-body svg, .actor.move-float .actor-body svg { animation: hover 1.4s ease-in-out infinite; }
.actor.move-float .actor-body svg { animation-duration: 3.2s; }
@keyframes hover { 50% { transform: translateY(-12%); } }
.actor.trick .actor-body svg { animation: trick .9s ease !important; }
@keyframes trick { 30% { transform: translateY(-40%) rotate(-12deg); } 60% { transform: translateY(-20%) rotate(12deg) scale(1.05); } }
.actor.sitting .actor-body svg { transform: scale(.94, .9); }
.actor.swinging .actor-body { transform-origin: 50% 3%; animation: swingRig 2s ease-in-out infinite; }
.actor-bubble {
  position: absolute; bottom: 102%; left: 50%; transform: translateX(-50%); width: max-content; max-width: 44cqw;
  padding: .6cqw 1.3cqw; border-radius: 1.6cqw; line-height: 1.25; white-space: normal; text-align: center;
  font: 600 clamp(12px, 2.4cqw, 20px) 'Fredoka', sans-serif; color: #3a2614;
  background: #fffaf0; border: 2px solid #c99a5a; box-shadow: 0 3px 8px rgba(0, 0, 0, .2); pointer-events: none;
}
.actor-bubble.left { left: 0; transform: none; }
.actor-bubble.right { left: auto; right: 0; transform: none; }
.actor-bubble.pop { animation: bubblePop .3s ease; }
.fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 95; }
.puff { position: absolute; transform: translateX(-50%); font-size: max(16px, 3.4cqw); line-height: 1; animation: puffUp 2s ease-out both; }
@keyframes puffUp {
  0% { opacity: 0; transform: translate(-50%, 0) scale(.5); } 15% { opacity: 1; transform: translate(-50%, -10px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(.9); }
}

/* Signposts in the garden */
.signs {
  position: relative; z-index: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 26px 14px; padding: 16px 14px 30px;
  background:
    radial-gradient(circle at 10% 30%, rgba(255, 255, 255, .12) 0 3px, transparent 4px) 0 0 / 38px 30px,
    linear-gradient(#5cb549, #4b9f3c);
}
.sign {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
  padding: 14px 12px 12px; color: #fff6e0; text-align: center; border-radius: 12px;
  background:
    linear-gradient(rgba(0, 0, 0, .12) 1px, transparent 1px) 0 33% / 100% 33.3%,
    linear-gradient(170deg, #c08850, #9a6438 60%, #85532c);
  border: 3px solid #5e3b1e; box-shadow: 0 6px 0 #4a2c14, inset 0 2px 0 rgba(255, 255, 255, .25);
  transition: transform .15s;
}
.sign::before {   /* the post: starts just below the board + its shadow, so the hover tilt can't draw it over the board */
  content: ''; position: absolute; z-index: -1; left: 50%; top: calc(100% + 9px); width: 14px; height: 15px; margin-left: -7px;
  background: linear-gradient(90deg, #5e3b1e, #8a5a32, #5e3b1e); border-radius: 0 0 4px 4px;
}
.sign::after {    /* nails */
  content: ''; position: absolute; inset: 7px; pointer-events: none;
  background:
    radial-gradient(circle, #e7d3a8 0 2.5px, transparent 3px) 0 0 / 10px 10px no-repeat,
    radial-gradient(circle, #e7d3a8 0 2.5px, transparent 3px) 100% 0 / 10px 10px no-repeat,
    radial-gradient(circle, #e7d3a8 0 2.5px, transparent 3px) 0 100% / 10px 10px no-repeat,
    radial-gradient(circle, #e7d3a8 0 2.5px, transparent 3px) 100% 100% / 10px 10px no-repeat;
}
.sign:hover { transform: rotate(-1.5deg) translateY(-2px); }
.sign:nth-child(even):hover { transform: rotate(1.5deg) translateY(-2px); }
.sign:active { transform: translateY(4px); box-shadow: 0 2px 0 #4a2c14; }
.sign:active::before { top: calc(100% + 5px); height: 15px; }
.sign-icon { font-size: 40px; line-height: 1.1; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .25)); }
.sign-title { font: 400 24px var(--display); text-shadow: 0 2px 0 #4a2c14; }
.sign-sub { font-size: 15px; font-weight: 600; opacity: .95; }
/* All signposts the same size (owner, Nov 2026); an odd last one sits in the middle. */
.signs { grid-auto-rows: 1fr; }
.sign:last-child:nth-child(odd) { grid-column: 1 / -1; justify-self: center; width: calc(50% - 7px); }
.sign-svg { width: 1.15em; height: 1.15em; display: block; overflow: visible; }
.sign.battle .sign-svg { animation: wobble 3s ease-in-out infinite; }
.sign .soon {
  position: absolute; top: -10px; right: -6px; padding: 3px 9px; border-radius: 4px; transform: rotate(6deg);
  background: #fff6dc; color: #84202a; font-size: 12px; font-weight: 700; box-shadow: 0 2px 4px rgba(0, 0, 0, .25);
}
/* The compass needle on the Quest sign turns slowly, always (not just on hover). */
.compass-needle { transform-box: fill-box; transform-origin: 50% 50%; animation: compassSpin 9s linear infinite; }
@keyframes compassSpin { to { transform: rotate(360deg); } }
/* Target Practice, Quest and Battle: locked until the first castle is beaten (owner, Nov 2026). */
.sign.locked { filter: grayscale(.7) brightness(.82); cursor: help; }
.sign.locked:hover { transform: none; }
.sign.locked .sign-svg, .sign.locked .compass-needle { animation: none; }
.sign-lock {
  position: absolute; top: -9px; left: -9px; width: 28px; height: 28px; border-radius: 50%;
  background: #fff6dc; display: none; align-items: center; justify-content: center; font-size: 15px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3); z-index: 1;
}
.sign.locked .sign-lock { display: flex; }
/* Target Practice: a coin hint for how much spaced-practice bonus is up for grabs right now. */
.sign-coins { font-size: 15px; min-height: 1.2em; filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .25)); }
@media (max-width: 420px) {
  .signs { gap: 24px 10px; padding-inline: 10px; }
  .sign { padding-inline: 6px; }
  .sign-sub { font-size: 13px; } .sign-title { font-size: 19px; } .sign-icon { font-size: 32px; }
  .sign:last-child:nth-child(odd) { width: calc(50% - 5px); }
}

/* ---------- Market ---------- */
.stalls { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 14px; }
.stall {
  --a: #c0392b; --b: #fff6e8;
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
  padding: 0 10px 14px; overflow: hidden; border-radius: 16px; background: var(--card);
  border: 3px solid var(--wood); box-shadow: 0 6px 0 var(--wood-dark); animation: popIn .45s ease both;
  transition: transform .15s;
}
.stall:hover { transform: translateY(-4px); }
.stall:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--wood-dark); }
.awning {
  align-self: stretch; height: 40px; margin: 0 -10px 6px;
  background: repeating-linear-gradient(90deg, var(--a) 0 20px, var(--b) 20px 40px);
  -webkit-mask: radial-gradient(circle at 10px 100%, transparent 9px, #000 10px) 0 0 / 20px 100%;
  mask: radial-gradient(circle at 10px 100%, transparent 9px, #000 10px) 0 0 / 20px 100%;
}
.s-barber { --a: #e0559b; } .s-hatter { --a: #2f5bb7; } .s-furnisher { --a: #6a3fb5; } .s-gardener { --a: #2f9a54; }
.stall-icon { font-size: 46px; animation: bob 2.6s ease-in-out infinite; }
.stall-name { font: 400 19px var(--display); }
.stall-blurb { font-size: 14px; color: var(--muted); font-weight: 600; }
.stall-owned { margin-top: 4px; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 99px; background: var(--gold-soft); color: var(--gold-dark); }

.tryon { display: flex; flex-direction: column; align-items: center; margin: 0 0 12px; }
.tryon-buddy {
  width: 170px; height: 170px; padding: 20px 10px 6px;
  background: radial-gradient(ellipse at 50% 92%, rgba(0, 0, 0, .18) 0 28%, transparent 30%),
              radial-gradient(circle, color-mix(in srgb, var(--gold) 30%, transparent), transparent 65%);
}
.tryon-note { margin: 4px 0 0; color: var(--muted); font-weight: 600; text-align: center; }
.wares { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.ware {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 8px 12px; text-align: center;
  border-radius: 16px; background: var(--card); border: 3px solid var(--line); box-shadow: 0 5px 0 var(--line);
  animation: popIn .4s ease both;
}
.ware.owned { border-color: var(--gold); box-shadow: 0 5px 0 var(--gold-dark); }
.ware.sel { border-color: var(--primary); box-shadow: 0 5px 0 var(--primary-dark), 0 0 0 4px color-mix(in srgb, var(--primary) 25%, transparent); }
.ware.just-bought { animation: boughtFlash 1s ease; }
@keyframes boughtFlash { 30% { transform: scale(1.08); box-shadow: 0 0 0 8px color-mix(in srgb, var(--gold) 60%, transparent); } }
.ware-art {
  width: 112px; height: 104px; display: flex; align-items: center; justify-content: center; padding: 12px 6px 4px;
  background: radial-gradient(circle, color-mix(in srgb, var(--gold) 16%, transparent), transparent 70%);
  border: 0; border-radius: 12px; cursor: pointer;
}
.ware-art svg { max-width: 100%; max-height: 100%; overflow: visible; }
.ware-art.wiggle svg { animation: jiggle .6s; }
.ware-name { font-weight: 700; font-size: 16px; line-height: 1.2; min-height: 2.4em; display: flex; align-items: center; }
.ware-has { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.pips { display: flex; gap: 5px; }
.pips i { width: 11px; height: 11px; border-radius: 50%; background: var(--line); }
.pips i.on { background: var(--gold); box-shadow: 0 0 0 2px var(--gold-dark) inset; }
.ware-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 4px; }
.buy, .wear {
  border-radius: 12px; padding: 7px 12px; font-weight: 700; font-size: 15px; cursor: pointer;
}
.buy { color: #5a3a00; background: linear-gradient(#ffe896, #f0b93a); border: 2px solid #b8860b; box-shadow: 0 3px 0 #9a6d0e; }
.buy:active { transform: translateY(2px); box-shadow: 0 1px 0 #9a6d0e; }
.buy.short { filter: grayscale(.8); opacity: .7; }
.buy .price { white-space: nowrap; }
.wear { background: var(--card2); color: var(--ink); border: 2px solid var(--line); }
.wear.on { background: var(--good-soft); border-color: var(--good); color: var(--good); }
span.wear { cursor: default; }
.maxed { font-weight: 700; color: var(--gold-dark); padding: 7px 0; }
.closet-hint { margin: -4px auto 14px; max-width: 520px; text-align: center; font-weight: 600; font-size: 14.5px; color: var(--muted); }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }

/* Wardrobe / mirror */
.wardrobe-top { display: flex; flex-direction: column; align-items: center; }
.closet-stage { display: flex; align-items: flex-end; justify-content: center; gap: 18px; margin-top: 16px; }
.closet-art { width: 92px; }
#wardrobe-furniture:has(.i-mirror) { width: 52px; }
.closet-art svg { width: 100%; height: auto; display: block; overflow: visible; }
#wardrobe-buddy { animation: float 3s ease-in-out infinite; }
.wrow h3 { font: 400 22px var(--display); margin: 18px 0 8px; }
.wchips { display: flex; flex-wrap: wrap; gap: 10px; }
.wchip {
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 104px; padding: 8px 6px 8px; cursor: pointer;
  border-radius: 14px; background: var(--card); border: 3px solid var(--line); box-shadow: 0 4px 0 var(--line);
  font-weight: 600; font-size: 13.5px; line-height: 1.2;
}
.wchip.on { border-color: var(--gold); background: var(--gold-soft); box-shadow: 0 4px 0 var(--gold-dark); }
.wchip-art { width: 74px; height: 70px; padding-top: 6px; display: flex; align-items: center; justify-content: center; font-size: 34px; }
.wchip-art svg { width: 100%; height: 100%; overflow: visible; }

/* ---------- Table picker (shields) ---------- */
.table-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.table-btn {
  position: relative; aspect-ratio: .92; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 4px solid var(--gold); cursor: pointer; color: #2a1a10; padding-bottom: 10px;
  border-radius: 18px 18px 50% 50% / 18px 18px 40% 40%;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 70%, #fff), var(--c));
  box-shadow: 0 6px 0 var(--gold-dark), inset 0 3px 0 rgba(255, 255, 255, .45);
  transition: transform .1s, box-shadow .1s;
}
.table-btn:hover { transform: translateY(-3px); }
.table-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--gold-dark); }
.tnum { font-size: clamp(34px, 9vw, 52px); font-weight: 700; line-height: 1; text-shadow: 0 2px 0 rgba(255, 255, 255, .5); }
.tlabel { font-size: 15px; font-weight: 600; }
.tstar { position: absolute; top: 6px; right: 8px; font-size: 20px; }
.tbonus {
  position: absolute; top: 7px; left: 8px; font-size: 12px; font-weight: 700; color: #5a3a00;
  background: rgba(255, 255, 255, .55); border-radius: 8px; padding: 1px 5px;
}
/* A table not yet reached in Adventure: locked in Target Practice (owner, Nov 2026). */
.table-btn.locked { filter: grayscale(.75) brightness(.8); cursor: not-allowed; }
.table-btn.locked:hover { transform: none; }
.tlock { position: absolute; top: 7px; left: 8px; font-size: 17px; }
.tlabel-sub { font-size: 10.5px; font-weight: 600; opacity: .85; text-align: center; padding: 0 4px; margin-top: 2px; }

/* Battle's "get ready" screen */
.battle-brief { text-align: center; font-weight: 600; margin: 8px 0 20px; }
.battle-brief p { margin: 8px 0; font-size: 16px; }

/* ---------- Quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.progress {
  position: relative; flex: 1; height: 22px; border-radius: 99px; background: var(--card2);
  border: 3px solid var(--wood); margin-top: 8px;
}
#progress-fill {
  height: 100%; width: 0; border-radius: 99px; transition: width .4s ease;
  background: repeating-linear-gradient(-45deg, rgba(255, 255, 255, .25) 0 8px, transparent 8px 16px), linear-gradient(90deg, var(--gold-hi), var(--gold));
  background-size: 22px 22px, auto; animation: stripes 1s linear infinite;
}
@keyframes stripes { to { background-position: 22px 0, 0 0; } }
.progress-buddy {
  position: absolute; left: 0; top: 50%; width: 42px; height: 42px; transform: translate(-50%, -62%);
  transition: left .4s ease; pointer-events: none;
  --stone: #dcd6ea; --stone-2: #c2bad8; --roof: #7b3fd0; --flag: #e0245e;
}
.progress-buddy svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 2px 1px rgba(0, 0, 0, .25)); }
.progress.boss #progress-fill { background: linear-gradient(90deg, #ff7a8a, #c0392b); animation: none; }
.progress.boss .progress-buddy { left: auto !important; right: -18px; transform: translate(0, -62%); }
.progress.hit { animation: shake .35s; }
.quiz-count { font-weight: 700; font-size: 18px; min-width: 56px; text-align: right; }
.quiz-sub { display: flex; justify-content: center; align-items: center; gap: 10px 14px; flex-wrap: wrap; margin-top: 10px; }
.quiz-title { text-align: center; font: 400 19px var(--display); color: var(--muted); }

.flame-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 12px 2px 8px; border-radius: 99px;
  background: var(--card); border: 2px solid var(--line); font-weight: 700;
}
.flame-chip b { font-size: 19px; min-width: 1ch; }
.fl { display: inline-block; font-size: 20px; filter: grayscale(1); opacity: .45; transition: font-size .2s; }
.fl-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.flame-chip.t1 .fl, .flame-chip.t2 .fl, .flame-chip.t3 .fl, .flame-chip.t4 .fl, .flame-chip.t5 .fl {
  filter: none; opacity: 1; animation: flameDance .6s ease-in-out infinite alternate; transform-origin: 50% 100%;
}
.flame-chip.t2 .fl { font-size: 24px; }
.flame-chip.t2 { border-color: #ff9d3b; box-shadow: 0 0 10px rgba(255, 140, 40, .45); }
.flame-chip.t3 .fl { font-size: 26px; filter: hue-rotate(190deg) saturate(1.4); }
.flame-chip.t3 { border-color: #3fa9ff; box-shadow: 0 0 14px rgba(63, 169, 255, .55); }
.flame-chip.t4 .fl { font-size: 28px; filter: hue-rotate(250deg) saturate(1.5); }
.flame-chip.t4 { border-color: #a66bff; box-shadow: 0 0 16px rgba(166, 107, 255, .6); }
.flame-chip.t5 .fl { font-size: 30px; animation: flameDance .6s ease-in-out infinite alternate, rainbow 2s linear infinite; }
.flame-chip.t5 { border-color: var(--gold); box-shadow: 0 0 20px rgba(255, 210, 80, .8); }
@keyframes flameDance { to { transform: scale(1.12, .92) rotate(-4deg); } }
@keyframes rainbow { to { filter: hue-rotate(360deg) saturate(1.6); } }
.flame-chip.bump b { animation: numPop .4s ease; display: inline-block; }
@keyframes numPop { 40% { transform: scale(1.5); color: var(--crimson); } }
.flame-chip.fizzle .fl { animation: fizzle .7s ease; }
@keyframes fizzle { 40% { transform: scale(1.4) translateY(-4px); filter: grayscale(1); } 100% { transform: scale(.9); } }

/* Battle's live "best to beat" chip */
.battle-best { border-color: var(--gold); }
.battle-best.beaten {
  background: var(--gold-soft); border-color: var(--gold); color: var(--gold-dark);
  box-shadow: 0 0 14px rgba(255, 210, 80, .8); animation: bestPop .6s ease;
}
@keyframes bestPop { 40% { transform: scale(1.3) rotate(-4deg); } }

.q-area {
  position: relative; margin: 4px 0 18px; padding: 16px 10px 20px; text-align: center;
  background: var(--card); border: 3px solid var(--line); border-radius: 22px;
  box-shadow: inset 0 0 0 5px var(--card2), 0 8px 18px var(--shadow);
}
.q-prompt { font-size: clamp(20px, 5vw, 26px); font-weight: 700; margin-bottom: 8px; }
.q-prompt .big { font-size: 1.6em; color: var(--crimson); vertical-align: middle; }
.q-rows { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.q-row {
  display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: .25em;
  font-size: clamp(46px, 13vw, 84px); font-weight: 700; line-height: 1.15;
}
.q-row.long { font-size: clamp(28px, 7.5vw, 54px); }
.q-rows.multi .q-row { font-size: clamp(34px, 9vw, 58px); }
.type-pattern .q-row { font-size: clamp(28px, 7.5vw, 54px); }
.type-truefalse .q-row, .type-numberline .q-row { font-size: clamp(40px, 11vw, 70px); }
.op { color: var(--op); }
.op.comma { color: var(--muted); margin-left: -.2em; }
.answer-box {
  min-width: 1.9em; padding: 0 .2em; text-align: center; border-radius: 18px;
  border: 4px dashed var(--gold); background: var(--card2); color: var(--muted);
}
.answer-box.filled { color: var(--ink); border-style: solid; border-color: var(--primary); background: var(--card); }
.answer-box.active { border-color: var(--primary); border-style: solid; box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 25%, transparent); }
.answer-box.good { color: var(--good); border: 4px solid var(--good); background: var(--good-soft); animation: goodPop .45s ease; }
.answer-box.bad { color: var(--bad); border: 4px solid var(--bad); background: var(--bad-soft); animation: shake .4s; }
.answer-box s { color: var(--muted); font-size: .55em; vertical-align: middle; }
@keyframes goodPop { 40% { transform: scale(1.18) rotate(-3deg); } }

/* Visual multiplication: numbered 10 × 10 grid. Cell size capped at 70% of the original 26px
   (owner, Nov 2026: shrunk to help the grid type fit above the keypad without scrolling). */
.mgrid {
  --cell: min(calc(26px * .7), calc((100vw - 84px) / 11));
  display: inline-grid; grid-template-columns: repeat(11, var(--cell)); grid-auto-rows: var(--cell);
  padding: 10px; margin: 0 auto 12px; border-radius: 16px; background: var(--card2); border: 2px solid var(--line);
}
.mg-label { display: flex; align-items: center; justify-content: center; font-size: calc(var(--cell) * .55); font-weight: 700; color: var(--muted); }
.mg-cell { border: 1px solid var(--line); margin: -.5px; display: flex; }
.mg-cell i { flex: 1; margin: 2px; border-radius: 6px; background: linear-gradient(#ffd86b, #e0a82e); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15); }
/* Smaller answer box for the grid type (owner, Nov 2026: looked oversized next to the shrunk grid). */
.type-grid .q-row { margin-top: 2px; font-size: clamp(26px, 6.5vw, 38px); }

/* Pick-an-option buttons */
.choices { display: grid; gap: 12px; width: min(420px, 100%); margin: 14px auto 0; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choice, .pair {
  position: relative; padding: 16px 12px; border-radius: 18px; border: 3px solid var(--line); background: var(--card2);
  font-size: clamp(24px, 6.5vw, 32px); font-weight: 700; cursor: pointer; box-shadow: 0 5px 0 var(--line);
  transition: transform .06s, box-shadow .06s, opacity .3s;
}
.choice:hover, .pair:hover { border-color: var(--gold); }
.choice:active, .pair:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.choice.tf-true { color: var(--good); }
.choice.tf-false { color: var(--bad); }
.choice.good, .pair.matched.good { border-color: var(--good); background: var(--good-soft); color: var(--good); animation: goodPop .45s ease; }
.choice.bad { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); animation: shake .4s; }
.key-hint { position: absolute; top: 6px; left: 8px; font-size: 12px; font-weight: 700; color: var(--muted); opacity: .7; }
@media (hover: none) { .key-hint { display: none; } }

/* Matching pairs */
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; width: min(440px, 100%); margin: 6px auto 0; }
.pair-col { display: flex; flex-direction: column; gap: 12px; }
.pair.calc { color: var(--primary); }
.pair.sel { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--card)); transform: scale(1.04); }
.pair.matched { opacity: .35; filter: grayscale(1); pointer-events: none; }
.pair.nope { animation: shake .4s; border-color: var(--bad); }

/* Number line */
.nline { position: relative; height: 110px; width: min(560px, 100%); margin: 16px auto 0; touch-action: none; cursor: pointer; user-select: none; }
.nline-track { position: absolute; left: 2%; right: 2%; top: 52px; height: 6px; border-radius: 3px; background: var(--wood); opacity: .6; }
.nline-arrow { position: absolute; left: 1%; top: 22px; height: 10px; border-radius: 5px; background: var(--primary); transition: width .15s ease; }
.nline-arrow::after {
  content: ''; position: absolute; right: -14px; top: -9px;
  border: 14px solid transparent; border-left: 18px solid var(--primary); border-right: 0;
}
.tick { position: absolute; top: 40px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; }
.tick i { width: 5px; height: 30px; border-radius: 3px; background: var(--ink); opacity: .6; }
.tick span { margin-top: 6px; font-size: clamp(18px, 4.6vw, 26px); font-weight: 700; padding: 0 6px; border-radius: 10px; }
.tick.on span { background: var(--primary); color: #fff; }
.tick.good span { background: var(--good); color: #fff; }
.tick.bad span { background: var(--bad); color: #fff; }

/* Keypad: stone tiles */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(360px, 100%); margin: 0 auto; }
.key {
  height: 66px; border-radius: 16px; border: 2px solid var(--line); cursor: pointer;
  background: linear-gradient(var(--card), var(--card2));
  font-size: 30px; font-weight: 700; box-shadow: 0 5px 0 var(--line), inset 0 2px 0 rgba(255, 255, 255, .4);
  transition: transform .06s, box-shadow .06s;
}
.key:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.key.ok { background: linear-gradient(#45b86a, var(--good)); color: #fff; border: 3px solid var(--gold); box-shadow: 0 5px 0 var(--good-dark); }
.key.del { color: var(--muted); }
.keypad.disabled { opacity: .45; pointer-events: none; }
/* Battle has no confirm button — answers submit themselves (owner, Nov 2026: for speed). */
.battle-mode .key.ok { visibility: hidden; pointer-events: none; }

/* ---------- Results ---------- */
.score-card { text-align: center; }
.score { font-size: clamp(56px, 16vw, 92px); font-weight: 700; color: var(--crimson); line-height: 1; text-shadow: 0 4px 0 var(--gold-soft); animation: goodPop .6s ease; }
.score-label { font: 400 20px var(--display); color: var(--muted); margin-top: 6px; }
.score-dots { display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
.score-dots i { width: 14px; height: 14px; border-radius: 50%; animation: popIn .3s ease both; }
.score-dots i.ok { background: var(--good); box-shadow: 0 2px 0 var(--good-dark); }
.score-dots i.no { background: var(--bad); box-shadow: 0 2px 0 var(--bad-soft); }
.results-rewards { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 18px; }
.news-card {
  display: flex; align-items: center; gap: 12px; max-width: 460px; padding: 10px 18px; border-radius: 16px;
  background: var(--gold-soft); border: 2px solid var(--gold); font-weight: 600; font-size: 17px; text-align: left;
}
.news-card .news-icon { font-size: 34px; flex: none; }
.news-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.news-chip { padding: 5px 12px; border-radius: 99px; background: var(--card); border: 2px solid var(--line); font-size: 15px; font-weight: 600; }
.news-card.pending, .news-chip.pending { visibility: hidden; }
.news-card.show, .news-chip.show { animation: popIn .45s cubic-bezier(.3, 1.6, .5, 1) both; }
.learn-card {
  max-width: 520px; margin: 0 auto; padding: 14px 18px 12px; border-radius: 18px;
  background: var(--card); border: 3px solid var(--primary); box-shadow: 0 5px 0 var(--shadow);
}
.learn-card h3 { font: 400 24px var(--display); margin: 0 0 12px; color: var(--primary); }
.learn-card .missed-item { font-size: 26px; padding: 8px 16px; border-color: var(--primary-hi); animation: popIn .4s ease both; }
.learn-tip { margin: 10px 0 0; color: var(--muted); font-weight: 600; font-size: 15px; }
.learn-card.perfect { border-color: var(--good); color: var(--good); font-weight: 700; font-size: 19px; }
.coin-total {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 22px 6px 14px; border-radius: 99px;
  font-size: 34px; color: #5a3a00; background: linear-gradient(#ffe896, #f0b93a); border: 3px solid #b8860b;
  box-shadow: 0 5px 0 #9a6d0e; animation: popIn .5s ease both;
}
.coin.big { display: inline-block; animation: coinSpin 1.2s ease .3s; }
.coin-lines { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.coin-line {
  padding: 3px 10px; border-radius: 99px; background: var(--card); border: 2px solid var(--line);
  font-size: 14px; font-weight: 600; animation: popIn .4s ease both;
}
.coin-line b { color: var(--gold-dark); }
.reward-note {
  padding: 8px 16px; border-radius: 14px; background: var(--gold-soft); border: 2px solid var(--gold);
  font-weight: 600; font-size: 17px; text-align: center; animation: popIn .45s ease both;
}
.new-friend { display: inline-flex; align-items: center; gap: 10px; }
.nf-art { width: 60px; height: 60px; flex: none; animation: float 2s ease-in-out infinite; }
.nf-art svg { width: 100%; height: 100%; }
.missed { text-align: center; margin-top: 18px; }
.missed h3 { font-size: 22px; margin: 0 0 10px; }
.missed-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.missed-item { padding: 8px 14px; border-radius: 14px; background: var(--card); border: 2px solid var(--line); font-size: 20px; font-weight: 600; }
.unlocked-note { color: var(--good); }
.skip-note { color: var(--primary); }

/* ---------- Quest map ---------- */
.map { border-radius: 24px; overflow: hidden; border: 5px solid var(--wood); box-shadow: 0 10px 22px var(--shadow), inset 0 0 0 2px var(--wood-dark); }
.land { position: relative; }
.land.locked { filter: saturate(.35) brightness(.97); }
.land-head {
  position: relative; z-index: 2; width: fit-content; max-width: calc(100% - 40px); margin: 12px auto 0; padding: 8px 34px;
  font: 400 21px var(--display); color: #fff6e0; text-align: center; text-shadow: 0 2px 0 rgba(0, 0, 0, .3);
  background: linear-gradient(var(--crimson), var(--crimson-dark));
  clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 50%, 100% 100%, 0 100%, 14px 50%);
  animation: bannerIn .6s ease both;
}
@keyframes bannerIn { from { transform: scaleX(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.land-body { position: relative; }
.land-path { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.land-path polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.land-path .base { stroke: rgba(255, 255, 255, .5); stroke-width: 7; stroke-dasharray: 1 16; }
.land-path .seg {
  stroke: #ffe066; stroke-width: 11; stroke-dasharray: 1 15;
  filter: drop-shadow(0 0 4px rgba(255, 240, 150, .95));
  animation: flow 1.1s linear infinite;
}
/* Newly-lit: the marching-ants "flow" pauses while app.js's growPath() draws it in via
   stroke-dashoffset (owner, Nov 2026); it resumes once the class is removed on completion. There used
   to be a SECOND @keyframes lightUp (for stars/crowns, further down) with the same name — the later
   one always wins for every element using it, so this one was silently replaced by the star's
   scale+rotate animation, which is why a newly-lit path used to visibly fly in sideways. */
.land-path .seg.lighting { animation: none; }
@keyframes flow { to { stroke-dashoffset: -32; } }
.cluster.current {
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 0 0 4px #ffd43b, 0 0 34px 12px rgba(255, 225, 90, .85);
  animation: spotlight 2.2s ease-in-out infinite;
}
@keyframes spotlight { 50% { box-shadow: 0 0 0 4px #ffd43b, 0 0 48px 20px rgba(255, 225, 90, .95); } }
.cluster.arrive { animation: arrive 1s ease 1.4s both, spotlight 2.2s ease-in-out 2.4s infinite; }
@keyframes arrive {
  0% { transform: translate(-50%, -50%) scale(.85); box-shadow: 0 0 0 0 rgba(255, 225, 90, 0); }
  60% { transform: translate(-50%, -50%) scale(1.1); box-shadow: 0 0 0 6px #ffd43b, 0 0 70px 30px rgba(255, 225, 90, 1); }
  100% { transform: translate(-50%, -50%) scale(1); }
}
.node.boss.current .castle-art svg, .node.portal.current { filter: drop-shadow(0 0 16px rgba(255, 225, 90, 1)); }
.barrier.shatter i { transition: transform 1s cubic-bezier(.2, .8, .3, 1.2), opacity 1s ease; }
.deco { position: absolute; transform: translate(-50%, -50%); font-size: 30px; opacity: .85; pointer-events: none; animation: bob 3s ease-in-out infinite; }
.deco:nth-child(odd) { animation-delay: -1.5s; }
.theme-meadow  { background: linear-gradient(#c6f2a8, #93dc7c); }
.theme-woods   { background: linear-gradient(#8fd69a, #4ea872); }
.theme-dunes   { background: linear-gradient(#ffe8a8, #f5c46c); }
.theme-snow    { background: linear-gradient(#f0f8ff, #bcdcf5); }
.theme-coast   { background: linear-gradient(#a8e8f2, #4cb6df); }
.theme-volcano { background: linear-gradient(#ffb894, #d75a4a); }
.theme-portal  { background: radial-gradient(circle at 50% 60%, #6b3fd8, #241650 70%); }
.theme-crystal { background: linear-gradient(#d6c4ff, #9273e3); }
.theme-clouds  { background: linear-gradient(#f6f2ff, #c4d6ff); }
.theme-stars   { background: linear-gradient(#2c2766, #110d33); }
.theme-woods .land-head { background: linear-gradient(#2f7a46, #1f5a32); }
.theme-dunes .land-head { background: linear-gradient(#c9822c, #9a5e18); }
.theme-snow .land-head { background: linear-gradient(#4a78d6, #2f5bb7); }
.theme-coast .land-head { background: linear-gradient(#2a9bb8, #1d7390); }
.theme-portal .land-head, .theme-stars .land-head, .theme-crystal .land-head, .theme-clouds .land-head { background: linear-gradient(#6a3fb5, #45267f); }

.node { position: absolute; z-index: 1; transform: translate(-50%, -50%); padding: 0; border: none; background: none; cursor: pointer; }
.cluster {
  position: absolute; z-index: 1; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  min-width: 176px; padding: 12px 12px 14px; border-radius: 36px;
  background: rgba(255, 255, 255, .5); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .07), 0 4px 14px rgba(0, 0, 0, .08);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.cluster.locked { filter: grayscale(1); }
.cluster.locked > * { opacity: .6; }
.cluster.done { background: rgba(255, 236, 153, .6); }
.table-badge {
  position: relative; width: 64px; height: 64px; border: none; cursor: pointer; padding: 0 0 6px;
  border-radius: 14px 14px 50% 50% / 14px 14px 42% 42%;
  background: var(--c); color: #2a1a10; font: 700 32px 'Fredoka', 'Trebuchet MS', sans-serif;
  box-shadow: 0 0 0 4px #ffd86b, 0 7px 0 3px rgba(0, 0, 0, .18);
}
.crown { position: absolute; top: -28px; left: 50%; transform: translateX(-50%) rotate(-8deg); font-size: 30px; animation: bob 2.4s ease-in-out infinite; }
/* Stars (one per tier) and the crown (final test) under each table on the map */
.medals { display: flex; align-items: flex-end; gap: 4px; }
.star-stop, .crown-stop { position: relative; padding: 0; border: 0; background: none; cursor: pointer; line-height: 0; }
.star-stop { width: 44px; height: 44px; }
.crown-stop { width: 58px; height: 46px; margin-left: 6px; }
.star-stop svg, .crown-stop svg { width: 100%; height: 100%; overflow: visible; }
.st-shape { fill: rgba(255, 255, 255, .55); stroke: #b8a57c; stroke-width: 2.5; stroke-linejoin: round; transition: fill .3s; }
.st-shine { stroke: transparent; stroke-width: 3; stroke-linecap: round; }
.star-stop.locked { opacity: .55; }
.star-stop.open .st-shape { fill: #fff6d2; stroke: #e0a800; stroke-width: 3; stroke-dasharray: 5 4; }
.star-stop.open { animation: medalPulse 1.6s ease-in-out infinite; }
.star-stop.lit .st-shape { fill: #ffd43b; stroke: #c98a00; }
.star-stop.lit .st-shine { stroke: #fff6c2; }
.star-stop.lit svg { filter: drop-shadow(0 0 6px rgba(255, 212, 59, .95)); }
.cr-shape, .cr-band, .cr-tip { fill: rgba(255, 255, 255, .55); stroke: #b8a57c; stroke-width: 2.5; stroke-linejoin: round; }
.cr-gem { fill: #d9cfb8; }
.crown-stop.dim { opacity: .55; }
.crown-stop.ready .cr-shape, .crown-stop.ready .cr-band, .crown-stop.ready .cr-tip { fill: #fff3c4; stroke: #e0a800; stroke-width: 3; }
.crown-stop.ready { animation: medalPulse 1.4s ease-in-out infinite; }
.crown-stop.ready svg { filter: drop-shadow(0 0 10px rgba(255, 212, 59, 1)); }
.crown-stop.lit .cr-shape, .crown-stop.lit .cr-tip { fill: #ffd43b; stroke: #c98a00; }
.crown-stop.lit .cr-band { fill: #f0b400; stroke: #c98a00; }
.crown-stop.lit .cr-gem { fill: #e0245e; }
.crown-stop.lit svg { filter: drop-shadow(0 0 8px rgba(255, 212, 59, 1)); }
.crown-go {
  position: absolute; left: 50%; top: -20px; transform: translateX(-50%); padding: 2px 8px; border-radius: 10px;
  background: #b8323a; color: #fff; font: 700 12px 'Fredoka', sans-serif; line-height: 1.3; white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .2);
}
/* A star/crown that was earned since the last map visit */
.star-stop.lighting, .crown-stop.lighting { animation: lightUp 1.1s cubic-bezier(.3, 1.6, .5, 1) .5s both; }
@keyframes lightUp {
  0% { transform: scale(.4) rotate(-40deg); filter: brightness(.6); }
  60% { transform: scale(1.5) rotate(10deg); filter: brightness(1.6); }
  100% { transform: scale(1) rotate(0); filter: none; }
}
@keyframes medalPulse { 50% { transform: scale(1.12); } }
.map-daily { margin: 0 0 16px; }

/* The talking sun on the home screen */
.sun-spot {
  position: absolute; z-index: 5; transform: translate(-50%, 50%); border-radius: 50%;
  background: none; border: 0; padding: 0; cursor: pointer;
}
.sun-spot .actor-bubble { bottom: auto; top: 75%; left: auto; right: 65%; transform: none; max-width: 40cqw; }
.sun-body { transform-box: fill-box; transform-origin: 50% 50%; }
.sun-body.sun-bounce { animation: sunBounce .7s ease; }
@keyframes sunBounce { 30% { transform: scale(1.18) rotate(-8deg); } 60% { transform: scale(.94) rotate(6deg); } }

/* Number line: the answer is given with the Check button */
.nline-row { margin-top: 18px; }
#nline-ok:disabled { opacity: .45; cursor: default; filter: grayscale(.6); }
.barrier { position: absolute; z-index: 1; width: 0; height: 0; pointer-events: none; }
.barrier i {
  position: absolute; left: -16px; top: -16px; font-size: 32px; font-style: normal; line-height: 1;
  transition: transform .7s ease, opacity .7s ease; filter: drop-shadow(0 3px 1px rgba(0, 0, 0, .25));
}
.barrier.lvl-0::before, .barrier.lvl-1::before {
  content: ''; position: absolute; left: -86px; width: 172px; top: -20px; height: 40px; border-radius: 14px;
  background: rgba(60, 30, 20, .28);
}
.barrier.lvl-1::before { background: rgba(60, 30, 20, .16); }
.barrier.lvl-open i { opacity: .55; }
.nbadge { position: absolute; top: -10px; right: -10px; font-size: 26px; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .25)); }
.node.locked { filter: grayscale(1); opacity: .75; }
.node.open { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: translate(-50%, -50%) scale(1.08); } }
.node.boss { width: var(--size); height: var(--size); --stone: #dcd6ea; --stone-2: #c2bad8; --roof: #7b3fd0; --flag: #e0245e; }
.node.boss .castle-art { position: absolute; inset: 0; }
.node.boss .castle-art svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 6px 0 rgba(0, 0, 0, .2)); }
.banner-wave { transform-box: fill-box; transform-origin: 0 50%; animation: flagWave 1.6s ease-in-out infinite; }
/* The castle's guardian stands beside it; once beaten it lies asleep with floating Zzz */
.castle-boss { position: absolute; width: 58%; right: -50%; bottom: -6%; line-height: 0; }
.castle-boss svg { width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .18)); }
.node.boss:not(.locked) .castle-boss:not(.asleep) svg { animation: bob 2.2s ease-in-out infinite; }
.castle-boss.asleep { transform: rotate(-14deg) translateY(12%); transform-origin: 50% 100%; }
.castle-boss.asleep svg { animation: snore 3s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes snore { 50% { transform: scale(1.04, .96); } }
.zzz { position: absolute; right: -44%; top: 18%; pointer-events: none; font: 700 18px 'Fredoka', sans-serif; color: #5a6fd0; }
.zzz i { position: absolute; font-style: normal; opacity: 0; animation: zzz 3s ease-in infinite; }
.zzz i:nth-child(2) { animation-delay: 1s; font-size: 22px; }
.zzz i:nth-child(3) { animation-delay: 2s; font-size: 27px; }
@keyframes zzz { 0% { opacity: 0; transform: translate(0, 0); } 20% { opacity: 1; } 100% { opacity: 0; transform: translate(18px, -40px); } }
.sheet-boss { width: 120px; margin: 0 auto 4px; }
.sheet-boss svg { width: 100%; height: auto; overflow: visible; }

/* Gates between the tables of a zone: closed until the table's crown is won */
.gate { position: absolute; z-index: 1; width: 230px; height: 92px; transform: translate(-50%, -62%); pointer-events: none; }
.gate-frame { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.gate-leaf { position: absolute; top: 26px; width: 57px; height: 62px; transition: transform 1s cubic-bezier(.3, 1.3, .5, 1); }
.gate-leaf svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .2)); }
.gate-leaf.l { left: 58px; transform-origin: 0 50%; }
.gate-leaf.r { left: 115px; transform-origin: 100% 50%; }
.gate.open .gate-leaf { transform: scaleX(.16); }
.gate.open .gate-leaf svg { filter: brightness(.85); }

/* ---------- Quest world map (the island) ---------- */
.world-map {
  position: relative; border-radius: 24px; overflow: hidden; border: 5px solid var(--wood); aspect-ratio: 1000 / 1200;
  box-shadow: 0 10px 22px var(--shadow), inset 0 0 0 2px var(--wood-dark); max-width: 640px; margin: 0 auto;
}
.world-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.w-zone.locked { filter: saturate(.4) brightness(.97); }
.w-path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.w-path.base { stroke: rgba(255, 255, 255, .75); stroke-width: 8; stroke-dasharray: 2 18; }
.w-path.lit { stroke: #ffe066; stroke-width: 12; stroke-dasharray: 2 18; filter: drop-shadow(0 0 4px rgba(255, 240, 150, .95)); animation: flow 1.1s linear infinite; }
.w-path.lit.lighting { animation: none; }  /* growPath() draws it in — see the .land-path .seg.lighting note */
.w-path.rainbow { stroke: #ff9ad5; stroke-width: 10; stroke-dasharray: 2 16; filter: drop-shadow(0 0 6px #fff); animation: flow 1.4s linear infinite; }
.w-smoke circle { animation: wSmoke 4s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes wSmoke { 0% { opacity: 0; transform: translate(0, 10px) scale(.6); } 30% { opacity: .9; } 100% { opacity: 0; transform: translate(14px, -30px) scale(1.3); } }
.w-smoke circle:nth-child(2) { animation-delay: 1.3s; } .w-smoke circle:nth-child(3) { animation-delay: 2.6s; }
.w-float { animation: bob 4s ease-in-out infinite; }
.zone {
  position: absolute; transform: translate(-50%, -50%); width: 26%; height: 15%; border: 0; padding: 0; cursor: pointer;
  background: none; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px;
}
.zone-name {
  padding: 3px 10px; border-radius: 10px; background: linear-gradient(var(--crimson), var(--crimson-dark)); color: #fff6e0;
  font: 400 clamp(11px, 2.6vw, 16px) var(--display); white-space: nowrap; box-shadow: 0 3px 0 rgba(0, 0, 0, .25);
}
.zone-prog { padding: 1px 8px; border-radius: 99px; background: rgba(255, 250, 240, .92); color: #3a2614; font-weight: 700; font-size: clamp(10px, 2.3vw, 13px); }
.zone.locked .zone-name { background: #6d6478; }
.zone.current .zone-name { box-shadow: 0 0 0 3px #ffd43b, 0 0 18px 6px rgba(255, 225, 90, .9); animation: medalPulse 1.6s ease-in-out infinite; }
.zone.arrive { animation: arrive 1.2s ease .8s both; }
.zone:hover .zone-name, .zone:focus-visible .zone-name { filter: brightness(1.15); }
.world-portal {
  position: absolute; transform: translate(-50%, -50%); width: 9%; aspect-ratio: 1; border-radius: 50%; border: 0; cursor: pointer;
  font-size: clamp(16px, 4vw, 30px); background: radial-gradient(circle, #fff 0 8%, #d0a8ff 28%, #7c4dff 55%, #2b1a70 100%);
  box-shadow: 0 0 24px #b388ff; animation: pulse 1.6s ease-in-out infinite;
}
.world-home {
  position: absolute; transform: translate(-50%, -50%); width: 7%; aspect-ratio: 1; border-radius: 50%;
  border: 3px solid #fff6e0; cursor: pointer; font-size: clamp(14px, 3.4vw, 24px);
  background: radial-gradient(circle, #fff6e0 0 40%, #e8c274 100%); box-shadow: 0 3px 0 #b8860b, 0 0 10px rgba(0, 0, 0, .2);
}
.world-home:active { transform: translate(-50%, -50%) translateY(2px); box-shadow: 0 1px 0 #b8860b; }
.world-buddy { position: absolute; width: 9%; aspect-ratio: 1; transform: translate(-50%, -50%); pointer-events: none; }
.world-buddy svg { width: 100%; height: 100%; overflow: visible; animation: float 2.4s ease-in-out infinite; }
#world .map-daily { max-width: 640px; margin: 0 auto 14px; }

/* ---------- Castle round: the boss asks the questions, the player's buddy cheers beside it ---------- */
.boss-mode #quiz-mascot { width: 118px; height: 110px; }
.boss-mode #quiz-mascot svg { overflow: visible; }
.mascot.ally { width: 64px; height: 64px; align-self: flex-end; }
.progress.boss .progress-buddy { width: 46px; height: 44px; }
.progress.boss #progress-fill { background: linear-gradient(90deg, #8fd3ff, #ffd43b); }
.node.boss.done { --flag: #ffd43b; --roof: #f59f00; }
.node.portal {
  width: 96px; height: 96px; border-radius: 50%; color: #fff; font-size: 38px; font-weight: 700;
  background: radial-gradient(circle, #fff 0 8%, #d0a8ff 28%, #7c4dff 55%, #2b1a70 100%);
  box-shadow: 0 0 34px #b388ff;
}
.node.portal.open { animation: pulse 1.6s ease-in-out infinite, glow 2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 60px #e0c3ff; } }
.node.portal.locked { background: #5f5a73; box-shadow: none; filter: none; opacity: .8; }
.map-buddy { position: absolute; z-index: 2; width: 64px; height: 64px; transform: translate(-50%, -50%); pointer-events: none; }
.map-buddy svg { width: 100%; height: 100%; overflow: visible; animation: float 2.4s ease-in-out infinite; }

/* ---------- Popup ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
           max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: rgba(30, 15, 5, .5);
}
@media (min-width: 600px) { .sheet { align-items: center; } }
.sheet-card {
  position: relative; width: min(520px, 100%); padding: 22px 18px 26px; border-radius: 24px;
  background: var(--bg); border: 4px solid var(--wood); box-shadow: 0 20px 50px rgba(0, 0, 0, .35), inset 0 0 0 3px var(--gold-soft);
  animation: popIn .3s ease;
}
.sheet-card h3 { margin: 0 48px 4px; text-align: center; font: 400 26px var(--display); }
.sheet-close { position: absolute; top: 12px; right: 12px; }
.sheet-note { text-align: center; color: var(--muted); font-weight: 600; margin: 0; }

/* ---------- Debug view (?debug) ---------- */
.debug {
  margin-top: 28px; padding: 14px; border-radius: 16px; background: var(--card); border: 2px dashed var(--line);
  font-family: system-ui, sans-serif; font-size: 14px; overflow-x: auto;
}
.debug h4 { margin: 0 0 6px; }
.debug p { margin: 6px 0; color: var(--muted); }
.debug table { border-collapse: collapse; width: 100%; }
.debug th, .debug td { padding: 4px 8px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.debug tr.now td { background: color-mix(in srgb, var(--primary) 15%, transparent); }
.debug .st-correct { color: var(--good); }
.debug .st-mistake { color: var(--bad); }
.debug .st-new { color: var(--muted); }

/* ---------- Effects ---------- */
.confetti { position: fixed; top: -40px; pointer-events: none; z-index: 30; animation: fall 2.6s ease-in forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
.flying-coin {
  position: fixed; z-index: 40; font-size: 26px; margin: -13px 0 0 -13px; pointer-events: none;
  transition: transform .7s cubic-bezier(.5, -.3, .6, 1), opacity .7s ease-in;
}
.spark {
  position: fixed; z-index: 30; pointer-events: none; color: var(--gold); font-size: 22px; margin: -11px 0 0 -11px;
  animation: sparkFly .8s ease-out forwards;
}
@keyframes sparkFly { from { transform: translate(0, 0) scale(.4); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(1.1); opacity: 0; } }
.toast {
  position: fixed; z-index: 35; left: 50%; top: max(70px, calc(env(safe-area-inset-top, 0px) + 60px));
  transform: translateX(-50%); padding: 10px 20px; border-radius: 16px; max-width: calc(100vw - 32px);
  background: var(--gold-soft); color: var(--ink); border: 3px solid var(--gold); font-weight: 700; font-size: 18px;
  box-shadow: 0 8px 20px var(--shadow); animation: toast 2.6s ease both; pointer-events: none; text-align: center;
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -20px) scale(.9); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  20% { transform: translate(-50%, 0) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -10px); }
}

@media (max-width: 540px) {
  .table-grid { grid-template-columns: repeat(3, 1fr); }
  .mascot-pick { grid-template-columns: repeat(2, 1fr); }
  .mascot { width: 104px; height: 104px; }
  .mascot.small { width: 76px; height: 76px; }
  .mascot.big { width: 160px; height: 160px; }
  .buddy { gap: 10px; }
  .wares { grid-template-columns: repeat(2, 1fr); }
  .stalls { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .wchip { width: calc(33.3% - 7px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
