:root {
  color-scheme: light;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #172728;
  background: #edf0eb;
  font-synthesis: none;
  --ink: #172728;
  --forest: #102a2b;
  --teal: #126b65;
  --paper: #fffdf8;
  --mist: #edf0eb;
  --line: #ccd5cf;
  --muted: #687675;
  --coral: #d95f45;
  --gold: #d6a647;
  --good: #14775d;
  --bad: #b74335;
  --shadow: 0 14px 40px rgba(16, 42, 43, 0.09);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--forest); }

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(rgba(16, 42, 43, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 42, 43, 0.035) 1px, transparent 1px),
    var(--mist);
  background-size: 28px 28px;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; padding-bottom: calc(28px + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 70px;
  padding: calc(10px + env(safe-area-inset-top)) clamp(16px, 4vw, 42px) 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(16, 42, 43, 0.96);
  color: white;
  backdrop-filter: blur(16px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0;
  border: 0;
  color: inherit;
  text-align: left;
  background: transparent;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  color: #ffe1a3;
  font: 700 25px/1 Georgia, serif;
}

.brand strong { display: block; font-size: 15px; letter-spacing: 0; }
.brand small { display: block; margin-top: 2px; color: #b9cfca; font-size: 11px; }
.topbar-actions { display: flex; gap: 8px; }

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: inherit;
  background: rgba(255, 255, 255, 0.07);
  font-size: 24px;
}

.icon-button:hover { background: rgba(255, 255, 255, 0.14); }

main { width: min(100% - 28px, 1060px); margin: 0 auto; outline: none; }

.dashboard { padding-top: clamp(30px, 7vw, 72px); }
.eyebrow { color: var(--coral); font-size: 12px; font-weight: 800; text-transform: uppercase; }

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(260px, 0.75fr);
  gap: clamp(28px, 6vw, 70px);
  align-items: end;
  padding-bottom: 38px;
  border-bottom: 1px solid var(--line);
}

h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: Georgia, "Songti SC", serif; font-weight: 700; }
h1 { max-width: 720px; margin: 10px 0 15px; font-size: clamp(38px, 7vw, 76px); line-height: 1.02; }
.intro-copy { max-width: 620px; margin: 0; color: var(--muted); font-size: 16px; line-height: 1.8; }

.mastery {
  padding-left: 24px;
  border-left: 4px solid var(--gold);
}

.mastery strong { display: block; font: 700 clamp(42px, 7vw, 68px)/1 Georgia, serif; }
.mastery span { color: var(--muted); font-size: 13px; }
.mastery-track { height: 8px; margin-top: 14px; overflow: hidden; background: #d8dfda; }
.mastery-track i { display: block; height: 100%; background: var(--teal); transition: width 0.4s ease; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}

.stat { padding: 24px 18px 24px 0; }
.stat + .stat { padding-left: 18px; border-left: 1px solid var(--line); }
.stat strong { display: block; margin-bottom: 5px; font: 700 30px/1 Georgia, serif; }
.stat span { color: var(--muted); font-size: 12px; }

.mode-section { padding-top: 36px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-head h2 { margin: 0; font-size: 25px; }
.section-head span { color: var(--muted); font-size: 12px; }

.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.mode-card {
  min-height: 176px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 253, 248, 0.7);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.mode-card:hover { transform: translateY(-3px); border-color: var(--teal); background: var(--paper); }
.mode-card.primary { color: white; border-color: var(--forest); background: var(--forest); }
.mode-card[disabled] { cursor: not-allowed; opacity: 0.5; transform: none; }
.mode-icon { color: var(--gold); font: 700 28px/1 Georgia, serif; }
.mode-card h3 { margin: 18px 0 7px; font-size: 18px; }
.mode-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.mode-card.primary p { color: #b9cfca; }

.practice-layout { padding-top: 26px; }
.practice-meta { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.back-button { border: 0; color: var(--teal); background: transparent; font-weight: 700; }
.progress-copy { margin-left: auto; color: var(--muted); font-size: 12px; }
.progress-bar { height: 5px; margin-bottom: 22px; overflow: hidden; background: #d6ded9; }
.progress-bar span { display: block; height: 100%; background: var(--coral); transition: width 0.25s ease; }

.question-panel {
  padding: clamp(22px, 5vw, 46px);
  border-top: 5px solid var(--forest);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.question-kicker { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.question-kicker .type { padding: 4px 7px; border: 1px solid var(--line); border-radius: 4px; color: var(--teal); font-weight: 700; }
.question-text { margin: 22px 0 28px; font: 700 clamp(21px, 4vw, 30px)/1.55 Georgia, "Songti SC", serif; white-space: pre-wrap; }
.options { display: grid; gap: 11px; }
.option {
  min-height: 58px;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.option:hover { border-color: var(--teal); }
.option.selected { border-color: var(--teal); background: #edf7f3; }
.option.correct { border-color: var(--good); background: #e5f4ed; }
.option.wrong { border-color: var(--bad); background: #faeae7; }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option-key { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-weight: 800; }
.option-copy { line-height: 1.55; }

.question-actions { display: flex; gap: 10px; margin-top: 24px; }
.primary-button, .secondary-button, .danger-button {
  min-height: 44px;
  padding: 0 17px;
  border-radius: 6px;
  font-weight: 800;
}
.primary-button { border: 1px solid var(--forest); color: white; background: var(--forest); }
.primary-button:disabled { cursor: not-allowed; opacity: 0.4; }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: white; }
.danger-button { border: 1px solid #e2b5ae; color: var(--bad); background: #fff5f3; }
.favorite-button { margin-left: auto; }

.answer-panel { margin-top: 26px; padding: 20px; border-left: 4px solid var(--good); background: #edf6f1; }
.answer-panel.incorrect { border-color: var(--bad); background: #fff1ee; }
.answer-panel h3 { margin-bottom: 8px; font-size: 17px; }
.answer-panel p { margin-bottom: 0; color: #415251; line-height: 1.7; white-space: pre-wrap; }
.answer-line { margin-bottom: 10px !important; color: var(--ink) !important; font-weight: 800; }

.empty-state { padding: 70px 20px; text-align: center; }
.empty-state h2 { font-size: 28px; }
.empty-state p { color: var(--muted); }

dialog {
  width: min(92vw, 580px);
  max-height: 88vh;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.28);
}
dialog::backdrop { background: rgba(8, 25, 26, 0.62); backdrop-filter: blur(4px); }
.dialog-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 22px; color: white; background: var(--forest); }
.dialog-head h2 { margin: 5px 0 0; font-size: 25px; }
.dialog-section { padding: 22px; border-bottom: 1px solid var(--line); }
.dialog-section h3 { margin-bottom: 8px; font-size: 15px; }
.dialog-section p { margin: 0; color: var(--muted); line-height: 1.65; }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; }
.file-button { display: inline-flex; align-items: center; cursor: pointer; }
.file-button input { display: none; }
.offline-state { margin-top: 15px; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.offline-state span { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.offline-state span.ready { background: var(--good); }
.source-note { background: #f5f5ef; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 30px);
  padding: 12px 17px;
  border-radius: 6px;
  color: white;
  background: var(--forest);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 15px);
  pointer-events: none;
  transition: 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .intro { grid-template-columns: 1fr; gap: 28px; }
  .mastery { padding-left: 18px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .mode-grid { grid-template-columns: 1fr; }
  .mode-card { min-height: 145px; }
}

@media (max-width: 420px) {
  main { width: min(100% - 20px, 1060px); }
  .brand strong { font-size: 14px; }
  .question-panel { padding: 20px 16px; }
  .question-actions { flex-wrap: wrap; }
  .favorite-button { margin-left: 0; }
  .button-row > * { width: 100%; justify-content: center; }
}

@media (max-width: 340px) {
  .topbar { padding-right: 10px; padding-left: 10px; }
  .brand { gap: 8px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand small { display: none; }
  .topbar-actions { gap: 4px; }
  .icon-button { width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}