:root {
  color-scheme: dark;
  --bg: #0b0614; --panel: rgba(18, 10, 36, .9); --line: rgba(140, 90, 255, .35);
  --pink: #ff3ea5; --violet: #8b3dff; --cyan: #22e6ff; --lime: #b6ff4a; --gold: #ffc81f; --text: #f6efff; --dim: #b4a6d6; --bad: #ff6b81;
  --accent: var(--cyan);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; -webkit-font-smoothing: antialiased; }
body { overflow-x: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; border-radius: 10px; }
.bg { position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(ellipse 70% 45% at 50% 30%, rgba(139, 61, 255, .25), transparent 70%),
    radial-gradient(ellipse 50% 40% at 0% 0%, rgba(255, 62, 165, .16), transparent 70%),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(34, 230, 255, .14), transparent 70%), var(--bg); }
.bg:before { content: ""; position: absolute; inset: 0; opacity: .55;
  background: repeating-linear-gradient(0deg, rgba(139, 61, 255, .08) 0 1px, transparent 1px 28px), repeating-linear-gradient(90deg, rgba(139, 61, 255, .08) 0 1px, transparent 1px 28px);
  -webkit-mask: radial-gradient(ellipse at 50% 50%, #000, transparent 78%); mask: radial-gradient(ellipse at 50% 50%, #000, transparent 78%); }

.screen { min-height: 100svh; display: flex; justify-content: center; padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.wrap { width: min(560px, 100%); display: flex; flex-direction: column; }
.brand { display: block; margin: 10px 0 0; text-align: center; font-size: 12px; letter-spacing: .28em; text-transform: uppercase; color: var(--dim); text-decoration: none; }
.title { margin: 8px 0 2px; text-align: center; font-size: clamp(40px, 12vw, 64px); font-weight: 900; font-style: italic; letter-spacing: .02em; line-height: 1;
  color: #fff; text-shadow: 0 0 18px var(--pink), 0 0 2px #000; }
.title span { color: var(--cyan); text-shadow: 0 0 18px var(--cyan); }
.tag { text-align: center; color: var(--dim); margin: 10px auto 18px; max-width: 34ch; line-height: 1.4; }
.pick-label { margin: 4px 0 8px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; font-size: 12px; color: var(--gold); text-align: center; }
.fine { font-size: 13px; color: var(--dim); text-align: center; margin: 14px 0 0; }
.linkbtn { background: none; border: 0; color: var(--dim); text-decoration: underline; cursor: pointer; padding: 4px; }

/* grade band cards */
.bands { display: grid; gap: 12px; }
.band { --c: var(--cyan); display: grid; grid-template-columns: 74px 1fr auto; align-items: center; gap: 14px; text-align: left; cursor: pointer; width: 100%;
  padding: 14px; border-radius: 20px; border: 2px solid color-mix(in srgb, var(--c) 55%, transparent); background: var(--panel);
  box-shadow: 0 0 22px color-mix(in srgb, var(--c) 22%, transparent); transition: transform .15s, box-shadow .15s; }
.band:hover { transform: translateY(-2px); box-shadow: 0 0 30px color-mix(in srgb, var(--c) 45%, transparent); }
.band.lime { --c: var(--lime); } .band.cyan { --c: var(--cyan); } .band.pink { --c: var(--pink); }
.band .g { display: grid; place-items: center; height: 74px; border-radius: 16px; font-weight: 900; font-size: 22px; color: var(--c);
  border: 2px solid var(--c); text-shadow: 0 0 10px var(--c); box-shadow: inset 0 0 14px color-mix(in srgb, var(--c) 30%, transparent); }
.band .g small { display: block; font-size: 10px; letter-spacing: .2em; color: var(--dim); text-shadow: none; margin-top: -10px; }
.band b { display: block; font-size: 19px; font-weight: 900; color: var(--text); }
.band span { display: block; color: var(--dim); font-size: 14px; margin-top: 3px; line-height: 1.3; }
.band .prog { font-size: 12px; font-weight: 800; color: var(--c); margin-top: 6px; letter-spacing: .04em; }
.band .arrow { font-size: 30px; color: var(--c); }

/* bars + chips */
.bar { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.back, .iconbtn, .say { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: rgba(20, 10, 32, .85);
  font-size: 26px; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0 0 3px; }
.iconbtn, .say { font-size: 20px; padding: 0; }
.back:hover, .iconbtn:hover, .say:hover { border-color: var(--cyan); }
.chip { display: inline-block; font-size: 12px; font-weight: 900; letter-spacing: .16em; padding: 6px 11px; border-radius: 20px; border: 1px solid var(--accent); color: var(--accent); margin: 0; }
.chip.lime { border-color: var(--lime); color: var(--lime); }
.bar .say { margin-left: auto; }
.h2 { margin: 12px 0 6px; font-size: clamp(26px, 7vw, 34px); font-weight: 900; line-height: 1.1; }
.h2.sm { font-size: 24px; margin-top: 0; }
.story { color: var(--dim); line-height: 1.45; margin: 4px 0 14px; }

/* doors on the chapter map */
.doors { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 10px; }
.door { width: 100%; display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center; text-align: left; cursor: pointer;
  padding: 12px; border-radius: 18px; border: 2px solid var(--line); background: var(--panel); }
.door .dic { position: relative; width: 54px; height: 66px; border-radius: 10px 10px 4px 4px; border: 3px solid var(--accent); box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 50%, transparent), inset 0 0 10px color-mix(in srgb, var(--accent) 25%, transparent); }
.door .dic:after { content: ""; position: absolute; right: 8px; top: 30px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.door .dic b { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 900; font-size: 22px; }
.door strong { display: block; font-size: 17px; }
.door small { display: block; color: var(--dim); font-size: 13px; margin-top: 2px; }
.door .stars { font-size: 16px; }
.door.next { border-color: var(--accent); box-shadow: 0 0 20px color-mix(in srgb, var(--accent) 35%, transparent); animation: pulse 2s ease-in-out infinite; }
.door.done .dic { border-color: var(--lime); box-shadow: 0 0 12px rgba(182, 255, 74, .5); }
.door.done .dic:after { background: var(--lime); }
.door.locked { cursor: not-allowed; opacity: .45; }
.door.locked .dic { border-color: #5b4d78; box-shadow: none; }
.door.locked .dic:after { display: none; }
.door .go { font-size: 13px; font-weight: 900; letter-spacing: .1em; color: var(--accent); }
@keyframes pulse { 50% { box-shadow: 0 0 34px color-mix(in srgb, var(--accent) 55%, transparent); } }
.stars { color: var(--gold); letter-spacing: .1em; text-shadow: 0 0 10px rgba(255, 200, 31, .6); margin: 0; }
.stars .off { color: #4a3d66; text-shadow: none; }
.stars.big { font-size: 40px; }

/* panels */
.panel { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 18px; box-shadow: 0 0 36px rgba(139, 61, 255, .28); }
.lead { font-size: 17px; line-height: 1.45; margin: 4px 0 10px; }
.ex-label { margin: 12px 0 4px; font-size: 12px; font-weight: 900; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.example { margin: 0 0 8px; font-size: 18px; font-weight: 800; line-height: 1.4; }
.steps { margin: 6px 0 14px; padding-left: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 9px 10px 9px 44px; margin: 6px 0; border-radius: 12px; background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .08); line-height: 1.45; animation: stepIn .35s cubic-bezier(.3, 1.3, .5, 1); }
.steps li:before { content: counter(s); position: absolute; left: 10px; top: 8px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 900; font-size: 13px; color: #14051f; background: var(--accent); }
.steps li:last-child { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.steps b { color: var(--lime); }
@keyframes stepIn { from { opacity: 0; transform: translateX(-14px); } }

.btn { display: block; width: 100%; margin: 8px 0 0; padding: 15px; border-radius: 16px; border: 2px solid var(--cyan); background: transparent;
  font-weight: 900; font-size: 17px; cursor: pointer; letter-spacing: .02em; }
.btn.primary { background: linear-gradient(90deg, var(--violet), var(--pink)); border-color: transparent; box-shadow: 0 0 22px rgba(255, 62, 165, .45); }
.btn.ghost { border-color: var(--line); color: var(--dim); }
.btn.small { width: auto; display: inline-block; padding: 9px 14px; font-size: 14px; border-radius: 12px; margin: 6px 6px 0 0; }

/* visuals */
.visual { display: flex; justify-content: center; margin: 8px 0; }
.visual:empty { display: none; }
.pic { width: 100%; max-width: 340px; max-height: 260px; height: auto; overflow: visible; }
.star { fill: rgba(255, 200, 31, .18); stroke: var(--gold); stroke-width: 2.5; filter: drop-shadow(0 0 4px rgba(255, 200, 31, .7)); }
.tapmark { cursor: pointer; transition: fill .15s; }
.tapmark.marked { fill: var(--gold); stroke: #fff; }
.dot-p { fill: var(--pink); filter: drop-shadow(0 0 4px var(--pink)); }
.dot-c { fill: var(--cyan); filter: drop-shadow(0 0 4px var(--cyan)); }
.blk-h { fill: rgba(34, 230, 255, .2); stroke: var(--cyan); stroke-width: 2; }
.blk-t { fill: rgba(255, 62, 165, .25); stroke: var(--pink); stroke-width: 2; }
.blk-o { fill: var(--lime); }
.blk-l { stroke: rgba(255, 255, 255, .18); stroke-width: 1; }
.bar-on { fill: var(--lime); filter: drop-shadow(0 0 6px rgba(182, 255, 74, .8)); }
.bar-off { fill: rgba(255, 255, 255, .05); stroke: #6a5a8e; stroke-width: 2; }
.axis { stroke: #cbbcf0; stroke-width: 2; fill: none; }
.grid { stroke: rgba(255, 255, 255, .08); stroke-width: 1; }
.lineg { stroke: var(--pink); stroke-width: 2.5; stroke-dasharray: 6 5; }
.pt { fill: var(--lime); filter: drop-shadow(0 0 5px var(--lime)); }
.lbl { fill: var(--dim); font: 700 13px system-ui, sans-serif; paint-order: stroke; stroke: #0b0614; stroke-width: 4px; stroke-linejoin: round; }
.lbl.hi { fill: #fff; font-size: 14px; }
.plane .lbl.hi { font-size: 17px; }
.plane .pt { r: 7px; }
.lbl.pinkt { fill: var(--pink); font-size: 16px; font-weight: 900; }
.shape { fill: rgba(34, 230, 255, .1); stroke: var(--cyan); stroke-width: 3; filter: drop-shadow(0 0 6px rgba(34, 230, 255, .5)); }
.dash { stroke: var(--gold); stroke-width: 2; stroke-dasharray: 5 4; }
.ang { fill: none; stroke: var(--pink); stroke-width: 2.5; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.05; margin: 0 .15em; font-weight: 900; }
.frac i { font-style: normal; padding: 0 .2em; }
.frac i:first-child { border-bottom: 2px solid currentColor; }

/* the puzzle room */
.roomwrap { gap: 10px; }
.room-name { flex: 1; font-weight: 900; font-size: 16px; text-align: center; letter-spacing: .04em; }
.door-top { display: flex; justify-content: center; }
.locks { display: flex; gap: 14px; padding: 10px 18px; border-radius: 30px; border: 2px solid var(--line); background: rgba(10, 5, 22, .8); }
.lock { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #5b4d78; display: grid; place-items: center; font-size: 13px; transition: all .3s; }
.lock.on { border-color: var(--lime); background: var(--lime); color: #14051f; box-shadow: 0 0 16px var(--lime); animation: pop .4s cubic-bezier(.3, 1.6, .5, 1); }
.lock.cur { border-color: var(--accent); box-shadow: 0 0 10px var(--accent); }
@keyframes pop { 40% { transform: scale(1.4); } }
.problem { padding-top: 16px; }
.problem .corner { position: absolute; right: 10px; top: 10px; }
.prompt { font-size: 19px; font-weight: 700; line-height: 1.45; text-align: center; padding: 0 42px; }
.prompt .eq { display: inline-block; font-size: clamp(30px, 9vw, 40px); font-weight: 900; margin: 6px 0; letter-spacing: .02em; color: #fff; text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 70%, transparent); }
.prompt .eq.sm { font-size: 22px; }
.prompt .big { font-size: 34px; }
.hl { color: var(--gold); }
.answer-row { display: flex; justify-content: center; }
.answer { min-width: 150px; min-height: 58px; padding: 6px 18px; border-radius: 16px; border: 2px solid var(--accent); font-size: 36px; font-weight: 900; text-align: center;
  background: rgba(0, 0, 0, .3); box-shadow: inset 0 0 14px color-mix(in srgb, var(--accent) 25%, transparent); letter-spacing: .06em; }
.answer:empty:before { content: "?"; color: #5b4d78; }
#room.right .answer { border-color: var(--lime); color: var(--lime); box-shadow: 0 0 20px rgba(182, 255, 74, .6); }
.problem.wrong { animation: shake .4s; }
#room.wrong .answer { border-color: var(--bad); color: var(--bad); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.choice { min-height: 74px; border-radius: 16px; border: 2px solid var(--line); background: rgba(255, 255, 255, .04); font-size: 26px; cursor: pointer; }
.choice:hover { border-color: var(--accent); }
.choice.bad { border-color: var(--bad); opacity: .45; }
.choice.good { border-color: var(--lime); box-shadow: 0 0 18px rgba(182, 255, 74, .6); }
.hint { margin-top: 12px; padding: 12px; border-radius: 14px; border: 1px solid rgba(255, 200, 31, .5); background: rgba(255, 200, 31, .07); }
.hint p { margin: 0; line-height: 1.45; }
.hint p:before { content: "Hint: "; font-weight: 900; color: var(--gold); }
.solve { margin-bottom: 0; }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pad button { min-height: 58px; border-radius: 16px; border: 1px solid var(--line); background: rgba(24, 14, 44, .92); font-size: 26px; font-weight: 800; cursor: pointer;
  touch-action: manipulation; user-select: none; }
.pad button:active { background: rgba(139, 61, 255, .35); }
.pad button:disabled { opacity: .3; }
.pad .ok { grid-column: 1 / -1; background: linear-gradient(90deg, var(--violet), var(--pink)); border: 0; font-size: 20px; letter-spacing: .08em; box-shadow: 0 0 20px rgba(255, 62, 165, .45); }

/* door opening */
.overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: rgba(7, 4, 16, .78); overflow: hidden; }
.dooranim { position: absolute; inset: 0; display: flex; pointer-events: none; }
.half { flex: 1; background: linear-gradient(90deg, #160c2c, #22123f); border: 3px solid var(--accent); box-shadow: inset 0 0 40px color-mix(in srgb, var(--accent) 35%, transparent);
  animation: openL 1s .5s cubic-bezier(.6, 0, .3, 1) forwards; position: relative; }
.half.r { animation-name: openR; }
.half i { position: absolute; top: 50%; width: 16px; height: 16px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 18px var(--lime); }
.half.l i { right: 18px; } .half.r i { left: 18px; }
@keyframes openL { to { transform: translateX(-102%); } }
@keyframes openR { to { transform: translateX(102%); } }
.clear-card { position: relative; width: min(420px, 100%); text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 22px;
  box-shadow: 0 0 50px rgba(182, 255, 74, .25); animation: rise .5s 1.1s both cubic-bezier(.3, 1.3, .5, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(30px) scale(.9); } }

.toast { position: fixed; left: 50%; top: 18%; transform: translate(-50%, -50%) scale(.8); z-index: 20; padding: 10px 22px; border-radius: 30px; font-weight: 900; font-size: 22px;
  background: var(--lime); color: #14051f; box-shadow: 0 0 30px rgba(182, 255, 74, .7); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap; }
.toast.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* phone: the keypad always stays on screen, the problem scrolls above it */
@media (max-width: 759px) {
  #room { height: 100svh; min-height: 0; }
  .roomwrap { height: 100%; gap: 8px; }
  .roomwrap .problem { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; }
  .pic { max-height: 190px; }
  .pic.plane { max-height: 300px; }
  .answer { min-height: 52px; font-size: 32px; padding: 4px 18px; }
  .pad { gap: 6px; }
  .pad button { min-height: 50px; }
  .pad .ok { min-height: 54px; }
}
.prompt .story { font-size: 14px; font-weight: 500; margin: 0 0 8px; }
@media (min-width: 760px) {
  .roomwrap { width: min(900px, 100%); display: grid; grid-template-columns: 1fr 320px; grid-template-rows: auto auto auto 1fr; column-gap: 18px; align-items: start; }
  .roomwrap .bar, .roomwrap .door-top { grid-column: 1 / -1; }
  .roomwrap .answer-row { grid-column: 2; grid-row: 3; margin-bottom: 10px; }
  .roomwrap .pad { grid-column: 2; grid-row: 4; }
  .roomwrap .problem { grid-column: 1; grid-row: 3 / span 2; }
}
@media (max-height: 700px) and (max-width: 759px) {
  .pad button { min-height: 44px; }
  .locks { padding: 6px 14px; } .lock { width: 24px; height: 24px; }
  .pic { max-height: 170px; }
  .prompt .eq { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) { *, *:before, *:after { animation-duration: .01s !important; animation-delay: 0s !important; transition-duration: .01s !important; } }
