:root {
  --bg: #f7f2e7;
  --bg-deep: #efe6d3;
  --card: #fffdf8;
  --ink: #1d2233;
  --muted: #646a7a;
  --line: #e2d8c3;
  --navy: #1f2a4d;
  --navy-2: #2e3d6b;
  --apple: #d23a2f;
  --apple-soft: #fbe3df;
  --gold: #c99a38;
  --gold-soft: #f7ecd2;
  --leaf: #3f8a3c;
  --leaf-soft: #e1f0dc;
  --amber: #e08a2f;
  --radius: 18px;
  --shadow: 0 1px 0 rgba(29, 34, 51, .04), 0 10px 30px -12px rgba(29, 34, 51, .18);
  --display: "Fraunces", Georgia, serif;
  --body: "Nunito", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% -10%, #fff7e3 0, transparent 45%),
    radial-gradient(circle at 110% 10%, #eee3cc 0, transparent 40%),
    var(--bg);
  color: var(--ink);
  font: 17px/1.6 var(--body);
}
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0 0 .4em; color: var(--navy); }
h1 { font-size: clamp(30px, 5vw, 44px); font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 26px; font-weight: 800; }
h3 { font-size: 20px; font-weight: 600; }
p { margin: 0 0 1em; }
a { color: var(--navy-2); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 8px; }

main { max-width: 980px; margin: 0 auto; padding: 24px 16px 96px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 980px; margin: 0 auto;
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
}
.topbar[hidden] { display: none; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--navy); }
.brand-name { font-family: var(--display); font-weight: 800; font-size: 20px; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-weight: 700; padding: 8px; }
.link-btn:hover { color: var(--ink); }

/* buttons + inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 13px 22px; cursor: pointer;
  background: var(--navy); color: #fff; font-weight: 800; font-size: 16px;
  box-shadow: 0 6px 16px -8px rgba(31, 42, 77, .8);
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease;
  text-decoration: none;
}
.btn:hover { background: var(--navy-2); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.apple { background: var(--apple); box-shadow: 0 6px 16px -8px rgba(210, 58, 47, .9); }
.btn.apple:hover { background: #b9302a; }
.btn.ghost { background: transparent; color: var(--navy); box-shadow: inset 0 0 0 2px var(--line); }
.btn.ghost:hover { background: var(--card); }
.btn.small { padding: 8px 14px; font-size: 14px; }

.field {
  width: 100%; border: 2px solid var(--line); border-radius: 14px; background: #fff;
  padding: 14px 16px; transition: border-color .12s ease;
}
.field:focus { outline: none; border-color: var(--navy-2); }
textarea.field { resize: vertical; min-height: 92px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.muted { color: var(--muted); }
.error-text { color: var(--apple); font-weight: 700; min-height: 1.6em; margin: 8px 0 0; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px;
  font-size: 13px; font-weight: 800; background: var(--bg-deep); color: var(--muted); white-space: nowrap;
}
.pill.ready { background: var(--leaf-soft); color: var(--leaf); }
.pill.working { background: var(--gold-soft); color: #8a6519; }
.pill.failed { background: var(--apple-soft); color: var(--apple); }
.pill.mastered { background: var(--navy); color: #fff; }

/* login */
.login { min-height: 82vh; display: grid; place-items: center; }
.login .card { width: min(440px, 100%); text-align: center; padding: 32px 28px; }
.login form { display: grid; gap: 12px; margin-top: 18px; text-align: left; }
.login .lemur { margin: -8px auto 4px; }

/* home */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; margin: 8px 0 28px; }
.hero p { font-size: 19px; color: var(--muted); max-width: 52ch; }
.request { display: grid; gap: 12px; }
.request-row { display: flex; gap: 10px; }
.request-row .field { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px dashed var(--line); background: transparent; border-radius: 999px; padding: 6px 12px;
  cursor: pointer; color: var(--muted); font-weight: 700; font-size: 14px;
}
.chip:hover { border-color: var(--gold); color: var(--ink); background: var(--gold-soft); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 36px 0 12px; }
.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.topic-card {
  display: grid; gap: 10px; align-content: start; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); transition: transform .14s ease, box-shadow .14s ease;
}
.topic-card:hover { transform: translateY(-3px) rotate(-.3deg); box-shadow: 0 16px 34px -16px rgba(29, 34, 51, .35); }
.topic-card h3 { margin: 0; }
.topic-card .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topic-card .step { font-size: 14px; color: var(--muted); min-height: 1.4em; }
.topic-card.working .step::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); margin-right: 8px; animation: pulse 1s ease-in-out infinite; }
.empty { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; padding: 20px; border: 2px dashed var(--line); border-radius: var(--radius); color: var(--muted); }

/* working timeline */
.working-view { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: start; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li {
  display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start;
  animation: rise .35s ease both;
}
.timeline .dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 900; background: var(--leaf-soft); color: var(--leaf); }
.timeline li.retry .dot { background: var(--gold-soft); color: #8a6519; }
.timeline li.error .dot { background: var(--apple-soft); color: var(--apple); }
.timeline li.video .dot { background: #e4e8f6; color: var(--navy-2); }
.timeline li.current .dot { background: var(--navy); color: #fff; }
.timeline li.current .dot::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); animation: pulse .9s ease-in-out infinite; }
.timeline li.current .dot span { display: none; }
.timeline .when { font-size: 12px; color: var(--muted); }

/* lesson page */
.topic-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.objectives { margin: 0; padding-left: 1.2em; }
.objectives li { margin-bottom: 4px; }
.lesson-section { padding: 22px 0; border-top: 1px solid var(--line); }
.lesson-section .concept { font-size: 12px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }
.lesson-body p { max-width: 68ch; }
.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 18px; align-items: start; }
.cta-bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 24px; padding: 18px 20px; border-radius: var(--radius); background: var(--navy); color: #fff; }
.cta-bar h3 { color: #fff; margin: 0; }
.cta-bar .btn { background: var(--apple); }

/* video */
.player { position: relative; border-radius: var(--radius); overflow: hidden; background: #f9f6ef; aspect-ratio: 16 / 9; border: 1px solid var(--line); box-shadow: var(--shadow); }
.player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #f9f6ef; }
.player video.hidden { visibility: hidden; }
.player-wait { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; gap: 6px; padding: 16px; background: rgba(249, 246, 239, .94); transition: opacity .2s ease; }
.player-wait.off { opacity: 0; pointer-events: none; }
.player-wait .lemur { margin: 0 auto; }
.player-start { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(31, 42, 77, .25); border: 0; cursor: pointer; }
.player-start span { width: 84px; height: 84px; border-radius: 50%; background: var(--apple); display: grid; place-items: center; box-shadow: 0 12px 30px -10px rgba(0,0,0,.5); transition: transform .15s ease; }
.player-start:hover span { transform: scale(1.06); }
.player-start svg { margin-left: 6px; }
.scene-dots { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 10px; }
.scene-dots i { width: 22px; height: 6px; border-radius: 3px; background: var(--line); }
.scene-dots i.ready { background: var(--gold); }
.scene-dots i.playing { background: var(--navy); }

/* quiz */
.quiz { display: grid; gap: 16px; }
.question { padding: 20px; }
.question .qnum { font-size: 13px; font-weight: 900; color: var(--gold); letter-spacing: .06em; text-transform: uppercase; }
.question .prompt { font-weight: 800; font-size: 18px; margin: 4px 0 12px; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px; cursor: pointer; background: #fff; transition: border-color .12s, background .12s; }
.choice:hover { border-color: var(--navy-2); }
.choice:has(input:checked) { border-color: var(--navy); background: #eef1fa; }
.choice input { margin-top: 5px; accent-color: var(--navy); }
.quiz-actions { display: flex; gap: 12px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }

/* results */
.result-hero { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; }
.score { font-family: var(--display); font-weight: 800; font-size: 64px; color: var(--navy); line-height: 1; }
.score small { font-size: 26px; color: var(--muted); }
.result-list { display: grid; gap: 10px; margin-top: 18px; }
.result { display: grid; grid-template-columns: 30px 1fr; gap: 12px; padding: 14px 16px; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.result .mark { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: #fff; }
.result.right .mark { background: var(--leaf); }
.result.wrong .mark { background: var(--apple); }
.result .expected { font-size: 15px; color: var(--muted); }
.result .how { font-size: 12px; color: var(--muted); opacity: .8; }
.cert-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.cert-form .field { flex: 1; min-width: 200px; }
.cert-preview { width: 100%; aspect-ratio: 11 / 8.5; border: 1px solid var(--line); border-radius: 12px; margin-top: 14px; background: #fff; }

/* the lemur */
.lemur { display: block; flex: none; }
.lemur-xs { width: 36px; height: 36px; }
.lemur-sm { width: 84px; height: 84px; }
.lemur-md { width: 150px; height: 150px; }
.lemur-lg { width: 200px; height: 200px; }
.lemur-canvas { width: 100%; height: 100%; display: block; }
.lemur-canvas.is-pixel { image-rendering: pixelated; image-rendering: crisp-edges; }
.lemur-svg { width: 100%; height: 100%; overflow: visible; }
.lemur-svg g { transform-box: fill-box; }
.lp-props > * { opacity: 0; }
.lemur[data-clip="idle"] .lp-body, .lemur[data-clip="idle"] .lp-head { animation: breathe 2.4s ease-in-out infinite; }
.lemur[data-clip="idle"] .lp-tail { transform-origin: 0% 100%; animation: sway 3s ease-in-out infinite; }
.lemur .lp-eye { transform-box: fill-box; transform-origin: center; animation: blink 4.5s infinite; }
.lemur[data-clip="write"] .lp-pad { opacity: 1; }
.lemur[data-clip="write"] .lp-arm-r { transform-origin: 20% 0%; animation: scribble .35s ease-in-out infinite alternate; }
.lemur[data-clip="write"] .lp-head { transform-origin: 50% 100%; animation: nod 1.2s ease-in-out infinite; }
.lemur[data-clip="juggle"] .lp-apple { opacity: 1; animation: juggle 1.2s linear infinite; }
.lemur[data-clip="juggle"] .a2 { animation-delay: -.4s; }
.lemur[data-clip="juggle"] .a3 { animation-delay: -.8s; }
.lemur[data-clip="juggle"] .lp-arm-l, .lemur[data-clip="juggle"] .lp-arm-r { animation: toss .4s ease-in-out infinite alternate; }
.lemur[data-clip="think"] .lp-head { transform-origin: 50% 100%; animation: tilt 1.6s ease-in-out infinite; }
.lemur[data-clip="think"] .lp-q { opacity: 1; animation: floaty 1.6s ease-in-out infinite; }
.lemur[data-clip="encourage"] .lp-arm-r { transform-origin: 20% 0%; animation: offer 1.2s ease-out both; }
.lemur[data-clip="celebrate"] svg { animation: jump .6s ease-out 3; }
.lemur[data-clip="celebrate"] .lp-arm-l, .lemur[data-clip="celebrate"] .lp-arm-r { transform-origin: 50% 0%; animation: cheer .3s ease-in-out 6 alternate; }
.lemur[data-clip="wave"] .lp-arm-l { transform-origin: 50% 0%; animation: wave .3s ease-in-out 6 alternate; }
.lemur[data-clip="thumbs_up"] .lp-arm-l { transform-origin: 50% 0%; transform: rotate(150deg); }
.lemur[data-clip="pull_down"] .lp-arm-l, .lemur[data-clip="pull_down"] .lp-arm-r { transform-origin: 50% 0%; transform: rotate(170deg); }
.lemur[data-clip="pull_down"] svg { animation: tug .5s ease-in-out 2 alternate; }

@keyframes breathe { 50% { transform: translateY(1.5px) scaleY(.985); } }
@keyframes sway { 50% { transform: rotate(6deg); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes scribble { to { transform: rotate(-14deg) translateX(-2px); } }
@keyframes nod { 50% { transform: rotate(4deg); } }
@keyframes juggle { 0% { transform: translate(-18px, 30px); } 25% { transform: translate(-10px, -8px); } 50% { transform: translate(17px, 30px); } 75% { transform: translate(8px, -8px); } 100% { transform: translate(-18px, 30px); } }
@keyframes toss { to { transform: translateY(-3px); } }
@keyframes tilt { 50% { transform: rotate(-9deg); } }
@keyframes floaty { 50% { transform: translateY(-4px); } }
@keyframes offer { 40% { transform: rotate(-35deg) translate(4px, -2px); } 100% { transform: rotate(-20deg); } }
@keyframes jump { 40% { transform: translateY(-14px); } }
@keyframes cheer { from { transform: rotate(150deg); } to { transform: rotate(185deg); } }
@keyframes wave { from { transform: rotate(130deg); } to { transform: rotate(170deg); } }
@keyframes tug { to { transform: translateY(6px); } }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* window-shade transition */
.shade { position: fixed; inset: 0; z-index: 100; pointer-events: none; overflow: hidden; }
.shade-panel {
  position: absolute; inset: 0; transform: translateY(calc(-100% - 140px));
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.06) 0 2px, transparent 2px 22px),
    linear-gradient(var(--navy-2), var(--navy));
  transition: transform .5s cubic-bezier(.6, .05, .3, 1);
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  display: grid; place-items: center;
}
.shade.down .shade-panel { transform: translateY(0); }
.shade.up .shade-panel { transform: translateY(calc(-100% - 140px)); transition-duration: .45s; transition-timing-function: cubic-bezier(.5, 0, .75, 0); }
.shade-caption { font-family: var(--display); font-weight: 800; color: #fff; font-size: clamp(24px, 4vw, 36px); opacity: .9; }
.shade-pull { position: absolute; bottom: -70px; left: 50%; transform: translateX(-50%); display: grid; justify-items: center; }
.shade-cord { width: 3px; height: 26px; background: var(--gold); }
.shade-lemur { width: 84px; height: 84px; }
.shade-panel::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 12px; background: var(--gold); }

/* wait overlay */
.wait-overlay { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(247, 242, 231, .82); backdrop-filter: blur(3px); opacity: 0; transition: opacity .2s ease; padding: 16px; }
.wait-overlay.on { opacity: 1; }
.wait-card { text-align: center; display: grid; justify-items: center; gap: 8px; }
.wait-msg { font-family: var(--display); font-weight: 800; font-size: 22px; color: var(--navy); }

/* apple confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; overflow: hidden; }
.confetti i { position: absolute; top: -30px; width: 16px; height: 16px; border-radius: 50%; background: var(--apple); animation: fall linear forwards; }
.confetti i::after { content: ""; position: absolute; width: 7px; height: 4px; border-radius: 50%; background: var(--leaf); top: -2px; left: 7px; transform: rotate(-30deg); }
.confetti i.gold { background: var(--gold); }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; }
  .hero .lemur { display: none; }
  .request-row { flex-direction: column; }
  .grid-2 { grid-template-columns: 1fr; }
  .working-view { grid-template-columns: 1fr; justify-items: center; }
  .result-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .score { font-size: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
