/* MyAlgoGuru help portal.
 *
 * Colour and type come from the MyAlgoGuru design system. Two hues only, navy and amber,
 * everything else a neutral. The system's hard rule is kept here: AMBER IS A SURFACE AND
 * NEVER INK. Emphasis is an amber block, pill or rule carrying dark ink on it; no word,
 * link or heading is ever set in amber.
 *
 * Light is the default. A docs site is read for minutes at a time, and long-form text
 * reads better on paper-white; dark is offered and remembered per reader.
 */

:root {
  --surface: #ffffff;
  --surface-muted: #f4f5f7;
  --surface-subtle: #e7e9ed;
  --surface-sunk: #fbfbfc;
  --surface-inverse: #121b39;
  --surface-accent: #fff8ea;

  --text-heading: #1a2750;
  --text-primary: #2e323d;
  --text-secondary: #5a6070;
  --text-muted: #6b7280;
  --text-inverse: #ffffff;

  --brand: #43509c;
  --brand-deep: #24366d;
  --brand-ink: #43509c;
  --brand-soft: #e5e8f6;

  --accent: #f6a001;
  --accent-soft: #ffefd0;
  --accent-border: #ffc766;
  --on-accent: #010314;

  --border: #e7e9ed;
  --border-strong: #d3d7de;
  --border-bright: #a5abb8;
  --focus: #a85c00;

  --ok: #0f7b4f;
  --ok-soft: #f1f8f4;
  --ok-border: #b8ddc9;
  --warn-soft: #fff8ea;
  --warn-border: #ffc766;
  --warn-text: #5c3200;

  --sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --nav-w: 288px;
  --toc-w: 232px;
  --measure: 68ch;
  --header-h: 60px;

  --shadow-sm: 0 1px 3px rgba(11, 18, 48, 0.08), 0 1px 2px rgba(11, 18, 48, 0.04);
  --shadow-md: 0 4px 16px -4px rgba(11, 18, 48, 0.1), 0 2px 6px -2px rgba(11, 18, 48, 0.06);
  --shadow-lg: 0 16px 40px -12px rgba(11, 18, 48, 0.16);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --surface: #010314;
  --surface-muted: #080b1a;
  --surface-subtle: #22263a;
  --surface-sunk: #060818;
  --surface-inverse: #070730;
  --surface-accent: #33240a;

  --text-heading: #ededf2;
  --text-primary: #d6d9e3;
  --text-secondary: #b9becf;
  --text-muted: #949aad;

  --brand: #5837fb;
  --brand-deep: #3e00de;
  --brand-ink: #b2a3fd;
  --brand-soft: #161b33;

  --accent-soft: #1d1408;
  --accent-border: rgba(242, 149, 26, 0.42);

  --border: #1c1e29;
  --border-strong: #2d303d;
  --border-bright: #43475b;
  --focus: #fdb02e;

  --ok: #05c7a3;
  --ok-soft: #07211c;
  --ok-border: #0f4d40;
  --warn-soft: #1d1408;
  --warn-border: #5c3200;
  --warn-text: #ededf2;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 16px -4px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, 0.65);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 20px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; animation: none !important; } }

body {
  margin: 0;
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}

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

/* ── header ─────────────────────────────────────────────────────────────── */
.hdr {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.hdr-brand { display: flex; align-items: center; gap: 11px; text-decoration: none; flex: 0 0 auto; }
.hdr-brand img { height: 26px; width: auto; display: block; }
/* The wordmark is a full-colour PNG with no single-colour version, so the light and
 * dark files are both shipped and swapped by theme. The dark one carries white
 * lettering that would be invisible on the light ground, and the reverse. */
.hdr-brand .wm-dark { display: none; }
:root[data-theme="dark"] .hdr-brand .wm-light { display: none; }
:root[data-theme="dark"] .hdr-brand .wm-dark { display: block; }
.hdr-brand span {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--text-muted); padding-left: 11px; border-left: 1px solid var(--border-strong);
}
.hdr-spacer { flex: 1 1 auto; }
.hdr-link { font-size: 14px; color: var(--text-secondary); text-decoration: none; white-space: nowrap; }
.hdr-link:hover { color: var(--text-heading); }
.hdr-cta {
  font-size: 14px; font-weight: 600; text-decoration: none;
  background: var(--accent); color: var(--on-accent);
  padding: 7px 15px; border-radius: 4px; white-space: nowrap;
}
.hdr-cta:hover { background: #fdb02e; }

.theme-btn, .nav-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); color: var(--text-secondary); cursor: pointer;
}
.theme-btn:hover, .nav-btn:hover { color: var(--text-heading); border-color: var(--border-bright); }
.nav-btn { display: none; }

/* ── search ─────────────────────────────────────────────────────────────── */
.search { position: relative; flex: 0 1 380px; min-width: 0; }
.search input {
  width: 100%; height: 34px; padding: 0 60px 0 34px;
  font-family: var(--sans); font-size: 14px; color: var(--text-primary);
  background: var(--surface-muted); border: 1px solid var(--border-strong);
  border-radius: 4px;
}
.search input::placeholder { color: var(--text-muted); }
.search input:focus { background: var(--surface); border-color: var(--brand); outline: none; }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--text-muted); pointer-events: none; }
.search kbd {
  position: absolute; right: 8px; top: 7px;
  font-family: var(--mono); font-size: 10.5px; color: var(--text-muted);
  border: 1px solid var(--border-strong); border-radius: 3px; padding: 1px 5px; background: var(--surface);
}
.results {
  position: absolute; top: 42px; left: 0; right: 0; max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px;
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 50;
}
.results a { display: block; padding: 9px 11px; border-radius: 4px; text-decoration: none; }
.results a:hover, .results a.on { background: var(--surface-muted); }
.results .r-sec { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.results .r-title { font-size: 14px; font-weight: 600; color: var(--text-heading); margin-top: 2px; }
.results .r-snip { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; line-height: 1.45; }
.results mark { background: var(--accent-soft); color: inherit; border-radius: 2px; padding: 0 1px; }
.results .r-none { padding: 14px 11px; font-size: 14px; color: var(--text-secondary); }

/* ── shell ──────────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--toc-w); gap: 0; align-items: start; }

.nav {
  position: sticky; top: var(--header-h); align-self: start;
  height: calc(100vh - var(--header-h)); overflow-y: auto;
  padding: 26px 18px 60px 24px; border-right: 1px solid var(--border);
}
.nav h4 {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-muted); margin: 22px 0 7px; font-weight: 500;
}
.nav h4:first-child { margin-top: 0; }
.nav a {
  display: block; padding: 5px 10px; margin-left: -10px; font-size: 14px;
  color: var(--text-secondary); text-decoration: none; border-radius: 4px; line-height: 1.4;
}
.nav a:hover { color: var(--text-heading); background: var(--surface-muted); }
.nav a.on { color: var(--text-heading); font-weight: 600; background: var(--brand-soft); }
.nav details { margin: 1px 0; }
.nav summary {
  list-style: none; cursor: pointer; padding: 5px 10px; margin-left: -10px; border-radius: 4px;
  font-size: 14px; color: var(--text-secondary); display: flex; align-items: center; gap: 7px;
}
.nav summary::-webkit-details-marker { display: none; }
.nav summary:hover { color: var(--text-heading); background: var(--surface-muted); }
.nav summary .chev { transition: transform 0.15s ease; flex: 0 0 auto; }
.nav details[open] > summary .chev { transform: rotate(90deg); }
.nav details > div { padding-left: 15px; border-left: 1px solid var(--border); margin-left: 4px; }

main { min-width: 0; padding: 40px 48px 96px; }
.wrap { max-width: var(--measure); }

.toc {
  position: sticky; top: var(--header-h); align-self: start;
  height: calc(100vh - var(--header-h)); overflow-y: auto;
  padding: 40px 24px 60px 8px;
}
.toc h4 { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-muted); margin: 0 0 9px; font-weight: 500; }
.toc a { display: block; font-size: 13px; line-height: 1.45; color: var(--text-secondary); text-decoration: none; padding: 4px 0 4px 11px; border-left: 2px solid var(--border); }
.toc a:hover { color: var(--text-heading); }
.toc a.on { color: var(--text-heading); border-left-color: var(--accent); font-weight: 500; }
.toc a.lvl3 { padding-left: 22px; font-size: 12.5px; }

/* ── prose ──────────────────────────────────────────────────────────────── */
.crumbs { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.crumbs a { color: var(--text-secondary); text-decoration: none; }
.crumbs a:hover { color: var(--text-heading); text-decoration: underline; }
.crumbs span { padding: 0 7px; opacity: 0.5; }

h1 { font-size: 40px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; color: var(--text-heading); margin: 0 0 14px; text-wrap: balance; }
h2 { font-size: 28px; line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; color: var(--text-heading); margin: 52px 0 14px; text-wrap: balance; scroll-margin-top: calc(var(--header-h) + 20px); }
h3 { font-size: 22px; line-height: 1.3; font-weight: 600; letter-spacing: -0.012em; color: var(--text-heading); margin: 36px 0 10px; text-wrap: balance; scroll-margin-top: calc(var(--header-h) + 20px); }
h4 { font-size: 16px; font-weight: 600; color: var(--text-heading); margin: 26px 0 8px; }

.lede { font-size: 19px; line-height: 1.6; color: var(--text-secondary); margin: 0 0 8px; }

p { margin: 16px 0; }
ul, ol { margin: 16px 0; padding-left: 24px; }
li { margin: 7px 0; }
li::marker { color: var(--text-muted); }

a { color: var(--brand-ink); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

strong { font-weight: 600; color: var(--text-heading); }
code { font-family: var(--mono); font-size: 0.87em; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; }
pre { background: var(--surface-muted); border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; overflow-x: auto; }
pre code { background: none; border: 0; padding: 0; font-size: 13px; line-height: 1.6; }
hr { border: 0; border-top: 1px solid var(--border); margin: 44px 0; }

/* numbered steps — the house pattern for every how-to */
ol.steps { list-style: none; counter-reset: s; padding-left: 0; margin: 22px 0; }
ol.steps > li { counter-increment: s; position: relative; padding-left: 44px; margin: 0 0 18px; min-height: 30px; }
ol.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: -1px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand); color: #ffffff;
  font-family: var(--mono); font-size: 13px; font-weight: 500;
  display: grid; place-items: center;
}

/* callouts */
.note { margin: 24px 0; padding: 14px 18px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-muted); }
.note > :first-child { margin-top: 0; } .note > :last-child { margin-bottom: 0; }
.note-t { font-weight: 600; color: var(--text-heading); margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.note.info { background: var(--brand-soft); border-color: var(--border-strong); }
.note.warning { background: var(--warn-soft); border-color: var(--warn-border); }
.note.warning .note-t, .note.warning p { color: var(--warn-text); }
.note.compliance { background: var(--surface-accent); border-color: var(--accent-border); }
.note.tip { background: var(--ok-soft); border-color: var(--ok-border); }

/* tables */
.tw { overflow-x: auto; margin: 24px 0; border: 1px solid var(--border-strong); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
thead th { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); font-weight: 500; text-align: left; padding: 11px 14px; background: var(--surface-muted); border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }

/* screenshots */
figure.shot { margin: 28px 0; }
figure.shot img { display: block; width: 100%; height: auto; border: 1px solid var(--border-strong); border-radius: 6px; box-shadow: var(--shadow-sm); background: var(--surface-muted); }
figure.shot figcaption { font-size: 13px; color: var(--text-muted); margin-top: 9px; }

/* ── diagrams ───────────────────────────────────────────────────────────────
 * Education is taught in pictures. Figures are hand-drawn inline SVG rather than
 * screenshots: a diagram can show a mechanism a screenshot cannot, it stays sharp at
 * any size, and it follows the theme because every stroke and fill reads a CSS variable
 * instead of a baked-in colour.
 */
.fig { margin: 30px 0; }
.fig svg { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-sunk); }
.fig figcaption { font-size: 13.5px; line-height: 1.55; color: var(--text-secondary); margin-top: 10px; }
.fig figcaption b { color: var(--text-heading); font-weight: 600; }

/* The drawing palette. Every figure uses these classes, so one change restyles them all. */
svg .d-ink { fill: var(--text-heading); }
svg .d-sub { fill: var(--text-secondary); }
svg .d-mute { fill: var(--text-muted); }
svg .d-line { stroke: var(--border-bright); fill: none; stroke-width: 1.5; }
svg .d-axis { stroke: var(--border-strong); fill: none; stroke-width: 1.5; }
svg .d-grid { stroke: var(--border); fill: none; stroke-width: 1; }
svg .d-box { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.5; }
svg .d-box-b { fill: var(--brand-soft); stroke: var(--brand); stroke-width: 1.5; }
svg .d-box-a { fill: var(--accent-soft); stroke: var(--accent-border); stroke-width: 1.5; }
svg .d-fill-b { fill: var(--brand); }
svg .d-fill-a { fill: var(--accent); }
svg .d-on-a { fill: var(--on-accent); }
svg .d-stroke-b { stroke: var(--brand); fill: none; stroke-width: 2; }
svg .d-stroke-a { stroke: var(--accent); fill: none; stroke-width: 2; }
svg .d-pos { fill: #0f7b4f; } svg .d-neg { fill: #ce0d0d; }
svg .d-stroke-pos { stroke: #0f7b4f; fill: none; stroke-width: 2; }
svg .d-stroke-neg { stroke: #ce0d0d; fill: none; stroke-width: 2; }

/* The semantic pair keeps its hue across themes so a gain always reads as a gain. The light
   values sit at roughly 3.5:1 on the dark ground though, which is under the bar for the
   label-sized text the figures use them on, so dark gets lifted variants of the same hues. */
:root[data-theme="dark"] svg .d-pos { fill: #3ddc97; }
:root[data-theme="dark"] svg .d-neg { fill: #ff6b6b; }
:root[data-theme="dark"] svg .d-stroke-pos { stroke: #3ddc97; }
:root[data-theme="dark"] svg .d-stroke-neg { stroke: #ff6b6b; }
svg .d-t { font-family: var(--sans); font-size: 13px; }
svg .d-t-sm { font-family: var(--sans); font-size: 11.5px; }
svg .d-n { font-family: var(--mono); font-size: 12px; }
svg .d-dash { stroke-dasharray: 4 4; }

/* a worked example, set apart from the running text */
.example { margin: 28px 0; border: 1px solid var(--border-strong); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; padding: 18px 22px; background: var(--surface-sunk); }
.example > :first-child { margin-top: 0; } .example > :last-child { margin-bottom: 0; }
.example .ex-k { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; }

/* key takeaways at the end of a chapter */
.takeaway { margin: 36px 0 0; padding: 22px 24px; border-radius: 8px; background: var(--brand-soft); border: 1px solid var(--border-strong); }
.takeaway h4 { margin: 0 0 10px; font-size: 15px; }
.takeaway ul { margin: 0; padding-left: 20px; }
.takeaway li { margin: 7px 0; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 26px 0; }
.card { display: block; padding: 20px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); text-decoration: none; box-shadow: var(--shadow-sm); transition: box-shadow 0.2s ease, border-color 0.2s ease; }
.card:hover { box-shadow: var(--shadow-md); border-color: var(--border-bright); }
.card .c-k { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
.card .c-t { font-size: 17px; font-weight: 600; color: var(--text-heading); margin-top: 7px; }
.card .c-d { font-size: 14px; line-height: 1.5; color: var(--text-secondary); margin-top: 5px; }

/* badges */
.badge { display: inline-block; font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; padding: 3px 8px; border-radius: 9999px; vertical-align: middle; }
.badge.soon { background: var(--accent); color: var(--on-accent); }
.badge.grp { background: var(--brand-soft); color: var(--brand-ink); }

/* prev / next */
.pager { display: flex; gap: 16px; margin-top: 60px; padding-top: 26px; border-top: 1px solid var(--border); }
.pager a { flex: 1 1 0; min-width: 0; padding: 15px 18px; border: 1px solid var(--border-strong); border-radius: 8px; text-decoration: none; }
.pager a:hover { border-color: var(--border-bright); box-shadow: var(--shadow-sm); }
.pager .p-k { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.pager .p-t { font-size: 15px; font-weight: 600; color: var(--text-heading); margin-top: 4px; }
.pager a.next { text-align: right; }


/* footer */
.ftr { border-top: 1px solid var(--border); background: var(--surface-muted); padding: 40px 48px; }
.ftr-in { display: flex; justify-content: space-between; gap: 28px; flex-wrap: wrap; }
.ftr a { color: var(--text-secondary); text-decoration: none; font-size: 14px; display: block; padding: 3px 0; }
.ftr a:hover { color: var(--text-heading); }
.ftr h5 { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--text-muted); margin: 0 0 9px; font-weight: 500; }
.ftr .note-sm { font-size: 12.5px; color: var(--text-muted); max-width: 46ch; line-height: 1.55; }

/* ── responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav { position: fixed; inset: var(--header-h) auto 0 0; width: 300px; background: var(--surface); border-right: 1px solid var(--border-strong); box-shadow: var(--shadow-lg); transform: translateX(-100%); transition: transform 0.2s ease; z-index: 45; }
  .nav.open { transform: none; }
  .nav-btn { display: grid; }
  main { padding: 28px 20px 72px; }
  .ftr { padding: 32px 20px; }
  h1 { font-size: 31px; }
  h2 { font-size: 24px; margin-top: 40px; }
  .hdr { padding: 0 16px; gap: 12px; }
  .hdr-link { display: none; }
  .search { flex: 1 1 auto; }
  .search kbd { display: none; }
}
