:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #fff;
  --sidebar: #f2f2ee;
  --text: #242421;
  --muted: #686862;
  --line: #d8d8d1;
  --line-dark: #b9b9b1;
  --accent: #be431e;
  --accent-soft: #f4e3dc;
  --code: #292925;
  --code-text: #f5f3e8;
  --inline-code: #ecece7;
  --display: "Trebuchet MS", "Segoe UI", ui-sans-serif, sans-serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --header-h: 60px;
  --sidebar-w: 268px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151718;
  --surface: #202324;
  --sidebar: #181a1b;
  --text: #ecece6;
  --muted: #aaa9a2;
  --line: #343738;
  --line-dark: #4b4f50;
  --accent: #ff845c;
  --accent-soft: #38251f;
  --code: #0e1011;
  --code-text: #f3f1e8;
  --inline-code: #26292a;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font: 16px/1.68 var(--sans); }
a { color: var(--accent); text-underline-offset: 0.16em; }
button, input { font: inherit; }
button { color: inherit; }
code, kbd { font-family: var(--mono); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(280px, 620px) 1fr;
  height: var(--header-h);
  border-bottom: 1px solid var(--line-dark);
  background: color-mix(in srgb, var(--bg) 96%, transparent);
  backdrop-filter: blur(10px);
}
.brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 1.1rem;
  background: var(--sidebar);
  color: var(--text);
  line-height: 1.1;
  text-decoration: none;
}
.brand strong { font-size: 1rem; font-weight: 820; letter-spacing: -0.035em; }
.brand .brand-word { margin: 0; color: var(--accent); font: inherit; }
.brand > span { margin-top: 0.2rem; color: var(--muted); font: 500 0.75rem/1.25 var(--mono); }
.search-wrap { position: relative; display: flex; min-width: 0; align-items: center; padding: 0.55rem 1rem; }
.search-wrap::before { position: absolute; left: 1.75rem; color: var(--muted); content: "⌕"; font: 1.05rem/1 var(--mono); }
.search-wrap input { width: 100%; height: 40px; border: 1px solid var(--line-dark); border-radius: 3px; padding: 0 3rem 0 2rem; background: var(--surface); color: var(--text); }
.search-wrap kbd { position: absolute; right: 1.65rem; border: 1px solid var(--line); border-bottom-color: var(--line-dark); border-radius: 3px; padding: 0.08rem 0.35rem; color: var(--muted); font-size: 0.75rem; }
.theme-toggle, .menu-toggle { border: 1px solid var(--line-dark); border-radius: 3px; background: transparent; color: var(--muted); cursor: pointer; }
.theme-toggle:hover, .menu-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle { display: grid; width: 40px; height: 40px; align-self: center; justify-self: end; margin-right: 1rem; padding: 0; place-items: center; }
.theme-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.theme-icon-sun, html[data-theme="dark"] .theme-icon-moon { display: none; }
html[data-theme="dark"] .theme-icon-sun { display: block; }
.menu-toggle { display: none; padding: 0.35rem 0.55rem; font: 650 0.75rem/1.3 var(--mono); }

.sidebar {
  position: fixed;
  z-index: 30;
  top: var(--header-h);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 1.25rem 1rem 3rem;
  background: var(--sidebar);
  scrollbar-width: thin;
}
.eyebrow, .kicker { margin: 0 0 0.55rem; color: var(--accent); font: 700 0.75rem/1.4 var(--mono); letter-spacing: 0.09em; text-transform: uppercase; }
.nav-section { margin-top: 1.45rem; }
.nav-link { display: flex; align-items: baseline; justify-content: space-between; gap: 0.8rem; padding: 0.42rem 0.35rem; color: var(--text); font-size: 0.84rem; line-height: 1.4; text-decoration: none; }
.nav-link:hover, .nav-link.active { color: var(--accent); }
.nav-link > span:last-child { color: var(--muted); font: 0.75rem/1 var(--mono); }
.service-nav { display: grid; gap: 0.06rem; margin-left: 0.55rem; border-left: 1px solid var(--line-dark); padding-left: 0.55rem; }
.service-link { position: relative; display: grid; grid-template-columns: auto minmax(0.75rem, 1fr) auto; gap: 0.4rem; align-items: baseline; padding: 0.42rem 0.25rem; }
.service-link.active::before { position: absolute; top: calc(50% - 1px); left: -0.62rem; width: 0.55rem; height: 2px; background: var(--accent); content: ""; }
.service-nav-name { overflow: hidden; color: inherit; text-overflow: ellipsis; white-space: nowrap; }
.service-leader { min-width: 0.75rem; border-bottom: 1px dotted var(--line-dark); transform: translateY(-0.16rem); }
.sidebar-scrim { display: none; }

main { min-width: 0; margin-left: var(--sidebar-w); }
.home { max-width: 1000px; margin: 0 auto; padding: 4.4rem clamp(1.5rem, 5vw, 5rem) 6rem; }
.hero { max-width: 720px; margin-bottom: 4.5rem; }
.home h1 { max-width: 12ch; margin: 0; font-family: var(--display); font-size: clamp(2.7rem, 6vw, 5rem); font-weight: 720; letter-spacing: -0.065em; line-height: 0.96; }
.hero h2 { margin: 1.35rem 0 0.15rem; font-family: var(--display); font-size: 1.25rem; font-weight: 650; letter-spacing: -0.02em; }
.hero > p:last-child { max-width: 59ch; margin: 0; color: var(--muted); font-size: 1.05rem; line-height: 1.72; }
.technique-index { margin-bottom: 4rem; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding-bottom: 0.65rem; border-bottom: 1px solid var(--line-dark); }
.section-title h2 { margin: 0; font-family: var(--display); font-size: 1.2rem; font-weight: 650; letter-spacing: -0.025em; }
.section-title span { color: var(--muted); font: 0.75rem/1 var(--mono); }
.technique-entry { display: block; padding: 1.35rem 0.1rem 1.45rem; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.technique-entry:hover h3 { color: var(--accent); }
.technique-kicker { margin: 0 0 0.45rem; color: var(--muted); font: 650 0.75rem/1.35 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; }
.technique-entry h3 { margin: 0; font-family: var(--display); font-size: 1.28rem; font-weight: 640; letter-spacing: -0.025em; line-height: 1.25; }
.technique-summary { max-width: 67ch; margin: 0.5rem 0 0.75rem; color: var(--muted); font-size: 0.91rem; line-height: 1.58; }
.technique-meta { display: flex; flex-wrap: wrap; gap: 0.2rem 0.55rem; color: var(--muted); font: 0.75rem/1.5 var(--mono); }
.technique-meta > * + *::before { margin-right: 0.55rem; color: var(--line-dark); content: "·"; }
.empty-state { padding: 1.3rem 0; color: var(--muted); }

.article-page { max-width: 898px; margin: 0 auto; padding: 3.1rem clamp(1.5rem, 5vw, 4rem) 7rem; }
.back-link { color: var(--muted); font: 0.78rem/1.4 var(--mono); text-decoration: none; }
.back-link:hover { color: var(--accent); }
.article-header { margin-top: 1.5rem; margin-bottom: 3rem; }
.article-header h1 { max-width: 100%; margin: 0; overflow-wrap: anywhere; font-family: var(--display); font-size: clamp(2.25rem, 3.4vw, 3rem); font-weight: 700; letter-spacing: -0.05em; line-height: 1.03; }
.dek { max-width: 64ch; margin: 1.1rem 0 0; color: var(--muted); font-size: 1.06rem; line-height: 1.72; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2rem; margin: 1.7rem 0 2.8rem; padding: 0.2rem 0; font-size: 0.88rem; }
.facts div { padding: 0.62rem 0; border-bottom: 1px solid var(--line); }
.facts > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
.facts dt { margin: 0 0 0.2rem; color: var(--muted); font: 700 0.75rem/1.4 var(--mono); letter-spacing: 0.065em; text-transform: uppercase; }
.facts dd { min-width: 0; margin: 0; line-height: 1.45; overflow-wrap: anywhere; }
.facts code { padding: 0; background: none; }
.article-body { max-width: 72ch; counter-reset: article-section; }
.article-body h2 { position: relative; margin: 4.4rem 0 1.05rem; font-family: var(--display); font-size: 1.65rem; font-weight: 650; letter-spacing: -0.03em; line-height: 1.2; scroll-margin-top: calc(var(--header-h) + 1rem); }
.article-body h2::before { position: absolute; top: 0.45rem; left: -3.15rem; color: var(--accent); content: counter(article-section, decimal-leading-zero); counter-increment: article-section; font: 700 0.75rem/1 var(--mono); letter-spacing: 0.06em; }
.article-body h3 { margin: 2.2rem 0 0.7rem; font-family: var(--display); font-size: 1.12rem; font-weight: 650; letter-spacing: -0.015em; }
.article-body p { margin: 0 0 1.05rem; }
.article-body ul, .article-body ol { padding-left: 1.35rem; }
.article-body li { margin: 0.38rem 0; }
.article-body code { border-radius: 2px; padding: 0.1rem 0.24rem; background: var(--inline-code); font-size: 0.9em; overflow-wrap: anywhere; }
.callout { --callout-color: #667a52; margin: 1.5rem 0; padding: 0.9rem 1rem; border-left: 3px solid var(--callout-color); background: color-mix(in srgb, var(--callout-color) 8%, var(--surface)); font-size: 0.92rem; line-height: 1.6; }
.callout.warning { --callout-color: var(--accent); background: var(--accent-soft); }
.callout.detection { --callout-color: #55758d; }
.callout > strong { display: block; margin-bottom: 0.25rem; font: 700 0.75rem/1.3 var(--mono); letter-spacing: 0.07em; text-transform: uppercase; }
.callout p { margin: 0; }
.codeblock { position: relative; width: calc(100% + 2rem); margin: 1.35rem 0 1.35rem -0.5rem; overflow: hidden; border-radius: 2px; background: var(--code); color: var(--code-text); }
.codeblock pre { margin: 0; overflow-x: auto; padding: 1rem 1rem 1.1rem; font: 0.82rem/1.72 var(--mono); tab-size: 2; }
.codeblock code { padding: 0; background: none; color: inherit; font-size: inherit; overflow-wrap: normal; }
.copy-button { position: absolute; z-index: 1; top: 0.45rem; right: 0.5rem; border: 1px solid #5e5e56; border-radius: 2px; padding: 0.28rem 0.5rem; background: #353530; color: #d5d3c8; cursor: pointer; font: 0.75rem/1.2 var(--mono); }
.copy-button:hover { border-color: #aaa89d; color: #fff; }
.table-wrap { width: calc(100% + 2rem); overflow-x: auto; margin: 1.6rem 0 1.6rem -0.5rem; border-top: 2px solid var(--accent); }
.article-body table { width: 100%; min-width: 610px; border-collapse: collapse; font-size: 0.82rem; }
.article-body th, .article-body td { border-bottom: 1px solid var(--line); padding: 0.72rem 0.75rem; text-align: left; vertical-align: top; }
.article-body th { background: var(--sidebar); font: 700 0.75rem/1.4 var(--mono); letter-spacing: 0.05em; text-transform: uppercase; }
.article-body table code { padding: 0; background: none; }

@media (max-width: 970px) {
  :root { --sidebar-w: 240px; }
  .topbar { grid-template-columns: var(--sidebar-w) minmax(250px, 1fr) auto; }
}

@media (max-width: 720px) {
  :root { --header-h: 58px; }
  .topbar { grid-template-columns: auto auto minmax(0, 1fr) auto; }
  .brand { padding: 0 0.7rem; background: transparent; }
  .brand > span { display: none; }
  .menu-toggle { display: block; align-self: center; margin-left: 0.25rem; }
  .search-wrap { padding: 0.45rem 0.4rem; }
  .search-wrap kbd { display: none; }
  .search-wrap input { padding-right: 0.5rem; }
  .theme-toggle { margin-right: 0.45rem; }
  .sidebar { width: min(82vw, 290px); transform: translateX(-102%); transition: transform 0.18s ease; box-shadow: 10px 0 28px rgb(0 0 0 / 15%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; z-index: 20; inset: var(--header-h) 0 0; width: 100%; border: 0; background: rgb(0 0 0 / 30%); }
  .sidebar.open + .sidebar-scrim { display: block; }
  main { margin-left: 0; }
  .home, .article-page { padding: 2.3rem 1rem 5rem; }
  .technique-entry { padding: 1.15rem 0 1.25rem; }
  .technique-entry h3 { overflow-wrap: anywhere; font-size: 1.18rem; }
  .technique-summary { font-size: 0.9rem; }
  .article-header h1 { font-size: 2.35rem; }
  .article-body h2::before { position: static; display: block; margin-bottom: 0.4rem; }
  .facts { grid-template-columns: 1fr; }
  .codeblock, .table-wrap { width: 100%; margin-left: 0; }
}

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