:root {
  color-scheme: light;
  --canvas: #f6f5ef;
  --paper: #fffefa;
  --ink: #1c2924;
  --muted: #58665f;
  --line: #dedfd6;
  --green: #145843;
  --green-dark: #0c3a2c;
  --green-soft: #e9f2ec;
  --gold: #f2e5af;
  --gold-ink: #554416;
  --good: #157040;
  --bad: #a53132;
  --shadow: 0 3px 18px #28271908;
  font-family: Inter, "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 20px; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 15px; line-height: 1.55; }
button, input, select { font: inherit; color: inherit; }
button, summary, select { cursor: pointer; }
a { color: inherit; }
b, strong { font-weight: 700; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 20px; line-height: 1.35; }
h3 { font-size: 15px; line-height: 1.4; }
p + p { margin-top: .5em; }
button, input, select, summary, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid #227c5a; outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }
.muted { color: var(--muted); font-size: 13px; }
.icon { width: 19px; height: 19px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

.skip-link {
  position: absolute; inset: 8px auto auto 8px; transform: translateY(-180%); z-index: 6;
  background: var(--paper); padding: 8px 14px; border: 1px solid var(--green);
}
.skip-link:focus { transform: none; }
.topbar { background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar-inner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  width: min(1180px, 100%); margin: 0 auto; padding: 15px 28px;
}
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; flex: 0 0 auto; line-height: 1.3; }
.brand img { display: block; border-radius: 10px; }
.brand b { display: block; font-size: 19px; letter-spacing: .04em; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.topbar-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 15px; }
.topbar-tools a, .header-button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 8px;
  color: var(--green); background: none; border: 0; border-radius: 7px; font-size: 14px; font-weight: 600; text-decoration: none;
}
.topbar-tools a:hover, .header-button:hover { background: var(--green-soft); }
.streak {
  display: inline-flex; align-items: center; gap: 3px; padding: 6px 10px; color: var(--green-dark);
  white-space: nowrap; background: var(--green-soft); border-radius: 999px; font-size: 13px;
}
.page { max-width: 1180px; margin: 0 auto; padding: 28px 28px 0; }
.foot { margin: 26px auto 0; padding: 0 20px max(28px, env(safe-area-inset-bottom)); text-align: center; font-size: 12px; color: var(--muted); }
.card { min-width: 0; padding: 22px; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.loading-card { max-width: 720px; margin: 0 auto; padding: 32px; }
.loading-card h1 { font-size: 21px; }
.loading-card .btn { margin-top: 14px; }

.btn {
  display: inline-flex; justify-content: center; align-items: center; gap: 8px;
  min-height: 44px; padding: 9px 15px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--paper); color: var(--ink); font-weight: 650; font-size: 14px; line-height: 1.35; text-align: center;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn .icon { width: 17px; height: 17px; }
.btn:hover:not(:disabled) { border-color: var(--green); color: var(--green-dark); background: var(--green-soft); }
.btn.primary { color: #fff; background: var(--green); border-color: var(--green); }
.btn.primary:hover:not(:disabled) { color: #fff; background: var(--green-dark); border-color: var(--green-dark); }
.btn:disabled { cursor: default; opacity: .54; }
.btn.text-button { border-color: transparent; background: transparent; color: var(--green); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: #fcf0ee; border-color: #edd6d3; color: var(--bad); }
.btn[aria-pressed="true"] { color: var(--green-dark); background: var(--green-soft); }
select, input[type=search] { min-height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: var(--paper); }
select { padding-right: 28px; }
input[type=search]::placeholder { color: #67736c; }

.dashboard-top, .dashboard-lower { display: grid; grid-template-columns: minmax(0, 2fr) minmax(295px, 1fr); gap: 18px; align-items: start; }
.dashboard-top { align-items: stretch; }
.study-hero {
  display: flex; position: relative; isolation: isolate; align-items: center; overflow: hidden;
  min-height: 300px; background: #10382f; color: #fffdf2; border-radius: 20px;
}
.hero-art { position: absolute; z-index: -2; right: 0; width: 79%; height: 100%; object-fit: cover; object-position: right 51%; }
.study-hero::after {
  position: absolute; z-index: -1; inset: 0; content: "";
  background: linear-gradient(90deg, #10382f 7%, #10382ff8 23%, #10382fc9 43%, #10382f00 81%);
}
.hero-content { padding: 29px 32px; }
.stage-field { display: flex; align-items: center; gap: 9px; color: #e3ede4; font-size: 13px; }
.stage-field select {
  min-height: 40px; color: #fffdf2; border-color: #d4ebdb61; background: #204b3f; font-weight: 650;
}
.stage-field select option { color: var(--ink); background: var(--paper); }
.study-hero :focus-visible { outline-color: var(--gold); }
.study-hero h1 { margin-top: 14px; font-size: clamp(34px, 4.35vw, 52px); line-height: 1.15; letter-spacing: .025em; }
.hero-meta { margin-top: 10px; color: #f0f2e8; font-weight: 600; font-size: 15px; }
.hero-meta span { margin: 0 5px; color: #b6cbbd; }
.hero-hint { margin-top: 12px; color: #e0ebe2; font-size: 13px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 23px; }
.hero-actions .btn { min-height: 46px; padding-inline: 16px; }
.hero-actions .hero-primary { background: var(--gold); border-color: var(--gold); color: var(--green-dark); }
.hero-actions .hero-primary:hover { background: #fff1bb; color: var(--green-dark); }
.hero-actions .hero-secondary { background: #123a30c9; border-color: #c9ded290; color: #fffdf2; }
.hero-actions .hero-secondary:hover { background: #255445; border-color: #fffdf2; color: #fffdf2; }

.section-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 5px 12px; margin-bottom: 15px; }
.section-heading h2 { display: inline-flex; align-items: center; gap: 7px; }
.section-heading h2 .icon { color: var(--green); }
.checkin-card { display: flex; flex-direction: column; justify-content: center; }
.checkin-total { color: var(--gold-ink); font-size: 13px; font-weight: 700; background: #f5edce; padding: 5px 9px; border-radius: 999px; }
.checkin-progress { margin-bottom: 14px; }
.progress-label { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; font-size: 14px; }
.progress-label strong { font-size: 17px; }
.progress-label strong span { color: var(--muted); font-size: 14px; font-weight: 600; }
.meter { display: block; width: 100%; height: 8px; margin: 8px 0; appearance: none; overflow: hidden; color: var(--accent, var(--green)); border: 0; border-radius: 999px; background: #e6e9e0; }
.meter::-webkit-progress-bar { background: transparent; border-radius: 999px; }
.meter::-webkit-progress-value { background: var(--accent, var(--green)); border-radius: 999px; }
.meter::-moz-progress-bar { background: var(--accent, var(--green)); border-radius: 999px; }
.checkin-card > .btn { width: 100%; }
.checked-in { text-align: center; padding: 11px 10px; border-radius: 9px; background: var(--green-soft); color: var(--green-dark); font-weight: 700; }
.checkin-footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 5px 10px; margin-top: 15px;
  padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px;
}
.checkin-footer .icon { width: 15px; height: 15px; color: #a46624; vertical-align: -2px; }
.checkin-footer b { color: var(--ink); }
.badges { margin-top: 6px; font-size: 13px; }
.badges summary { min-height: 28px; padding-top: 4px; color: var(--green); }
.mobile-study-streak { display: none; }
.badges-list { margin: 6px 0 0; padding: 0; list-style: none; }
.badges-list li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }

.quick-section { margin: 24px 0; }
.quick-section .section-heading { margin-bottom: 11px; }
.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tone-daode { --accent: #875826; --wash: #f7eddc; }
.tone-lishi { --accent: #9b4940; --wash: #f8e9e4; }
.tone-dili { --accent: #285f82; --wash: #e7eff5; }
.tone-shengwu { --accent: #237254; --wash: #e4f1e8; }
.tile-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 39px; width: 39px; height: 39px;
  color: var(--accent); background: var(--wash); border-radius: 10px;
}
.quick-card {
  display: flex; min-width: 0; min-height: 74px; align-items: center; gap: 10px; padding: 12px;
  text-align: left; color: var(--ink); border: 1px solid var(--line); background: var(--paper); border-radius: 13px;
  transition: border-color .15s, background-color .15s;
}
.quick-card:hover { border-color: var(--accent); background: var(--wash); }
.quick-name { min-width: 0; }
.quick-name strong, .quick-name small { display: block; }
.quick-name strong { font-size: 14px; }
.quick-name small { color: var(--muted); }
.quick-arrow { color: var(--muted); margin-left: auto; width: 15px; }

.subject-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.subject-entry { padding: 12px; background: #fff; border: 1px solid #e8e6de; border-radius: 12px; min-width: 0; }
.subject-heading { display: flex; align-items: center; gap: 8px; }
.subject-heading p { color: var(--muted); font-size: 12px; }
.subject-entry .meter { height: 6px; margin-top: 11px; }
.subject-stats { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 8px; color: var(--muted); font-size: 12px; }
.weak-chapters { margin-top: 13px; }
.weak-chapters summary { color: var(--bad); }
.weak-chapters ul { padding: 0; list-style: none; }
.weak-chapters li { display: flex; gap: 8px; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.weak-chapters strong { color: var(--bad); }
.daily-column { display: grid; gap: 12px; }
.daily-card { background: #fcf8ea; }
.daily-stem {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
  margin-block: 8px 14px; line-height: 1.65; font-size: 14px;
}
.daily-card .btn { border-color: #c8c5ac; }
.chip {
  display: inline-block; border-radius: 6px; padding: 4px 8px; background: var(--wash, var(--green-soft));
  color: var(--accent, var(--green-dark)); font-size: 12px; font-weight: 700; line-height: 1.4; white-space: nowrap;
}
.mini-card .btn, .wrong-today .btn { margin-top: 10px; }
.wrong-today summary { font-weight: 700; }
.wrong-today ol { padding-left: 20px; font-size: 13px; }
.wrong-today li + li { margin-top: 10px; }
.wrong-today li strong { display: block; color: var(--green); }
.search-card { margin-top: 18px; scroll-margin-top: 18px; }
.search-fields { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.search-fields input { width: 100%; min-width: 0; }
#searchStatus:not(:empty) { margin-top: 9px; }
.search-results { display: grid; gap: 6px; }
.search-hit { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding-top: 12px; margin-top: 7px; border-top: 1px solid var(--line); }
.search-hit p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; margin-top: 5px; }
.search-hit .btn { flex-shrink: 0; }

.practice-shell { max-width: 812px; margin: 0 auto; }
.practice-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 12px; padding: 0 0 10px; font-size: 13px; color: var(--muted); }
.practice-top .btn { padding-left: 0; }
.question-card { padding: clamp(16px, 4vw, 31px); }
.question-progress { margin-bottom: 20px; }
.question-progress #qProg { color: var(--muted); font-size: 12px; }
.question-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.chapter-tag { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.question-card h1 { font-size: clamp(18px, 2.4vw, 23px); line-height: 1.65; overflow-wrap: anywhere; white-space: pre-line; }
.material { padding: 12px; margin-bottom: 8px; border-left: 3px solid var(--green); background: var(--green-soft); }
.options { display: grid; gap: 8px; margin-top: 15px; }
.selection-hint { margin-top: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 10px; min-width: 0; min-height: 51px; width: 100%; padding: 11px 13px;
  border: 1px solid #dfe2d9; border-radius: 9px; background: #fff; text-align: left;
  line-height: 1.55; overflow-wrap: anywhere; transition: border-color .15s, background-color .15s;
}
.opt:hover:not(:disabled), .opt[aria-pressed="true"] { background: var(--green-soft); border-color: var(--green); }
.opt:disabled { cursor: default; color: var(--ink); }
.opt-key { display: inline-grid; place-items: center; flex: 0 0 25px; height: 25px; border-radius: 6px; color: var(--green-dark); background: var(--green-soft); font-weight: 700; }
.opt-text { flex: 1; }
.opt[aria-pressed="true"] .opt-key { background: var(--green); color: #fff; }
.opt.right { border-color: #7bb18f; background: #edf8ef; }
.opt.wrong { border-color: #d09c96; background: #faefed; }
.opt.right .opt-key, .opt.right .opt-status { color: var(--good); background: #dfeee3; }
.opt.wrong .opt-key, .opt.wrong .opt-status { color: var(--bad); background: #f3e0dc; }
.opt-status:not(:empty) { border-radius: 5px; padding: 2px 5px; font-size: 12px; white-space: nowrap; }
.opt-status:empty { display: none; }
.question-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 7px 12px; margin-top: 15px; }
.question-tools, .question-flow { display: flex; flex-wrap: wrap; gap: 6px; }
.question-tools .btn { padding-inline: 8px; }
.result-panel {
  margin-top: 14px; padding: 15px; border: 1px solid #dfd2a9; border-left: 4px solid #a36b20;
  background: #fcf6e6; border-radius: 9px; overflow-wrap: anywhere;
}
.result-panel.correct { border-color: #b7d3c1; border-left-color: var(--good); background: #edf7ee; }
.result-panel.incorrect { border-color: #e2c2b8; border-left-color: var(--bad); background: #fcf1eb; }
.result-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 12px; margin-bottom: 8px; }
.result-title strong { color: var(--gold-ink); font-size: 17px; }
.result-panel.correct .result-title strong { color: var(--good); }
.result-panel.incorrect .result-title strong { color: var(--bad); }
.result-note { margin-top: 8px; color: var(--muted); font-size: 13px; }
.source-details { margin-top: 9px; font-size: 13px; color: var(--muted); }
.exp-body { line-height: 1.7; }
.navbox { margin-top: 12px; padding: 12px 16px; }
.navbox summary { min-height: 32px; padding-top: 4px; font-weight: 700; }
.navbox summary span { margin-left: 7px; font-weight: 400; }
.nav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin-top: 10px; }
.nav-grid button { min-height: 44px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.nav-grid button.done { background: #e2f1e7; color: var(--good); }
.nav-grid button.wrong { background: #f7e7e3; color: var(--bad); }
.nav-grid button[aria-current] { border: 2px solid var(--green); font-weight: 700; }
.nav-paging { display: flex; align-items: center; justify-content: space-between; gap: 5px; margin-top: 8px; }

#qfig:not(:empty) { margin-top: 12px; }
.figure-button { display: grid; justify-items: center; gap: 4px; max-width: 100%; margin: 0 auto; padding: 5px; border: 1px solid var(--line); border-radius: 9px; color: var(--green); background: #fff; cursor: zoom-in; }
.figure-button img { display: block; max-width: 100%; max-height: 360px; object-fit: contain; }
.figure-button span { padding: 4px; font-size: 13px; }
.figure-dialog { width: min(94vw, 930px); text-align: center; }
.figure-dialog form { display: flex; justify-content: flex-end; }
.figure-dialog img { display: block; max-width: 100%; max-height: 75dvh; margin: 0 auto 7px; object-fit: contain; }
.dialog {
  width: min(calc(100% - 24px), 530px); max-height: 90dvh; overflow: auto; padding: 20px;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 18px 48px #001b1350;
}
.dialog.figure-dialog { width: min(calc(100% - 24px), 930px); }
.dialog::backdrop { background: #18241ee0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
#importMessage:not(:empty) { margin-top: 14px; }
.data-reset { margin-top: 15px; border-top: 1px solid var(--line); padding-top: 7px; }

.toast {
  position: fixed; z-index: 5; left: 50%; bottom: max(18px, env(safe-area-inset-bottom));
  width: max-content; max-width: min(90vw, 460px); padding: 10px 15px; background: #152d24; color: #fff;
  border-radius: 10px; box-shadow: 0 4px 16px #0002; text-align: center; font-size: 14px;
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 800px) {
  .dashboard-top, .dashboard-lower { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .topbar-inner { padding: 11px 18px; }
  .page { padding: 16px 18px 0; }
  .study-hero { min-height: 258px; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-section { margin-block: 19px; }
}
@media (max-width: 480px) {
  .topbar-inner { padding: 10px 13px; }
  .topbar-tools { gap: 3px; }
  .topbar-tools a, .header-button { padding-inline: 6px; font-size: 13px; }
  .brand { gap: 7px; }
  .brand b { font-size: 17px; }
  .brand img { width: 36px; height: 36px; }
  .streak { display: none; }
  .mobile-study-streak { display: block; }
  .page { padding: 12px 12px 0; }
  .card { padding: 16px; border-radius: 14px; }
  h2 { font-size: 18px; }
  .study-hero { border-radius: 16px; min-height: 241px; }
  .hero-art { width: 100%; opacity: .78; }
  .study-hero::after { background: linear-gradient(90deg, #10382f 4%, #10382ff2 30%, #10382fb3 60%, #10382f15 100%); }
  .hero-content { padding: 20px 16px; }
  .hero-actions { margin-top: 16px; gap: 7px; }
  .hero-actions .btn { padding-inline: 10px; }
  .hero-meta, .hero-hint { font-size: 13px; }
  .quick-grid, .subject-grid { gap: 8px; }
  .quick-card { padding: 9px; gap: 7px; }
  .tile-icon { width: 34px; height: 34px; flex-basis: 34px; }
  .quick-arrow { width: 13px; }
  .quick-name strong { font-size: 13px; }
  .subject-entry { padding: 10px; }
  .subject-heading { gap: 6px; }
  .subject-heading h3 { font-size: 13px; }
  .subject-stats, .subject-heading p { font-size: 11px; }
  .search-fields { grid-template-columns: minmax(0, 1fr); }
  .search-hit .btn { padding-inline: 8px; }
  .search-hit .btn .icon { display: none; }
  .question-actions { flex-direction: column-reverse; }
  .question-flow .btn { flex: 1; }
  .opt { padding: 11px 10px; }
  .nav-paging .btn { padding-inline: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
