/* ═══════════════════════════════════════════════════════════════════
   code.css — the "source" button and the sheet it opens.

   The sheet borrows the chapter's own colour for its edge, so it reads
   as part of the chapter rather than as a tool bolted onto the page.
   The code sits on the same paper as the intro: this is still the book,
   just a page of it that happens to be source.

   No third typeface is loaded. The code uses the system mono stack,
   which every machine already has.
   ═══════════════════════════════════════════════════════════════════ */

/* ── the button, inside each chapter's top line, in that chapter's ink ── */
.src__open{
  -webkit-appearance:none;appearance:none;
  margin-left:14px;padding:3px 10px 4px;
  font:inherit;font-size:.92em;font-weight:700;line-height:1.2;
  color:currentColor;background:transparent;
  border:1.5px solid currentColor;border-radius:999px;
  cursor:pointer;opacity:.78;
  transition:opacity .18s ease,transform .18s ease;
  white-space:nowrap;vertical-align:baseline;
}
.src__open i{font-style:normal;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.92em;letter-spacing:-.04em;margin-right:.35em}
.src__open:hover,.src__open:focus-visible{opacity:1;transform:translateY(-1px)}
.src__open:focus-visible{outline:2px solid currentColor;outline-offset:3px}

/* ── the sheet ────────────────────────────────────────────────────── */
html.src-open{overflow:hidden}

.src{position:fixed;inset:0;z-index:9000;font-family:var(--display)}
.src__scrim{
  position:absolute;inset:0;background:#11111166;
  opacity:0;transition:opacity .32s ease;
}
.src__panel{
  position:absolute;top:0;right:0;bottom:0;
  width:min(860px,100%);
  display:flex;flex-direction:column;
  background:var(--paper,#E8E6E1);color:var(--ink,#111);
  border-left:5px solid var(--accent,#EE3D9C);
  box-shadow:-24px 0 64px #0000002e;
  transform:translateX(100%);
  transition:transform .34s cubic-bezier(.22,.8,.2,1);
  will-change:transform;
}
.src.on .src__scrim{opacity:1}
.src.on .src__panel{transform:translateX(0)}

.src__head{
  display:flex;align-items:flex-start;justify-content:space-between;gap:20px;
  padding:22px 24px 16px;border-bottom:1.5px solid #11111118;
}
.src__label{margin:0;font-size:clamp(19px,2vw,24px);font-weight:700;line-height:1.15;letter-spacing:-.01em}
.src__note{margin:7px 0 0;font-family:'Inter',system-ui,sans-serif;font-size:13px;line-height:1.4;max-width:46ch;opacity:.78}
.src__x{
  -webkit-appearance:none;appearance:none;flex:none;
  padding:5px 12px 6px;font:inherit;font-size:13px;font-weight:700;
  color:inherit;background:transparent;border:1.5px solid currentColor;border-radius:999px;
  cursor:pointer;opacity:.6;transition:opacity .18s ease;
}
.src__x:hover,.src__x:focus-visible{opacity:1}

.src__tabs{display:flex;gap:4px;padding:12px 24px 0;flex-wrap:wrap}
.src__tabs[hidden]{display:none}
.src__tabs button{
  -webkit-appearance:none;appearance:none;
  padding:5px 11px 6px;border:0;border-radius:7px 7px 0 0;cursor:pointer;
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;
  color:inherit;background:#11111110;opacity:.6;
  transition:opacity .18s ease,background-color .18s ease;
}
.src__tabs button:hover{opacity:.9}
.src__tabs button[aria-current="true"]{opacity:1;background:#1111111f;font-weight:700}

.src__scroll{flex:1;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;padding:16px 0 24px}
.src__pre{
  margin:0;
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:12.5px;line-height:1.58;tab-size:2;
}
/* one row per line of the file: number, then the line. the line wraps
   inside its own cell, so a 200-character line stays readable and its
   number stays next to it instead of drifting. */
.src__code{
  display:grid;grid-template-columns:max-content minmax(0,1fr);
  column-gap:16px;padding:0 24px;
}
.src__code .ln{
  text-align:right;user-select:none;-webkit-user-select:none;
  color:#11111152;font-variant-numeric:tabular-nums;
}
.src__code .lc{
  white-space:pre-wrap;overflow-wrap:anywhere;
  /* a wrapped line is indented so you can see it is a continuation */
  padding-left:2.2ch;text-indent:-2.2ch;
}

/* the five things worth telling apart, and nothing else */
.c-cm{color:#6E6657;font-style:italic}
.c-st{color:#1F6F4A}
.c-nu{color:#9A4A16}
.c-kw{color:#6A3FA0;font-weight:600}

.src__foot{
  display:flex;align-items:center;justify-content:space-between;gap:16px;
  padding:13px 24px 15px;border-top:1.5px solid #11111118;
}
.src__where{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;opacity:.68;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.src__copy{
  -webkit-appearance:none;appearance:none;flex:none;
  padding:5px 14px 6px;font:inherit;font-size:13px;font-weight:700;
  color:var(--paper,#E8E6E1);background:var(--ink,#111);border:0;border-radius:999px;cursor:pointer;
  transition:opacity .18s ease;
}
.src__copy:hover,.src__copy:focus-visible{opacity:.82}

/* ── phones: the sheet comes up from the bottom instead ───────────── */
@media (max-width:720px){
  .src__panel{
    top:auto;left:0;height:88svh;width:100%;
    border-left:0;border-top:5px solid var(--accent,#EE3D9C);
    border-radius:16px 16px 0 0;
    transform:translateY(100%);
    box-shadow:0 -20px 56px #00000036;
  }
  .src.on .src__panel{transform:translateY(0)}
  .src__head{padding:18px 18px 14px}
  .src__tabs{padding:10px 18px 0}
  .src__code{padding:0 18px;column-gap:12px}
  .src__foot{padding:11px 18px 13px}
  .src__pre{font-size:11.5px}
}

@media (prefers-reduced-motion:reduce){
  .src__panel,.src__scrim{transition:none}
  .src__open{transition:none}
}

@media print{.src,.src__open{display:none !important}}
