:root {
  --cream: #FFFCF5; --ink: #14130F; --blue: #2740E8; --red: #D2401C; --yellow: #FFD23F; --green: #0B7F58;
  --line: #E4DFD2; --mute: #6A675F; --paper: #E9E4D6;
  --display: 'Kanit', 'Arial Black', sans-serif; --body: 'Anuphan', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: #0B0A08; color: var(--ink); font-family: var(--body); -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.k { font-family: var(--display); }
svg { display: block; width: 100%; height: auto; }

/* App column: full screen on phones, a centred device-sized column on big screens. */
#app { max-width: 480px; height: 100dvh; margin: 0 auto; background: var(--cream); display: flex; flex-direction: column; overflow: hidden; position: relative; }
@media (min-width: 560px) and (min-height: 760px) {
  #app { height: min(900px, calc(100dvh - 48px)); margin-top: 24px; border-radius: 26px; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
}

.strip { display: flex; gap: 4px; padding: max(12px, env(safe-area-inset-top)) 12px 9px; background: var(--ink); align-items: flex-end; min-height: 44px; }
.strip .brand { color: var(--cream); font-family: var(--display); font-weight: 800; font-size: 16px; letter-spacing: .08em; }
.strip .brand b { color: var(--yellow); }
.strip .tool { background: none; border: 1px solid #55524A; color: var(--cream); font-size: 11px; border-radius: 8px; padding: 4px 9px; font-family: var(--display); }
.strip .tool.home { margin-right: 4px; }
.seg { flex: 1; text-align: left; background: none; border: 0; padding: 0; color: var(--mute); font-size: 10px; cursor: default; min-width: 0; }
.seg i { display: block; height: 4px; border-radius: 2px; background: #55524A; margin-bottom: 5px; }
.seg.done i { background: var(--cream); } .seg.done { color: #A8A496; cursor: pointer; }
.seg.on i { background: var(--yellow); } .seg.on { color: var(--yellow); font-weight: 600; }

.screen { flex: 1; display: flex; flex-direction: column; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); gap: 12px; overflow-y: auto; min-height: 0; }
.screen.dark { background: var(--ink); color: var(--cream); }
.q { font-family: var(--display); font-weight: 700; font-size: 22px; line-height: 1.15; margin: 0; }
.small { font-size: 14px; color: #55524A; margin: 0; }
.big { font-family: var(--display); font-weight: 800; font-size: 44px; line-height: 1; }
.btn { font-family: var(--display); font-weight: 700; font-size: 17px; border: 0; border-radius: 14px; padding: 14px; background: var(--yellow); color: var(--ink); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.ghost { background: none; border: 2px solid var(--line); padding: 10px; font-size: 14px; }
.screen.dark .btn.ghost { border-color: #55524A; }
.row { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }
.stuck { align-self: flex-end; margin-bottom: -4px; font-size: 13px; background: var(--cream); border: 1.5px solid var(--ink); border-radius: 20px; padding: 5px 12px; font-weight: 600; }
.hint { background: #FFF3C4; border-left: 4px solid var(--yellow); padding: 10px 12px; font-size: 14px; border-radius: 6px; }
input[type=range] { width: 100%; accent-color: var(--blue); height: 30px; }

/* home */
.hello { font-family: var(--display); font-weight: 800; font-size: 30px; line-height: 1; margin: 4px 0 0; }
.subject { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--mute); margin-top: 6px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { border: 0; border-radius: 16px; padding: 14px 12px; min-height: 150px; text-align: left; color: #fff; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; }
.tile .tn { font-family: var(--display); font-weight: 800; font-size: 30px; line-height: 1; }
.tile .ts { font-size: 13px; opacity: .92; }
.tile .tl { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; opacity: .85; }
.tile .stars { display: flex; gap: 2px; } .tile .stars svg { width: 16px; }
.tile.soon { background: var(--line) !important; color: var(--mute); cursor: default; }

/* mission */
.mission { background: var(--ink); color: var(--cream); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.mission .lab, .missioncard .lab { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--yellow); }
.mission .mq { font-family: var(--display); font-weight: 500; font-size: 17px; line-height: 1.2; }
.facts { display: flex; gap: 6px; }
.fact { flex: 1; border-radius: 10px; padding: 6px 8px; font-size: 12px; line-height: 1.15; display: flex; gap: 8px; align-items: center; }
.fact b { font-family: var(--display); font-size: 19px; white-space: nowrap; }
.fact.r { background: var(--red); } .fact.b { background: var(--blue); }

/* story */
.line { opacity: 0; animation: fd .7s both; font-size: 17px; line-height: 1.35; margin: 0; }
.line b.r { color: #FF7A57; } .line b.b { color: #8FA0FF; } .line b.y { color: var(--yellow); }
.missioncard { border: 2px solid var(--yellow); border-radius: 14px; padding: 12px 14px; opacity: 0; animation: fd .7s both; }
.missioncard .mq { font-family: var(--display); font-size: 20px; line-height: 1.2; margin-top: 4px; }
.caption { font-size: 10px; color: var(--mute); text-align: center; letter-spacing: .1em; text-transform: uppercase; }

/* do */
.lh { flex: 1; border: 0; border-radius: 16px; padding: 10px 6px 12px; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.lh:active { transform: scale(.96); } .lh:disabled { opacity: .4; cursor: default; }
.lh.r { background: var(--red); } .lh.b { background: var(--blue); } .lh.y { background: var(--yellow); color: var(--ink); } .lh.g { background: var(--green); }
.lh b { font-family: var(--display); font-size: 19px; } .lh span { font-size: 12px; opacity: .9; }
.found { font-weight: 600; font-size: 15px; min-height: 20px; color: var(--green); margin: 0; }
.found.bad { color: var(--red); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 52px; height: 52px; border-radius: 14px; border: 2px solid var(--ink); background: #fff; font-family: var(--display); font-size: 28px; }
.stepper .big { flex: 1; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; border: 1.5px solid var(--line); border-radius: 20px; padding: 6px 10px; background: #fff; }
.chip.sel { border-color: var(--blue); background: var(--blue); color: #fff; }
.chip.ok { border-color: var(--green); color: var(--green); cursor: default; } .chip.no { border-color: var(--red); color: var(--red); cursor: default; }

/* answer */
.display { border: 2px solid var(--ink); border-radius: 14px; padding: 8px 14px; display: flex; align-items: baseline; gap: 8px; }
.display .big { min-width: 60px; font-size: 38px; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.keys button { font-family: var(--display); font-size: 20px; padding: 6px 0; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; min-height: 44px; }
.keys button.word { font-size: 14px; }
.shake { animation: shk .4s; } @keyframes shk { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.verdict { font-family: var(--display); font-weight: 700; font-size: 17px; min-height: 22px; margin: 0; }
.verdict.ok { color: var(--green); }

/* solution */
.stage { flex: 1; min-height: 420px; border-radius: 16px; position: relative; overflow: hidden; display: flex; flex-direction: column; padding: 14px 12px 12px; gap: 8px; }
.stage.a1 { background: var(--ink); color: var(--cream); } .stage.a2 { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.stage.a3 { background: var(--paper); color: var(--ink); } .stage.a4 { background: var(--blue); color: var(--cream); }
.stage .act { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; opacity: .7; display: flex; justify-content: space-between; }
.stage .head { font-family: var(--display); font-weight: 700; font-size: 24px; line-height: 1.1; margin: 0; }
.stage .say { font-size: 15px; line-height: 1.35; opacity: .92; margin: 0; }
.stage .vis { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; }
.title-card { text-align: center; color: var(--yellow); font-size: 56px; margin-top: 6px; }
.sheet { background: #fff; border-radius: 4px; box-shadow: 0 1px 0 #D6D0BF, 0 6px 16px rgba(0,0,0,.08); padding: 10px 10px 6px; color: var(--ink); }
.sheet .qt { font-size: 12px; line-height: 1.35; border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 4px; }
.sheet .qt b { font-family: var(--display); margin-right: 4px; } .sheet .qt .mk { float: right; color: var(--mute); font-size: 11px; margin-left: 6px; }
.meth { font-family: var(--display); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--green); margin: 2px 0 4px; }
.prod { font-family: var(--display); font-size: 20px; font-weight: 600; margin: 4px 8px; }
.pf { display: inline-block; min-width: 22px; text-align: center; border-radius: 6px; padding: 0 3px; border: 2px solid transparent; }
.pf.g { background: #D3EEDF; border-color: var(--green); } .pf.y { background: #FFF0B3; border-color: #D9A800; }
.key { font-size: 12px; color: #55524A; margin: 4px 8px; } .key .pf { font-family: var(--display); font-size: 13px; min-width: 16px; }
.res { font-family: var(--display); color: var(--green); font-size: 21px; font-weight: 700; text-align: center; margin: 6px 0; }
.ans { font-family: var(--display); border: 2.5px solid var(--ink); border-radius: 4px; padding: 4px 10px; margin: 4px 6px; font-size: 17px; font-weight: 600; display: inline-block; }
.work { font-family: var(--display); font-size: 19px; font-weight: 600; margin: 6px 8px; line-height: 1.6; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.05; margin: 0 2px; }
.frac span:first-child { border-bottom: 2.5px solid currentColor; padding: 0 3px; }
.ctrl { display: flex; gap: 8px; align-items: center; }
.ctrl button { font-family: var(--display); border: 1.5px solid var(--ink); background: #fff; border-radius: 12px; padding: 10px 14px; font-size: 15px; }
.ctrl button:disabled { opacity: .35; }
.ctrl button.next { background: var(--yellow); border-color: var(--yellow); flex: 1; font-weight: 700; }
.dots { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.dots button { width: 10px; height: 10px; padding: 0; border: 0; border-radius: 50%; background: var(--line); }
.dots button.on { background: var(--ink); } .dots button.d4 { background: #9BA8F5; } .dots button.d4.on { background: var(--blue); }

/* review + cards */
.rv { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.rv .ln { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding: 5px 0; }
.steps { display: flex; flex-wrap: wrap; gap: 5px; }
.steps button { font-size: 11px; border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 5px 7px; text-align: left; }
.card { background: var(--ink); color: var(--cream); border-radius: 14px; padding: 12px 14px; }
.card .t { font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--yellow); }
.card .cb { font-size: 13px; line-height: 1.45; }
.card.locked { background: none; border: 2px dashed var(--line); color: var(--mute); }
.card.locked .t { color: var(--mute); }
.starsrow { display: flex; gap: 4px; align-items: center; } .starsrow svg { width: 30px; }

/* motion */
.fade { animation: fd .6s both; } @keyframes fd { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pop { animation: pp .7s cubic-bezier(.34,1.56,.64,1) both; transform-box: fill-box; transform-origin: center; }
@keyframes pp { from { opacity: 0; transform: scale(1.8); } to { opacity: 1; transform: none; } }
.beam { opacity: 0; } .beam.r { animation: fl 2s infinite; } .beam.b { animation: fl 3s infinite; }
@keyframes fl { 0% { opacity: .95; } 18% { opacity: 0; } 100% { opacity: 0; } }
.lamp.r { animation: lampR 2s infinite; } .lamp.b { animation: lampB 3s infinite; }
@keyframes lampR { 0% { fill: #FFD23F; } 18%, 100% { fill: #D2401C; } } @keyframes lampB { 0% { fill: #FFD23F; } 18%, 100% { fill: #2740E8; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; }
  .beam { opacity: .6; }
}
