/* NXD manual theme.
   Layered over mdBook's stock CSS: this file only overrides variables and the
   handful of elements whose defaults read as unstyled. It deliberately matches
   the project site (nxd.lamhub.com) so the manual does not feel like a
   different product.

   Why this re-skins the built-in themes instead of adding a custom one:
   mdBook 0.5 only honours its five built-in names. A custom `default-theme`
   is silently ignored (the page resolves to `preferred-dark-theme`, or
   `light`), the theme picker never lists it, and a reader who switches away
   can never get back. Verified in a browser: with `default-theme = "nxd"` the
   served page carried `class="coal"`, so `.nxd` rules never matched.

   So the NXD palette is applied to the classes mdBook actually sets — `coal`
   for dark and `light` for light — and the picker keeps working. `rust`,
   `navy`, and `ayu` are left at mdBook's defaults for readers who pick them
   deliberately. */

:root {
  --nxd-accent: #4f46e5;
  --nxd-accent-light: #818cf8;
  --nxd-radius: 10px;
  --nxd-mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono",
    "Cascadia Code", Menlo, Consolas, monospace;
  --nxd-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

/* --- Dark palette: mdBook's `coal`, re-skinned to match the site --------- */

.coal {
  --bg: #080a10;
  --fg: #e8edf5;

  --sidebar-bg: #0c0f17;
  --sidebar-fg: #b8c2d1;
  --sidebar-non-existant: #55606f;
  --sidebar-active: #a5b4fc;
  --sidebar-spacer: rgba(255, 255, 255, 0.07);

  --scrollbar: #3a4354;

  --icons: #7c8798;
  --icons-hover: #c7d2fe;

  --links: #a5b4fc;

  --inline-code-color: #c7d2fe;

  --theme-popup-bg: #111827;
  --theme-popup-border: rgba(255, 255, 255, 0.12);
  --theme-hover: rgba(255, 255, 255, 0.06);

  --quote-bg: rgba(129, 140, 248, 0.08);
  --quote-border: #6366f1;

  --warning-border: #f59e0b;

  --table-border-color: rgba(255, 255, 255, 0.12);
  --table-header-bg: rgba(255, 255, 255, 0.05);
  --table-alternate-bg: rgba(255, 255, 255, 0.02);

  --searchbar-border-color: rgba(255, 255, 255, 0.16);
  --searchbar-bg: #111827;
  --searchbar-fg: #e8edf5;
  --searchbar-shadow-color: rgba(0, 0, 0, 0.5);
  --searchresults-header-fg: #8b95a5;
  --searchresults-border-color: rgba(255, 255, 255, 0.12);
  --searchresults-li-bg: rgba(255, 255, 255, 0.03);
  --search-mark-bg: rgba(245, 158, 11, 0.35);

  --color-scheme: dark;
}

.coal .content .header {
  color: #f3f6fb;
}

/* --- Light palette: mdBook's `light`, re-skinned to match ---------------- */

.light {
  --bg: #ffffff;
  --fg: #1f2733;

  --sidebar-bg: #f5f7fb;
  --sidebar-fg: #46536a;
  --sidebar-non-existant: #a5aec0;
  --sidebar-active: #4f46e5;
  --sidebar-spacer: rgba(15, 23, 42, 0.09);

  --scrollbar: #c2cad8;

  --icons: #7b8798;
  --icons-hover: #4f46e5;

  --links: #4338ca;

  --inline-code-color: #4338ca;

  --theme-popup-bg: #ffffff;
  --theme-popup-border: rgba(15, 23, 42, 0.14);
  --theme-hover: rgba(79, 70, 229, 0.08);

  --quote-bg: rgba(79, 70, 229, 0.06);
  --quote-border: #6366f1;

  --warning-border: #b45309;

  --table-border-color: rgba(15, 23, 42, 0.13);
  --table-header-bg: rgba(15, 23, 42, 0.045);
  --table-alternate-bg: rgba(15, 23, 42, 0.022);

  --searchbar-border-color: rgba(15, 23, 42, 0.18);
  --searchbar-bg: #ffffff;
  --searchbar-fg: #1f2733;
  --searchbar-shadow-color: rgba(15, 23, 42, 0.12);
  --searchresults-header-fg: #6b7686;
  --searchresults-border-color: rgba(15, 23, 42, 0.12);
  --searchresults-li-bg: rgba(15, 23, 42, 0.025);
  --search-mark-bg: rgba(245, 158, 11, 0.4);

  --color-scheme: light;
}

.light .content .header {
  color: #131a24;
}

.light .chapter li a.active {
  background: rgba(79, 70, 229, 0.1);
}

/* --- Typography ---------------------------------------------------------- */

html {
  font-family: var(--nxd-sans);
}

/* mdBook sets `html { font-size: 62.5% }` so that 1rem == 10px. Every rem
   here would therefore be 10/16 of its intended size -- body text rendered at
   10px and the content column at 540px. Use px for the sizes that must not
   depend on that root, and keep rem only where a 10px base is intended. */
.content {
  font-size: 17px;
  line-height: 1.7;
}

/* Layout. mdBook ships a 300px sidebar and a 750px content column, which is
   the same range Stripe, Tailwind and the Rust Book use, so the sidebar is
   left alone. The content column is widened modestly: reference tables and
   shell examples here are wider than book prose, but 860px+ is too long a
   line for comfortable reading at 17px. */
.content main {
  max-width: 800px;
  margin-inline: auto;
  padding-inline: 1.5rem;
}

/* Wide screens can afford a little more without hurting the measure. */
@media (min-width: 1600px) {
  .content main {
    max-width: 840px;
  }
}

/* The sidebar is readable at mdBook's own width; only the type was small. */
.sidebar {
  font-size: 14.5px;
}

.content h1,
.content h2,
.content h3,
.content h4 {
  font-weight: 680;
  letter-spacing: -0.018em;
  line-height: 1.25;
  text-wrap: balance;
}

.content h1 { font-size: 2.1rem; margin: 0 0 1.2rem; }
.content h2 {
  font-size: 1.55rem;
  margin: 2.6rem 0 0.9rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--table-border-color);
}
.content h3 { font-size: 1.25rem; margin: 1.9rem 0 0.6rem; }
.content h4 { font-size: 1.08rem; margin: 1.5rem 0 0.5rem; }

.content p,
.content li {
  hyphens: none;
}

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

.content li + li {
  margin-top: 0.3rem;
}

/* Anchor links: visible on hover rather than permanently, so headings read
   cleanly but stay linkable. */
.content .header:hover a.header::before,
.content .header a.header::before {
  opacity: 0.35;
}

/* --- Code ---------------------------------------------------------------- */

code {
  font-family: var(--nxd-mono);
  font-size: 0.875em;
}

:not(pre) > code {
  padding: 0.12em 0.38em;
  border-radius: 5px;
  background: var(--quote-bg);
  word-break: break-word;
}

pre {
  border-radius: var(--nxd-radius);
  border: 1px solid var(--table-border-color);
  padding: 0.35rem 0.2rem;
}

pre > code {
  font-size: 0.86em;
  line-height: 1.6;
}

/* Long command lines scroll inside the block. Keep the scrollbar slim and
   themed rather than the heavy default track. */
pre {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

pre::-webkit-scrollbar {
  height: 8px;
}

pre::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 4px;
}

pre::-webkit-scrollbar-track {
  background: transparent;
}

/* --- Tables -------------------------------------------------------------- */

.content table {
  width: 100%;
  border-collapse: collapse;
  display: table;
  margin: 1.4rem 0;
  font-size: 0.93em;
}

/* mdBook's default header fill is a flat mid-grey that reads as washed out
   against the page. Use a tinted band and the page foreground instead. */
.content table thead th {
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 650;
  white-space: nowrap;
  background: var(--table-header-bg);
  color: var(--fg);
  border-bottom: 1px solid var(--table-border-color);
}

.content table td {
  border-top: 1px solid var(--table-border-color);
}

.content table td,
.content table th {
  padding: 0.6rem 0.85rem;
  vertical-align: top;
}

/* Reference tables (CLI options, resource schemas) carry far more columns than
   prose needs. Let them use the space beyond the prose measure on wide screens
   rather than wrapping every cell to three words. */
@media (min-width: 1200px) {
  .content main > .table-wrapper,
  .content main > table {
    width: calc(100% + 12rem);
    max-width: calc(100vw - var(--sidebar-width) - 8rem);
    margin-inline: -6rem;
  }
}

@media (min-width: 1200px) {
  .sidebar-hidden .content main > .table-wrapper,
  .sidebar-hidden .content main > table {
    max-width: calc(100vw - 8rem);
  }
}

/* Wide reference tables must scroll inside themselves, never widen the page. */
.table-wrapper {
  overflow-x: auto;
  margin: 1.4rem 0;
}

/* --- Blockquotes & admonitions ------------------------------------------- */

blockquote {
  border-left: 3px solid var(--quote-border);
  border-top: 0;
  border-bottom: 0;
  border-right: 0;
  border-radius: 0 var(--nxd-radius) var(--nxd-radius) 0;
  padding: 0.8rem 1.1rem;
  margin: 1.4rem 0;
}

blockquote > :last-child { margin-bottom: 0; }
blockquote > :first-child { margin-top: 0; }

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

.sidebar .sidebar-scrollbox {
  padding: 1rem 0.9rem;
}

.chapter li.chapter-item {
  line-height: 1.45;
  margin-top: 0.3em;
}

.chapter li a {
  border-radius: 6px;
  padding: 0.28rem 0.5rem;
}

.chapter li a:hover {
  background: var(--theme-hover);
}

.chapter li a.active {
  background: rgba(129, 140, 248, 0.14);
  font-weight: 600;
}

/* Part titles ("Tutorials", "Reference", …) read as section labels. */
.chapter .part-title {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  opacity: 0.62;
  margin: 1.4rem 0 0.3rem;
  padding: 0 0.5rem;
}

/* --- Menu bar ------------------------------------------------------------ */

.menu-title {
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* --- Print --------------------------------------------------------------- */

@media print {
  .content main { max-width: none; }
  pre { border: 1px solid #ccc; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
