@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Instrument+Serif:ital@0;1&display=swap");

:root {
  --background: #faf6f0;
  --background-elevated: #ffffffd9;
  --background-soft: #ffffff8c;
  --foreground: #171513;
  --foreground-muted: #171513b3;
  --foreground-faint: #17151380;
  --line: #1715131f;
  --line-strong: #17151338;
  --accent: #d06e58;
  --accent-strong: #b55640;
  --code-bg: #1a1612;
  --code-text: #f5f1ea;
  --inline-code-bg: #1715130d;
  --shadow-soft: 0 18px 60px #1f181214;
  --radius-xl: 28px;
  --radius-lg: 18px;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--foreground);
  background:
    radial-gradient(circle at top left, #d6795f14, transparent 34%),
    radial-gradient(circle at top right, #503e2a0a, transparent 28%),
    linear-gradient(180deg, #fdfaf5 0%, var(--background) 100%);
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.62;
}

a {
  color: var(--accent-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

/* ----- Header ----- */

.site-header {
  position: relative;
  z-index: 50;
  width: min(1280px, 100% - 32px);
  margin: 0 auto;
  padding: 24px 0 12px;
}

.site-header__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--foreground);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-decoration: none;
  text-transform: uppercase;
}

.site-title::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 0 0 4px #d06e5824;
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--background-soft);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.nav-toggle:hover {
  background: var(--background-elevated);
  border-color: var(--foreground-faint);
}

.nav-toggle__bar {
  position: absolute;
  width: 18px;
  height: 1.5px;
  background: var(--foreground);
  transition: transform 0.22s, opacity 0.18s;
}

.nav-toggle__bar:nth-child(1) { transform: translateY(-6px); }
.nav-toggle__bar:nth-child(2) { transform: translateY(0); }
.nav-toggle__bar:nth-child(3) { transform: translateY(6px); }

body.nav-open .nav-toggle__bar:nth-child(1) { transform: rotate(45deg); }
body.nav-open .nav-toggle__bar:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle__bar:nth-child(3) { transform: rotate(-45deg); }

.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #1715135e;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
}

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

body.nav-open {
  overflow: hidden;
}

/* ----- Layout ----- */

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 240px) minmax(0, 1fr);
  gap: 44px;
  width: min(1280px, 100% - 32px);
  margin: 0 auto;
  padding: 24px 0 96px;
}

.layout--with-toc {
  grid-template-columns: minmax(220px, 240px) minmax(0, 1fr) minmax(180px, 220px);
}

/* ----- Sidebar nav ----- */

.site-nav {
  align-self: start;
  padding: 6px 4px 24px;
  font-size: 14px;
}

.site-nav ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.site-nav > ul > li > span {
  display: block;
  margin-top: 22px;
  margin-bottom: 6px;
  padding: 0 10px;
  color: var(--foreground-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.site-nav > ul > li:first-child > span {
  margin-top: 0;
}

.site-nav ul ul {
  padding-left: 0;
}

.site-nav li {
  margin: 2px 0;
}

.site-nav a {
  display: block;
  padding: 7px 10px;
  border-radius: 10px;
  color: var(--foreground-muted);
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s, background-color 0.15s;
}

.site-nav a:hover {
  color: var(--foreground);
  background: var(--background-soft);
}

.site-nav .active > a {
  color: var(--foreground);
  font-weight: 600;
  background: var(--background-elevated);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* ----- Content ----- */

.content {
  min-width: 0;
  max-width: 760px;
  padding-bottom: 12vh;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.content h1,
.content h2,
.content h3,
.content h4 {
  line-height: 1.12;
  letter-spacing: -0.02em;
}

.content > h1:first-child {
  margin-top: 8px;
  margin-bottom: 28px;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(2.6rem, 5vw, 4rem);
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1;
}

.content h2 {
  margin-top: 56px;
  margin-bottom: 14px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.85rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.content h3 {
  margin-top: 32px;
  margin-bottom: 8px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0;
}

.content p,
.content li {
  font-size: 1rem;
  color: var(--foreground);
}

.content > p:first-of-type {
  color: var(--foreground-muted);
  font-size: 1.12rem;
  line-height: 1.7;
}

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

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

.content code {
  padding: 0.08em 0.3em;
  border-radius: 4px;
  background: var(--inline-code-bg);
  color: var(--foreground);
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.content .highlight,
.content pre {
  position: relative;
  margin: 18px 0;
}

.content .highlight pre,
.content pre {
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0;
  padding: 18px 20px;
  border: 1px solid #00000040;
  border-radius: 12px;
  background: var(--code-bg);
  box-shadow: var(--shadow-soft);
  scrollbar-width: thin;
  scrollbar-color: #ffffff33 transparent;
}

.content .highlight pre::-webkit-scrollbar,
.content pre::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.content .highlight pre::-webkit-scrollbar-track,
.content pre::-webkit-scrollbar-track {
  background: transparent;
}

.content .highlight pre::-webkit-scrollbar-thumb,
.content pre::-webkit-scrollbar-thumb {
  background: #ffffff26;
  border-radius: 999px;
}

.content .highlight pre::-webkit-scrollbar-thumb:hover,
.content pre::-webkit-scrollbar-thumb:hover {
  background: #ffffff52;
}

.content .highlight {
  border-radius: 12px;
}

.content .highlight pre {
  border-radius: 12px;
}

.content pre code {
  padding: 0;
  background: transparent;
  color: var(--code-text);
  font-size: 0.92rem;
  line-height: 1.6;
}

/* ----- Pygments token palette (warm dark) ----- */

.highlight .c, .highlight .ch, .highlight .cm, .highlight .cp, .highlight .cpf,
.highlight .c1, .highlight .cs { color: #8a8275; font-style: italic; }    /* comments */
.highlight .err              { color: #e57373; }                          /* error */
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn,
.highlight .kp, .highlight .kr, .highlight .kt { color: #e8a060; }        /* keyword */
.highlight .l, .highlight .ld, .highlight .m, .highlight .mb, .highlight .mf,
.highlight .mh, .highlight .mi, .highlight .il, .highlight .mo            { color: #c099e0; } /* literals/numbers */
.highlight .s, .highlight .sa, .highlight .sb, .highlight .sc, .highlight .dl,
.highlight .sd, .highlight .s2, .highlight .se, .highlight .sh, .highlight .si,
.highlight .sx, .highlight .sr, .highlight .s1, .highlight .ss            { color: #b9d394; } /* strings */
.highlight .n                { color: #f1ece2; }                          /* name (default) */
.highlight .na               { color: #7ec3d8; }                          /* attribute */
.highlight .nb, .highlight .bp { color: #f0b86e; }                        /* builtin */
.highlight .nc, .highlight .ne, .highlight .nf, .highlight .nl,
.highlight .nn, .highlight .nx { color: #7ec3d8; }                        /* class/function/namespace */
.highlight .nt               { color: #e8a060; }                          /* tag (json keys) */
.highlight .nv, .highlight .vc, .highlight .vg, .highlight .vi, .highlight .vm { color: #d6cfc2; }
.highlight .o, .highlight .ow { color: #d6cfc2; }                         /* operator */
.highlight .p                { color: #cfc6b6; }                          /* punctuation */
.highlight .w                { color: inherit; }                          /* whitespace */
.highlight .gp               { color: #d06e58; font-weight: 600; }        /* prompt */
.highlight .go               { color: #b8b1a3; }                          /* output */
.highlight .gd               { color: #e57373; }                          /* deleted */
.highlight .gi               { color: #b9d394; }                          /* inserted */
.highlight .gs               { font-weight: 600; }
.highlight .ge               { font-style: italic; }

/* ----- Copy button ----- */

.code-block {
  position: relative;
}

.copy-button {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 5px 10px;
  border: 1px solid #ffffff1f;
  border-radius: 7px;
  background: #ffffff0d;
  color: #d6cfc2;
  font: 600 11px/1 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background-color 0.15s, border-color 0.15s;
}

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

.copy-button:hover {
  color: #fff;
  background: #ffffff14;
  border-color: #ffffff33;
}

.copy-button.is-copied {
  color: #b9d394;
  border-color: #b9d39433;
  background: #b9d3940f;
  opacity: 1;
}

.copy-button.is-failed {
  color: #e57373;
  border-color: #e5737333;
  background: #e573730f;
  opacity: 1;
}

/* ----- Per-line copy (bash) ----- */

.code-line {
  display: block;
  position: relative;
  padding-right: 28px;
}

.code-line--blank {
  min-height: 1.6em;
}

.code-line__copy {
  position: absolute;
  top: 0;
  right: 0;
  width: 22px;
  height: 1.6em;
  padding: 0;
  border: none;
  background: transparent;
  color: #ffffff66;
  font-size: 14px;
  line-height: 1.6;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
}

.code-line:hover .code-line__copy,
.code-line__copy:focus-visible {
  opacity: 1;
}

.code-line__copy:hover {
  color: #ffffffd9;
}

.content blockquote {
  margin: 18px 0;
  padding: 4px 0 4px 18px;
  border-left: 3px solid var(--accent);
  color: var(--foreground-muted);
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.25rem;
  font-style: italic;
  line-height: 1.5;
}

.content blockquote p {
  margin: 0;
}

.content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 28px auto 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.content figure {
  margin: 28px 0;
}

.content figcaption {
  max-width: 44rem;
  margin: 10px auto 0;
  color: var(--foreground-faint);
  font-size: 0.86rem;
  line-height: 1.45;
  text-align: center;
}

.diagram {
  margin: 28px 0;
  padding: 18px;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--background-elevated);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft);
  scrollbar-width: thin;
  scrollbar-color: #1715133d transparent;
}

.diagram::-webkit-scrollbar {
  height: 8px;
}

.diagram::-webkit-scrollbar-track {
  background: transparent;
}

.diagram::-webkit-scrollbar-thumb {
  background: #1715132b;
  border-radius: 999px;
}

.diagram::-webkit-scrollbar-thumb:hover {
  background: #17151359;
}

.mermaid {
  min-width: 480px;
}

@media (max-width: 640px) {
  .mermaid {
    min-width: 0;
  }
}

.table-scroll {
  margin: 18px 0;
  overflow-x: auto;
  border-radius: 8px;
  scrollbar-width: thin;
  scrollbar-color: #1715133d transparent;
}

.table-scroll::-webkit-scrollbar {
  height: 8px;
}

.table-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.table-scroll::-webkit-scrollbar-thumb {
  background: #1715132b;
  border-radius: 999px;
}

.table-scroll::-webkit-scrollbar-thumb:hover {
  background: #17151359;
}

.content table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: 0.94rem;
}

.table-scroll table {
  min-width: 100%;
  margin: 0;
}

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

.content th {
  border-bottom: 1px solid var(--line-strong);
  color: var(--foreground-faint);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ----- Panels (used on home) ----- */

.panel {
  margin-bottom: 22px;
  padding: 44px 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--background-elevated);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft);
}

.panel:last-child {
  margin-bottom: 0;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.display-title {
  margin: 0;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(2.8rem, 7vw, 5.4rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 0.95;
}

.section-title {
  margin: 0 0 18px;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.02;
}

.lead {
  max-width: 56ch;
  margin: 22px 0 0;
  color: var(--foreground-muted);
  font-size: 1.18rem;
  line-height: 1.62;
}

.lead strong {
  color: var(--foreground);
  font-weight: 600;
}

.body-copy {
  margin: 0;
  color: var(--foreground-muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

/* ----- Buttons ----- */

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 30px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.15s, background-color 0.15s, border-color 0.15s;
}

.button-link:hover {
  transform: translateY(-1px);
}

.button-link--primary {
  background: var(--foreground);
  color: #fff7f0;
}

.button-link--primary:hover {
  background: #0f0d0b;
}

.button-link--secondary {
  border-color: var(--line-strong);
  background: #fff6;
  color: var(--foreground);
}

.button-link--secondary:hover {
  background: #ffffffc4;
}

.button-link--subtle {
  padding-left: 4px;
  padding-right: 4px;
  color: var(--foreground-muted);
}

.button-link--subtle:hover {
  color: var(--foreground);
  transform: none;
}

/* ----- Parts list (home) ----- */

.parts-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: part;
}

.parts-list > li {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 28px;
  align-items: baseline;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}

.parts-list > li:last-child {
  border-bottom: none;
}

.parts-list__index {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 2.4rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--accent);
  line-height: 1;
}

.parts-list__body h3 {
  margin: 0;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.parts-list__body h3 a {
  color: var(--foreground);
  text-decoration: none;
}

.parts-list__body h3 a:hover {
  color: var(--accent-strong);
}

.parts-list__body p {
  margin: 6px 0 0;
  color: var(--foreground-muted);
  font-size: 1rem;
  line-height: 1.55;
}

/* ----- Page TOC (right rail) ----- */

.page-toc {
  position: sticky;
  top: 24px;
  align-self: start;
  padding: 6px 4px 24px;
  font-size: 13px;
  line-height: 1.45;
}

.page-toc__heading {
  margin: 0 0 10px;
  padding: 0 10px;
  color: var(--foreground-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-toc .toc {
  margin: 0;
}

.page-toc ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.page-toc ul ul {
  margin-top: 2px;
  padding-left: 12px;
}

.page-toc li {
  margin: 0;
}

.page-toc a {
  display: block;
  padding: 5px 10px;
  border-left: 2px solid transparent;
  color: var(--foreground-muted);
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}

.page-toc a:hover {
  color: var(--foreground);
  border-left-color: var(--accent);
}

/* ----- Responsive ----- */

@media (max-width: 1180px) {
  .layout--with-toc {
    grid-template-columns: minmax(220px, 240px) minmax(0, 1fr);
  }

  .page-toc {
    display: none;
  }
}

@media (max-width: 900px) {
  .layout,
  .layout--with-toc {
    display: block;
    padding: 12px 0 64px;
  }

  .nav-toggle {
    display: inline-flex;
    position: relative;
  }

  .site-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: min(86%, 320px);
    margin: 0;
    padding: 80px 18px 28px;
    border: none;
    border-right: 1px solid var(--line);
    background: var(--background);
    box-shadow: 18px 0 60px #1f181226;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    visibility: hidden;
  }

  body.nav-open .site-nav {
    transform: translateX(0);
    visibility: visible;
  }

  .panel {
    padding: 32px 26px;
  }

  .parts-list > li {
    grid-template-columns: 56px 1fr;
    gap: 18px;
  }

  .parts-list__index {
    font-size: 1.8rem;
  }

  .content {
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 16px;
  }

  .display-title {
    font-size: clamp(2.4rem, 11vw, 3.6rem);
  }

  .section-title {
    font-size: 1.8rem;
  }
}
