/* ==== index.css ==== */
/*
 * luismasg.com — stylesheet entry.
 * Plain CSS, no preprocessor. Files are concatenated in this order at build time
 * and shipped unminified, so what you read in DevTools is what is in the repo.
 *
 * Layer order: later layers win, regardless of selector specificity.
 */
@layer reset, tokens, base, layout, components, utilities, enhancements;

/* ==== reset.css ==== */
/* reset.css — a small modern reset. */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body, h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol, table { margin: 0; }
  ul[class], ol[class] { list-style: none; padding: 0; }
  img, svg { display: block; max-width: 100%; }
  table { border-collapse: collapse; }
  button { font: inherit; }
}

/* ==== tokens.css ==== */
/*
 * tokens.css — the whole palette comes from one hue.
 * --hue is soldermask green. Every color is OKLCH, so lightness steps are
 * perceptually even and contrast is predictable across hues.
 *
 * Light theme: a datasheet printed on paper.
 * Dark theme: the same document opened in a schematic editor.
 */
@layer tokens {
  :root {
    --hue: 155;

    /* Raw values: -l for light, -d for dark. */
    --paper-l: oklch(98.6% 0.004 var(--hue));
    --paper-d: oklch(19% 0.014 var(--hue));
    --ink-l: oklch(21% 0.016 var(--hue));
    --ink-d: oklch(93% 0.012 var(--hue));
    --muted-l: oklch(44% 0.016 var(--hue));
    --muted-d: oklch(74% 0.018 var(--hue));
    --rule-l: oklch(86% 0.008 var(--hue));
    --rule-d: oklch(33% 0.018 var(--hue));
    --rule-strong-l: oklch(60% 0.012 var(--hue));
    --rule-strong-d: oklch(52% 0.02 var(--hue));
    --accent-l: oklch(47% 0.12 var(--hue));
    --accent-d: oklch(80% 0.16 var(--hue));
    --surface-l: oklch(100% 0 0);
    --surface-d: oklch(23% 0.016 var(--hue));
    --chip-l: oklch(23% 0.012 var(--hue));
    --chip-d: oklch(29% 0.03 var(--hue));
    --chip-ink-l: oklch(95% 0.005 var(--hue));
    --chip-ink-d: oklch(93% 0.012 var(--hue));
    --pin-l: oklch(74% 0.01 90);
    --pin-d: oklch(68% 0.09 var(--hue));

    /* Fallback for browsers without light-dark(): follow the system theme. */
    --paper: var(--paper-l); --ink: var(--ink-l); --muted: var(--muted-l); --rule: var(--rule-l);
    --rule-strong: var(--rule-strong-l); --accent: var(--accent-l); --surface: var(--surface-l);
    --chip: var(--chip-l); --chip-ink: var(--chip-ink-l); --pin: var(--pin-l);

    color-scheme: light dark;
    accent-color: var(--accent);

    --font: 'Mona Sans', system-ui, sans-serif;
    --measure: 66ch;
    --gap: clamp(1.25rem, 1rem + 1.5vw, 2.25rem);
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --paper: var(--paper-d); --ink: var(--ink-d); --muted: var(--muted-d); --rule: var(--rule-d);
      --rule-strong: var(--rule-strong-d); --accent: var(--accent-d); --surface: var(--surface-d);
      --chip: var(--chip-d); --chip-ink: var(--chip-ink-d); --pin: var(--pin-d);
    }
  }

  /* light-dark() lets the theme toggle override the system preference. */
  @supports (color: light-dark(#000, #fff)) {
    :root {
      --paper: light-dark(var(--paper-l), var(--paper-d));
      --ink: light-dark(var(--ink-l), var(--ink-d));
      --muted: light-dark(var(--muted-l), var(--muted-d));
      --rule: light-dark(var(--rule-l), var(--rule-d));
      --rule-strong: light-dark(var(--rule-strong-l), var(--rule-strong-d));
      --accent: light-dark(var(--accent-l), var(--accent-d));
      --surface: light-dark(var(--surface-l), var(--surface-d));
      --chip: light-dark(var(--chip-l), var(--chip-d));
      --chip-ink: light-dark(var(--chip-ink-l), var(--chip-ink-d));
      --pin: light-dark(var(--pin-l), var(--pin-d));
    }
  }

  /* The toggle writes <meta name="color-scheme">; CSS follows it. */
  :root:has(> head > meta[name="color-scheme"][content="dark"]) { color-scheme: dark; }
  :root:has(> head > meta[name="color-scheme"][content="light"]) { color-scheme: light; }
}

/* ==== functions.css ==== */
/*
 * functions.css — custom CSS functions (@function, CSS Functions and Mixins Module).
 * Chromium-only for now. Every declaration that calls one is preceded by a plain
 * fallback; browsers without @function drop the call at parse time and keep the fallback.
 *
 * --t is a 0→1 progress value: how far the page container is between 22rem and 80rem.
 */

/* Linear interpolation between two numbers. */
@function --lerp(--a <number>, --b <number>, --t <number>) returns <number> {
  result: calc(var(--a) + (var(--b) - var(--a)) * var(--t));
}

/* Fluid size in rem, driven by the container progress --t. */
@function --fluid(--min <number>, --max <number>) returns <length> {
  result: calc(--lerp(var(--min), var(--max), var(--t)) * 1rem);
}

/* Used by the colophon to prove, without JavaScript, that @function runs here. */
@function --shown() { result: inline; }
@function --hidden() { result: none; }

/* ==== base.css ==== */
/* base.css — type, rhythm and the --t progress value. */
@font-face {
  font-family: 'Mona Sans';
  font-style: normal;
  font-display: swap;
  font-weight: 200 900;
  font-stretch: 75% 125%;
  src: url(/fonts/mona-sans-latin-wdth-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Mona Sans';
  font-style: normal;
  font-display: swap;
  font-weight: 200 900;
  font-stretch: 75% 125%;
  src: url(/fonts/mona-sans-latin-ext-wdth-normal.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@layer base {
  body {
    background: var(--paper);
    color: var(--ink);
    font: 400 1.0625rem/1.6 var(--font);
    font-stretch: 100%;
  }

  /* Progress through the layout: 0 at 22rem wide, 1 at 80rem.
     Stepped fallback first; real interpolation where typed calc() division exists. */
  .page { --t: 0.5; }
  @container page (width < 40rem) { .page * { --t: 0; } }
  @container page (width > 64rem) { .page * { --t: 1; } }
  @supports (scale: calc(1px / 1px)) {
    .page * { --t: clamp(0, (100cqi - 22rem) / 58rem, 1); }
  }

  h1, h2, h3, h4 { line-height: 1.1; text-wrap: balance; }
  p, li, dd, td { text-wrap: pretty; }
  a { color: var(--accent); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
  a:hover { text-decoration-thickness: 2px; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
  ::selection { background: var(--accent); color: var(--paper); }
  code { font: inherit; font-weight: 600; }
  time, .num { font-variant-numeric: tabular-nums; }
}

/* ==== layout.css ==== */
/* layout.css — the datasheet grid: a label column and a content column. */
@layer layout {
  .page {
    container: page / inline-size;
    width: min(100% - 2 * var(--gap), 76rem);
    margin-inline: auto;
  }

  .sheet {
    display: grid;
    grid-template-columns: minmax(11rem, 15rem) minmax(0, 1fr);
    column-gap: clamp(1.5rem, 4vw, 4rem);
    padding-block: 2.25rem;
    border-top: 1px solid var(--rule);
    scroll-margin-top: 1rem;
  }
  .sheet > h2 { grid-column: 1; align-self: start; position: sticky; top: 1.25rem; }
  .sheet > :not(h2) { grid-column: 2; }

  @container page (width < 46rem) {
    .sheet { grid-template-columns: 1fr; row-gap: 1.25rem; }
    .sheet > h2 { position: static; }
    .sheet > :not(h2) { grid-column: 1; }
  }
}

/* ==== components/sheet.css ==== */
/* sheet.css — section headings: plain name first, the datasheet term second. */
@layer components {
  .sheet > h2 { font-size: 1.375rem; font-weight: 750; font-stretch: 90%; }
  .sheet > h2 .ds { display: block; margin-top: 0.3rem; font-size: 0.875rem; font-weight: 500; font-stretch: 100%; color: var(--muted); }
}

/* ==== components/masthead.css ==== */
/* masthead.css — the datasheet header: maker line, part number, name, role, description. */
@layer components {
  @scope (.masthead) {
    :scope { padding-block: 1rem clamp(1.5rem, 5vw, 3rem); }

    .maker {
      display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem 2rem;
      padding-block: 0.75rem; border-bottom: 2px solid var(--ink); font-size: 0.9375rem;
    }
    .maker ul { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }
    .maker a { color: var(--ink); }
    .langs a, .langs strong { padding: 0.15rem 0.4rem; }
    .langs strong { box-shadow: inset 0 -2px 0 var(--accent); }

    .part { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; margin-top: 1.75rem; color: var(--muted); font-size: 0.9375rem; }
    .part b { color: var(--ink); font-weight: 700; letter-spacing: 0.04em; }

    h1 {
      margin-top: 0.5rem;
      font-weight: 800;
      letter-spacing: -0.02em;
      line-height: 0.95;
      font-size: calc(2.3rem + 2.3rem * var(--t));
      font-size: --fluid(2.3, 4.6);
      font-stretch: 92%;
      font-stretch: calc(--lerp(78, 112, var(--t)) * 1%);
    }
    .role { margin-top: 0.6rem; font-size: 1.375rem; font-weight: 600; font-stretch: 96%; }
    .description { margin-top: 1.25rem; max-width: var(--measure); font-size: 1.125rem; }
    .actions { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-top: 1.25rem; }
    .actions .primary { font-weight: 700; }
  }
}

/* ==== components/features.css ==== */
/* features.css — the first-page bullet list every datasheet opens with. */
@layer components {
  @scope (.features) {
    :scope { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); gap: 0.85rem 2.5rem; }
    li { position: relative; padding-left: 1.25rem; }
    li::before { content: ""; position: absolute; left: 0; top: 0.62em; width: 0.5rem; height: 0.5rem; background: var(--accent); }
    a { color: var(--ink); text-decoration: none; }
    a:hover { text-decoration: underline; }
  }
}

/* ==== components/pinout.css ==== */
/*
 * pinout.css — the skills chip, drawn as a DIP-16 package.
 * Pins 1–8 run down the left side, 9–16 run back up the right side, like a real datasheet.
 * Positions come from sibling-index() where supported; an inline --n is the fallback.
 */
@layer components {
  @scope (.pinout) {
    :scope { display: grid; justify-items: center; gap: 1.5rem; }

    .chip {
      --pin-h: 2.25rem;
      display: grid;
      grid-template-columns: 1fr auto minmax(7rem, 9rem) auto 1fr;
      grid-template-rows: repeat(8, var(--pin-h));
      width: min(100%, 40rem);
      font-size: 0.9375rem;
    }
    .body {
      grid-column: 3; grid-row: 1 / -1;
      position: relative;
      display: grid; place-content: center; text-align: center; gap: 0.2rem;
      background: var(--chip); color: var(--chip-ink);
      border-radius: 6px;
      padding-inline: 0.5rem;
    }
    /* The notch and the pin-1 dot. */
    .body::before { content: ""; position: absolute; top: -1px; left: 50%; width: 1.6rem; height: 0.8rem; translate: -50% 0; background: var(--paper); border-radius: 0 0 999px 999px; }
    .body::after { content: ""; position: absolute; top: 0.9rem; left: 0.9rem; width: 0.45rem; height: 0.45rem; border-radius: 50%; background: var(--chip-ink); opacity: 0.7; }
    .body b { font-size: 1.125rem; letter-spacing: 0.06em; font-stretch: 85%; }
    .body span { font-size: 0.8125rem; opacity: 0.8; }

    .pins { display: contents; }
    .pin { display: contents; }
    .pin a {
      display: flex; align-items: center; gap: 0.5rem;
      color: var(--ink); text-decoration: none; white-space: nowrap;
      padding-inline: 0.35rem;
    }
    .pin a:hover .name, .pin a:focus-visible .name { color: var(--accent); text-decoration: underline; }
    .num { font-size: 0.75rem; color: var(--muted); min-width: 1.3rem; text-align: center; }
    .leg { flex-shrink: 0; width: 1.1rem; height: 0.55rem; background: var(--pin); border-radius: 1px; }

    /* Left side: pins 1–8, top to bottom. */
    .pin:nth-child(-n + 8) a { grid-column: 1 / 3; grid-row: var(--n); justify-content: flex-end; }
    /* Right side: pins 9–16, bottom to top. */
    .pin:nth-child(n + 9) a { grid-column: 4 / 6; grid-row: calc(17 - var(--n)); flex-direction: row-reverse; justify-content: flex-end; }
  }

  /* With sibling-index(), the markup does not need the inline --n at all. */
  @supports (order: sibling-index()) {
    @scope (.pinout) {
      .pin { --n: sibling-index(); }
    }
  }

  @container page (width < 34rem) {
    @scope (.pinout) {
      .chip { --pin-h: 1.9rem; grid-template-columns: 1fr auto minmax(3.75rem, 4.5rem) auto 1fr; font-size: 0.75rem; }
      .pin a { gap: 0.3rem; padding-inline: 0.15rem; }
      .leg { width: 0.7rem; }
      .num { min-width: 1rem; }
      .body b { font-size: 0.9375rem; }
      .body span { display: none; }
    }
  }
}

/* Registered so sibling-index() is computed on the <li>, not on the link inside it. */
@property --n {
  syntax: '<integer>';
  inherits: true;
  initial-value: 1;
}

/*
 * The package outline as one shape: rounded corners and the notch at the top, drawn with
 * border-shape: shape(). The real background shows through the notch (including the dot grid
 * of the dark theme). Where border-shape is missing, the ::before notch above is the fallback.
 */
@layer enhancements {
  @supports (border-shape: shape(from 0 0, line to 1px 1px, close)) {
    @scope (.pinout) {
      .body {
        --r: 6px;
        --notch: 0.8rem;
        border-radius: 0;
        border-shape: shape(from var(--r) 0,
          hline to calc(50% - var(--notch)),
          arc to calc(50% + var(--notch)) 0 of var(--notch) ccw,
          hline to calc(100% - var(--r)),
          arc to 100% var(--r) of var(--r) cw,
          vline to calc(100% - var(--r)),
          arc to calc(100% - var(--r)) 100% of var(--r) cw,
          hline to var(--r),
          arc to 0 calc(100% - var(--r)) of var(--r) cw,
          vline to var(--r),
          arc to var(--r) 0 of var(--r) cw,
          close);
      }
      .body::before { content: none; }
    }
  }
}

/* ==== components/pin-table.css ==== */
/* pin-table.css — the pin list in text, with the CV evidence behind each pin. */
@layer components {
  @scope (.pin-table) {
    :scope { display: grid; gap: 0.25rem; width: 100%; }
    li { border-bottom: 1px solid var(--rule); scroll-margin-top: 1rem; }
    li:target { background: color-mix(in oklch, var(--accent) 10%, transparent); }
    summary { display: grid; grid-template-columns: 2.5rem minmax(0, 1fr) auto 1rem; gap: 1rem; align-items: baseline; padding-block: 0.6rem; cursor: pointer; list-style: none; }
    summary::-webkit-details-marker { display: none; }
    summary .n { color: var(--muted); font-variant-numeric: tabular-nums; }
    summary .count { color: var(--muted); font-size: 0.875rem; }
    summary::after { content: "+"; justify-self: end; color: var(--muted); }
    details[open] summary::after { content: "–"; }
    ul { padding: 0 0 0.9rem 3.5rem; display: grid; gap: 0.35rem; max-width: calc(var(--measure) + 3.5rem); }
    ul li { border: 0; list-style: disc; }
    .status { color: var(--muted); font-size: 0.875rem; }
  }
  @container page (width < 34rem) {
    @scope (.pin-table) {
      summary { grid-template-columns: 2rem minmax(0, 1fr) 1rem; row-gap: 0.1rem; }
      summary .count { grid-column: 2; grid-row: 2; }
      ul { padding-left: 2rem; }
    }
  }
}

/* ==== components/diagram.css ==== */
/* diagram.css — the block diagram: how the platform is put together and where I sit in it. */
@layer components {
  @scope (.diagram) {
    :scope { display: grid; gap: 1.25rem; }
    .flow { display: grid; grid-template-columns: 1fr auto 1.4fr auto 1fr; align-items: stretch; gap: 0.5rem; }
    .block { border: 1.5px solid var(--ink); background: var(--surface); padding: 0.85rem 1rem; border-radius: 4px; }
    .block b { display: block; font-stretch: 90%; }
    .block span { color: var(--muted); font-size: 0.875rem; }
    .wire { align-self: center; width: 2.25rem; height: 2px; background: var(--ink); position: relative; }
    .wire::after { content: ""; position: absolute; right: -1px; top: -4px; border: 5px solid transparent; border-left-color: var(--ink); border-right: 0; }
    .wire.both::before { content: ""; position: absolute; left: -1px; top: -4px; border: 5px solid transparent; border-right-color: var(--ink); border-left: 0; }

    .bus { border: 1.5px dashed var(--rule-strong); border-radius: 4px; padding: 0.85rem 1rem; }
    .bus > p { font-size: 0.875rem; color: var(--muted); margin-bottom: 0.6rem; }
    .bus ul { display: flex; flex-wrap: wrap; gap: 0.5rem; }
    .bus li { border: 1.5px solid var(--rule-strong); border-radius: 4px; padding: 0.3rem 0.7rem; font-size: 0.9375rem; }
    .bus li.owned { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
    .legend { font-size: 0.875rem; color: var(--muted); }
    .legend i { display: inline-block; width: 0.9rem; height: 0.9rem; vertical-align: -0.1rem; margin-right: 0.35rem; border: 1.5px solid var(--accent); box-shadow: inset 3px 0 0 var(--accent); }

    .principles { display: grid; gap: 0.5rem; max-width: var(--measure); margin-top: 0.5rem; }
    .principles li { padding-left: 1.25rem; position: relative; }
    .principles li::before { content: "→"; position: absolute; left: 0; color: var(--accent); }
  }

  @container page (width < 46rem) {
    @scope (.diagram) {
      .flow { grid-template-columns: 1fr; }
      .wire { justify-self: center; width: 2px; height: 1.5rem; }
      .wire::after { right: -4px; top: auto; bottom: -1px; border: 5px solid transparent; border-top-color: var(--ink); border-bottom: 0; }
      .wire.both::before { left: -4px; top: -1px; border: 5px solid transparent; border-bottom-color: var(--ink); border-top: 0; }
    }
  }
}

/* ==== components/spec-table.css ==== */
/* spec-table.css — the table style shared by conditions, revisions, packages and the colophon. */
@layer components {
  @scope (.spec-table) {
    :scope { width: 100%; font-size: 0.9688rem; }
    caption { text-align: left; color: var(--muted); font-size: 0.875rem; padding-bottom: 0.5rem; }
    th, td { text-align: left; vertical-align: top; padding: 0.6rem 1rem 0.6rem 0; border-bottom: 1px solid var(--rule); }
    thead th { font-weight: 600; font-size: 0.875rem; color: var(--muted); border-bottom: 1.5px solid var(--ink); }
    tbody th { font-weight: 600; }
    td:last-child, th:last-child { padding-right: 0; }
    .rev { font-weight: 800; font-stretch: 85%; width: 3.5rem; }
    .when { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
  }
  @container page (width < 34rem) {
    @scope (.spec-table) {
      .when { white-space: normal; }
    }
  }
}

/* ==== components/revisions.css ==== */
/* revisions.css — experience as a revision history; each revision opens to its change notes. */
@layer components {
  @scope (.revisions) {
    :scope { display: grid; }
    .rev-row { border-bottom: 1px solid var(--rule); scroll-margin-top: 1rem; }
    .rev-row:first-child { border-top: 1.5px solid var(--ink); }
    summary { display: grid; grid-template-columns: 3.5rem minmax(0, 1fr) auto; gap: 0.25rem 1rem; padding-block: 0.85rem; cursor: pointer; list-style: none; align-items: baseline; }
    summary::-webkit-details-marker { display: none; }
    .rev { font-weight: 800; font-stretch: 85%; font-size: 1.125rem; }
    .what b { font-weight: 700; }
    .what span { color: var(--muted); }
    .when { color: var(--muted); font-size: 0.9375rem; text-align: right; }
    .current .rev { color: var(--accent); }
    .notes { padding: 0 0 1.25rem 4.5rem; max-width: calc(var(--measure) + 4.5rem); }
    .notes p { color: var(--muted); }
    .notes ul { display: grid; gap: 0.4rem; margin-top: 0.6rem; padding-left: 1.1rem; list-style: disc; }
    .notes li { scroll-margin-top: 1rem; }
    .notes li:target { background: color-mix(in oklch, var(--accent) 12%, transparent); outline: 1px solid var(--accent); outline-offset: 2px; }
  }
  @container page (width < 34rem) {
    @scope (.revisions) {
      summary { grid-template-columns: 2.75rem 1fr; }
      .when { grid-column: 2; text-align: left; }
      .notes { padding-left: 0; }
    }
  }
}

/* ==== components/notes.css ==== */
/* notes.css — application notes (case studies) and reference designs (side work). */
@layer components {
  @scope (.notes-list) {
    :scope { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 1.25rem; }
    article { border: 1px solid var(--rule); border-top: 3px solid var(--ink); background: var(--surface); padding: 1rem 1.15rem 1.15rem; scroll-margin-top: 1rem; }
    .code { font-size: 0.8125rem; font-weight: 700; letter-spacing: 0.04em; color: var(--muted); }
    h3 { font-size: 1.125rem; margin-top: 0.35rem; font-stretch: 92%; }
    p { margin-top: 0.5rem; }
    ul { margin-top: 0.6rem; display: grid; gap: 0.35rem; padding-left: 1.1rem; list-style: disc; }
    .tags { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; margin-top: 0.85rem; font-size: 0.875rem; color: var(--muted); }
  }
}

/* ==== components/references.css ==== */
/* references.css — recommendations, quoted as written. */
@layer components {
  @scope (.refs) {
    :scope { display: grid; gap: 1.5rem; max-width: var(--measure); }
    blockquote { border-left: 3px solid var(--accent); padding-left: 1.1rem; }
    cite { display: block; margin-top: 0.5rem; font-style: normal; font-weight: 600; }
  }
}

/* ==== components/colophon.css ==== */
/*
 * colophon.css — "How this site is built". Each row says whether YOUR browser
 * supports the feature, decided with CSS only: the "No" shows by default and
 * the "Yes" takes over inside the feature's own test.
 */
@layer components {
  .support .yes { display: none; }
  .support .no { display: inline; color: var(--muted); }
  .support .yes { color: var(--accent); font-weight: 700; }
}
@layer enhancements {
  @supports (color: oklch(from red l c h)) { .s-oklch .yes { display: inline; } .s-oklch .no { display: none; } }
  @supports (color: light-dark(#000, #fff)) { .s-light-dark .yes { display: inline; } .s-light-dark .no { display: none; } }
  @supports selector(:has(a)) { .s-has .yes { display: inline; } .s-has .no { display: none; } }
  @supports (text-wrap: pretty) { .s-text-wrap .yes { display: inline; } .s-text-wrap .no { display: none; } }
  @supports (order: sibling-index()) { .s-sibling-index .yes { display: inline; } .s-sibling-index .no { display: none; } }
  @supports (border-shape: shape(from 0 0, line to 1px 1px, close)) { .s-border-shape .yes { display: inline; } .s-border-shape .no { display: none; } }
  /* Viewport segments: an unknown media feature is false; a known one is true at 1 or 2 segments. */
  @media (horizontal-viewport-segments) { .s-viewport-segments .yes { display: inline; } .s-viewport-segments .no { display: none; } }
  @supports (scale: calc(1px / 1px)) { .s-typed-calc .yes { display: inline; } .s-typed-calc .no { display: none; } }
  @supports (container-type: inline-size) { .s-container .yes { display: inline; } .s-container .no { display: none; } }
  /* @scope has no @supports test: the rule only applies where @scope exists. */
  @scope (.colophon) { .s-scope .yes { display: inline; } .s-scope .no { display: none; } }
  /* @function: the declaration only parses where custom functions exist. */
  .s-function .yes { display: --shown(); }
  .s-function .no { display: --hidden(); }
  /* @layer: this rule lives in a layer, so it only exists where layers do. */
  .s-layer .yes { display: inline; } .s-layer .no { display: none; }
}

/* ==== components/chrome.css ==== */
/* chrome.css — the title block at the bottom, the theme toggle and the language banner. */
@layer components {
  @scope (.title-block) {
    :scope { display: grid; grid-template-columns: 2fr repeat(3, 1fr); border: 1.5px solid var(--ink); margin-block: 2.5rem 1.5rem; font-size: 0.875rem; }
    div { padding: 0.55rem 0.8rem; border-left: 1px solid var(--ink); }
    div:first-child { border-left: 0; }
    span { display: block; color: var(--muted); font-size: 0.75rem; }
    b { font-weight: 700; }
  }
  @container page (width < 40rem) {
    @scope (.title-block) {
      :scope { grid-template-columns: 1fr 1fr; }
      div:nth-child(3) { border-left: 0; }
      div:nth-child(n + 3) { border-top: 1px solid var(--ink); }
    }
  }

  .foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem 2rem; padding-bottom: 3rem; color: var(--muted); font-size: 0.9375rem; }

  .theme-toggle { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--ink); background: var(--surface); border: 1.5px solid var(--ink); border-radius: 4px; padding: 0.45rem 0.85rem; cursor: pointer; font-weight: 600; }
  .theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
  .theme-toggle svg { width: 1.05rem; height: 1.05rem; }
  .theme-toggle span { display: inline-flex; align-items: center; gap: 0.5rem; }
  .theme-toggle .to-light { display: none; }
  :root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-toggle { .to-dark { display: none; } .to-light { display: inline-flex; } }
  @media (prefers-color-scheme: dark) {
    :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-toggle { .to-dark { display: none; } .to-light { display: inline-flex; } }
  }
  @supports not (color: light-dark(#000, #fff)) { .theme-toggle { display: none; } }

  .lang-banner { position: fixed; inset-inline: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; gap: 1rem; align-items: center; padding: 0.7rem 1rem; background: var(--ink); color: var(--paper); }
  .lang-banner a { color: inherit; font-weight: 700; }
  .lang-banner button { background: none; border: 1px solid currentColor; color: inherit; border-radius: 4px; padding: 0.15rem 0.6rem; cursor: pointer; }
  .lang-banner[hidden] { display: none; }
}

/* ==== utilities.css ==== */
/* utilities.css — the few helpers that are not components. */
@layer utilities {
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
  .skip { position: absolute; left: 1rem; top: -3rem; z-index: 20; background: var(--surface); padding: 0.5rem 0.75rem; }
  .skip:focus { top: 1rem; }
  .muted { color: var(--muted); }
}

/* ==== enhancements.css ==== */
/* enhancements.css — schematic sheet texture in dark mode, forced colors and print. */
@layer enhancements {
  /* Dark theme: the dot grid of a schematic editor sheet. */
  @media (prefers-color-scheme: dark) {
    :root:not(:has(> head > meta[name="color-scheme"][content="light"])) body {
      background-image: radial-gradient(circle, var(--rule) 1px, transparent 1.2px);
      background-size: 24px 24px;
    }
  }
  :root:has(> head > meta[name="color-scheme"][content="dark"]) body {
    background-image: radial-gradient(circle, var(--rule) 1px, transparent 1.2px);
    background-size: 24px 24px;
  }

  @media (forced-colors: active) {
    .chip .body { border: 2px solid CanvasText; }
    .leg { background: CanvasText; }
    .features li::before { background: CanvasText; }
    .bus li.owned { border-width: 3px; }
  }

  @media (prefers-reduced-motion: no-preference) {
    .pin a .leg { transition: translate 0.2s ease; }
    .pin:nth-child(-n + 8) a:hover .leg { translate: -3px 0; }
    .pin:nth-child(n + 9) a:hover .leg { translate: 3px 0; }
  }

  @media print {
    .theme-toggle, .lang-banner, .skip, .langs { display: none; }
    .sheet > h2 { position: static; }
    body { background: none; }
  }
}

/* ==== fold.css ==== */
/*
 * fold.css — on a foldable, the datasheet opens as a two-page spread.
 * Viewport Segments API: the media features say how the screen is split,
 * and env(viewport-segment-*) says exactly where each half and the hinge are.
 * Front leaf: masthead, strengths and the chip. Back leaf: everything else.
 * Unfolded or unsupported, none of this applies and the page reads top to bottom.
 */
@layer enhancements {
  /* Book posture: two segments side by side. Each half scrolls on its own. */
  @media (horizontal-viewport-segments: 2) {
    .page {
      --hinge: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));
      display: grid;
      grid-template-columns: env(viewport-segment-width 0 0) var(--hinge) env(viewport-segment-width 1 0);
      width: 100%;
      margin: 0;
    }
    main { display: contents; }
    .leaf, .page > footer { padding-inline: var(--gap); }
    .leaf { container: page / inline-size; }
    .front {
      grid-column: 1; grid-row: 1 / span 2; align-self: start;
      position: sticky; top: 0; height: 100dvh;
      overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
    }
    .back, .page > footer { grid-column: 3; }
  }

  /* Tabletop posture: two segments stacked. The top half holds the front leaf;
     the rest of the sheet scrolls in the bottom half and never under the hinge. */
  @media (vertical-viewport-segments: 2) {
    .front {
      container: page / inline-size;
      position: sticky; top: 0; z-index: 2;
      height: env(viewport-segment-top 0 1);
      padding-bottom: calc(env(viewport-segment-top 0 1) - env(viewport-segment-bottom 0 0));
      overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
      background: var(--paper);
      border-bottom: 2px solid var(--ink);
    }
  }
}
