:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --surface: #fffdf8;
  --surface-raised: #ffffff;
  --surface-soft: #eeebe3;
  --surface-hover: #e7e2d7;
  --text: #181b22;
  --text-soft: #586070;
  --text-faint: #7c8491;
  --border: #d8d4ca;
  --border-strong: #bbb5a8;
  --accent: #6758d9;
  --accent-bright: #745ff4;
  --accent-soft: rgba(103, 88, 217, 0.12);
  --accent-line: rgba(103, 88, 217, 0.42);
  --code-bg: #eeebe4;
  --code-text: #242733;
  --shadow: 0 20px 80px rgba(45, 40, 31, 0.18);
  --header-bg: rgba(247, 245, 240, 0.9);
  --selection: rgba(103, 88, 217, 0.26);
  --font-sans: "Inter Tight", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Newsreader", Iowan Old Style, Baskerville, Georgia, serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --header-height: 57px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090d15;
  --surface: #0e131e;
  --surface-raised: #121824;
  --surface-soft: #171e2b;
  --surface-hover: #1d2534;
  --text: #e6e9ef;
  --text-soft: #a8b3c7;
  --text-faint: #748096;
  --border: #242a38;
  --border-strong: #374053;
  --accent: #9d8cff;
  --accent-bright: #b1a4ff;
  --accent-soft: rgba(157, 140, 255, 0.13);
  --accent-line: rgba(157, 140, 255, 0.45);
  --code-bg: #111722;
  --code-text: #d8dfeb;
  --shadow: 0 22px 90px rgba(0, 0, 0, 0.55);
  --header-bg: rgba(9, 13, 21, 0.9);
  --selection: rgba(157, 140, 255, 0.28);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 30px);
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body.nav-open {
  overflow: hidden;
}

::selection {
  background: var(--selection);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.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;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 9px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.reading-progress {
  position: fixed;
  z-index: 90;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  pointer-events: none;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #68d7c4);
  transition: width 80ms linear;
}

.site-header {
  position: sticky;
  z-index: 80;
  top: 0;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(18px) saturate(140%);
}

.header-inner {
  display: flex;
  width: 100%;
  max-width: 1600px;
  height: 100%;
  padding: 0 48px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
}

.brand {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.035em;
  text-decoration: none;
}

.brand-dot {
  color: var(--accent);
}

.brand-orbit {
  position: relative;
  display: grid;
  width: 19px;
  height: 19px;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  place-items: center;
  transform: rotate(-22deg);
}

.brand-orbit::before,
.brand-orbit::after {
  position: absolute;
  width: 23px;
  height: 8px;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  content: "";
}

.brand-orbit::after {
  transform: rotate(64deg);
}

.brand-orbit span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-bright);
  box-shadow: 0 0 12px var(--accent);
}

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

.search-trigger {
  display: flex;
  width: min(30vw, 330px);
  height: 34px;
  padding: 0 7px 0 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-faint);
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.search-trigger:hover {
  border-color: var(--border-strong);
  background: var(--surface-raised);
  color: var(--text-soft);
}

.search-trigger > span:nth-child(2) {
  overflow: hidden;
  flex: 1;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-icon {
  position: relative;
  display: inline-block;
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  border: 1.6px solid currentColor;
  border-radius: 50%;
}

.search-icon::after {
  position: absolute;
  right: -4px;
  bottom: -2px;
  width: 5px;
  height: 1.6px;
  border-radius: 2px;
  background: currentColor;
  content: "";
  transform: rotate(45deg);
  transform-origin: left center;
}

kbd {
  font-family: var(--font-sans);
}

.search-trigger kbd {
  display: inline-flex;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--text-faint);
  align-items: center;
  font-size: 11px;
  line-height: 1;
}

.theme-switcher {
  display: flex;
  height: 32px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  align-items: stretch;
}

.theme-switcher button {
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  cursor: pointer;
}

.theme-switcher button:hover {
  color: var(--text);
}

.theme-switcher button[aria-pressed="true"] {
  background: var(--surface-hover);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.source-link {
  display: inline-flex;
  height: 32px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-soft);
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 550;
  text-decoration: none;
}

.source-link:hover {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.knowledge-link {
  display: inline-flex;
  height: 32px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-soft);
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.knowledge-link:hover,
.knowledge-link.active {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.knowledge-icon {
  position: relative;
  width: 13px;
  height: 15px;
  border: 1.5px solid currentColor;
  border-radius: 2px 5px 5px 2px;
}

.knowledge-icon::before {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  border-left: 1px solid currentColor;
  content: "";
  opacity: 0.55;
}

.knowledge-count {
  display: grid;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text-faint);
  place-items: center;
  font-size: 10px;
}

.knowledge-link.has-annotations .knowledge-count {
  background: var(--accent-soft);
  color: var(--accent-bright);
}

.menu-trigger {
  display: none;
  width: 34px;
  height: 34px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
}

.menu-trigger > span:not(.sr-only) {
  display: block;
  width: 100%;
  height: 1px;
  margin: 3px 0;
  background: var(--text-soft);
}

.app-shell {
  display: grid;
  width: 100%;
  max-width: 1600px;
  min-height: calc(100vh - var(--header-height));
  padding: 0 48px;
  margin: 0 auto;
  grid-template-columns: 240px minmax(0, 904px) minmax(170px, 1fr);
  gap: 40px;
}

.curriculum-sidebar {
  position: sticky;
  z-index: 30;
  top: calc(var(--header-height) + 1px);
  display: flex;
  max-height: calc(100vh - var(--header-height) - 1px);
  padding: 45px 0 22px;
  flex-direction: column;
  align-self: start;
}

.sidebar-heading,
.toc-heading {
  display: flex;
  margin-bottom: 14px;
  color: var(--text-faint);
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.sidebar-heading span:last-child {
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-faint);
  letter-spacing: 0;
}

#chapter-navigation {
  overflow: hidden auto;
  padding-right: 9px;
  overscroll-behavior: contain;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
}

.chapter-group {
  border-bottom: 1px solid transparent;
}

.chapter-group summary {
  position: relative;
  display: grid;
  min-height: 34px;
  padding: 7px 24px 7px 0;
  color: var(--text-soft);
  align-items: center;
  cursor: pointer;
  grid-template-columns: 25px 1fr;
  font-size: 13px;
  font-weight: 550;
  list-style: none;
  transition: color 150ms ease;
}

.chapter-group summary::-webkit-details-marker {
  display: none;
}

.chapter-group summary::after {
  position: absolute;
  right: 4px;
  width: 6px;
  height: 6px;
  border-right: 1px solid var(--text-faint);
  border-bottom: 1px solid var(--text-faint);
  content: "";
  transform: rotate(-45deg);
  transition: transform 150ms ease;
}

.chapter-group[open] summary::after {
  transform: rotate(45deg) translateY(-2px);
}

.chapter-group summary:hover,
.chapter-group.has-active summary {
  color: var(--text);
}

.chapter-number {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10px;
}

.chapter-links {
  padding: 0 0 8px 25px;
}

.chapter-link {
  position: relative;
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.35;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease;
}

.chapter-link:hover {
  background: var(--surface-soft);
  color: var(--text-soft);
}

.chapter-link.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 550;
}

.chapter-link.active::before {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: -11px;
  width: 2px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
}

.sidebar-footer {
  display: flex;
  padding-top: 16px;
  margin-top: auto;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.sync-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #61c9a8;
  box-shadow: 0 0 0 3px rgba(97, 201, 168, 0.12);
}

.sidebar-scrim {
  display: none;
}

.reader-main {
  min-width: 0;
  padding: 47px 0 100px;
}

.reader-article {
  width: 100%;
}

.breadcrumbs {
  display: flex;
  min-height: 20px;
  margin-bottom: 12px;
  color: var(--text-faint);
  align-items: center;
  gap: 7px;
  font-size: 12px;
}

.breadcrumbs a {
  color: var(--text-faint);
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--text-soft);
}

.breadcrumbs .separator {
  opacity: 0.52;
}

.article-header {
  padding-bottom: 30px;
  border-bottom: 1px solid var(--border);
}

.article-meta {
  display: flex;
  min-height: 22px;
  margin-bottom: 6px;
  color: var(--text-faint);
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  font-size: 11px;
}

.article-meta .chapter-label {
  display: inline-flex;
  min-width: 23px;
  height: 20px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--accent-bright);
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 650;
}

.article-meta .dot {
  color: var(--border-strong);
}

.article-meta a {
  color: var(--text-faint);
  font-weight: 550;
  text-underline-offset: 3px;
}

.article-meta a:hover {
  color: var(--text);
}

.article-header h1 {
  margin: 0;
  color: var(--text);
  font-family: var(--font-serif);
  font-size: clamp(2.25rem, 3.2vw, 2.5rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.08;
}

.article-deck {
  max-width: 790px;
  margin: 13px 0 0;
  color: var(--text-soft);
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.62;
}

.article-content {
  min-height: 480px;
  padding-top: 37px;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.72;
}

.article-content > :first-child {
  margin-top: 0;
}

.article-content > h1:first-child {
  display: none;
}

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
  position: relative;
  color: var(--text);
  scroll-margin-top: calc(var(--header-height) + 26px);
}

.article-content h2 {
  padding-top: 12px;
  margin: 3.2rem 0 1rem;
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.article-content h2::before {
  display: block;
  width: 34px;
  height: 2px;
  margin-bottom: 17px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), transparent);
  content: "";
}

.article-content h3 {
  margin: 2.3rem 0 0.8rem;
  font-size: 1.28rem;
  font-weight: 650;
  letter-spacing: -0.018em;
  line-height: 1.3;
}

.article-content h4 {
  margin: 1.8rem 0 0.65rem;
  font-size: 1.03rem;
  font-weight: 650;
}

.heading-anchor {
  position: absolute;
  top: 50%;
  right: calc(100% + 10px);
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 0.72em;
  font-weight: 500;
  opacity: 0;
  text-decoration: none;
  transform: translateY(-50%);
  transition: opacity 130ms ease;
}

.article-content :is(h2, h3, h4):hover .heading-anchor,
.heading-anchor:focus {
  opacity: 1;
}

.article-content p {
  margin: 1rem 0;
}

.article-content strong {
  color: var(--text);
  font-weight: 650;
}

.article-content em {
  color: var(--text-soft);
}

.article-content a {
  color: var(--accent-bright);
  text-decoration-color: var(--accent-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.article-content a:hover {
  text-decoration-color: currentColor;
}

.article-content ul,
.article-content ol {
  padding-left: 1.45rem;
  margin: 1rem 0;
}

.article-content li {
  padding-left: 0.25rem;
  margin: 0.36rem 0;
}

.article-content li::marker {
  color: var(--accent);
}

.article-content hr {
  height: 1px;
  margin: 3rem 0;
  border: 0;
  background: var(--border);
}

.article-content blockquote {
  position: relative;
  padding: 0.9rem 1.15rem 0.9rem 1.3rem;
  margin: 1.5rem 0;
  border-left: 2px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: linear-gradient(90deg, var(--accent-soft), transparent 88%);
  color: var(--text-soft);
}

.article-content blockquote > :first-child {
  margin-top: 0;
}

.article-content blockquote > :last-child {
  margin-bottom: 0;
}

.article-content code {
  padding: 0.16em 0.38em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.code-block {
  position: relative;
  margin: 1.45rem 0;
}

.article-content pre {
  overflow: auto;
  padding: 18px 20px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
  white-space: pre;
}

.article-content pre code {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
}

.copy-code {
  position: absolute;
  z-index: 2;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: color-mix(in srgb, var(--code-bg) 86%, transparent);
  color: var(--text-faint);
  font-size: 10px;
  opacity: 0;
  cursor: pointer;
  transition: opacity 130ms ease, color 130ms ease;
}

.code-block:hover .copy-code,
.copy-code:focus {
  opacity: 1;
}

.copy-code:hover {
  color: var(--text);
}

.table-scroll {
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: 9px;
}

.article-content table {
  width: 100%;
  min-width: 580px;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.5;
}

.article-content th,
.article-content td {
  padding: 10px 13px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.article-content th:last-child,
.article-content td:last-child {
  border-right: 0;
}

.article-content tr:last-child td {
  border-bottom: 0;
}

.article-content th {
  background: var(--surface-soft);
  color: var(--text);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

.article-content tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface-soft) 38%, transparent);
}

.article-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.article-content .mermaid {
  overflow: auto;
  padding: 20px;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  text-align: center;
}

.article-content .mermaid svg {
  max-width: 100%;
  height: auto;
}

.pagination {
  display: grid;
  padding-top: 38px;
  margin-top: 58px;
  border-top: 1px solid var(--border);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.pagination-link {
  display: flex;
  min-height: 102px;
  padding: 15px 17px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  flex-direction: column;
  text-decoration: none;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.pagination-link:hover {
  border-color: var(--border-strong);
  background: var(--surface-raised);
  transform: translateY(-1px);
}

.pagination-link.next {
  text-align: right;
}

.pagination-direction {
  margin-bottom: 5px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.pagination-title {
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.25;
}

.pagination-section {
  margin-top: auto;
  color: var(--text-faint);
  font-size: 11px;
}

.toc-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 1px);
  max-height: calc(100vh - var(--header-height) - 1px);
  padding: 45px 0 25px;
  align-self: start;
}

#table-of-contents {
  overflow: auto;
  max-height: calc(100vh - 190px);
  padding: 1px 8px 1px 0;
  border-left: 1px solid var(--border);
  scrollbar-width: thin;
}

.toc-link {
  position: relative;
  display: block;
  padding: 4px 0 4px 14px;
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.4;
  text-decoration: none;
  transition: color 120ms ease;
}

.toc-link[data-level="3"] {
  padding-left: 25px;
}

.toc-link:hover,
.toc-link.active {
  color: var(--text);
}

.toc-link.active::before {
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: -1px;
  width: 2px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
}

.back-to-top {
  display: inline-flex;
  margin-top: 17px;
  color: var(--text-faint);
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-decoration: none;
}

.back-to-top:hover {
  color: var(--text);
}

.search-dialog {
  width: min(680px, calc(100vw - 32px));
  max-width: none;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  background: transparent;
  color: var(--text);
  box-shadow: var(--shadow);
}

.search-dialog::backdrop {
  background: rgba(2, 5, 11, 0.67);
  backdrop-filter: blur(5px);
}

.search-panel {
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface-raised);
}

.search-input-row {
  display: flex;
  height: 60px;
  padding: 0 14px 0 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
  align-items: center;
  gap: 13px;
}

.search-input-row .search-icon {
  width: 16px;
  height: 16px;
}

.search-input-row input {
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  flex: 1;
  font-size: 16px;
}

.search-input-row input::placeholder {
  color: var(--text-faint);
}

.search-input-row input::-webkit-search-cancel-button {
  display: none;
}

#search-close {
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--text-faint);
  font-size: 10px;
  cursor: pointer;
}

.search-results {
  overflow: auto;
  min-height: 240px;
  max-height: min(58vh, 520px);
  padding: 8px;
}

.search-result {
  display: grid;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: inherit;
  grid-template-columns: 29px minmax(0, 1fr) auto;
  gap: 10px;
  text-decoration: none;
}

.search-result:hover,
.search-result.is-selected {
  border-color: var(--border);
  background: var(--surface-soft);
}

.result-number {
  display: grid;
  width: 27px;
  height: 27px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-faint);
  place-items: center;
  font-family: var(--font-mono);
  font-size: 9px;
}

.result-copy {
  min-width: 0;
}

.result-title {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-excerpt {
  overflow: hidden;
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-section {
  color: var(--text-faint);
  align-self: center;
  font-size: 10px;
}

.search-empty {
  display: grid;
  min-height: 230px;
  color: var(--text-faint);
  place-items: center;
  text-align: center;
}

.search-empty strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-soft);
  font-size: 14px;
}

.search-footer {
  display: flex;
  min-height: 37px;
  padding: 0 15px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  align-items: center;
  gap: 17px;
  font-size: 10px;
}

.search-footer span:last-child {
  margin-left: auto;
}

.search-footer kbd {
  display: inline-grid;
  min-width: 17px;
  height: 17px;
  padding: 0 3px;
  margin-right: 2px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface-soft);
  place-items: center;
  font-size: 9px;
}

.selection-toolbar {
  position: fixed;
  z-index: 145;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-raised);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.24);
}

.selection-toolbar[hidden] {
  display: none;
}

.selection-toolbar button {
  display: inline-flex;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.annotation-mark {
  padding: 0 1px;
  border-bottom: 1.5px dotted var(--accent-bright);
  background: linear-gradient(180deg, transparent 66%, var(--accent-soft) 66%);
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.annotation-mark:hover,
.annotation-mark:focus-visible {
  border-bottom-style: solid;
  background: var(--accent-soft);
  outline: none;
}

.annotation-action {
  display: inline-grid;
  width: 14px;
  height: 14px;
  margin-left: 3px;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--accent-bright);
  place-items: center;
  vertical-align: 0.08em;
}

.annotation-action::before {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  content: "i";
}

.knowledge-dialog,
.unlock-dialog {
  width: min(720px, calc(100vw - 28px));
  max-height: min(88vh, 880px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow);
}

.unlock-dialog {
  width: min(430px, calc(100vw - 28px));
}

.knowledge-dialog::backdrop,
.unlock-dialog::backdrop {
  background: rgba(3, 6, 12, 0.68);
  backdrop-filter: blur(5px);
}

.knowledge-panel {
  max-height: inherit;
  overflow: auto;
}

.knowledge-panel-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-raised) 94%, transparent);
  backdrop-filter: blur(14px);
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.knowledge-eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--accent-bright);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.knowledge-panel-header h2,
.unlock-panel h2 {
  padding: 0;
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.8rem;
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.dialog-close {
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-faint);
  place-items: center;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.dialog-close:hover {
  color: var(--text);
}

.annotation-form,
.annotation-view {
  padding: 24px;
}

.phrase-preview {
  padding: 14px 16px;
  margin-bottom: 20px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--accent-soft);
}

.phrase-preview > span {
  display: block;
  margin-bottom: 4px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.phrase-preview strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.28rem;
  font-weight: 500;
  line-height: 1.3;
}

.phrase-preview small {
  display: block;
  margin-top: 5px;
  color: var(--text-soft);
  font-size: 11px;
}

.field-group {
  display: grid;
  margin-bottom: 17px;
  gap: 7px;
}

.field-group > span {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 650;
}

.field-group em,
.field-group small {
  margin-left: 5px;
  color: var(--text-faint);
  font-size: 10px;
  font-style: normal;
  font-weight: 500;
}

.field-group input,
.field-group textarea,
.knowledge-toolbar input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.field-group input,
.knowledge-toolbar input {
  height: 40px;
  padding: 0 12px;
}

.field-group textarea {
  min-height: 76px;
  padding: 10px 12px;
  line-height: 1.48;
  resize: vertical;
}

.field-group input:focus,
.field-group textarea:focus,
.knowledge-toolbar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-group .code-input {
  font-family: var(--font-mono);
  font-size: 12px;
}

.annotation-form-actions,
.annotation-view-actions {
  display: flex;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
}

.button-primary,
.button-secondary {
  display: inline-flex;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.button-primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.button-primary:hover {
  background: var(--accent-bright);
}

.button-secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
}

.button-secondary:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.button-secondary.danger {
  margin-right: auto;
  color: #d65e6c;
}

.button-primary:disabled,
.button-secondary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.full-width {
  width: 100%;
}

.annotation-definition {
  padding: 2px 0 18px;
  font-family: var(--font-serif);
  font-size: 1.42rem;
  line-height: 1.45;
}

.annotation-definition p {
  margin: 0;
}

.prose-compact {
  padding: 16px 18px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.65;
}

.prose-compact > :first-child {
  margin-top: 0;
}

.prose-compact > :last-child {
  margin-bottom: 0;
}

.annotation-diagram {
  padding: 18px;
  margin-bottom: 18px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 12px;
  text-align: center;
}

.annotation-diagram svg {
  max-width: 100%;
  height: auto;
}

.annotation-references {
  display: grid;
  margin-bottom: 15px;
  gap: 7px;
}

.annotation-references h3 {
  margin: 0 0 3px;
  font-size: 12px;
}

.annotation-references a {
  color: var(--accent-bright);
  font-size: 13px;
  text-underline-offset: 3px;
}

.annotation-references a::after {
  content: " ↗";
}

.annotation-tags,
.knowledge-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.annotation-tags {
  margin-bottom: 18px;
}

.annotation-tags span,
.knowledge-card-tags span {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text-soft);
  font-size: 10px;
}

.annotation-source {
  display: inline-flex;
  margin-bottom: 20px;
  color: var(--accent-bright);
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
}

.unlock-panel {
  position: relative;
  padding: 28px;
}

.unlock-panel .dialog-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.unlock-panel > p:not(.form-error) {
  margin: 10px 0 22px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.55;
}

.remember-choice {
  display: flex;
  margin: -2px 0 17px;
  color: var(--text-soft);
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.remember-choice input {
  accent-color: var(--accent);
}

.form-error {
  min-height: 18px;
  margin: 0 0 10px;
  color: #d65e6c;
  font-size: 11px;
}

.knowledge-index {
  padding-top: 30px;
}

.knowledge-toolbar {
  display: grid;
  padding: 14px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
}

.knowledge-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.knowledge-toolbar-actions button {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 650;
  cursor: pointer;
}

.knowledge-toolbar-actions button:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.knowledge-grid {
  display: grid;
  gap: 10px;
}

.knowledge-card {
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  transition: border-color 150ms ease, transform 150ms ease, background 150ms ease;
}

.knowledge-card:hover {
  border-color: var(--accent-line);
  background: var(--surface-raised);
  transform: translateY(-1px);
}

.knowledge-card-main {
  display: block;
  width: 100%;
  padding: 17px 18px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.knowledge-card h3 {
  padding: 0;
  margin: 0 0 5px;
  font-family: var(--font-serif);
  font-size: 1.24rem;
  font-weight: 550;
  letter-spacing: -0.018em;
}

.knowledge-card h3::before {
  display: none;
}

.knowledge-card p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.knowledge-card-meta {
  display: flex;
  margin-top: 12px;
  color: var(--text-faint);
  justify-content: space-between;
  gap: 12px;
  font-size: 10px;
}

.knowledge-card-tags {
  padding: 0 18px 14px;
}

.knowledge-empty,
.knowledge-locked {
  padding: 52px 30px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
}

.knowledge-empty strong,
.knowledge-locked h2 {
  display: block;
  padding: 0;
  margin: 0 0 7px;
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 500;
}

.knowledge-locked h2::before {
  display: none;
}

.knowledge-empty p,
.knowledge-locked p {
  max-width: 470px;
  margin: 0 auto 18px;
  color: var(--text-soft);
  font-size: 13px;
}

.knowledge-lock-icon {
  display: block;
  width: 26px;
  height: 22px;
  margin: 0 auto 15px;
  border: 2px solid var(--accent-line);
  border-radius: 5px;
}

.knowledge-lock-icon::before {
  display: block;
  width: 13px;
  height: 11px;
  margin: -12px auto 0;
  border: 2px solid var(--accent-line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  content: "";
}

.toast {
  position: fixed;
  z-index: 120;
  right: 18px;
  bottom: 18px;
  padding: 9px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface-raised);
  color: var(--text-soft);
  box-shadow: var(--shadow);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.skeleton-line,
.skeleton-pill,
.content-skeleton span,
.sidebar-skeleton span {
  display: block;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--surface-soft) 25%, var(--surface-hover) 50%, var(--surface-soft) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.7s infinite linear;
}

.skeleton-line {
  width: 100%;
  height: 13px;
  margin: 8px 0;
}

.skeleton-line.short {
  width: 160px;
  height: 10px;
}

.skeleton-line.title {
  width: 74%;
  height: 44px;
}

.skeleton-line.medium {
  width: 61%;
}

.skeleton-pill {
  width: 56px;
  height: 17px;
}

.content-skeleton {
  display: grid;
  gap: 16px;
}

.content-skeleton span {
  height: 13px;
}

.content-skeleton span:nth-child(2),
.content-skeleton span:nth-child(5) {
  width: 88%;
}

.content-skeleton span:nth-child(3) {
  width: 68%;
}

.content-skeleton span:nth-child(4) {
  width: 94%;
  height: 30px;
  margin-top: 23px;
}

.sidebar-skeleton {
  display: grid;
  gap: 16px;
}

.sidebar-skeleton span {
  height: 11px;
}

.sidebar-skeleton span:nth-child(even) {
  width: 78%;
}

.article-error {
  padding: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: center;
}

.article-error h2 {
  padding: 0;
  margin: 0 0 8px;
}

.article-error h2::before {
  display: none;
}

@keyframes skeleton {
  to { background-position: -200% 0; }
}

@media (max-width: 1399px) {
  .app-shell {
    max-width: 1280px;
    grid-template-columns: 240px minmax(0, 904px);
  }

  .toc-sidebar {
    display: none;
  }
}

@media (max-width: 1040px) {
  .header-inner {
    padding: 0 24px;
  }

  .theme-switcher,
  .source-link {
    display: none;
  }

  .search-trigger {
    width: min(48vw, 340px);
  }

  .menu-trigger {
    display: block;
  }

  .app-shell {
    display: block;
    padding: 0 24px;
  }

  .curriculum-sidebar {
    position: fixed;
    z-index: 75;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    width: min(320px, calc(100vw - 48px));
    max-height: none;
    padding: 28px 22px 22px;
    border-right: 1px solid var(--border);
    background: var(--bg);
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  body.nav-open .curriculum-sidebar {
    transform: translateX(0);
  }

  .sidebar-scrim {
    position: fixed;
    z-index: 70;
    inset: var(--header-height) 0 0;
    display: block;
    border: 0;
    background: rgba(1, 4, 10, 0.58);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  body.nav-open .sidebar-scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .reader-main {
    max-width: 904px;
    padding-top: 38px;
    margin: 0 auto;
  }
}

@media (max-width: 680px) {
  :root {
    --header-height: 54px;
  }

  .header-inner {
    padding: 0 16px;
  }

  .brand {
    font-size: 16px;
  }

  .brand-orbit {
    width: 17px;
    height: 17px;
  }

  .search-trigger {
    width: 35px;
    padding: 0;
    justify-content: center;
  }

  .search-trigger > span:nth-child(2),
  .search-trigger kbd {
    display: none;
  }

  .header-actions {
    gap: 8px;
  }

  .knowledge-link {
    padding: 0 7px;
  }

  .knowledge-link > span:nth-child(2) {
    display: none;
  }

  .app-shell {
    padding: 0 17px;
  }

  .reader-main {
    padding: 28px 0 70px;
  }

  .breadcrumbs {
    margin-bottom: 15px;
  }

  .article-header {
    padding-bottom: 24px;
  }

  .article-header h1 {
    font-size: 2.24rem;
  }

  .article-deck {
    font-size: 17px;
    line-height: 1.55;
  }

  .article-content {
    padding-top: 29px;
    font-size: 15.5px;
  }

  .article-content h2 {
    margin-top: 2.7rem;
    font-size: 1.73rem;
  }

  .article-content h3 {
    font-size: 1.18rem;
  }

  .heading-anchor {
    display: none;
  }

  .article-content pre {
    padding: 16px;
    font-size: 12px;
  }

  .copy-code {
    opacity: 1;
  }

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

  .pagination-link.next {
    text-align: left;
  }

  .search-dialog {
    width: calc(100vw - 18px);
  }

  .search-input-row {
    height: 55px;
    padding-left: 16px;
  }

  .search-results {
    max-height: 64vh;
  }

  .result-section,
  .search-footer span:last-child {
    display: none;
  }

  .search-result {
    grid-template-columns: 29px minmax(0, 1fr);
  }

  .knowledge-panel-header,
  .annotation-form,
  .annotation-view {
    padding-right: 17px;
    padding-left: 17px;
  }

  .knowledge-toolbar {
    grid-template-columns: 1fr;
  }

  .knowledge-toolbar-actions {
    flex-wrap: wrap;
  }

  .knowledge-toolbar-actions button {
    flex: 1 1 auto;
  }

  .knowledge-card-main {
    padding-right: 15px;
    padding-left: 15px;
  }

  .knowledge-card-tags {
    padding-right: 15px;
    padding-left: 15px;
  }

  .annotation-view-actions,
  .annotation-form-actions {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .site-header,
  .curriculum-sidebar,
  .toc-sidebar,
  .reading-progress,
  .pagination,
  .selection-toolbar,
  .knowledge-dialog,
  .unlock-dialog,
  .toast {
    display: none !important;
  }

  body {
    background: #fff;
    color: #111;
  }

  .app-shell {
    display: block;
    max-width: 760px;
    padding: 0;
    margin: 0 auto;
  }

  .reader-main {
    padding: 0;
  }

  .article-content a {
    color: inherit;
  }
}
