/* Fonts are self-hosted (Zilla Slab 400-700, DM Mono 400; both SIL OFL), latin and latin-ext subsets. */
/* latin-ext */
@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/dmmono-400-latin-ext.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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/dmmono-400-latin.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;
}
/* latin-ext */
@font-face {
  font-family: 'Zilla Slab';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/zilla-400-latin-ext.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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Zilla Slab';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/zilla-400-latin.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;
}
/* latin-ext */
@font-face {
  font-family: 'Zilla Slab';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/zilla-500-latin-ext.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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Zilla Slab';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/zilla-500-latin.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;
}
/* latin-ext */
@font-face {
  font-family: 'Zilla Slab';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/static/fonts/zilla-600-latin-ext.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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Zilla Slab';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/static/fonts/zilla-600-latin.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;
}
/* latin-ext */
@font-face {
  font-family: 'Zilla Slab';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/static/fonts/zilla-700-latin-ext.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-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Zilla Slab';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/static/fonts/zilla-700-latin.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;
}

/* Token names and values come from the Trackit design system (tokens.json). */
:root {
  --paper-0: #FBF8F1;
  --paper-1: #F3EEE3;
  --paper-2: #EAE3D4;
  --paper-3: #DED5C3;

  --ink-0: #1B1F24;
  --ink-1: #2A3037;
  --ink-2: #535C66;
  --ink-3: #8A9199;

  --ai-1: #12283F;
  --ai-2: #2E5484;
  --ai-4: #C3D3E2;
  --ai-5: #E4EBF2;

  /* Links and footnote markers. Not from the design system: ai-2 is too soft for text that must
     read as clickable, so this is a more saturated, slightly brighter indigo (6.5:1 on paper-1). */
  --link: #1B4FA3;
  --link-line: var(--ai-3);

  --beni-1: #8E2B1D;
  --beni-2: #C4442E;
  --beni-3: #E39184;
  --beni-4: #F4DCD6;

  --ochre-1: #8A6318;
  --ochre-2: #C08B2C;
  --ochre-3: #E0BE7C;
  --ochre-4: #F3E6CB;

  --moegi-1: #3F5636;
  --moegi-2: #6E8C5A;
  --moegi-3: #A8BE96;
  --moegi-4: #E1E9D8;

  /* piece-table-viz colours the buffers, nothing else: original blue, append yellow. */
  --viz-original: var(--ai-4);
  --viz-append: var(--ochre-4);
  /* The one exception to the two colours: only with highlight-appendable. */
  --viz-appendable: #F6D3A8;
  --viz-error: var(--beni-3);
  /* Text a script has selected (about to be deleted): moegi green, never a buffer colour. */
  --viz-selection: var(--ochre-4);

  /* Code highlighting: a deliberately small palette. Only these token types get a
     style; names of functions, classes and variables stay plain. */
  --code-comment: var(--ink-2);
  --code-string: color-mix(in oklch, var(--moegi-1) 45%, var(--moegi-2));
  /* Dark blue, only a step lighter than the body text. */
  --code-type: color-mix(in oklch, var(--ai-2) 65%, var(--ink-0));
  /* The design system has no cyan, so this is indigo pulled toward moegi. */
  --code-number: color-mix(in oklch, var(--ai-2) 55%, var(--moegi-1));

  --line-hairline: color-mix(in srgb, var(--ink-1) 30%, transparent);
  --line-rule: color-mix(in srgb, var(--ink-1) 25%, transparent);

  --font-slab: "Zilla Slab", Rockwell, "Hiragino Mincho ProN", Georgia, serif;
  --font-mono: "DM Mono", "SFMono-Regular", Menlo, monospace;

  --text-2xs: 11px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-md: 17px;
  --text-2xl: 34px;

  --heading-title: var(--text-2xl);
  --heading-1: 24px;
  --heading-2: 20px;
  --heading-3: var(--text-md);
  --heading-4: var(--text-base);

  --leading-snug: 1.2;
  --line-spacing: 1.45; /* body text line height */
  --block-gap: var(--space-4); /* space below paragraphs, lists, quotes, code, tables */
  --code-line-height: calc(var(--text-sm) * var(--line-spacing)); /* one line of code; drives max-lines */
  --code-padding-block: var(--space-2); /* space above/below the code, inside the frame */

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-11: 96px;

  --radius-1: 2px;
  --radius-control: 6px;
  --radius-card: 8px;

  --shadow-2: 0 1px 2px rgba(27, 31, 36, .08), 0 0 0 1px rgba(27, 31, 36, .05);

  --measure: 79ch;
  --row-height: 36px;

  --dur-fast: 90ms;
  --ease-standard: cubic-bezier(.3, .1, .25, 1);

  /* A 2px paper gap, then a 2px indigo ring. */
  --ring-focus: 0 0 0 2px var(--paper-1), 0 0 0 4px var(--ai-2);

  --note-width: 240px;
  --note-gap: var(--space-7);
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--moegi-3);
  color: var(--ink-0);
}

body {
  display: flex; /* column: main grows, so a short page keeps the footer at the bottom */
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: var(--space-8) var(--space-8) var(--space-11);
  background: var(--paper-1);
  color: var(--ink-1);
  font-family: var(--font-slab);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: var(--line-spacing);
}

/* The header and the content column share one measure and are centred together. */
.site-header,
main,
.site-footer {
  width: 100%; /* auto side margins would otherwise shrink a flex item to its content */
  max-width: var(--measure);
  margin-inline: auto;
}

main {
  flex: 1 0 auto;
}

.site-header {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--line-hairline);
}

.site-header a {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-2);
}

.site-header a:hover {
  color: var(--ai-1);
}

.site-footer {
  margin-top: var(--space-8);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line-hairline);
}

/* The type styling sits on the inner <p>: --measure is in ch, so a small font on the
   footer itself would make its column narrower than the header and main. */
.site-footer p {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

/* ---------- type ---------- */

h1,
h2,
h3,
h4 {
  margin: 0;
  color: var(--ink-0);
  font-weight: 600;
  line-height: var(--leading-snug);
}

/* Page-level title (article title, index title). */
h1 {
  font-size: var(--heading-title);
  letter-spacing: -0.012em;
}

/* Headings written inside an article body. */
.prose h1 {
  margin: var(--space-8) 0 var(--space-3);
  font-size: var(--heading-1);
  letter-spacing: -0.01em;
}

h2 {
  margin: var(--space-8) 0 var(--space-3);
  font-size: var(--heading-2);
  letter-spacing: -0.008em;
}

h3 {
  margin: var(--space-7) 0 var(--space-2);
  font-size: var(--heading-3);
  letter-spacing: -0.008em;
}

h4 {
  margin: var(--space-6) 0 var(--space-2);
  font-size: var(--heading-4);
  letter-spacing: -0.008em;
}

p {
  margin: 0 0 var(--block-gap);
}

/* Article body paragraphs only; the date line under the title stays ragged. */
.prose p {
  text-align: justify;
  hyphens: auto;
}

article h1 + p {
  margin: var(--space-2) 0 var(--space-7);
}

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.2em;
  transition:
    color var(--dur-fast) var(--ease-standard),
    text-decoration-color var(--dur-fast) var(--ease-standard);
}

a:hover {
  color: var(--ai-1);
  text-decoration-color: var(--ai-1);
}

a:focus-visible {
  outline: none;
  border-radius: var(--radius-1);
  box-shadow: var(--ring-focus);
}

/* Dates are mono and absolute. */
time {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: 0.02em;
  color: var(--ink-2);
}

/* The date sits on the left of the meta row, the tags (plain text badges) on the right. */
.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin: var(--space-3) 0 var(--block-gap);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
}

.tags li {
  margin: 0;
  padding: 2px 7px;
  border: 1px solid var(--line-hairline);
  border-radius: var(--radius-1);
  background: var(--paper-2);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}

ul,
ol {
  margin: 0 0 var(--block-gap);
  padding-left: var(--space-6);
}

li {
  margin-bottom: var(--space-1);
}

hr {
  margin: var(--space-7) 0;
  border: 0;
  border-top: 1px solid var(--line-hairline);
}

blockquote {
  margin: 0 0 var(--block-gap);
  padding-left: var(--space-5);
  border-left: 1px solid var(--line-rule);
  color: var(--ink-2);
}

code {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  padding: 1px var(--space-1);
  background: var(--paper-2);
  border-radius: var(--radius-1);
  tab-size: 4;
}

pre {
  margin: 0 0 var(--block-gap);
  padding: var(--space-4) var(--space-5);
  overflow-x: auto;
  background: var(--paper-0);
  border: 1px solid var(--line-hairline);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-2);
}

pre code {
  padding: 0;
  background: none;
  line-height: var(--line-spacing);
}

/* ---------- article index ---------- */

.article-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line-hairline);
}

.article-list li {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  align-items: baseline;
  min-height: var(--row-height);
  margin: 0;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line-hairline);
}

.article-list time {
  grid-column: 1;
  grid-row: 1;
}

.article-list a {
  grid-column: 2;
  grid-row: 1;
  font-weight: 500;
}

.article-list em {
  grid-column: 3;
  grid-row: 1;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-style: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- tables ---------- */

table {
  width: 100%;
  margin: 0 0 var(--block-gap);
  border-collapse: collapse;
  border-top: 1px solid var(--line-hairline);
}

tr {
  height: var(--row-height);
}

th,
td {
  padding: var(--space-2) var(--space-4) var(--space-2) 0;
  border-bottom: 1px solid var(--line-hairline);
  text-align: left;
  vertical-align: baseline;
}

th:last-child,
td:last-child {
  padding-right: 0;
}

/* Header cells are the system's mono label: 11px, uppercase, wide tracking. */
th {
  border-bottom-color: var(--line-rule);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 400;
  line-height: var(--leading-snug);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* Author CSS beats the align attribute's presentational hint, so restate it. */
th[align="right"],
td[align="right"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

th[align="center"],
td[align="center"] {
  text-align: center;
}

caption {
  caption-side: bottom;
  padding-top: var(--space-2);
  text-align: left;
  font-size: var(--text-sm);
  color: var(--ink-2);
}

/* ---------- inline footnotes ---------- */

/* The counter lives on the article body so every page numbers from 1. The
   host element increments it, so numbering is right before and after the
   component upgrades. */
.prose {
  counter-reset: footnote;
}

inline-footnote {
  counter-increment: footnote;
}

/* Without JS, or before the component upgrades, the note is plain inline text. */
inline-footnote:not(:defined)::before {
  content: " (";
}

inline-footnote:not(:defined)::after {
  content: ")";
}

.footnote-marker {
  appearance: none;
  padding: 0 0.15em;
  border: 0;
  border-radius: var(--radius-1);
  background: none;
  color: var(--link);
  font: inherit;
  font-size: 0.8em;
  font-weight: 500;
  line-height: 0;
  vertical-align: super;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-standard);
}

.footnote-marker::after {
  content: counter(footnote);
}

.footnote-marker:hover {
  color: var(--ai-1);
}

.footnote-marker:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}

.footnote-body {
  display: none;
  text-align: left;
  hyphens: manual;
  font-size: var(--text-sm);
  line-height: var(--line-spacing);
  color: var(--ink-2);
}

.footnote-body::before {
  content: counter(footnote);
  margin-right: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  color: var(--link);
}

/* Narrow: the note opens in place, like a blockquote with a thick indigo rule. */
@media (max-width: 1259px) {
  .footnote-body[data-open] {
    display: block;
    margin: var(--space-2) 0;
    padding-left: var(--space-5);
    border-left: 3px solid var(--ai-2);
  }
}

/* Wide: the centred column needs (note width + gap) free on each side, so 79ch (about 685px) + 2 * 272px, plus room for a scrollbar, rounded up to 1260px. Retune together with --measure. */
@media (min-width: 1260px) {
  .footnote-marker {
    cursor: default;
  }

  .footnote-body {
    display: block;
    float: right;
    clear: right;
    width: var(--note-width);
    margin-right: calc(-1 * (var(--note-width) + var(--note-gap)));
  }
}

@media (max-width: 599px) {
  body {
    padding: var(--space-5) var(--space-5) var(--space-11);
  }

  .article-list li {
    grid-template-columns: 96px 1fr auto;
  }
}

/* ---------- demo components ---------- */

.button-counter {
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--line-rule);
  border-radius: var(--radius-control);
  background: var(--paper-0);
  color: var(--ink-1);
  font: inherit;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-standard);
}

.button-counter:hover {
  border-color: var(--ai-2);
}

.button-counter:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}

.button-counter span {
  font-variant-numeric: tabular-nums;
}

/* ---------- ingredient list ---------- */

/* <ingredient-list> holds <li amount unit note group> children (see ingredient-list.ts).
   Without JS (not :defined) it is a plain unframed list of names. */
ingredient-list {
  display: block;
  margin: 0 0 var(--block-gap);
}

ingredient-list:defined {
  position: relative;
  overflow: hidden;
  background: var(--paper-0);
  border: 1px solid var(--line-hairline);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-2);
}

/* The accent tab hanging from the top edge. */
ingredient-list:defined::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--space-5);
  width: 56px;
  height: 5px;
  border-radius: 0 0 var(--radius-1) var(--radius-1);
  background: var(--ai-2);
}

.ingredient-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6) var(--space-4);
}

.ingredient-title {
  margin: 0;
  font-size: var(--text-md);
  line-height: var(--leading-snug);
}

.ingredient-stepper {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.ingredient-label,
.ingredient-count {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.ingredient-stepper .ingredient-label {
  margin-right: var(--space-2);
}

.ingredient-count {
  min-width: 32px;
  text-align: center;
  font-size: var(--text-md);
  font-weight: 500;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  color: var(--ink-0);
}

.ingredient-step,
.ingredient-copy {
  appearance: none;
  border: 1px solid var(--line-rule);
  border-radius: var(--radius-control);
  background: var(--paper-0);
  box-shadow: 0 1px 0 rgba(27, 31, 36, .06);
  color: var(--ink-1);
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard),
    color var(--dur-fast) var(--ease-standard);
}

.ingredient-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--ink-2);
}

.ingredient-copy {
  height: 28px;
  padding: 0 10px;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
}

.ingredient-step:hover:not(:disabled),
.ingredient-copy:hover {
  background: var(--paper-1);
  border-color: var(--ink-3);
  color: var(--ink-0);
}

.ingredient-step:active:not(:disabled),
.ingredient-copy:active {
  box-shadow: inset 0 1px 2px rgba(27, 31, 36, .16);
}

.ingredient-step:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.ingredient-step:focus-visible,
.ingredient-copy:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}

/* Group band: a mono label across the card. */
.ingredient-group {
  padding: 7px var(--space-6);
  background: var(--paper-1);
  border-top: 1px solid var(--line-hairline);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* One row: amount | unit | name + note. */
ingredient-list:defined li {
  display: grid;
  grid-template-columns: 64px 28px minmax(0, 1fr);
  column-gap: var(--space-3);
  align-items: baseline;
  margin: 0;
  padding: 11px var(--space-6);
  border-top: 1px solid var(--line-hairline);
  list-style: none;
}

.ingredient-amount {
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
  color: var(--ink-0);
}

.ingredient-unit {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--ink-2);
}

.ingredient-name {
  font-size: 16px;
  font-weight: 500;
  line-height: 22px;
  color: var(--ink-0);
}

.ingredient-note {
  margin-left: 10px;
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--ink-2);
}

.ingredient-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  border-top: 1px solid var(--line-hairline);
}

@media (max-width: 480px) {
  .ingredient-header,
  ingredient-list:defined li,
  .ingredient-group,
  .ingredient-footer {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  .ingredient-stepper .ingredient-label {
    display: none;
  }
}

/* ---------- code blocks ---------- */

/* <code-block> wraps <pre><code>. Before the component upgrades (or without JS)
   the plain pre keeps its own frame; once defined, the frame moves to the host. */
code-block,
viz-area {
  display: block;
  margin: 0 0 var(--block-gap);
}

/* The shared frame: code-block and viz-area look identical from the outside. */
code-block:defined,
viz-area {
  overflow: hidden;
  background: var(--paper-0);
  border: 1px solid var(--line-hairline);
  border-radius: var(--radius-control);
  box-shadow: var(--shadow-2);
}

code-block:defined pre {
  flex: 1 0 auto; /* grow to the longest line; the body scrolls, not the pre */
  margin: 0;
  padding: var(--code-padding-block) var(--space-4) var(--code-padding-block) var(--space-3);
  overflow: visible;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

code-block:defined pre code {
  display: block;
  font-size: var(--text-sm);
  line-height: var(--code-line-height);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  padding: 2px var(--space-2) 2px var(--space-3);
  border-bottom: 1px solid var(--line-hairline);
}

.code-block-language {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.code-block-copy {
  appearance: none;
  padding: 2px var(--space-2);
  border: 1px solid var(--line-hairline);
  border-radius: var(--radius-control);
  background: none;
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    color var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard);
}

.code-block-copy:hover {
  color: var(--ai-1);
  border-color: var(--ai-2);
}

.code-block-copy:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}

/* The body is the single scroll container, so gutter and code scroll together
   vertically. The vertical padding lives on the children, not here: padding on a
   scroller shows the next line below the cap. --max-lines (set by the component
   from max-lines="N") caps the height; absent means unlimited. */
.code-block-body {
  display: flex;
  overflow: auto;
  max-height: calc(var(--max-lines) * var(--code-line-height) + var(--code-padding-block));
}

.code-block-gutter {
  position: sticky;
  left: 0;
  z-index: 1; /* keep scrolled code underneath the numbers */
  flex: none;
  /* Don't stretch to the (max-height capped) body: the box would end at the
     viewport height and its background wouldn't cover the overflowing numbers. */
  align-self: flex-start;
  padding: var(--code-padding-block) var(--space-2) var(--code-padding-block) var(--space-3);
  background: var(--paper-0);
  border-right: 1px solid var(--line-hairline);
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--code-line-height);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: pre;
  user-select: none;
}

/* ---------- code highlighting ---------- */

/* highlight.js theme (scripts/highlight.ts adds the hljs-* spans). Keywords are
   bold, comments faded, strings green, types dark blue, numbers and the literals
   true / false / nil dark cyan. Everything else is the default text colour. */
.hljs-keyword {
  font-weight: 700;
}

.hljs-comment {
  color: var(--code-comment);
}

.hljs-string {
  color: var(--code-string);
}

.hljs-type {
  color: var(--code-type);
}

.hljs-number,
.hljs-literal {
  color: var(--code-number);
}

/* ---------- viz area ---------- */

/* <viz-area> is a plain styled container for visualizations and demos: the same
   frame as code-block, no header, no JS. It is the scroll container itself, so
   content wider or taller than the box scrolls. Cap its height inline when
   needed: <viz-area style="max-height: 320px">. */
viz-area {
  overflow: auto;
  padding: var(--space-4);
}

/* Keep trailing content margins from adding extra space at the bottom. */
viz-area > :last-child {
  margin-bottom: 0;
}

/* A directive that failed (unknown name, missing file, ...): see directives.go. */
.directive-error {
  margin: 0 0 var(--block-gap);
  padding: var(--space-3) var(--space-4);
  background: var(--viz-error);
  border: 1px solid var(--line-rule);
  border-radius: var(--radius-control);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  color: var(--ink-1);
}

/* ---------- piece-table-viz ---------- */

/* Drawn by scripts/piece-table-viz.ts inside a <viz-area>. */
.pt {
  /* Sizes for the whole visualization; change them here. */
  --pt-text: 12px;
  --pt-small: 10px;
  --pt-cell-width: 19px;
  /* Narrower than this and the viz-area scrolls sideways instead of wrapping,
     so the layout doesn't jump around. Size it for your longest result row
     (one cell is --pt-cell-width plus a 2px gap). */
  --pt-min-width: 640px;
  /* One row of cells: the char box (padding + border + line), and the index under it. */
  --pt-char-height: calc(8px + var(--leading-snug) * var(--pt-text));
  --pt-index-height: calc(2px + var(--pt-small));
  /* A piece card: padding + gap, and its two lines (they inherit the page line-height). */
  --pt-piece-height: calc(14px + (var(--pt-text) + var(--pt-small)) * var(--line-spacing));

  display: grid;
  gap: var(--space-4);
  min-width: var(--pt-min-width);
}

piece-table-viz {
  display: block;
}

/* Before the script defines the element it is empty; hold roughly its height so
   the page does not jump when the visualizations appear. Animated ones fix their
   exact height as soon as they are ready. */
piece-table-viz:not(:defined) {
  min-height: 260px;
}

.pt-label {
  margin-bottom: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* Rows wrap onto more lines when they are wider than the column. */
.pt-cells,
.pt-pieces {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) 2px; /* row gap leaves room for the indexes under the cells */
}

.pt-pieces {
  gap: var(--space-2);
}

.pt-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: var(--pt-cell-width);
}

.pt-char {
  width: 100%;
  padding: 3px 0;
  /* Always 1px, so a faded (unused) cell is exactly as tall as a used one and
     the indexes under them line up. */
  border: 1px dashed transparent;
  border-radius: var(--radius-1);
  background: var(--paper-2);
  color: var(--ink-0);
  font-family: var(--font-mono);
  font-size: var(--pt-text);
  line-height: var(--leading-snug);
  text-align: center;
  white-space: pre;
}

.pt-index {
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: var(--pt-small);
  line-height: 1;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* Buffer cells no piece points at are faded back. */
.pt-unused .pt-char {
  background: none;
  border-color: var(--line-rule);
  color: var(--ink-3);
}

.pt-piece {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  border-radius: var(--radius-control);
  color: var(--ink-0);
  white-space: nowrap;
}

.pt-piece-title {
  font-family: var(--font-mono);
  font-size: var(--pt-text);
  font-weight: 500;
}

.pt-piece-range {
  font-family: var(--font-mono);
  font-size: var(--pt-small);
  letter-spacing: 0.04em;
  color: var(--ink-2);
}

/* An empty row keeps the height of a row with cells in it, so what is below it
   does not move when the first character shows up. */
.pt-empty {
  line-height: var(--pt-char-height);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.pt-pieces .pt-empty {
  line-height: var(--pt-piece-height);
}

.pt-indexed .pt-empty {
  line-height: calc(var(--pt-char-height) + var(--pt-index-height));
}

.pt-error {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--ink-0);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line-rule);
  border-radius: var(--radius-control);
  background: var(--viz-error);
}

.pt-original { --pt-color: var(--viz-original); }
.pt-append { --pt-color: var(--viz-append); }
.pt-appendable { --pt-color: var(--viz-appendable); }

.pt-piece,
.pt-cell:not(.pt-unused) .pt-char {
  background: var(--pt-color);
}

/* Text a script has selected, about to be deleted. Green, so it reads as a
   selection whichever buffer the text lives in. */
.pt-cell.pt-selected .pt-char {
  background: var(--viz-selection);
  text-decoration: line-through;
}

/* The character typed most recently in the animated piece-table-viz. */
.pt-new .pt-char {
  box-shadow: 0 0 0 2px var(--ai-2);
}
