/* ========== Tokens ========== */
:root {
  --bg: #faf6ef;
  --surface: #ffffff;
  --surface-2: #f3ece2;
  --text: #221c18;
  --muted: #6f655c;
  --border: #e6dccf;
  --accent: #c53a2c;
  --accent-strong: #a52f23;
  --accent-soft: #fbe8e4;
  --on-accent: #ffffff;
  --gold: #c7951f;
  --good: #2c8a55;
  --good-soft: #e2f3e9;
  --bad: #c53a2c;
  --bad-soft: #fbe8e4;
  --ink: #221c18;
  --outline: #ddd2c4;
  --grid: #e3aaa2;
  --t1: #d4302a;
  --t2: #d27a00;
  --t3: #2b8a3e;
  --t4: #1f62d6;
  --t5: #8a827a;
  --shadow: 0 1px 2px rgb(60 40 20 / 0.05), 0 8px 24px rgb(60 40 20 / 0.06);
  --radius: 16px;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --font-zh: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --font-zh-display: "Noto Serif SC", "Songti SC", "SimSun", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f;
    --surface: #201b17;
    --surface-2: #2a241f;
    --text: #f3ede5;
    --muted: #a79c90;
    --border: #3a322b;
    --accent: #f0644f;
    --accent-strong: #ff7d6a;
    --accent-soft: #3b211b;
    --on-accent: #1d0f0b;
    --gold: #e0b048;
    --good: #57c487;
    --good-soft: #17301f;
    --bad: #ff7a69;
    --bad-soft: #3b211b;
    --ink: #f3ede5;
    --outline: #4a3f36;
    --grid: #6a3c35;
    --t1: #ff6b5f;
    --t2: #ffb23f;
    --t3: #63cf7d;
    --t4: #73a6ff;
    --t5: #a39a90;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15120f;
  --surface: #201b17;
  --surface-2: #2a241f;
  --text: #f3ede5;
  --muted: #a79c90;
  --border: #3a322b;
  --accent: #f0644f;
  --accent-strong: #ff7d6a;
  --accent-soft: #3b211b;
  --on-accent: #1d0f0b;
  --gold: #e0b048;
  --good: #57c487;
  --good-soft: #17301f;
  --bad: #ff7a69;
  --bad-soft: #3b211b;
  --ink: #f3ede5;
  --outline: #4a3f36;
  --grid: #6a3c35;
  --t1: #ff6b5f;
  --t2: #ffb23f;
  --t3: #63cf7d;
  --t4: #73a6ff;
  --t5: #a39a90;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
  color-scheme: dark;
}

/* ========== Base ========== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
[lang="zh-CN"] { font-family: var(--font-zh); }
a { color: inherit; }
button { font: inherit; color: inherit; }
svg { display: block; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: clamp(1.8rem, 4.2vw, 2.6rem); font-weight: 700; }
h2 { font-size: 1.35rem; font-weight: 700; margin-top: 2.25rem; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 1em; }
ul { margin: 0; padding: 0; list-style: none; }
kbd {
  font-family: var(--font);
  font-size: 0.7rem;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid currentColor;
  opacity: 0.55;
}
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.container { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }
main:focus { outline: none; }
.view { animation: rise 0.25s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.t1 { color: var(--t1); }
.t2 { color: var(--t2); }
.t3 { color: var(--t3); }
.t4 { color: var(--t4); }
.t5 { color: var(--t5); }
ruby { ruby-position: over; }
rt { font-family: var(--font); font-size: 0.32em; font-weight: 500; letter-spacing: 0; }

.eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.lead { color: var(--muted); font-size: 1.05rem; max-width: 64ch; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.count {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  margin-left: 6px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  vertical-align: middle;
}
.title-zh { font-family: var(--font-zh-display); color: var(--accent); font-weight: 600; margin-left: 4px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}
.back:hover { color: var(--accent); }
.back svg { width: 18px; height: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.note {
  margin: 16px 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface-2);
  border-left: 4px solid var(--gold);
  font-size: 0.95rem;
}
.note p:last-child { margin: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.good { background: var(--good-soft); color: var(--good); }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.good { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.btn.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.btn.disabled, .btn:disabled { opacity: 0.45; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row.center { justify-content: center; }

.play {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.play:hover { background: var(--accent-soft); border-color: var(--accent); }
.play svg { width: 18px; height: 18px; }
.speaking { animation: pulse 0.6s ease; }
@keyframes pulse { 40% { transform: scale(1.1); } }

.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ========== Top bar & navigation ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; white-space: nowrap; font-weight: 500; }
.seal {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-zh-display);
  font-size: 21px;
  font-weight: 600;
  line-height: 1;
}
.brand-name b { color: var(--accent); }
.nav { display: flex; gap: 2px; margin-left: auto; }
.nav a {
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }

.tabbar { display: none; }

@media (max-width: 880px) {
  .nav { display: none; }
  .icon-btn { margin-left: auto; }
  .container { padding-bottom: 104px; }
  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 0;
    border-radius: 10px;
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
  }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--accent); }
}

.banner { max-width: 1080px; margin: 12px auto 0; padding: 0 16px; }
.banner-inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.92rem;
}
.banner-inner b { color: var(--text); }
.banner-close {
  flex: none;
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

/* ========== Home ========== */
.hero {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 24px;
  align-items: center;
  padding: 32px;
  border-radius: 24px;
  overflow: hidden;
}
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.2rem); }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero-art {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 24px 12px;
  border: 0;
  border-radius: 20px;
  background: var(--surface-2);
  cursor: pointer;
}
.hero-art .big { font-family: var(--font-zh-display); font-size: clamp(4rem, 11vw, 7rem); line-height: 1.15; }
.hero-art .big rt { font-size: 0.26em; }
.hero-art small { color: var(--muted); }
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; padding: 20px; }
  .hero-art { padding: 16px 12px; }
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.stat { padding: 16px 18px; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat-value small { font-size: 0.9rem; color: var(--muted); font-weight: 500; }
.stat-label { color: var(--muted); font-size: 0.88rem; }
@media (max-width: 560px) {
  .stats { gap: 8px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 1.35rem; }
  .stat-label { font-size: 0.78rem; }
}

.step { display: flex; align-items: center; gap: 12px; margin: 2.25rem 0 0.9rem; }
.step h2 { margin: 0; }
.step-num {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 0.9rem;
}

.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.feature {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 18px;
  text-decoration: none;
  transition: transform 0.15s, border-color 0.15s;
}
.feature:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.feature-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-zh-display);
  font-size: 1.4rem;
}
.feature-icon svg { width: 22px; height: 22px; }
.feature b { display: block; margin-bottom: 2px; }
.feature span { color: var(--muted); font-size: 0.9rem; }

.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.lesson-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.lesson-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.lesson-top { display: flex; justify-content: space-between; align-items: center; min-height: 22px; }
.lesson-num { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.lesson-zh { font-family: var(--font-zh-display); font-size: 1.65rem; color: var(--accent); line-height: 1.35; }
.lesson-title { font-weight: 600; }
.lesson-meta { font-size: 0.84rem; color: var(--muted); }
.progress { display: block; height: 6px; margin-top: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--good); }

/* One collapsible block per HSK level (lesson lists) */
.level { margin-bottom: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.level > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  list-style: none;
}
.level > summary::-webkit-details-marker { display: none; }
.level > summary::after {
  content: '';
  flex: none;
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.15s;
}
.level[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
.level > summary:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.level-meta { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.level-body { padding: 0 12px 12px; }
.level-body > .h-small:first-child { margin-top: 0.4rem; }
.loading { padding: 12px 4px; }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.link-btn { border: 0; padding: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: inherit; }
.link-btn:hover { color: var(--bad); }

/* ========== Tabs ========== */
.tabs {
  display: flex;
  gap: 4px;
  margin: 18px 0 22px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs a {
  flex: 1 0 auto;
  padding: 9px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.93rem;
  text-align: center;
  text-decoration: none;
}
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ========== Pinyin ========== */
.tone-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tone-card { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.tone-card[data-tone="1"] { --tone: var(--t1); }
.tone-card[data-tone="2"] { --tone: var(--t2); }
.tone-card[data-tone="3"] { --tone: var(--t3); }
.tone-card[data-tone="4"] { --tone: var(--t4); }
.tone-card[data-tone="5"] { --tone: var(--t5); }
.tone-head { display: flex; align-items: center; gap: 12px; }
.tone-mark { font-size: 2.3rem; font-weight: 700; line-height: 1; color: var(--tone); min-width: 1.2em; }
.contour { width: 100%; height: auto; color: var(--tone); }
.contour .lvl { stroke: var(--border); stroke-width: 1; }
.contour text { fill: var(--muted); font-size: 7px; font-family: var(--font); }
.tone-card p { margin: 0; font-size: 0.92rem; }
.tone-ex {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
}
.tone-ex:hover { border-color: var(--tone); }
.tone-ex-hz { font-size: 1.6rem; line-height: 1; }
.tone-ex svg { width: 18px; height: 18px; margin-left: auto; color: var(--accent); }

.sound-group { margin-bottom: 22px; }
.sound-group h3 { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; }
.sound-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sound-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.sound-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.sound { font-size: 1.65rem; font-weight: 700; line-height: 1.15; }
.sound-ex { font-size: 0.95rem; }
.sound-ex [lang] { font-size: 1.15rem; margin-right: 2px; }
.sound-tip { font-size: 0.8rem; color: var(--muted); line-height: 1.4; }

.drill { max-width: 560px; margin: 0 auto; padding: 24px; text-align: center; }
.drill-play {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  margin: 10px auto 16px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 35%, transparent);
}
.drill-play svg { width: 42px; height: 42px; }
.tone-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tone-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 4px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.tone-opt b { font-size: 1.7rem; line-height: 1.1; }
.tone-opt small { font-size: 0.75rem; color: var(--muted); }
.tone-opt:hover:not(:disabled) { border-color: var(--accent); }
.tone-opt.correct, .option.correct { border-color: var(--good); background: var(--good-soft); }
.tone-opt.wrong, .option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.tone-opt:disabled { cursor: default; }
.drill-feedback { min-height: 64px; margin-top: 16px; }
.drill-answer { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.drill-answer [lang] { font-size: 2rem; }

/* ========== Lesson ========== */
.lesson-head { margin-bottom: 8px; }
.vocab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.word { position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.word.learned { border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }
.word-hz {
  flex: none;
  min-width: 2.4em;
  padding: 4px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  font-size: 1.9rem;
  line-height: 1.3;
  cursor: pointer;
}
.word-hz:hover { background: var(--surface-2); }
.word-body { flex: 1; min-width: 0; }
.word-py { font-weight: 600; }
.word-vi { font-size: 0.93rem; line-height: 1.45; }
.word-hv { font-size: 0.8rem; color: var(--muted); }
.word-actions { display: flex; flex-direction: column; gap: 6px; }
.learned-badge {
  position: absolute;
  top: -7px;
  left: -7px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--good);
  color: var(--surface);
  font-size: 0.7rem;
  font-weight: 700;
}

.grammar-list { display: grid; gap: 12px; }
.grammar { padding: 16px 18px; }
.grammar h3 { margin-bottom: 0.3em; }
.grammar p { margin: 0; color: var(--muted); }
.ex {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
}
.ex-zh { font-size: 1.15rem; line-height: 1.4; }
.ex-py { font-size: 0.88rem; color: var(--muted); }
.ex-vi { font-size: 0.93rem; }
.sentences { padding: 4px 16px; }
.sentences .ex { margin: 0; padding: 12px 0; border-radius: 0; background: none; border-bottom: 1px solid var(--border); }
.sentences .ex:last-child { border-bottom: 0; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 32px; }
.pager .btn { max-width: 48%; }

/* ========== Review (flashcards) ========== */
.due-box { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 18px 0; padding: 18px 20px; }
.due-num { font-size: 2.4rem; font-weight: 700; line-height: 1; color: var(--accent); }
.due-text { flex: 1; min-width: 160px; }
.prefs { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; font-size: 0.95rem; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); }
.seg button { padding: 6px 12px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.deck-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.deck-item { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; padding: 12px 16px; text-decoration: none; }
.deck-item .progress { grid-column: 1 / -1; margin-top: 4px; }

.deck-head { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; margin-bottom: 12px; }
.deck-head .back { margin: 0; }
.deck-title { font-weight: 600; }
.deck-count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; margin-bottom: 22px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 0.3s ease; }

.stage { max-width: 520px; margin: 0 auto; perspective: 1200px; }
.flashcard {
  position: relative;
  height: 340px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard:focus-visible { outline: none; }
.flashcard:focus-visible .face { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); }
.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.back { transform: rotateY(180deg); }
.flashcard:not(.flipped) .back, .flashcard.flipped .front { pointer-events: none; }
.face-hz { font-family: var(--font-zh-display); font-size: clamp(3.4rem, 13vw, 5.2rem); line-height: 1.2; }
.face-vi { font-size: 1.35rem; font-weight: 600; max-width: 22ch; }
.face-hint { position: absolute; bottom: 14px; color: var(--muted); font-size: 0.82rem; }
.deck-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 520px; margin: 18px auto 0; }
.deck-actions .btn:only-child { grid-column: 1 / -1; }
.hint { margin-top: 14px; text-align: center; color: var(--muted); font-size: 0.82rem; }
@media (hover: none) { .hint, .option .key, .btn kbd { display: none; } }

.done { max-width: 560px; margin: 0 auto; padding: 32px 22px; text-align: center; }
.done-seal {
  display: inline-grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin-bottom: 14px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-zh-display);
  font-size: 48px;
  transform: rotate(-4deg);
}
.empty { padding: 28px 22px; text-align: center; }

/* ========== Quiz ========== */
.quiz-wrap { max-width: 660px; margin: 0 auto; }
.q-prompt { margin-bottom: 14px; padding: 24px 20px; text-align: center; }
.q-label { margin-bottom: 10px; color: var(--muted); font-size: 0.9rem; }
.q-hz { font-family: var(--font-zh-display); font-size: clamp(3rem, 11vw, 4.4rem); line-height: 1.2; }
.q-vi { font-size: 1.45rem; font-weight: 600; }
.q-prompt .drill-play { margin: 4px auto; width: 84px; height: 84px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled { cursor: default; }
.option .key {
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}
.option.correct .key { background: var(--good); color: var(--surface); }
.option.wrong .key { background: var(--bad); color: var(--surface); }
.option.hz [lang] { font-size: 1.55rem; line-height: 1.2; }
@media (max-width: 480px) { .options { grid-template-columns: 1fr; } }
.feedback {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 14px;
}
.feedback.ok { background: var(--good-soft); }
.feedback.no { background: var(--bad-soft); }
.feedback-title { font-weight: 700; }
.feedback.ok .feedback-title { color: var(--good); }
.feedback.no .feedback-title { color: var(--bad); }
.feedback-word [lang] { font-size: 1.25rem; margin-right: 4px; }
.feedback .btn { margin-left: auto; }

.result { padding: 30px 22px; text-align: center; }
.score-ring {
  display: grid;
  place-items: center;
  width: 140px;
  height: 140px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0);
}
.score-ring > span {
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: var(--surface);
  font-size: 2rem;
  font-weight: 700;
}
.more-links { margin: 14px 0; }

/* Mock tests */
.exam-links { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.exam-links .passed { border-color: var(--good); color: var(--good); }
.exam-part { margin: 0 0 8px; font-size: 0.85rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }
.exam-parts { display: inline-block; margin: 8px 0 14px; padding-left: 20px; text-align: left; }
.exam-parts li { margin: 4px 0; }
.option.zh-option [lang] { font-size: 1.2rem; }
.exam-mistake { flex-direction: column; align-items: flex-start; gap: 2px; }
.exam-mistake [lang] { font-size: 1.05rem; }

/* Readings */
.reading .prefs { margin: 4px 0 14px; }
.reading-lines { padding: 6px 18px; }
.reading-lines .ex-zh { font-size: 1.3rem; }
.reading.hide-py .ex-py, .reading.hide-vi .ex-vi { display: none; }
.who { font-size: 0.8rem; font-weight: 700; color: var(--accent); }
.reading-questions { display: grid; gap: 12px; }
.rq { padding: 16px; }
.rq-title { margin: 0 0 10px; font-weight: 600; }
.rq .option { min-height: 48px; }

/* Sentence practice */
.q-sentence { font-size: clamp(1.5rem, 6vw, 2rem); line-height: 1.5; }
.options.one-col { grid-template-columns: 1fr; }
.build-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 64px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1.5px dashed var(--border);
  border-radius: 14px;
}
.build-line.ok { border-style: solid; border-color: var(--good); background: var(--good-soft); }
.build-line.no { border-style: solid; border-color: var(--bad); background: var(--bad-soft); }
.build-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 16px; }
.tile {
  min-width: 48px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 1.4rem;
  cursor: pointer;
}
.tile:hover:not(:disabled) { border-color: var(--accent); }
.tile:disabled { cursor: default; }
.tile.ghost { border-style: dashed; background: transparent; min-height: 48px; }
.feedback-sentence { flex: 1 1 220px; }
.feedback-sentence [lang] { font-size: 1.25rem; }
.mistakes { margin: 20px 0; text-align: left; }
.mistake { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.mistake [lang] { font-size: 1.3rem; }

/* ========== Writing ========== */
.write-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
@media (max-width: 760px) { .write-layout { grid-template-columns: 1fr; } }
.write-pad { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px; }
.tianzige {
  position: relative;
  width: min(340px, 100%);
  aspect-ratio: 1;
  border: 2px solid var(--grid);
  border-radius: 6px;
  background: var(--surface);
  touch-action: none;
}
.tianzige .grid { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tianzige .grid path { stroke: var(--grid); stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; fill: none; }
.tianzige .hw { position: absolute; inset: 0; }
.tianzige .hw svg { width: 100%; height: 100%; }
.write-status { min-height: 1.6em; margin: 0; text-align: center; font-weight: 500; }
.char-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 52px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  text-decoration: none;
  cursor: pointer;
  line-height: 1.25;
}
.chip [lang], .chip.zh { font-size: 1.45rem; }
.chip small { font-size: 0.72rem; color: var(--muted); }
.chip:hover { border-color: var(--accent); }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.char-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.h-small { font-size: 1rem; margin: 1.6rem 0 0.7rem; color: var(--muted); }
.char-info { padding: 20px; }
.char-head { display: flex; align-items: center; gap: 14px; }
.char-big { font-family: var(--font-zh-display); font-size: 4.4rem; line-height: 1.1; color: var(--accent); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 14px 0 18px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.word-links li { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.word-links li:last-child { border-bottom: 0; }
.word-links a { text-decoration: none; font-weight: 600; margin-right: 6px; }
.word-links a:hover [lang] { color: var(--accent); }
.word-links [lang] { font-size: 1.1rem; margin-right: 4px; }

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