/*
 * Compound Engineer — design tokens ("Compound Curve" brand system v1.0).
 * Source of truth for colour, type and shape. Values come from design/canvas/Main.dc.html.
 * Theme is chosen by <html data-theme="light|dark">, set before first paint in BaseLayout.
 */

:root {
  /* Type */
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Layout */
  /* 80% of the window, never narrower than 1080px (the on-screen width the site had at its old 90% zoom). */
  --container: max(1080px, 80vw);
  --gutter: 24px;

  /* Radii */
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 14px;
  --r-2xl: 18px;
  --r-3xl: 24px;
  --r-pill: 999px;

  /* Light theme (default) */
  color-scheme: light;
  --bg: #F7F7F4;            /* Paper — ground */
  --surface: #FFFFFF;       /* Surface — cards */
  --sunken: #EFEFEA;
  --line: #E2E2DC;          /* Rule — borders */
  --field: #CFCFC7;         /* Input borders */
  --ink: #111418;           /* Ink — text, mark */
  --ink-2: #2A2F37;
  --muted: #5B6270;         /* Graphite — secondary */
  --signal: #E8590C;        /* Signal — accent, CTA */
  --signal-text: #B5420A;   /* Signal text — links */
  --signal-soft: #E8590C1A;
  --on-signal: #111418;

  --mark-bg: #111418;
  --mark-fg: #F7F7F4;

  --inv: #111418;           /* Inverted panels (CTA bands) */
  --inv-line: #111418;
  --inv-ink: #F7F7F4;
  --inv-muted: #A3AAB6;

  --btn-bg: #111418;        /* Ink button */
  --btn-ink: #F7F7F4;

  --free: #0B6E55;
  --free-soft: #0E8A6A17;
  --medium: #B45309;

  --code-bg: #111418;
  --code-line: #111418;
  --code-ink: #E6E8EC;
  --dot: #E2E2DC;
  --bar: #C9CCD2;
  --panel: #EDEDE7;         /* Login side panel */

  /* Newsletter banner */
  --banner-bg: #111418;
  --banner-ink: #F7F7F4;
  --banner-link: #FF8A4C;
  --banner-muted: #A3AAB6;

  /* Diagram palette — one colour per node role, used across every lesson */
  --client: #5B6270;
  --svc: #2563EB;   --svc-text: #1D4FC4;   --svc-soft: #2563EB14;   --svc-fill: #EAF0FD;
  --cache: #7C3AED; --cache-text: #6A2BD6; --cache-soft: #7C3AED14;
  --db: #0E8A6A;    --db-text: #0B6E55;    --db-soft: #0E8A6A14;
  --queue: #B45309; --queue-text: #95450A; --queue-soft: #B4530914;
  /* Rejected / wrong / error — used by step-through players (DSA lessons) */
  --bad: #C8382B;   --bad-text: #A92B1F;   --bad-soft: #C8382B14;

  --shadow: 0 30px 60px -36px rgba(17, 20, 24, 0.35);
  --shadow-menu: 0 24px 48px -28px rgba(17, 20, 24, 0.35);
  --shadow-chip: 0 1px 2px rgba(17, 20, 24, 0.12);
  --shadow-signal: 0 30px 60px -40px rgba(232, 89, 12, 0.45);
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0D0F12;
  --surface: #15181D;
  --sunken: #1E2228;
  --line: #272C34;
  --field: #363C46;
  --ink: #EDEEF0;
  --ink-2: #C9CDD4;
  --muted: #9AA2AE;
  --signal: #FF6A1F;
  --signal-text: #FF8A4C;
  --signal-soft: #FF6A1F1F;

  --mark-bg: #F7F7F4;
  --mark-fg: #111418;

  --inv: #15181D;
  --inv-line: #272C34;
  --inv-ink: #EDEEF0;
  --inv-muted: #9AA2AE;

  --btn-bg: #EDEEF0;
  --btn-ink: #111418;

  --free: #34C79E;
  --free-soft: #34C79E1F;
  --medium: #E8963A;

  --code-bg: #0A0B0D;
  --code-line: #272C34;
  --dot: #232830;
  --bar: #3A404A;
  --panel: #15181D;

  --banner-bg: #1E2228;
  --banner-ink: #EDEEF0;
  --banner-muted: #9AA2AE;

  --client: #9AA2AE;
  --svc: #6B9BFF;   --svc-text: #8DB3FF;   --svc-soft: #6B9BFF1F;   --svc-fill: #1A2335;
  --cache: #A685FF; --cache-text: #B89DFF; --cache-soft: #A685FF1F;
  --db: #34C79E;    --db-text: #34C79E;    --db-soft: #34C79E1F;
  --queue: #E8963A; --queue-text: #F0A95A; --queue-soft: #E8963A1F;
  --bad: #FF7B6B;   --bad-text: #FF9C8F;   --bad-soft: #FF7B6B1F;

  --shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.7);
  --shadow-menu: 0 24px 48px -24px rgba(0, 0, 0, 0.75);
  --shadow-chip: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-signal: 0 30px 70px -40px rgba(255, 106, 31, 0.45);
}

/*
 * Base styles for article documents (served as /article.css together with tokens.css).
 * Articles run inside a frame on the article page, so nothing here can leak into the site.
 * Everything is optional: an article can use these classes, plain HTML, or its own <style>.
 */

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.ce-article {
  margin: 0;
  padding: 0 0 8px;
  background: var(--bg);
  color: var(--ink-2);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

.ce-article *,
.ce-article *::before,
.ce-article *::after {
  box-sizing: border-box;
}

.ce-article :where(h2, h3, h4) {
  color: var(--ink);
  font-family: var(--font-display);
  letter-spacing: -0.025em;
  text-wrap: balance;
  scroll-margin-top: 24px;
}

.ce-article :where(h2) {
  margin: 48px 0 16px;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.15;
}

.ce-article :where(h3) {
  margin: 36px 0 12px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.ce-article > :where(:first-child),
.ce-article :where(article, section, main) > :where(:first-child) {
  margin-top: 0;
}

.ce-article :where(p, ul, ol, figure, pre, table, blockquote) {
  margin: 0 0 24px;
}

.ce-article :where(p) {
  text-wrap: pretty;
}

/* The article frame is as wide as the page allows, so text keeps a readable line length
   while figures, players, videos, code and tables use the full width. */
.ce-article :where(p, ul, ol, h2, h3, h4, blockquote) {
  max-width: 960px;
}

.ce-article :where(ul, ol) {
  padding-left: 1.3em;
}

.ce-article :where(li + li) {
  margin-top: 6px;
}

.ce-article :where(a) {
  color: var(--signal-text);
  font-weight: 500;
}

.ce-article :where(strong, b) {
  color: var(--ink);
  font-weight: 600;
}

.ce-article :where(code) {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--sunken);
  padding: 2px 6px;
  border-radius: 4px;
}

.ce-article :where(h2 code, h3 code) {
  background: none;
  padding: 0;
  font-weight: 500;
}

/* Code blocks: <pre><code>…</code></pre> */
.ce-article :where(pre) {
  overflow-x: auto;
  padding: 18px 22px;
  border-radius: var(--r-xl);
  border: 1px solid var(--code-line);
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.75;
}

.ce-article :where(pre code) {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* Token colours for hand-highlighted code: <span class="kw">return</span> */
.ce-article pre .kw { color: #FF8A4C; }
.ce-article pre .ty { color: #8DB3FF; }
.ce-article pre .fn { color: #F2C462; }
.ce-article pre .num { color: #5FD4AE; }
.ce-article pre .str { color: #5FD4AE; }
.ce-article pre .com { color: #8D95A3; }

.ce-article :where(blockquote) {
  padding-left: 18px;
  border-left: 3px solid var(--line);
  color: var(--ink-2);
}

/* Figures: <figure class="figure"><div class="figure-body">…</div><figcaption>…</figcaption></figure> */
.ce-article .figure {
  margin: 8px 0 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ce-article .figure-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  overflow-x: auto;
}

.ce-article :where(figcaption) {
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

.ce-article :where(figcaption b) {
  color: var(--ink);
}

/* Callouts: <div class="callout"><span class="callout-label">Interview tip</span><p>…</p></div> */
.ce-article .callout {
  margin: 8px 0 28px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface);
}

.ce-article .callout > :last-child {
  margin-bottom: 0;
}

.ce-article .callout p {
  font-size: 16px;
  line-height: 1.65;
}

.ce-article .callout-label {
  display: block;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--signal-text);
}

/* Diagram nodes, one colour per role: <span class="node node-svc">API</span> */
.ce-article .node {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.ce-article .node small {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

.ce-article .node-client { border-color: var(--client); }
.ce-article .node-svc { border-color: var(--svc); background: var(--svc-soft); }
.ce-article .node-cache { border-color: var(--cache); background: var(--cache-soft); }
.ce-article .node-db { border-color: var(--db); background: var(--db-soft); }
.ce-article .node-queue { border-color: var(--queue); background: var(--queue-soft); }
.ce-article .node-focus { border: 2px solid var(--signal); }

.ce-article .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

/* Tables */
.ce-article :where(table) {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.5;
  display: block;
  overflow-x: auto;
}

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

.ce-article :where(th) {
  color: var(--ink);
  font-weight: 600;
  border-bottom: 2px solid var(--ink);
}

.ce-article :where(img, svg, video) {
  max-width: 100%;
  height: auto;
}

@media (max-width: 600px) {
  body.ce-article {
    font-size: 17px;
  }
  .ce-article :where(h2) {
    font-size: 27px;
  }
  .ce-article .figure-body {
    padding: 16px;
  }
}
