:root {
  --navy: #1d2a5c;
  --navy-2: #2c3e7a;
  --gold: #f6b92b;
  --gold-dark: #c88a0a;
  --cream: #fff8ea;
  --ink: #1b2240;
  --muted: #5d6685;
  --ok: #22b573;
  --ok-dark: #138a54;
  --bad: #ef4444;
  --bad-dark: #b91c1c;
  --card: #ffffff;
  --line: #e7e3d8;
  --vocab: #f59e0b;
  --listening: #14b8a6;
  --grammar: #8b5cf6;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9d4ff; }
body {
  font-family: "Fredoka", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(12px + var(--safe-t)) 14px 0;
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  pointer-events: none; z-index: 5;
}
#hud > * { pointer-events: auto; }
.hearts { display: flex; gap: 3px; background: rgba(255,255,255,.85); padding: 6px 9px; border-radius: 999px; box-shadow: 0 4px 14px rgba(20,30,70,.15); }
.heart { width: 20px; height: 20px; transition: transform .3s, opacity .3s, filter .3s; }
.heart path { fill: #ef4444; stroke: #b91c1c; stroke-width: 1.2; }
.heart.lost { opacity: .35; filter: grayscale(1); }
.heart.pop { animation: heartPop .6s ease; }
@keyframes heartPop { 0% { transform: scale(1); } 30% { transform: scale(1.6) rotate(-12deg); } 100% { transform: scale(1); } }
.progress-pill { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.85); padding: 6px 12px; border-radius: 999px; box-shadow: 0 4px 14px rgba(20,30,70,.15); font-weight: 700; font-size: 14px; color: var(--navy); white-space: nowrap; }
.pbar { display: block; width: 56px; height: 8px; border-radius: 99px; background: #e2e5ef; overflow: hidden; }
.pbar b { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), #5fd99a); border-radius: inherit; transition: width .5s; }
.pill-btn { font: inherit; font-weight: 700; font-size: 14px; color: var(--navy); background: rgba(246,185,43,.62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); border: 0; border-radius: 999px; padding: 9px 14px; box-shadow: 0 3px 0 var(--gold-dark), 0 4px 14px rgba(20,30,70,.15); cursor: pointer; white-space: nowrap; }
.pill-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--gold-dark); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); box-shadow: 0 4px 14px rgba(20,30,70,.15); display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; fill: var(--navy); stroke: var(--navy); }
.icon-btn.muted .wave { display: none; }
.cam-stack { position: fixed; right: 14px; top: calc(62px + var(--safe-t)); z-index: 5; display: flex; flex-direction: column; gap: 8px; }
.cam-stack .icon-btn { font: inherit; font-weight: 700; font-size: 22px; line-height: 1; color: var(--navy); }
.cam-stack .icon-btn.txt { font-size: 13px; letter-spacing: .02em; }
.cam-stack .icon-btn.on { background: rgba(246,185,43,.75); }
#dayBtn { font-size: 18px; }

/* ---------- touch ---------- */
#touch { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#stickZone { position: absolute; left: 0; bottom: 0; width: 55%; height: 55%; pointer-events: auto; }
#stick { position: absolute; left: 34px; bottom: calc(34px + var(--safe-b)); width: 118px; height: 118px; border-radius: 50%; background: rgba(255,255,255,.28); border: 2px solid rgba(255,255,255,.65); backdrop-filter: blur(2px); }
#knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255,255,255,.92); box-shadow: 0 4px 12px rgba(0,0,0,.18); }
#jumpBtn { position: absolute; right: 30px; bottom: calc(44px + var(--safe-b)); width: 84px; height: 84px; border-radius: 50%; border: 0; pointer-events: auto; background: rgba(246,185,43,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); box-shadow: 0 6px 0 var(--gold-dark), 0 10px 20px rgba(0,0,0,.2); display: grid; place-items: center; }
#jumpBtn:active, #jumpBtn.on { transform: translateY(4px); box-shadow: 0 2px 0 var(--gold-dark), 0 6px 12px rgba(0,0,0,.2); }
#jumpBtn svg { width: 38px; height: 38px; fill: var(--navy); }
#keyHint { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); margin: 0; padding: 8px 14px; border-radius: 999px; background: rgba(29,42,92,.75); color: #fff; font-size: 14px; z-index: 4; white-space: nowrap; }
kbd { font-family: inherit; background: rgba(255,255,255,.18); padding: 1px 6px; border-radius: 6px; }

#toast { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translate(-50%, -10px); opacity: 0; transition: .3s; z-index: 6; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 14px; font-weight: 600; box-shadow: 0 8px 22px rgba(0,0,0,.2); max-width: calc(100% - 32px); text-align: center; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#fade { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 7; }
#fade.on { opacity: .85; }

/* ---------- overlays & cards ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at center, rgba(29,42,92,.35), rgba(29,42,92,.62)); overflow-y: auto; }
.card { width: min(440px, 100%); background: var(--card); border-radius: 26px; padding: 26px 22px 22px; text-align: center; box-shadow: 0 24px 60px rgba(10,20,60,.35); position: relative; animation: cardIn .45s cubic-bezier(.2,.9,.3,1.2); }
.card.small { width: min(320px, 100%); }
@keyframes cardIn { from { transform: translateY(18px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.crest { width: 64px; height: 64px; margin: -58px auto 8px; border-radius: 20px; display: grid; place-items: center; font-size: 34px; background: linear-gradient(160deg, var(--navy-2), var(--navy)); box-shadow: 0 8px 20px rgba(29,42,92,.35), inset 0 -3px 0 rgba(0,0,0,.2); }
.card.small .crest { margin-top: -50px; }
.eyebrow { margin: 0 0 6px; color: var(--gold-dark); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: 13px; }
h1 { margin: 0 0 10px; font-size: 26px; line-height: 1.15; color: var(--navy); }
.lead { margin: 0 0 16px; color: var(--muted); font-size: 16px; line-height: 1.45; }
.muted { color: var(--muted); margin: 10px 0 0; font-size: 14px; }
.tiny { margin: 12px 0 0; color: #9aa1b9; font-size: 12.5px; }
.rules { list-style: none; padding: 0; margin: 0 0 18px; text-align: left; display: grid; gap: 8px; }
.rules li { display: flex; gap: 10px; align-items: flex-start; background: var(--cream); border-radius: 14px; padding: 10px 12px; font-size: 15px; line-height: 1.35; color: var(--ink); }
.rule-ico { font-size: 18px; line-height: 1.2; }
.bar { height: 10px; background: #edf0f7; border-radius: 99px; overflow: hidden; margin: 8px 0 0; }
.bar i { display: block; height: 100%; width: 5%; background: linear-gradient(90deg, var(--gold), #ffd667); border-radius: inherit; transition: width .3s; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 700; font-size: 16px; border-radius: 16px; border: 0; padding: 12px 18px; cursor: pointer; text-decoration: none; transition: transform .08s, box-shadow .08s; }
.btn.big { width: 100%; font-size: 18px; padding: 15px 18px; }
.btn.primary { background: var(--gold); color: var(--navy); box-shadow: 0 5px 0 var(--gold-dark); }
.btn.primary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--gold-dark); }
.btn.ghost { background: #fff; color: var(--navy); border: 2px solid var(--navy); box-shadow: 0 3px 0 var(--navy); margin-top: 10px; width: 100%; }
.btn.ghost:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--navy); }

/* ---------- quiz sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 9; display: flex; align-items: flex-end; justify-content: center; background: linear-gradient(to top, rgba(29,42,92,.55), rgba(29,42,92,.05) 70%); }
.sheet { width: min(520px, 100%); max-height: 86vh; overflow-y: auto; background: #fff; border-radius: 26px 26px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); box-shadow: 0 -12px 40px rgba(10,20,60,.3); animation: sheetIn .35s cubic-bezier(.2,.9,.3,1.1); touch-action: pan-y; }
@keyframes sheetIn { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 760px) and (min-height: 560px) {
  .sheet-wrap { align-items: center; background: rgba(29,42,92,.35); }
  .sheet { border-radius: 26px; padding: 22px 24px 24px; }
}
.q-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.chip { font-weight: 700; font-size: 13.5px; letter-spacing: .03em; padding: 5px 12px; border-radius: 999px; color: #fff; background: var(--vocab); }
.chip.listening { background: var(--listening); }
.chip.grammar { background: var(--grammar); }
.chip.mix { background: #ff5a7a; }
.q-post { color: var(--muted); font-weight: 600; font-size: 14px; }
.q-steps { display: flex; gap: 4px; margin: -4px 0 12px; }
.q-steps i { flex: 1; height: 6px; border-radius: 99px; background: #e6e8f0; transition: background .3s; }
.q-steps i.done { background: var(--ok); }
.q-steps i.now { background: #ffd36b; }
.gap { margin: -6px 0 14px; padding: 12px 14px; border-radius: 14px; background: #eefbf8; border: 1.5px dashed #8fdccf; font-size: 18px; line-height: 1.4; color: var(--ink); font-weight: 600; }
.best { margin: -6px 0 14px; font-weight: 700; color: var(--navy); }
#qPrompt { margin: 4px 0 14px; font-size: 22px; line-height: 1.3; color: var(--navy); }
.listen { display: flex; align-items: center; gap: 10px; margin: 0 auto 14px; padding: 12px 20px; border-radius: 999px; border: 0; background: var(--listening); color: #fff; font: inherit; font-weight: 700; font-size: 17px; cursor: pointer; box-shadow: 0 4px 0 #0d8a7c; }
.listen svg { width: 24px; height: 24px; fill: #fff; }
.listen.playing { animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.options { display: grid; gap: 9px; }
.opt { font: inherit; font-size: 17px; font-weight: 600; text-align: left; padding: 14px 16px; border-radius: 16px; border: 2px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; box-shadow: 0 3px 0 var(--line); transition: transform .08s, background .2s, border-color .2s; display: flex; align-items: center; gap: 12px; }
.opt:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.opt .key { flex: none; width: 28px; height: 28px; border-radius: 9px; background: #f1f2f7; display: grid; place-items: center; font-size: 14px; color: var(--muted); }
.opt:disabled { cursor: default; }
.opt.correct { background: #e7f8ef; border-color: var(--ok); box-shadow: 0 3px 0 var(--ok-dark); }
.opt.correct .key { background: var(--ok); color: #fff; }
.opt.wrong { background: #fdecec; border-color: var(--bad); box-shadow: 0 3px 0 var(--bad-dark); animation: shake .35s; }
.opt.wrong .key { background: var(--bad); color: #fff; }
.opt.dim { opacity: .5; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.feedback { margin-top: 14px; animation: sheetIn .3s ease; }
.fb-title { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
.fb-title.ok { color: var(--ok-dark); }
.fb-title.bad { color: var(--bad-dark); }
.fb-answer { margin: 0 0 4px; font-size: 16px; color: var(--ink); }
.fb-answer b { color: var(--ok-dark); }
.fb-explain { margin: 0 0 12px; font-size: 14.5px; color: var(--muted); line-height: 1.45; }
.help { background: linear-gradient(160deg, #f3f6ff, #fff8ea); border: 1.5px solid #e2e6f3; border-radius: 18px; padding: 14px; margin: 0 0 14px; text-align: left; }
.help-title { margin: 0 0 4px; font-weight: 700; color: var(--navy); font-size: 15.5px; }
.help-text { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.4; }

/* ---------- finish ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 16px; }
.stats div { background: var(--cream); border-radius: 14px; padding: 10px 6px; display: grid; gap: 2px; }
.stats b { font-size: 22px; color: var(--navy); }
.stats span { font-size: 12.5px; color: var(--muted); }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 520px) { #keyHint { white-space: normal; text-align: center; width: max-content; max-width: calc(100% - 24px); font-size: 13px; } }
@media (max-width: 340px) {
  #hud { padding-left: 8px; padding-right: 8px; gap: 6px; }
  .hearts { padding: 5px 7px; gap: 1px; }
  .heart { width: 16px; height: 16px; }
  .progress-pill { padding: 6px 9px; gap: 6px; font-size: 13px; }
  .pbar { width: 34px; }
  .icon-btn { width: 34px; height: 34px; flex: none; }
}
@media (max-width: 380px) {
  h1 { font-size: 23px; }
  #qPrompt { font-size: 20px; }
  .opt { font-size: 16px; padding: 12px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* lift: floor buttons appear while standing on a lift pad */
.lift-panel { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + var(--safe-b)); z-index: 30; width: min(92vw, 380px); padding: 10px; border-radius: 18px; background: rgba(255,255,255,.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: 0 6px 20px rgba(0,0,0,.18); pointer-events: auto; }
.lift-head { font-weight: 700; color: var(--navy); font-size: 14px; margin: 0 4px 8px; }
.lift-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: 42vh; overflow-y: auto; }
.lift-grid button { font: inherit; border: 0; border-radius: 12px; padding: 6px 4px; background: rgba(246,185,43,.62); color: var(--navy); font-weight: 700; font-size: 17px; display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer; }
.lift-grid button small { font-size: 10px; font-weight: 600; line-height: 1.1; text-align: center; opacity: .85; }
.lift-grid button.here { background: rgba(255,255,255,.75); cursor: default; }
@media (min-width: 900px) { .lift-panel { bottom: 90px; } }

/* view nudge pad: opens under the ✥ button, hold a direction to keep turning */
#navBtn { font-size: 20px; }
.nav-pad { display: grid; grid-template-areas: ". up ." "left . right" ". down ."; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); gap: 3px; margin-left: -68px; }
.nav-pad[hidden] { display: none; }
.cam-stack .nav-pad .icon-btn { width: 34px; height: 34px; font-size: 14px; touch-action: none; user-select: none; -webkit-user-select: none; }
.lift-head { display: flex; align-items: center; gap: 4px; }
.lift-head span { flex: 1; }
.lift-x { width: 28px; height: 28px; flex: none; border: 0; border-radius: 50%; background: rgba(29,42,92,.14); color: var(--navy); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; display: grid; place-items: center; }

/* 👁 opens Out / In / ↩ underneath it */
#viewBtn { font-size: 19px; }
.view-drop { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.view-drop[hidden] { display: none; }
.cam-stack .view-drop .icon-btn { width: 36px; height: 36px; margin: 0 2px; }
#backBtn { font-size: 19px; }

/* ---------- bottom navigation ---------- */
:root { --nav-h: 60px; }
.tab-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: rgba(251,246,234,.9); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-top: 1px solid rgba(91,57,32,.1); box-shadow: 0 -6px 20px rgba(20,30,70,.08); }
.tab-bar[hidden] { display: none; }
.tab { position: relative; flex: 1; border: 0; background: none; font: inherit; color: #7c6f60; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab svg .fill { fill: currentColor; }
.tab span { font-size: 12px; font-weight: 600; }
.tab.on { color: var(--navy); }
.tab.on svg { stroke-width: 2.1; }
.tab.on span { font-weight: 700; }
.tab-dot { position: absolute; top: 9px; left: calc(50% + 12px); width: 8px; height: 8px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 2px rgba(251,246,234,.9); }
.tab-dot[hidden] { display: none; }
body.tabs-on #stickZone { bottom: calc(var(--nav-h) + var(--safe-b)); }
body.tabs-on #stick { bottom: calc(26px + var(--nav-h) + var(--safe-b)); }
body.tabs-on #jumpBtn { bottom: calc(34px + var(--nav-h) + var(--safe-b)); }
body.tabs-on #keyHint { bottom: calc(14px + var(--nav-h) + var(--safe-b)); }
body.tabs-on .lift-panel { bottom: calc(140px + var(--nav-h) + var(--safe-b)); }
@media (min-width: 900px) { body.tabs-on .lift-panel { bottom: calc(70px + var(--nav-h)); } }
.tab-sheet { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 8px); z-index: 8; width: min(520px, calc(100% - 16px)); max-height: min(64vh, 620px); display: flex; flex-direction: column; background: rgba(255,255,255,.96); border-radius: 22px; box-shadow: 0 12px 40px rgba(10,20,60,.28); }
.tab-sheet[hidden] { display: none; }
.ts-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; }
.ts-head h2 { flex: 1; margin: 0; font-size: 19px; color: var(--navy); }
.ts-body { overflow-y: auto; padding: 4px 16px 16px; color: #2b2b3a; font-size: 14px; line-height: 1.45; }
.ts-body h3 { margin: 14px 0 6px; font-size: 14px; color: var(--navy); }
.ts-sub { margin: 0 0 8px; color: #6b6b7a; }
.ms-list, .ip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ip-list li { display: flex; gap: 8px; }
.ms-item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 14px; background: #f7f3ea; }
.ms-item.done { background: #eaf6ec; }
.ms-ico { font-size: 22px; width: 30px; text-align: center; flex: none; }
.ms-txt { flex: 1; min-width: 0; }
.ms-txt b { display: block; font-size: 14px; color: #23233a; }
.ms-txt small { color: #6b6b7a; font-size: 12px; }
.ms-state { flex: none; font-size: 12px; font-weight: 700; color: #8a7a5c; }
.ms-item.done .ms-state { color: #2e8b57; }
.ms-bar { height: 8px; border-radius: 99px; background: #efe7d6; overflow: hidden; margin: 2px 0 12px; }
.ms-bar i { display: block; height: 100%; background: var(--gold); border-radius: 99px; }
.kp-card { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 16px; background: #f7f3ea; text-decoration: none; color: inherit; }
.kp-card + .kp-card { margin-top: 8px; }
.kp-card .ms-ico { font-size: 26px; }
.kp-go { flex: none; font-weight: 700; font-size: 13px; color: var(--navy); background: rgba(246,185,43,.6); padding: 6px 10px; border-radius: 99px; }
.ak-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.ak-ava { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; background: linear-gradient(135deg, #f6c64a, #e2b23a); }
.ak-head b { display: block; font-size: 17px; color: var(--navy); }
.ak-head small { color: #6b6b7a; }
.ak-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ak-stats div { background: #f7f3ea; border-radius: 14px; padding: 10px 12px; }
.ak-stats b { display: block; font-size: 20px; color: var(--navy); }
.ak-stats span { font-size: 12px; color: #6b6b7a; }
.ak-row { display: flex; gap: 8px; margin-top: 12px; }
.ak-row button { flex: 1; font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 10px; background: #f0e9da; color: var(--navy); cursor: pointer; }
.ip-dir details { background: #f7f3ea; border-radius: 12px; padding: 8px 12px; }
.ip-dir details + details { margin-top: 6px; }
.ip-dir summary { font-weight: 700; color: var(--navy); cursor: pointer; }
.ip-dir ul { margin: 6px 0 2px; padding-left: 0; list-style: none; columns: 2; column-gap: 12px; font-size: 12px; }
.ip-dir li { break-inside: avoid; padding: 1px 0; }
.ip-dir code { font-family: inherit; font-weight: 700; color: #8a5a2c; }
