/* ═══════════════════════════════════════════════════
   FRACTAL MANDALA 3D — Quantum Orbital Edition
   Nebula palette: indigo deep, dusty rose, cool blue, amber dust
   ═══════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* iOS safe-area padding for viewport-fit=cover */
@supports (padding: env(safe-area-inset-top)) {
  :root {
    --sat: env(safe-area-inset-top);
    --sab: env(safe-area-inset-bottom);
    --sal: env(safe-area-inset-left);
    --sar: env(safe-area-inset-right);
  }
}

:root {
  --bg:         #06050a;
  --text-warm:  #f0ead8;
  --text-muted: #c8bca6;
  --text-faint: #5a5248;
  --text-secondary: #b0a692;
  --gold:       #f0c850;
  --gold-dim:   #a8883a;
  --amber:      #e8a830;
  --rose:       #d4889a;
  --lavender:   #a088c0;
  --blue-star:  #a0d4f0;
  --teal-glow:  #7ec8a0;
  --panel-bg:   radial-gradient(ellipse at 50% 50%, rgba(8,6,14,0.42) 30%, rgba(8,6,14,0.042) 90%, transparent 100%);
  --panel-border: rgba(155, 138, 184, 0.12);
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Jost', 'Helvetica Neue', sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* iOS standalone / PWA: -webkit-fill-available fixes undersized 100% height chain */
html {
  height: 100%;
  height: -webkit-fill-available;
  color-scheme: dark; /* align scrollbars / UA chrome with theme-color + meta color-scheme */
}

html, body {
  width: 100%;
  min-height: 100%;
  min-height: 100svh; /* stable mobile viewport (browser chrome visible) */
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-warm);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* iOS: prevent rubber-band scroll and ensure full coverage */
  position: fixed;
  inset: 0;
}

canvas {
  display: block;
  position: fixed;
  inset: 0;
  width: 100vw !important;
  max-width: 100dvw;
  height: 100vh !important;
  height: 100svh !important;
  /* iOS dynamic viewport fallback */
  height: 100dvh !important;
  touch-action: none; /* prevent browser zoom/pan on canvas */
}

/* Primary landmark for accessibility + document outline (SEO-friendly structure) */
#main-content {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  margin: 0;
  padding: 0;
}

/* ═══ HUD ═══ */
.hud {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  /* Respect notch / dynamic island safe areas */
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  pointer-events: none;
  z-index: 10;
  box-sizing: border-box;
}

.hud > * {
  pointer-events: auto;
}

/* ═══ WELCOME ═══ */
/* Grid: top row scrolls (hero); bottom row is full-width lede strip — reliable vs flex alone */
.welcome {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  justify-items: stretch;
  min-height: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: rgba(6, 5, 10, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  transition: opacity 1.2s var(--ease-out), visibility 1.2s;
  overflow: hidden;
  overscroll-behavior: contain;
  padding: 0;
  /* Encourage browser pinch-zoom on the welcome overlay */
  touch-action: pan-y pinch-zoom;
}

/* Home-screen PWA on iPhone: extra guard so the overlay matches the visual viewport */
@media (display-mode: standalone) {
  .welcome {
    height: 100%;
    min-height: 100%;
    min-height: 100dvh;
    min-height: 100svh;
    min-height: -webkit-fill-available;
  }
}

/* Centered hero block (title → details); scrolls inside top grid row */
.welcome-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 5vh 0 1rem;
  /* Equal vertical gap: instruction ↔ button ↔ convergence (same as button margins) */
  --welcome-rhythm: 1.5rem;
}

.welcome.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.welcome-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(2.2rem, 6vmin, 4.8rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f8f4e6;
  text-align: center;
  padding: 0 1.2rem;
}

.welcome-sub {
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.4vmin, 1.6rem);
  color: var(--lavender);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: 0.6rem;
  opacity: 0.85;
}

/* Shown only when the inline script detects a failed 3D/module load */
.welcome-engine-error {
  display: none;
  max-width: min(32rem, calc(100vw - 2rem));
  margin: 1rem auto 0;
  padding: 0 1.2rem;
  font-family: var(--font-body);
  font-size: clamp(0.82rem, 1.5vmin, 0.98rem);
  line-height: 1.55;
  color: var(--text-secondary);
  text-align: center;
  white-space: pre-line;
}

.welcome-engine-error:not([hidden]) {
  display: block;
}

.welcome.welcome--engine-error .welcome-instruction,
.welcome.welcome--engine-error .enter-btn,
.welcome.welcome--engine-error .welcome-convergence-details,
.welcome.welcome--engine-error .welcome-lede {
  display: none !important;
}

/* Flex + full-width inner: fixes Safari/WebKit where text-align on <p> stayed left */
.welcome-lede {
  flex-shrink: 0;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 100%;
  margin: 0;
  justify-self: stretch;
  box-sizing: border-box;
  padding: 0.65rem max(1rem, env(safe-area-inset-right, 0px)) max(0.65rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
  font-family: var(--font-body);
  font-size: clamp(0.75rem, 1.45vmin, 0.95rem);
  font-weight: 400;
  line-height: 1.3;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  border-top: 1px solid rgba(155, 138, 184, 0.15);
  background: rgba(4, 3, 8, 0.35);
  direction: ltr;
}

.welcome-lede-inner {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  text-align: center !important;
}

.welcome-instruction {
  font-size: clamp(0.85rem, 1.5vmin, 1rem);
  color: var(--text-muted);
  letter-spacing: 0.1em;
  margin-top: 2rem;
}

.enter-btn {
  margin-top: var(--welcome-rhythm, 1.5rem);
  margin-bottom: 0;
  padding: 0.85rem 2.8rem;
  border: 1px solid var(--gold-dim);
  border-radius: 2px;
  background: transparent;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: clamp(1rem, 1.8vmin, 1.3rem);
  letter-spacing: 0.15em;
  text-transform: lowercase;
  cursor: pointer;
  transition: background 0.3s var(--ease-out), color 0.3s var(--ease-out), border-color 0.3s var(--ease-out);
}

.enter-btn:hover {
  background: var(--gold-dim);
  color: #0a0908;
  border-color: var(--gold);
}

.welcome-convergence-details {
  margin-top: var(--welcome-rhythm, 1.5rem);
  width: min(900px, calc(100vw - 2.4rem));
  margin-left: auto;
  margin-right: auto;
  /* Center the block, but allow inner content to left-align */
  text-align: center;
}

.welcome-convergence-summary {
  /* Match the instruction line: same font + size, different color */
  font-family: var(--font-body);
  font-weight: 400;
  font-size: clamp(0.85rem, 1.5vmin, 1rem);
  letter-spacing: 0.1em;
  color: #dbe7f0;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(240, 200, 100, 0.12);
  user-select: none;
  /* Make it a comfortable tap target on phones */
  padding: 0.6rem 0.8rem;
  list-style: none;
  outline: none;
  /* Text block + chevron on its own row — reads cleanly on narrow viewports */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.65rem, 1.6vmin, 0.95rem);
}

.welcome-convergence-summary__text {
  display: block;
  width: 100%;
  max-width: min(26rem, calc(100vw - 2.75rem));
  margin: 0 auto;
  line-height: 1.58;
  color: #dbe7f0;
  text-wrap: balance;
}

/* Hide default marker */
.welcome-convergence-details > summary::-webkit-details-marker { display: none; }
.welcome-convergence-details > summary::marker { content: ""; }

/* Stroke chevrons: geometry is #mandala-chevron-up / #mandala-chevron-down in index.html */
.welcome-convergence-summary__chevron {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* ~44px min touch target; summary handles click, chevron stays visually centered */
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.35rem 0.75rem;
  box-sizing: border-box;
  cursor: pointer;
  line-height: 0;
  color: #f0d9a0;
  filter: drop-shadow(0 0 4px rgba(240, 200, 100, 0.7))
         drop-shadow(0 0 8px rgba(200, 160, 60, 0.35));
  transition: color 0.2s var(--ease-out), filter 0.2s var(--ease-out);
}
.welcome-convergence-summary:hover .welcome-convergence-summary__chevron {
  color: #f8f0c8;
  filter: drop-shadow(0 0 6px rgba(248, 220, 140, 0.85))
         drop-shadow(0 0 12px rgba(220, 180, 80, 0.45));
}
.welcome-convergence-summary__chevron-icon {
  display: block;
}
.welcome-convergence-summary__chevron-icon--down {
  animation: welcomeChevronBounceDown 2.4s ease-in-out infinite;
}
.welcome-convergence-summary__chevron-icon--up {
  display: none;
  animation: welcomeChevronBounceUp 2.4s ease-in-out infinite;
}
.welcome-convergence-details[open] .welcome-convergence-summary__chevron-icon--down {
  display: none;
}
.welcome-convergence-details[open] .welcome-convergence-summary__chevron-icon--up {
  display: block;
}

@keyframes welcomeChevronBounceDown {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(5px); }
}
@keyframes welcomeChevronBounceUp {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

.welcome-convergence-summary:hover {
  color: #dbe7f0;
}

.welcome-convergence-summary:focus-visible {
  box-shadow: 0 0 0 2px rgba(240, 200, 80, 0.25);
  border-radius: 6px;
}

.welcome-convergence {
  margin-top: 0.85rem;
  /* Center the whole list block; keep text left-aligned within it */
  display: inline-block;
  padding: 0 1.2rem 0 1.35rem;
  max-width: min(880px, calc(100vw - 2.4rem));
  list-style: disc;
  list-style-position: outside;
  text-align: left;
  color: #dbe7f0;
  font-family: 'Lora', serif;
  font-size: clamp(0.92rem, 1.55vmin, 1.12rem);
  line-height: 1.6;
  opacity: 0.95;
}

/* When expanded, keep the list usable on small screens */
.welcome-convergence-details[open] .welcome-convergence {
  max-height: min(48vh, 420px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.35rem;
}

/* (Centering handled via details text-align + inline-block list) */

.welcome-convergence strong {
  font-family: var(--font-display);
  font-weight: 600;
  /* Slightly larger so labels read as intended */
  font-size: 1.1em;
  letter-spacing: 0.02em;
  /* Slight gold tint to pop against the nebula */
  color: #f1dd9a;
}

@media (max-height: 760px) {
  .welcome-stack {
    --welcome-rhythm: 1.1rem;
  }
  .welcome-convergence {
    max-width: min(760px, calc(100vw - 2.0rem));
    font-size: clamp(0.9rem, 1.5vmin, 1.06rem);
    line-height: 1.55;
  }
}

@media (max-width: 520px) {
  .welcome-instruction {
    margin-top: 1.5rem;
    padding: 0 1.2rem;
    text-align: center;
  }
  .welcome-convergence-summary {
    letter-spacing: 0.045em;
    padding: 0.65rem 1rem;
  }
  .welcome-convergence-summary__text {
    font-size: clamp(0.78rem, 3.1vw, 0.92rem);
    line-height: 1.62;
    max-width: calc(100vw - 1.85rem);
  }
  .welcome-convergence-details {
    width: min(900px, calc(100vw - 1.6rem));
  }
  .welcome-convergence {
    padding: 0 1.0rem 0 1.25rem;
    font-size: clamp(0.98rem, 2.0vmin, 1.18rem);
    line-height: 1.62;
  }

  /* iPhone-size: make the bold labels a touch larger */
  .welcome-convergence strong {
    font-size: 1.16em;
  }
}

/* ═══ LAYER TITLE ═══ */
.layer-title {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -46%) scale(0.98);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  filter: blur(4px);
  transition: opacity 1.8s cubic-bezier(0.25, 0.1, 0.25, 1), transform 1.8s cubic-bezier(0.25, 0.1, 0.25, 1), filter 1.8s cubic-bezier(0.25, 0.1, 0.25, 1);
  z-index: 20;
  text-shadow:
    0 2px 20px rgba(6, 5, 10, 0.9),
    0 0 40px rgba(6, 5, 10, 0.7),
    0 0 80px rgba(6, 5, 10, 0.4);
  /* Padding gives the backdrop vignette room to breathe around the text */
  padding: 2.5rem 3.5rem;
}

/* Soft radial vignette behind the title — keeps text readable
   against bright torus rings at every layer without a hard box.
   Sized generously so the fade never ends abruptly.
   Only rendered when .visible to prevent iOS compositor ghosts. */
.layer-title::before,
.layer-title::after {
  content: none;
  position: absolute;
  z-index: -1;
  pointer-events: none;
  border-radius: 50%;
}

.layer-title.visible::before {
  content: '';
  inset: -80% -70%;
  background: radial-gradient(
    ellipse 50% 50% at 50% 50%,
    rgba(4, 3, 8, 0.66) 0%,
    rgba(4, 3, 8, 0.52) 30%,
    rgba(4, 3, 8, 0.28) 55%,
    rgba(4, 3, 8, 0.08) 75%,
    transparent 100%
  );
}

/* Dim the actual canvas pixels behind the title text area.
   backdrop-filter works through the composited WebGL canvas;
   the blur softens hard geometry edges and brightness dims them.
   Masked to a soft oval so it blends without a visible box edge. */
.layer-title.visible::after {
  content: '';
  inset: -40% -30%;
  backdrop-filter: brightness(0.56) blur(4px);
  -webkit-backdrop-filter: brightness(0.56) blur(4px);
  mask-image: radial-gradient(
    ellipse 52% 52% at 50% 50%,
    black 0%, black 40%, transparent 100%
  );
  -webkit-mask-image: radial-gradient(
    ellipse 52% 52% at 50% 50%,
    black 0%, black 40%, transparent 100%
  );
}

/* iPhone/iOS Safari (and some Android WebViews) can produce rectangular compositing
   artifacts with backdrop-filter over WebGL canvases. Use a pure gradient fallback
   on coarse-pointer/mobile contexts to avoid white slab overlays. */
@media (pointer: coarse), (max-width: 768px) {
  .layer-title.visible::after {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: radial-gradient(
      ellipse 52% 52% at 50% 50%,
      rgba(5, 4, 9, 0.56) 0%,
      rgba(5, 4, 9, 0.38) 42%,
      rgba(5, 4, 9, 0.16) 70%,
      transparent 100%
    );
  }
}

/* Visible: settled at center, sharp, fully opaque */
.layer-title.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  filter: blur(0);
}

/* Dissolve out: drifts up, disperses — wave receding into ocean */
.layer-title.dissolve-out {
  opacity: 0;
  transform: translate(-50%, -56%) scale(1.03);
  filter: blur(6px);
}

.layer-number {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(0.7rem, 1.1vmin, 0.85rem);
  color: var(--lavender);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  opacity: 0.8;
  text-shadow: 0 1px 12px rgba(4, 3, 8, 0.9);
}

.layer-name {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(2rem, 4.5vmin, 3.8rem);
  color: var(--gold);
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-wrap: balance;
  text-shadow:
    0 0 30px rgba(240, 200, 80, 0.35),
    0 0 60px rgba(212, 165, 116, 0.15),
    0 2px 16px rgba(4, 3, 8, 0.95),
    0 0 40px rgba(4, 3, 8, 0.6);
}

.layer-subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(0.9rem, 1.6vmin, 1.2rem);
  color: var(--rose);
  margin-top: 0.5rem;
  letter-spacing: 0.04em;
  opacity: 0.85;
  text-shadow: 0 1px 12px rgba(4, 3, 8, 0.9);
}

/* ═══ TEACHING PANEL ═══ */
.teaching-wrap {
  position: absolute;
  bottom: clamp(80px, 12vh, 140px);
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, 92vw);
  z-index: 20;
  /* Must not use pointer-events: none — iOS home-screen / standalone WebKit often fails to
     deliver taps to children (scroll-hint buttons) even when they set pointer-events: auto. */
  pointer-events: auto;
}

/* Collapsed: free the viewport — panel collapses; only the toggle stays tappable */
.teaching-wrap--collapsed {
  pointer-events: none;
}
.teaching-wrap--collapsed .teaching-panel-toggle {
  pointer-events: auto;
}
.teaching-wrap--collapsed .teaching-panel {
  max-height: 0 !important;
  min-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  border: none !important;
  box-shadow: none !important;
}
.teaching-wrap--collapsed .scroll-hint {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Before entering the scene, keep the control out of the way */
.teaching-wrap:not(.teaching-wrap--in-scene) .teaching-panel-toggle {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Matches .audio-toggle / .mic-toggle — sits on panel top-right when expanded */
.teaching-panel-toggle {
  position: absolute;
  z-index: 36;
  top: 6px;
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: auto;
  left: auto;
  transform: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--text-faint);
  border-radius: 50%;
  background: rgba(6, 5, 10, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  transition:
    color 0.3s var(--ease-out),
    border-color 0.3s var(--ease-out),
    background 0.3s var(--ease-out),
    top 0.35s var(--ease-out),
    right 0.35s var(--ease-out),
    bottom 0.35s var(--ease-out),
    left 0.35s var(--ease-out),
    transform 0.35s var(--ease-out),
    width 0.35s var(--ease-out),
    height 0.35s var(--ease-out),
    border-radius 0.35s var(--ease-out);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  box-sizing: border-box;
}
.teaching-panel-toggle:hover {
  color: var(--gold);
  border-color: var(--gold-dim);
}
.teaching-panel-toggle__icon {
  flex-shrink: 0;
}
.teaching-panel-toggle__icon--show {
  display: none;
}
.teaching-wrap--collapsed .teaching-panel-toggle__icon--hide {
  display: none;
}
.teaching-wrap--collapsed .teaching-panel-toggle__icon--show {
  display: block;
}
/*
 * Collapsed: “show key ideas” chip — fixed to viewport so it stays truly centered
 * (the wrap is only min(640px, 92vw); centering inside it skewed the pill on wide screens).
 */
.teaching-wrap--collapsed .teaching-panel-toggle {
  position: fixed;
  top: auto;
  right: auto;
  left: 50%;
  transform: translateX(-50%);
  /* Match .teaching-wrap bottom (overridden in mobile / landscape blocks below) */
  bottom: clamp(80px, 12vh, 140px);
  z-index: 40;
  width: auto;
  min-width: 44px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(232, 220, 200, 0.88);
}
.teaching-panel-toggle::after {
  content: none;
}
.teaching-wrap--collapsed .teaching-panel-toggle::after {
  content: 'key ideas';
}
.teaching-wrap--collapsed .teaching-panel-toggle .teaching-panel-toggle__icon--show {
  margin-right: 2px;
}

.teaching-panel {
  position: relative;
  max-height: 42vh;
  overflow-y: auto;
  overscroll-behavior: contain;   /* prevent scroll-chaining to canvas */
  -webkit-overflow-scrolling: touch; /* smooth inertial scroll on iOS */
  touch-action: pan-y;            /* tell browser: vertical = scroll this panel */
  background: var(--panel-bg);
  backdrop-filter: blur(26px);
  -webkit-backdrop-filter: blur(26px);
  border: none;
  border-radius: 20px;
  padding: clamp(24px, 4vmin, 38px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
  /* Diffuse edges — mask fades the entire element (including backdrop blur) at edges */
  -webkit-mask-image: radial-gradient(ellipse 92% 90% at 50% 50%, black 50%, transparent 100%);
  mask-image: radial-gradient(ellipse 92% 90% at 50% 50%, black 50%, transparent 100%);
  /* Soft outer glow bleeds panel into scene */
  box-shadow:
    0 0 40px 15px rgba(8, 6, 14, 0.35),
    0 0 80px 30px rgba(8, 6, 14, 0.15);
}

.teaching-panel.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
  animation: panelSlideIn 2.0s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes panelSlideIn {
  0%   { opacity: 0;   transform: translateY(28px); filter: blur(3px); }
  30%  { opacity: 0.3; transform: translateY(16px); filter: blur(1px); }
  60%  { opacity: 0.7; transform: translateY(6px);  filter: blur(0);   }
  100% { opacity: 1;   transform: translateY(0);    filter: blur(0);   }
}

/* Subtle scroll-fade indicators — inset shadows */
.teaching-panel.fade-top {
  box-shadow:
    inset 0 18px 16px -12px rgba(6, 5, 10, 0.7),
    0 0 40px rgba(155, 138, 184, 0.04), 0 0 80px rgba(199, 136, 154, 0.03);
}
.teaching-panel.fade-bottom {
  box-shadow:
    inset 0 -18px 16px -12px rgba(6, 5, 10, 0.7),
    0 0 40px rgba(155, 138, 184, 0.04), 0 0 80px rgba(199, 136, 154, 0.03);
}
.teaching-panel.fade-top.fade-bottom {
  box-shadow:
    inset 0 18px 16px -12px rgba(6, 5, 10, 0.7),
    inset 0 -18px 16px -12px rgba(6, 5, 10, 0.7),
    0 0 40px rgba(155, 138, 184, 0.04), 0 0 80px rgba(199, 136, 154, 0.03);
}

/* Scroll hint arrows — same chevrons as welcome; buttons when scrollable (not disabled) */
.scroll-hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 0.5rem 1rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: #f0d9a0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease-out);
  z-index: 25;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  filter: drop-shadow(0 0 4px rgba(240, 200, 100, 0.7))
         drop-shadow(0 0 8px rgba(200, 160, 60, 0.35));
}
.scroll-hint:not(:disabled) {
  opacity: 1;
  pointer-events: auto;
}
.scroll-hint:disabled {
  cursor: default;
}
.scroll-hint:focus {
  outline: none;
}
.scroll-hint:focus-visible {
  box-shadow: 0 0 0 2px rgba(240, 200, 80, 0.35);
  border-radius: 6px;
}
.scroll-hint--up {
  bottom: 100%;
  margin-bottom: 8px;
  animation: hintBounceUp 2.4s ease-in-out infinite;
}
.scroll-hint--down {
  top: 100%;
  margin-top: 8px;
  animation: hintBounceDown 2.4s ease-in-out infinite;
}

@keyframes hintBounceDown {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(5px); }
}
@keyframes hintBounceUp {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-5px); }
}

.teaching-panel::-webkit-scrollbar { width: 4px; }
.teaching-panel::-webkit-scrollbar-track { background: transparent; }
.teaching-panel::-webkit-scrollbar-thumb { background: var(--text-faint); border-radius: 2px; }

.teaching-inner {
  font-family: 'Lora', Georgia, serif;
  font-size: clamp(1rem, 1.8vmin, 1.18rem);
  line-height: 1.75;
}

/* Organic reveal — each element surfaces like a discovery */
.teaching-inner .stagger-in {
  --drift: 8px;
  opacity: 0;
  transform: translateY(var(--drift));
  animation: discoverFadeIn 2.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes discoverFadeIn {
  0%   { opacity: 0;    transform: translateY(var(--drift)); filter: blur(2px); }
  45%  { opacity: 0.85; transform: translateY(1px);          filter: blur(0);   }
  70%  { opacity: 1;    transform: translateY(0);            filter: blur(0);   }
  85%  { opacity: 1;    filter: brightness(1.12); }
  100% { opacity: 1;    transform: translateY(0);            filter: brightness(1); }
}

@media (prefers-reduced-motion: reduce) {
  .teaching-inner .stagger-in {
    opacity: 1;
    transform: none;
    animation: none;
    filter: none !important;
  }
}

/* Communal presence — lineage of minds who sat here */
.communal-presence {
  display: block;
  font-family: 'Jost', sans-serif;
  font-size: 0.82em;
  letter-spacing: 0.08em;
  color: rgba(190, 178, 205, 0.7);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  text-align: center;
  margin-top: 1.5rem;
  padding-top: 0.8rem;
  line-height: 1.8;
  border-top: 1px solid rgba(160, 145, 175, 0.12);
}
.communal-presence em {
  font-style: italic;
  color: rgba(215, 200, 155, 0.55);
  /* The historical names are grey-violet (past). 'you' is warm gold (present).
     The only living presence in the lineage. */
}

.teaching-inner p {
  margin-bottom: 0.7rem;
  max-width: 60ch;
}

.teaching-inner .key-phrase {
  font-family: var(--font-display);
  color: var(--gold);
  font-weight: 500;
  font-size: 1.1em;
}

.teaching-inner .dim {
  color: var(--text-muted);
}

/* Elegant one-sentence explanations — clean italic with radiating glow */
.teaching-inner .explain {
  display: block;
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: 1.12em;
  line-height: 1.65;
  color: #fbf8f0;
  margin: 0.25rem 0 0.85rem 0;
  padding: 0.3em 0.5em;
  position: relative;
  border-radius: 3px;
  /* Dark outline for letterform definition, then warm diffuse haze */
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.6),
    0 0 1px rgba(0, 0, 0, 0.35),
    0 0 14px rgba(240, 200, 100, 0.18),
    0 0 32px rgba(212, 165, 116, 0.09);
}

/* Radiating background glow — diffuse, slow-breathing warmth */
.teaching-inner .explain::before {
  content: '';
  position: absolute;
  inset: -10px -22px;
  border-radius: 14px;
  background: radial-gradient(
    ellipse at 30% 50%,
    rgba(240, 200, 80, 0.16) 0%,
    rgba(212, 165, 116, 0.10) 35%,
    rgba(126, 200, 160, 0.06) 60%,
    rgba(212, 136, 154, 0.04) 80%,
    transparent 100%
  );
  opacity: 0.5;
  animation: explainGlow 28s linear infinite;
  z-index: -1;
  pointer-events: none;
}

/* Secondary layer — diffuse warm edge-light, offset timing for depth */
.teaching-inner .explain::after {
  content: '';
  position: absolute;
  inset: -6px -16px;
  border-radius: 10px;
  background: radial-gradient(
    ellipse at 70% 40%,
    rgba(240, 210, 130, 0.12) 0%,
    rgba(200, 160, 80, 0.05) 55%,
    transparent 100%
  );
  opacity: 0;
  animation: explainGlow2 28s linear infinite;
  animation-delay: -7s;
  z-index: -1;
  pointer-events: none;
}

/* Primary glow — Gaussian bell-curve breath: slow swell, soft crest, gentle release */
@keyframes explainGlow {
  0%, 100% {
    opacity: 0.15;
    transform: scale(0.98);
    filter: blur(10px);
  }
  15% {
    opacity: 0.3;
    transform: scale(0.99);
    filter: blur(11px);
  }
  30% {
    opacity: 0.55;
    transform: scale(1.0);
    filter: blur(13px);
  }
  42% {
    opacity: 0.82;
    transform: scale(1.015);
    filter: blur(14px);
  }
  50% {
    opacity: 0.95;
    transform: scale(1.025);
    filter: blur(16px);
  }
  58% {
    opacity: 0.82;
    transform: scale(1.015);
    filter: blur(14px);
  }
  70% {
    opacity: 0.55;
    transform: scale(1.0);
    filter: blur(13px);
  }
  85% {
    opacity: 0.3;
    transform: scale(0.99);
    filter: blur(11px);
  }
}

/* Secondary glow — same bell shape, slightly offset phase via delay */
@keyframes explainGlow2 {
  0%, 100% {
    opacity: 0;
    transform: scale(1.0);
    filter: blur(8px);
  }
  15% {
    opacity: 0.08;
    transform: scale(1.005);
    filter: blur(9px);
  }
  30% {
    opacity: 0.22;
    transform: scale(1.01);
    filter: blur(11px);
  }
  42% {
    opacity: 0.4;
    transform: scale(1.02);
    filter: blur(12px);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.025);
    filter: blur(14px);
  }
  58% {
    opacity: 0.4;
    transform: scale(1.02);
    filter: blur(12px);
  }
  70% {
    opacity: 0.22;
    transform: scale(1.01);
    filter: blur(11px);
  }
  85% {
    opacity: 0.08;
    transform: scale(1.005);
    filter: blur(9px);
  }
}

.teaching-inner .math {
  font-family: 'Courier New', 'Menlo', monospace;
  color: var(--blue-star);
  font-size: 1.05em;
  letter-spacing: 0.02em;
}

/* Notable quotes — understated, attributed */
.teaching-inner .quote {
  display: block;
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
  font-size: 1.02em;
  line-height: 1.6;
  color: rgba(240, 218, 150, 1);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6), 0 0 8px rgba(0, 0, 0, 0.3), 0 0 14px rgba(210, 185, 110, 0.12);
  margin: 0.8rem 0 0.15rem 0;
  padding: 0.45em 0 0.1em 1.1em;
  border-left: 2.5px solid rgba(170, 155, 185, 0.55);
  background: rgba(8, 6, 14, 0.18);
  border-radius: 0 6px 0 0;
}
.teaching-inner .quote-author {
  display: block;
  font-family: 'Jost', sans-serif;
  font-style: normal;
  font-size: 0.85em;
  color: rgba(225, 205, 145, 0.82);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  letter-spacing: 0.06em;
  margin: 0 0 0.7rem 0;
  padding: 0.1em 0 0.45em 1.1em;
  border-left: 2.5px solid rgba(170, 155, 185, 0.55);
  background: rgba(8, 6, 14, 0.18);
  border-radius: 0 0 6px 0;
}

.teaching-inner .latin {
  font-style: italic;
  color: var(--rose);
  font-size: 1.1em;
}

.teaching-inner .symbol {
  color: var(--lavender);
  font-size: 1.2em;
  margin-right: 0.5rem;
}

.teaching-inner .distinction {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: baseline;
}

.teaching-inner ul { list-style: none; padding: 0; }
.teaching-inner ul li {
  padding-left: 1.3em;
  position: relative;
  margin-bottom: 0.45rem;
  font-size: clamp(0.92rem, 1.6vmin, 1.08rem);
}
.teaching-inner ul li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--rose);
  opacity: 0.6;
}

/* ═══ NAV SLIDER ═══ */
/* Persistent layer id — complements the brief center title; always readable at the track */
.layer-context {
  margin: 0;
  padding: 0 0 2px;
  max-width: min(7.5rem, 28vw);
  font-family: var(--font-display);
  font-size: clamp(0.58rem, 1.35vmin, 0.72rem);
  letter-spacing: 0.06em;
  line-height: 1.25;
  text-align: center;
  text-transform: none;
  color: var(--gold-dim);
  opacity: 0.92;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-controls {
  position: absolute;
  right: clamp(16px, 2.5vw, 36px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 25;
  user-select: none;
  -webkit-user-select: none;
}

.nav-endpoint {
  font-family: var(--font-display);
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-faint);
  opacity: 0.5;
  transition: opacity 0.3s var(--ease-out);
}
.nav-controls:hover .nav-endpoint { opacity: 0.75; }

.slider-track {
  position: relative;
  width: 3px;
  height: clamp(140px, 28vh, 240px);
  background: rgba(78, 70, 64, 0.35);
  border-radius: 2px;
  cursor: pointer;
  touch-action: none;
}
/* Invisible wider touch zone — 44px min per WCAG, much easier to grab */
.slider-track::before {
  content: '';
  position: absolute;
  inset: -12px -22px;
  cursor: pointer;
}

.slider-fill {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  border-radius: 2px;
  background: linear-gradient(to bottom, var(--gold), var(--lavender));
  opacity: 0.5;
  transition: height 0.4s var(--ease-out);
  pointer-events: none;
}

.slider-thumb {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg);
  box-shadow: 0 0 10px rgba(212, 165, 116, 0.5), 0 0 3px rgba(212, 165, 116, 0.3);
  cursor: grab;
  touch-action: none;
  transition: top 0.4s var(--ease-out), transform 0.15s var(--ease-out), box-shadow 0.2s var(--ease-out);
  z-index: 3;
}
.slider-thumb:hover,
.slider-thumb.dragging {
  transform: translate(-50%, -50%) scale(1.25);
  box-shadow: 0 0 16px rgba(212, 165, 116, 0.7), 0 0 4px rgba(155, 138, 184, 0.4);
}
.slider-thumb.dragging {
  cursor: grabbing;
  transition: transform 0.1s var(--ease-out), box-shadow 0.1s var(--ease-out);
}

.slider-stops {
  position: absolute;
  inset: 0;
}
.slider-stop {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--text-faint);
  background: transparent;
  transition: background 0.3s var(--ease-out), border-color 0.3s var(--ease-out),
              box-shadow 0.3s var(--ease-out), transform 0.3s var(--ease-out);
  cursor: pointer;
  /* Invisible 44px touch target — WCAG minimum, easy for thumbs */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.slider-stop::before {
  content: '';
  position: absolute;
  inset: -18px;
  border-radius: 50%;
}
.slider-stop.visited {
  background: rgba(212, 165, 116, 0.3);
  border-color: var(--gold-dim);
}
.slider-stop.active {
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(240, 200, 80, 0.5), 0 0 20px rgba(212, 165, 116, 0.25);
  transform: translate(-50%, -50%) scale(1);
}
/* Grow + glow pulse when a stop becomes active (tapped/clicked) */
.slider-stop.pulse {
  animation: stopPulse 0.6s var(--ease-out);
}
@keyframes stopPulse {
  0%   { transform: translate(-50%, -50%) scale(1);   box-shadow: 0 0 8px rgba(240, 200, 80, 0.5), 0 0 20px rgba(212, 165, 116, 0.25); }
  35%  { transform: translate(-50%, -50%) scale(1.9);  box-shadow: 0 0 16px rgba(240, 200, 80, 0.8), 0 0 40px rgba(212, 165, 116, 0.4); }
  100% { transform: translate(-50%, -50%) scale(1);   box-shadow: 0 0 8px rgba(240, 200, 80, 0.5), 0 0 20px rgba(212, 165, 116, 0.25); }
}

.slider-tooltip {
  position: absolute;
  right: 100%;
  margin-right: 14px;
  white-space: nowrap;
  font-family: var(--font-display);
  font-size: clamp(0.7rem, 1.2vmin, 0.85rem);
  color: var(--gold);
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.3s var(--ease-out), transform 0.3s var(--ease-out);
  pointer-events: none;
  text-shadow: 0 1px 8px rgba(6, 5, 10, 0.9);
}
.slider-tooltip.visible {
  opacity: 1;
  transform: translateX(0);
}

/* ═══ BREATH ═══ */
.breath {
  position: absolute;
  top: clamp(12px, 2vh, 32px);
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.breath-word {
  font-family: var(--font-display);
  font-size: clamp(0.65rem, 1vmin, 0.8rem);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--lavender);
  opacity: 0.15;
  /* 19s cycle: 4s inhale (21%) + 7s hold (37%) + 8s exhale (42%)
     A real contemplative rhythm, not a decorative sine wave.
     The form instructs the practice. */
  animation: breatheText 19s ease-in-out infinite;
}

/* Gyro vignette — background-only calm focus */
.gyro-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15; /* above canvas, below HUD controls/panels */
  opacity: 0;
  transition: opacity 0.6s var(--ease-out);
  background:
    radial-gradient(ellipse 85% 75% at 50% 52%,
      rgba(6, 5, 10, 0) 40%,
      rgba(6, 5, 10, 0.18) 70%,
      rgba(6, 5, 10, 0.42) 100%);
}

@keyframes breatheText {
  /* Inhale: 0% → 21% (4s of 19s) — rise */
  0%   { opacity: 0.12; letter-spacing: 0.28em; }
  21%  { opacity: 0.48; letter-spacing: 0.52em; }
  /* Hold: 21% → 58% (7s of 19s) — stillness at peak */
  58%  { opacity: 0.44; letter-spacing: 0.50em; }
  /* Exhale: 58% → 100% (8s of 19s) — slow dissolve */
  100% { opacity: 0.12; letter-spacing: 0.28em; }
}

/* ═══ BOTTOM HUD ROW (flex: one shared baseline — fixes iOS PWA / standalone mis-alignment) ═══ */
.hud-bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(12px, 2vh, 24px);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding-left: clamp(12px, 2vw, 24px);
  padding-right: clamp(12px, 2vw, 24px);
  box-sizing: border-box;
  pointer-events: none;
  z-index: 25;
}
.hud-bottom-cluster {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}
.hud-bottom-cluster--right {
  flex-shrink: 0;
}

/* ═══ AUDIO TOGGLE ═══ */
.audio-toggle {
  position: relative;
  width: 44px;
  height: 44px;
  border: 1px solid var(--text-faint);
  border-radius: 50%;
  background: rgba(6, 5, 10, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.3s var(--ease-out), border-color 0.3s var(--ease-out), opacity 0.6s var(--ease-out);
  opacity: 0;
  pointer-events: none;
  z-index: 25;
  touch-action: manipulation;    /* no 300ms delay on iOS */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.audio-toggle.visible {
  opacity: 1;
  pointer-events: auto;
}
.audio-toggle:hover {
  color: var(--gold);
  border-color: var(--gold-dim);
}
.audio-toggle .audio-icon {
  width: 18px;
  height: 18px;
}
.audio-toggle .audio-off { display: none; }
.audio-toggle.muted .audio-on  { display: none; }
.audio-toggle.muted .audio-off { display: block; }

/* ═══ MICROPHONE REACTIVE TOGGLE ═══ */
.mic-toggle {
  position: relative;
  width: 44px;
  height: 44px;
  border: 1px solid var(--text-faint);
  border-radius: 50%;
  background: rgba(6, 5, 10, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.3s var(--ease-out), border-color 0.3s var(--ease-out), box-shadow 0.6s var(--ease-out);
  z-index: 25;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.mic-toggle:hover {
  color: var(--gold);
  border-color: var(--gold-dim);
}
.mic-toggle .mic-icon {
  width: 18px;
  height: 18px;
}
.mic-toggle .mic-on-icon { display: none; }
.mic-toggle.active {
  color: var(--gold);
  border-color: var(--gold-dim);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.2);
}
.mic-toggle.active .mic-off-icon { display: none; }
.mic-toggle.active .mic-on-icon  { display: block; }

/* ── Mic permission modal ── */
.mic-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease-out);
}
.mic-modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.mic-modal {
  background: rgba(12, 10, 18, 0.95);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 2rem 2.2rem;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 0 40px rgba(212, 175, 55, 0.08);
}
.mic-modal h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--gold);
  margin: 0 0 1rem;
}
.mic-modal p {
  font-family: 'Lora', Georgia, serif;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--text-secondary);
  margin: 0 0 0.8rem;
}
.mic-modal-detail {
  font-size: 0.8rem !important;
  color: var(--text-faint) !important;
  font-style: italic;
}
.mic-headphone-hint {
  color: var(--text-secondary) !important;
  font-style: normal;
  margin-top: 0.6rem !important;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  background: rgba(212, 175, 55, 0.06);
  border-left: 2px solid var(--gold-dim);
}
.mic-modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.4rem;
  justify-content: center;
}
.mic-modal-btn {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  padding: 0.55rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s var(--ease-out);
  border: 1px solid var(--gold-dim);
}
.mic-modal-allow {
  background: rgba(212, 175, 55, 0.12);
  color: var(--gold);
}
.mic-modal-allow:hover {
  background: rgba(212, 175, 55, 0.22);
}
.mic-modal-deny {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--text-faint);
}
.mic-modal-deny:hover {
  color: var(--text-secondary);
}


/* ═══ FULLSCREEN TOGGLE ═══ */
.fs-toggle {
  position: relative;
  width: 44px;
  height: 44px;
  border: 1px solid var(--text-faint);
  border-radius: 50%;
  background: rgba(6, 5, 10, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.3s var(--ease-out), border-color 0.3s var(--ease-out), opacity 0.6s var(--ease-out);
  z-index: 25;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.fs-toggle:hover {
  color: var(--gold);
  border-color: var(--gold-dim);
}
.fs-toggle .fs-icon {
  width: 18px;
  height: 18px;
}
.fs-toggle .fs-exit { display: none; }
.fs-toggle.is-fs .fs-enter { display: none; }
.fs-toggle.is-fs .fs-exit  { display: block; }

/* ═══ EXIT (welcome splash) — positioned in flex row with audio/fs/mic ═══ */
.exit-toggle {
  position: relative;
  width: 44px;
  height: 44px;
  border: 1px solid var(--text-faint);
  border-radius: 50%;
  background: rgba(6, 5, 10, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.3s var(--ease-out), border-color 0.3s var(--ease-out), opacity 0.45s var(--ease-out);
  z-index: 25;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  opacity: 0;
  pointer-events: none;
}
.exit-toggle.visible {
  opacity: 1;
  pointer-events: auto;
}
.exit-toggle:hover {
  color: var(--gold);
  border-color: var(--gold-dim);
}
.exit-toggle .exit-icon {
  width: 18px;
  height: 18px;
}

/* ═══ MOBILE ═══ */
@media (max-width: 768px) {
  .teaching-wrap {
    bottom: clamp(70px, 10vh, 100px);
  }
  .teaching-panel {
    max-height: 38vh;
    padding: clamp(14px, 3vmin, 22px);
  }
  .teaching-inner {
    font-size: clamp(1.1rem, 4.6vw, 1.35rem);
  }
  .teaching-inner .key-phrase {
    font-size: 1.14em;
  }
  .teaching-inner .explain {
    font-size: 1.22em;
    line-height: 1.75;
    font-weight: 400;
    padding: 0.35em 0.5em;
  }
  .teaching-inner ul li {
    font-size: clamp(1.05rem, 4.4vw, 1.28rem);
  }
  .nav-controls {
    right: 8px;
  }
  .nav-endpoint {
    display: none;
  }
  .slider-track {
    height: clamp(120px, 24vh, 180px);
  }
  .slider-thumb {
    width: 22px;
    height: 22px;
  }
  .slider-stop {
    width: 13px;
    height: 13px;
    border-width: 2px;
  }

  /* Bottom HUD — match prior mobile tap targets; flex row keeps exit level with left cluster */
  .hud-bottom-bar {
    bottom: 8px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .audio-toggle,
  .fs-toggle,
  .mic-toggle,
  .exit-toggle {
    width: 38px;
    height: 38px;
  }
  .teaching-panel-toggle {
    width: 38px;
    height: 38px;
  }
  .teaching-wrap--collapsed .teaching-panel-toggle {
    width: auto;
    height: 36px;
    padding: 0 12px;
    font-size: 0.65rem;
    bottom: clamp(70px, 10vh, 100px);
    transform: translateX(-50%);
  }
}

/* Same rules as above, expressed as a single @media (no nested @media) so engines without
   full CSS nesting support for @rules (older Firefox, etc.) still apply portrait layout.
   Arc uses Chromium and is unaffected; this is for Gecko / odd embeds. */
@media (max-width: 768px) and (orientation: portrait) {
  .teaching-wrap--collapsed .teaching-panel-toggle {
    left: 50%;
    right: auto;
    transform: translateX(-50%) !important;
  }
  .teaching-wrap:not(.teaching-wrap--collapsed) .teaching-panel-toggle {
    left: 50%;
    right: auto;
    top: auto;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
  }
  .teaching-wrap .scroll-hint--up {
    bottom: calc(100% + 56px);
    margin-bottom: 0;
  }
}

/* ═══ LANDSCAPE CRAMPED VIEWPORT ═══
   Phones in landscape with Safari/Chrome chrome visible:
   typically ~375-430px tall after browser UI eats ~100px.
   Tighten everything so it fits the squeezed space. */
@media (orientation: landscape) and (max-height: 500px) {
  /* Breath indicator — nudge down away from address bar */
  .breath {
    top: 4px;
  }
  .breath-word {
    font-size: 0.55rem;
  }

  /* Layer title — compact for short viewports */
  .layer-title {
    padding: 1.2rem 2rem;
  }
  .layer-title::before {
    inset: -50% -40%;
  }
  .layer-title::after {
    inset: -25% -20%;
  }
  .layer-name {
    font-size: clamp(1.4rem, 4vmin, 2.4rem);
  }
  .layer-number {
    font-size: 0.6rem;
    margin-bottom: 0.25rem;
  }
  .layer-subtitle {
    font-size: clamp(0.8rem, 1.4vmin, 1rem);
    margin-top: 0.25rem;
  }

  /* Teaching panel — less height, tighter padding, closer to bottom */
  .teaching-wrap {
    bottom: 56px;
    width: min(560px, 88vw);
  }
  .teaching-panel {
    max-height: 34vh;
    padding: clamp(12px, 2.5vmin, 18px);
    border-radius: 14px;
  }
  .teaching-inner {
    font-size: clamp(0.85rem, 1.6vmin, 1rem);
    line-height: 1.6;
  }
  .teaching-inner .explain {
    font-size: 1.05em;
    line-height: 1.55;
    padding: 0.2em 0.4em;
  }

  /* Navigation slider — shorter track */
  .slider-track {
    height: clamp(80px, 22vh, 140px);
  }
  .slider-thumb {
    width: 14px;
    height: 14px;
  }
  .slider-stop {
    width: 9px;
    height: 9px;
  }
  .nav-endpoint {
    font-size: 0.45rem;
  }

  /* Bottom HUD bar — tighter to edge (landscape) */
  .hud-bottom-bar {
    bottom: 8px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .audio-toggle,
  .fs-toggle,
  .mic-toggle,
  .exit-toggle {
    width: 38px;
    height: 38px;
  }
  .teaching-panel-toggle {
    width: 38px;
    height: 38px;
  }
  .teaching-wrap--collapsed .teaching-panel-toggle {
    width: auto;
    height: 36px;
    padding: 0 11px;
    font-size: 0.62rem;
    bottom: 56px;
  }

  /* Welcome screen — compact */
  .welcome-title {
    font-size: clamp(1.6rem, 5vmin, 3rem);
  }
  .welcome-sub {
    font-size: clamp(0.85rem, 2vmin, 1.1rem);
    margin-top: 0.3rem;
  }
  .welcome-lede {
    font-size: clamp(0.7rem, 1.35vmin, 0.88rem);
    line-height: 1.28;
    padding: 0.55rem max(0.65rem, env(safe-area-inset-right, 0px)) max(0.55rem, env(safe-area-inset-bottom, 0px)) max(0.65rem, env(safe-area-inset-left, 0px));
  }
  .welcome-lede-inner {
    text-align: center !important;
  }
  .welcome-instruction {
    font-size: clamp(0.75rem, 1.3vmin, 0.9rem);
    margin-top: 0.8rem;
  }
  .enter-btn {
    margin-top: 0.8rem;
    padding: 0.6rem 2rem;
    font-size: clamp(0.9rem, 1.5vmin, 1.1rem);
  }
  .welcome-convergence-details {
    margin-top: 0.8rem;
  }

  /* Mic modal — compact for landscape */
  .mic-modal {
    max-width: 340px;
    padding: 1.4rem 1.6rem;
  }
  .mic-modal h3 {
    font-size: 1.1rem;
    margin-bottom: 0.6rem;
  }
  .mic-modal p {
    font-size: 0.82rem;
    line-height: 1.5;
    margin-bottom: 0.5rem;
  }
}

/* ── Focus-visible: keyboard navigation indicator ── */
:focus-visible {
  outline: 2px solid rgba(200, 184, 138, 0.7);
  outline-offset: 3px;
  border-radius: 4px;
}

.audio-toggle:focus-visible,
.mic-toggle:focus-visible,
.fs-toggle:focus-visible,
.exit-toggle:focus-visible,
.teaching-panel-toggle:focus-visible {
  outline: 2px solid rgba(200, 184, 138, 0.8);
  outline-offset: 4px;
  box-shadow: 0 0 12px 2px rgba(200, 184, 138, 0.15);
}

.enter-btn:focus-visible {
  outline: 2px solid rgba(200, 184, 138, 0.9);
  outline-offset: 4px;
  box-shadow: 0 0 20px 4px rgba(200, 184, 138, 0.2);
}

.slider-track:focus-visible {
  outline: 2px solid rgba(200, 184, 138, 0.6);
  outline-offset: 2px;
}

/* Remove default outlines for mouse/touch users */
:focus:not(:focus-visible) {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Mobile compositor safety mode ───────────────────────────────────────────
   Some mobile engines regress backdrop/mask compositing over WebGL surfaces.
   JS sets `.mobile-compositor-safe` on <html> for affected browsers. */
html.mobile-compositor-safe .welcome,
html.mobile-compositor-safe .teaching-panel,
html.mobile-compositor-safe .teaching-panel-toggle,
html.mobile-compositor-safe .audio-toggle,
html.mobile-compositor-safe .mic-toggle,
html.mobile-compositor-safe .fs-toggle,
html.mobile-compositor-safe .exit-toggle,
html.mobile-compositor-safe .mic-modal-overlay {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

html.mobile-compositor-safe .welcome {
  background: rgba(6, 5, 10, 0.84) !important;
  transform: translateZ(0);
  backface-visibility: hidden;
}

html.mobile-compositor-safe .teaching-panel {
  background: linear-gradient(
    180deg,
    rgba(12, 10, 19, 0.92) 0%,
    rgba(10, 8, 16, 0.90) 100%
  ) !important;
  -webkit-mask-image: none !important;
  mask-image: none !important;
}

html.mobile-compositor-safe .teaching-panel-toggle,
html.mobile-compositor-safe .audio-toggle,
html.mobile-compositor-safe .mic-toggle,
html.mobile-compositor-safe .fs-toggle,
html.mobile-compositor-safe .exit-toggle {
  background: rgba(8, 7, 13, 0.72) !important;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.22) inset;
  transform: translateZ(0);
  backface-visibility: hidden;
}

html.mobile-compositor-safe .mic-modal-overlay {
  background: rgba(0, 0, 0, 0.78) !important;
}

/* Fallback when backdrop-filter is unavailable (e.g., some Firefox mobile paths). */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .welcome,
  .teaching-panel,
  .teaching-panel-toggle,
  .audio-toggle,
  .mic-toggle,
  .fs-toggle,
  .exit-toggle,
  .mic-modal-overlay {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .teaching-panel {
    -webkit-mask-image: none;
    mask-image: none;
    background: linear-gradient(
      180deg,
      rgba(12, 10, 19, 0.92) 0%,
      rgba(10, 8, 16, 0.90) 100%
    );
  }
}
