:root {
  color-scheme: light;
  --bg: #f8f7f4;
  --surface: #ffffff;
  --surface-soft: #efeee9;
  --text: #151515;
  --muted: #686761;
  --line: #d7d4cc;
  --line-strong: #222222;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif: "Times New Roman", "Noto Serif SC", SimSun, serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0d;
  --surface: #171715;
  --surface-soft: #22221f;
  --text: #f1f0eb;
  --muted: #a7a49a;
  --line: #34342f;
  --line-strong: #ece8dd;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.72;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto auto;
  align-items: center;
  gap: 22px;
  padding: 18px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}

.brand {
  max-width: 360px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.top-nav a {
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.top-nav a:hover,
.top-nav a[aria-current="page"] {
  background: var(--text);
  color: var(--bg);
}

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

.icon-button,
.anchor-copy,
.search-row button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-button {
  width: 38px;
  font-size: 18px;
}

.page-shell {
  display: grid;
  grid-template-columns: minmax(180px, 250px) minmax(0, 900px);
  gap: clamp(24px, 5vw, 70px);
  width: min(1240px, calc(100% - 36px));
  margin: 0 auto;
  padding: 54px 0 96px;
}

.page-shell--wide {
  display: block;
  width: min(1120px, calc(100% - 36px));
}

.content {
  min-width: 0;
}

.toc {
  position: sticky;
  top: 92px;
  align-self: start;
  max-height: calc(100vh - 120px);
  overflow: auto;
  padding-right: 10px;
}

.toc-title {
  margin-bottom: 14px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
}

.toc a {
  display: block;
  padding: 8px 0 8px 13px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.toc a:hover,
.toc a[aria-current="true"] {
  border-left-color: var(--line-strong);
  color: var(--text);
}

.hero {
  padding: clamp(64px, 10vw, 128px) 0 44px;
}

.hero h1 {
  max-width: 980px;
  margin: 0;
  font-size: clamp(42px, 7vw, 86px);
  font-weight: 760;
  letter-spacing: 0;
  line-height: 1.02;
  text-wrap: balance;
}

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

.section-card {
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.section-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
  transition: transform 160ms ease, border-color 160ms ease;
}

.section-card span,
.section-card small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.section-card strong {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.2;
  text-wrap: balance;
}

.markdown {
  font-size: 17px;
  overflow-wrap: anywhere;
}

.markdown h1,
.markdown h2,
.markdown h3 {
  letter-spacing: 0;
  line-height: 1.18;
}

.markdown h1 {
  margin: 0 0 28px;
  font-size: clamp(38px, 6vw, 72px);
}

.markdown h2 {
  margin: 0 0 36px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  font-size: clamp(34px, 5vw, 58px);
}

.markdown h3 {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  scroll-margin-top: 104px;
  margin: 58px 0 18px;
  font-size: clamp(22px, 3vw, 34px);
}

.markdown p,
.markdown li {
  color: color-mix(in srgb, var(--text) 86%, var(--muted));
}

.markdown a {
  border-bottom: 1px solid var(--line-strong);
}

.markdown hr {
  margin: 36px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin: 24px 0;
}

.markdown th,
.markdown td {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown th {
  background: var(--surface-soft);
}

.markdown code {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 0.9em;
}

.anchor-copy {
  flex: 0 0 auto;
  padding: 6px 11px;
  color: var(--muted);
  font-size: 12px;
}

.anchor-copy:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.original-intro {
  max-width: 760px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.search-panel[hidden] {
  display: none;
}

.search-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
}

.search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
}

.search-dialog {
  position: relative;
  width: min(720px, calc(100% - 28px));
  margin: 10vh auto 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.search-row input {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.search-row input:focus {
  border-color: var(--line-strong);
}

.search-row button {
  padding: 0 16px;
}

.search-results {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.search-item {
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 4px 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.search-item:hover {
  border-color: var(--line-strong);
}

.search-item span {
  grid-row: span 2;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.search-item strong {
  line-height: 1.25;
}

.search-item small,
.empty-result {
  color: var(--muted);
}

@media (max-width: 980px) {
  .site-header {
    grid-template-columns: 1fr auto;
  }

  .top-nav {
    grid-column: 1 / -1;
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    border-radius: var(--radius);
  }

  .page-shell {
    display: block;
    padding-top: 32px;
  }

  .toc {
    position: relative;
    top: 0;
    display: flex;
    gap: 8px;
    max-height: none;
    margin-bottom: 34px;
    overflow-x: auto;
    padding: 0 0 8px;
  }

  .toc-title {
    display: none;
  }

  .toc a {
    flex: 0 0 min(260px, 72vw);
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
  }

  .home-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .site-header {
    padding: 14px 16px;
  }

  .brand {
    font-size: 13px;
  }

  .home-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    padding-top: 44px;
  }

  .hero h1 {
    font-size: 42px;
  }

  .markdown {
    font-size: 16px;
  }

  .markdown h3 {
    display: block;
  }

  .anchor-copy {
    margin-top: 12px;
  }

  .search-item {
    grid-template-columns: 1fr;
  }

  .markdown table,
  .markdown thead,
  .markdown tbody,
  .markdown tr,
  .markdown th,
  .markdown td {
    display: block;
    width: 100%;
  }

  .markdown table {
    border: 1px solid var(--line);
  }

  .markdown tr + tr {
    border-top: 1px solid var(--line);
  }

  .markdown th,
  .markdown td {
    border-width: 0 0 1px;
  }
}
