:root {
  --paper: #f5f1e8;
  --paper-raised: #fbf9f4;
  --ink: #162238;
  --muted: #68748a;
  --accent: #1f5eff;
  --accent-soft: #e7edff;
  --line: #d8d1c5;
  --line-strong: #b8b0a3;
  --positive: #14735c;
  --header-height: 72px;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
  scroll-behavior: smooth;
}

* {
  box-sizing: border-box;
}

body {
  background:
    linear-gradient(rgba(22, 34, 56, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(22, 34, 56, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  margin: 0;
}

a {
  color: inherit;
}

.skip-link {
  background: var(--ink);
  color: white;
  left: 14px;
  padding: 10px 14px;
  position: fixed;
  top: -80px;
  z-index: 100;
}

.skip-link:focus {
  top: 10px;
}

.reading-progress {
  background: transparent;
  height: 3px;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 80;
}

.reading-progress span {
  background: var(--accent);
  display: block;
  height: 100%;
  transition: width 100ms linear;
  width: 0;
}

.reader-header {
  align-items: center;
  backdrop-filter: blur(18px);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 300px 1fr auto;
  height: var(--header-height);
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.reader-brand {
  align-items: center;
  display: flex;
  gap: 12px;
  text-decoration: none;
}

.reader-brand > span:first-child {
  align-items: center;
  background: var(--ink);
  border-radius: 10px;
  color: white;
  display: flex;
  font: 500 18px Georgia, serif;
  height: 40px;
  justify-content: center;
  width: 40px;
}

.reader-brand strong,
.reader-brand small {
  display: block;
}

.reader-brand strong {
  font-size: 14px;
  letter-spacing: -0.02em;
}

.reader-brand small {
  color: var(--muted);
  font-size: 10px;
  margin-top: 2px;
  text-transform: uppercase;
}

.reader-header > nav {
  display: flex;
  gap: 30px;
  justify-content: center;
}

.reader-header > nav a {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.reader-header > nav a:hover {
  color: var(--accent);
}

.index-toggle {
  align-items: center;
  background: none;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  display: none;
  font: 700 12px inherit;
  gap: 8px;
}

.index-toggle i,
.index-toggle i::after {
  background: currentColor;
  content: "";
  display: block;
  height: 1px;
  transition: transform 180ms ease;
  width: 16px;
}

.index-toggle i::after {
  transform: translateY(5px);
}

.reader-shell {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(520px, 840px) minmax(170px, 230px);
  justify-content: center;
  min-height: calc(100vh - var(--header-height));
}

.handbook-index {
  align-self: start;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
  padding: 0;
  position: sticky;
  top: var(--header-height);
}

.index-controls {
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  padding: 30px 26px 18px 32px;
}

.index-heading p,
.page-outline > p,
.document-meta span {
  color: var(--accent);
  font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  margin: 0 0 7px;
  text-transform: uppercase;
}

.index-heading strong {
  display: block;
  font: 500 20px/1.25 Georgia, serif;
  margin-bottom: 4px;
}

.index-heading small {
  color: var(--muted);
  display: block;
  font-size: 10px;
  margin-bottom: 17px;
}

.index-search {
  display: block;
}

.index-search span {
  display: none;
}

.index-search input {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  color: var(--ink);
  font: 12px inherit;
  outline: none;
  padding: 9px 2px;
  width: 100%;
}

.index-search input:focus {
  border-color: var(--accent);
}

#chapter-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 20px 30px 32px;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

#chapter-list:focus-visible {
  box-shadow: inset 2px 0 var(--accent);
  outline: none;
}

#chapter-list details {
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  padding: 7px 0 10px;
}

#chapter-list summary {
  align-items: center;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace;
  justify-content: space-between;
  letter-spacing: 0.09em;
  list-style: none;
  padding: 9px 6px 8px 0;
  text-transform: uppercase;
}

#chapter-list summary::-webkit-details-marker {
  display: none;
}

#chapter-list summary::before {
  content: "›";
  font-size: 14px;
  margin-right: 7px;
  transform: rotate(0);
  transition: transform 150ms ease;
}

#chapter-list details[open] summary::before {
  transform: rotate(90deg);
}

#chapter-list summary span {
  background: #e9e4da;
  border-radius: 999px;
  font-size: 8px;
  letter-spacing: 0;
  margin-left: auto;
  padding: 3px 6px;
}

#chapter-list details > div {
  padding-top: 2px;
}

#chapter-list a {
  align-items: center;
  border-left: 2px solid transparent;
  color: var(--muted);
  display: grid;
  font-size: 11px;
  gap: 9px;
  grid-template-columns: 22px 1fr;
  margin-left: -10px;
  padding: 8px 8px;
  text-decoration: none;
  transition:
    background 150ms ease,
    color 150ms ease;
}

#chapter-list a i {
  font: normal 9px ui-monospace, SFMono-Regular, Menlo, monospace;
  opacity: 0.75;
}

#chapter-list a:hover,
#chapter-list a.is-current {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}

.index-actions {
  background: var(--paper-raised);
  border-top: 1px solid var(--line-strong);
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: 1fr 1fr;
  padding: 12px 20px 14px 22px;
}

.index-actions a {
  padding: 7px 9px;
  text-decoration: none;
}

.index-actions a + a {
  border-left: 1px solid var(--line);
}

.index-actions span,
.index-actions i {
  display: block;
}

.index-actions span {
  font-size: 10px;
  font-weight: 800;
}

.index-actions i {
  color: var(--muted);
  font: normal 8px ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-top: 3px;
  text-transform: uppercase;
}

.index-actions a:hover span {
  color: var(--accent);
}

.article-wrap {
  background: color-mix(in srgb, var(--paper-raised) 82%, transparent);
  min-width: 0;
  padding: clamp(48px, 7vw, 96px) clamp(38px, 6vw, 88px) 60px;
}

.document-meta {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  margin-bottom: clamp(36px, 5vw, 64px);
  padding-bottom: 14px;
}

.document-meta span {
  margin: 0;
}

.document-meta a {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-decoration: none;
}

.document-meta a:hover {
  color: var(--accent);
}

.article {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.76;
}

.article > * {
  animation: article-in 420ms both;
}

.article > *:nth-child(n + 2) {
  animation-delay: 35ms;
}

@keyframes article-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.article h1,
.article h2,
.article h3,
.article h4 {
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  scroll-margin-top: calc(var(--header-height) + 26px);
}

.article h1 {
  font-size: clamp(44px, 6vw, 78px);
  font-weight: 650;
  letter-spacing: -0.065em;
  line-height: 0.98;
  margin: 0 0 34px;
  max-width: 760px;
}

.article h1 + p,
.article h1 + blockquote {
  color: var(--muted);
  font-size: 21px;
  line-height: 1.62;
}

.article h2 {
  border-top: 1px solid var(--line-strong);
  font-size: clamp(26px, 3vw, 38px);
  letter-spacing: -0.045em;
  line-height: 1.12;
  margin: 78px 0 22px;
  padding-top: 24px;
}

.article h3 {
  color: var(--accent);
  font-size: 19px;
  letter-spacing: -0.025em;
  margin: 42px 0 15px;
}

.article h4 {
  font-size: 15px;
  margin-top: 30px;
}

.article p {
  margin: 0 0 20px;
}

.article ul,
.article ol {
  margin: 0 0 26px;
  padding-left: 25px;
}

.article li {
  margin-bottom: 9px;
  padding-left: 5px;
}

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

.article strong {
  color: #0f2b58;
}

.article a {
  color: #154dc7;
  text-decoration-color: #9cb4f2;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.article blockquote {
  border-left: 3px solid var(--accent);
  color: #34445f;
  font-size: 19px;
  font-style: italic;
  margin: 34px 0;
  padding: 8px 0 8px 24px;
}

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

.article hr {
  border: 0;
  border-top: 1px solid var(--line-strong);
  margin: 68px 0;
}

.article code {
  background: #ebe6db;
  border-radius: 4px;
  font: 0.82em ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 2px 5px;
}

.article pre {
  background: var(--ink);
  border-radius: 10px;
  color: #edf2ff;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: auto;
  padding: 22px;
}

.article pre code {
  background: none;
  color: inherit;
  padding: 0;
}

.table-scroll {
  border-bottom: 1px solid var(--line-strong);
  margin: 30px 0 38px;
  overflow-x: auto;
}

.article table {
  border-collapse: collapse;
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 12px;
  line-height: 1.5;
  min-width: 560px;
  width: 100%;
}

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

.article th {
  background: #e8e3d9;
  color: #253653;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.article tr:hover td {
  background: color-mix(in srgb, var(--accent-soft) 45%, transparent);
}

.page-outline {
  align-self: start;
  border-left: 1px solid var(--line);
  max-height: calc(100vh - var(--header-height));
  overflow: auto;
  padding: 42px 28px;
  position: sticky;
  top: var(--header-height);
}

#page-outline a,
#page-outline span {
  border-left: 1px solid var(--line);
  color: var(--muted);
  display: block;
  font-size: 10px;
  line-height: 1.45;
  padding: 6px 0 6px 12px;
  text-decoration: none;
}

#page-outline a[data-level="3"] {
  padding-left: 24px;
}

#page-outline a:hover,
#page-outline a.is-current {
  border-color: var(--accent);
  color: var(--ink);
}

.back-to-top {
  color: var(--accent);
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  margin-top: 24px;
  text-decoration: none;
}

.document-pager {
  border-bottom: 1px solid var(--line-strong);
  border-top: 1px solid var(--line-strong);
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 90px;
}

.document-pager a {
  min-height: 100px;
  padding: 24px 0;
  text-decoration: none;
}

.document-pager a + a {
  border-left: 1px solid var(--line);
  padding-left: 28px;
}

.document-pager a.next {
  text-align: right;
}

.document-pager span,
.document-pager strong {
  display: block;
}

.document-pager span {
  color: var(--muted);
  font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.document-pager strong {
  font-size: 13px;
}

.document-pager a:hover strong {
  color: var(--accent);
}

.document-footer {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 10px;
  justify-content: space-between;
  padding-top: 24px;
}

.index-backdrop {
  background: rgba(10, 18, 32, 0.45);
  inset: 0;
  position: fixed;
  z-index: 55;
}

@media (max-width: 1180px) {
  .reader-shell {
    grid-template-columns: minmax(240px, 280px) minmax(0, 820px);
  }

  .page-outline {
    display: none;
  }
}

@media (max-width: 820px) {
  :root {
    --header-height: 66px;
  }

  .reader-header {
    grid-template-columns: 1fr auto;
    padding: 0 18px;
    z-index: 70;
  }

  .reader-header > nav {
    display: none;
  }

  .index-toggle {
    display: flex;
  }

  .reader-shell {
    display: block;
  }

  .handbook-index {
    background: var(--paper-raised);
    bottom: auto;
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    left: 0;
    max-width: 340px;
    overflow: hidden;
    padding: 0;
    position: fixed;
    top: var(--header-height);
    transform: translateX(-105%);
    transition: transform 220ms cubic-bezier(0.2, 0.7, 0.2, 1);
    width: 88vw;
    z-index: 60;
  }

  .index-controls {
    padding: 24px 22px 16px;
  }

  #chapter-list {
    padding: 10px 14px max(24px, env(safe-area-inset-bottom)) 22px;
  }

  #chapter-list a {
    font-size: 12px;
    min-height: 42px;
    padding-block: 10px;
  }

  #chapter-list summary {
    min-height: 42px;
  }

  .index-actions {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .handbook-index.is-open {
    transform: translateX(0);
  }

  .index-toggle[aria-expanded="true"] i {
    transform: rotate(45deg) translateY(2px);
  }

  .index-toggle[aria-expanded="true"] i::after {
    transform: rotate(-90deg);
  }

  body.index-open {
    overflow: hidden;
  }

  .index-backdrop {
    top: var(--header-height);
  }

  .article-wrap {
    padding: 42px 21px 42px;
  }

  .article {
    font-size: 16px;
    line-height: 1.7;
  }

  .article h1 {
    font-size: clamp(39px, 12vw, 56px);
  }

  .article h1 + p,
  .article h1 + blockquote {
    font-size: 18px;
  }

  .article h2 {
    margin-top: 62px;
  }

  .document-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .document-pager {
    grid-template-columns: 1fr;
  }

  .document-pager a + a {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
  }

  .document-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
}

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

  .article > * {
    animation: none;
  }
}

@media print {
  body {
    background: white;
  }

  .reader-header,
  .handbook-index,
  .page-outline,
  .reading-progress,
  .document-pager,
  .document-footer,
  .document-meta {
    display: none;
  }

  .reader-shell {
    display: block;
  }

  .article-wrap {
    background: white;
    padding: 0;
  }

  .article {
    font-size: 11pt;
  }
}
