/* ==========================================================================
   The Knitting Studio — site styles
   A warm paper ground with a full spectrum of yarn colours on top: every
   topic, card, lesson and swatch carries its own hue from the rainbow.
   ========================================================================== */

:root {
  /* --- the spectrum ------------------------------------------------- */
  --c-red:    #d63f3f;  --c-red-w:    #fdeaea;
  --c-orange: #de7118;  --c-orange-w: #fdefdf;
  --c-yellow: #c99700;  --c-yellow-w: #fbf4d8;
  --c-lime:   #6f9c1e;  --c-lime-w:   #f0f6df;
  --c-green:  #2f9558;  --c-green-w:  #e3f5ea;
  --c-teal:   #16959a;  --c-teal-w:   #def3f4;
  --c-blue:   #2f72cc;  --c-blue-w:   #e6effb;
  --c-indigo: #5a4fd0;  --c-indigo-w: #ebe9fc;
  --c-violet: #9540bd;  --c-violet-w: #f5e8fb;
  --c-pink:   #cf3d86;  --c-pink-w:   #fce9f2;

  --rainbow: linear-gradient(90deg,
    var(--c-red) 0%, var(--c-orange) 14%, var(--c-yellow) 28%, var(--c-lime) 42%,
    var(--c-green) 56%, var(--c-teal) 68%, var(--c-blue) 80%, var(--c-indigo) 90%,
    var(--c-violet) 100%);

  /* --- paper and ink ------------------------------------------------ */
  --paper:        #fdfaf4;
  --paper-2:      #f5eee2;
  --card:         #ffffff;
  --ink:          #2a2622;
  --ink-2:        #57504a;
  --ink-3:        #857b73;
  --rule:         #e7ddcd;
  --rule-2:       #d5c8b4;

  /* the page's default accent — overridden per page and per card */
  --accent:   var(--c-teal);
  --accent-w: var(--c-teal-w);

  /* --- yarn colours used by the swatch diagrams --------------------- */
  --yarn:         #d8c5aa;
  --yarn-dark:    #b39871;
  --yarn-alt:     #6f93b8;
  --yarn-hi:      #fffdf8;

  --shadow:    0 1px 2px rgba(43,39,36,.05), 0 8px 24px -12px rgba(43,39,36,.22);
  --shadow-lg: 0 2px 4px rgba(43,39,36,.06), 0 24px 48px -20px rgba(43,39,36,.3);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans:  ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  --mono:  ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --wrap: 1150px;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-red:    #ff7a7a;  --c-red-w:    #3a1f1f;
    --c-orange: #ffa257;  --c-orange-w: #3a2a17;
    --c-yellow: #eccb4a;  --c-yellow-w: #383014;
    --c-lime:   #b6d95f;  --c-lime-w:   #2c3417;
    --c-green:  #63cf90;  --c-green-w:  #1c3527;
    --c-teal:   #4fcdd2;  --c-teal-w:   #133134;
    --c-blue:   #74a9f5;  --c-blue-w:   #1a2740;
    --c-indigo: #9b90fb;  --c-indigo-w: #241f42;
    --c-violet: #cd82ea;  --c-violet-w: #331f3d;
    --c-pink:   #f57ab3;  --c-pink-w:   #3b1c2c;

    --paper:   #171513;
    --paper-2: #201d1a;
    --card:    #262220;
    --ink:     #f1eae0;
    --ink-2:   #c4bab0;
    --ink-3:   #948a80;
    --rule:    #3a3430;
    --rule-2:  #4d453f;

    --yarn:      #6f6250;
    --yarn-dark: #93815f;
    --yarn-alt:  #5d7d9e;
    --yarn-hi:   #a99a80;

    --shadow:    0 1px 2px rgba(0,0,0,.35), 0 8px 24px -12px rgba(0,0,0,.65);
    --shadow-lg: 0 2px 4px rgba(0,0,0,.4), 0 24px 48px -20px rgba(0,0,0,.75);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 96px; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { filter: brightness(.88); }

h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.14; margin: 0 0 .5em; font-weight: 600; letter-spacing: -.012em; }
h1 { font-size: clamp(2.1rem, 5vw, 3.15rem); }
h2 { font-size: clamp(1.6rem, 3.4vw, 2.2rem); }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.03rem; font-family: var(--sans); font-weight: 700; }
h5 { font-family: var(--sans); }
p  { margin: 0 0 1.1em; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 24px; }
.narrow { max-width: 800px; }

/* ---------- Accent classes -------------------------------------------- */

.a-red    { --accent: var(--c-red);    --accent-w: var(--c-red-w); }
.a-orange { --accent: var(--c-orange); --accent-w: var(--c-orange-w); }
.a-yellow { --accent: var(--c-yellow); --accent-w: var(--c-yellow-w); }
.a-lime   { --accent: var(--c-lime);   --accent-w: var(--c-lime-w); }
.a-green  { --accent: var(--c-green);  --accent-w: var(--c-green-w); }
.a-teal   { --accent: var(--c-teal);   --accent-w: var(--c-teal-w); }
.a-blue   { --accent: var(--c-blue);   --accent-w: var(--c-blue-w); }
.a-indigo { --accent: var(--c-indigo); --accent-w: var(--c-indigo-w); }
.a-violet { --accent: var(--c-violet); --accent-w: var(--c-violet-w); }
.a-pink   { --accent: var(--c-pink);   --accent-w: var(--c-pink-w); }

/* ---------- Header ---------------------------------------------------- */

.rainbow-top { height: 5px; background: var(--rainbow); }

.site-head {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: saturate(1.5) blur(12px);
  border-bottom: 1px solid var(--rule);
}
.head-inner {
  max-width: var(--wrap); margin: 0 auto; padding: 11px 24px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--serif); font-size: 1.22rem; font-weight: 600;
  color: var(--ink); text-decoration: none; letter-spacing: -.015em;
}
.brand svg { width: 32px; height: 32px; flex: none; }
.brand b { font-weight: 600; background: var(--rainbow); -webkit-background-clip: text; background-clip: text; color: transparent; }

.nav { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  padding: 7px 11px; border-radius: 999px; text-decoration: none;
  color: var(--ink-2); font-size: .93rem; font-weight: 500; white-space: nowrap;
  border: 1px solid transparent;
}
.nav a:nth-child(1) { --nc: var(--c-red); }
.nav a:nth-child(2) { --nc: var(--c-orange); }
.nav a:nth-child(3) { --nc: var(--c-lime); }
.nav a:nth-child(4) { --nc: var(--c-green); }
.nav a:nth-child(5) { --nc: var(--c-teal); }
.nav a:nth-child(6) { --nc: var(--c-blue); }
.nav a:nth-child(7) { --nc: var(--c-violet); }
.nav a:nth-child(8) { --nc: var(--c-pink); }
.nav a:nth-child(9) { --nc: var(--c-indigo); }
.nav a:nth-child(10){ --nc: var(--c-yellow); }
.nav a:hover { color: var(--nc); border-color: var(--nc); filter: none; }
.nav a[aria-current="page"] { background: var(--nc); color: #fff; border-color: var(--nc); }

@media (prefers-color-scheme: dark) {
  .nav a[aria-current="page"] { color: #17130f; }
}

/* ---------- Hero ------------------------------------------------------ */

.hero {
  position: relative; overflow: hidden;
  background:
    radial-gradient(900px 400px at 12% -10%, var(--c-yellow-w), transparent 65%),
    radial-gradient(760px 380px at 88% 6%, var(--c-teal-w), transparent 62%),
    radial-gradient(700px 420px at 55% 110%, var(--c-violet-w), transparent 60%),
    var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: clamp(46px, 8vw, 88px) 0 clamp(40px, 6vw, 70px);
}
.hero-grid { display: grid; grid-template-columns: 1.02fr .98fr; gap: 48px; align-items: center; }
.hero h1 { margin-bottom: .35em; }
.hero h1 em { font-style: normal; background: var(--rainbow); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .lede { font-size: 1.16rem; color: var(--ink-2); max-width: 47ch; }
.eyebrow {
  font-family: var(--sans); font-size: .76rem; font-weight: 700;
  letter-spacing: .15em; text-transform: uppercase; color: var(--accent);
  margin: 0 0 14px; display: flex; align-items: center; gap: 10px;
}
.eyebrow::after { content: ""; flex: 1; max-width: 90px; height: 3px; border-radius: 2px; background: var(--rainbow); }
.hero-art { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-lg); }
.hero-art::before { content: ""; display: block; height: 4px; border-radius: 3px; background: var(--rainbow); margin: -6px 0 16px; }

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 999px; text-decoration: none;
  font-weight: 600; font-size: .96rem; border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(.9); color: #fff; }
.btn-ghost { border-color: var(--rule-2); color: var(--ink); background: var(--card); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); filter: none; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #17130f; } .btn-primary:hover { color: #17130f; } }

/* ---------- Sections -------------------------------------------------- */

section { padding: clamp(44px, 6vw, 74px) 0; position: relative; }
section + section::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--rainbow); opacity: .5;
}
.section-head { max-width: 64ch; margin-bottom: 34px; }
.section-head p { color: var(--ink-2); margin-bottom: 0; }

.page-head { padding: clamp(38px, 5vw, 60px) 0 10px; }
.page-head .lede { font-size: 1.14rem; color: var(--ink-2); max-width: 62ch; }

/* ---------- Cards ----------------------------------------------------- */

.grid { display: grid; gap: 22px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }

.card {
  background: var(--card); border: 1px solid var(--rule);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.card h3, .card h4 { margin-bottom: .35em; }
.card p:last-child { margin-bottom: 0; }
.card .meta { font-size: .84rem; color: var(--ink-3); }

a.card { text-decoration: none; color: inherit; display: block; transition: transform .15s ease, box-shadow .15s ease; }
a.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); color: inherit; filter: none; }

.step-num {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-w); color: var(--accent);
  border: 1.5px solid var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: .95rem;
  font-family: var(--mono); margin-bottom: 12px;
}

/* ---------- Badges ---------------------------------------------------- */

.badge {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  background: var(--accent-w); color: var(--accent);
}
.b-easy   { background: var(--c-green-w);  color: var(--c-green); }
.b-medium { background: var(--c-orange-w); color: var(--c-orange); }
.b-hard   { background: var(--c-red-w);    color: var(--c-red); }
.b-info   { background: var(--c-blue-w);   color: var(--c-blue); }
.tags { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; align-items: center; }

/* ---------- Lesson blocks --------------------------------------------- */

.lesson {
  background: var(--card); border: 1px solid var(--rule);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  padding: clamp(20px, 3vw, 34px); box-shadow: var(--shadow); margin-bottom: 28px;
  scroll-margin-top: 100px;
}
.lesson-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.lesson-head h2, .lesson-head h3 { margin-bottom: 0; }
.lesson-split { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: start; margin-top: 20px; }

ol.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
ol.steps li { counter-increment: s; position: relative; padding-left: 46px; margin-bottom: 16px; }
ol.steps li::before {
  content: counter(s); position: absolute; left: 0; top: -1px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-w); border: 1.5px solid var(--accent); color: var(--accent);
  display: grid; place-items: center; font-family: var(--mono); font-size: .85rem; font-weight: 700;
}
ol.steps li b { color: var(--ink); }

.callout {
  border-left: 4px solid var(--c-yellow); background: var(--c-yellow-w);
  padding: 14px 18px; border-radius: 0 10px 10px 0; margin: 20px 0; font-size: .95rem;
}
.callout.tip   { border-color: var(--c-green);  background: var(--c-green-w); }
.callout.watch { border-color: var(--c-red);    background: var(--c-red-w); }
.callout.note  { border-color: var(--c-blue);   background: var(--c-blue-w); }
.callout.deep  { border-color: var(--c-violet); background: var(--c-violet-w); }
.callout strong { display: block; font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 4px; }
.callout p:last-child { margin-bottom: 0; }

/* ---------- Diagram frames -------------------------------------------- */

.diagram {
  background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: 12px; padding: 18px; margin: 0 0 12px; overflow-x: auto;
}
.diagram.plain { background: var(--card); }
.diagram svg { display: block; margin: 0 auto; height: auto; }
.diagram-cap { font-size: .87rem; color: var(--ink-3); text-align: center; margin: 10px 0 0; }
.diagram-cap b { color: var(--ink-2); }
figure { margin: 0 0 22px; }

.swatch-frame { display: flex; flex-wrap: wrap; gap: 26px; align-items: flex-start; justify-content: center; }
.swatch-unit { text-align: center; }
.swatch-unit h5 {
  font-size: .72rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 10px; font-weight: 700;
}

/* ---------- Video ----------------------------------------------------- */

.video-card {
  background: var(--card); border: 1px solid var(--rule); border-top: 3px solid var(--accent);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.video-embed {
  position: relative; aspect-ratio: 16 / 9; width: 100%;
  background: var(--accent-w) center/cover no-repeat; border: 0; cursor: pointer; padding: 0; display: block;
}
.video-embed::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.02), rgba(0,0,0,.42));
}
.video-embed .play {
  position: absolute; z-index: 2; inset: 0; margin: auto;
  width: 64px; height: 45px; border-radius: 12px;
  background: var(--accent); border: 2px solid rgba(255,255,255,.55);
  display: grid; place-items: center; transition: transform .15s ease;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
.video-embed:hover .play { transform: scale(1.09); }
.video-embed .play svg { width: 18px; height: 18px; fill: #fff; }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-embed.playing::after, .video-embed.playing .play { display: none; }

.video-body { padding: 16px 18px; flex: 1; display: flex; flex-direction: column; }
.video-body h4 { margin: 0 0 6px; line-height: 1.35; font-size: 1rem; }
.video-body p { font-size: .9rem; color: var(--ink-2); margin: 0 0 12px; }
.video-body .meta { margin-top: auto; font-size: .82rem; color: var(--ink-3); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.video-body .meta a { text-decoration: none; font-weight: 600; color: var(--accent); }

/* ---------- Tables ---------------------------------------------------- */

.table-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 12px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--rule); vertical-align: top; }
thead th { background: var(--accent-w); color: var(--accent); font-size: .74rem; letter-spacing: .09em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--paper); }
td code, p code, li code, th code {
  font-family: var(--mono); font-size: .88em; background: var(--accent-w);
  color: var(--accent); padding: 1px 6px; border-radius: 5px;
}

/* ---------- Pattern block --------------------------------------------- */

.pattern {
  font-family: var(--mono); font-size: .9rem; line-height: 1.95;
  background: var(--paper-2); border: 1px solid var(--rule);
  border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0;
  padding: 14px 18px; margin: 0 0 18px; overflow-x: auto;
}
.pattern div { white-space: nowrap; }
.pattern .rowlabel { color: var(--accent); font-weight: 700; }

/* ---------- Filters --------------------------------------------------- */

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 30px; }
.filters button {
  font: inherit; font-size: .9rem; font-weight: 600;
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--fc, var(--rule-2)); background: var(--card); color: var(--fc, var(--ink-2));
}
.filters button:hover { background: var(--card); filter: brightness(.95); }
.filters button[aria-pressed="true"] { background: var(--fc, var(--ink)); color: #fff; }
@media (prefers-color-scheme: dark) { .filters button[aria-pressed="true"] { color: #17130f; } }
.filters button:nth-child(10n+1) { --fc: var(--c-red); }
.filters button:nth-child(10n+2) { --fc: var(--c-orange); }
.filters button:nth-child(10n+3) { --fc: var(--c-yellow); }
.filters button:nth-child(10n+4) { --fc: var(--c-lime); }
.filters button:nth-child(10n+5) { --fc: var(--c-green); }
.filters button:nth-child(10n+6) { --fc: var(--c-teal); }
.filters button:nth-child(10n+7) { --fc: var(--c-blue); }
.filters button:nth-child(10n+8) { --fc: var(--c-indigo); }
.filters button:nth-child(10n+9) { --fc: var(--c-violet); }
.filters button:nth-child(10n){ --fc: var(--c-pink); }

/* ---------- Checklist ------------------------------------------------- */

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { border-bottom: 1px solid var(--rule); }
.checklist li:last-child { border-bottom: 0; }
.checklist li:nth-child(10n+1) { --accent: var(--c-red); }
.checklist li:nth-child(10n+2) { --accent: var(--c-orange); }
.checklist li:nth-child(10n+3) { --accent: var(--c-yellow); }
.checklist li:nth-child(10n+4) { --accent: var(--c-lime); }
.checklist li:nth-child(10n+5) { --accent: var(--c-green); }
.checklist li:nth-child(10n+6) { --accent: var(--c-teal); }
.checklist li:nth-child(10n+7) { --accent: var(--c-blue); }
.checklist li:nth-child(10n+8) { --accent: var(--c-indigo); }
.checklist li:nth-child(10n+9) { --accent: var(--c-violet); }
.checklist li:nth-child(10n)   { --accent: var(--c-pink); }
.checklist label { display: flex; gap: 12px; align-items: flex-start; padding: 12px 2px; cursor: pointer; }
.checklist input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.checklist span { font-size: .96rem; }
.checklist small { display: block; color: var(--ink-3); font-size: .84rem; }
.checklist input:checked + span { color: var(--ink-3); text-decoration: line-through; }
.progress-note { font-size: .86rem; color: var(--ink-3); margin: 14px 0 0; }

/* ---------- TOC ------------------------------------------------------- */

.toc { position: sticky; top: 100px; align-self: start; padding-left: 16px; border-left: 3px solid transparent;
       background: linear-gradient(var(--rainbow)) left/3px 100% no-repeat; }
.toc h4 { font-size: .72rem; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 12px; }
.toc a { display: block; padding: 4px 0; font-size: .92rem; text-decoration: none; color: var(--ink-2); }
.toc a:hover { color: var(--c-teal); filter: none; }
.with-toc { display: grid; grid-template-columns: 220px 1fr; gap: 44px; align-items: start; }

/* ---------- Legend / key ---------------------------------------------- */

.legend { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; font-size: .85rem; color: var(--ink-2); margin-top: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend svg { width: 26px; height: 24px; flex: none; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* ---------- Footer ---------------------------------------------------- */

.site-foot { border-top: 1px solid var(--rule); background: var(--paper-2); padding: 0 0 34px; margin-top: 40px; font-size: .92rem; color: var(--ink-2); }
.site-foot .rainbow-top { margin-bottom: 42px; }
.foot-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 34px; }
.foot-grid h5 { font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 12px; }
.foot-grid ul { list-style: none; padding: 0; margin: 0; }
.foot-grid li { margin-bottom: 7px; }
.foot-grid a { text-decoration: none; color: var(--ink-2); }
.foot-grid a:hover { color: var(--c-teal); filter: none; }
.foot-bottom { border-top: 1px solid var(--rule); margin-top: 32px; padding-top: 20px; font-size: .85rem; color: var(--ink-3); }

/* Grid children default to min-width:auto, which lets a wide table or SVG
   push the whole column past the viewport. Pin them to zero instead. */
.with-toc > *, .grid > *, .lesson-split > *, .hero-grid > *, .foot-grid > * { min-width: 0; }

/* ---------- Utility --------------------------------------------------- */

.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.center { text-align: center; }
.muted { color: var(--ink-2); }
.small { font-size: .9rem; }
.hidden { display: none !important; }

/* ---------- Responsive ------------------------------------------------ */

@media (max-width: 960px) {
  .hero-grid, .lesson-split { grid-template-columns: 1fr; }
  .g4, .g3 { grid-template-columns: 1fr 1fr; }
  .with-toc { grid-template-columns: 1fr; }
  .toc { position: static; padding: 16px 0 0; background: linear-gradient(var(--rainbow)) top/100% 3px no-repeat; padding-left: 0; }
  .foot-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .foot-grid { grid-template-columns: 1fr; }
  .head-inner { padding: 10px 16px; gap: 10px; }
  .nav { margin-left: 0; width: 100%; overflow-x: auto; }
  .wrap { padding: 0 16px; }
}

/* ==========================================================================
   Installed-app / iOS support
   ========================================================================== */

html {
  -webkit-text-size-adjust: 100%;          /* stop iOS resizing text on rotate */
  overscroll-behavior-y: none;             /* no rubber-band past the ends */
}

body { -webkit-tap-highlight-color: rgba(47,149,88,.15); }

/* Safe areas: keep content clear of the notch, the rounded corners and the
   home indicator, in both orientations. */
.head-inner,
.wrap {
  padding-left:  max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
}
.site-foot { padding-bottom: max(34px, calc(24px + env(safe-area-inset-bottom))); }

/* Running as an installed app there is no browser chrome, so the sticky
   header has to account for the status bar itself. */
@media (display-mode: standalone) {
  .site-head { padding-top: env(safe-area-inset-top); }
  html { scroll-padding-top: calc(96px + env(safe-area-inset-top)); }
}

/* ---------- phones ---------------------------------------------------- */

@media (max-width: 640px) {
  /* Ten nav items wrap into three cramped rows on a phone. One swipeable
     row is easier to use and takes a third of the height. */
  .nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
    margin: 0 -16px;                        /* bleed to the screen edges */
    padding-left: 16px;
    padding-right: 16px;
    scroll-snap-type: x proximity;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    scroll-snap-align: start;
    padding: 9px 14px;                      /* a comfortable tap target */
  }

  .head-inner, .wrap {
    padding-left:  max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  /* Diagrams are wide by nature; let them scroll rather than squash. */
  .diagram { margin-left: -16px; margin-right: -16px; padding: 14px 16px; border-radius: 0; }

  .btn { padding: 13px 20px; }              /* 44px minimum touch target */
  .checklist label { padding: 14px 2px; }
}

/* ---------- install prompt -------------------------------------------- */

.install-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 8px; }
@media (max-width: 640px) { .install-steps { grid-template-columns: 1fr; } }

/* ==========================================================================
   Sister-site bar — links to the other sites that live in this folder.
   Sits above the site header so it is clearly not part of this site's nav.
   ========================================================================== */

.site-switch {
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
  font-size: .85rem;
}
.switch-inner {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 8px max(24px, env(safe-area-inset-right)) 8px max(24px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.switch-inner > b {
  color: var(--ink-3);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  flex: none;
}
.site-switch a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink-2);
  font-weight: 600;
  white-space: nowrap;
}
.site-switch a::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--sc);
  flex: none;
}
.site-switch a:hover { color: var(--sc); filter: none; }
.site-switch a:nth-of-type(1) { --sc: var(--c-orange); }
.site-switch a:nth-of-type(2) { --sc: var(--c-green); }
.site-switch a:nth-of-type(3) { --sc: var(--c-indigo); }

@media (max-width: 640px) {
  /* drop the label and let the three links scroll, rather than stacking */
  .switch-inner > b { display: none; }
  .switch-inner {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .switch-inner::-webkit-scrollbar { display: none; }
}
