/* ═══════════════════════════════════════════════════════════
   TOC Rail — chapter-based navigation for scroll pages.
   Distinctive look (not a clone of devouringdetails):
   - Vertical chapter bars with rotated labels
   - Tiny section ticks within each chapter
   - Slide-in panel on hover reveals full titles

   Usage:
     <link rel="stylesheet" href="/assets/css/toc-rail.css">
     <script src="/assets/js/toc-rail.js" defer></script>

   Markup is generated by JS from section data-toc attributes.
   ─────────────────────────────────────────────────────────── */

.tocr {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 80;
  display: flex;
  align-items: stretch;
  font-family: var(--font-sans, system-ui);
  pointer-events: none; /* only the inner elements catch events */
}

/* ─── Hover-detect column (invisible wider zone to make hover forgiving) ── */
.tocr__hotzone {
  width: 44px;
  height: 100%;
  pointer-events: auto;
  position: relative;
}

/* ─── The visible rail ── */
.tocr__rail {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 28px;
  padding: 96px 0 96px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
  pointer-events: auto;
  background: transparent;
}

/* ─── Chapter group ── */
.tocr__chapter {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  justify-content: center;
  position: relative;
}
.tocr__chapter + .tocr__chapter::before {
  content: '';
  position: absolute;
  top: -10px; left: 50%;
  width: 10px; height: 1px;
  background: var(--border, rgba(0,0,0,0.1));
  transform: translateX(-50%);
}

/* Chapter label — rotated vertical mono number */
.tocr__chapter-label {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-3, #9a918a);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1;
  opacity: 0.55;
  transition: opacity 0.22s ease, color 0.22s ease;
}
.tocr__chapter.is-active-chapter .tocr__chapter-label {
  opacity: 1;
  color: var(--text, #1a1816);
}

/* Section ticks within chapter */
.tocr__ticks {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
}
.tocr__tick {
  display: block;
  width: 6px;
  height: 2px;
  background: var(--text-3, #9a918a);
  opacity: 0.3;
  border-radius: 1px;
  cursor: pointer;
  transition: width 0.22s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.22s ease,
              background 0.22s ease;
  border: 0;
  padding: 0;
}
.tocr__tick:hover {
  width: 14px;
  opacity: 0.8;
}
.tocr__tick.is-active {
  width: 18px;
  opacity: 1;
  background: var(--color-brain, #8a6ab0);
  box-shadow: 0 0 0 3px rgba(138, 106, 176, 0.08);
}

/* ─── Slide-in panel (full titles) ── */
.tocr__panel {
  position: absolute;
  left: 28px; top: 0; bottom: 0;
  width: 300px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg, #fff);
  border-right: 1px solid var(--border, rgba(0,0,0,0.1));
  box-shadow: 24px 0 48px rgba(0, 0, 0, 0.06);
  padding: 0;
  opacity: 0;
  transform: translateX(-14px);
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
  font-family: var(--font-sans, system-ui);
}
.tocr__panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 64px 24px 24px;
  scrollbar-width: thin;
}
.tocr__panel-scroll::-webkit-scrollbar { width: 6px; }
.tocr__panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.10);
  border-radius: 3px;
}
.tocr[data-ctx="dark"] .tocr__panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(240, 236, 228, 0.14);
}

/* Panel opens on any hover within the TOC root — more reliable than sibling-selector. */
.tocr:hover .tocr__panel,
.tocr.is-open .tocr__panel {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
/* When the panel is open, fill the 28px rail-strip with the panel's background
   so the panel visually extends seamlessly to the viewport's left edge.
   Opacity is applied to children (labels/ticks) instead of the rail itself, so
   the background stays fully opaque and seamless with the panel. */
.tocr:hover .tocr__rail,
.tocr.is-open .tocr__rail {
  background: var(--bg, #fff);
}
.tocr:hover .tocr__rail .tocr__chapter-label,
.tocr.is-open .tocr__rail .tocr__chapter-label,
.tocr:hover .tocr__rail .tocr__tick,
.tocr.is-open .tocr__rail .tocr__tick {
  opacity: 0.4;
}
/* Active chapter/tick still needs to read clearly even when panel is open */
.tocr:hover .tocr__rail .tocr__chapter.is-active-chapter .tocr__chapter-label,
.tocr.is-open .tocr__rail .tocr__chapter.is-active-chapter .tocr__chapter-label,
.tocr:hover .tocr__rail .tocr__tick.is-active,
.tocr.is-open .tocr__rail .tocr__tick.is-active {
  opacity: 1;
}
/* On dark sections, the rail strip matches the dark backdrop. */
[data-theme="dark"] .tocr:hover .tocr__rail,
[data-theme="dark"] .tocr.is-open .tocr__rail,
.tocr.tocr--dark:hover .tocr__rail,
.tocr.tocr--dark.is-open .tocr__rail {
  background: var(--bg, #08070b);
}

.tocr__panel-title {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-3, #9a918a);
  margin-bottom: 18px;
}

.tocr__ch-block {
  margin-bottom: 24px;
}
.tocr__ch-block:last-child { margin-bottom: 0; }

.tocr__ch-title {
  font-family: var(--font-sans, system-ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text, #1a1816);
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 4px 8px 6px;
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  text-decoration: none;
  border-radius: 4px 4px 0 0;
  transition: background 0.15s ease, color 0.15s ease;
  cursor: pointer;
}
.tocr__ch-title:hover {
  background: rgba(138, 106, 176, 0.08);
  color: var(--color-brain, #8a6ab0);
}
.tocr__ch-num {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  font-weight: 700;
  color: var(--color-brain, #8a6ab0);
  letter-spacing: 1px;
  background: rgba(138, 106, 176, 0.1);
  padding: 2px 7px;
  border-radius: 4px;
}

.tocr__sections {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.tocr__section-link {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text-2, #4a4541);
  text-decoration: none;
  line-height: 1.35;
  transition: background 0.18s ease, color 0.18s ease;
}
.tocr__section-link:hover {
  background: var(--bg-2, rgba(0,0,0,0.03));
  color: var(--text, #1a1816);
}
.tocr__section-link.is-active {
  background: rgba(138, 106, 176, 0.08);
  color: var(--text, #1a1816);
  font-weight: 500;
}
.tocr__section-num {
  flex-shrink: 0;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3, #9a918a);
  letter-spacing: 0.5px;
  min-width: 26px;
  font-variant-numeric: tabular-nums;
}
.tocr__section-link.is-active .tocr__section-num {
  color: var(--color-brain, #8a6ab0);
}

/* ─── Hint: "T" key hint at the bottom of the rail ── */
.tocr__hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  writing-mode: vertical-rl;
  transform: translateX(-50%) rotate(180deg);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 1.2px;
  color: var(--text-3, #9a918a);
  opacity: 0.45;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s ease;
}
.tocr__hint-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 8px;
  writing-mode: horizontal-tb;
}
.tocr:hover .tocr__hint,
.tocr.is-open .tocr__hint {
  opacity: 0;
}
.tocr[data-ctx="dark"] .tocr__hint { color: rgba(240, 236, 228, 0.6); }

/* ─── Eyebrow Ch·NN chip (auto-injected by toc-rail.js) ── */
.eyebrow__ch-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}
.eyebrow__ch-mono {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.95em;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: var(--color-brain, #8a6ab0);
  padding: 2px 8px;
  background: rgba(138, 106, 176, 0.09);
  border-radius: 3px;
  white-space: nowrap;
}
.eyebrow__ch-sep {
  color: var(--text-3, #9a918a);
  margin-right: 2px;
}
/* Dark sections: brighten the chip */
[style*="background:#08070b"] .eyebrow__ch-mono,
[style*="background: #08070b"] .eyebrow__ch-mono,
.section--pronoun .eyebrow__ch-mono,
.section--dark .eyebrow__ch-mono {
  color: #c4a8e0;
  background: rgba(196, 168, 224, 0.12);
}
[style*="background:#08070b"] .eyebrow__ch-sep,
[style*="background: #08070b"] .eyebrow__ch-sep,
.section--pronoun .eyebrow__ch-sep,
.section--dark .eyebrow__ch-sep { color: rgba(240, 236, 228, 0.4); }

/* ─── Dark-section override (so rail shows up on dark slides) ── */
.tocr[data-ctx="dark"] .tocr__tick {
  background: rgba(240, 236, 228, 0.5);
}
.tocr[data-ctx="dark"] .tocr__tick.is-active {
  background: #c4a8e0;
  box-shadow: 0 0 0 3px rgba(196, 168, 224, 0.12);
}
.tocr[data-ctx="dark"] .tocr__chapter-label {
  color: rgba(240, 236, 228, 0.5);
}
.tocr[data-ctx="dark"] .tocr__chapter.is-active-chapter .tocr__chapter-label {
  color: #f0ece4;
}

/* ═══════════════════════════════════════════════════════════
   ONBOARDING — first-visit educational tooltip
   Shown automatically on first page load (persisted via
   localStorage key 'tocr_onboarded'). Teaches users the rail
   is there and that `T` opens it. Auto-dismisses on click
   anywhere, on `T`, or after 8s.
   ─────────────────────────────────────────────────────────── */
.tocr__onboard {
  position: fixed;
  left: 44px;
  top: 50%;
  transform: translateY(-50%) translateX(-8px);
  width: 280px;
  padding: 20px 22px 22px;
  background: var(--bg, #fff);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.12));
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06),
              0 16px 40px rgba(0, 0, 0, 0.10),
              0 48px 96px rgba(0, 0, 0, 0.04);
  z-index: 120;
  opacity: 0;
  pointer-events: none;
  font-family: var(--font-sans, system-ui);
  transition: opacity 0.45s ease 0.9s, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.9s;
}
.tocr__onboard.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%) translateX(0);
}
/* Arrow pointing back at the rail */
.tocr__onboard::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 30px;
  width: 14px;
  height: 14px;
  background: var(--bg, #fff);
  border-left: 1px solid var(--border, rgba(0, 0, 0, 0.12));
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.12));
  transform: rotate(45deg);
}
.tocr__onboard-label {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--color-accent, #2ab85a);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tocr__onboard-label::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--color-accent, #2ab85a);
  animation: tocr-pulse 1.6s ease-in-out infinite;
}
@keyframes tocr-pulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.3); }
}
.tocr__onboard-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text, #1a1816);
  letter-spacing: -0.1px;
  margin-bottom: 8px;
  line-height: 1.35;
}
.tocr__onboard-body {
  font-size: 13px;
  color: var(--text-2, #4a4541);
  line-height: 1.55;
  margin-bottom: 14px;
}
.tocr__onboard-shortcuts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border, rgba(0, 0, 0, 0.08));
}
.tocr__onboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-2, #4a4541);
}
.tocr__onboard-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.18));
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  font-weight: 700;
  color: var(--text, #1a1816);
  background: var(--bg, #fff);
}
.tocr__onboard-dismiss {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px; height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-3, #9a918a);
  font-size: 16px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s ease;
}
.tocr__onboard-dismiss:hover { background: var(--bg-2, rgba(0,0,0,0.05)); color: var(--text); }

/* Dark ctx */
.tocr[data-ctx="dark"] + .tocr__onboard,
.tocr__onboard[data-ctx="dark"] {
  background: #14131a;
  border-color: rgba(240, 236, 228, 0.14);
  color: #f0ece4;
}

/* ─── Projects switcher (bottom of panel) ── */
.tocr__projects {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border, rgba(0, 0, 0, 0.1));
}
.tocr__projects-label {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-3, #9a918a);
  margin-bottom: 10px;
}
.tocr__projects-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tocr__projects-list li { margin: 0; padding: 0; }
.tocr__project {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-2, #4a4541);
  font-size: 13px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
a.tocr__project:hover {
  background: var(--bg-2, rgba(0,0,0,0.04));
  color: var(--text, #1a1816);
}
a.tocr__project:hover .tocr__project-arrow {
  transform: translateX(2px);
  opacity: 1;
}
.tocr__project--current {
  background: var(--bg-2, rgba(0,0,0,0.04));
  cursor: default;
}
.tocr__project-num {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-3, #9a918a);
}
.tocr__project--current .tocr__project-num {
  color: var(--color-brain, #6a4a90);
}
.tocr__project-title {
  font-weight: 500;
  letter-spacing: -0.2px;
}
.tocr__project--current .tocr__project-title {
  color: var(--text, #1a1816);
  font-weight: 600;
}
.tocr__project-arrow {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 14px;
  opacity: 0.5;
  transition: transform 0.15s ease, opacity 0.15s ease;
  color: var(--text-3, #9a918a);
}
.tocr__project-mark {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--color-brain, #6a4a90);
  padding: 2px 6px;
  background: rgba(106, 74, 144, 0.08);
  border-radius: 3px;
}

/* Dark variant for panel over dark sections */
.tocr[data-ctx="dark"] .tocr__projects {
  border-top-color: rgba(240, 236, 228, 0.14);
}
.tocr[data-ctx="dark"] .tocr__projects-label,
.tocr[data-ctx="dark"] .tocr__project-num,
.tocr[data-ctx="dark"] .tocr__project-arrow {
  color: rgba(240, 236, 228, 0.5);
}
.tocr[data-ctx="dark"] .tocr__project {
  color: rgba(240, 236, 228, 0.75);
}
.tocr[data-ctx="dark"] a.tocr__project:hover {
  background: rgba(240, 236, 228, 0.06);
  color: #f0ece4;
}
.tocr[data-ctx="dark"] .tocr__project--current {
  background: rgba(240, 236, 228, 0.06);
}
.tocr[data-ctx="dark"] .tocr__project--current .tocr__project-title {
  color: #f0ece4;
}

/* ─── Mobile: hide rail, optionally show a floating button ── */
@media (max-width: 768px) {
  .tocr { display: none; }
}

/* ─── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .tocr__panel,
  .tocr__tick,
  .tocr__chapter-label { transition: none !important; }
}

/* ═══ FONT SIZE SCALE (global, applied via TOC control) ═══════
   Continuous incremental scale. The actual scaling is performed
   in toc-rail.js by computing each text node's natural size and
   multiplying by --fscale. CSS exposes the variable for any opt-in
   declarations, but JS does the heavy lifting. */
:root { --fscale: 1; }

/* ─── Font size control inside TOC panel (sticky footer) ─── */
.tocr__font-ctrl {
  flex: 0 0 auto;
  margin: 0;
  padding: 14px 24px 18px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: var(--bg, #fff);
}
.tocr[data-ctx="dark"] .tocr__font-ctrl {
  border-top-color: rgba(240, 236, 228, 0.10);
  background: var(--bg, #08070b);
}
.tocr__font-ctrl-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 6px;
}
.tocr__font-ctrl-label {
  font-family: var(--font-mono, monospace);
  font-size: 10px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}
.tocr[data-ctx="dark"] .tocr__font-ctrl-label {
  color: rgba(240, 236, 228, 0.45);
}
.tocr__font-pct {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.7);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
  padding-right: 4px;
}
.tocr[data-ctx="dark"] .tocr__font-pct { color: rgba(240, 236, 228, 0.78); }

.tocr__font-btn {
  width: 30px;
  height: 30px;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.65);
  font-family: var(--font-sans, system-ui);
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 120ms, color 120ms, border-color 120ms, transform 120ms;
}
.tocr__font-btn:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.07);
  color: rgba(0, 0, 0, 0.92);
  border-color: rgba(0, 0, 0, 0.2);
}
.tocr__font-btn:active:not(:disabled) {
  transform: scale(0.94);
}
.tocr__font-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.tocr__font-btn--reset {
  font-size: 10px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  font-family: var(--font-mono, monospace);
  width: auto;
  padding: 0 8px;
  margin-left: 2px;
}
.tocr[data-ctx="dark"] .tocr__font-btn {
  background: rgba(240, 236, 228, 0.05);
  border-color: rgba(240, 236, 228, 0.1);
  color: rgba(240, 236, 228, 0.7);
}
.tocr[data-ctx="dark"] .tocr__font-btn:hover:not(:disabled) {
  background: rgba(240, 236, 228, 0.12);
  border-color: rgba(240, 236, 228, 0.24);
  color: #ededed;
}
