/* Layout: one-screen lesson player. Sticky progress header, one step per screen, thumb-reach action bar at the bottom.
   Identity: "highlighter" colors, one per prompt ingredient, used everywhere that ingredient appears. */
:root {
  --bg: #F1F2F6;
  --surface: #FFFFFF;
  --ink: #141726;
  --muted: #586077;
  --line: #DADDE7;
  --ctx: #2459E0;
  --task: #D9540B;
  --rule: #BE2560;
  --fmt: #0A8763;
  --ex: #6C3FD1;
  --good: #0A8763;
  --bad: #C42B2B;
  --btn: #141726;
  --btn-fg: #FFFFFF;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1019; --surface: #181B28; --ink: #E8EAF3; --muted: #9AA1B6; --line: #2B2F40;
    --ctx: #7BA2FF; --task: #FF9150; --rule: #F2709E; --fmt: #3CCB9C; --ex: #B49BFF; --good: #3CCB9C; --bad: #FF7373;
    --btn: #E8EAF3; --btn-fg: #0E1019; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1019; --surface: #181B28; --ink: #E8EAF3; --muted: #9AA1B6; --line: #2B2F40;
  --ctx: #7BA2FF; --task: #FF9150; --rule: #F2709E; --fmt: #3CCB9C; --ex: #B49BFF; --good: #3CCB9C; --bad: #FF7373;
  --btn: #E8EAF3; --btn-fg: #0E1019; color-scheme: dark;
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 17px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
* { box-sizing: border-box; }
img { max-width: 100%; }
button { font: inherit; color: inherit; }
a { color: var(--ctx); font-weight: 700; text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--ctx); outline-offset: 2px; border-radius: 6px; }

.app { max-width: 560px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* Header */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px 10px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px;
}
.top-row { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
}
.top-label { flex: 1; min-width: 0; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.progress span { height: 5px; border-radius: 3px; background: var(--line); transition: background .3s; }
.progress span.done { background: var(--ink); }

/* Stage */
main {
  flex: 1; display: flex; flex-direction: column; gap: 18px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px 150px;
}
main > * { min-width: 0; }
.step-in { animation: rise .35s ease-out; }
@keyframes rise { from { transform: translateY(10px); opacity: .4; } to { transform: none; opacity: 1; } }

.eyebrow { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 0; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; letter-spacing: -.01em; }
h1 { font-size: clamp(32px, 9vw, 44px); line-height: 1.05; font-weight: 800; }
h2 { font-size: clamp(25px, 7vw, 31px); line-height: 1.12; font-weight: 700; }
h3 { font-size: 20px; line-height: 1.2; font-weight: 700; }
p { margin: 0; max-width: 62ch; }
.lead { font-size: 18px; color: var(--muted); }
.small { font-size: 14px; color: var(--muted); }
.stack { display: grid; gap: 10px; }

/* Ingredient highlighter */
.hl { padding: 1px 3px; border-radius: 3px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.hl.ctx { background: color-mix(in srgb, var(--ctx) 17%, transparent); box-shadow: inset 0 -2px 0 var(--ctx); }
.hl.task { background: color-mix(in srgb, var(--task) 17%, transparent); box-shadow: inset 0 -2px 0 var(--task); }
.hl.rule { background: color-mix(in srgb, var(--rule) 17%, transparent); box-shadow: inset 0 -2px 0 var(--rule); }
.hl.fmt { background: color-mix(in srgb, var(--fmt) 17%, transparent); box-shadow: inset 0 -2px 0 var(--fmt); }
.hl.ex { background: color-mix(in srgb, var(--ex) 15%, transparent); box-shadow: inset 0 -2px 0 var(--ex); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ctx { background: var(--ctx); } .dot.task { background: var(--task); } .dot.rule { background: var(--rule); }
.dot.fmt { background: var(--fmt); } .dot.ex { background: var(--ex); }

/* Prompt box: looks like a chat input */
.prompt {
  font-family: var(--font-mono); font-size: 14.5px; line-height: 1.75; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; overflow-wrap: anywhere; white-space: pre-wrap;
}
.prompt-label { display: flex; align-items: center; gap: 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.reply { border-left: 3px solid var(--line); padding: 4px 0 4px 14px; font-size: 16px; display: grid; gap: 8px; min-width: 0; }
.reply .small { display: block; }
.reply ul, .reply ol { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.table-wrap { overflow-x: auto; }
.reply table { border-collapse: collapse; font-size: 14.5px; min-width: 100%; }
.reply th, .reply td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.reply th { font-size: 12.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.chat { display: grid; gap: 10px; }

/* Segmented toggle */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg.wrap { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
.seg button { border: 0; background: transparent; padding: 10px 8px; border-radius: 9px; font-weight: 700; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1.25; }
.seg button[aria-pressed="true"] { background: var(--btn); color: var(--btn-fg); }

/* Reveal cards */
.ingr { display: grid; gap: 10px; }
.ingr-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.ingr-card > button { width: 100%; text-align: left; border: 0; background: transparent; padding: 14px 16px; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.ingr-name { font-family: var(--font-display); font-weight: 700; font-size: 20px; flex: 1; }
.ingr-q { font-size: 14px; color: var(--muted); }
.ingr-body { padding: 0 16px 16px; display: grid; gap: 8px; }
.chev { transition: transform .2s; color: var(--muted); flex: none; }
.ingr-card.open .chev { transform: rotate(90deg); }
.seen { font-size: 12px; font-weight: 700; color: var(--good); }

/* Quiz options */
.opts { display: grid; gap: 10px; }
.opt {
  text-align: left; width: 100%; background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 14px 16px; cursor: pointer; display: flex; gap: 12px; align-items: flex-start; min-height: 52px;
}
.opt .key { font-family: var(--font-mono); font-size: 13px; color: var(--muted); padding-top: 2px; flex: none; }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 9%, var(--surface)); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.opt.dim { opacity: .55; }

.feedback { border-radius: 14px; padding: 14px 16px; display: grid; gap: 4px; border: 1.5px solid; }
.feedback strong { font-family: var(--font-display); font-size: 18px; }
.feedback.ok { border-color: var(--good); background: color-mix(in srgb, var(--good) 8%, var(--surface)); }
.feedback.no { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 7%, var(--surface)); }
.feedback.ok strong { color: var(--good); } .feedback.no strong { color: var(--bad); }

/* Tap-a-phrase */
.tapline { display: flex; flex-wrap: wrap; gap: 8px; }
.tapline button {
  font-family: var(--font-mono); font-size: 14px; background: var(--surface); border: 1.5px dashed var(--muted);
  border-radius: 10px; padding: 10px 12px; cursor: pointer; text-align: left; line-height: 1.45;
}
.tapline button[aria-pressed="true"] { border-style: solid; border-color: var(--ink); background: color-mix(in srgb, var(--ink) 9%, var(--surface)); }
.tapline button.right { border-style: solid; border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, var(--surface)); }
.tapline button.wrong { border-style: solid; border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.tapline button.missed { border-style: solid; border-color: var(--task); }
.tapline button:disabled { cursor: default; }

/* Sorting */
.pool { display: flex; flex-wrap: wrap; gap: 8px; min-height: 48px; }
.chip {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px;
  font-size: 15px; cursor: pointer; text-align: left; line-height: 1.35;
}
.chip.sel { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 15%, transparent); }
.bins { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bin {
  border: 1.5px solid var(--line); border-radius: 14px; padding: 10px; min-height: 92px; background: var(--surface);
  display: flex; flex-direction: column; gap: 6px; cursor: pointer; text-align: left; min-width: 0;
}
.bin-head { display: flex; align-items: center; gap: 6px; font-family: var(--font-display); font-weight: 700; font-size: 16px; line-height: 1.2; }
.bin-item { font-size: 13px; line-height: 1.3; padding: 6px 8px; border-radius: 8px; background: color-mix(in srgb, var(--muted) 12%, transparent); }
.bin.ctx .bin-item { background: color-mix(in srgb, var(--ctx) 14%, transparent); }
.bin.task .bin-item { background: color-mix(in srgb, var(--task) 14%, transparent); }
.bin.rule .bin-item { background: color-mix(in srgb, var(--rule) 14%, transparent); }
.bin.fmt .bin-item { background: color-mix(in srgb, var(--fmt) 14%, transparent); }
.bin.ex .bin-item { background: color-mix(in srgb, var(--ex) 14%, transparent); }
.bin.armed { border-style: dashed; border-color: var(--ink); }
.shake { animation: shake .35s; border-color: var(--bad) !important; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.hint { font-size: 14px; color: var(--muted); min-height: 21px; }
.hint.no { color: var(--bad); font-weight: 700; }

/* Ordering */
.seq { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.seq li { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1.5px solid var(--good); border-radius: 12px; padding: 10px 12px; font-size: 15px; }
.seq li b { font-family: var(--font-mono); font-size: 13px; color: var(--good); padding-top: 2px; }
.seq-empty { border: 1.5px dashed var(--line); border-radius: 12px; padding: 12px; color: var(--muted); font-size: 14px; }

/* Dial (slider simulator) */
.dial { display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.dial-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; font-weight: 700; }
.dial-row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.dial input[type="range"] { width: 100%; accent-color: var(--ink); height: 32px; margin: 0; }
.dial-ticks { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* Meter */
.meter { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 74px); z-index: 4; background: var(--bg); padding-block: 6px; display: grid; gap: 6px; }
.meter-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; font-weight: 700; }
.meter-row b { font-family: var(--font-display); font-size: 22px; font-variant-numeric: tabular-nums; }
.meter-track { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; display: flex; }
.meter-track i { display: block; height: 100%; transition: width .45s cubic-bezier(.2,.8,.2,1); background: var(--ink); }
.meter-track i.ctx { background: var(--ctx); } .meter-track i.task { background: var(--task); }
.meter-track i.rule { background: var(--rule); } .meter-track i.fmt { background: var(--fmt); } .meter-track i.ex { background: var(--ex); }
.meter-track i + i { box-shadow: inset 2px 0 0 var(--bg); }

.slot { display: grid; gap: 8px; }
.slot-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.slot-head .dot { align-self: center; }
.slot-head .small { font-family: var(--font-body); font-weight: 400; }
.radio {
  text-align: left; width: 100%; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; font-family: var(--font-mono); font-size: 14px; line-height: 1.5;
}
.radio[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
.verdict { font-size: 14px; padding-left: 2px; }
.verdict b.s { color: var(--good); } .verdict b.m { color: var(--task); } .verdict b.w { color: var(--bad); }

/* Forms */
.field { display: grid; gap: 6px; }
.field label { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.field label .small { font-family: var(--font-body); font-weight: 400; }
.field textarea, .field input {
  width: 100%; font-family: var(--font-mono); font-size: 15px; line-height: 1.5; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.field textarea { resize: vertical; min-height: 76px; }
.field textarea:focus, .field input:focus { outline: none; border-color: var(--ink); }
.field .tip { font-size: 13.5px; color: var(--muted); }
.field .tip:empty { display: none; }
.field .tip.warn { color: var(--rule); font-weight: 700; }
.ghost { border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 9px 16px; font-weight: 700; cursor: pointer; font-size: 15px; }
.ghost.danger { color: var(--bad); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 15px; }
.checks li { display: flex; gap: 8px; align-items: flex-start; }
.checks li::before { content: "○"; color: var(--muted); font-weight: 700; width: 16px; flex: none; }
.checks li.ok::before { content: "✓"; color: var(--good); }

/* Finish */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 2px; align-content: start; }
.stat b { font-family: var(--font-display); font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { font-size: 12.5px; color: var(--muted); line-height: 1.3; }
.check { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.check li { display: flex; gap: 10px; align-items: flex-start; }
.check .dot { margin-top: 7px; }
.locked { border: 1.5px dashed var(--line); border-radius: 14px; padding: 14px 16px; display: grid; gap: 4px; }
.next-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: grid; gap: 4px; }

/* Intro */
.badge { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 700; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; width: fit-content; }
.outline { list-style: none; padding: 0; margin: 0; display: grid; border-top: 1px solid var(--line); }
.outline li { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.outline li span:first-child { font-family: var(--font-mono); font-size: 13px; color: var(--muted); padding-top: 3px; width: 44px; flex: none; }
.ingr-strip { display: flex; flex-wrap: wrap; gap: 6px; }

/* Course home */
.course-meter { display: grid; gap: 6px; }
.lessons { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lesson-row {
  width: 100%; text-align: left; display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer;
}
.lesson-row:disabled { cursor: default; opacity: .6; background: transparent; }
.lesson-row.current { border-color: var(--ink); }
.lesson-num { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 18px; border: 1.5px solid var(--line); }
.lesson-row.done .lesson-num { background: var(--good); border-color: var(--good); color: var(--bg); }
.lesson-row.current .lesson-num { background: var(--btn); border-color: var(--btn); color: var(--btn-fg); }
.lesson-title { font-family: var(--font-display); font-weight: 700; font-size: 18px; line-height: 1.2; display: block; }
.lesson-sub { font-size: 13.5px; color: var(--muted); display: block; margin-top: 2px; }
.status { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.lesson-row.done .status { color: var(--good); }
.lesson-row.current .status { color: var(--ink); }

/* Library */
.lib { display: grid; gap: 10px; }
.lib-item { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: grid; gap: 8px; min-width: 0; }
.lib-item h3 { font-size: 18px; }
.lib-when { font-size: 14px; color: var(--muted); }
.lib-text { font-family: var(--font-mono); font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 9.6em; overflow: hidden; position: relative; }
.lib-text.full { max-height: none; }
.lib-meta { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.lib-empty { border: 1.5px dashed var(--line); border-radius: 14px; padding: 14px 16px; color: var(--muted); font-size: 15px; }
.ph { font-weight: 700; color: var(--task); }

/* Bottom bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: linear-gradient(to top, var(--bg) 70%, color-mix(in srgb, var(--bg) 0%, transparent));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 22px calc(14px + env(safe-area-inset-bottom, 0px));
}
.bar-inner { max-width: 528px; margin: 0 auto; display: grid; gap: 6px; }
.bar-note { text-align: center; font-size: 13.5px; color: var(--muted); min-height: 20px; }
.cta {
  width: 100%; border: 0; border-radius: 14px; padding: 16px; font-family: var(--font-display); font-weight: 700; font-size: 18px;
  background: var(--btn); color: var(--btn-fg); cursor: pointer; transition: transform .1s, opacity .2s;
}
.cta:active { transform: scale(.98); }
.cta:disabled { opacity: .3; cursor: default; transform: none; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(118px + env(safe-area-inset-bottom, 0px)); background: var(--btn); color: var(--btn-fg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; z-index: 20; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
