/* Fonts
   ────────────────────────────────────────────────────────────────────────── */

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/IBMPlexSans-Regular.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/IBMPlexSans-Italic.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Regular.woff2") format("woff2");
}


/* Tokens
   ────────────────────────────────────────────────────────────────────────── */

/* Palette slots are taken from Catppuccin Latte (light) / Macchiato (dark).
   New colours pick a named slot, paired across both palettes — no hand-mixing. */
:root {
  color-scheme: light dark;

  --base:    light-dark(#eff1f5, #24273a);
  --mantle:  light-dark(#e6e9ef, #1e2030);
  --text:    light-dark(#4c4f69, #cad3f5);
  --subtext: light-dark(#6c6f85, #a5adcb);
  --overlay: light-dark(#9ca0b0, #6e738d);
  --accent:  light-dark(#1e66f5, #8aadf4);
  --heading: light-dark(#e64553, #c6a0f6);
  --rule:    light-dark(#bcc0cc, #494d64);

  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI",
               sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo,
               Consolas, monospace;

  /* Type scale (roughly 1.2 ratio, anchored at --fs-base) */
  --fs-xs:   0.8125rem;
  --fs-sm:   0.875rem;
  --fs-base: 1rem;
  --fs-md:   1.2rem;
  --fs-lg:   1.44rem;
  --fs-xl:   1.728rem;

  --leading-tight: 1.25;

  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 1rem;
  --sp-4: 1.5rem;
  --sp-5: 2rem;
  --sp-6: 3rem;

  --measure:      600px;   /* prose column — px so font choice doesn't move it */
  --measure-code: 1200px;  /* upper bound for code-block stretch (~120 cols) */

  --code-radius:      6px;
  --hairline:         1px solid var(--rule);
  --anchor-clearance: 4rem;   /* keep anchor-linked headings clear of sticky breadcrumb */
}


/* Reset
   ────────────────────────────────────────────────────────────────────────── */

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  background: var(--base);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.6;

  /* Sticky-footer scaffold: header / main / footer with main absorbing
     extra space so the footer rests at the bottom of the viewport on
     short pages and at the bottom of content on long ones. */
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

img, svg { max-width: 100%; height: auto; }

::selection {
  background: var(--accent);
  color: var(--base);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0s !important;
    animation-duration:  0s !important;
  }
}


/* Layout
   ────────────────────────────────────────────────────────────────────────── */

.breadcrumb {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--mantle);
  border-bottom: var(--hairline);
  font-size: var(--fs-sm);
  color: var(--subtext);
  padding-inline: var(--sp-3);   /* safety gutter for narrow viewports */

  nav {
    max-width: var(--measure);
    margin: 0 auto;
    padding-block: var(--sp-2);  /* vertical only — horizontal lives on .breadcrumb */
  }

  a                            { color: var(--subtext); text-decoration: none; }
  a:is(:hover, :focus-visible) { color: var(--accent);  text-decoration: underline; }
  .sep                         { margin: 0 var(--sp-1); color: var(--overlay); }
  [aria-current="page"]        { color: var(--text); }
}

nav ul {
  list-style: none;
  padding-left: 0;
}

main {
  width: 100%;
  max-width: var(--measure-code);
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-3) var(--sp-6);
}

/* Three-track grid: gutter / prose at --measure / gutter, with a `wide`
   span across all three for elements that need to break out. Sections
   dissolve so their children participate in the grid directly. */
article {
  display: grid;
  grid-template-columns:
    [wide-start]    minmax(0, 1fr)
    [content-start] min(100%, var(--measure)) [content-end]
                    minmax(0, 1fr)            [wide-end];
}

article > section { display: contents; }

/* :where() holds specificity at zero so the relaxed-width rule wins cleanly. */
:where(article > *, article > section > *) { grid-column: content; }

/* Relaxed width: drop the prose-column constraint. Sit at natural width,
   floored at prose, capped at the wide lane. `pre` opts in by default
   (long code lines are the common case); other elements opt in by
   carrying class="relaxed-width" — figures, images, tables, etc. */
:where(article > *, article > section > *):is(pre, .relaxed-width) {
  grid-column: wide;
  justify-self: center;
  width: max-content;
  min-width: min(var(--measure), 100%);
  max-width: 100%;
}

.page-footer {
  font-size: var(--fs-xs);
  color: var(--subtext);
  border-top: var(--hairline);
  padding: var(--sp-4) var(--sp-3) var(--sp-5);

  .inner {
    max-width: var(--measure);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    align-items: center;
    gap: var(--sp-3);
    text-align: center;

    & > :first-child { text-align: start; }
    & > :last-child  { text-align: end; }
  }

  a, a:visited { color: inherit; text-decoration: none; }
  a:hover      { text-decoration: underline; }
}


/* Typography
   ────────────────────────────────────────────────────────────────────────── */

.page-head { margin-bottom: var(--sp-5); }
.meta {
  margin: 0;
  color: var(--subtext);
  font-size: var(--fs-sm);
}

h1, h2 {
  font-weight: 600;
  line-height: var(--leading-tight);
  color: var(--heading);
}

h1 {
  font-size: var(--fs-xl);
  margin: 0 0 var(--sp-2);
  letter-spacing: -0.01em;
}

h2 {
  font-size: var(--fs-lg);
  margin: var(--sp-6) 0 var(--sp-3);
  letter-spacing: -0.005em;
  scroll-margin-top: var(--anchor-clearance);
}

h3 {
  font-size: var(--fs-md);
  font-weight: 600;
  margin: var(--sp-5) 0 var(--sp-2);
  scroll-margin-top: var(--anchor-clearance);
}

p { margin: 0 0 var(--sp-3); }

strong { font-weight: 600; }   /* UA default is 700; we ship SemiBold (600) */


/* Components
   ────────────────────────────────────────────────────────────────────────── */

a {
  color: var(--accent);
  text-underline-offset: 0.15em;

  &:visited { color: var(--overlay); }
  &:hover   { text-decoration-thickness: 2px; }
  &:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
}

/* Heading anchor — hidden, revealed on hover/focus of the heading. */
:is(h2, h3) .anchor {
  margin-left: var(--sp-2);
  color: var(--overlay);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
}
:is(h2, h3):is(:hover, :focus-within) .anchor,
.anchor:focus-visible { opacity: 1; }

code, pre, .formula { font-family: var(--font-mono); }

code, pre {
  background: var(--mantle);
  border: var(--hairline);
  border-radius: var(--code-radius);
}

code {
  font-size: 0.92em;
  padding: 0.1em 0.32em;
}

pre {
  font-size: var(--fs-sm);
  line-height: 1.5;
  padding: var(--sp-3);
  margin: var(--sp-4) 0;
  overflow-x: auto;
  tab-size: 2;
}

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

.formula {
  font-size: var(--fs-base);
  text-align: center;
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-4) 0;
  border-block: var(--hairline);
}

ol.cases {
  list-style: decimal;
  padding-left: var(--sp-4);
  margin: var(--sp-3) 0 var(--sp-4);

  li {
    margin: var(--sp-1) 0;
    padding-left: var(--sp-1);

    &::marker { color: var(--subtext); }
  }
}

figure { margin: var(--sp-5) 0; }
.diagram {
  display: block;
  width: 100%;
  height: auto;
  font-family: var(--font-mono);   /* inherited by SVG <text> children */
}
.diagram-axis, .diagram-ticks line { stroke: var(--overlay); stroke-width: 1; }
.diagram-interval line              { stroke: var(--text);    stroke-width: 2; }
.diagram-ticks text { font-size: 11px; fill: var(--subtext); }
.diagram-label      { font-size: 12px; fill: var(--text); }

figcaption {
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--subtext);
  line-height: 1.5;
}
