:root {
  --bg: #f7f7f5;
  --paper: #ffffff;
  --text: #202124;
  --muted: #666b73;
  --line: #e7e7e3;
  --soft: #f1f1ee;
  --accent: #2d5bff;
  --code: #f4f4f2;
  --quote: #f5f7ff;
  --shadow: 0 10px 30px rgb(0 0 0 / 6%);
  --reader-scale: 1;
}
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: calc(16px * var(--reader-scale));
  line-height: 1.68;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
}

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

.brand {
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-decoration: none;
}

.document-shell {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 28px 20px 24px 24px;
  border-right: 1px solid var(--line);
  background: rgb(247 247 245 / 92%);
  backdrop-filter: blur(12px);
}

.sidebar-label {
  margin: 14px 0 18px;
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.4;
  text-transform: uppercase;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar nav a {
  padding: 7px 9px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
  text-decoration: none;
}

.sidebar nav a:hover {
  background: var(--soft);
  color: var(--text);
}

.sidebar nav .toc-level-3 {
  padding-left: 22px;
  font-size: 0.82rem;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 28px;
  padding: 18px 9px 0;
  border-top: 1px solid var(--line);
}

.sidebar-footer a {
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
}

.sidebar-footer a:hover {
  color: var(--text);
}

.document-main {
  min-width: 0;
  padding: 42px 32px 72px;
}

.document-article {
  max-width: 860px;
  margin: 0 auto;
  padding: 64px 72px 84px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.document-article > h1:first-of-type {
  max-width: 16ch;
  margin: 0 0 34px;
  font-size: clamp(2.25rem, 5vw, 4rem);
  font-weight: 780;
  letter-spacing: -0.045em;
  line-height: 1.02;
}

.document-article h2 {
  margin: 3.1rem 0 1rem;
  padding-top: 0.25rem;
  font-size: 1.72rem;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.document-article h3 {
  margin: 2.2rem 0 0.8rem;
  font-size: 1.18rem;
  line-height: 1.3;
}

.document-article h1,
.document-article h2,
.document-article h3 {
  scroll-margin-top: 28px;
}

.document-article p {
  margin: 0.85rem 0 1.05rem;
}

.document-article strong {
  font-weight: 720;
}

.document-article ul,
.document-article ol {
  padding-left: 1.4rem;
}

.document-article li {
  margin: 0.34rem 0;
}

.document-article blockquote {
  margin: 1.6rem 0;
  padding: 1rem 1.2rem;
  border-left: 4px solid var(--accent);
  border-radius: 0 12px 12px 0;
  background: var(--quote);
  font-size: 1.03rem;
}

.document-article blockquote p {
  margin: 0;
}

.document-article pre {
  overflow: auto;
  margin: 1.4rem 0;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--code);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 40%);
  font-size: 0.9rem;
  line-height: 1.55;
}

.document-article code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.document-article p code,
.document-article li code {
  padding: 0.12rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--code);
  font-size: 0.9em;
}

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

.document-article table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 0.94rem;
}

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

.document-article th {
  background: var(--soft);
  font-weight: 700;
}

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

.document-article hr {
  margin: 3rem 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.reader-settings {
  position: relative;
  display: inline-flex;
}

.font-menu-toggle,
.font-popover button {
  min-width: 36px;
  height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  line-height: 1;
  touch-action: manipulation;
}

.font-menu-toggle {
  min-width: 42px;
}

.font-menu-toggle:active,
.font-popover button:active {
  transform: translateY(1px);
}

.font-popover {
  position: absolute;
  z-index: 40;
  top: calc(100% + 8px);
  right: 0;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 10px 28px rgb(0 0 0 / 14%);
  white-space: nowrap;
}

.font-popover.open {
  display: flex;
}

.font-value {
  min-width: 48px;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.desktop-tools {
  display: flex;
  justify-content: flex-end;
  margin: -24px 0 22px;
}

.mobile-top {
  display: none;
}

.document-footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

.document-footer p {
  margin: 0;
}

.portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1160px;
  margin: 0 auto;
  padding: 32px 28px;
}

.portal-header > a:last-child {
  color: var(--muted);
  font-size: 0.88rem;
  text-decoration: none;
}

.portal-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 11vh 28px 96px;
}

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

.eyebrow--brand {
  color: var(--text);
  font-weight: 800;
  text-transform: none;
}

.portal-main > h1,
.error-main h1 {
  max-width: 10ch;
  margin: 0;
  font-size: clamp(3.5rem, 10vw, 7rem);
  letter-spacing: -0.055em;
  line-height: 0.95;
}

.portal-intro {
  max-width: 650px;
  margin: 34px 0 72px;
  color: var(--muted);
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  line-height: 1.5;
}

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

.publication-card {
  padding: 40px 0 44px;
  border-bottom: 1px solid var(--line);
}

.publication-card h2 {
  margin: 0 0 12px;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  letter-spacing: -0.035em;
  line-height: 1.12;
}

.publication-card h2 a {
  text-decoration: none;
}

.publication-card h2 a:hover,
.read-link:hover {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.publication-card > p:not(.eyebrow) {
  max-width: 680px;
  color: var(--muted);
}

.read-link {
  display: inline-block;
  margin-top: 10px;
  font-weight: 700;
  text-decoration: none;
}

.error-page {
  min-height: 100vh;
}

.error-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 20vh 28px 80px;
}

.error-main > p:not(.eyebrow) {
  max-width: 560px;
  margin: 28px 0;
  color: var(--muted);
  font-size: 1.15rem;
}

@media (max-width: 980px) {
  .document-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .document-main {
    padding: 0;
  }

  .document-article {
    min-height: 100vh;
    max-width: none;
    padding: 34px 22px 60px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .mobile-top {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: rgb(247 247 245 / 94%);
    backdrop-filter: blur(12px);
  }

  .mobile-brand {
    font-weight: 800;
    letter-spacing: 0.08em;
  }

  .mobile-actions {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .mobile-top a,
  .mobile-toc summary {
    color: var(--muted);
    font-size: 0.88rem;
    text-decoration: none;
  }

  .mobile-toc summary {
    display: flex;
    min-height: 44px;
    align-items: center;
    padding: 0 4px;
    cursor: pointer;
    list-style: none;
    touch-action: manipulation;
    user-select: none;
  }

  .mobile-toc summary::-webkit-details-marker {
    display: none;
  }

  .mobile-toc[open] summary {
    color: var(--text);
  }

  .mobile-toc nav {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    display: flex;
    max-height: calc(100vh - 100%);
    max-height: calc(100dvh - 100%);
    flex-direction: column;
    gap: 2px;
    overflow: auto;
    padding: 12px 14px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
    box-shadow: 0 14px 28px rgb(0 0 0 / 12%);
    overscroll-behavior: contain;
  }

  .mobile-toc nav a {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--muted);
    line-height: 1.35;
  }

  .mobile-toc nav a:hover,
  .mobile-toc nav a:focus-visible {
    background: var(--soft);
    color: var(--text);
  }

  .mobile-toc nav .toc-level-3 {
    padding-left: 28px;
    font-size: 0.82rem;
  }

  .document-article > h1:first-of-type {
    margin-top: 14px;
  }

  .desktop-tools {
    display: none;
  }
}

@media (max-width: 560px) {
  .document-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .portal-main {
    padding-top: 9vh;
  }

  .portal-intro {
    margin-bottom: 50px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --paper: #1d1d1f;
    --text: #f1f1f1;
    --muted: #a7a7ab;
    --line: #323236;
    --soft: #252528;
    --accent: #8aa2ff;
    --code: #242427;
    --quote: #20253a;
    --shadow: none;
  }

  .sidebar {
    background: rgb(21 21 21 / 92%);
  }

  .mobile-top {
    background: rgb(21 21 21 / 94%);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

@media print {
  body {
    background: #ffffff;
    color: #000000;
    font-size: 16px;
  }

  .sidebar,
  .mobile-top,
  .desktop-tools,
  .document-footer {
    display: none !important;
  }

  .document-shell {
    display: block;
  }

  .document-main {
    padding: 0;
  }

  .document-article {
    max-width: none;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .document-article a {
    color: inherit;
    text-decoration: none;
  }

  .document-article pre,
  .document-article blockquote,
  .table-wrap {
    break-inside: avoid;
  }

  .document-article h2,
  .document-article h3 {
    break-after: avoid;
  }
}
