:root {
  --ink: #12263a;
  --muted: #5a6f82;
  --paper: #edf2f7;
  --surface: #f7fafc;
  --card: #ffffff;
  --accent: #0f766e;
  --accent-deep: #0a5c56;
  --line: #c8d4e0;
  --warn: #9a3412;
  --shadow: 0 12px 40px rgba(18, 38, 58, 0.08);
  --radius: 14px;
  --font-display: "ZCOOL XiaoWei", "Songti SC", serif;
  --font-body: "Noto Sans SC", "PingFang SC", sans-serif;
  --rel-prereq: #0f766e;
  --rel-includes: #1d4ed8;
  --rel-related: #64748b;
  --rel-confusable: #b45309;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.65;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(15, 118, 110, 0.14), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(18, 38, 58, 0.08), transparent 50%),
    linear-gradient(180deg, #e8eef5 0%, var(--paper) 40%, #e4ebf3 100%);
}
.bg-grid::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(18, 38, 58, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 38, 58, 0.04) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, #000 0%, transparent 70%);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.site-header,
.view,
.status { position: relative; z-index: 1; }

/* ── Site header ── */
.site-header {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 0.85rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  border-bottom: 1px solid rgba(200, 212, 224, 0.7);
}

.site-brand .brand-mark {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.15rem, 4.5vw, 2.85rem);
  letter-spacing: 0.18em;
  color: var(--accent);
  line-height: 1.1;
}
.site-brand .brand-sub {
  margin: 0.25rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.site-nav {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.22rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}
.nav-tab {
  appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  padding: 0.5rem 1.05rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.nav-tab:hover { color: var(--accent-deep); }
.nav-tab.active {
  background: var(--accent);
  color: #fff;
}

/* ── View chrome ── */
.view {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.35rem 1.25rem 0;
}
.view-head { margin-bottom: 1.1rem; }
.view-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 3vw, 2rem);
  font-weight: 400;
  letter-spacing: 0.04em;
}
.view-desc {
  margin: 0.3rem 0 0;
  color: var(--muted);
  max-width: 40rem;
  font-size: 0.95rem;
}

.search {
  margin-top: 1rem;
  display: flex;
  gap: 0.65rem;
  max-width: 42rem;
  align-items: stretch;
}
.similar-search .limit-wrap {
  display: flex;
  align-items: stretch;
}
.similar-search select,
.graph-controls select {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  cursor: pointer;
  outline: none;
  box-shadow: var(--shadow);
}
.similar-search select:focus,
.graph-controls select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}
.search input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 0.85rem 1.2rem;
  font: inherit;
  font-size: 1rem;
  box-shadow: var(--shadow);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}
.search button,
.actions button,
.actions a,
.graph-controls button {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  border-radius: 999px;
  padding: 0.85rem 1.35rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.search button,
.actions .primary,
.graph-controls .primary {
  background: var(--accent);
  color: #fff;
}
.search button:hover,
.actions .primary:hover,
.graph-controls .primary:hover { background: var(--accent-deep); }
.actions .ghost {
  background: transparent;
  color: var(--accent-deep);
  border: 1px solid var(--line);
  padding: 0.75rem 1.1rem;
}
.actions .ghost:hover { border-color: var(--accent); }

/* ── Split layout (kp / similar) ── */
.layout {
  margin: 0 0 2.5rem;
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr;
  gap: 1rem;
  align-items: start;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 12rem;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1.1rem 0.5rem;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}
.meta { color: var(--muted); font-size: 0.85rem; }

.result-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  max-height: min(70vh, 720px);
  overflow: auto;
}
.result-list li button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.result-list li button:hover,
.result-list li button.active {
  background: var(--surface);
}
.result-list .title {
  display: block;
  font-weight: 600;
}
.result-list .sub {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.result-list .score {
  display: inline-block;
  margin-right: 0.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-deep);
}
.result-list .preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}
.similar-card { margin: 0; }
#similar-meta { word-break: break-all; }
#similar-body .fallback { color: var(--muted); }
#view-similar .pane {
  max-height: calc(100vh - 12rem);
  overflow: auto;
}

.detail { padding: 0; overflow: hidden; }
.empty {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--muted);
}
.detail-head {
  padding: 1.25rem 1.35rem 1rem;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 55%),
    var(--card);
}
.crumbs {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.detail-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 400;
}
.meta-row {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.actions {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.55rem 1rem 0;
  border-bottom: 1px solid var(--line);
}
.tab {
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active {
  color: var(--accent-deep);
  border-bottom-color: var(--accent);
}

.pane { padding: 1.1rem 1.35rem 1.5rem; }
.prose {
  font-size: 0.98rem;
  max-width: 46rem;
}
.prose p {
  margin: 0 0 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.prose .formula-ph,
.prose .img-ph {
  display: inline-block;
  margin: 0 0.15em;
  padding: 0.05em 0.4em;
  border-radius: 4px;
  background: #e6f2f0;
  color: var(--accent-deep);
  font-size: 0.85em;
}
.prose img.inline-media {
  max-width: min(100%, 520px);
  height: auto;
  vertical-align: middle;
  margin: 0.35rem 0.15rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
}
.prose img.formula-img {
  display: inline-block;
  height: 1.5em;
  width: auto;
  max-width: min(100%, 18em);
  vertical-align: middle;
  margin: 0 0.06em;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  object-fit: contain;
}
.prose img.formula-img.formula-block {
  display: inline-block;
  height: 1.5em;
  max-width: min(100%, 18em);
  margin: 0.1rem 0;
  padding: 0;
  border: none;
  vertical-align: middle;
}
.prose img.diagram-img {
  display: block;
  margin: 0.75rem auto;
  max-width: min(100%, 420px);
  width: auto;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem;
}
.prose td img.formula-img,
.prose td img.formula-block {
  height: 1.5em;
  max-width: min(100%, 16em);
  display: inline-block;
  margin: 0 0.05em;
  vertical-align: middle;
}
.q-body.prose img.formula-img,
.q-body.prose img.formula-img.formula-block,
.q-body img.formula-img,
.q-body img.formula-block {
  height: 1.5em !important;
  max-height: 1.5em !important;
  width: auto !important;
  max-width: min(100%, 18em) !important;
  display: inline-block !important;
  vertical-align: middle;
  margin: 0 0.06em;
}
.q-body mjx-container { font-size: 1em !important; }
.q-body .math-inline {
  font-size: 1em;
  line-height: inherit;
  vertical-align: middle;
}
.prose .math-inline {
  display: inline-block;
  margin: 0 0.05em;
  vertical-align: middle;
}
.prose .math-fallback {
  font-family: "Times New Roman", "Songti SC", serif;
  font-style: italic;
  color: var(--ink);
}
.prose .fallback {
  color: var(--muted);
  border-left: 3px solid var(--accent);
  padding-left: 0.85rem;
}
.prose .table-wrap {
  overflow-x: auto;
  margin: 0.75rem 0 1rem;
}
.prose table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
}
.prose td {
  border: 1px solid var(--line);
  padding: 0.35rem 0.5rem;
  vertical-align: top;
}

.practice-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.practice-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.pager {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.pager .ghost {
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--accent-deep);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
}
.pager .ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pager-label {
  min-width: 4.5rem;
  text-align: center;
  font-weight: 600;
  color: var(--accent-deep);
}

.question-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 1.1rem 1.15rem 1.25rem;
}
.q-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  margin-bottom: 0.85rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.q-head span {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem 0.65rem;
}
.q-body {
  word-break: break-word;
  font-size: 1.02rem;
  line-height: 1.75;
  min-height: 4rem;
}
.q-body p { white-space: normal; }
.q-body .img-token {
  color: var(--warn);
  font-size: 0.85em;
}

.answer-box {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--line);
}
.answer-box h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}
.hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.hint.subtle { opacity: 0.85; }
.answer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  background: #fff;
  font-weight: 500;
  color: var(--accent-deep);
}
.file-btn:hover { border-color: var(--accent); }
.answer-preview { margin-top: 0.85rem; }
.answer-preview img {
  max-width: min(100%, 420px);
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}
.upload-status {
  margin: 0.55rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  min-height: 1.2em;
}
.answer-history { margin-top: 0.85rem; }
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.65rem;
}
.history-grid figure {
  margin: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.history-grid img {
  display: block;
  width: 100%;
  height: 96px;
  object-fit: cover;
}
.history-grid figcaption {
  padding: 0.3rem 0.45rem;
  font-size: 0.72rem;
  color: var(--muted);
}

/* ── Graph list mindmap (章 → 节 → 知识点) ── */
.graph-controls {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
}
.graph-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.graph-controls select {
  min-width: 7.5rem;
  padding: 0.7rem 1rem;
}
.graph-layout {
  margin: 0 0 2.5rem;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 380px);
  gap: 1rem;
  align-items: start;
  min-height: 28rem;
}
.graph-panel {
  position: relative;
  min-height: 28rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.graph-tree {
  flex: 1;
  overflow: auto;
  padding: 0.55rem 0.75rem 1rem;
  min-height: 280px;
  max-height: min(68vh, 640px);
  background: var(--surface);
}
.graph-tree[hidden] { display: none; }
.mm-list { list-style: none; margin: 0; padding: 0; }
.mm-chapters > .mm-chapter {
  margin-bottom: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  overflow: hidden;
}
.mm-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.mm-toggle:hover { background: rgba(15, 23, 42, 0.04); }
.mm-caret {
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.mm-chapter.is-open > .mm-toggle .mm-caret,
.mm-section.is-open > .mm-toggle .mm-caret { transform: rotate(45deg); }
.mm-level {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
}
.mm-section > .mm-toggle .mm-level {
  background: #ecfdf5;
  color: #047857;
}
.mm-label { font-weight: 600; line-height: 1.35; }
.mm-sections,
.mm-kps {
  list-style: none;
  margin: 0;
  padding: 0 0 0.35rem 0.85rem;
  display: none;
}
.mm-chapter.is-open > .mm-sections,
.mm-section.is-open > .mm-kps { display: block; }
.mm-section {
  margin: 0.15rem 0;
  border-left: 2px solid #bae6fd;
  padding-left: 0.25rem;
}
.mm-kp {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.45rem 0.55rem;
  margin: 0.1rem 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.mm-kp:hover { background: rgba(180, 83, 9, 0.08); }
.mm-kp.is-active {
  background: rgba(180, 83, 9, 0.14);
  box-shadow: inset 3px 0 0 #b45309;
}
.mm-kp-name { font-weight: 500; }
.mm-qcount {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.graph-empty { margin: 1.25rem 0.75rem; }
.graph-empty[hidden] { display: none; }
.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.1rem;
  padding: 0.55rem 1.1rem 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
}
.graph-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.graph-legend span::before {
  content: "";
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 2px;
  background: currentColor;
}
.graph-legend [data-level="chapter"] { color: #0369a1; }
.graph-legend [data-level="section"] { color: #047857; }
.graph-legend [data-level="knowledge_point"] { color: #b45309; }
.graph-detail {
  max-height: min(78vh, 760px);
  overflow: auto;
}
.graph-q-list {
  list-style: none;
  margin: 0.65rem 0 0;
  padding: 0;
}
.graph-q-list li button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.45rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.graph-q-list li button:hover {
  border-color: var(--accent);
  background: #fff;
}
.graph-q-list .qid {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  word-break: break-all;
}
.graph-q-list .hint-link {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.78rem;
  color: var(--accent-deep);
}


.status {
  max-width: 1180px;
  margin: 0 auto 2rem;
  padding: 0 1.25rem;
  color: var(--muted);
  min-height: 1.5rem;
}
.status.error { color: #b91c1c; }

@media (max-width: 900px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .layout,
  .graph-layout {
    grid-template-columns: 1fr;
  }
  .result-list {
    max-height: 240px;
  }
  .graph-tree {
    max-height: 42vh;
  }
  .graph-detail {
    max-height: none;
  }
  .practice-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .pager { justify-content: space-between; }
}

@media (max-width: 520px) {
  .site-nav {
    width: 100%;
    overflow-x: auto;
  }
  .nav-tab {
    flex: 1;
    white-space: nowrap;
    padding: 0.45rem 0.7rem;
    font-size: 0.88rem;
  }
}
