/* FxDart Theory — the paged book viewer.
 *
 * Hand-maintained (like site.css and js/*.js). The page HTML under
 * docs/theory/ is generated from content/theory/ by tool/build_docs.dart;
 * this file and js/theorybook.js are its runtime.
 *
 * The viewer is deliberately *paper*: it keeps a fixed light palette whatever
 * the OS theme is, because the thing being simulated is a printed textbook.
 * Only the surrounding site chrome follows the reader's theme.
 */

/* The book page loads this stylesheet and nothing else — no site.css — so the
   reset lives here. Isolation is the point: the site's theme tokens, header
   layout and typography cannot reach the page box, and the book cannot push
   the site's chrome around. The reader leaves via the close button. */
* { box-sizing: border-box; }

body.book-standalone {
  margin: 0;
  /* No document scrolling: the stage is exactly the viewport, so there is
     never a scroll position that can hide part of the UI. */
  overflow: hidden;
  background: var(--desk);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* The paper palette. Declared on the no-JS fallback too: it renders the same
   manuscript (figures included) outside the stage, and the SVGs read these
   variables. */
#book-stage,
#source {
  --page-w: 560px;
  --page-h: 700px;
  --paper: #FDFCF8;
  --desk: #2E3140;
  /* Diagram palette — the SVGs reference these with their own fallbacks. */
  --fp-value: #3B82F6;
  --fp-op: #6C5CE7;
  --fp-ok: #2F9E68;
  --fp-err: #E5484D;
  --fp-time: #F59E0B;
  --fp-lazy: #9CA3AF;
  --fp-bg: #F0F1F6;
  --fp-ink: #26283B;
}

#book-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* The stage *is* the page: the whole viewport, with nothing above it to
     measure or guess at. `dvh` keeps mobile browsers' collapsing toolbars
     from cropping the book. */
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  background: var(--desk);
  color: var(--fp-ink);
  overflow: hidden;
  /* Contain the sheets' z-indexes so nothing in the book can paint over the
     header once it is sticky. */
  z-index: 0;
}

#scaler { transform-origin: center center; }

/* The book is a plain two-column spread — no perspective, no stacking. Every
   3D flip effect was removed after 300 pages of composited sheets started
   bleeding stale pages through the current one. */
#book {
  position: relative;
  width: calc(var(--page-w) * 2);
  height: var(--page-h);
}

/* Back board — the desk-side panel the pages sit on. */
#book .board {
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: -10px;
  right: -10px;
  background: linear-gradient(135deg, #4B3F72, #3A3159);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
}

#book .spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 26px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(0, 0, 0, .22), rgba(0, 0, 0, .04) 40%,
      rgba(0, 0, 0, .04) 60%, rgba(0, 0, 0, .22));
  z-index: 5;
  pointer-events: none;
}

#sheets {
  position: absolute;
  inset: 0;
  display: flex;
}

.page-slot {
  width: var(--page-w);
  height: 100%;
  background: var(--paper);
  overflow: hidden;
}
.page-slot.left {
  border-radius: 8px 0 0 8px;
  box-shadow: inset -12px 0 24px -14px rgba(0, 0, 0, .35);
}
.page-slot.right {
  border-radius: 0 8px 8px 0;
  box-shadow: inset 12px 0 24px -14px rgba(0, 0, 0, .35);
}
.page-slot[hidden] { display: none; }

/* A short cue that the page changed. The content is already in place before
   this runs, so an interrupted animation can never show the wrong page. */
@keyframes page-in-fwd {
  from { opacity: .35; transform: translateX(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes page-in-back {
  from { opacity: .35; transform: translateX(-6px); }
  to { opacity: 1; transform: none; }
}
.page-slot.turn-fwd { animation: page-in-fwd .16s ease-out; }
.page-slot.turn-back { animation: page-in-back .16s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .page-slot.turn-fwd, .page-slot.turn-back { animation: none; }
}

/* --- the closed book ------------------------------------------------------ */

.book-cover {
  position: absolute;
  left: 50%;
  top: -8px;
  width: calc(var(--page-w) + 10px);
  height: calc(100% + 16px);
  z-index: 6;
}
.book-cover[hidden] { display: none; }

.hc-face { position: absolute; inset: 0; border-radius: 10px; }
.hc-front {
  background:
    radial-gradient(120% 90% at 20% 0%, rgba(255, 255, 255, .10), transparent 55%),
    linear-gradient(150deg, #5A4FD6 0%, #4834D4 55%, #372A96 100%);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
}
.hc-front::before {
  content: '';
  position: absolute; top: 0; bottom: 0; left: 0; width: 14px;
  border-radius: 10px 0 0 10px;
  background: linear-gradient(90deg, rgba(0, 0, 0, .34), rgba(0, 0, 0, 0));
}
.hc-front::after {
  content: '';
  position: absolute; top: 0; bottom: 0; right: 0; width: 8px;
  border-radius: 0 10px 10px 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, .32));
}

.hc-frame {
  position: absolute;
  inset: 24px;
  border: 1.5px solid rgba(255, 255, 255, .30);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
  padding: 34px;
}
.hc-frame .hc-mark { font-size: 13px; letter-spacing: .22em; opacity: .8; margin-bottom: 26px; }
.hc-frame h1 { font-size: 40px; line-height: 1.15; margin: .1em 0 .5em; letter-spacing: .01em; }
.hc-frame .sub { font-size: 15px; opacity: .9; line-height: 1.7; }
.hc-frame .author { position: absolute; bottom: 28px; left: 0; right: 0; font-size: 14px; letter-spacing: .08em; opacity: .92; }

/* --- pages ---------------------------------------------------------------- */

/* Theme isolation. The page is paper in both themes, but site.css colours text
   from the reader's theme (`p, li { color: var(--text) }`, `a`, `code`), and in
   dark mode those tokens are near-white — unreadable on cream. Every text
   colour inside the book is therefore restated from the paper palette instead
   of being inherited. Selectors stay at `.page-content x` so they outrank the
   element-level rules in site.css. */
.page-content,
.page-content p,
.page-content li,
.page-content strong,
.page-content em,
.page-content code,
.page-content blockquote,
.page-content th,
.page-content td,
.page-content h1,
.page-content h2 { color: var(--fp-ink); }

.page { position: relative; width: 100%; height: 100%; padding: 34px 38px 44px; }
.page.cover-full { padding: 0; }
.page-content {
  height: 100%;
  overflow: hidden;
  font-size: 14.5px;
  line-height: 1.72;
  font-family: ui-serif, Georgia, "Times New Roman", serif;
}
.pageno { position: absolute; bottom: 16px; font-size: 11.5px; opacity: .55; }
.pageno.r { right: 22px; }
.pageno.l { left: 22px; }

.page-content p { margin: 0 0 .85em; }
.page-content h2 {
  font-size: 1.2em;
  margin: 1.1em 0 .55em;
  padding-bottom: .25em;
  border-bottom: 2px solid var(--fp-op);
  font-family: system-ui, -apple-system, sans-serif;
}
.page-content h3 {
  font-size: 1.03em;
  margin: 1em 0 .4em;
  color: var(--fp-op);
  font-family: system-ui, -apple-system, sans-serif;
}
.page-content code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: .86em;
  background: var(--fp-bg);
  padding: .05em .24em;
  border-radius: 3px;
}
.page-content a { color: #4834D4; }
.page-content ul, .page-content ol { margin: 0 0 .85em; padding-left: 1.4em; }
.page-content li { margin: 0 0 .3em; }
.page-content hr { border: 0; border-top: 1px solid rgba(0, 0, 0, .12); margin: 1.2em 0; }

.page-content .cap {
  font-size: .82em;
  opacity: .72;
  text-align: center;
  margin: .2em 0 1em;
  line-height: 1.5;
  font-family: system-ui, -apple-system, sans-serif;
}

/* Tightened only when the caption sits directly under its figure — as the
   first block on a page a negative margin would push it off the paper. */
.page-content figure.fig + .cap { margin-top: -.4em; }
.page-content figure.fig { margin: .4em 0 .5em; text-align: center; }
.page-content figure.fig svg { max-width: 100%; height: auto; }

.page-content pre.code {
  background: var(--fp-bg);
  /* `border: 0` first: site.css boxes every pre.code in var(--border), which
     is a dark navy line in the reader's dark theme. */
  border: 0;
  border-left: 3px solid var(--fp-op);
  border-radius: 0 5px 5px 0;
  padding: 9px 11px;
  margin: 0 0 .85em;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.page-content pre.code code { background: none; padding: 0; font-size: inherit; }

/* A listing too tall for one page is cut into parts; the markers say so, so a
   reader never mistakes a page break for the end of the program. */
.page-content [data-code-more] pre.code::after,
.page-content [data-code-from] pre.code::before {
  display: block;
  content: '⋯';
  opacity: .5;
  letter-spacing: .2em;
}
.page-content [data-table-from] thead th::after {
  content: ' ⋯';
  opacity: .5;
  font-weight: 400;
}
.page-content pre.code .cl { display: block; text-indent: -1.6em; padding-left: 1.6em; }

.page-content blockquote {
  margin: 0 0 .9em;
  padding: 10px 13px;
  border-radius: 6px;
  background: var(--fp-bg);
  border-left: 3px solid var(--fp-lazy);
  font-size: .95em;
}
.page-content blockquote p:last-child { margin-bottom: 0; }
.page-content blockquote.goals { border-left-color: var(--fp-value); background: #EEF4FE; }
.page-content blockquote.deep { border-left-color: var(--fp-op); background: #F1EFFD; }

.page-content .tbl { width: 100%; border-collapse: collapse; margin: 0 0 .9em; font-size: .88em; }
.page-content .tbl th, .page-content .tbl td {
  border-bottom: 1px solid rgba(0, 0, 0, .12);
  padding: 5px 7px;
  text-align: left;
  vertical-align: top;
}
.page-content .tbl th { font-family: system-ui, -apple-system, sans-serif; font-size: .95em; }

/* Chapter opener */
.page-content .ch-open { margin: .5em 0 1.4em; }
.page-content .part-tag {
  font-size: .78em;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--fp-op);
  font-family: system-ui, -apple-system, sans-serif;
}
.page-content .part-blurb { font-size: .84em; opacity: .7; margin-top: .3em; }
.page-content .ch-num {
  font-size: 3.2em;
  font-weight: 700;
  line-height: 1;
  color: var(--fp-op);
  opacity: .28;
  margin-top: .25em;
  font-family: system-ui, -apple-system, sans-serif;
}
.page-content .ch-title {
  font-size: 1.55em;
  font-weight: 700;
  line-height: 1.25;
  margin-top: -.15em;
  font-family: system-ui, -apple-system, sans-serif;
}

/* Title page + table of contents */
/* The title page is full-bleed (no page padding), so it carries its own. */
.page-content .title-page { text-align: center; padding: 26% 46px 0; }
.page-content .title-page h1 { font-size: 1.9em; line-height: 1.25; margin: 0 0 .5em; }
.page-content .title-page .sub { font-size: .95em; opacity: .75; }
.page-content .title-page .byline { margin-top: 2.4em; font-size: .85em; letter-spacing: .08em; opacity: .7; }

.page-content .toc h2 { border-bottom-width: 1px; }
.page-content .toc .toc-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: .92em;
  margin: 0 0 .42em;
  cursor: pointer;
}
.page-content .toc .toc-row:hover .t { text-decoration: underline; }
.page-content .toc .n { width: 1.6em; color: var(--fp-op); font-weight: 700; }
.page-content .toc .t { flex: 1; }
.page-content .toc .pg { opacity: .55; font-size: .9em; }
.page-content .toc .toc-part {
  margin: 1em 0 .5em;
  font-size: .78em;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--fp-op);
  font-family: system-ui, -apple-system, sans-serif;
}

/* --- run buttons ---------------------------------------------------------- */

.runwrap { position: relative; margin: 0 0 .85em; }
.runwrap pre.code { margin-bottom: 0; }
.runbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-family: system-ui, -apple-system, sans-serif;
}
.run-btn {
  font: inherit;
  font-size: 11px;
  padding: 2px 9px;
  border: 1px solid var(--fp-op);
  color: var(--fp-op);
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
}
.run-btn:hover { background: var(--fp-op); color: #fff; }
.run-btn[disabled] { opacity: .5; cursor: default; }
.run-status { font-size: 10.5px; opacity: .65; }

/* Edit opens the whole program in the overlay — a book page is a fixed box, so
   typing cannot happen in place without pushing text off the paper. */
.edit-btn {
  font: inherit;
  font-size: 11px;
  padding: 2px 9px;
  border: 1px solid var(--fp-lazy);
  color: var(--fp-ink);
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  opacity: .75;
}
.edit-btn:hover { opacity: 1; border-color: var(--fp-ink); }

/* An edited listing still prints the published text; the badge says so. */
.runwrap[data-edited] .runbar::after {
  content: attr(data-edited-label);
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--fp-time);
  border: 1px solid var(--fp-time);
  border-radius: 999px;
  padding: 1px 7px;
}
.runwrap[data-edited] pre.code { border-left-color: var(--fp-time); }

/* Absolutely positioned so showing output never reflows the page — a book
   page has a fixed height, and reflow would push text off the paper. */
.run-out {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 20;
  background: #1E2030;
  color: #E7E9F5;
  border-radius: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
  overflow: hidden;
  font-family: ui-monospace, Menlo, monospace;
}
.run-out-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  background: rgba(255, 255, 255, .07);
  font-size: 10.5px;
  letter-spacing: .06em;
}
.run-close { background: none; border: 0; color: inherit; cursor: pointer; font-size: 12px; line-height: 1; }
.run-log {
  margin: 0;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.5;
  max-height: 190px;
  overflow: auto;
  white-space: pre-wrap;
}

/* --- navigation ----------------------------------------------------------- */

.book-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  z-index: 500;
}
.book-nav:hover { background: rgba(255, 255, 255, .24); }
.book-nav[disabled] { opacity: .25; cursor: default; }
#nav-prev { left: 14px; }
#nav-next { right: 14px; }

/* Close: the only way out of the book, so it is always in the same corner. */
#book-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  text-decoration: none;
  z-index: 500;
}
#book-close:hover { background: rgba(255, 255, 255, .26); }

#book-hud {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  color: rgba(255, 255, 255, .8);
  font-size: 12px;
  z-index: 500;
}

.book-note {
  color: rgba(255, 255, 255, .6);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 11.5px;
  max-width: 40ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-note:hover { color: rgba(255, 255, 255, .9); }

.book-langs {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}
.book-langs a {
  color: rgba(255, 255, 255, .55);
  text-decoration: none;
  font-size: 11.5px;
}
.book-langs a:hover { color: rgba(255, 255, 255, .9); }
.book-langs a[aria-current="page"] { color: #fff; font-weight: 700; }

/* The switcher's last row is not an edition — it is how one gets made. A
   border keeps it from reading as another language in the list. */
.book-contribute {
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  padding: 2px 10px;
}
.book-contribute:hover { border-color: rgba(255, 255, 255, .6); }
#book-hud button {
  font: inherit;
  background: rgba(255, 255, 255, .12);
  color: inherit;
  border: 0;
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
}
#book-hud button:hover { background: rgba(255, 255, 255, .24); }

/* The page picker, the language button and the chapter crumb belong to
   single-page mode; a spread shows its own page numbers, carries the Contents
   button and lists every edition along the foot of the page. */
#goto-btn, #lang-btn, #book-crumb { display: none; }

/* --- single-page mode ------------------------------------------------------
 *
 * A spread of two 560px pages fitted to a phone lands at about a quarter
 * scale: a picture of a book, not a page anyone can read. Under ~880px (or a
 * very short window) the viewer drops the fold and gives one page the whole
 * screen — which is why nothing here has a fixed size. js/theorybook.js
 * measures what this layout leaves over, writes it back as --page-w/--page-h,
 * and flows the manuscript into that box.
 *
 * The controls move with the paper: full-bleed pages leave no margin for the
 * side arrows to sit in, so back, the page picker and forward line up in a bar
 * beneath the page, and the language links move into the picker sheet.
 */

body.book-single #book-stage {
  display: flex;
  flex-direction: column;
  /* Room for the close button — with the paper reaching both edges there is no
     margin left for it to float in. */
  padding-top: 38px;
  /* svh, not dvh: a collapsing browser toolbar must not change the page box,
     or a scroll would re-flow three hundred pages. */
  height: 100svh;
}

/* #scaler stops scaling and just centres the page in the space the bar and
   the close strip leave over. It is pinned to the stage's width and clipped:
   left to size itself it would follow #book, which is sized *from* this box. */
body.book-single #scaler {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: none !important;
}

body.book-single #book { width: var(--page-w); }
body.book-single #book .board { left: -5px; right: -5px; }
body.book-single .spine,
body.book-single .page-slot.left { display: none; }
body.book-single .page-slot.right { border-radius: 8px; box-shadow: none; }
body.book-single .book-cover { left: 0; width: 100%; }

/* The page is now the width of a phone: less margin, larger type. */
body.book-single .page { padding: 22px 18px 30px; }
body.book-single .page-content { font-size: 15.5px; }
body.book-single .page-content pre.code { font-size: 10.5px; }
body.book-single .pageno { bottom: 9px; }
body.book-single .pageno.r { right: 14px; }
body.book-single .pageno.l { left: 14px; }
body.book-single .hc-frame { padding: 24px; }
body.book-single .hc-frame h1 { font-size: 32px; }

body.book-single #book-close { top: 5px; right: 8px; width: 32px; height: 32px; }

/* Which chapter this is — a spread showed that for free, one page does not. */
body.book-single #book-crumb {
  display: block;
  position: absolute;
  top: 13px;
  left: 14px;
  right: 52px;
  color: rgba(255, 255, 255, .55);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 500;
}

/* The bar: three touch targets, nothing else. The page indicator moves into
   the picker button, and the notice and language links into its sheet. */
body.book-single #book-hud {
  position: static;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
body.book-single #book-hud #page-indicator,
body.book-single #book-hud #toc-btn,
body.book-single #book-hud .book-note,
body.book-single #book-hud .book-langs { display: none; }

body.book-single .book-nav {
  position: static;
  transform: none;
  flex: 0 0 auto;
  width: 62px;
  height: 44px;
  border-radius: 12px;
}
body.book-single #goto-btn {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  border-radius: 12px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
/* Globe plus the tag of the edition being read — the bar has room for that
   much, and it doubles as the label for what the button opens. */
body.book-single #lang-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 0 0 auto;
  height: 44px;
  padding: 0 11px;
  border-radius: 12px;
  font-size: 12px;
  letter-spacing: .04em;
}
body.book-single #lang-btn svg { flex: 0 0 auto; opacity: .85; }

/* --- the page picker ------------------------------------------------------ */

.goto-sheet {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(12, 13, 22, .6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.goto-sheet[hidden] { display: none; }

.goto-panel {
  width: min(520px, 100%);
  max-height: 84%;
  display: flex;
  flex-direction: column;
  background: #232637;
  color: #E7E9F5;
  border-radius: 14px 14px 0 0;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -18px 50px rgba(0, 0, 0, .5);
}

.goto-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
  font-size: 13px;
}
.goto-close {
  background: none;
  border: 0;
  color: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.goto-form { display: flex; gap: 8px; padding: 0 14px 10px; }
.goto-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  /* 16px exactly: anything smaller and iOS zooms the page on focus. */
  font-size: 16px;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(255, 255, 255, .06);
  color: inherit;
}
.goto-submit {
  font: inherit;
  font-size: 14px;
  padding: 8px 18px;
  border: 0;
  border-radius: 9px;
  background: var(--fp-op, #6C5CE7);
  color: #fff;
  cursor: pointer;
}

.goto-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 8px 12px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.goto-row {
  display: flex;
  width: 100%;
  gap: 10px;
  align-items: baseline;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  background: none;
  border: 0;
  color: inherit;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.goto-row:hover { background: rgba(255, 255, 255, .08); }
/* The chapter being read — the list opens scrolled to it. */
.goto-row[aria-current] { background: rgba(169, 155, 255, .16); }
.goto-row[aria-current] .t { font-weight: 700; }
.goto-row .n { width: 1.8em; color: #A99BFF; font-weight: 700; }
.goto-row .t { flex: 1 1 auto; }
.goto-row .pg { opacity: .5; font-size: .9em; }
.goto-part {
  margin: 14px 8px 4px;
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .45);
}

/* The language sheet: the same panel, holding the switcher as a list of rows
   big enough to hit. The links are the page's own — moved here, not copied —
   so they keep the handler that carries the reading position across editions. */
.lang-body {
  overflow-y: auto;
  padding: 2px 8px 14px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.lang-sheet .book-langs { display: block; }
.lang-sheet .book-langs a {
  display: block;
  padding: 12px 10px;
  border-radius: 8px;
  font-size: 15px;
  color: rgba(255, 255, 255, .75);
}
.lang-sheet .book-langs a[aria-current="page"] {
  background: rgba(169, 155, 255, .16);
  color: #fff;
}
.lang-sheet .book-contribute {
  margin-top: 10px;
  text-align: center;
  border-color: rgba(255, 255, 255, .35);
  border-radius: 10px;
  padding: 12px 10px;
  font-size: 14px;
  color: rgba(255, 255, 255, .9);
}
.lang-sheet .book-note {
  display: block;
  margin-top: 8px;
  padding: 10px;
  max-width: none;
  white-space: normal;
  font-size: 12px;
  line-height: 1.5;
}

/* The overlay editor has no margin to spare on a phone. */
body.book-single .editor-overlay { padding: 8px; }

/* --- the editor overlay --------------------------------------------------- */

.editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(12, 13, 22, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.editor-overlay[hidden] { display: none; }

.editor-panel {
  width: min(920px, 100%);
  height: min(760px, 100%);
  display: flex;
  flex-direction: column;
  background: #1E2030;
  color: #E7E9F5;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, .06);
  font-size: 13px;
}
.editor-close {
  background: none;
  border: 0;
  color: inherit;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
}

.editor-code {
  flex: 1;
  min-height: 220px;
  resize: none;
  border: 0;
  outline: none;
  padding: 14px;
  background: transparent;
  color: #E7E9F5;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.editor-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.editor-run, .editor-reset {
  font: inherit;
  font-size: 12.5px;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .25);
  background: transparent;
  color: #E7E9F5;
}
.editor-run { background: var(--fp-op); border-color: var(--fp-op); color: #fff; }
.editor-run[disabled], .editor-reset[disabled] { opacity: .45; cursor: default; }
.editor-status { font-size: 11.5px; opacity: .7; }

.editor-out {
  border-top: 1px solid rgba(255, 255, 255, .08);
  background: #14161f;
}
.editor-out[hidden] { display: none; }
.editor-log {
  margin: 0;
  padding: 12px 14px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  max-height: 34vh;
  overflow: auto;
  white-space: pre-wrap;
}

#source { display: none; }

/* No per-width height overrides here: the header is exactly what wraps at
   narrow widths, so any constant subtracted from 100vh is wrong precisely
   where it matters. js/theorybook.js measures it instead. */

@media print {
  #book-stage, .book-nav, #book-hud { display: none; }
}
