:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --ink: #182230;
  --muted: #667085;
  --line: #d9e0ea;
  --blue: #1d4e89;
  --blue-soft: #e8f1ff;
  --green: #1f7a4d;
  --green-soft: #e4f6ea;
  --gold: #9a5b00;
  --gold-soft: #fff2d8;
  --violet: #6842a0;
  --violet-soft: #f1e8ff;
  --danger: #a83d54;
  --radius: 8px;
  --shadow: 0 20px 50px rgba(21, 38, 66, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(232, 241, 255, 0.72), rgba(245, 247, 251, 0) 320px),
    var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

button, input { font: inherit; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: 28px 32px 20px;
  border-bottom: 1px solid rgba(217, 224, 234, 0.75);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue);
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3 { margin: 0; letter-spacing: 0; }

h1 { font-size: 30px; line-height: 1.2; }
h2 { font-size: 26px; line-height: 1.25; }
h3 { font-size: 18px; line-height: 1.35; }

.subhead, .chapter-meta {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.top-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search-wrap {
  position: relative;
  width: min(440px, 42vw);
}

.search-mark {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 18px;
}

input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px 12px 40px;
  outline: none;
  color: var(--ink);
}

input[type="search"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 78, 137, 0.14);
}

.ghost-button,
.progress-card button,
.card-action,
.quiz-actions button,
.tab {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
  cursor: pointer;
}

.ghost-button:hover,
.progress-card button:hover,
.card-action:hover,
.quiz-actions button:hover,
.tab:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 300px;
  gap: 20px;
  padding: 22px 24px 34px;
}

.sidebar,
.right-rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 14px;
  align-self: start;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding-right: 4px;
}

.panel,
.hero-panel,
.search-results,
.study-card,
.slide-card,
.term-card,
.formula-card,
.quiz-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(217, 224, 234, 0.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel { padding: 16px; }
.panel.compact { padding: 14px; }
.panel-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.stat strong {
  display: block;
  font-size: 20px;
  color: var(--blue);
}

.stat span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.chapter-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chapter-button {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.chapter-button.active {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.chapter-button.done .chapter-name::after {
  content: "已完成";
  float: right;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.chapter-name {
  display: block;
  font-weight: 800;
  font-size: 14px;
  line-height: 1.35;
}

.chapter-small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.content { min-width: 0; }

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  gap: 18px;
  padding: 22px;
  margin-bottom: 18px;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.tab {
  padding: 9px 14px;
  color: var(--muted);
}

.tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.progress-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  background: var(--surface-soft);
}

.progress-ring {
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: conic-gradient(var(--green) var(--progress, 0deg), #e8edf4 0deg);
  color: var(--ink);
  font-weight: 900;
  box-shadow: inset 0 0 0 12px #fff;
}

.progress-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.progress-card button {
  width: 100%;
  padding: 9px;
  font-size: 13px;
}

.view-root {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
  margin: 4px 0 2px;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.cards-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.study-card,
.term-card,
.formula-card,
.quiz-card,
.slide-card {
  padding: 16px;
}

.study-card h3,
.term-card h3,
.formula-card h3,
.quiz-card h3,
.slide-card h3 {
  color: var(--ink);
  margin-bottom: 8px;
}

.study-card p,
.term-card p,
.formula-card p,
.quiz-card p,
.slide-card p,
.slide-card li {
  color: #344054;
  line-height: 1.65;
}

.study-card p,
.term-card p,
.formula-card p,
.quiz-card p,
.slide-card p {
  margin: 0;
}

.linked-formulas strong {
  display: block;
  margin-bottom: 7px;
  color: var(--blue);
  font-size: 13px;
}

.linked-formulas {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(104, 66, 160, 0.22);
  border-radius: var(--radius);
  background: var(--violet-soft);
}

.linked-formula {
  display: grid;
  grid-template-columns: minmax(120px, 0.32fr) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 8px 0;
  border-top: 1px solid rgba(104, 66, 160, 0.16);
}

.linked-formula:first-of-type {
  border-top: 0;
}

.linked-formula span {
  font-weight: 800;
  color: var(--violet);
}

.linked-formula code {
  font-family: "Cascadia Mono", Consolas, "Microsoft YaHei", monospace;
  color: #344054;
  white-space: normal;
  overflow-wrap: anywhere;
}

.tag-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

.slide-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.slide-card ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.slide-card mark,
.search-results mark {
  background: #fff0b3;
  color: inherit;
  padding: 0 2px;
}

.formula-text {
  border-left: 4px solid var(--blue);
  background: var(--blue-soft);
  padding: 10px 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-weight: 900;
  color: var(--blue);
  margin: 10px 0;
  overflow-wrap: anywhere;
}

.formula-explain {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.formula-explain strong {
  display: block;
  margin-bottom: 5px;
  color: var(--blue);
  font-size: 13px;
}

.formula-explain p {
  margin: 0;
}

.formula-explain ol {
  margin: 0;
  padding-left: 20px;
  color: #344054;
  line-height: 1.65;
}

.formula-explain.example {
  background: var(--green-soft);
  border-color: rgba(31, 122, 77, 0.24);
}

.formula-explain.example strong {
  color: var(--green);
}

.formula-explain.warning {
  background: var(--gold-soft);
  border-color: rgba(154, 91, 0, 0.24);
}

.formula-explain.warning strong {
  color: var(--gold);
}

.formula-explain.linked {
  background: var(--violet-soft);
  border-color: rgba(104, 66, 160, 0.24);
}

.formula-explain.linked strong {
  color: var(--violet);
}

.formula-explain.linked ul {
  margin: 0;
  padding-left: 20px;
  color: #344054;
  line-height: 1.65;
}

.formula-source {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.quiz-card {
  display: grid;
  gap: 12px;
}

.quiz-answer {
  display: none;
  border-left: 4px solid var(--green);
  background: var(--green-soft);
  padding: 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.quiz-card.show-answer .quiz-answer { display: block; }

.quiz-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search-results {
  padding: 16px;
  margin-bottom: 18px;
}

.hidden { display: none; }

.result-item {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.result-item:first-child { border-top: 0; padding-top: 0; }

.result-item button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.result-item p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.mini-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-item {
  border-left: 3px solid var(--gold);
  background: var(--gold-soft);
  padding: 10px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.mini-item strong {
  display: block;
  color: var(--gold);
  margin-bottom: 4px;
}

.mini-item span {
  color: #4b5563;
  font-size: 13px;
  line-height: 1.55;
}

.formula-mini {
  display: grid;
  gap: 8px;
}

.formula-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px;
  background: var(--surface-soft);
}

.formula-chip strong {
  display: block;
  margin-bottom: 4px;
  color: var(--violet);
}

.formula-chip span {
  display: block;
  color: var(--muted);
  overflow-wrap: anywhere;
  font-size: 13px;
}

.mindmap-panel img {
  width: 100%;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 240px minmax(0, 1fr);
  }
  .right-rail {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .topbar,
  .layout,
  .hero-panel {
    display: block;
  }
  .topbar { padding: 22px 18px 16px; }
  .top-actions { justify-content: stretch; margin-top: 16px; }
  .search-wrap { width: 100%; }
  .layout { padding: 16px; }
  .sidebar {
    position: static;
    max-height: none;
    margin-bottom: 16px;
  }
  .chapter-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .hero-panel { padding: 18px; }
  .progress-card { margin-top: 16px; }
  .cards-grid { grid-template-columns: 1fr; }
  .right-rail { display: flex; margin-top: 16px; }
}

@media (max-width: 560px) {
  h1 { font-size: 25px; }
  h2 { font-size: 22px; }
  .chapter-nav { grid-template-columns: 1fr; }
  .mode-tabs { display: grid; grid-template-columns: repeat(2, 1fr); }
  .tab { width: 100%; }
}
