:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --paper: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dedb;
  --line-strong: #aeb9b4;
  --teal: #0f766e;
  --teal-soft: #dff3ef;
  --blue: #2563eb;
  --amber: #b45309;
  --rose: #be123c;
  --shadow: 0 18px 50px rgba(18, 32, 26, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  line-height: 1.72;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
}

button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

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

a:hover {
  text-decoration: underline;
}

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

.shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 560px);
  gap: 18px;
  align-items: center;
  padding: 14px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 246, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  min-width: 0;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--teal), #1f2937);
  font-weight: 800;
  letter-spacing: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.term-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 10px;
}

.term-form input {
  min-width: 0;
  height: 42px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  outline: none;
}

.term-form input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.term-form button {
  color: #ffffff;
  border-color: var(--teal);
  background: var(--teal);
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 22px;
  width: min(1580px, 100%);
  margin: 0 auto;
  padding: 22px clamp(16px, 3vw, 36px) 42px;
}

.sidebar {
  position: sticky;
  top: 84px;
  align-self: start;
  max-height: calc(100vh - 104px);
  overflow: auto;
}

.status-panel,
.term-list-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.status-panel {
  padding: 14px;
}

.status-line {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.status-line span {
  color: var(--muted);
  font-size: 13px;
}

.status-line strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.metrics div {
  min-height: 70px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.metrics strong,
.metrics span {
  display: block;
}

.metrics strong {
  font-size: 22px;
  line-height: 1.1;
}

.metrics span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.toc {
  display: grid;
  gap: 6px;
  margin: 14px 0;
}

.toc a {
  display: block;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
}

.toc a:hover {
  border-color: var(--line);
  background: var(--paper);
  text-decoration: none;
}

.term-list-wrap {
  padding: 14px;
}

.side-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.term-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.term-chip {
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 13px;
}

.term-chip.active {
  color: #ffffff;
  border-color: var(--teal);
  background: var(--teal);
}

.content {
  min-width: 0;
}

.message {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.message.error {
  color: #7f1d1d;
  border-color: #fecaca;
  background: #fff7f7;
}

.result {
  display: grid;
  gap: 18px;
}

.result-head,
.section-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.result-head {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.result-head h2 {
  margin: 0;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.15;
  letter-spacing: 0;
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.actions button {
  padding: 0 12px;
}

.section-block {
  overflow: hidden;
}

.section-title {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.section-title h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.section-body {
  display: grid;
  gap: 12px;
  padding: 16px 18px 18px;
}

.source-grid,
.definition-grid,
.origin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.record-box,
.paragraph,
.path-step {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.record-box {
  padding: 13px;
}

.record-box h4,
.paragraph h4,
.path-step h4 {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: 0;
}

.record-box p,
.paragraph p,
.path-step p {
  margin: 0;
}

.record-meta {
  margin-top: 10px;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-links a,
.source-pill {
  display: inline-flex;
  max-width: 100%;
  min-height: 28px;
  align-items: center;
  padding: 3px 8px;
  overflow-wrap: anywhere;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  color: #1d4ed8;
  background: #eef2ff;
  font-size: 12px;
}

.source-links a:hover {
  text-decoration: none;
  border-color: var(--blue);
}

.label-line {
  padding: 12px 14px;
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: var(--teal-soft);
  font-weight: 700;
}

.paragraph {
  padding: 0;
}

.paragraph-main {
  padding: 16px;
}

.paragraph-main h4 {
  color: #111827;
  font-size: 18px;
}

.paragraph-main p {
  font-size: 16px;
}

.paragraph details,
.path-step details {
  border-top: 1px solid var(--line);
}

.paragraph summary,
.path-step summary {
  min-height: 44px;
  padding: 10px 16px;
  color: var(--teal);
  cursor: pointer;
  font-weight: 800;
}

.qa-list {
  display: grid;
  gap: 10px;
  padding: 0 16px 16px;
}

.qa-item {
  padding: 12px;
  border: 1px solid #dbeafe;
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: #f8fbff;
}

.qa-item h5 {
  margin: 0 0 8px;
  color: #1e3a8a;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;
}

.qa-anchor {
  display: inline-flex;
  margin-bottom: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  color: #7c2d12;
  background: #ffedd5;
  font-size: 12px;
}

.path-step {
  padding: 15px;
  border-left: 4px solid var(--amber);
}

.path-step h4 {
  color: #7c2d12;
  font-size: 17px;
}

.path-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.path-cell {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
}

.path-cell strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.path-list {
  display: grid;
  gap: 10px;
  padding: 0 0 4px 18px;
  margin: 8px 0 0;
}

.raw-box {
  width: 100%;
  min-height: 360px;
  padding: 14px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: #111827;
  background: #fbfcfb;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (max-width: 980px) {
  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .toc {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .source-grid,
  .definition-grid,
  .origin-grid,
  .path-grid {
    grid-template-columns: 1fr;
  }

  .result-head {
    display: grid;
  }

  .actions {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 12px;
  }

  .term-form {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 12px 12px 30px;
  }

  .toc {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-title {
    display: grid;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
