:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #f7f9f8;
  --text: #17211d;
  --muted: #66736d;
  --line: #dfe5e2;
  --accent: #176b4d;
  --accent-strong: #0f553d;
  --accent-soft: #e8f3ee;
  --warning: #a66017;
  --warning-soft: #fff5e8;
  --danger: #b84135;
  --danger-soft: #fff0ee;
  --success: #16734f;
  --shadow: 0 12px 30px rgba(24, 42, 34, .08);
  --radius: 8px;
  color-scheme: light;
}

[data-theme="paper"] {
  --bg: #eef1ea; --surface: #fbfcf7; --surface-soft: #f2f5ed; --text: #202821;
  --muted: #687066; --line: #d8ded2; --accent: #526f48; --accent-strong: #405a38;
  --accent-soft: #e7eee1; --shadow: 0 12px 30px rgba(41, 54, 37, .09);
}
[data-theme="night"] {
  --bg: #151817; --surface: #1e2321; --surface-soft: #252b28; --text: #eff3f1;
  --muted: #aab4af; --line: #353d39; --accent: #55c695; --accent-strong: #70d4aa;
  --accent-soft: #243d33; --warning: #efb15f; --warning-soft: #3a3022; --danger: #f18176;
  --danger-soft: #3a2927; --success: #6ad3a7; --shadow: 0 12px 30px rgba(0, 0, 0, .24); color-scheme: dark;
}
[data-theme="sunny"] {
  --bg: #f4f2ea; --surface: #fffefa; --surface-soft: #f7f5ec; --text: #24251f;
  --muted: #6e7065; --line: #e3dfcd; --accent: #35695c; --accent-strong: #285348;
  --accent-soft: #e8f0e9; --warning: #96600e; --warning-soft: #fff3c9; --shadow: 0 12px 30px rgba(71, 65, 37, .09);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif; letter-spacing: 0; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent); outline-offset: 2px; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.topbar { height: 68px; padding: 0 24px; display: flex; align-items: center; gap: 28px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; background: var(--accent); color: #fff; font-family: Georgia, serif; font-weight: 700; font-size: 21px; border-radius: 6px; }
.brand-mark.large { width: 48px; height: 48px; margin: 0 auto 8px; font-size: 28px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; }
.brand small { color: var(--muted); font-size: 10px; text-transform: uppercase; margin-top: 1px; }
.desktop-nav { height: 100%; display: flex; align-items: stretch; gap: 8px; }
.nav-item { padding: 0 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-weight: 600; }
.nav-item:hover, .nav-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; display: grid; place-items: center; cursor: pointer; font-weight: 700; }
.icon-button:hover { background: var(--surface-soft); border-color: var(--accent); }
.account-button { height: 40px; border: 0; background: transparent; display: flex; gap: 8px; align-items: center; cursor: pointer; font-weight: 600; }
.avatar { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
.theme-menu-wrap { position: relative; }
.theme-menu { position: absolute; right: 0; top: 46px; width: 190px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); z-index: 30; }
.theme-option { width: 100%; padding: 9px; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; border-radius: 5px; cursor: pointer; text-align: left; }
.theme-option:hover, .theme-option.active { background: var(--surface-soft); }
.theme-swatch { width: 24px; height: 24px; border: 1px solid rgba(0,0,0,.12); border-radius: 50%; }

.view { display: none; }
.view.active { display: grid; }
#learnView { grid-template-columns: 260px minmax(420px, 1fr) 250px; min-height: calc(100vh - 68px); max-width: 1500px; margin: 0 auto; }
.lesson-sidebar, .session-sidebar { background: var(--surface); padding: 28px 20px; }
.lesson-sidebar { border-right: 1px solid var(--line); }
.session-sidebar { border-left: 1px solid var(--line); }
.sidebar-heading { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.eyebrow { display: block; color: var(--accent); font-size: 11px; font-weight: 800; text-transform: uppercase; margin-bottom: 6px; }
h1, h2, h3, p { margin-top: 0; }
.sidebar-heading h1 { font-size: 19px; margin-bottom: 20px; }
.difficulty-switch { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.difficulty-button { position: relative; min-width: 0; min-height: 36px; padding: 3px 5px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; cursor: pointer; display: grid; place-content: center; gap: 1px; font-size: 11px; font-weight: 700; }
.difficulty-button small { color: var(--warning); font-size: 8px; font-weight: 600; }
.difficulty-button:hover { color: var(--text); }
.difficulty-button.active { color: #fff; background: var(--accent); }
.overall-progress { color: var(--muted); font-size: 11px; margin-bottom: 20px; }
.overall-progress > span { display: block; margin-bottom: 6px; text-align: right; }
.progress-track { height: 6px; overflow: hidden; background: var(--line); border-radius: 3px; }
.progress-track i { display: block; width: 0; height: 100%; background: var(--accent); border-radius: inherit; transition: width .25s ease; }
.lesson-list { display: grid; gap: 4px; }
.lesson-item { width: 100%; min-height: 54px; padding: 8px; display: grid; grid-template-columns: 32px 1fr 18px; align-items: center; gap: 9px; text-align: left; border: 0; border-radius: 6px; background: transparent; cursor: pointer; }
.lesson-item:hover { background: var(--surface-soft); }
.lesson-item.active { background: var(--accent-soft); color: var(--accent); }
.lesson-index { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; font-size: 11px; font-weight: 700; }
.lesson-item.active .lesson-index { color: #fff; border-color: var(--accent); background: var(--accent); }
.lesson-copy strong, .lesson-copy small { display: block; }
.lesson-copy strong { font-size: 13px; margin-bottom: 2px; }
.lesson-copy small { color: var(--muted); font-size: 10px; }
.lesson-state { color: var(--success); font-weight: 800; }

.practice-panel { padding: 42px clamp(28px, 5vw, 76px); background: var(--bg); }
.practice-topline { display: grid; grid-template-columns: 1fr auto; align-items: start; margin-bottom: 28px; }
.practice-topline h2 { margin: 0; font-size: 25px; }
.back-lessons { display: none; }
.sentence-progress { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.sentence-dots { display: flex; flex: 1; gap: 5px; }
.sentence-dots i { height: 4px; flex: 1; background: var(--line); border-radius: 2px; }
.sentence-dots i.done { background: var(--accent); }
.sentence-dots i.current { background: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.sentence-progress strong { color: var(--muted); font-size: 11px; }
.translation-workspace { padding: clamp(24px, 4vw, 46px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.prompt-block { min-height: 120px; display: flex; flex-direction: column; justify-content: center; text-align: center; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
.prompt-label, .answer-label { display: block; color: var(--muted); font-size: 11px; font-weight: 700; margin-bottom: 12px; }
.prompt-block p { font-family: Georgia, "Microsoft YaHei", serif; font-size: 29px; line-height: 1.45; margin-bottom: 24px; }
.answer-wrap { position: relative; }
input:focus { border-color: var(--accent); }
.word-slots { min-height: 112px; display: flex; align-items: end; justify-content: center; align-content: center; flex-wrap: wrap; gap: 16px 12px; padding: 4px 26px 8px 4px; }
.word-slot { display: grid; grid-template-rows: 19px 46px 20px; justify-items: center; min-width: 42px; }
.word-phonetic { height: 19px; color: var(--muted); font-family: Georgia, "Times New Roman", serif; font-size: 11px; white-space: nowrap; }
.word-entry-line { display: flex; align-items: end; }
.word-entry { width: var(--slot-width); min-width: 42px; max-width: 220px; height: 46px; padding: 0 2px 3px; border: 0; border-bottom: 4px solid var(--slot-color); border-radius: 0; color: var(--text); background: transparent; font-family: Arial, "Segoe UI", sans-serif; font-size: 29px; line-height: 39px; text-align: center; }
.word-entry:focus { border-bottom-color: var(--accent-strong); outline-offset: 3px; }
.word-entry::placeholder { color: color-mix(in srgb, var(--muted) 35%, transparent); }
.word-punctuation { padding-bottom: 5px; font-size: 29px; }
.word-gloss { max-width: 140px; height: 20px; overflow: hidden; color: var(--muted); font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.word-count { position: absolute; right: 5px; bottom: 12px; color: var(--muted); font-family: Inter, "Segoe UI", sans-serif; font-size: 10px; }
.practice-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.primary-button, .secondary-button { min-height: 40px; border-radius: 6px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); cursor: pointer; font-weight: 700; font-size: 13px; }
.primary-button { margin-left: auto; color: #fff; background: var(--accent); border-color: var(--accent); }
.primary-button:hover { background: var(--accent-strong); }
.secondary-button { background: var(--surface); }
.secondary-button:hover { border-color: var(--accent); color: var(--accent); }
.wide { width: 100%; margin-left: 0; }
.feedback { margin-top: 16px; padding: 14px; border-radius: 6px; font-size: 13px; line-height: 1.55; }
.feedback span { display: block; }
.feedback .case-note { margin-bottom: 4px; font-weight: 700; }
.feedback.good { color: var(--success); background: var(--accent-soft); }
.feedback.close { color: var(--warning); background: var(--warning-soft); }
.feedback.wrong { color: var(--danger); background: var(--danger-soft); }
.feedback strong { display: block; margin-bottom: 4px; }
.lesson-note { display: flex; gap: 12px; padding: 18px 4px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.lesson-note strong { color: var(--text); }
.lesson-note p { margin: 4px 0 0; }
.note-icon { width: 22px; height: 22px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-weight: 800; }

.session-title { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; margin-bottom: 16px; }
.live-dot { width: 7px; height: 7px; background: var(--accent); border-radius: 50%; box-shadow: 0 0 0 4px var(--accent-soft); }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.metric-grid div { padding: 16px; }
.metric-grid div + div { border-left: 1px solid var(--line); }
.metric-grid strong, .metric-grid span { display: block; }
.metric-grid strong { font-size: 22px; margin-bottom: 3px; }
.metric-grid span { color: var(--muted); font-size: 10px; }
.mini-section { padding: 22px 0; border-bottom: 1px solid var(--line); }
.mini-heading { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 9px; }
.streak-box { display: flex; align-items: center; gap: 12px; margin-top: 22px; padding: 14px; background: var(--surface-soft); border-radius: var(--radius); }
.streak-symbol { width: 32px; height: 32px; display: grid; place-items: center; color: var(--warning); background: var(--warning-soft); border-radius: 6px; font-weight: 800; }
.streak-box strong, .streak-box small { display: block; }
.streak-box small { color: var(--muted); font-size: 10px; margin-top: 2px; }
blockquote { margin: 26px 0; color: var(--muted); font-family: Georgia, serif; font-size: 13px; line-height: 1.6; }
blockquote > span { color: var(--accent); font-size: 30px; line-height: .8; }
.shortcut-note { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
kbd { padding: 3px 6px; color: var(--text); background: var(--surface-soft); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; }

.page-view { display: none; max-width: 1120px; margin: 0 auto; padding: 48px 28px 100px; }
.page-view.active { display: block; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.page-header h2 { margin: 0; font-size: 28px; }
.filter-bar { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.filter { padding: 10px 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.filter.active { color: var(--accent); border-color: var(--accent); font-weight: 700; }
.review-list { display: grid; gap: 10px; }
.review-card { padding: 18px; display: grid; grid-template-columns: 1fr auto; gap: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.review-card p { margin-bottom: 7px; font-size: 16px; }
.review-card small { color: var(--muted); }
.empty-state { padding: 70px 20px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 7px; }
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 26px; }
.stat-card { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat-card span, .stat-card strong { display: block; }
.stat-card span { color: var(--muted); font-size: 11px; margin-bottom: 10px; }
.stat-card strong { font-size: 26px; }
.difficulty-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 26px; }
.difficulty-stat { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.difficulty-stat-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 11px; font-size: 12px; }
.difficulty-stat-heading span { font-weight: 800; }
.difficulty-stat-heading strong { color: var(--muted); font-size: 11px; }
.data-section { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.section-heading { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.section-heading h3 { color: var(--text); font-size: 15px; }
.mastery-chart { min-height: 230px; display: flex; align-items: end; gap: 12px; padding-top: 30px; }
.chart-bar { flex: 1; min-width: 24px; text-align: center; color: var(--muted); font-size: 9px; }
.chart-bar i { height: var(--value); min-height: 4px; display: block; background: var(--accent); border-radius: 4px 4px 0 0; margin-bottom: 8px; }
.admin-summary { width: 190px; padding: 18px; margin-bottom: 18px; border-left: 3px solid var(--accent); background: var(--surface); }
.admin-summary span, .admin-summary small { display: block; }
.admin-summary span { font-size: 25px; font-weight: 800; }
.admin-summary small { color: var(--muted); }
.admin-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; }
th { color: var(--muted); background: var(--surface-soft); }
.status-chip { display: inline-block; padding: 4px 7px; color: var(--success); background: var(--accent-soft); border-radius: 4px; font-size: 10px; font-weight: 700; }
.difficulty-chip { display: inline-block; margin-right: 5px; padding: 3px 6px; border-radius: 4px; font-size: 10px; font-weight: 800; font-style: normal; }
.difficulty-chip.easy { color: var(--success); background: var(--accent-soft); }
.difficulty-chip.normal { color: var(--warning); background: var(--warning-soft); }
.difficulty-chip.hard { color: var(--danger); background: var(--danger-soft); }
.table-action { border: 0; color: var(--accent); background: transparent; cursor: pointer; font-weight: 700; }

dialog { width: min(430px, calc(100% - 32px)); padding: 0; border: 0; border-radius: var(--radius); color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 18, 14, .55); backdrop-filter: blur(3px); }
.dialog-card { position: relative; padding: 32px; display: grid; gap: 16px; text-align: center; }
.dialog-card h2 { margin: 0; }
.dialog-card p { color: var(--muted); font-size: 13px; }
.dialog-card label { display: grid; gap: 6px; text-align: left; color: var(--muted); font-size: 11px; font-weight: 700; }
.dialog-card input, .dialog-card select { width: 100%; padding: 11px; color: var(--text); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; }
.dialog-card > small { color: var(--muted); line-height: 1.5; }
.dialog-close { position: absolute; right: 12px; top: 10px; border: 0; background: transparent; color: var(--muted); font-size: 24px; cursor: pointer; }
.lesson-form { text-align: left; }
.lesson-form { max-height: min(86vh, 820px); overflow-y: auto; }
.checkbox-label { display: flex !important; grid-template-columns: none !important; align-items: center; gap: 8px !important; color: var(--text) !important; }
.checkbox-label input { width: 16px; height: 16px; }
.sentence-admin-section { padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.sentence-admin-section > div:first-child { display: flex; justify-content: space-between; align-items: center; }
#sentenceAdminList { display: grid; gap: 5px; margin-top: 8px; }
.sentence-admin-item { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); cursor: pointer; text-align: left; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.danger-button { min-height: 38px; border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); border-radius: 6px; color: var(--danger); background: var(--danger-soft); cursor: pointer; font-weight: 700; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.auth-tabs button { min-height: 36px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 700; }
.auth-tabs button.active { color: #fff; background: var(--accent); }
.auth-form { display: grid; gap: 14px; }
.text-button { border: 0; color: var(--accent); background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; }
.auth-status { padding: 10px; border-radius: 6px; color: var(--warning); background: var(--warning-soft); font-size: 12px; line-height: 1.5; }
.auth-status.error { color: var(--danger); background: var(--danger-soft); }
.auth-status.success { color: var(--success); background: var(--accent-soft); }
.auth-user { display: grid; gap: 14px; }
.connection-banner { position: fixed; left: 50%; bottom: 76px; z-index: 40; transform: translateX(-50%); width: min(520px, calc(100% - 28px)); padding: 11px 14px; display: flex; align-items: center; gap: 12px; color: var(--danger); background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--line)); border-radius: 6px; box-shadow: var(--shadow); font-size: 12px; }
.connection-banner span { flex: 1; }
.connection-banner button { border: 0; color: var(--danger); background: transparent; cursor: pointer; font-weight: 800; }
.mobile-nav { display: none; }

@media (max-width: 1050px) {
  #learnView { grid-template-columns: 230px 1fr; }
  .session-sidebar { display: none; }
}
@media (max-width: 760px) {
  body { padding-bottom: 64px; }
  .topbar { height: 58px; padding: 0 14px; }
  .brand { min-width: 0; }
  .brand small, .desktop-nav, .account-button { display: none; }
  .top-actions { gap: 5px; }
  #learnView { display: block; min-height: auto; }
  .lesson-sidebar { display: none; position: fixed; inset: 58px 0 64px; z-index: 15; overflow-y: auto; border: 0; }
  .lesson-sidebar.mobile-open { display: block; }
  .practice-panel { padding: 24px 16px; }
  .practice-topline { grid-template-columns: 34px 1fr auto; gap: 8px; }
  .back-lessons { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; font-size: 22px; }
  .practice-topline h2 { font-size: 21px; }
  .translation-workspace { padding: 22px 18px; }
  .prompt-block { min-height: 105px; }
  .prompt-block p, .word-entry, .word-punctuation { font-size: 23px; }
  .word-slots { justify-content: flex-start; gap: 14px 9px; padding-right: 18px; }
  .word-entry { height: 42px; line-height: 35px; max-width: 170px; }
  .word-slot { grid-template-rows: 18px 42px 19px; }
  .practice-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .primary-button { margin-left: 0; }
  .lesson-note { padding-bottom: 10px; }
  .mobile-nav { position: fixed; bottom: 0; left: 0; right: 0; height: 64px; z-index: 25; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: var(--surface); }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); display: grid; place-content: center; gap: 2px; cursor: pointer; }
  .mobile-nav button.active { color: var(--accent); }
  .mobile-nav span { font-size: 18px; line-height: 1; }
  .mobile-nav small { font-size: 9px; }
  .page-view { padding: 28px 16px 90px; }
  .page-header { align-items: end; }
  .page-header h2 { font-size: 23px; }
  .stat-cards { grid-template-columns: 1fr 1fr; }
  .difficulty-summary { grid-template-columns: 1fr; }
  .mastery-chart { gap: 6px; overflow-x: auto; }
  .chart-bar { min-width: 28px; }
  .review-card { grid-template-columns: 1fr; }
}
@media (max-width: 390px) {
  .brand strong { font-size: 14px; }
  .icon-button { width: 34px; height: 34px; }
  .practice-actions { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
