/* ==========================================================================
   pgAcademy — editorial light theme
   An illustrated field guide to the Postgres planner & executor.

   Palette: warm cream paper, deep navy ink, engraved gold seals.
   Type:    Fraunces (display serif, variable)
            IBM Plex Sans (body)
            JetBrains Mono (code & labels)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,300..700&family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* paper & ink */
  --paper:        #FBF7EC;
  --paper-sunk:   #F2EAD2;
  --paper-deep:   #E8DCBB;
  --paper-white:  #FFFEFA;

  --ink:          #14213D;
  --ink-soft:     #2D3B59;
  --ink-muted:    #6B6555;
  --ink-faint:    #9C9684;

  /* engraved accents */
  --seal:         #9A7B1E;      /* dimmed gold — reads as printed ink, not highlighter */
  --seal-bright:  #C3A246;
  --brick:        #A84A26;      /* warm terracotta for rare emphasis */
  --rule:         #C8B98A;      /* dried gold, for hairlines */
  --rule-faint:   #E6DBBD;

  /* semantic */
  --good:         #3D6F3F;
  --warn:         #9A6B14;
  --bad:          #A33428;

  /* legacy aliases (per-page overrides use these — do not rename) */
  --bg:             var(--paper);
  --panel:          var(--paper-sunk);
  --panel-2:        var(--paper-deep);
  --accent:         var(--ink);
  --accent2:        var(--seal);
  --accent3:        var(--brick);
  --text:           var(--ink);
  --muted:          var(--ink-muted);
  --border:         var(--rule);
  --border-strong:  var(--seal);
  --code-bg:        var(--paper-sunk);

  --shadow-sm:  0 1px 0 rgba(20,33,61,0.04), 0 1px 2px rgba(20,33,61,0.05);
  --shadow-md:  0 2px 4px rgba(20,33,61,0.06), 0 8px 20px rgba(20,33,61,0.08);

  /* typography */
  --ff-serif:    "Fraunces", "Iowan Old Style", Georgia, serif;
  --ff-sans:     "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  --ff-mono:     "JetBrains Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  font-family: var(--ff-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--paper);
  /* faint baseline: two nearly-invisible diagonal hatches for paper grain */
  background-image:
    radial-gradient(1200px 500px at 80% -10%, rgba(154,123,30,0.05), transparent 60%),
    radial-gradient(900px 400px  at -10% 30%, rgba(20,33,61,0.035), transparent 60%);
  background-attachment: fixed;
}

a {
  color: var(--ink);
  text-decoration-line: underline;
  text-decoration-color: var(--seal);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.15s;
}
a:hover { color: var(--seal); text-decoration-color: var(--ink); }

/* -------- content-page header (masthead strip) -------- */
header {
  padding: 14px 36px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--paper-white), var(--paper) 100%);
  display: flex;
  align-items: center;
  gap: 28px;
  position: relative;
}
/* engraved double rule under every content header */
header::after {
  content: "";
  position: absolute;
  left: 36px; right: 36px; bottom: -5px;
  height: 1px;
  background: var(--rule);
  opacity: 0.55;
}
/* brand pill — 'pgAcademy' set as small caps with a gold laurel ornament */
header::before {
  content: "❦  pg·Academy";
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--ff-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 2.8px;
  text-transform: uppercase;
  color: var(--ink);
  padding: 6px 12px 5px;
  border-top: 1px solid var(--seal);
  border-bottom: 1px solid var(--seal);
  background: transparent;
  white-space: nowrap;
  flex-shrink: 0;
}

h1 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-family: var(--ff-serif);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.4px;
  color: var(--ink);
}
h1 .sub {
  font-family: var(--ff-sans);
  color: var(--ink-muted);
  font-weight: 400;
  font-size: 13.5px;
  margin-left: 10px;
  font-style: italic;
}

.home-link {
  color: var(--ink-muted);
  font-family: var(--ff-mono);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 6px 14px;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--paper-white);
  text-decoration: none;
  transition: all 0.15s;
  flex-shrink: 0;
}
.home-link:hover { border-color: var(--ink); color: var(--ink); }

/* -------- main layout -------- */
main {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: calc(100vh - 71px);
}

.narration {
  border-right: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--paper-white) 0%, var(--paper) 100%);
  display: flex;
  flex-direction: column;
  height: 100%;
}
.narration-scroll { padding: 32px 32px 24px; overflow-y: auto; flex: 1; }
.narration-pinned {
  padding: 18px 32px 20px;
  border-top: 1px solid var(--rule);
  background: var(--paper-sunk);
  position: relative;
}
/* thin gold accent rule above pinned block — marks it as a distinct 'chapter foot' */
.narration-pinned::before {
  content: "";
  position: absolute;
  left: 32px; right: 32px; top: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--seal) 0%, var(--seal) 48px, transparent 48px);
}
.narration-pinned .controls { margin-top: 0; }
.narration-pinned .controls + .controls { margin-top: 10px; }

/* eyebrow (step label) — set like a chapter marker */
.narration h2 {
  margin: 0 0 12px;
  font-family: var(--ff-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--seal);
  display: flex;
  align-items: center;
  gap: 10px;
}
.narration h2::before {
  content: "§";
  font-family: var(--ff-serif);
  font-size: 16px;
  font-weight: 500;
  color: var(--seal);
  letter-spacing: 0;
  line-height: 1;
}
.narration h2 span { font-family: var(--ff-mono); color: var(--ink); font-weight: 600; font-size: 11px; }

.step-title {
  margin: 0 0 18px;
  font-family: var(--ff-serif);
  font-optical-sizing: auto;
  font-weight: 450;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.5px;
  color: var(--ink);
  font-variation-settings: "opsz" 48;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule-faint);
}

.narration p {
  margin: 0 0 12px;
  font-family: var(--ff-sans);
  font-size: 14.5px;
  line-height: 1.62;
  color: var(--ink-soft);
}
.narration p + p { margin-top: 2px; }
.narration p b { color: var(--ink); font-weight: 600; }
.narration code,
.pgnote code,
.stage code {
  font-family: var(--ff-mono);
  font-size: 12px;
  padding: 1px 6px;
  background: var(--paper-sunk);
  border: 1px solid var(--rule-faint);
  border-radius: 2px;
  color: var(--ink);
}

/* marginalia-flavoured footnote callout */
.pgnote {
  margin-top: 22px;
  padding: 16px 16px 14px 18px;
  border-left: 2px solid var(--seal);
  background: var(--paper-sunk);
  font-family: var(--ff-sans);
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
  position: relative;
}
/* faint gold ornament at the top — helps the left-rule feel 'cast' rather than pasted */
.pgnote::after {
  content: "";
  position: absolute;
  left: -2px; top: 0;
  width: 2px; height: 18px;
  background: var(--ink);
}
.pgnote::before {
  content: "Marginalia";
  position: absolute;
  top: -8px; left: 12px;
  padding: 1px 8px 0;
  background: var(--paper);
  font-family: var(--ff-mono);
  font-size: 9px;
  letter-spacing: 2.8px;
  text-transform: uppercase;
  color: var(--seal);
  font-weight: 600;
  border-left: 1px solid var(--rule-faint);
  border-right: 1px solid var(--rule-faint);
}
.pgnote b { color: var(--ink); font-weight: 600; }

/* -------- stage -------- */
.stage {
  padding: 36px 40px;
  overflow: auto;
  background: var(--paper);
}

body .query-box {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--ink);
  padding: 16px 20px;
  border-radius: 0;
  font-family: var(--ff-mono);
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 28px;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  position: relative;
}
body .query-box::before {
  content: "SQL";
  position: absolute;
  top: -9px; left: 14px;
  padding: 0 6px;
  background: var(--paper);
  font-family: var(--ff-mono);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--seal);
  font-weight: 600;
}
body .query-box .kw  { color: var(--ink); font-weight: 600; }
body .query-box .str { color: var(--good); font-style: italic; }
body .query-box .num { color: var(--brick); font-weight: 500; }

/* -------- buttons -------- */
.controls { margin-top: 22px; display: flex; gap: 10px; align-items: center; }
button {
  background: var(--ink);
  color: var(--paper-white);
  border: 1px solid var(--ink);
  padding: 9px 18px;
  border-radius: 0;
  font-family: var(--ff-mono);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}
button:hover { background: var(--paper-white); color: var(--ink); }
/* primary CTA (Next) — emphasise with subtle gold underline on hover so it stays distinct from the inverted look */
#next {
  box-shadow: 0 1px 0 var(--seal), var(--shadow-sm);
}
#next:hover:not(:disabled) {
  background: var(--paper-white);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--seal), var(--shadow-sm);
  transform: translateY(-1px);
}
#next:active:not(:disabled) { transform: translateY(0); }

button.secondary {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--rule);
  box-shadow: none;
}
button.secondary:hover { border-color: var(--ink); color: var(--ink); background: var(--paper-white); }
button:disabled { opacity: 0.3; cursor: not-allowed; }
button:disabled:hover { background: var(--ink); color: var(--paper-white); transform: none; box-shadow: var(--shadow-sm); }

/* step counter — upgraded from tiny afterthought to a visible progress indicator */
.step-counter {
  color: var(--ink);
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  margin-left: auto;
  padding: 4px 10px 3px;
  background: var(--paper-white);
  border: 1px solid var(--rule);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.step-counter::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--seal);
  box-shadow: 0 0 0 2px var(--paper-white), 0 0 0 3px var(--rule-faint);
}

/* -------- legend -------- */
.legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dotted var(--rule);
  font-family: var(--ff-mono);
  font-size: 10.5px;
  letter-spacing: 0.5px;
  color: var(--ink-muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot {
  width: 11px; height: 11px; border-radius: 1px;
  border: 1px solid rgba(20,33,61,0.15);
  box-shadow: inset 0 0 0 0.5px rgba(255,255,255,0.5);
}

/* -------- generic primitives -------- */
.panel {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 16px 18px;
  transition: all 0.4s ease;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.panel-title {
  font-family: var(--ff-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2.2px;
  color: var(--ink-muted);
  margin-bottom: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-title::before {
  content: "";
  display: inline-block;
  width: 14px; height: 1px;
  background: var(--seal);
}
.panel.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink), var(--shadow-md);
}
.panel.active .panel-title { color: var(--ink); }
.panel.active .panel-title::before { background: var(--ink); }
.panel.done { border-color: var(--good); }
.panel.done .panel-title { color: var(--good); }
.panel.done .panel-title::before { background: var(--good); }

/* -------- heap pages / tuples -------- */
.pages { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; }
body .page {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 8px;
  transition: all 0.4s;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.page-num {
  font-size: 9.5px;
  color: var(--ink-muted);
  text-align: center;
  margin-bottom: 6px;
  font-family: var(--ff-mono);
  letter-spacing: 0.5px;
}
.tuples { display: grid; grid-template-columns: repeat(2, 1fr); gap: 3px; }
body .tuple {
  aspect-ratio: 1;
  border-radius: 1px;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  transition: all 0.3s;
}
body .tuple.candidate { background: #F4D48C; border-color: var(--warn); }
body .tuple.match     { background: #9BC39D; border-color: var(--good); }
body .tuple.reject    { background: #E2B4B0; border-color: var(--bad); opacity: 0.6; }
body .tuple.scanning  { background: #AFBFDE; border-color: var(--ink); }

body .page.reading {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink), var(--shadow-md);
  transform: translateY(-3px);
}

/* -------- rows (tabular results) -------- */
body .row {
  font-family: var(--ff-mono);
  font-size: 11.5px;
  padding: 7px 11px;
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  margin-bottom: 4px;
  transition: all 0.3s;
  color: var(--ink);
}
body .row.highlight { border-color: var(--ink);    background: rgba(20,33,61,0.05);   box-shadow: inset 3px 0 0 var(--ink); }
body .row.match     { border-color: var(--good);   background: rgba(61,111,63,0.08);  box-shadow: inset 3px 0 0 var(--good); }
body .row.cursor    { border-color: var(--seal);   background: rgba(154,123,30,0.08); box-shadow: inset 3px 0 0 var(--seal); }
body .row.scanned   { opacity: 0.38; }

/* -------- tree nodes (B-tree / GiST) -------- */
body .tnode {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  color: var(--ink-muted);
  box-shadow: var(--shadow-sm);
  font-family: var(--ff-mono);
  border-radius: 0;
}
body .tnode .k { color: var(--ink); }
body .tnode.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
  color: var(--ink);
  background: var(--paper-white);
}
body .tnode.path   { border-color: var(--good); color: var(--good); background: rgba(61,111,63,0.05); }
body .tnode.match  { background: rgba(154,123,30,0.12); border-color: var(--seal); color: #6b5613; }
body .tnode.reject { opacity: 0.28; }
body .leaf-link { color: var(--ink-muted); }
body .leaf-link.active { color: var(--seal); }

/* -------- GiST 2D map -------- */
body .map {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  box-shadow: inset 0 0 0 4px var(--paper-white), inset 0 0 0 5px var(--rule-faint);
  background-image:
    linear-gradient(to right, rgba(20,33,61,0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(20,33,61,0.04) 1px, transparent 1px);
  background-size: 10% 10%;
}
body .box.active { box-shadow: 0 0 0 2px var(--ink); }

/* -------- bitmap bits -------- */
body .bit {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  color: var(--ink-faint);
  font-family: var(--ff-mono);
  border-radius: 0;
}
body .bit.set {
  background: var(--ink);
  color: var(--paper-white);
  border-color: var(--ink);
  font-weight: 600;
}
body .bit.set.pink  { background: var(--seal);   border-color: var(--seal);   color: var(--paper-white); }
body .bit.set.green { background: var(--good);   border-color: var(--good);   color: var(--paper-white); }

body .arrow.active { color: var(--ink); }
body .page.lossy::after {
  background: var(--brick);
  color: var(--paper-white);
  font-family: var(--ff-mono);
  font-weight: 700;
}

/* -------- scrollbars -------- */
.narration-scroll::-webkit-scrollbar,
.stage::-webkit-scrollbar { width: 10px; height: 10px; }
.narration-scroll::-webkit-scrollbar-track,
.stage::-webkit-scrollbar-track { background: transparent; }
.narration-scroll::-webkit-scrollbar-thumb,
.stage::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 0;
  border: 3px solid var(--paper);
}
.narration-scroll::-webkit-scrollbar-thumb { border-color: var(--paper); }

/* -------- selection -------- */
::selection { background: rgba(195,162,70,0.45); color: var(--ink); }

/* ==========================================================================
   Per-page primitive overrides — defeat hardcoded dark hex values inside
   each content page's inline <style>. Use body-scoped selectors so these
   win on specificity without touching the HTML files.
   ========================================================================== */

/* tree nodes used by bitmap-index-scan / index-scan / others */
body .bnode {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  color: var(--ink-muted);
  font-family: var(--ff-mono);
  border-radius: 0;
  box-shadow: var(--shadow-sm);
}
body .bnode.active { border-color: var(--ink); color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
body .bnode.path   { border-color: var(--good); color: var(--good); background: rgba(61,111,63,0.06); }

/* leaf-entry chips (index-scan, index-only-scan) */
body .leaf-entry {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  color: var(--ink);
  border-radius: 0;
  font-family: var(--ff-mono);
}
body .leaf-entry.hit       { background: rgba(154,123,30,0.12); border-color: var(--seal); color: #6b5613; }
body .leaf-entry.fetched   { background: rgba(61,111,63,0.10);  border-color: var(--good); color: var(--good); }
body .leaf-entry.answered  { background: rgba(61,111,63,0.10);  border-color: var(--good); color: var(--good); }
body .leaf-entry.needs-heap{ background: rgba(154,107,20,0.10); border-color: var(--warn); color: var(--warn); }

/* hash buckets (hash-join, hash-aggregate, hash-index) */
body .bucket {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  font-family: var(--ff-mono);
  box-shadow: var(--shadow-sm);
}
body .bucket .bhead { color: var(--ink-muted); }
body .bucket .entry {
  background: var(--paper-sunk);
  color: var(--ink);
  border-radius: 0;
}
body .bucket .entry.matched { background: rgba(61,111,63,0.14); color: var(--good); }
body .bucket.updating,
body .bucket.probing {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink), var(--shadow-md);
}
body .bucket .key   { color: var(--seal); }
body .bucket .state { color: var(--good); }
body .bucket .overflow { color: var(--warn); border-top-color: var(--rule); }

/* nested-loop / hash-join / merge-join output rows */
body .result-row {
  background: rgba(61,111,63,0.08);
  border: 1px solid var(--good);
  border-radius: 0;
  color: var(--good);
  font-family: var(--ff-mono);
  box-shadow: inset 3px 0 0 var(--good);
}
body .pairing,
body .cursor-indicator {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  color: var(--ink-muted);
  border-radius: 0;
  font-family: var(--ff-mono);
}
body .pairing b,
body .cursor-indicator b { color: var(--ink); }

/* visibility map bits (index-only-scan) */
body .vm-bit {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  color: var(--ink-muted);
  font-family: var(--ff-mono);
  border-radius: 0;
}
body .vm-bit.all-visible { background: rgba(61,111,63,0.14);  color: var(--good); border-color: var(--good); }
body .vm-bit.dirty       { background: rgba(154,107,20,0.14); color: var(--warn); border-color: var(--warn); }
body .vm-bit.checking    { box-shadow: 0 0 0 2px var(--ink); }

/* hash-index — indexed-values list */
body .key-row {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  font-family: var(--ff-mono);
  color: var(--ink);
}
body .key-row.highlight {
  border-color: var(--ink);
  background: rgba(20,33,61,0.04);
  box-shadow: inset 3px 0 0 var(--ink);
}
body .key-row .h { color: var(--seal); }

/* GIN — documents & inverted index */
body .doc {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink);
}
body .doc .did     { color: var(--seal); font-family: var(--ff-mono); }
body .doc .content { color: var(--ink-soft); font-family: var(--ff-sans); font-style: italic; }
body .doc.highlight { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }

body .term-row {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  font-family: var(--ff-mono);
  color: var(--ink);
}
body .term-row .term { color: var(--seal); font-weight: 700; }
body .term-row .chip {
  background: rgba(61,111,63,0.10);
  border: 1px solid var(--good);
  color: var(--good);
  border-radius: 0;
}
body .term-row.highlight { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
body .intersect-box {
  background: rgba(168,74,38,0.06);
  border: 1px dashed var(--brick);
  border-radius: 0;
  color: var(--brick);
  font-family: var(--ff-mono);
}

/* BRIN — heap strip & range table */
body .hblock {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink-muted);
  font-family: var(--ff-mono);
}
body .hblock.in-range { opacity: 1; }
body .hblock.skipped  { background: rgba(163,52,40,0.14); border-color: var(--bad); color: var(--bad); opacity: 0.6; }
body .hblock.selected { background: var(--ink);          border-color: var(--ink); color: var(--paper-white); font-weight: 600; }

body .range-row {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  font-family: var(--ff-mono);
  color: var(--ink);
}
body .range-row .rlabel  { color: var(--ink-muted); }
body .range-row .rmin    { color: var(--ink); }
body .range-row .rmax    { color: var(--seal); }
body .range-row.hit      { border-color: var(--good); background: rgba(61,111,63,0.06); box-shadow: inset 3px 0 0 var(--good); }
body .range-row.hit .verdict  { color: var(--good); }
body .range-row.skip     { opacity: 0.45; }
body .range-row.skip .verdict { color: var(--bad); }

/* Bloom index — bit array & value list */
body .bbit {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  color: var(--ink-faint);
  font-family: var(--ff-mono);
  border-radius: 0;
}
body .bbit.set         { background: var(--ink);  border-color: var(--ink);  color: var(--paper-white); font-weight: 600; }
body .bbit.probe       { box-shadow: 0 0 0 2px var(--seal); }
body .bbit.probe.set   { background: var(--good); border-color: var(--good); color: var(--paper-white); }
body .bbit.probe.unset { background: var(--bad);  border-color: var(--bad);  color: var(--paper-white); }

body .val {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink);
  font-family: var(--ff-mono);
}
body .val .hashes  { color: var(--ink-muted); }
body .val.active   { border-color: var(--ink);   background: rgba(20,33,61,0.04);   box-shadow: inset 3px 0 0 var(--ink); }
body .val.match    { border-color: var(--good);  background: rgba(61,111,63,0.08);  box-shadow: inset 3px 0 0 var(--good); }
body .val.false-pos{ border-color: var(--warn);  background: rgba(154,107,20,0.08); box-shadow: inset 3px 0 0 var(--warn); }
body .val.miss     { border-color: var(--bad);   background: rgba(163,52,40,0.08);  box-shadow: inset 3px 0 0 var(--bad); }

body .verdict {
  background: var(--paper-sunk);
  border-left: 3px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  font-family: var(--ff-mono);
}

/* Gather — parallel workers */
body .worker {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  box-shadow: var(--shadow-sm);
}
body .worker.active    { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink), var(--shadow-md); }
body .worker .name     { color: var(--seal); font-family: var(--ff-mono); font-weight: 600; }
body .worker .blocks   { color: var(--ink-muted); font-family: var(--ff-mono); }
body .worker .emitted  { color: var(--good); font-family: var(--ff-mono); }

body .queue {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink-muted);
  font-family: var(--ff-mono);
}
body .tuple-chip {
  background: rgba(61,111,63,0.10);
  border: 1px solid var(--good);
  color: var(--good);
  border-radius: 0;
}
body .block {
  background: var(--paper-white);
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--ink-muted);
  font-family: var(--ff-mono);
}
body .block.w0 { background: rgba(20,33,61,0.12);   color: var(--ink);   border-color: var(--ink); }
body .block.w1 { background: rgba(154,123,30,0.18); color: #6b5613;      border-color: var(--seal); }
body .block.w2 { background: rgba(168,74,38,0.12);  color: var(--brick); border-color: var(--brick); }

/* streams (hash-aggregate, index-only) */
body .stream { background: transparent; }

/* TID badges (bitmap-index-scan) */
body .tid-badge {
  background: rgba(154,123,30,0.10);
  border: 1px solid var(--seal);
  color: #6b5613;
  border-radius: 0;
  font-family: var(--ff-mono);
}

/* bitmap color classes (bitmap-and.html / bitmap-or.html) — force text to paper-white
   since they hardcode color:#0f172a on ink-dark backgrounds. */
body .bit.a,
body .bit.b,
body .bit.and,
body .bit.or  { color: var(--paper-white); }
body .bit.a   { background: var(--ink);   border-color: var(--ink); }
body .bit.b   { background: var(--seal);  border-color: var(--seal); }
body .bit.and { background: var(--good);  border-color: var(--good); }
body .bit.or  { background: var(--brick); border-color: var(--brick); }

/* GiST 2D map — region colors shift onto the light grid */
body .box.r1 { border-color: var(--ink);   color: var(--ink); }
body .box.r2 { border-color: var(--seal);  color: #6b5613; }
body .box.l  { border-color: var(--good);  color: var(--good); background: rgba(61,111,63,0.06); }
body .box.q  { border-color: var(--warn);  color: var(--warn); background: rgba(154,107,20,0.10); border-style: dashed; }

/* -------- pgnote: dark-marker variant used by some legacy markup -------- */
/* keep pgnote consistent even if any page injects raw text after ::before. */

/* ==========================================================================
   Polish pass — micro-interactions, empty states, responsive stack.
   ========================================================================== */

/* Empty / intermediate-result containers in the stage — a muted italic feel
   so "(none yet)" or "(empty)" reads as deliberately quiet, not forgotten.
   Applies to the common #results / minHeight placeholders used across pages. */
.stage #results:empty::before,
.stage .panel > div[id]:empty::before { content: ""; }

body .stage #results,
body .stage .panel > div[id^="results"],
body .stage .panel > div[id="output"] {
  font-family: var(--ff-mono);
  font-size: 12px;
  color: var(--ink-muted);
}
body .stage .muted-empty,
body .stage .empty {
  font-family: var(--ff-mono);
  font-size: 12px;
  font-style: italic;
  color: var(--ink-faint);
}

/* Panel-entry emphasis: pages that animate a newly-added result feel more
   'inked' with a subtle gold leading mark. Safe no-op where unused. */
body .stage .entered {
  position: relative;
  padding-left: 14px;
}
body .stage .entered::before {
  content: "–";
  position: absolute;
  left: 0; top: 0;
  color: var(--seal);
  font-family: var(--ff-serif);
  font-weight: 600;
}

/* Responsive: on narrow viewports, stack narration above stage so the
   380px sidebar doesn't squeeze the visualization. */
@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: calc(100vh - 71px);
  }
  .narration {
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    height: auto;
    max-height: 60vh;
  }
  .narration-scroll { padding: 24px 22px 18px; }
  .narration-pinned { padding: 14px 22px 16px; }
  .stage { padding: 24px 22px; }
  header { padding: 12px 20px; gap: 14px; flex-wrap: wrap; }
  header h1 { font-size: 18px; }
  h1 .sub { display: block; margin-left: 0; margin-top: 2px; font-size: 12.5px; }
  .pages { grid-template-columns: repeat(4, 1fr); }
  .controls { flex-wrap: wrap; }
  .step-counter { margin-left: 0; }
}

@media (max-width: 560px) {
  .pages { grid-template-columns: repeat(3, 1fr); }
  header::before { display: none; } /* drop the brand pill — h1 carries the page */
  .step-title { font-size: 22px; }
}

/* Accessibility: visible focus outlines that match the editorial palette. */
button:focus-visible,
.home-link:focus-visible,
a:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  #next:hover:not(:disabled) { transform: none; }
}
