:root {
  color-scheme: light;
  --canvas: #f7faf9;
  --surface: #ffffff;
  --ink: #15211f;
  --muted: #60716e;
  --line: #dbe6e2;
  --green: #08766b;
  --green-dark: #07584f;
  --coral: #dd5a4d;
  --coral-pale: #fff0ed;
  --yellow: #f3c968;
  --yellow-pale: #fff8df;
  --shadow: 0 12px 30px rgba(21, 33, 31, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { min-width: 320px; min-height: 100%; margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(8, 118, 107, 0.28); outline-offset: 2px; }

.app-shell { width: min(1240px, 100%); margin: 0 auto; padding: env(safe-area-inset-top) 22px calc(86px + env(safe-area-inset-bottom)); }
.app-header { min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 11px; padding: 0; border: 0; background: transparent; color: var(--ink); text-align: left; }
.brand img { width: 42px; height: 42px; border-radius: 8px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: 0; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.outline-button, .text-button, .module-tabs button, .bottom-nav button, .chapter-row, .category-card { border: 0; background: transparent; color: inherit; }
.outline-button { min-height: 38px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); font-weight: 650; font-size: 13px; }
.text-button { padding: 5px 0; color: var(--green); font-size: 14px; font-weight: 700; }
.page-content { padding: 30px 0; }
.overview-band, .page-title-row, .chapter-title-row, .section-heading, .chapter-topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.overview-band { padding: 25px 0 24px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 7px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: 0; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 620px; margin-bottom: 0; font-size: clamp(26px, 4vw, 42px); line-height: 1.12; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 20px; letter-spacing: 0; }
h3 { margin-bottom: 0; font-size: 16px; letter-spacing: 0; }
.daily-setting { display: flex; min-width: 120px; flex-direction: column; gap: 8px; color: var(--muted); font-size: 12px; }
.daily-setting select { height: 38px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 22px 0; }
.metric { min-height: 102px; padding: 17px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.metric:nth-child(2) { background: var(--yellow-pale); border-color: #efdfac; }
.metric:nth-child(3) { background: var(--coral-pale); border-color: #f2d2cb; }
.metric span, .metric small { display: block; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin: 5px 0 3px; font-size: 27px; letter-spacing: 0; }
.metric small { color: var(--muted); font-size: 12px; }
.section-block { margin-top: 32px; }
.section-heading { align-items: end; margin-bottom: 14px; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; }
.daily-list { display: grid; gap: 8px; }
.daily-row, .chapter-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); text-align: left; }
.daily-row:hover, .chapter-row:hover { border-color: #9bbfb8; }
.daily-row strong, .chapter-row strong { display: block; font-size: 15px; }
.daily-row small, .chapter-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.row-status { flex: 0 0 auto; color: var(--green); font-size: 12px; font-weight: 700; }
.category-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.category-card { min-height: 132px; padding: 17px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); text-align: left; }
.category-card:nth-child(3n + 2) { background: #eff8f5; }
.category-card:nth-child(3n + 3) { background: #fff5eb; }
.category-card:hover { border-color: #8eb9b0; }
.category-card strong, .category-card span { display: block; }
.category-card strong { font-size: 16px; }
.category-card span { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.page-title-row { align-items: end; margin-bottom: 22px; }
.search-field { display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); font-size: 13px; }
.search-field input { width: 100%; border: 0; background: transparent; color: var(--ink); }
.search-field input:focus { outline: 0; }
.chapter-list { display: grid; gap: 23px; margin-top: 24px; }
.chapter-group { display: grid; gap: 8px; }
.group-heading { display: flex; align-items: center; justify-content: space-between; padding-bottom: 3px; }
.group-heading h2 { font-size: 17px; }
.chapter-index { color: var(--green); font-weight: 800; font-size: 12px; }
.chapter-topline { align-items: center; margin-bottom: 13px; }
.category-label { padding: 5px 8px; border-radius: 999px; background: #e4f4ef; color: var(--green-dark); font-size: 12px; font-weight: 750; }
.chapter-title-row { align-items: end; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.chapter-title-row h1 { font-size: clamp(24px, 3vw, 36px); }
.chapter-title-row .muted { margin: 7px 0 0; }
.module-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 19px 0 18px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.module-tabs button { min-height: 42px; border-radius: 5px; color: var(--muted); font-size: 14px; font-weight: 700; }
.module-tabs button[aria-selected="true"] { background: var(--green); color: white; }
.practice-card { padding: clamp(18px, 4vw, 34px); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.word-position { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; }
.word-position .progress-bar { width: 130px; height: 6px; overflow: hidden; border-radius: 99px; background: #e8eeec; }
.word-position .progress-bar span { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.study-word { margin: 20px 0 8px; font-size: clamp(34px, 7vw, 58px); line-height: 1.03; overflow-wrap: anywhere; letter-spacing: 0; }
.phonetic { margin: 0; color: var(--green); font-size: 16px; }
.meaning { margin: 13px 0 0; font-size: 16px; line-height: 1.55; }
.phrase { margin: 10px 0 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.control-row { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 24px; }
.primary-button, .secondary-button, .danger-button { min-height: 42px; padding: 9px 14px; border: 0; border-radius: 7px; font-weight: 750; font-size: 14px; }
.primary-button { background: var(--green); color: white; }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.danger-button { background: var(--coral); color: white; }
.recognition-result, .result-panel, .translation-panel { margin-top: 19px; padding: 14px; border-left: 4px solid var(--green); border-radius: 0 7px 7px 0; background: #eef8f5; font-size: 14px; line-height: 1.6; }
.result-panel.error { border-left-color: var(--coral); background: var(--coral-pale); }
.diagnosis.needs-work { border-left-color: var(--coral); background: var(--coral-pale); }
.diagnosis.success { border-left-color: var(--green); background: #eef8f5; }
.diagnosis-title { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 14px; }
.diagnosis-title strong { color: var(--green-dark); font-size: 15px; }
.diagnosis.needs-work .diagnosis-title strong { color: #a43b35; }
.diagnosis-title span, .diagnosis-disclaimer, .diagnosis-more { color: var(--muted); font-size: 12px; }
.diagnosis > p { margin: 8px 0 0; overflow-wrap: anywhere; }
.diagnosis-advice { font-weight: 650; }
.diagnosis-disclaimer { margin-bottom: 8px !important; }
.diagnosis-list { display: grid; gap: 9px; margin: 10px 0 0; padding-left: 20px; }
.diagnosis-list li { padding-left: 2px; }
.diagnosis-list li span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.diagnosis-list li span b { color: var(--ink); }
.diagnosis-more { margin-top: 10px !important; }
.context-title { margin: 20px 0 0; color: var(--muted); font-size: 13px; font-weight: 750; }
.context-text { margin: 10px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(19px, 3.2vw, 24px); line-height: 1.75; }
.word-link { display: inline; padding: 0 2px; border: 0; border-bottom: 2px solid var(--yellow); background: transparent; color: inherit; font: inherit; font-weight: 700; }
.word-link:hover { background: var(--yellow-pale); }
.translation-panel { border-left-color: var(--yellow); background: var(--yellow-pale); }
.quiz-card { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.quiz-card h3 { margin-bottom: 8px; }
.quiz-card p { color: var(--muted); font-size: 14px; line-height: 1.6; }
.quiz-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.quiz-options button { min-height: 44px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); text-align: left; font-weight: 700; overflow-wrap: anywhere; }
.quiz-options button:hover { border-color: var(--green); }
.quiz-options button.correct { border-color: var(--green); background: #e9f8f3; color: var(--green-dark); }
.quiz-options button.incorrect { border-color: var(--coral); background: var(--coral-pale); color: #b23e34; }
.dictation-input { width: min(100%, 460px); height: 48px; margin-top: 17px; padding: 0 13px; border: 1px solid #aabeb8; border-radius: 7px; background: white; color: var(--ink); font-size: 18px; }
.dictation-input.correct { border-color: var(--green); background: #effaf6; }
.dictation-input.incorrect { border-color: var(--coral); background: #fff4f2; }
.small-note { margin: 17px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.chapter-content { display: grid; gap: 16px; }
.source-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.image-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.image-figure { overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.image-figure img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #e8eeec; }
.image-figure figcaption { padding: 8px 10px; color: var(--muted); font-size: 12px; }
.practice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.practice-panel { padding: 19px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.practice-panel.listening-panel { background: #ecf7fb; border-color: #cde5ef; }
.practice-panel.speaking-panel { background: #f8eef9; border-color: #ead4ed; }
.practice-panel.writing-panel { background: #fff0f1; border-color: #f2d2d7; }
.practice-panel.reading-panel { background: #fff8e9; border-color: #f0e0b7; }
.practice-panel h2 { margin-bottom: 10px; }
.practice-intro, .practice-zh, .practice-panel p { color: var(--muted); font-size: 14px; line-height: 1.65; }
.source-list { display: grid; gap: 9px; margin: 14px 0 0; padding-left: 18px; }
.source-list li { color: var(--ink); line-height: 1.55; }
.source-list li small { display: block; margin-top: 2px; color: var(--muted); }
.english-block { margin: 12px 0 0; padding: 12px; border: 1px solid rgba(21, 33, 31, 0.1); border-radius: 7px; background: rgba(255, 255, 255, 0.72); }
.english-block p { margin: 0; color: var(--ink); white-space: pre-line; }
.english-block em { font-family: Georgia, "Times New Roman", serif; font-size: 16px; }
.inline-audio { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 10px; }
.inline-audio button { min-height: 32px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--green-dark); font-size: 12px; font-weight: 750; }
.inline-audio small { color: var(--muted); font-size: 12px; }
.inline-audio .compact-result, .inline-audio .compact-diagnosis { flex-basis: 100%; width: 100%; margin-top: 4px; }
.inline-audio .compact-diagnosis { padding: 11px; font-size: 13px; }
.inline-audio .diagnosis-list { gap: 7px; }
.source-rich-text { color: var(--ink); font-size: 14px; line-height: 1.7; }
.source-rich-text p { color: var(--ink); }
.source-rich-text code { padding: 1px 4px; border-radius: 4px; background: #e3f4ef; color: var(--green-dark); font-family: inherit; font-weight: 750; }
.chapter-tips { display: grid; gap: 10px; }
.scenario-stack { display: grid; gap: 14px; }
.scenario-card { padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.scenario-card:nth-child(2n) { background: #f7fbf9; }
.scenario-card h3 { margin-bottom: 7px; }
.scenario-card .context-text { margin-top: 8px; }
.empty-state { padding: 22px; border: 1px dashed #b5c9c3; border-radius: 8px; color: var(--muted); text-align: center; }
.modal[hidden] { display: none; }
.modal { position: fixed; z-index: 30; inset: 0; display: grid; place-items: end center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(13, 29, 27, 0.44); }
.modal-card { position: relative; width: min(560px, 100%); padding: 25px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.modal-close { position: absolute; top: 13px; right: 14px; border: 0; background: transparent; color: var(--muted); font-size: 13px; }
.bottom-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; display: none; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(12px); padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav button { min-height: 58px; color: var(--muted); font-size: 12px; font-weight: 750; }
.bottom-nav button.active { color: var(--green); }

@media (max-width: 760px) {
  .app-shell { padding: env(safe-area-inset-top) 16px calc(74px + env(safe-area-inset-bottom)); }
  .app-header { min-height: 68px; }
  .page-content { padding: 22px 0; }
  .overview-band, .chapter-title-row { align-items: flex-start; flex-direction: column; }
  .daily-setting { width: 100%; flex-direction: row; align-items: center; justify-content: space-between; }
  .daily-setting select { min-width: 88px; }
  .metric-grid { gap: 8px; }
  .metric { min-height: 94px; padding: 13px; }
  .metric strong { font-size: 23px; }
  .category-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .category-card { min-height: 116px; padding: 13px; }
  .module-tabs { position: sticky; z-index: 10; top: 8px; box-shadow: 0 8px 20px rgba(21, 33, 31, 0.1); }
  .module-tabs button { min-width: 0; padding: 4px 2px; font-size: 12px; }
  .image-gallery, .practice-grid { grid-template-columns: 1fr; }
  .quiz-options { grid-template-columns: 1fr; }
  .bottom-nav { display: grid; }
  .app-header > .outline-button { display: none; }
  .control-row > * { flex: 1 1 110px; }
}

@media (min-width: 761px) {
  .view { width: min(940px, 100%); }
}
