/*
 * REVU Developers - documentation theme.
 * Built on the REVU design system (BRAND.md / Brand Guidelines v1.8):
 *   Midnight Blue #0E1A2B  primary / structure / dark surface
 *   Sky Cyan      #28C8E0  accent: CTAs, active states, fills
 *   Slate Gray    #5B6B7A  secondary text
 *   Off White     #F7F9FB  muted surface
 *   Lime Signal   #B5FF5E  insight highlight (used sparingly)
 *   Soft Rose     #F29BC0  emotive accent (used sparingly)
 * Typography: Inter (base), IBM Plex Mono (code). Type scale and 1.3/1.6 line
 * heights per section 6.3. Motion 200ms, reduced-motion honored.
 *
 * Accessibility: pure cyan fails AA as link text on white, so inline links use
 * a darkened cyan (--link) that meets WCAG AA; true cyan (--accent) is reserved
 * for fills, borders, and active backgrounds. Dark mode uses bright cyan, which
 * passes on Midnight Blue.
 */

/* Self-hosted fonts (latin subset, woff2). No third-party request: better for
 * privacy and first paint, and the docs work offline. font-display: swap keeps
 * text visible during load. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/inter-400.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/assets/fonts/inter-500.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/assets/fonts/inter-600.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/assets/fonts/inter-700.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/plex-mono-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/assets/fonts/plex-mono-500.woff2") format("woff2");
}

:root {
  color-scheme: light;

  /* Brand palette */
  --midnight: #0e1a2b;
  --cyan: #28c8e0;
  --slate: #5b6b7a;
  --offwhite: #f7f9fb;
  --lime: #b5ff5e;
  --rose: #f29bc0;

  /* Neutral ramp (from the site design tokens) */
  --neutral-50: #f5f7fa;
  --neutral-100: #eceff3;
  --neutral-200: #d8dee6;
  --neutral-400: #9aa5b3;
  --neutral-500: #6b7788;
  --neutral-600: #5b6b7a;
  --neutral-800: #142033;
  --neutral-900: #0e1a2b;

  /* Semantic tokens */
  --bg: #ffffff;
  --bg-soft: var(--offwhite);
  --bg-code: #f4f6f8;
  --bg-elevated: #ffffff;
  --text: var(--midnight);
  --text-soft: var(--slate);
  --border: rgba(14, 26, 43, 0.12);
  --border-strong: rgba(14, 26, 43, 0.22);
  --accent: var(--cyan);
  --accent-soft: rgba(40, 200, 224, 0.12);
  --link: #0b7e93;
  --link-hover: #086476;
  --highlight: var(--lime);
  --focus: #0eb1d2;
  --badge-bg: rgba(14, 26, 43, 0.06);
  --badge-text: var(--slate);

  /* Typography */
  --font: "Inter", "Satoshi", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --lh-heading: 1.3;
  --lh-body: 1.6;

  /* Shape and motion */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1.25rem;
  --shadow-soft: 0 15px 35px rgba(14, 26, 43, 0.08);
  --shadow-card: 0 20px 45px rgba(14, 26, 43, 0.12);
  --transition: 200ms ease-in-out;

  /* Layout */
  --sidebar-w: 17rem;
  --toc-w: 15rem;
  --content-max: 46rem;
  --header-h: 3.75rem;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--midnight);
  --bg-soft: #15233a;
  --bg-code: #0b1626;
  --bg-elevated: #15233a;
  --text: var(--neutral-100);
  --text-soft: var(--neutral-400);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  --accent: var(--cyan);
  --accent-soft: rgba(40, 200, 224, 0.16);
  --link: #4fd6ea;
  --link-hover: #7ee2f1;
  --badge-bg: rgba(255, 255, 255, 0.08);
  --badge-text: var(--neutral-400);
  --shadow-soft: 0 15px 35px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 20px 45px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    color-scheme: dark;
    --bg: var(--midnight);
    --bg-soft: #15233a;
    --bg-code: #0b1626;
    --bg-elevated: #15233a;
    --text: var(--neutral-100);
    --text-soft: var(--neutral-400);
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    --accent-soft: rgba(40, 200, 224, 0.16);
    --link: #4fd6ea;
    --link-hover: #7ee2f1;
    --badge-bg: rgba(255, 255, 255, 0.08);
    --badge-text: var(--neutral-400);
    --shadow-soft: 0 15px 35px rgba(0, 0, 0, 0.4);
    --shadow-card: 0 20px 45px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 0.75rem);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.skip-link {
  position: absolute;
  left: -999px;
}

.skip-link:focus {
  left: 1rem;
  top: 0.5rem;
  z-index: 100;
  background: var(--bg-elevated);
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-h);
  padding: 0 1.5rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand:hover {
  text-decoration: none;
}

.brand svg {
  width: 1.5rem;
  height: 1.5rem;
  display: block;
}

.brand .brand-sub {
  color: var(--text-soft);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-actions #search {
  width: 16rem;
  max-width: 40vw;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition);
}

.header-actions #search:focus {
  border-color: var(--accent);
  outline: none;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  width: 2.1rem;
  height: 2.1rem;
  transition: border-color var(--transition), background var(--transition);
}

#theme-toggle:hover {
  border-color: var(--border-strong);
  background: var(--bg-soft);
}

.header-link {
  font-size: 0.9rem;
  color: var(--text-soft);
}

.header-link:hover {
  color: var(--text);
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 2.5rem;
  max-width: 84rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 1.5rem 0.5rem 3rem 0;
  font-size: 0.92rem;
}

.nav-group {
  margin-bottom: 0.5rem;
}

.nav-group>summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.4rem 0.5rem;
  list-style: none;
  color: var(--text);
  border-radius: var(--radius-sm);
}

.nav-group>summary:hover {
  background: var(--bg-soft);
}

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

.nav-group ul {
  list-style: none;
  margin: 0.15rem 0 0.5rem;
  padding: 0 0 0 0.5rem;
}

.nav-group li a {
  display: block;
  padding: 0.32rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  transition: color var(--transition), background var(--transition);
}

.nav-group li a:hover {
  background: var(--bg-soft);
  text-decoration: none;
  color: var(--text);
}

.nav-group li a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--link);
  font-weight: 600;
}

.badge {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--badge-bg);
  color: var(--badge-text);
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
  vertical-align: middle;
}

/* Content */
.content {
  min-width: 0;
  padding: 2.25rem 0 4rem;
}

.content article {
  max-width: var(--content-max);
}

.content h1 {
  font-size: 2rem;
  line-height: var(--lh-heading);
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
}

.content h2 {
  font-size: 1.5rem;
  line-height: var(--lh-heading);
  letter-spacing: -0.01em;
  margin: 2.75rem 0 0.75rem;
  padding-top: 0.5rem;
}

.content h3 {
  font-size: 1.25rem;
  line-height: var(--lh-heading);
  margin: 1.85rem 0 0.5rem;
}

.content h2,
.content h3 {
  scroll-margin-top: calc(var(--header-h) + 0.75rem);
}

.content p,
.content li {
  color: var(--text);
}

.content strong {
  font-weight: 650;
}

.content a.anchor {
  margin-left: 0.4rem;
  color: var(--border-strong);
  opacity: 0;
  font-weight: 400;
  text-decoration: none;
}

.content h2:hover a.anchor,
.content h3:hover a.anchor {
  opacity: 1;
}

.content code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  padding: 0.1em 0.36em;
  border-radius: var(--radius-sm);
}

.content pre {
  position: relative;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.55;
  box-shadow: var(--shadow-soft);
}

.content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* Syntax highlighting (build-time tokens). Restrained palette tied to the
 * brand: cyan for keywords/tags, green for strings, amber for numbers, slate
 * for comments. Light values first, dark overrides below. */
.tok-keyword {
  color: #0a7d91;
  font-weight: 600;
}

.tok-string {
  color: #1f7a3d;
}

.tok-number {
  color: #b45309;
}

.tok-boolean {
  color: #b45309;
}

.tok-comment {
  color: var(--slate);
  font-style: italic;
}

.tok-function {
  color: #2954c8;
}

.tok-property {
  color: #0e1a2b;
}

.tok-tag {
  color: #0a7d91;
  font-weight: 600;
}

.tok-attr {
  color: #2954c8;
}

.tok-punct {
  color: var(--slate);
}

html[data-theme="dark"] .tok-keyword,
html[data-theme="dark"] .tok-tag {
  color: #4fd6ea;
}

html[data-theme="dark"] .tok-string {
  color: #7ee787;
}

html[data-theme="dark"] .tok-number,
html[data-theme="dark"] .tok-boolean {
  color: #f0b46b;
}

html[data-theme="dark"] .tok-comment {
  color: #7d8aa0;
}

html[data-theme="dark"] .tok-function,
html[data-theme="dark"] .tok-attr {
  color: #93b8ff;
}

html[data-theme="dark"] .tok-property {
  color: var(--neutral-100);
}

@media (prefers-color-scheme: dark) {

  html[data-theme="auto"] .tok-keyword,
  html[data-theme="auto"] .tok-tag {
    color: #4fd6ea;
  }

  html[data-theme="auto"] .tok-string {
    color: #7ee787;
  }

  html[data-theme="auto"] .tok-number,
  html[data-theme="auto"] .tok-boolean {
    color: #f0b46b;
  }

  html[data-theme="auto"] .tok-comment {
    color: #7d8aa0;
  }

  html[data-theme="auto"] .tok-function,
  html[data-theme="auto"] .tok-attr {
    color: #93b8ff;
  }

  html[data-theme="auto"] .tok-property {
    color: var(--neutral-100);
  }
}

.content pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  right: 0.7rem;
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-family: var(--font);
  font-size: 0.7rem;
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, border-color var(--transition), color var(--transition);
}

.content pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.88rem;
  display: block;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

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

.content tr td:last-child,
.content tr th:last-child {
  border-right: none;
}

.content tbody tr:last-child td {
  border-bottom: none;
}

.content th {
  background: var(--bg-soft);
  font-weight: 600;
}

.content blockquote {
  margin: 1.25rem 0;
  padding: 0.65rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-soft);
}

.content blockquote p {
  margin: 0.25rem 0;
}

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.75rem 0;
}

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

.content li {
  margin: 0.3rem 0;
}

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

.page-footer {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 1.5rem;
  font-size: 0.85rem;
}

/* TOC */
.toc {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 2.25rem 0;
  font-size: 0.82rem;
}

.toc-title {
  font-weight: 600;
  color: var(--text-soft);
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.7rem;
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}

.toc li a {
  display: block;
  padding: 0.28rem 0 0.28rem 0.8rem;
  color: var(--text-soft);
  border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color var(--transition), border-color var(--transition);
}

.toc li a:hover,
.toc li a.active {
  color: var(--link);
  border-left-color: var(--accent);
  text-decoration: none;
}

.toc-h3 a {
  padding-left: 1.6rem;
  font-size: 0.95em;
}

/* Search results */
#search-results {
  position: fixed;
  top: var(--header-h);
  right: 1.5rem;
  width: 24rem;
  max-width: 90vw;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  z-index: 30;
  padding: 0.5rem;
}

#search-results a {
  display: block;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text);
}

#search-results a:hover,
#search-results a.active {
  background: var(--accent-soft);
  text-decoration: none;
}

#search-results .sr-platform {
  font-size: 0.7rem;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#search-results .sr-empty {
  padding: 0.7rem;
  color: var(--text-soft);
  font-size: 0.88rem;
}

/* Mobile nav toggle (hidden on desktop, shown in the responsive block) */
#nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  margin-right: 0.25rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
#nav-toggle:hover {
  border-color: var(--border-strong);
}

.nav-backdrop {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  background: rgba(14, 26, 43, 0.45);
  z-index: 25;
}

/* Site footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  margin-top: 3rem;
}
.site-footer-inner {
  max-width: 84rem;
  margin: 0 auto;
  padding: 2.25rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 3rem;
  align-items: baseline;
}
.site-footer-brand strong {
  font-size: 1rem;
}
.site-footer-brand p {
  margin: 0.3rem 0 0;
  color: var(--text-soft);
  font-size: 0.88rem;
  max-width: 26rem;
}
.site-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}
.site-footer-links a {
  color: var(--text-soft);
  font-size: 0.9rem;
}
.site-footer-links a:hover {
  color: var(--text);
}
.site-footer-legal {
  width: 100%;
  margin: 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .toc {
    display: none;
  }
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 0 1rem;
  }

  /* The sidebar becomes an off-canvas drawer toggled from the header. */
  #nav-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: min(82vw, 19rem);
    height: auto;
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 1.25rem 1rem 3rem;
    transform: translateX(-100%);
    transition: transform var(--transition);
    z-index: 26;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-card);
  }

  .header-actions #search {
    width: 8rem;
  }
}

@media (max-width: 560px) {
  .brand .brand-sub {
    display: none;
  }

  /* Reclaim header space on phones: GitHub lives in the footer and the brand. */
  .header-link {
    display: none;
  }

  .header-actions {
    gap: 0.5rem;
  }

  .header-actions #search {
    width: 7.5rem;
  }
}

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