:root {
  --bg: #F6F8FC; --surface: #FFFFFF; --surface-2: #EEF2F9; --ink: #16305C; --text: #26324A;
  --muted: #55607A; --line: #D8DFEB; --gold: #E3B04B; --gold-ink: #835F12; --gold-soft: #FBF1DC;
  --ok: #1F7A4D; --ok-soft: #E3F3EA; --danger: #A23B2A;
  --band: #16305C; --band-text: #F2F5FB;
  --bubble-a: #FFFFFF; --bubble-b: #E9EFF9;
  --display: 'Sora', 'Segoe UI', system-ui, sans-serif;
  --body: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 48, 92, .06), 0 4px 16px rgba(22, 48, 92, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1730; --surface: #12244A; --surface-2: #0F1F40; --ink: #F2F5FB; --text: #DCE3F1;
    --muted: #A6B1C9; --line: #253A63; --gold-ink: #EBC57A; --gold-soft: #2A2A26;
    --ok: #6FD3A0; --ok-soft: #14352A; --danger: #F29B8B;
    --band: #07101F; --bubble-a: #12244A; --bubble-b: #1B3260;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B1730; --surface: #12244A; --surface-2: #0F1F40; --ink: #F2F5FB; --text: #DCE3F1;
  --muted: #A6B1C9; --line: #253A63; --gold-ink: #EBC57A; --gold-soft: #2A2A26;
  --ok: #6FD3A0; --ok-soft: #14352A; --danger: #F29B8B;
  --band: #07101F; --bubble-a: #12244A; --bubble-b: #1B3260;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--body);
  font-size: 17px; line-height: 1.6; -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
a { color: var(--ink); text-underline-offset: 3px; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3, h4 { font-family: var(--display); color: var(--ink); line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); letter-spacing: -0.015em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 12px; }

/* Logo */
.mark { flex: none; --knock: var(--bg); color: var(--ink); }
.mark .m-ink { fill: none; stroke: currentColor; stroke-width: 24px; stroke-linecap: round; stroke-linejoin: round; }
.mark .m-knock { fill: none; stroke: var(--knock); stroke-width: 40px; stroke-linecap: round; stroke-linejoin: round; }
.mark .m-gold { fill: none; stroke: var(--gold); stroke-width: 24px; stroke-linecap: round; stroke-linejoin: round; }
.mark .m-cut { stroke-linecap: butt; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--display); font-weight: 700; font-size: 1.1rem; color: var(--ink); }
.brand .mark { --knock: var(--surface); }
.brand small { font-weight: 400; color: var(--muted); font-size: .85rem; }
.nav { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-size: .9rem; }
.nav a, .nav button { text-decoration: none; color: var(--muted); background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.nav a:hover, .nav button:hover { color: var(--ink); background: var(--surface-2); }
.nav .who { color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .nav .who, .brand small { display: none; } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--display); font-weight: 600; font-size: .95rem;
  border-radius: 10px; padding: 11px 18px; border: 1px solid transparent; cursor: pointer;
  text-decoration: none; transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { filter: brightness(1.12); }
.btn-gold { background: var(--gold); color: #1B2440; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-sm { padding: 7px 12px; font-size: .85rem; }

/* Cards and layout */
main { padding: 28px 0 80px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.eyebrow { font-family: var(--display); font-size: .75rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--gold-ink); }
.muted { color: var(--muted); }
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; border-radius: 12px; background: var(--gold-soft); border: 1px solid var(--gold); margin: 18px 0; }
.banner p { margin: 0; }
.banner > span { color: var(--gold-ink); margin-top: 3px; flex: none; }
.banner strong { font-family: var(--display); color: var(--ink); }

/* Sign-in */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 440px; padding: 34px 28px; }
.auth .brand { font-size: 1.25rem; margin-bottom: 22px; }
.auth h1 { font-size: 1.6rem; margin-bottom: 8px; }
.field { display: grid; gap: 6px; margin: 18px 0 14px; font-family: var(--display); font-size: .88rem; font-weight: 600; color: var(--ink); }
.field input { font-family: var(--body); font-size: 1.05rem; font-weight: 400; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.field input:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px var(--gold-soft); }
.auth .btn { width: 100%; }
.note { font-size: .9rem; color: var(--muted); margin-top: 16px; }
.msg { margin-top: 14px; padding: 12px 14px; border-radius: 10px; font-size: .95rem; }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.err { background: #FBE9E5; color: var(--danger); }

/* Dashboard */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: end; margin-bottom: 8px; }
@media (max-width: 720px) { .hero { grid-template-columns: 1fr; } }
.progress-line { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress-line span { display: block; height: 100%; background: var(--gold); border-radius: 99px; }
.next-card { padding: 18px 20px; min-width: 280px; }
.next-card h3 { margin: 4px 0 12px; }
.modules { display: grid; gap: 14px; margin-top: 26px; }
.module { padding: 20px 22px; }
.module-head { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start; }
.module-num { font-family: var(--display); font-weight: 700; color: var(--gold-ink); font-size: .9rem; background: var(--gold-soft); border-radius: 10px; width: 40px; height: 40px; display: grid; place-items: center; }
.module-head p { margin: 4px 0 0; color: var(--muted); font-size: .95rem; }
.module-meta { font-family: var(--display); font-size: .8rem; color: var(--muted); white-space: nowrap; }
.lesson-list { list-style: none; margin: 14px 0 0; padding: 0; border-top: 1px solid var(--line); }
.lesson-list li { border-bottom: 1px solid var(--line); }
.lesson-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; align-items: center; padding: 11px 4px; text-decoration: none; color: var(--text); }
.lesson-row:hover .lesson-title { color: var(--ink); text-decoration: underline; }
.lesson-title { font-family: var(--display); font-weight: 600; font-size: .95rem; color: var(--ink); }
.lesson-sub { font-size: .88rem; color: var(--muted); }
.status { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--line); }
.status.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.status.locked { border: 0; color: var(--muted); }
.tag { font-family: var(--display); font-size: .72rem; font-weight: 600; letter-spacing: .04em; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.free { background: var(--gold-soft); color: var(--gold-ink); }
details.module-task { margin-top: 12px; }
details.module-task summary { cursor: pointer; font-family: var(--display); font-size: .88rem; font-weight: 600; color: var(--ink); }
details.module-task ul { margin: 8px 0 0; padding-left: 1.2em; }

/* Lesson */
.lesson-layout { display: grid; grid-template-columns: 220px 1fr; gap: 32px; align-items: start; }
@media (max-width: 860px) { .lesson-layout { grid-template-columns: 1fr; gap: 0; } }
.steps-nav { position: sticky; top: 80px; display: grid; gap: 2px; font-family: var(--display); font-size: .88rem; }
.steps-nav a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; }
.steps-nav a:hover { background: var(--surface); color: var(--ink); }
.steps-nav a b { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: .75rem; color: var(--ink); flex: none; }
@media (max-width: 860px) {
  .steps-nav { position: sticky; top: 60px; z-index: 10; display: flex; overflow-x: auto; gap: 6px; padding: 10px 0; margin: 0 -16px 8px; padding-left: 16px; background: var(--bg); border-bottom: 1px solid var(--line); scrollbar-width: none; }
  .steps-nav a { flex: none; background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }
}
.crumb { font-family: var(--display); font-size: .85rem; margin-bottom: 10px; }
.crumb a { color: var(--muted); }
.lesson-head { margin-bottom: 18px; }
.lesson-head .cando { margin-top: 12px; padding: 12px 14px; border-left: 4px solid var(--gold); background: var(--surface); border-radius: 0 10px 10px 0; }
.toolbar { position: sticky; top: 60px; z-index: 9; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0; background: var(--bg); border-bottom: 1px solid var(--line); margin-bottom: 18px; }
@media (max-width: 860px) { .toolbar { position: static; padding: 4px 0 12px; } .toolbar .seg button { padding: 6px 10px; } .audio-note { margin-left: 0; width: 100%; } }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 12px; font-family: var(--display); font-size: .82rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.audio-note { font-family: var(--display); font-size: .8rem; color: var(--muted); margin-left: auto; }
.step { padding: 22px 22px 18px; margin-bottom: 16px; scroll-margin-top: 130px; }
.step > h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 1.15rem; }
.step > h2 b { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--bg); display: grid; place-items: center; font-size: .8rem; flex: none; }
.step .prose ol, .step .prose ul { padding-left: 1.3em; }
.step .prose blockquote { margin: 10px 0; padding: 12px 16px; background: var(--surface-2); border-radius: 10px; font-size: .95rem; }
.step .prose blockquote p { margin: 0 0 6px; }

/* Dialogue */
.dialogue { display: grid; gap: 10px; margin: 6px 0 14px; }
.line { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; max-width: 88%; }
.line.right { justify-self: end; grid-template-columns: 1fr auto; }
.line.right .play { order: 2; }
.bubble { background: var(--bubble-a); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 10px 14px; }
.line.right .bubble { background: var(--bubble-b); border-radius: 14px 14px 4px 14px; }
.who-label { font-family: var(--display); font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pt { font-family: var(--display); font-weight: 600; color: var(--ink); font-size: 1rem; line-height: 1.45; }
.en { color: var(--muted); font-size: .93rem; }
.sounds { font-family: var(--display); font-size: .8rem; letter-spacing: .02em; color: var(--gold-ink); }
.hide-en .en { display: none; }
.hide-en .en-head { visibility: hidden; }

/* Play buttons */
.play {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--ink); color: var(--bg); border: 0; cursor: pointer;
}
.play svg { width: 16px; height: 16px; }
.play.playing { background: var(--gold); color: #1B2440; }
.play.pending { background: var(--surface-2); color: var(--muted); cursor: help; }

/* Phrase lists */
.phrases { list-style: none; margin: 4px 0 14px; padding: 0; display: grid; gap: 8px; }
.phrase { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.phrase .label { font-family: var(--display); font-weight: 700; color: var(--gold-ink); margin-right: 6px; }
.phrase-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.phrase-grid .phrase { grid-template-columns: auto 1fr; }

/* Practice */
.practice { display: grid; grid-template-columns: 180px 1fr; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.practice dt, .practice dd { margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.practice dt { font-family: var(--display); font-size: .85rem; font-weight: 600; color: var(--ink); background: var(--surface-2); }
.practice dt:last-of-type, .practice dd:last-of-type { border-bottom: 0; }
@media (max-width: 600px) { .practice { grid-template-columns: 1fr; } .practice dt { border-bottom: 0; padding-bottom: 2px; } }

.task-box { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 14px; }
.check { display: inline-flex; gap: 10px; align-items: center; font-family: var(--display); font-weight: 600; font-size: .92rem; color: var(--ink); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--ok); }
.finish { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: center; padding: 20px 22px; }

/* Locked */
.locked-card { text-align: center; padding: 40px 24px; }
.locked-card .lock-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold-ink); margin: 0 auto 14px; }

/* Admin */
.admin-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 16px 0; }
.admin-tools input { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); min-width: 240px; }
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.users th { text-align: left; font-family: var(--display); font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.users td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.pill { font-family: var(--display); font-size: .75rem; font-weight: 600; padding: 3px 9px; border-radius: 99px; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--surface-2); color: var(--muted); }

/* Toast and loading */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--bg); font-family: var(--display); font-size: .9rem; padding: 11px 18px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.loading { display: grid; place-items: center; min-height: 50vh; color: var(--muted); font-family: var(--display); }
.footer { text-align: center; font-family: var(--display); font-size: .8rem; color: var(--muted); padding: 24px 16px 40px; }
.footer a { color: var(--muted); }
