:root {
  --bg: #faf6ef; --panel: #ffffff; --panel-2: #f3eee4; --ink: #201c1a; --ink-2: #4d4642; --muted: #867f78;
  --line: #e6dfd2; --brand: #b83a2e; --brand-2: #cf5043; --brand-soft: #f9e6e3; --accent: #b9831a; --accent-soft: #f8edd3;
  --ok: #2f8a4e; --ok-soft: #e0f1e5; --warn: #a96d12; --warn-soft: #fbefd6; --bad: #c2352a; --bad-soft: #fbe3e0;
  --t1: #d6372c; --t2: #2e8b3c; --t3: #2467c9; --t4: #8a3bb8; --t5: #7a7570;
  --shadow: 0 1px 2px rgba(40, 25, 15, .06), 0 4px 16px rgba(40, 25, 15, .06);
  --radius: 14px; --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --zh: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161312; --panel: #1f1b1a; --panel-2: #2a2523; --ink: #efe9e4; --ink-2: #c8bfb8; --muted: #968c85;
    --line: #342e2b; --brand: #e0675a; --brand-2: #ea7d71; --brand-soft: #3a211e; --accent: #e0a63e; --accent-soft: #3a2f18;
    --ok: #5cc27e; --ok-soft: #1c3324; --warn: #e3a94a; --warn-soft: #3a2f1c; --bad: #ef7a6e; --bad-soft: #3d2220;
    --t1: #ff6b60; --t2: #62c86f; --t3: #6aa3f5; --t4: #c58be8; --t5: #a39c96;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: var(--ink); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.h1 { font-size: 1.45rem; font-weight: 700; }
.h2 { font-size: 1.1rem; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow, .spacer { flex: 1; }
.center { text-align: center; }

/* shell */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 18px; padding: 8px 20px;
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 600; font-size: 1.05rem; white-space: nowrap; }
.brand img { width: 28px; height: 28px; }
.brand b { color: var(--brand); }
.nav { display: flex; gap: 2px; }
.nav a, .nav button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px; color: var(--ink-2); font-weight: 500;
  border: 0; background: transparent; cursor: pointer; white-space: nowrap; }
.nav a:hover, .nav button:hover { background: var(--panel-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .ico { display: none; font-size: 1.25rem; line-height: 1; }
.badge { background: var(--brand); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 7px; font-weight: 700; line-height: 1.6; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.streak { font-weight: 600; color: var(--accent); font-size: .92rem; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; padding: 7px; border-radius: 10px; cursor: pointer; color: var(--ink-2); display: inline-flex; }
.icon-btn:hover { background: var(--panel-2); }
main { max-width: 980px; margin: 0 auto; padding: 20px 16px 80px; outline: none; }

@media (max-width: 760px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand span { display: none; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; justify-content: space-around; gap: 0; padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--line); }
  .nav a, .nav button { flex-direction: column; gap: 0; padding: 4px 6px; border-radius: 10px; font-size: .68rem; min-width: 56px; position: relative; }
  .nav .ico { display: block; }
  .nav .badge { position: absolute; top: 0; right: 6px; font-size: .62rem; padding: 0 5px; }
  main { padding: 14px 12px 96px; }
}

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; transition: background .12s, border-color .12s; text-align: center; }
.btn:hover { border-color: var(--brand-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 5px 10px; font-size: .86rem; border-radius: 8px; }
.btn.lg { padding: 12px 20px; font-size: 1.05rem; }
.btn.rec { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; background: var(--panel-2);
  color: var(--ink-2); border: 0; font-weight: 500; }
button.chip { cursor: pointer; }
.cmenu { position: relative; display: inline-block; }
.cmenu > summary { list-style: none; cursor: pointer; user-select: none; } .cmenu > summary::-webkit-details-marker { display: none; }
.cmenu-list { position: absolute; z-index: 30; left: 0; top: calc(100% + 4px); min-width: 220px; max-width: min(86vw, 320px); max-height: 60vh; overflow: auto; padding: 6px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.cmenu-list a { padding: 9px 10px; border-radius: 8px; color: var(--ink); } .cmenu-list a:hover { background: var(--panel-2); text-decoration: none; }
.chip.ok { background: var(--ok-soft); color: var(--ok); } .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); } .chip.brand { background: var(--brand-soft); color: var(--brand); }
.chip.tog { cursor: pointer; border: 1px solid var(--line); background: var(--panel); padding: 4px 12px; }
.chip.tog.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
input[type=text], input[type=password], textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px 18px; }
.sec { margin: 18px 0 8px; display: flex; align-items: baseline; gap: 10px; }
.sec .h2 { font-size: 1.05rem; }
.note { background: var(--warn-soft); color: var(--ink-2); border-radius: 10px; padding: 8px 12px; font-size: .88rem; margin: 8px 0; }
.verdict { border-radius: 10px; padding: 8px 12px; font-weight: 500; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); } .verdict.bad { background: var(--bad-soft); color: var(--bad); }
.verdict.mid { background: var(--warn-soft); color: var(--warn); }
.err { color: var(--bad); min-height: 1.3em; font-size: .9rem; }

/* Chinese text with ruby pinyin */
.zh { font-family: var(--zh); font-size: 1.9rem; line-height: 1.2; letter-spacing: .02em; }
.zh.xl { font-size: 3.4rem; } .zh.lg { font-size: 2.5rem; } .zh.md { font-size: 1.5rem; } .zh.sm { font-size: 1.15rem; }
.zh ruby { ruby-position: over; ruby-align: center; }
.zh rt { font-family: var(--font); font-size: .42em; letter-spacing: 0; color: var(--ink-2); font-weight: 500; padding-bottom: .1em; }
.zh.sm rt { font-size: .5em; }
.zh .py-only { font-family: var(--font); font-size: .5em; color: var(--ink-2); }
body.tones .zh .hz.t1, body.tones .zh rt.t1 { color: var(--t1); } body.tones .zh .hz.t2, body.tones .zh rt.t2 { color: var(--t2); }
body.tones .zh .hz.t3, body.tones .zh rt.t3 { color: var(--t3); } body.tones .zh .hz.t4, body.tones .zh rt.t4 { color: var(--t4); }
body.tones .zh .hz.t5, body.tones .zh rt.t5 { color: var(--t5); }
body.hide-pinyin .zh:not(.reveal) rt { display: none; }
body.hide-hanzi .zh:not(.reveal) .hz { visibility: hidden; }
body.hide-hanzi .zh:not(.reveal), body.hide-pinyin .zh:not(.reveal) { cursor: pointer; }
body.hide-vi .vi { display: none; } body.hide-en .en { display: none; }
.zh.fixed rt { display: revert !important; } .zh.fixed.nopy rt { display: none !important; } .zh.fixed .hz { visibility: visible !important; }
.vi { color: var(--ink); } .en { color: var(--muted); font-size: .88em; }
.toggles { position: sticky; top: 49px; z-index: 20; display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 0; background: var(--bg); }
@media (max-width: 760px) { .toggles { top: 49px; } .zh.xl { font-size: 2.8rem; } }

/* audio button */
.play { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; color: var(--brand); flex: none; }
.play:hover { background: var(--brand-soft); }
.play.sm { width: 32px; height: 32px; }
.play:disabled { cursor: progress; }
.play.loading { position: relative; animation: play-pulse 1s ease-in-out infinite; }
.play.loading::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid transparent; border-top-color: var(--brand); opacity: 0;
  animation: play-spin .8s linear infinite, play-show 0s .15s forwards; }
@keyframes play-spin { to { transform: rotate(360deg); } } @keyframes play-show { to { opacity: 1; } }
@keyframes play-pulse { 50% { background: var(--brand-soft); } }
.audio-pill { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); z-index: 60; display: none; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: .85rem; color: var(--ink-2); pointer-events: none; }
.audio-pill.show { display: inline-flex; }
.audio-pill .spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--brand); animation: play-spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) { .play.loading, .play.loading::after, .audio-pill .spin { animation-duration: 2s; } }
.play.on { background: var(--brand); color: #fff; }

/* lists */
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.word { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; position: relative; }
.word .top { display: flex; align-items: flex-start; gap: 10px; }
.word .pos { font-size: .78rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); display: inline-block; flex: none; }
.dot.learning { background: var(--accent); } .dot.known { background: var(--ok); }
.example { border-top: 1px dashed var(--line); padding-top: 6px; }
.line { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line.playing { background: var(--brand-soft); }
.spk { width: 26px; height: 26px; border-radius: 50%; background: var(--panel-2); color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem; flex: none; margin-top: 4px; }
.spk.B { background: var(--accent-soft); color: var(--accent); }
.pattern { font-family: var(--zh); font-size: 1.2rem; background: var(--panel-2); border-radius: 10px; padding: 8px 12px; margin: 6px 0; }
.prose { white-space: pre-wrap; }
.mod { margin-top: 20px; }
.lesson-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.lesson-row:last-child { border-bottom: 0; }
.lesson-row:hover { background: var(--panel-2); }
.lesson-row .no { width: 30px; height: 30px; border-radius: 50%; background: var(--panel-2); display: flex; align-items: center; justify-content: center; font-weight: 600; flex: none; }
.lesson-row.done .no { background: var(--ok-soft); color: var(--ok); }
.bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; } .bar .k { background: var(--ok); } .bar .l { background: var(--accent); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: .8rem; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tblwrap { overflow-x: auto; }
@media (max-width: 520px) { .tbl { font-size: .86rem; } .tbl th, .tbl td { padding: 6px 4px; } .tbl.mistakes th:nth-child(4), .tbl.mistakes td:nth-child(4) { display: none; } }
.stat { padding: 12px 14px; text-align: center; } .stat b { display: block; font-size: 1.6rem; line-height: 1.2; } .stat span { color: var(--muted); font-size: .82rem; }

/* plan / home */
.plan-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); color: var(--ink); }
.plan-item:last-child { border-bottom: 0; } .plan-item:hover { background: var(--panel-2); }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; flex: none; font-size: .8rem; color: #fff; }
.check.done { background: var(--ok); border-color: var(--ok); }
.tile { padding: 14px; display: flex; flex-direction: column; gap: 4px; color: var(--ink); min-height: 92px; }
.tile:hover { border-color: var(--brand-2); } .tile.soon { opacity: .55; pointer-events: none; }
.tile .t { font-weight: 600; } .tile .e { font-size: 1.5rem; }

/* review card */
.flash { padding: 26px 18px; min-height: 280px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.flash .big-vi { font-size: 1.7rem; font-weight: 600; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.grades .btn { flex-direction: column; padding: 10px 4px; gap: 0; } .grades small { font-size: .72rem; opacity: .75; font-weight: 400; }
.g-again { border-color: var(--bad); color: var(--bad); } .g-hard { border-color: var(--warn); color: var(--warn); }
.g-good { border-color: var(--ok); color: var(--ok); } .g-easy { border-color: var(--t3); color: var(--t3); }
.answer-box { border-top: 1px solid var(--line); padding-top: 14px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* dictation / diff cells */
.cells { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 10px 0; }
.cell { min-width: 56px; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); text-align: center; background: var(--panel); }
.cell .a { font-family: var(--zh); font-size: 1.5rem; line-height: 1.2; } .cell .b { font-size: .78rem; color: var(--muted); }
.cell .neu { font-size: .62em; margin-left: 2px; color: var(--muted); }
.cell.ok { background: var(--ok-soft); border-color: var(--ok); } .cell.tone, .cell.tone_missing, .cell.homophone { background: var(--warn-soft); border-color: var(--warn); }
.cell.syllable, .cell.missing, .cell.extra { background: var(--bad-soft); border-color: var(--bad); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; font-weight: 500; color: var(--ink-2); }
.seg button.on { background: var(--brand); color: #fff; }
.meter { width: 80px; height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; display: inline-block; } .meter i { display: block; height: 100%; background: var(--bad); width: 0; }

/* modal / toast */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.modal .box { background: var(--panel); border-radius: 18px 18px 0 0; padding: 18px; width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; }
@media (min-width: 761px) { .modal { align-items: center; padding: 20px; } .modal .box { border-radius: 18px; } }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); background: #2b2523; color: #fff; padding: 9px 16px; border-radius: 12px; opacity: 0;
  pointer-events: none; transition: .2s; z-index: 80; max-width: 90vw; font-size: .92rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.login { max-width: 380px; margin: 12vh auto 0; display: flex; flex-direction: column; gap: 10px; align-items: stretch; text-align: center; }
.login img { width: 56px; height: 56px; align-self: center; }

/* course switcher (header) + drafting placeholder */
.course-switch { font: inherit; font-weight: 600; font-size: .9rem; color: var(--brand); background: var(--brand-soft); border: 1px solid transparent; border-radius: 999px;
  padding: 5px 26px 5px 12px; cursor: pointer; max-width: 11.5rem; text-overflow: ellipsis; }
.course-switch:hover, .course-switch:focus-visible { border-color: var(--brand); outline: none; }
.course-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); color: inherit; cursor: pointer; background: none; border-left: 0; border-right: 0;
  border-top: 0; width: 100%; text-align: left; font: inherit; }
.course-card:last-child { border-bottom: 0; }
.course-card:hover { background: var(--panel-2); }
.course-card.on { background: var(--brand-soft); }
.drafting { text-align: center; padding: 28px 16px; }
.drafting .big { font-size: 2.6rem; }
@media (max-width: 760px) { .course-switch { max-width: 7.5rem; padding: 4px 22px 4px 9px; font-size: .82rem; } }
