:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede6;
  --text: #22211f;
  --muted: #6b6a64;
  --faint: #a3a19a;
  --border: rgba(0, 0, 0, 0.12);
  --border-strong: rgba(0, 0, 0, 0.22);
  --good: #0f6e56;
  --good-bg: #e1f5ee;
  --bad: #a32d2d;
  --bad-bg: #fcebeb;
  --gold: #ef9f27;
  --gold-ink: #633806;
  --gold-bg: #faeeda;
  --note: #fde68a;
  --note-edge: #e8c547;
  --accent: #7f77dd;
  --tc: #7f77dd;
  --tc-bg: color-mix(in srgb, var(--tc) 14%, var(--surface));
  --tc-ink: color-mix(in srgb, var(--tc) 70%, black);
  --radius: 12px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a19;
    --surface: #262624;
    --surface-2: #31312e;
    --text: #f1efe8;
    --muted: #b4b2a9;
    --faint: #7d7b74;
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.24);
    --good: #5dcaa5;
    --good-bg: #133b30;
    --bad: #f09595;
    --bad-bg: #4a1d1d;
    --gold-ink: #fac775;
    --gold-bg: #3d2a0c;
    --tc-bg: color-mix(in srgb, var(--tc) 26%, var(--surface));
    --tc-ink: color-mix(in srgb, var(--tc) 45%, white);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
/* No double-tap zoom anywhere (iOS Safari honors manipulation; it ignores touch-action: none). */
html, body, button, a, input, .screen { touch-action: manipulation; }
/* While practicing, the page never scrolls or bounces: drags are for notes and writing. */
html:has(.practice), html:has(.practice) body { overflow: hidden; height: 100%; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }

#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; }
.screen {
  display: flex; flex-direction: column; min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  gap: 12px;
}
.practice { position: relative; height: 100dvh; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* ---------- generic ---------- */
.btn {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius);
  padding: 12px 18px; font-size: 17px; font-weight: 600;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.block { width: 100%; }
.btn.small { padding: 6px 12px; font-size: 14px; font-weight: 500; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; font-size: 18px; flex: none;
}
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
h1 { font-size: 26px; margin: 0; }
h2 { font-size: 20px; margin: 0; }

/* ---------- name screen ---------- */
.welcome { justify-content: center; }
.logo {
  width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 40px; font-weight: 700; margin: 0 auto 8px;
}
.profile-list { display: flex; flex-direction: column; gap: 8px; }
.profile-btn {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; font-size: 18px; text-align: left;
}
.name-input {
  width: 100%; height: 52px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); padding: 0 14px; font-size: 18px;
}
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--gold-bg); color: var(--gold-ink);
}

/* ---------- home ---------- */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tab {
  height: 48px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
  font-size: 26px; font-weight: 600; color: var(--muted);
}
.tab.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.today { background: var(--tc-bg); border: 1px solid color-mix(in srgb, var(--tc) 40%, transparent); color: var(--tc-ink); }
.today .label { font-size: 13px; opacity: 0.85; }
.today .big { font-size: 22px; font-weight: 700; margin: 2px 0 4px; }
.units { display: flex; flex-direction: column; gap: 6px; }
.unit {
  display: grid; grid-template-columns: 56px 34px 1fr auto; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; text-align: left; width: 100%;
}
.unit.active { border: 2px solid var(--tc); padding: 9px 11px; }
.unit.locked { color: var(--faint); background: transparent; }
.unit .tname { font-size: 18px; font-weight: 700; color: var(--tc-ink); }
.unit.locked .tname { color: var(--faint); }
.belt { width: 34px; height: 12px; border-radius: 4px; border: 1px solid var(--border-strong); }
.unit .stage { font-size: 14px; color: var(--muted); }
.meter { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.meter > div { height: 100%; background: var(--good); border-radius: 6px; transition: width 0.6s; }

/* ---------- practice frame ---------- */
.bar { display: flex; align-items: center; gap: 10px; }
.bar .sub { font-size: 13px; color: var(--muted); }
.bar .title { font-size: 18px; font-weight: 700; }
.stage-area { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.status { display: flex; align-items: center; gap: 10px; min-height: 52px; }
.stars { display: flex; gap: 2px; }
.stars svg { width: 22px; height: 22px; display: block; }
.stars .on { color: var(--gold); }
.stars .off { color: var(--border-strong); }
.tokens { display: flex; gap: 4px; }
.token {
  width: 18px; height: 18px; border-radius: 3px; background: var(--note);
  border-bottom: 3px solid var(--note-edge); transform: rotate(-6deg);
}
.status .spacer { flex: 1; }
.idk { white-space: nowrap; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 10px; font-size: 14px; color: var(--muted); }
.feedback { min-height: 22px; text-align: center; font-size: 15px; font-weight: 600; color: var(--muted); }
.feedback.bad { color: var(--bad); }
.feedback.good { color: var(--good); }

/* ---------- answer input ---------- */
.bar .spacer { flex: 1; }
.inputarea { display: flex; flex-direction: column; gap: 8px; }
.wpad { position: relative; height: clamp(150px, 25dvh, 240px); border-radius: 16px; border: 2px dashed var(--border-strong); background: var(--surface); }
.wcanvas { width: 100%; height: 100%; display: block; touch-action: none; color: var(--text); border-radius: 14px; cursor: crosshair; }
.whint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); pointer-events: none; font-size: 16px; }
.wbar { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.wbar .key { font-size: 18px; }
.wbar .key.ok { font-size: 26px; }

/* ---------- keypad ---------- */
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  height: clamp(48px, 7.5dvh, 62px); border-radius: 14px; border: 1px solid var(--border-strong);
  background: var(--surface); font-size: 26px; font-weight: 600; touch-action: manipulation; user-select: none;
}
.key:active, .key.hit { background: var(--surface-2); transform: scale(0.96); }
.key.ok { background: var(--good-bg); color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }

/* ---------- sticky note peek ---------- */
.peek {
  position: relative; overflow: hidden; border-radius: 8px; background: var(--surface-2); user-select: none; -webkit-user-select: none; touch-action: none; cursor: grab;
  display: grid; place-items: center; font-weight: 700; color: var(--tc-ink);
}
.peek-ans { font-size: inherit; }
.note {
  position: absolute; inset: 0; background: var(--note); border-bottom: 4px solid var(--note-edge);
  border-radius: 4px 4px 2px 2px; touch-action: none; cursor: grab;
  display: grid; place-items: center; color: #7a5c00; font-size: 14px; font-weight: 600;
  transition: transform 0.3s cubic-bezier(.2,.9,.3,1.2);
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.note::before { content: ""; position: absolute; top: 5px; width: 22px; height: 3px; border-radius: 2px; background: rgba(122, 92, 0, 0.35); }
.note.gone { transform: translateY(-140%) rotate(-12deg) !important; opacity: 0; transition: transform 0.4s, opacity 0.4s; pointer-events: none; }
.note.locked { filter: grayscale(0.7) brightness(0.92); }
.peekslot { width: 120px; height: 84px; font-size: 44px; flex: none; }
.peekslot > .peek, .pslot > .peek { width: 100%; height: 100%; }

/* ---------- read column (stage 1) & fill (stage 3) ---------- */
.column { flex: 1; min-height: 0; display: grid; grid-template-rows: repeat(11, 1fr); gap: 3px; }
.crow {
  display: grid; grid-template-columns: 1fr 90px; align-items: center; padding: 0 14px;
  border-radius: 10px; background: var(--tc-bg); color: var(--tc-ink);
  font-size: clamp(16px, 3.2dvh, 26px); font-weight: 600; min-height: 0;
}
.crow .pslot { height: 86%; }
.crow .peek { font-size: inherit; background: var(--surface); }
.crow .cell { text-align: center; border-bottom: 2px solid color-mix(in srgb, var(--tc) 40%, transparent); min-height: 1.2em; }
.crow.cur { outline: 3px solid var(--tc); background: var(--surface); }
.crow.done .cell { border-color: transparent; color: var(--good); }
.crow.todo { background: transparent; color: var(--muted); }

/* ---------- build column (stage 2) ---------- */
.stack { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 4px; }
.sitem { display: flex; justify-content: space-between; align-items: center; border-radius: 12px; padding: 0 16px; color: var(--tc-ink); flex: none; }
.sitem.cur { height: clamp(64px, 11dvh, 92px); font-size: clamp(30px, 5.5dvh, 44px); font-weight: 700; background: var(--tc-bg); border: 3px solid var(--tc); }
.sitem.cur .cell { min-width: 2.4em; text-align: center; border-bottom: 3px solid var(--tc); }
.sitem.done { height: clamp(30px, 4.6dvh, 40px); font-size: clamp(17px, 2.8dvh, 22px); }
.sitem.done b { font-weight: 700; }

/* ---------- drill (stage 4/5) ---------- */
.progress { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--good); transition: width 0.3s; }
.flash {
  flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.problem { font-size: clamp(48px, 10dvh, 76px); font-weight: 700; letter-spacing: 1px; }
.answer {
  min-width: 140px; height: clamp(64px, 10dvh, 84px); border-radius: 16px; border: 3px solid var(--border-strong);
  display: grid; place-items: center; font-size: clamp(36px, 7dvh, 52px); font-weight: 700; padding: 0 16px; background: var(--surface);
}
.answer.missed { border-color: var(--bad); }
.reveal { background: var(--tc-bg); color: var(--tc-ink); border-radius: 14px; padding: 10px 18px; text-align: center; font-size: 26px; font-weight: 700; }
.reveal small { display: block; font-size: 14px; font-weight: 500; opacity: 0.85; margin-top: 2px; }

/* ---------- results / intro ---------- */
.center-card { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.badge-circle { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; background: var(--good-bg); color: var(--good); font-size: 44px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; text-align: left; }
.tile .n { font-size: 28px; font-weight: 700; }
.tile .l { font-size: 13px; color: var(--muted); }
.callout { width: 100%; background: var(--gold-bg); color: var(--gold-ink); border-radius: var(--radius); padding: 12px 14px; font-weight: 600; text-align: left; }
.btn-row { display: flex; gap: 10px; width: 100%; }
.btn-row .btn { flex: 1; }

/* ---------- grid ---------- */
.fgrid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; }
.fgrid > div { aspect-ratio: 1; border-radius: 4px; display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.fgrid .hdr { font-weight: 700; font-size: 13px; }
.fgrid .c { cursor: pointer; border: 1px solid var(--border); background: var(--surface); }
.fgrid .c.learning { background: #9fe1cb; border-color: transparent; }
.fgrid .c.weak { background: #f5c4b3; border-color: transparent; }
.fgrid .c.mastered { background: #1d9e75; border-color: transparent; }
.fgrid .c.sel { outline: 2px solid var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; border: 1px solid var(--border); }
.trouble { display: flex; flex-wrap: wrap; gap: 6px; }
.trouble span { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 4px 10px; font-weight: 600; }

/* ---------- effects ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.conf { position: absolute; width: 9px; height: 13px; border-radius: 2px; animation: fly 1.2s ease-out forwards; }
.toast {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px;
  padding: 16px 22px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  animation: toastIn 0.45s cubic-bezier(.2,.9,.3,1.3); min-width: 220px; max-width: 90vw;
}
.toast .t1 { font-size: 14px; color: var(--muted); }
.toast .t2 { font-size: 30px; font-weight: 800; }
.toast.small { top: auto; bottom: 28%; padding: 10px 16px; }
.toast.small .t2 { font-size: 18px; }
.toast.out { opacity: 0; transform: translateX(-50%) translateY(-10px); transition: all 0.35s; }

@keyframes fly { 0% { transform: translate(0, 0) rotate(0); opacity: 1; } 100% { transform: translate(var(--x), var(--y)) rotate(600deg); opacity: 0; } }
@keyframes toastIn { 0% { transform: translateX(-50%) scale(0.6); opacity: 0; } 100% { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes drop { 0% { transform: translateY(-110%); opacity: 0; } 70% { transform: translateY(5%); opacity: 1; } 100% { transform: translateY(0); } }
@keyframes pushDown { 0% { transform: translateY(-60%) scale(1.25); } 100% { transform: none; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 60% { transform: translateX(8px); } }
@keyframes spin { 0% { transform: scale(0.3) rotate(-120deg); } 60% { transform: scale(1.5) rotate(15deg); } 100% { transform: scale(1) rotate(0); } }
.drop { animation: drop 0.5s ease-out; }
.push { animation: pushDown 0.45s cubic-bezier(.2,.9,.3,1.2); }
.pop { animation: pop 0.35s ease; }
.shake { animation: shake 0.3s ease; }
.spin { animation: spin 0.45s ease-out; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
@media (min-width: 700px) {
  .screen { padding-top: 24px; padding-bottom: 24px; }
}

/* ---------- settings ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button {
  height: 46px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2);
  font-size: 16px; font-weight: 600; color: var(--muted);
}
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.preview { display: flex; align-items: center; gap: 4px; margin-top: 12px; min-height: 30px; }
.preview.stars svg { width: 24px; height: 24px; }

/* ---------- adventure pieces (used only by the Adventure theme) ---------- */
.wallet {
  display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 15px;
  padding: 3px 9px 3px 6px; border-radius: 999px; background: var(--gold-bg); color: var(--gold-ink);
}
.wallet svg { display: block; }
.hearts { gap: 3px; }
.heart { display: block; line-height: 0; }
.heart.heal { animation: heal 0.4s ease-out; }
.heart.hurt { animation: hurt 0.45s ease-out; }
@keyframes heal { 0% { transform: scale(0.6); filter: brightness(2); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes hurt { 0%, 40% { filter: brightness(3) saturate(0); transform: scale(1.3); } 100% { filter: none; transform: scale(1); } }
.damage-flash { position: absolute; inset: 0; pointer-events: none; z-index: 5; background: radial-gradient(ellipse 70% 55% at 50% 45%, rgba(220, 30, 30, 0.42), rgba(220, 30, 30, 0) 75%); animation: dmg 0.45s ease-out forwards; }
@keyframes dmg { from { opacity: 1; } to { opacity: 0; } }
.flygem { position: absolute; transition: transform 0.75s cubic-bezier(.45, -0.35, .7, 1), opacity 0.75s ease-in; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.gem-earned { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 700; color: var(--gold-ink); }

.hero-wrap { width: 190px; height: 200px; margin-top: 24px; }
.hero-scene { width: 100%; height: 100%; overflow: visible; }
.hero-scene .arm-l { transform-box: view-box; transform-origin: 66px 88px; transform: rotate(10deg); animation: armL 0.45s 0.35s ease-out forwards; }
.hero-scene .arm-r { transform-box: view-box; transform-origin: 94px 88px; transform: rotate(-10deg); animation: armR 0.45s 0.35s ease-out forwards; }
@keyframes armL { to { transform: rotate(-162deg); } }
@keyframes armR { to { transform: rotate(162deg); } }
.hero-scene .sword { opacity: 0; transform-box: view-box; transform-origin: 80px 50px; animation: swordIn 0.4s 0.75s ease-out forwards; }
@keyframes swordIn { 0% { opacity: 0; transform: translateY(12px) scale(0.4); } 60% { opacity: 1; transform: translateY(-3px) scale(1.12); } 100% { opacity: 1; transform: none; } }
.hero-scene .glint { opacity: 0; transform-box: view-box; transform-origin: 80px 6.5px; animation: glint 1.4s 1.15s ease-in-out infinite; }
@keyframes glint { 0%, 100% { opacity: 0; transform: scale(0.3) rotate(0); } 30% { opacity: 1; transform: scale(1.3) rotate(45deg); } 60% { opacity: 0; } }
.hero-scene .rays { opacity: 0; transform-box: view-box; transform-origin: 80px 30px; animation: raysIn 0.6s 0.8s ease-out forwards, spin 10s linear infinite; }
@keyframes raysIn { to { opacity: 0.2; } }
@keyframes spin { to { transform: rotate(360deg); } }
.hero-scene .hero { animation: heroHop 0.35s 0.75s ease-out; transform-box: view-box; transform-origin: 80px 160px; }
@keyframes heroHop { 50% { transform: translateY(-5px); } }

/* ---------- Adventure theme ---------- */
:root[data-theme="adventure"] {
  --bg: #10201a;
  --surface: #1c3326;
  --surface-2: #27442f;
  --text: #f6ecd0;
  --muted: #cbbd96;
  --faint: #8a8166;
  --border: rgba(232, 184, 58, 0.28);
  --border-strong: rgba(232, 184, 58, 0.55);
  --good: #8fe39a;
  --good-bg: #1f4a2c;
  --bad: #ff9a8a;
  --bad-bg: #4d2020;
  --gold: #f2c443;
  --gold-ink: #ffe08a;
  --gold-bg: #3b2f0e;
  --note: #f1dfae;
  --note-edge: #b8964a;
  --accent: #d9a62e;
  --radius: 6px;
  --tc-bg: color-mix(in srgb, var(--tc) 28%, var(--surface));
  --tc-ink: color-mix(in srgb, var(--tc) 40%, #fff8e0);
  --font-pixel: "Pixelify Sans", ui-monospace, monospace;
  color-scheme: dark;
}
[data-theme="adventure"] body {
  background-color: var(--bg);
  background-image:
    radial-gradient(rgba(242, 196, 67, 0.07) 1px, transparent 1px),
    radial-gradient(rgba(143, 227, 154, 0.05) 1px, transparent 1px);
  background-size: 22px 22px, 37px 37px;
  background-position: 0 0, 11px 7px;
}
/* Pixel font for titles only: numbers stay in the clear rounded font so digits never blur together. */
[data-world] h1,
[data-world] h2,
[data-world] .bar .title,
[data-world] .today .label,
[data-world] .toast .t1 { font-family: var(--font-title, var(--font-pixel)); letter-spacing: 0.5px; }
[data-world] .card,
[data-world] .tile,
[data-world] .unit,
[data-world] .profile-btn {
  border: 2px solid var(--border-strong); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
}
[data-world] .unit.locked { border-style: dashed; border-color: var(--border); box-shadow: none; }
[data-world] .btn.primary,
[data-world] .tab.on,
[data-world] .seg button.on {
  background: var(--accent); border-color: #8a6410; color: #2a1c04;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
}
[data-world] .key {
  background: linear-gradient(#3a2b1a, #2c2013); border: 2px solid #6b4f26; color: var(--text);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35);
}
[data-world] .key.ok { background: linear-gradient(#2f6b3b, #23522d); border-color: #4c9a5a; color: #e8ffe6; }
[data-world] .answer,
[data-world] .wpad { border: 3px solid var(--border-strong); background: rgba(0, 0, 0, 0.25); }
[data-world] .answer.missed { border-color: var(--bad); }
[data-world] .toast { background: #20140a; border: 3px solid var(--gold); color: var(--text); }
[data-world] .logo { background: var(--accent); color: #2a1c04; }
[data-world] .icon-btn { border: 2px solid var(--border); }

/* ---------- camp (Adventure home) ---------- */
.camp-screen { padding-top: 0; }
.camp { position: relative; margin: 0 -16px; height: clamp(280px, 86vw, 450px); overflow: hidden; border-bottom: 3px solid var(--border-strong); }
.camp-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud { position: absolute; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 10px 12px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-top { top: max(0px, env(safe-area-inset-top)); }
.plate { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; background: rgba(16, 24, 18, 0.72); border: 2px solid var(--border-strong); border-radius: 10px; padding: 5px 8px; }
.plate .pname { font-family: var(--font-title, var(--font-pixel)); font-size: 18px; color: var(--text); margin-right: 2px; }
.hud-btns { display: flex; gap: 6px; }
.hud-btns .icon-btn { background: rgba(16, 24, 18, 0.72); }
.hud-items {
  position: absolute; left: 12px; top: calc(max(0px, env(safe-area-inset-top)) + 58px); display: flex; align-items: center; gap: 6px;
  background: rgba(16, 24, 18, 0.72); border: 2px solid var(--border-strong); border-radius: 10px; padding: 4px 10px 4px 6px;
  color: var(--gold-ink); font-weight: 700; font-size: 14px;
}
.hud-items svg { display: block; }
.quest-btn { margin-top: 12px; font-size: 19px; padding: 14px; }

.camp-svg .cloud { animation: drift 38s ease-in-out infinite alternate; }
.camp-svg .c2 { animation-duration: 52s; animation-direction: alternate-reverse; }
.camp-svg .c3 { animation-duration: 44s; }
@keyframes drift { to { transform: translateX(34px); } }
.camp-svg .tree { animation: sway 5s ease-in-out infinite alternate; }
.camp-svg .tree.far { animation-duration: 6.5s; }
@keyframes sway { from { transform: rotate(-1.2deg); } to { transform: rotate(1.2deg); } }
.camp-svg .tuft { animation: tuft 2.4s ease-in-out infinite alternate; }
@keyframes tuft { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
.camp-svg .flag { transform-box: fill-box; transform-origin: 0 50%; animation: flag 0.9s ease-in-out infinite alternate; }
@keyframes flag { from { transform: skewY(-10deg) scaleX(0.9); } to { transform: skewY(8deg) scaleX(1.05); } }
.camp-svg .fl { transform-box: fill-box; transform-origin: 50% 100%; animation: flick 0.45s ease-in-out infinite alternate; }
.camp-svg .f2 { animation-duration: 0.36s; }
.camp-svg .f3 { animation-duration: 0.28s; }
@keyframes flick { 0% { transform: scale(1, 1) skewX(0); } 50% { transform: scale(1.05, 1.13) skewX(-4deg); } 100% { transform: scale(0.94, 0.93) skewX(4deg); } }
.camp-svg .glow { transform-box: fill-box; transform-origin: center; animation: glowPulse 1.1s ease-in-out infinite alternate; }
@keyframes glowPulse { from { opacity: 0.8; transform: scale(0.97); } to { opacity: 1; transform: scale(1.05); } }
.camp-svg .spark { animation: riseL 1.8s ease-out infinite; }
.camp-svg .spark:nth-of-type(even) { animation-name: riseR; }
@keyframes riseL { from { transform: translate(0, 0); opacity: 1; } to { transform: translate(-9px, -58px); opacity: 0; } }
@keyframes riseR { from { transform: translate(0, 0); opacity: 1; } to { transform: translate(8px, -52px); opacity: 0; } }
.camp-svg .star { animation: twinkle 2.2s ease-in-out infinite alternate; }
@keyframes twinkle { from { opacity: 0.25; } to { opacity: 1; } }
.camp-svg .firefly { animation: firefly 6s ease-in-out infinite alternate; }
@keyframes firefly { 0% { transform: translate(0, 0); opacity: 0.2; } 50% { opacity: 1; } 100% { transform: translate(14px, -16px); opacity: 0.3; } }
.camp-svg .birds { stroke: #2a3a4a; stroke-width: 1.3; fill: none; stroke-linecap: round; animation: birds 28s linear infinite; }
@keyframes birds { from { transform: translate(-60px, 70px); } to { transform: translate(460px, 24px); } }
.camp-svg .relic-glow { animation: twinkle 1.6s ease-in-out infinite alternate; }
.camp-svg .relic .lit { animation: relic 1.6s ease-in-out infinite alternate; }
@keyframes relic { from { filter: brightness(1); } to { filter: brightness(1.35); } }
.camp-svg .lid { transform-box: fill-box; transform-origin: 0% 100%; transition: transform 0.35s ease; }
.camp-svg .lid.open { transform: rotate(-58deg); }
.camp-svg .chest-gems.shine { animation: relic 0.5s ease-in-out infinite alternate; }
.camp-svg .tent-flap { transform-box: fill-box; transform-origin: 100% 100%; }
.camp-svg .tent.rustle .tent-flap { animation: flap 0.3s ease-in-out 3 alternate; }
@keyframes flap { to { transform: skewX(-14deg) scaleX(0.65); } }
.camp-svg .tent-inside { transition: fill 0.6s; }
.camp-svg .tent.lit .tent-inside { fill: #ffcf6a; }
.camp-svg .lean-sword { transition: opacity 0.3s; }
.camp-svg .lean-sword.taken { opacity: 0; }
.camp-svg .sign, .camp-svg .fire, .camp-svg .hero-face { cursor: pointer; }
.camp-svg .sign:active { transform: translateY(1px); }
.camp-svg .sign-text { font: 700 8.5px var(--font-pixel, monospace); fill: #3b2614; }
.camp-svg .bubble { transition: opacity 0.3s; pointer-events: none; }
.camp-svg .bubble-text { font: 700 8.5px var(--font); fill: #3b2a17; }

/* hero poses */
.camp-svg .hero-face { transform-box: fill-box; transform-origin: 50% 50%; transition: transform 0.2s; }
.camp-svg .hero-body { transition: transform 0.35s ease; }
.camp-svg .leg, .camp-svg .arm, .camp-svg .torso { transform-box: fill-box; transform-origin: 50% 0%; transition: transform 0.35s ease; }
.camp-svg .head { transform-box: fill-box; transform-origin: 50% 100%; transition: transform 0.35s ease; }
.camp-svg .eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.6s infinite; }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
.camp-svg .held-sword { display: none; }
.camp-svg .inspect .held-sword { display: inline; }
.camp-svg .blade-glint { opacity: 0; transform-box: fill-box; transform-origin: center; }
.camp-svg .inspect .blade-glint { animation: glint 1.6s 0.5s ease-in-out infinite; }
.camp-svg .idle .torso { animation: breathe 2.8s ease-in-out infinite; }
@keyframes breathe { 50% { transform: translateY(0.7px); } }
.camp-svg .walk { animation: bob 0.26s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-1.6px); } }
.camp-svg .walk .leg-l, .camp-svg .walk .arm-r { animation: swingA 0.52s ease-in-out infinite alternate; }
.camp-svg .walk .leg-r, .camp-svg .walk .arm-l { animation: swingB 0.52s ease-in-out infinite alternate; }
@keyframes swingA { from { transform: rotate(20deg); } to { transform: rotate(-20deg); } }
@keyframes swingB { from { transform: rotate(-20deg); } to { transform: rotate(20deg); } }
.camp-svg .sit { transform: translateY(10px); }
.camp-svg .sit .hero-shadow { opacity: 0; }
.camp-svg .sit .leg { transform: rotate(-82deg); }
.camp-svg .warm .arm-l, .camp-svg .warm .arm-r { animation: warm 1.3s ease-in-out infinite alternate; }
@keyframes warm { from { transform: rotate(-68deg); } to { transform: rotate(-84deg); } }
.camp-svg .inspect .arm-r { transform: rotate(-125deg); }
.camp-svg .inspect .head { transform: rotate(9deg); }
.camp-svg .inspect .eyes { transform: translate(2px, -1px); animation: none; }
.camp-svg .wave .arm-r { animation: wave 0.32s ease-in-out infinite alternate; }
@keyframes wave { from { transform: rotate(-140deg); } to { transform: rotate(-168deg); } }
.camp-svg .crouch { transform: translateY(5px); }
.camp-svg .crouch .leg { transform: scaleY(0.72); }
.camp-svg .reach .arm-r { transform: rotate(-55deg); }
.camp-svg .stretch .arm-l { transform: rotate(165deg); }
.camp-svg .stretch .arm-r { transform: rotate(-165deg); }
.camp-svg .stretch .head { transform: translateY(-1px) rotate(-4deg); }
.camp-svg .waving .arm-r { animation: wave 0.32s ease-in-out infinite alternate !important; }
.camp-svg .look .eyes { animation: look 2.6s ease-in-out infinite; }
.camp-svg .look .head { animation: lookHead 2.6s ease-in-out infinite; }
@keyframes look { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-2.4px); } 65% { transform: translateX(2.4px); } }
@keyframes lookHead { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-6deg); } 65% { transform: rotate(6deg); } }

/* ---------- inventory ---------- */
.inv-panel { background: linear-gradient(#1a2c22, #14231b); border: 2px solid var(--border-strong); border-radius: 10px; padding: 12px; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.3); }
.inv-panel h2 { font-family: var(--font-title, var(--font-pixel)); font-size: 18px; color: var(--gold-ink); margin: 0 0 10px; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.slot { background: rgba(0, 0, 0, 0.3); border: 2px solid rgba(232, 184, 58, 0.35); border-radius: 8px; padding: 8px 6px; text-align: center; }
.slot.equipped { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(242, 196, 67, 0.25), inset 0 0 14px rgba(242, 196, 67, 0.2); }
.slot-icon { height: 58px; display: grid; place-items: center; }
.slot.locked .slot-icon { filter: brightness(0) opacity(0.35); }
.slot-name { font-size: 13px; font-weight: 700; margin-top: 4px; }
.slot.locked .slot-name { color: var(--faint); }
.slot-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.inv-note { font-size: 13px; color: var(--muted); margin-top: 10px; }
.compass-row { display: flex; gap: 14px; align-items: center; }
.shard-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 8px; font-size: 13px; }
.shard-list span { display: flex; align-items: center; gap: 4px; color: var(--faint); }
.shard-list span.have { color: var(--text); font-weight: 700; }
.shard-list i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; background: #2b2b33; }
.newitem { display: flex; align-items: center; gap: 10px; width: 100%; background: var(--gold-bg); border: 2px solid var(--gold); border-radius: 10px; padding: 8px 12px; color: var(--gold-ink); font-weight: 700; text-align: left; }
.newitem svg { flex: none; }

/* ---------- theme picker ---------- */
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left;
  border: 2px solid var(--border); background: var(--surface-2); border-radius: var(--radius); padding: 10px;
}
.theme-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.tc-label { font-weight: 700; font-size: 15px; }
.tc-preview { display: flex; align-items: center; gap: 3px; min-height: 20px; }
.tc-preview svg { display: block; }
.star-mini svg { width: 18px; height: 18px; display: block; color: var(--gold); }

/* ---------- Blocks world ---------- */
:root[data-theme="blocks"] {
  --bg: #262626; --surface: #3a3a3a; --surface-2: #4a4a4a;
  --text: #f2f2f2; --muted: #cfcfcf; --faint: #8a8a8a;
  --border: rgba(255, 255, 255, 0.18); --border-strong: rgba(255, 255, 255, 0.38);
  --good: #7ee05a; --good-bg: #2a4a1e; --bad: #ff7a6a; --bad-bg: #4a1e1e;
  --gold: #f7d83b; --gold-ink: #ffe98a; --gold-bg: #3b3410;
  --note: #f2e6b0; --note-edge: #b8a050; --accent: #5aa832; --radius: 0px;
  --tc-bg: color-mix(in srgb, var(--tc) 30%, var(--surface)); --tc-ink: color-mix(in srgb, var(--tc) 40%, #ffffff);
  --font-title: "Silkscreen", ui-monospace, monospace; --font-pixel: var(--font-title);
  color-scheme: dark;
}
[data-theme="blocks"] body {
  background-color: var(--bg);
  background-image: linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 16px 16px;
}
[data-theme="blocks"] .card, [data-theme="blocks"] .tile, [data-theme="blocks"] .unit, [data-theme="blocks"] .inv-panel, [data-theme="blocks"] .slot {
  border-radius: 0; border: 3px solid #1a1a1a; box-shadow: inset 2px 2px 0 rgba(255,255,255,0.15), inset -2px -2px 0 rgba(0,0,0,0.35);
}
[data-theme="blocks"] .btn.primary, [data-theme="blocks"] .tab.on, [data-theme="blocks"] .seg button.on { background: #5aa832; border-color: #2f6a1a; color: #fff; }
[data-theme="blocks"] .key { background: #6f6f6f; border: 3px solid #1a1a1a; border-radius: 0; color: #fff; box-shadow: inset 2px 2px 0 rgba(255,255,255,0.25), inset -2px -2px 0 rgba(0,0,0,0.35); }
[data-theme="blocks"] .key.ok { background: #4f8f2f; }
[data-theme="blocks"] .toast { border-radius: 0; background: #2a2a2a; border: 3px solid #f7d83b; }

/* ---------- Frontier world ---------- */
:root[data-theme="frontier"] {
  --bg: #24170e; --surface: #3a2716; --surface-2: #4a331d;
  --text: #f6e7c8; --muted: #d8c299; --faint: #9a8462;
  --border: rgba(214, 170, 100, 0.3); --border-strong: rgba(214, 170, 100, 0.6);
  --good: #9be07a; --good-bg: #2f4a1e; --bad: #ff9a7a; --bad-bg: #4d2018;
  --gold: #f2c443; --gold-ink: #ffe08a; --gold-bg: #3f2c0c;
  --note: #f1dfae; --note-edge: #b8964a; --accent: #c8752a; --radius: 6px;
  --tc-bg: color-mix(in srgb, var(--tc) 26%, var(--surface)); --tc-ink: color-mix(in srgb, var(--tc) 40%, #fff3dc);
  --font-title: "Rye", Georgia, serif; --font-pixel: var(--font-title);
  color-scheme: dark;
}
[data-theme="frontier"] body {
  background-color: var(--bg);
  background-image: radial-gradient(rgba(242, 196, 67, 0.05) 1px, transparent 1px), radial-gradient(rgba(0, 0, 0, 0.25) 1px, transparent 1px);
  background-size: 9px 9px, 13px 13px;
}
[data-theme="frontier"] .card, [data-theme="frontier"] .tile, [data-theme="frontier"] .unit, [data-theme="frontier"] .inv-panel { border-style: solid; box-shadow: inset 0 0 0 3px rgba(0,0,0,0.25), inset 0 0 0 4px rgba(214,170,100,0.18); }
[data-theme="frontier"] .btn.primary, [data-theme="frontier"] .tab.on, [data-theme="frontier"] .seg button.on { background: #c8752a; border-color: #7a3f12; color: #fff3dc; }
[data-theme="frontier"] .key { background: linear-gradient(#5a3d22, #45301a); border-color: #8a6436; }

/* ---------- Reactor City world ---------- */
:root[data-theme="reactor"] {
  --bg: #070d0c; --surface: #142060; --surface-2: #1c2a78;
  --text: #eef2ff; --muted: #bcc6f0; --faint: #7480b8;
  --border: rgba(220, 230, 255, 0.35); --border-strong: rgba(235, 240, 255, 0.8);
  --good: #7affc4; --good-bg: #123a2c; --bad: #ff8a8a; --bad-bg: #4a1418;
  --gold: #e8c45a; --gold-ink: #ffe9a8; --gold-bg: #20263a;
  --note: #e8f0ff; --note-edge: #8aa0d8; --accent: #4fe37a; --radius: 4px;
  --tc-bg: color-mix(in srgb, var(--tc) 30%, var(--surface)); --tc-ink: color-mix(in srgb, var(--tc) 35%, #ffffff);
  --font-title: "Cinzel", Georgia, serif; --font-pixel: var(--font-title);
  color-scheme: dark;
}
[data-theme="reactor"] body { background: radial-gradient(ellipse at 50% 0%, #10302a 0%, #070d0c 65%) fixed var(--bg); }
/* classic JRPG menu windows: blue gradient with a bright border */
[data-theme="reactor"] .card, [data-theme="reactor"] .tile, [data-theme="reactor"] .unit, [data-theme="reactor"] .inv-panel, [data-theme="reactor"] .plate, [data-theme="reactor"] .hud-items {
  background: linear-gradient(#2a4cb8, #0c1a58); border: 2px solid var(--border-strong); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.45);
}
[data-theme="reactor"] .unit.locked { background: rgba(12, 26, 88, 0.45); }
[data-theme="reactor"] .btn.primary, [data-theme="reactor"] .tab.on, [data-theme="reactor"] .seg button.on { background: linear-gradient(#6af08e, #2fae58); border-color: #e8fff0; color: #04220e; }
[data-theme="reactor"] .key { background: linear-gradient(#2a4cb8, #142a6a); border: 2px solid rgba(235,240,255,0.65); color: #fff; }
[data-theme="reactor"] .key.ok { background: linear-gradient(#2fae58, #1a7a3c); }
[data-theme="reactor"] .toast { background: linear-gradient(#2a4cb8, #0c1a58); border: 2px solid #fff; }

/* ---------- world scene extras ---------- */
.camp-svg .horse-head { transform-box: fill-box; transform-origin: 0% 100%; animation: graze 6s ease-in-out infinite; }
@keyframes graze { 0%, 40%, 100% { transform: rotate(0); } 55%, 85% { transform: rotate(40deg); } }
.camp-svg .horse-tail { transform-box: fill-box; transform-origin: 100% 0%; animation: swish 2.2s ease-in-out infinite alternate; }
@keyframes swish { from { transform: rotate(-12deg); } to { transform: rotate(14deg); } }
.camp-svg .tumbleweed { animation: tumble 22s linear infinite; }
@keyframes tumble { 0% { transform: translate(-30px, 236px) rotate(0); } 40% { transform: translate(430px, 236px) rotate(1600deg); } 100% { transform: translate(430px, 236px) rotate(1600deg); } }
.camp-svg .steam { animation: steam 2.4s ease-out infinite; }
@keyframes steam { from { opacity: 0.6; transform: translateY(0); } to { opacity: 0; transform: translateY(-10px); } }
.camp-svg .reactor .beam { animation: beam 3s ease-in-out infinite alternate; }
@keyframes beam { from { opacity: 0.35; } to { opacity: 0.95; } }
.camp-svg .ring, .camp-svg .win { animation: twinkle 2.6s ease-in-out infinite alternate; }
.camp-svg .plume { transform-box: fill-box; transform-origin: center; animation: plume 4.5s ease-out infinite; }
@keyframes plume { 0% { transform: translateY(6px) scale(0.6); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateY(-18px) scale(1.4); opacity: 0; } }
.camp-svg .godray { animation: godray 7s ease-in-out infinite alternate; }
@keyframes godray { from { opacity: 0.04; } to { opacity: 0.16; } }
.camp-svg .lamp-light { animation: lamp 5s steps(1) infinite; }
@keyframes lamp { 0%, 41%, 45%, 100% { opacity: 1; } 42%, 44% { opacity: 0.25; } 43% { opacity: 0.8; } }
.camp-svg .neon { fill: #ff6fae; stroke: #ff6fae; stroke-width: 0.3; animation: neon 2.6s ease-in-out infinite; }
@keyframes neon { 0%, 100% { opacity: 1; } 50% { opacity: 0.75; } 52% { opacity: 0.3; } 54% { opacity: 1; } }
