/* Design tokens: one neutral surface family, one primary, one accent, two semantic colours. */
:root {
  --ink: #0e1420;
  --ink-2: #5c6675;
  --ink-3: #98a1ae;
  --surface: #f5f6f8;
  --surface-2: #eceef2;
  --card: #ffffff;
  --line: rgba(14, 20, 32, .09);
  --primary: #0b5fd1;
  --primary-ink: #ffffff;
  --primary-soft: rgba(11, 95, 209, .10);
  --accent: #c9323f;
  --success: #1b8a4b;
  --success-soft: #e6f5ec;
  --danger: #c43d3d;
  --danger-soft: #fbeaea;
  --glass: rgba(255, 255, 255, .78);
  --shadow: 0 12px 32px rgba(14, 20, 32, .10), 0 1px 2px rgba(14, 20, 32, .06);
  --shadow-sheet: 0 -16px 48px rgba(14, 20, 32, .16);
  --r-s: 10px;
  --r-m: 16px;
  --r-l: 24px;
  --gutter: 20px;
  --ease: cubic-bezier(.32, .72, 0, 1);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--surface); color: var(--ink); font: 400 16px/1.45 var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
#camerafeed { position: fixed; inset: 0; width: 100%; height: 100%; display: none; }
body:not([data-screen="welcome"]) #camerafeed { display: block; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
h1, h2, p { margin: 0; }
h1 { font-size: 36px; line-height: 1.08; font-weight: 700; letter-spacing: -.025em; }
h2 { font-size: 21px; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
.overline { display: block; color: var(--ink-3); font-size: 12px; line-height: 1.2; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.eyebrow { color: var(--primary); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.lead { color: var(--ink-2); font-size: 17px; line-height: 1.5; }
.footnote { color: var(--ink-3); font-size: 13px; text-align: center; }

/* Buttons: one family, three weights, plus round icon buttons. */
.btn { display: inline-flex; align-items: center; justify-content: center; width: 100%; min-height: 54px; padding: 0 22px; border-radius: var(--r-m); font-size: 17px; font-weight: 600; letter-spacing: -.005em; transition: transform .14s var(--ease), background-color .14s, opacity .14s; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; }
.btn-primary { color: var(--primary-ink); background: var(--primary); box-shadow: 0 8px 20px rgba(11, 95, 209, .22); }
.btn-primary:active { background: #0a53b6; }
.btn-secondary { color: var(--ink); background: var(--surface-2); }
.btn-secondary:active { background: #e1e4ea; }
.btn-ghost { min-height: 48px; color: var(--primary); font-weight: 500; }
.btn-ghost:active { opacity: .6; }
.icon-btn { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; color: var(--ink); transition: transform .14s var(--ease), opacity .14s; }
.icon-btn:active { transform: scale(.92); opacity: .7; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.small { width: 40px; height: 40px; color: var(--ink-2); }
.icon-btn.small svg { width: 20px; height: 20px; }
.icon-btn.play { width: 58px; height: 58px; color: var(--primary-ink); background: var(--primary); box-shadow: 0 8px 20px rgba(11, 95, 209, .26); }
.icon-btn.play svg { width: 24px; height: 24px; stroke-width: 1.5; fill: currentColor; }

.glass { background: var(--glass); -webkit-backdrop-filter: saturate(160%) blur(24px); backdrop-filter: saturate(160%) blur(24px); box-shadow: var(--shadow), inset 0 0 0 .5px rgba(255, 255, 255, .6); }
.actions { display: grid; gap: 10px; }
.actions.row { grid-template-columns: 1fr 1fr; }

/* Welcome */
.screen { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; overflow: auto; max-width: 520px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 48px) var(--gutter) calc(env(safe-area-inset-bottom) + 24px); background: radial-gradient(120% 70% at 50% -10%, #ffffff 0%, var(--surface) 70%); transition: opacity .32s var(--ease), visibility .32s; }
body:not([data-screen="welcome"]) #welcome { opacity: 0; visibility: hidden; pointer-events: none; }
.welcome-top { display: grid; gap: 14px; }
.mark { display: grid; justify-self: start; place-items: center; width: 64px; height: 64px; margin-bottom: 10px; border-radius: 20px; color: var(--accent); background: var(--card); box-shadow: var(--shadow); }
.mark svg { width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.facts { display: grid; gap: 2px; margin: 32px 0 0; padding: 6px 0; list-style: none; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.facts li { display: flex; align-items: center; gap: 14px; min-height: 52px; color: var(--ink); font-size: 15px; font-weight: 500; }
.fact-icon { display: grid; flex: none; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--primary); background: var(--primary-soft); }
.fact-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
#welcome .actions { margin-top: auto; padding-top: 28px; }
.welcome-top > *, .facts, #welcome .actions { animation: rise .6s var(--ease) both; }
.welcome-top > :nth-child(2) { animation-delay: .06s; }
.welcome-top > :nth-child(3) { animation-delay: .12s; }
.welcome-top > :nth-child(4) { animation-delay: .18s; }
.facts { animation-delay: .26s; }
#welcome .actions { animation-delay: .34s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Lesson overlay */
#hud { position: fixed; inset: 0; z-index: 30; display: none; flex-direction: column; gap: 12px; max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) calc(env(safe-area-inset-bottom) + 16px); pointer-events: none; }
body:not([data-screen="welcome"]) #hud { display: flex; }
body.clean #hud { display: none; }
#hud button { pointer-events: auto; }
.grow { flex: 1; }
#topbar { padding: 8px 8px 12px 18px; border-radius: 20px; }
.topbar-row { display: flex; align-items: center; gap: 2px; min-height: 40px; }
.topbar-text { display: grid; flex: 1; gap: 2px; min-width: 0; }
#chapterIndex:empty { display: none; }
#chapter { overflow: hidden; font-size: 16px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; text-overflow: ellipsis; }
#progress { display: flex; gap: 5px; margin: 8px 10px 0 0; }
#progress span { flex: 1; height: 3px; overflow: hidden; border-radius: 2px; background: rgba(14, 20, 32, .12); }
#progress i { display: block; width: 0; height: 100%; border-radius: 2px; background: var(--primary); }
#subtitle { display: none; padding: 13px 18px; border-radius: var(--r-m); font-size: 17px; line-height: 1.4; font-weight: 500; letter-spacing: -.005em; text-align: center; }
#subtitle.active { display: block; animation: fade .25s var(--ease); }
#status { position: relative; display: none; overflow: hidden; padding: 12px 18px; border-radius: var(--r-m); color: var(--ink-2); font-size: 15px; font-weight: 500; text-align: center; }
#status.active { display: block; animation: fade .25s var(--ease); }
#statusBar { position: absolute; left: 0; bottom: 0; display: none; width: 0; height: 3px; border-radius: 2px; background: var(--primary); transition: width .3s var(--ease); }
#status.loading #statusBar { display: block; }
#prompt:empty { display: none; }
#prompt .btn { animation: rise .4s var(--ease); }
#controls { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 999px; }
.icon-btn.nav { display: inline-flex; gap: 6px; width: auto; min-width: 48px; padding: 0 14px 0 10px; border-radius: 999px; font-size: 15px; font-weight: 600; letter-spacing: -.005em; }
.icon-btn.nav svg { width: 20px; height: 20px; fill: currentColor; stroke-width: 1.6; }
.icon-btn.nav:last-child { padding: 0 10px 0 14px; }
.icon-btn:disabled { opacity: .3; pointer-events: none; }

/* Labels, leader lines and scene transitions */
#veil { position: fixed; inset: 0; z-index: 10; background: var(--surface); opacity: 0; pointer-events: none; }
#lines { position: fixed; inset: 0; z-index: 20; width: 100%; height: 100%; pointer-events: none; }
#lines line { stroke: #fff; stroke-width: 1.5; stroke-linecap: round; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .5)); }
#labels { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
.callout { position: absolute; display: none; width: max-content; max-width: min(66vw, 300px); padding: 9px 15px; border-radius: 14px; text-align: center; transform: translate(-50%, -50%); background: var(--glass); -webkit-backdrop-filter: saturate(160%) blur(24px); backdrop-filter: saturate(160%) blur(24px); box-shadow: var(--shadow); }
.callout.active { display: block; }
.callout strong { display: block; font-size: 15px; font-weight: 600; letter-spacing: -.005em; }
.callout span { display: block; margin-top: 1px; color: var(--ink-2); font-size: 13px; line-height: 1.3; }
.callout span:empty { display: none; }
body[data-screen="welcome"] #labels, body[data-screen="welcome"] #lines { display: none; }

/* Sheets */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-width: 560px; max-height: calc(100% - env(safe-area-inset-top) - 24px); margin: 0 auto; padding: 22px var(--gutter) calc(env(safe-area-inset-bottom) + 20px); overflow: auto; border-radius: var(--r-l) var(--r-l) 0 0; background: var(--card); box-shadow: var(--shadow-sheet); transform: translateY(110%); transition: transform .42s var(--ease); }
.sheet::before { content: ""; display: block; width: 36px; height: 4px; margin: -8px auto 18px; border-radius: 2px; background: var(--line); }
body[data-screen="finish"] #finish, body[data-screen="quiz"] #quiz, #report:not([hidden]) { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.steps { display: flex; gap: 4px; }
.steps i { width: 18px; height: 3px; border-radius: 2px; background: var(--surface-2); }
.steps i.done { background: var(--primary); }
.steps i.now { background: var(--ink-3); }

/* Quiz */
#quizBody.enter { animation: rise .32s var(--ease); }
#choices { display: grid; gap: 8px; margin: 18px 0 14px; }
.choice { display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 10px 14px 10px 10px; border: 1.5px solid var(--line); border-radius: var(--r-m); text-align: left; font-size: 16px; font-weight: 500; line-height: 1.3; background: var(--card); transition: transform .14s var(--ease), border-color .18s, background-color .18s, opacity .18s; }
.choice:not(:disabled):active { transform: scale(.985); background: var(--surface); }
.choice:disabled { opacity: 1; }
.choice b { display: grid; flex: none; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: var(--ink-2); font-size: 13px; font-weight: 600; background: var(--surface-2); }
.choice b svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.choice.correct { border-color: var(--success); background: var(--success-soft); }
.choice.correct b { color: #fff; background: var(--success); }
.choice.wrong { border-color: var(--danger); background: var(--danger-soft); }
.choice.wrong b { color: #fff; background: var(--danger); }
.choice.faded { opacity: .55; }
#feedback { min-height: 46px; margin-bottom: 14px; color: var(--ink-2); font-size: 15px; line-height: 1.45; }
#feedback:not(:empty) { animation: fade .25s var(--ease); }
#feedback strong { font-weight: 600; }
#feedback.good strong { color: var(--success); }
#feedback.bad strong { color: var(--danger); }

/* Results */
.result { display: grid; justify-items: center; gap: 6px; padding: 6px 0 18px; text-align: center; }
.ring { position: relative; width: 124px; height: 124px; margin-bottom: 10px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; stroke-linecap: round; }
.ring-track { stroke: var(--surface-2); }
.ring-fill { stroke: var(--primary); stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset 1s var(--ease) .15s; }
.ring-value { position: absolute; inset: 0; display: grid; place-content: center; }
.ring-value strong { font-size: 36px; line-height: 1; font-weight: 700; letter-spacing: -.03em; }
.ring-value span { margin-top: 3px; color: var(--ink-3); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
#finishBody { color: var(--ink-2); font-size: 15px; }
#finishBody:empty { display: none; }
.code { margin-bottom: 12px; padding: 14px 16px; border-radius: var(--r-s); text-align: center; background: var(--primary-soft); }
.code strong { display: block; margin: 4px 0 2px; color: var(--primary); font-size: 30px; font-weight: 700; letter-spacing: .18em; font-variant-numeric: tabular-nums; }
.code strong:empty { display: none; }
.code p { margin: 0; color: var(--ink-2); font-size: 14px; line-height: 1.4; }
.closing { margin-bottom: 18px; padding: 14px 16px; border-radius: var(--r-s); color: var(--ink-2); font-size: 14px; line-height: 1.45; text-align: center; background: var(--surface); }
#log { max-height: 42vh; margin: 0 0 16px; padding: 12px; overflow: auto; border-radius: var(--r-s); background: var(--surface); font: 12px/1.5 ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }

/* Lite mode: no blur over the camera image, which is the costliest effect on slow phones. */
body.lite .glass, body.lite .callout { background: rgba(255, 255, 255, .94); -webkit-backdrop-filter: none; backdrop-filter: none; }

@media (max-height: 640px) {
  h1 { font-size: 30px; }
  .screen { padding-top: calc(env(safe-area-inset-top) + 24px); }
  .mark { width: 52px; height: 52px; }
  .facts { margin-top: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
