:root {
  --paper: #faf8f3;
  --card: #fffdf9;
  --ink: #241f1a;
  --ink-2: #4b443c;
  --muted: #857c70;
  --line: #e2dbcd;
  --line-strong: #d2c8b6;
  --accent: #2f6f5e;
  --accent-soft: #e6efe9;
  --amber: #a9741f;
  --amber-soft: #f6eeda;
  --red: #a8453a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(36 31 26 / 4%), 0 8px 24px -18px rgb(36 31 26 / 30%);
  --sans: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  --serif: 'Songti SC', 'Noto Serif SC', 'Source Han Serif SC', 'SimSun', serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
  min-height: 100dvh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgb(250 248 243 / 92%);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand small {
  display: block;
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar {
  display: none;
}

.nav a {
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 0.9rem;
  white-space: nowrap;
}

.nav a:hover {
  background: #f1ece1;
  text-decoration: none;
}

.nav a[aria-current='page'] {
  background: var(--ink);
  color: var(--paper);
}

/* 窄屏：品牌独占一行，导航另起一行可横滑，避免最后一个入口被裁掉 */
@media (max-width: 640px) {
  .topbar-inner {
    flex-wrap: wrap;
    row-gap: 4px;
    padding-bottom: 8px;
  }

  .brand {
    flex: 1 0 100%;
  }

  .brand small {
    display: inline;
    margin-left: 8px;
  }

  .nav {
    margin-left: 0;
    width: 100%;
  }

  .nav a {
    padding: 6px 10px;
    font-size: 0.85rem;
  }
}

/* ---------- 布局 ---------- */

.wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 26px 18px 80px;
}

.hero {
  padding: 18px 0 26px;
}

.hero h1 {
  font-family: var(--serif);
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  line-height: 1.3;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}

.hero p {
  margin: 0;
  color: var(--ink-2);
  max-width: 34em;
}

.eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

/* ---------- 统计 ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 22px 0 28px;
}

@media (min-width: 640px) {
  .stats {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.stat b {
  display: block;
  font-family: var(--serif);
  font-size: 1.5rem;
  line-height: 1.2;
}

.stat span {
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------- 按钮 ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #27604f;
  text-decoration: none;
}

.btn-ghost {
  border-color: var(--line-strong);
  background: var(--card);
}

.btn-ghost:hover {
  border-color: var(--ink-2);
  text-decoration: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

/* ---------- 册次卡片 ---------- */

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 34px 0 14px;
}

.section-head h2 {
  font-family: var(--serif);
  font-size: 1.2rem;
  margin: 0;
}

.section-head span {
  color: var(--muted);
  font-size: 0.82rem;
}

.books {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 560px) {
  .books {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 860px) {
  .books {
    grid-template-columns: repeat(4, 1fr);
  }
}

.book {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--ink);
}

.book:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.book b {
  display: block;
  font-size: 1rem;
  font-weight: 600;
}

.book span {
  color: var(--muted);
  font-size: 0.8rem;
}

.book .bar {
  height: 3px;
  border-radius: 3px;
  background: var(--accent-soft);
  margin-top: 10px;
  overflow: hidden;
}

.book .bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

/* ---------- 工具栏 ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 18px 0 16px;
}

.toolbar select,
.toolbar input {
  font: inherit;
  font-size: 0.9rem;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  min-width: 0;
}

.toolbar input {
  flex: 1 1 200px;
}

.toolbar .count {
  color: var(--muted);
  font-size: 0.82rem;
  margin-left: auto;
}

/* ---------- 目录列表 ---------- */

.unit {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  margin-bottom: 10px;
  overflow: hidden;
}

.unit > summary {
  cursor: pointer;
  padding: 13px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.unit > summary::-webkit-details-marker {
  display: none;
}

.unit > summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 0.8rem;
  transition: transform 0.15s;
}

.unit[open] > summary::before {
  transform: rotate(90deg);
}

.unit > summary em {
  margin-left: auto;
  font-style: normal;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.78rem;
}

.topic-list {
  border-top: 1px solid var(--line);
}

.topic {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 16px;
  border: 0;
  border-bottom: 1px solid #f0ebe0;
  background: transparent;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}

.topic:last-child {
  border-bottom: 0;
}

.topic:hover {
  background: #fbf7ee;
}

.topic .name {
  flex: 1;
}

.topic .tag {
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}

/* ---------- 详情面板 ---------- */

.detail {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  background: var(--card);
  border-top: 1px solid var(--line-strong);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px -20px rgb(36 31 26 / 45%);
  max-height: 82dvh;
  overflow-y: auto;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  .detail {
    position: sticky;
    inset: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: none;
    max-height: calc(100dvh - 120px);
  }
}

.detail h3 {
  font-family: var(--serif);
  font-size: 1.25rem;
  margin: 6px 0 4px;
}

.detail .where {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0 0 14px;
}

.detail h4 {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  margin: 18px 0 6px;
}

.detail p {
  margin: 0 0 10px;
}

.detail ul {
  margin: 0 0 10px;
  padding-left: 1.2em;
}

.detail li {
  margin-bottom: 4px;
}

.pill {
  display: inline-block;
  font-size: 0.75rem;
  border-radius: 999px;
  padding: 2px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-right: 6px;
}

.pill.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chip {
  font-size: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  background: #fff;
  cursor: pointer;
  color: var(--ink-2);
  font-family: inherit;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.x {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
}

/* ---------- 诊断链 ---------- */

.chain {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  counter-reset: step;
}

.chain li {
  position: relative;
  padding: 12px 16px 12px 52px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.chain li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 14px;
  top: 12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.chain li.root {
  border-color: var(--amber);
  background: #fffaf0;
}

.chain li.root::before {
  background: var(--amber-soft);
  color: var(--amber);
}

.chain li.target {
  border-color: var(--accent);
}

.chain .why {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.note {
  background: var(--amber-soft);
  border-left: 3px solid var(--amber);
  padding: 12px 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: #5d4a25;
  font-size: 0.86rem;
  margin: 16px 0;
}

.footer {
  border-top: 1px solid var(--line);
  margin-top: 40px;
  padding-top: 16px;
  color: var(--muted);
  font-size: 0.78rem;
}

.footer a {
  color: var(--ink-2);
}

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

/* ---------- 复习页专用（沿用原样式类的映射） ---------- */

.sheet {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px;
  box-shadow: var(--shadow);
}

.meta {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.front {
  font-size: 1.35rem;
  line-height: 1.55;
  font-weight: 600;
  margin: 6px 0 18px;
  white-space: pre-wrap;
  word-break: break-word;
}

.back {
  border-top: 1px dashed var(--line-strong);
  padding-top: 16px;
  margin-bottom: 20px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #3a352e;
}

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.grades button {
  border: 0;
  border-radius: 12px;
  padding: 12px 4px 10px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  font-family: inherit;
}

.grades small {
  font-weight: 400;
  font-size: 0.7rem;
  opacity: 0.9;
}

.again {
  background: var(--red);
}

.hard {
  background: #b07a2a;
}

.good {
  background: var(--accent);
}

.easy {
  background: #2d5f9a;
}

.primary {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  font-family: inherit;
}

.subjects {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 16px;
}

.subjects button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

.subjects button.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.panel {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  color: var(--muted);
  font-size: 0.85rem;
}

.panel summary {
  cursor: pointer;
  color: var(--ink);
  font-size: 0.9rem;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0;
}

.row button,
.file {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
}

.file input {
  display: none;
}

.danger {
  color: var(--red);
  border-color: #e3c4bf;
}

code {
  background: #efe9dd;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.85em;
}

/* ---------- 目录页布局 ---------- */

.catalog-layout {
  display: grid;
  gap: 18px;
  align-items: start;
  grid-template-columns: minmax(0, 1fr);
}

/* 只有选中有知识点、右侧要显示详情时，才变成两栏；否则列表铺满 */
@media (min-width: 900px) {
  .catalog-layout.has-detail {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
}

.topic[aria-current='true'] {
  background: var(--accent-soft);
}

.today {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.85rem;
}

.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

