/* ============================================================================
   sacred-chemistry-immersive.css
   ----------------------------------------------------------------------------
   Immersion overlay for sacred-chemistry.html. Loaded AFTER:
     - ancient-medicine.css   (functional layout for the wheel)
     - liquid-glass.css       (glass primitives)
     - themes.css             (role color tokens)

   This file does not redefine layout. It adds the contemplative artifact
   surface: cosmos backdrop, phi-pulse animations, scrying tooltip, sound
   pill, portal dialog, citation tray, crescendo overlay, ritual close.

   Token reference (set on :root in the HTML):
     --sc-tint-tryptamine        #00e5cc
     --sc-tint-phenethylamine    #ff9a3c
     --sc-tint-lysergamide       #b988ff
     --sc-tint-dissociative      #6cc7ff
     --sc-tint-empathogen        #ff7cc7
     --sc-tint-indole            #ffb86b
     --sc-tint-isoxazole         #f5d272
     --sc-tint-terpenoid         #8ad27b
     --sc-tint-peptide           #ff6b6b
     --sc-tint-tropane           #a39574
     --sc-tint-beta-carboline    #c97cff
     --sc-tint-tryptamine-maoi   #4fb8a8
     --sc-phi-pulse              6.18s
     --sc-samadhi-hz             256

   Theme tokens used:
     --th-color-frequency  (amber)
     --th-color-codex      (violet)
     --th-color-gateway    (cyan)
     --font-display, --font-body, --font-mono
   ============================================================================ */

/* ----------------------------------------------------------------------------
   0. LOCAL VARIABLES — derived defaults so the file is robust if tokens slip
   ---------------------------------------------------------------------------- */
:root {
  --sc-ink:          rgba(8, 10, 18, 0.88);
  --sc-ink-soft:     rgba(8, 10, 18, 0.78);
  --sc-hairline:     rgba(255, 255, 255, 0.10);
  --sc-hairline-2:   rgba(255, 255, 255, 0.18);
  --sc-mist:         rgba(255, 255, 255, 0.045);
  --sc-text:         rgba(255, 255, 255, 0.92);
  --sc-text-soft:    rgba(255, 255, 255, 0.70);
  --sc-text-faint:   rgba(255, 255, 255, 0.42);
  --sc-shadow-card:  0 18px 38px rgba(0, 0, 0, 0.45),
                     inset 0 1px 0 rgba(255, 255, 255, 0.08);
  --sc-shadow-lift:  0 8px 24px rgba(0, 0, 0, 0.35),
                     inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --sc-ease-out:     cubic-bezier(.16, 1, .3, 1);
  --sc-ease-in:      cubic-bezier(.6, .05, .4, .95);
  --sc-z-cosmos:     0;
  --sc-z-tray:       24;
  --sc-z-pill:       25;
  --sc-z-portal:     28;
  --sc-z-crescendo:  30;
}

/* ============================================================================
   1. COSMOS BACKDROP CANVAS
   ============================================================================ */
#sc-cosmos.sc-cosmos {
  position: fixed;
  inset: 0;
  z-index: var(--sc-z-cosmos);
  pointer-events: none;
  opacity: 1;
  transition: opacity 1s ease;
}

body[data-sc-crescendo="in"] #sc-cosmos {
  opacity: 0.4;
}

/* Light starfield/grain helpers if the JS mounts them inside #sc-cosmos */
.sc-stars,
.sc-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 1.2s ease;
}
.sc-grain {
  opacity: 0.025;
  mix-blend-mode: overlay;
}
.sc-stars {
  opacity: 0.9;
}

body[data-sc-crescendo="in"] .sc-stars { opacity: 0.3; }
body[data-sc-crescendo="in"] .sc-grain { opacity: 0.012; }

@media (max-width: 767px) {
  #sc-cosmos { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #sc-cosmos { display: none; }
}

/* ============================================================================
   2. COMPOUND NODES — hover glow + Samadhi phi-pulse + chord drift
   ============================================================================ */

/* Make every compound node responsive to hover without altering its base
   geometry. We rely on `currentColor` from the inline fill D3 sets. */
.am-node-compound {
  transition:
    transform 280ms var(--sc-ease-out),
    filter   280ms var(--sc-ease-out);
  transform-box: fill-box;
  transform-origin: center;
  cursor: pointer;
}

.am-node-compound:hover {
  transform: scale(1.18);
  filter: drop-shadow(0 0 14px currentColor);
}

/* Brighten labels on hover. We target the label inside the same group. */
.am-node-compound:hover .am-node-label,
.am-node-compound:focus-visible .am-node-label {
  fill: #ffffff;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.6));
}

.am-node-label {
  transition: fill 220ms ease, filter 220ms ease;
  pointer-events: none;
}

/* Focus ring for keyboard nav (no layout shift). */
.am-node-compound:focus-visible {
  outline: none;
  filter: drop-shadow(0 0 14px currentColor)
          drop-shadow(0 0 2px rgba(255, 255, 255, 0.85));
}

/* --- Samadhi disc — phi-cadence pulse ----------------------------------- */
.am-node-center {
  transform-box: fill-box;
  transform-origin: center;
  animation: sc-phi-pulse var(--sc-phi-pulse, 6.18s) ease-in-out infinite;
  will-change: filter;
}

@keyframes sc-phi-pulse-center {
  0%, 100% {
    filter: brightness(1)
            drop-shadow(0 0 8px var(--th-color-frequency, #e0c97f));
  }
  50% {
    filter: brightness(1.15)
            drop-shadow(0 0 22px var(--th-color-frequency, #e0c97f));
  }
}

.am-node-center {
  animation-name: sc-phi-pulse-center;
}

/* --- Chord-line drift --------------------------------------------------- */
/* A slow stroke-dashoffset drift gives the chord lines a breathing
   directionality without changing their core geometry. */
.am-link {
  stroke-dasharray: 6 14;
  animation: sc-chord-drift 18s linear infinite;
  will-change: stroke-dashoffset;
}

@keyframes sc-chord-drift {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: -240; }
}

/* ============================================================================
   3. CURSOR INSTRUMENT — fine-pointer only
   ============================================================================ */

/* Default cursor over the wheel: 8px luminous ring + 2px center dot.
   Encoded inline as data-URI SVG. */
@media (hover: hover) and (pointer: fine) {
  #ancient-medicine,
  #ancient-medicine svg {
    cursor:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><circle cx='12' cy='12' r='7.5' fill='none' stroke='rgba(255,255,255,0.85)' stroke-width='1'/><circle cx='12' cy='12' r='1' fill='rgba(255,255,255,0.95)'/></svg>") 12 12,
      default;
  }

  /* Compound nodes — slightly larger ring on hover. */
  #ancient-medicine .am-node-compound,
  #ancient-medicine .am-node-compound * {
    cursor:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'><circle cx='20' cy='20' r='13.5' fill='none' stroke='rgba(255,255,255,0.95)' stroke-width='1'/><circle cx='20' cy='20' r='1.5' fill='rgba(255,255,255,1)'/></svg>") 20 20,
      pointer;
  }
}

/* ============================================================================
   4. SCRYING-MIRROR TOOLTIP — override the bland default in ancient-medicine.css
   ============================================================================ */

/* !important is required here only to override the rule already established
   in ancient-medicine.css with the same specificity. */
#am-tooltip {
  background: var(--sc-ink-soft) !important;          /* override am .9 black */
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--sc-hairline) !important;    /* override am border */
  box-shadow: var(--sc-shadow-card);
  border-radius: 12px;
  color: var(--sc-text);
  padding: 12px 14px;
  /* positioning + transform left to ancient-medicine.css */
}

.am-tooltip-name {
  font-family: var(--font-display, 'Cinzel', serif);
  font-size: 0.92rem;
  letter-spacing: 0.06em;
  color: var(--th-color-frequency, #e0c97f);
  margin: 0 0 6px 0;
}

.am-tooltip-detail,
.am-tooltip-meta {
  font-size: 0.72rem;
  color: var(--sc-text-soft);
  letter-spacing: 0.04em;
  line-height: 1.4;
}

/* ============================================================================
   5. SOUND PILL — bottom-left liquid-glass instrument
   ============================================================================ */

#sc-sound-pill.sc-sound-pill {
  position: fixed;
  /* Anchored bottom-center on every viewport — the bottom-left position
     collided with the left dock's compound selection pills (compare mode)
     and got visually clipped. Center keeps it clear of both side panels. */
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--sc-z-pill);

  display: none;                /* revealed by .revealed */
  align-items: center;
  gap: 10px;

  height: 36px;
  min-width: 96px;
  padding: 0 14px;

  background: var(--sc-mist);
  border: 1px solid var(--sc-hairline);
  border-radius: 14px;
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  box-shadow: var(--sc-shadow-lift);

  color: var(--sc-text);
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;

  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;

  transition:
    transform 220ms var(--sc-ease-out),
    border-color 280ms ease,
    background 280ms ease,
    opacity 280ms ease;
}

#sc-sound-pill.sc-sound-pill.revealed {
  display: inline-flex;
  animation: sc-sound-pill-enter 600ms var(--sc-ease-out) both;
}

@keyframes sc-sound-pill-enter {
  /* Preserve the translateX(-50%) center anchor; only animate Y on enter. */
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

#sc-sound-pill.sc-sound-pill:hover {
  /* Same — keep horizontal centering, lift on hover. */
  transform: translate(-50%, -2px) scale(1.03);
  background: rgba(255, 255, 255, 0.08);
}

/* Sine glyph — two concentric arcs drawn with CSS borders */
.sc-sound-pill__glyph {
  position: relative;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}
.sc-sound-pill__glyph::before,
.sc-sound-pill__glyph::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0.55;
}
.sc-sound-pill__glyph::after {
  inset: 3px;
  opacity: 0.85;
}

/* Engaged state — phi-pulse the glyph, lift the border to accent gold. */
#sc-sound-pill.sc-sound-pill[aria-pressed="true"],
#sc-sound-pill.sc-sound-pill.engaged {
  border-color: var(--th-color-frequency, #e0c97f);
  color: var(--th-color-frequency, #e0c97f);
}

#sc-sound-pill.sc-sound-pill[aria-pressed="true"] .sc-sound-pill__glyph,
#sc-sound-pill.sc-sound-pill.engaged .sc-sound-pill__glyph {
  animation: sc-phi-pulse-strong var(--sc-phi-pulse, 6.18s) ease-in-out infinite;
}

.sc-sound-pill__label {
  display: inline-block;
  line-height: 1;
}

/* Mobile — full-width strip across the bottom edge. */
@media (max-width: 600px) {
  #sc-sound-pill.sc-sound-pill {
    left: 16px;
    right: 16px;
    bottom: 16px;
    justify-content: center;
  }
}

/* ============================================================================
   6. PORTAL DIALOG — native <dialog>
   ============================================================================ */

#sc-portal.sc-portal {
  /* Reset native dialog chrome */
  padding: 0;
  border: 1px solid var(--sc-hairline);
  border-radius: 18px;
  background: var(--sc-ink);
  color: var(--sc-text);

  /* Explicit centering via translate — inset:0 + margin:auto fails
     when width is explicit (margins resolve to 0). Translate is bulletproof.
     Order matters: inset: auto first, THEN top/left/transform. */
  position: fixed;
  inset: auto;
  margin: 0;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  width: min(720px, calc(100vw - 48px));
  max-width: 720px;
  max-height: calc(100vh - 48px);
  height: auto;
  overflow: hidden;

  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);

  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);

  z-index: var(--sc-z-portal);

  /* Default accent — overridden by [data-family]. */
  --family-accent: var(--th-color-frequency, #e0c97f);
}

#sc-portal.sc-portal::backdrop {
  background: rgba(2, 4, 12, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Open / close animation — opacity only; transform owns centering. */
#sc-portal.sc-portal[open] {
  animation: sc-portal-open 280ms var(--sc-ease-out) both;
}
#sc-portal.sc-portal[open]::backdrop {
  animation: sc-portal-backdrop-in 280ms ease both;
}

#sc-portal.sc-portal.closing {
  animation: sc-portal-close 220ms var(--sc-ease-in) both;
}
#sc-portal.sc-portal.closing::backdrop {
  animation: sc-portal-backdrop-out 220ms ease both;
}

@keyframes sc-portal-open {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes sc-portal-close {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to   { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
}
@keyframes sc-portal-backdrop-in {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes sc-portal-backdrop-out {
  from { opacity: 1; } to { opacity: 0; }
}

/* --- Family theming ----------------------------------------------------- */
#sc-portal[data-family="tryptamine"]        { --family-accent: var(--sc-tint-tryptamine); }
#sc-portal[data-family="phenethylamine"]    { --family-accent: var(--sc-tint-phenethylamine); }
#sc-portal[data-family="lysergamide"]       { --family-accent: var(--sc-tint-lysergamide); }
#sc-portal[data-family="dissociative"]      { --family-accent: var(--sc-tint-dissociative); }
#sc-portal[data-family="empathogen"]        { --family-accent: var(--sc-tint-empathogen); }
#sc-portal[data-family="indole"]            { --family-accent: var(--sc-tint-indole); }
#sc-portal[data-family="isoxazole"]         { --family-accent: var(--sc-tint-isoxazole); }
#sc-portal[data-family="terpenoid"]         { --family-accent: var(--sc-tint-terpenoid); }
#sc-portal[data-family="peptide"]           { --family-accent: var(--sc-tint-peptide); }
#sc-portal[data-family="tropane"]           { --family-accent: var(--sc-tint-tropane); }
#sc-portal[data-family="beta-carboline"]    { --family-accent: var(--sc-tint-beta-carboline); }
#sc-portal[data-family="tryptamine-maoi"]   { --family-accent: var(--sc-tint-tryptamine-maoi); }

/* --- Inner shell -------------------------------------------------------- */
.sc-portal__inner {
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  overflow: hidden;
}
.sc-portal__header {
  padding: 22px 28px 14px;
  flex-shrink: 0;
}
.sc-portal__scroll {
  padding: 0 28px 12px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  /* Hide scrollbar — Jason's directive */
  scrollbar-width: none;       /* Firefox */
  -ms-overflow-style: none;    /* IE 10+ */
}
.sc-portal__scroll::-webkit-scrollbar {
  display: none;               /* Chromium / Safari */
  width: 0;
  height: 0;
}
.sc-portal__footer {
  padding: 14px 28px 18px;
  flex-shrink: 0;
  border-top: 1px solid var(--sc-hairline, rgba(255,255,255,0.06));
}
/* Global scrollbar-hide for any scrollable inside the portal. */
.sc-portal *::-webkit-scrollbar { display: none; width: 0; height: 0; }
.sc-portal * { scrollbar-width: none; -ms-overflow-style: none; }
/* Citation tray and crescendo overlay too. */
#sc-citation-tray::-webkit-scrollbar { display: none; }
#sc-citation-tray { scrollbar-width: none; }

.sc-portal__header {
  position: relative;
  padding-right: 56px;        /* clear close button */
}

.sc-portal__kicker {
  display: block;
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  opacity: 0.6;
  color: var(--family-accent);
  margin-bottom: 8px;
}

.sc-portal__title {
  font-family: var(--font-display, 'Cinzel', serif);
  font-size: 1.7rem;
  line-height: 1.15;
  font-weight: 500;
  color: var(--sc-text);
  margin: 0 0 8px 0;
  letter-spacing: 0.01em;
}

.sc-portal__source {
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.78rem;
  color: var(--sc-text-soft);
  opacity: 0.65;
  margin: 0;
  letter-spacing: 0.03em;
}

/* --- Close button (contrasting, container-free, spins on hover) -------- */
.sc-portal__close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--family-accent, var(--th-color-frequency, #e0c97f));
  font-family: var(--font-display, 'Cinzel', serif);
  font-size: 24px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 220ms ease, transform 360ms cubic-bezier(.4, 1.6, .4, 1), opacity 220ms ease;
  opacity: 0.55;
}
.sc-portal__close:hover,
.sc-portal__close:focus-visible {
  background: transparent;
  color: #ffffff;
  opacity: 1;
  transform: rotate(135deg) scale(1.15);
  outline: none;
  text-shadow: 0 0 12px var(--family-accent, rgba(255,255,255,0.4));
}

/* --- Section titles ----------------------------------------------------- */
.sc-portal__section {
  margin-top: 22px;
}
.sc-portal__section-title {
  display: block;
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.20em;
  opacity: 0.5;
  margin: 0 0 8px 0;
  color: var(--sc-text);
}

/* --- Approach cards (SET / SETTING / RESPECT) --------------------------- */
/* Section is a vertical stack: title on top, then a 3-up grid of cards.
   Title must NOT be a grid item — it spans the whole section. */
.sc-portal__approach {
  display: block;
}
.sc-portal__approach .sc-portal__section-title {
  margin-bottom: 10px;
}
.sc-portal__approach-grid,
.sc-portal__approach > .sc-approach-card:first-of-type {
  /* CSS-only fallback if no wrapper: cards still grid via section selector */
}
.sc-portal__approach {
  /* When cards are direct children, lay them out via this nested rule. */
}
.sc-portal__approach > .sc-approach-card {
  display: block;
}
/* Grid wrapper for cards (we render them as direct siblings; use a CSS
   subgrid via flex to get 3 equal columns that wrap on narrow screens). */
.sc-portal__approach {
  /* container query not needed — use flex with min-width per card */
}
.sc-portal__approach::after {
  content: '';
  display: block;
  clear: both;
}
/* The actual 3-up layout: use a flex wrapper. Since the cards are siblings
   of the h3, we use the :not selector to flex them together. */
.sc-portal__approach {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.sc-portal__approach .sc-portal__section-title {
  grid-column: 1 / -1;
}
.sc-portal__approach {
  /* Override above with a real grid for the 3 cards while keeping title spanning. */
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.sc-approach-card {
  position: relative;
  padding: 14px 14px 14px 16px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--sc-hairline);
  border-left: 2px solid var(--sc-text-faint);
  border-radius: 12px;
  transition: transform 240ms var(--sc-ease-out), background 240ms ease;
  min-width: 0;
  max-height: 180px;
  overflow: hidden;
  cursor: pointer;
}
.sc-approach-card:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.055);
  max-height: 600px;
}

.sc-approach-card[data-role="set"]     { border-left-color: var(--th-color-gateway,   #6cc7ff); }
.sc-approach-card[data-role="setting"] { border-left-color: var(--th-color-frequency, #e0c97f); }
.sc-approach-card[data-role="respect"] { border-left-color: var(--sc-tint-peptide,    #ff6b6b); }

.sc-approach-card__label {
  display: block;
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--sc-text-soft);
  margin-bottom: 6px;
}
.sc-approach-card__body {
  font-size: 0.78rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 7;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
}
.sc-approach-card:hover .sc-approach-card__body {
  -webkit-line-clamp: 30;
}
.sc-approach-card__body-stub {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--sc-text);
}

@media (max-width: 720px) {
  .sc-portal__approach { grid-template-columns: 1fr; }
}

/* --- Brain SVG ---------------------------------------------------------- */
.sc-portal__brain {
  margin-top: 8px;
  display: block;
  max-width: 100%;
  height: auto;
}

.sc-brain-outline {
  fill: none;
  stroke: rgba(255, 255, 255, 0.32);
  stroke-width: 1.25;
}

.sc-brain-blob {
  fill: rgba(255, 255, 255, 0.08);
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 1;
  transition: fill 600ms ease, filter 600ms ease, opacity 600ms ease;
}

.sc-brain-region[data-active="true"] .sc-brain-blob {
  /* Toned down from full saturation — neon glow looked clinical-comic; this
     reads as illuminated rather than highlighted. */
  fill: color-mix(in srgb, var(--family-accent) 38%, transparent);
  stroke: var(--family-accent);
  stroke-width: 1.25;
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--family-accent) 45%, transparent));
  animation: sc-phi-pulse-strong var(--sc-phi-pulse, 6.18s) ease-in-out infinite;
  opacity: 0.85;
}

.sc-brain-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.sc-brain-legend__chip {
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--sc-hairline);
  color: var(--sc-text-soft);
}
.sc-brain-legend__chip[data-active="true"] {
  color: var(--family-accent);
  border-color: var(--family-accent);
  background: color-mix(in srgb, var(--family-accent) 12%, transparent);
}

/* --- Mechanism list ----------------------------------------------------- */
.sc-portal__mechanisms {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.sc-mechanism {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 2fr;
  gap: 16px;
  align-items: baseline;
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}
.sc-mechanism:last-child { border-bottom: 0; }

.sc-mechanism__pathway {
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--family-accent);
}
.sc-mechanism__detail {
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--sc-text);
}

/* --- Receptor chips ----------------------------------------------------- */
.sc-portal__receptors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sc-receptor-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  background: color-mix(in srgb, var(--family-accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--family-accent) 28%, transparent);
  color: var(--sc-text);
}
.sc-receptor-chip__affinity {
  opacity: 0.7;
  font-size: 0.62rem;
}

/* --- Clinical findings -------------------------------------------------- */
.sc-portal__findings {
  margin: 0;
  padding: 0 0 0 18px;
  list-style: disc;
  color: var(--sc-text);
}
.sc-portal__findings li {
  font-size: 0.82rem;
  line-height: 1.55;
  margin-bottom: 6px;
}
.sc-portal__findings li::marker {
  color: var(--family-accent);
}

/* --- Footer ------------------------------------------------------------- */
.sc-portal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--sc-hairline);
}
.sc-portal__btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--sc-hairline-2);
  color: var(--sc-text);
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease, color 200ms ease;
}
.sc-portal__btn:hover,
.sc-portal__btn:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--family-accent);
  color: var(--family-accent);
  outline: none;
}
.sc-portal__btn--primary {
  border-color: var(--family-accent);
  color: var(--family-accent);
}

/* ============================================================================
   7. CITATION TRAY — slide-in right rail
   ============================================================================ */

#sc-citation-tray.sc-citation-tray {
  position: fixed;
  right: 16px;
  top: 88px;
  bottom: 16px;
  width: 260px;
  z-index: var(--sc-z-tray);

  display: flex;
  flex-direction: column;

  background: var(--sc-ink-soft);
  border: 1px solid var(--sc-hairline);
  border-radius: 14px;
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: var(--sc-shadow-card);

  transform: translateX(0);
  opacity: 1;
  transition:
    transform 320ms var(--sc-ease-out),
    opacity 320ms ease;
}

#sc-citation-tray.sc-citation-tray[aria-hidden="true"] {
  transform: translateX(110%);
  opacity: 0;
  pointer-events: none;
}

.sc-citation-tray__header {
  padding: 14px 16px 10px;
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.62rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--sc-text-soft);
  border-bottom: 1px solid var(--sc-hairline);
}

.sc-citation-tray__list {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sc-citation-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 10px 10px 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--sc-hairline);
  border-radius: 10px;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--sc-text);
}

.sc-citation-item__text {
  word-break: break-word;
}
.sc-citation-item__cite {
  display: block;
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  color: var(--sc-text-soft);
  margin-top: 4px;
}

.sc-citation-item__remove {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--sc-text-soft);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  transition: background 180ms ease, color 180ms ease;
}
.sc-citation-item__remove:hover,
.sc-citation-item__remove:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: var(--sc-text);
  outline: none;
}

@media (max-width: 900px) {
  #sc-citation-tray.sc-citation-tray {
    top: auto;
    bottom: 80px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: 40vh;
  }
}

/* ============================================================================
   8. CRESCENDO OVERLAY — endgame "different doors, same room"
   ============================================================================ */

#sc-crescendo-overlay.sc-crescendo-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--sc-z-crescendo);
  pointer-events: none;
  opacity: 1;
  visibility: visible;
  transition: opacity 600ms ease, visibility 0s linear 0s;
}

#sc-crescendo-overlay.sc-crescendo-overlay[aria-hidden="true"] {
  opacity: 0;
  visibility: hidden;
  transition: opacity 600ms ease, visibility 0s linear 600ms;
}

/* Full-bleed white burst */
.sc-crescendo-burst {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
}
.sc-crescendo-burst.firing,
.sc-crescendo-burst.sc-crescendo-burst-active {
  animation: sc-burst 1400ms var(--sc-ease-out) forwards;
}
.sc-crescendo-burst.sc-crescendo-burst-soft {
  animation: sc-burst-soft 900ms ease forwards;
}
@keyframes sc-burst {
  0%   { opacity: 0; }
  20%  { opacity: 0.95; }
  60%  { opacity: 0.6; }
  100% { opacity: 0; }
}
@keyframes sc-burst-soft {
  0%   { opacity: 0; }
  40%  { opacity: 0.25; }
  100% { opacity: 0; }
}

/* Caption — "Different doors. / Same room." */
.sc-crescendo-caption {
  position: absolute;
  top: 40%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-display, 'Cinzel', serif);
  font-size: 2.4rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #ffffff;
  text-shadow:
    0 0 24px rgba(255, 255, 255, 0.45),
    0 0 6px  rgba(255, 255, 255, 0.85);
  opacity: 0;
  line-height: 1.35;
  padding: 0 24px;
  transition: opacity 1200ms ease;
}
.sc-crescendo-caption.lit,
.sc-crescendo-caption.sc-crescendo-caption-visible { opacity: 1; }

.sc-crescendo-caption__line {
  display: block;
}
.sc-crescendo-caption__line + .sc-crescendo-caption__line {
  margin-top: 8px;
  opacity: 0.85;
}

/* Return pill — hidden by default; JS adds .sc-crescendo-return-visible to show. */
.sc-crescendo-return {
  position: fixed;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0;

  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  font-size: 0.7rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--sc-text);

  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--sc-hairline-2);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  cursor: pointer;

  transition: opacity 600ms ease, background 240ms ease, color 240ms ease, border-color 240ms ease;
}
.sc-crescendo-return.sc-crescendo-return-visible {
  opacity: 1;
  pointer-events: auto;
}
.sc-crescendo-return:hover,
.sc-crescendo-return:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--th-color-frequency, #e0c97f);
  color: var(--th-color-frequency, #e0c97f);
  outline: none;
}

/* When the crescendo is in OR holding, mute every other page surface.
   Specificity HACK: ancient-medicine.css uses body.am-seen .am-thesis-hero
   { opacity:1 !important } for return-visit, which beats single-class rules.
   We use body[data-sc-crescendo] (matching specificity) + !important to win.
   Detail panel may also be open — dim it via #am-detail-panel selector. */
body[data-sc-crescendo="in"]   .am-intro-panel-wrap,
body[data-sc-crescendo="hold"] .am-intro-panel-wrap,
body[data-sc-crescendo="in"]   .am-thesis-hero,
body[data-sc-crescendo="hold"] .am-thesis-hero,
body[data-sc-crescendo="in"]   .am-safety-doctrine,
body[data-sc-crescendo="hold"] .am-safety-doctrine,
body[data-sc-crescendo="in"]   .am-banner,
body[data-sc-crescendo="hold"] .am-banner,
body[data-sc-crescendo="in"]   .am-mode-controls,
body[data-sc-crescendo="hold"] .am-mode-controls,
body[data-sc-crescendo="in"]   #am-detail-panel,
body[data-sc-crescendo="hold"] #am-detail-panel,
body[data-sc-crescendo="in"]   #am-intro-panel,
body[data-sc-crescendo="hold"] #am-intro-panel,
body[data-sc-crescendo="in"]   .unified-nav,
body[data-sc-crescendo="hold"] .unified-nav {
  opacity: 0.16 !important;
  filter: saturate(0.25);
  transition: filter 900ms ease, opacity 900ms ease;
  pointer-events: none;
}

/* Node collapse toward Samadhi center. JS computes per-node delta and writes
   --sc-node-x / --sc-node-y in pixels (signed) onto the node element. */
.am-node-compound.sc-crescendo-collapsing {
  transition:
    transform 3.5s var(--sc-ease-in),
    opacity   3.5s ease;
  transform:
    translate(
      calc(50vw - var(--sc-node-x, 0) * 1px),
      calc(50vh - var(--sc-node-y, 0) * 1px)
    );
  opacity: 0;
}
/* Hide labels as they collapse — 17 labels piling at center looks chaotic.
   The circles themselves remain (faintly) for the visual funnel effect. */
.am-node-compound.sc-crescendo-collapsing .am-node-label {
  opacity: 0;
  transition: opacity 1.6s ease;
}

/* During crescendo, also dim the doctrine + thesis cards on the right
   (they sit outside .am-* selectors so we catch them by container). */
body[data-sc-crescendo="in"]   #ancient-medicine .am-pop-card,
body[data-sc-crescendo="hold"] #ancient-medicine .am-pop-card,
body[data-sc-crescendo="in"]   .am-pop-card,
body[data-sc-crescendo="hold"] .am-pop-card {
  filter: saturate(0.3);
  opacity: 0.18;
  transition: filter 800ms ease, opacity 800ms ease;
}

/* Chord links funnel inward — stroke thickens, opacity rises. */
.am-link.sc-crescendo-funneling {
  transition:
    stroke-opacity 2.5s ease,
    stroke-width   2.5s ease;
  stroke-opacity: 0.85;
  stroke-width: 2.5;
}

/* ============================================================================
   9. RITUAL CLOSE — appended to the fractal-scales finale
   ============================================================================ */

/* The fractal section already renders an `.fs-return-link`. We can't add new
   markup without touching that file, so the close line is a pseudo-element. */
.fs-return-link {
  position: relative;
  display: inline-block;
  text-align: center;
}

/* ============================================================================
   11. TOUR HUD — bottom-center HUD that drives the guided walkthrough
   ============================================================================ */

.sc-tour-hud {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 26;
  display: none;       /* shown by [data-active="true"] */

  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  color: var(--sc-text, rgba(255,255,255,0.85));

  background: rgba(8, 10, 18, 0.78);
  border: 1px solid var(--sc-hairline, rgba(255,255,255,0.10));
  border-radius: 999px;
  padding: 10px 18px;
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: 0 18px 38px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.06);

  gap: 14px;
  align-items: center;
  pointer-events: auto;
}
.sc-tour-hud[data-active="true"] {
  display: flex;
  animation: sc-tour-hud-enter 600ms cubic-bezier(.16,1,.3,1) both;
}
@keyframes sc-tour-hud-enter {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

.sc-tour-hud__progress {
  width: 140px;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.sc-tour-hud__progress-fill {
  height: 100%;
  width: 0%;
  background: var(--th-color-frequency, #e0c97f);
  transition: width 0.2s linear;
  box-shadow: 0 0 8px var(--th-color-frequency, #e0c97f);
}

.sc-tour-hud__counter {
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
}

.sc-tour-hud__controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.sc-tour-hud__btn {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--sc-text, rgba(255,255,255,0.85));
  font-size: 16px;
  font-family: var(--font-mono, monospace);
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 200ms ease, color 200ms ease, transform 200ms ease;
}
.sc-tour-hud__btn:hover,
.sc-tour-hud__btn:focus-visible {
  background: rgba(255, 255, 255, 0.10);
  color: var(--th-color-frequency, #e0c97f);
  outline: none;
}
.sc-tour-hud__btn--exit {
  font-size: 22px;
  font-weight: 300;
  margin-left: 4px;
}
.sc-tour-hud__btn--exit:hover {
  transform: rotate(90deg);
  color: var(--sc-tint-peptide, #ff6b6b);
}

/* ============================================================================
   12. SIDE PANEL HIDE — when portal opens, hide the redundant side panel
        from ancient-medicine.js (#am-detail-panel) so we don't show two
        compound dossiers stacked.
   ============================================================================ */

body:has(#sc-portal[open]) #am-detail-panel,
body:has(#sc-portal[open]) #am-panel,
body:has(#sc-portal[open]) .am-detail-panel {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 320ms ease;
}

/* ============================================================================
   13. SCRUBBER + fractal scroll — keep them from colliding
   ============================================================================ */

/* When scrubber is active, push fractal section down so the bottom strip
   doesn't sit on top of scene 7's RETURN link. */
body[data-sc-timeline="on"] #fractal-scales {
  padding-bottom: 160px;
}

/* The scrubber strip needs to render above the fractal scenes during scroll. */
.sc-timeline-strip {
  z-index: 60;
}

/* ============================================================================
   14. INDICATION + FAMILY CHIP MICRO-INTERACTION
        Subtle hover + active pulse — give filter buttons the same liveliness
        as the rest of the page.
   ============================================================================ */

.am-indication-item,
.am-legend-item {
  transition: background 220ms ease, border-color 220ms ease,
              transform 220ms cubic-bezier(.4,1.6,.4,1),
              box-shadow 220ms ease, color 220ms ease;
}
.am-indication-item:hover,
.am-legend-item:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4),
              0 0 12px var(--th-color-frequency, rgba(224, 201, 127, 0.35));
}
.am-indication-item:active,
.am-legend-item:active {
  transform: translateY(0) scale(0.98);
}
.am-indication-item.active,
.am-legend-item.active {
  animation: sc-chip-pulse 2.6s ease-in-out infinite;
}
@keyframes sc-chip-pulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50%      { box-shadow: 0 0 16px 1px var(--th-color-frequency, rgba(224, 201, 127, 0.45)); }
}

/* ============================================================================
   15. SIBYL ORB — react to crescendo + portal events
        The Sibyl agent dock sits bottom-right. During crescendo, the orb
        pulses brighter and gets a halo. During portal open it dims slightly
        so it doesn't compete with the dossier.
   ============================================================================ */

#sibyl-dock,
.am-sibyl-dock {
  transition: opacity 600ms ease, filter 600ms ease, transform 600ms ease;
}
body[data-sc-crescendo="in"] #sibyl-dock,
body[data-sc-crescendo="hold"] #sibyl-dock,
body[data-sc-crescendo="in"] .am-sibyl-dock,
body[data-sc-crescendo="hold"] .am-sibyl-dock {
  animation: sc-sibyl-witness var(--sc-phi-pulse, 6.18s) ease-in-out infinite;
  filter: drop-shadow(0 0 24px var(--th-color-frequency, rgba(224, 201, 127, 0.6)));
  transform: scale(1.08);
}
@keyframes sc-sibyl-witness {
  0%, 100% { filter: drop-shadow(0 0 18px var(--th-color-frequency, rgba(224, 201, 127, 0.5))); }
  50%      { filter: drop-shadow(0 0 32px var(--th-color-frequency, rgba(224, 201, 127, 0.85))); }
}
body:has(#sc-portal[open]) #sibyl-dock,
body:has(#sc-portal[open]) .am-sibyl-dock {
  opacity: 0.45;
  filter: saturate(0.4);
}

/* ============================================================================
   16. MOBILE / TABLET ADAPTATION  (< 900px and < 600px breakpoints)
        The page is a contemplative artifact — works as a desktop experience
        primarily — but must remain legible on phones.
   ============================================================================ */

@media (max-width: 900px) {
  /* Sound pill is already bottom-center on desktop; just tighten the gap */
  #sc-sound-pill.sc-sound-pill {
    bottom: 14px;
  }
  /* Portal — give it more screen */
  #sc-portal.sc-portal {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }
  .sc-portal__inner { max-height: calc(100vh - 24px); }
  .sc-portal__approach { grid-template-columns: 1fr; }
  .sc-approach-card { max-height: 220px; }
  /* Tour HUD — wider, sits above the sound pill */
  .sc-tour-hud {
    bottom: 64px;
    padding: 8px 14px;
    gap: 10px;
  }
  .sc-tour-hud__progress { width: 96px; }
  /* Citation tray — convert to bottom sheet */
  #sc-citation-tray.sc-citation-tray {
    right: 12px;
    left: 12px;
    bottom: 120px;
    top: auto;
    width: auto;
    max-height: 35vh;
  }
}

@media (max-width: 600px) {
  /* Cosmos backdrop already hidden under 768px (see top of file) */
  /* Tour HUD — compact + drop the progress bar */
  .sc-tour-hud__progress { display: none; }
  .sc-tour-hud__counter { font-size: 0.58rem; }
  /* Portal title smaller */
  .sc-portal__title { font-size: 1.4rem; }
  .sc-portal__kicker { font-size: 0.56rem; }
  /* Scrubber strip — shorter so it doesn't dominate */
  .sc-timeline-strip { height: 96px; }
  /* Crescendo caption — single line, smaller */
  .sc-crescendo-caption { font-size: 1.4rem; }
  /* Compare mirror — stack vertically instead of side-by-side */
  #sc-compare-mirror.sc-compare-mirror { flex-direction: column; }
  /* Indication chips wrap tighter */
  .am-indication-item { font-size: 0.62rem; padding: 4px 8px; }
}

/* ============================================================================
   17. PRINT — emergency screen print of a compound page for reference reading
        Strip the entire immersive layer, give the user clean text.
   ============================================================================ */

@media print {
  #sc-cosmos, .sc-stars, .sc-grain, .sc-sound-pill,
  .sc-tour-hud, .sc-timeline-strip, .sc-crescendo-overlay,
  #sibyl-dock, .am-sibyl-dock, .unified-nav,
  #sc-compare-mirror, #sc-citation-tray { display: none !important; }
  body { background: #ffffff !important; color: #000 !important; }
  .sc-portal__inner { color: #000; background: #fff; }
}

.fs-return-link::after {
  content: 'The wheel will be here when you come back.';
  display: block;
  font-family: var(--font-body, 'Libre Baskerville', serif);
  font-size: 0.78rem;
  font-style: italic;
  letter-spacing: 0.06em;
  color: rgba(243, 225, 166, 0.42);
  margin-top: 20px;
  text-align: center;
  text-transform: none;
  border: 0;
  /* Wider line spacing so the close line breathes after the all-caps link */
  line-height: 1.4;
}

/* ============================================================================
   10. PHI-PULSE — shared animations
   ============================================================================ */

@keyframes sc-phi-pulse {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.15); }
}

@keyframes sc-phi-pulse-strong {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.04); opacity: 0.92; }
}

/* A softer pulse for subtle accents (legend chips, etc.) */
@keyframes sc-phi-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
  50%      { box-shadow: 0 0 16px 0 color-mix(in srgb, var(--family-accent, #e0c97f) 35%, transparent); }
}

/* ============================================================================
   11. PREFERS-REDUCED-MOTION — kill it all
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .sc-cosmos,
  .sc-grain,
  .sc-stars { display: none; }

  /* !important because we override the per-component animation declarations
     above; reduced-motion is a non-negotiable accessibility override. */
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .sc-crescendo-overlay .sc-crescendo-burst { display: none; }
  .am-link { stroke-dasharray: none; }
}
