:root {
  color-scheme: light;
  --page: #f8f8f3;
  --card: #fff;
  --ink: #17322a;
  --muted: #4e6258;
  --line: #dce4da;
  --green: #1c503f;
  --on-green: #fff;
  --green-soft: #e5eee5;
  --hero: #173b32;
  --hero-text: #fffdf0;
  --hero-muted: #d4e4d4;
  --lime: #dcf19f;
  --success: #205742;
  --success-bg: #e5f2e9;
  --error: #812f28;
  --error-bg: #f9e9e6;
  --tone-1: #edf2d6;
  --tone-2: #e1efe6;
  --tone-3: #f9e7dd;
  --tone-4: #ece6f5;
  --tone-5: #edf0ee;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 100%;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #131d19;
  --card: #1d2a24;
  --ink: #eef6eb;
  --muted: #bbcdbf;
  --line: #3b4f44;
  --green: #d9efac;
  --on-green: #173127;
  --green-soft: #2a4437;
  --success: #c7e9d3;
  --success-bg: #273e33;
  --error: #ffd0ca;
  --error-bg: #452b2a;
  --tone-1: #37422b;
  --tone-2: #2b4438;
  --tone-3: #46372d;
  --tone-4: #3c3447;
  --tone-5: #303a35;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); line-height: 1.55; }
button { border: 0; font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--green); }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid #77a94e; outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.16; }
h1 { font-size: clamp(2.1rem, 5vw, 3.5rem); letter-spacing: -.055em; }
h2 { font-size: clamp(1.4rem, 3.2vw, 1.9rem); letter-spacing: -.032em; }
h3 { font-size: 1.12rem; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; white-space: nowrap; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
}
.topbar-inner, .layout { width: min(100%, 1184px); margin-inline: auto; }
.topbar-inner { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 17px clamp(16px, 4vw, 40px); }
.brand { display: inline-flex; align-items: center; gap: 12px; padding: 0; background: none; font-weight: 750; text-align: left; line-height: 1.15; }
.brand-icon { display: inline-flex; flex: 0 0 36px; height: 36px; align-items: center; justify-content: center; gap: 3px; background: var(--hero); color: var(--lime); border-radius: 11px; }
.brand-icon i { display: block; width: 2px; height: 8px; border-radius: 4px; background: currentColor; }
.brand-icon i:nth-child(2) { height: 15px; }
.brand-icon i:nth-child(3) { height: 20px; }
.brand-icon i:nth-child(4) { height: 11px; }
.progress { min-width: 134px; color: var(--muted); font-size: .875rem; font-weight: 650; text-align: right; }
.progress progress { display: block; width: 100%; height: 6px; margin-top: 5px; border: 0; border-radius: 8px; overflow: hidden; background: var(--green-soft); color: var(--green); }
progress::-webkit-progress-bar { background: var(--green-soft); }
progress::-webkit-progress-value { background: var(--green); }
progress::-moz-progress-bar { background: var(--green); }

.layout { display: grid; grid-template-columns: 224px minmax(0, 1fr); align-items: start; gap: clamp(26px, 5vw, 58px); padding: 36px clamp(16px, 4vw, 40px) calc(55px + env(safe-area-inset-bottom, 0px)); }
.sidebar { padding-top: 11px; }
.sidebar-title { letter-spacing: -.04em; font-size: 1.48rem; }
.sidebar-subtitle { margin: 4px 0 22px; color: var(--muted); font-size: .94rem; }
.desktop-nav, .mobile-nav nav { display: grid; gap: 5px; }
.nav-button { display: flex; align-items: center; gap: 11px; padding: 9px 11px; min-height: 44px; width: 100%; text-align: left; background: transparent; border-radius: 11px; font-size: .94rem; }
.nav-button:hover { background: var(--card); }
.nav-button[aria-current="step"] { background: var(--green-soft); color: var(--ink); font-weight: 700; }
.nav-index { display: grid; place-items: center; min-width: 25px; height: 25px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); font-size: .78rem; font-weight: 700; }
.nav-button[aria-current="step"] .nav-index, .nav-index.done { color: var(--on-green); background: var(--green); border-color: var(--green); }
.mobile-nav { display: none; }

.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, .6fr); align-items: center; gap: 15px; background: var(--hero); color: var(--hero-text); border-radius: 24px; padding: clamp(24px, 5vw, 44px); }
.hero p { color: var(--hero-muted); max-width: 32ch; margin-top: 14px; font-size: clamp(1rem, 2vw, 1.11rem); }
.hero .hero-kicker { color: var(--lime); font-size: .85rem; font-weight: 700; margin: 0 0 9px; }
.hero .button { margin-top: 24px; }
.hero-diagram { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 5px 0; }
.hero-tone { min-width: 0; padding: 9px 12px 6px; border: 1px solid #577768; border-radius: 13px; background: #21483d; color: var(--lime); }
.hero-tone:nth-child(2), .hero-tone:nth-child(3) { background: #2a5044; }
.hero-tone span { font-size: 1.15rem; font-weight: 650; line-height: 1; color: #f5f1e5; }
.hero-tone canvas { width: 100%; height: 24px; }

.section { margin-top: 28px; }
.section > p { color: var(--muted); margin-top: 8px; }
.examples { margin-top: 16px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.tone-1 { --tone-bg: var(--tone-1); }
.tone-2 { --tone-bg: var(--tone-2); }
.tone-3 { --tone-bg: var(--tone-3); }
.tone-4 { --tone-bg: var(--tone-4); }
.tone-5 { --tone-bg: var(--tone-5); }
.sample { display: grid; text-align: left; grid-template-columns: 1fr auto; gap: 0 4px; align-items: center; padding: 13px 13px 12px; border: 1px solid transparent; border-radius: 15px; min-height: 108px; background: var(--tone-bg); }
.sample:hover, .tone-card:hover { border-color: var(--green); }
.sample-word { font-weight: 750; font-size: clamp(1.45rem, 2.7vw, 2rem); line-height: 1; }
.sample-hanzi { font-size: 1.26rem; font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif; }
.sample-meaning { color: var(--muted); font-size: .87rem; }
.sample .play-icon { justify-self: end; }
.play-icon { display: inline-grid; width: 30px; height: 30px; place-items: center; border-radius: 50%; background: var(--green); color: var(--on-green); }
.play-icon::after { content: ''; width: 0; height: 0; border-left: 8px solid currentColor; border-block: 5px solid transparent; margin-left: 2px; }
.is-playing .play-icon::after { width: 8px; height: 10px; border: 0; border-inline: 3px solid currentColor; margin-left: 0; }

.screen-head { margin: 4px 0 22px; }
.screen-head p { margin-top: 10px; max-width: 64ch; color: var(--muted); }
.screen-head .kicker { margin: 0 0 9px; font-size: .88rem; font-weight: 720; color: var(--green); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 19px; padding: clamp(17px, 3.5vw, 30px); }
.panel + .panel { margin-top: 12px; }
.panel > p { margin-top: 10px; }
.formula { margin-top: 20px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.formula div { display: grid; align-content: start; gap: 5px; padding: 14px; border-radius: 12px; background: var(--green-soft); }
.formula strong { font-size: clamp(1.55rem, 4vw, 2.1rem); line-height: 1; }
.formula span { overflow-wrap: anywhere; font-size: .9rem; font-weight: 700; }
.formula small { color: var(--muted); font-size: .82rem; }
.tone-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tone-card { display: grid; min-width: 0; text-align: left; padding: 17px; gap: 7px; border: 1px solid transparent; border-radius: 15px; background: var(--tone-bg); }
.tone-card:last-child { grid-column: 1 / -1; }
.tone-card-top, .row { display: flex; align-items: center; gap: 9px; }
.tone-card-top { justify-content: space-between; }
.tone-card-name { font-weight: 710; }
.tone-card-word { font-size: 2rem; font-weight: 720; line-height: 1; }
.tone-card-detail { color: var(--muted); font-size: .91rem; }
canvas { display: block; width: 100%; height: 54px; }

.button, .button-secondary { display: inline-flex; justify-content: center; align-items: center; gap: 8px; padding: 9px 16px; min-height: 45px; border-radius: 11px; font-weight: 700; text-align: center; }
.button { background: var(--green); color: var(--on-green); border: 1px solid transparent; }
.button-secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.button-hero { background: var(--lime); color: var(--hero); }
.button:hover:not(:disabled), .button-secondary:hover:not(:disabled) { filter: brightness(.95); }
.button:disabled, .button-secondary:disabled { background: var(--green-soft); border-color: transparent; color: var(--muted); opacity: .74; }
.actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.actions > :only-child { margin-inline-start: auto; }
.credits { display: inline-block; margin-top: 16px; font-size: .88rem; }
.lesson-tools { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 17px; font-size: .88rem; }
.setup-brand { color: var(--ink); text-decoration: none; }
.setup-page { width: min(100%, 720px); margin-inline: auto; padding: 28px 16px 50px; }
.setup-panel { display: grid; gap: 12px; }
.setup-panel > p { margin-top: 0; }
.setup-form, .setup-field { display: grid; gap: 8px; }
.setup-form > button { justify-self: start; }
.setup-field label { font-weight: 700; }
.setup-field p { font-size: .9rem; }
.setup-page input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--page);
  color: var(--ink);
  font: inherit;
}
.setup-page input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.setup-page input[aria-invalid="true"] { border-color: var(--error); }
.setup-error { color: var(--error); }
.setup-copy { display: flex; gap: 8px; }
.setup-copy > button { flex: 0 0 auto; }
.setup-copy-status { position: fixed; inset: auto 16px 16px; width: fit-content; max-width: calc(100% - 32px); margin-inline: auto; padding: 8px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--green-soft); }
.setup-steps { margin: 0; padding-inline-start: 23px; }
.setup-steps li + li { margin-top: 6px; }
.question { display: grid; gap: 17px; }
.question-count { color: var(--muted); font-weight: 700; font-size: .9rem; }
.steps { display: flex; gap: 5px; }
.steps span { flex: 1 1 12px; max-width: 35px; height: 5px; border-radius: 8px; background: var(--line); }
.steps .past, .steps .current { background: var(--green); }
.steps .past { opacity: .45; }
.question-word { margin: 3px 0; font-size: clamp(3.4rem, 10vw, 5.75rem); letter-spacing: -.04em; }
.listen-box { display: flex; align-items: center; gap: 13px; width: fit-content; max-width: 100%; background: var(--green-soft); padding: 10px 15px; border-radius: 14px; text-align: left; font-weight: 700; }
.listen-box:hover { outline: 1px solid var(--green); }
.choice-grid { display: grid; gap: 9px; }
.choice-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice { text-align: left; padding: 11px 13px; min-height: 46px; background: var(--page); border: 1px solid var(--line); border-radius: 10px; font-weight: 650; }
.choice:hover:not(:disabled) { border-color: var(--green); }
.choice[aria-pressed="true"]:not(:disabled) { background: var(--green-soft); border-color: var(--green); }
.choice.correct, .feedback.correct { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.choice.wrong, .feedback.wrong { background: var(--error-bg); color: var(--error); border-color: var(--error); }
.choice:disabled:not(.correct, .wrong) { color: var(--muted); }
.choice:disabled[aria-pressed="true"] { opacity: 1; }
.feedback { padding: 11px 14px; border-radius: 11px; border: 1px solid var(--line); }
.feedback strong { display: block; }
.match-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 12px; }
.match-column { display: grid; align-content: start; gap: 8px; }
.match-column h3 { margin-bottom: 2px; }
.match-audio { gap: 7px; display: flex; min-height: 52px; align-items: center; }
.match-audio[aria-pressed="true"] { background: var(--green-soft); border-color: var(--green); }
.match-audio .play-icon { width: 25px; height: 25px; flex: 0 0 25px; }
.match-word { text-align: center; min-height: 52px; font-size: 1.1rem; }
.question .feedback .listen-box { margin-top: 9px; }
.result { display: grid; gap: 16px; }
.result-score { font-size: clamp(3rem, 8vw, 4.5rem); line-height: 1; font-weight: 760; letter-spacing: -.055em; color: var(--green); }
.review { margin: 0; padding-inline-start: 22px; }
.review li + li { margin-top: 10px; }
.review p { margin-top: 3px; }
.audio-error { position: fixed; z-index: 2; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); width: min(calc(100% - 24px), 540px); padding: 10px 14px; border: 1px solid var(--error); border-radius: 12px; color: var(--error); background: var(--error-bg); }
.no-script { max-width: 520px; padding: 12px; margin-inline: auto; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; gap: 17px; padding-top: 13px; }
  .sidebar { padding: 0; }
  .sidebar-title, .sidebar-subtitle, .desktop-nav { display: none; }
  .mobile-nav { display: block; border: 1px solid var(--line); border-radius: 11px; background: var(--card); }
  .mobile-nav summary { display: flex; min-height: 45px; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 13px; cursor: pointer; list-style: none; font-weight: 700; font-size: .91rem; }
  .mobile-nav summary::-webkit-details-marker { display: none; }
  .mobile-nav nav { padding: 0 5px 5px; }
  .chevron { width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); margin-right: 2px; }
  .mobile-nav[open] .chevron { transform: translateY(2px) rotate(225deg); }
}

@media (max-width: 530px) {
  .setup-copy { flex-wrap: wrap; }
  .topbar-inner { padding-block: 12px; }
  .progress { min-width: 92px; font-size: .78rem; }
  .brand { font-size: .92rem; gap: 8px; }
  .brand-icon { flex-basis: 32px; height: 32px; }
  .hero { grid-template-columns: 1fr; gap: 16px; padding: 24px 19px 19px; border-radius: 18px; }
  .hero .button { margin-top: 17px; }
  .hero-diagram { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 1px 0 0; }
  .hero-tone { border-radius: 9px; padding: 6px; }
  .hero-tone span { font-size: 1rem; }
  .hero-tone canvas { height: 18px; }
  .section { margin-top: 23px; }
  .examples { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .sample { min-height: 92px; }
  .tone-card { padding: 12px; }
  .tone-card-name { font-size: .89rem; }
  .tone-card-detail { font-size: .88rem; }
  .formula div { padding: 10px 8px; }
}
