/* ==========================================================================
   Medusa Transmission — scroll intro for the homepage (index.html)
   The hero medusa photo is redrawn live as a grid of figures and symbols.
   Scroll decodes it, the medusae dance, then dissolve into the normal hero.
   Shown only when html.mx-on is set (WebGL present, motion allowed).
   ========================================================================== */

.mx-track {
  --mx-bg: #020617;
  --mx-ink: #e2e8f0;
  --mx-soft: rgba(226, 232, 240, 0.6);
  --mx-dim: rgba(226, 232, 240, 0.34);
  --mx-accent: #8ec5ff;
  --mx-pink: #ec4899;
  --mx-rule: rgba(148, 163, 184, 0.16);
  --mx-serif: 'Instrument Serif', Georgia, serif;
  --mx-mono: 'JetBrains Mono', ui-monospace, monospace;

  display: none;
  position: relative;
  height: 420vh;
  background: var(--mx-bg);
  color: var(--mx-ink);
}
html.mx-on .mx-track { display: block; }

.mx-stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  overflow: clip;
  touch-action: pan-y;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  background: var(--mx-bg);
}

.mx-stage::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 140px;
  z-index: 1;
  background: linear-gradient(to bottom, rgba(2, 6, 23, 0.9), rgba(2, 6, 23, 0));
  pointer-events: none;
}

.mx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 1.4s ease;
}
.mx-stage[data-status="ready"] .mx-canvas { opacity: 1; }

.mx-top, .mx-log, .mx-head, .mx-aside, .mx-hint, .mx-dock, .mx-caption, .mx-loader {
  position: absolute;
  z-index: 2;
}

/* --- Top bar --- */
.mx-top {
  top: 0;
  left: clamp(16px, 2.4vw, 32px);
  right: clamp(16px, 2.4vw, 32px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: clamp(14px, 1.8vw, 22px) 0 12px;
  border-bottom: 1px solid var(--mx-rule);
  font: 500 10.5px/1 var(--mx-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  pointer-events: none;
}
.mx-top__l img { height: 16px; width: auto; display: block; }
.mx-top__c { text-align: center; }
.mx-top__c > * { white-space: nowrap; }
.mx-top__c em {
  font: italic 400 15px/1 var(--mx-serif);
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--mx-accent);
}
.mx-top__r {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--mx-soft);
}
.mx-live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.mx-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mx-accent);
  box-shadow: 0 0 10px var(--mx-accent);
  animation: mx-blink 1.6s steps(2) infinite;
}
@keyframes mx-blink { 50% { opacity: 0.25; } }
.mx-skip {
  pointer-events: auto;
  white-space: nowrap;
  margin-left: 10px;
  padding: 7px 11px;
  border: 1px solid var(--mx-rule);
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.5);
  color: var(--mx-soft);
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.mx-skip:hover { color: var(--mx-ink); border-color: var(--mx-accent); }
.mx-skip:focus-visible { outline: 1px solid var(--mx-accent); outline-offset: 2px; }

/* --- Live log --- */
.mx-log {
  left: clamp(16px, 2.4vw, 32px);
  top: 76px;
  margin: 0;
  font: 500 10px/1.7 var(--mx-mono);
  letter-spacing: 0.04em;
  color: var(--mx-dim);
  white-space: pre;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 40%);
  mask-image: linear-gradient(to bottom, transparent, #000 40%);
}

/* --- Headline --- */
.mx-head {
  left: clamp(16px, 2.4vw, 32px);
  bottom: clamp(24px, 4vw, 56px);
  margin: 0;
  font: 400 clamp(52px, 8.2vw, 148px)/0.88 var(--mx-serif);
  letter-spacing: -0.035em;
  text-shadow: 0 0 40px rgba(2, 6, 23, 0.85);
  pointer-events: none;
}
.mx-head .ln { display: block; overflow: hidden; padding-bottom: 0.06em; }
.mx-head .li { display: block; animation: mx-rise 1.6s cubic-bezier(0.16, 1, 0.3, 1) both; }
.mx-head .ln:nth-child(1) .li { animation-delay: 0.5s; }
.mx-head .ln:nth-child(2) .li { animation-delay: 0.6s; }
.mx-head em { color: var(--mx-accent); }
@keyframes mx-rise { from { transform: translateY(110%); } }

/* --- Aside --- */
.mx-aside {
  right: clamp(16px, 2.4vw, 32px);
  bottom: clamp(88px, 9vw, 120px);
  width: min(300px, 40vw);
  pointer-events: none;
}
.mx-aside p {
  margin: 0;
  font: 400 12.5px/1.55 var(--mx-mono);
  color: var(--mx-soft);
}

/* --- Hint --- */
.mx-hint {
  left: 50%;
  top: 50%;
  transform: translate(-50%, 0);
  margin-top: min(36vh, 330px);
  font: 500 10px/1 var(--mx-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mx-soft);
  pointer-events: none;
  white-space: nowrap;
}
.mx-hint span {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px); display: inline-block; animation: mx-bob 2.4s ease-in-out infinite; }
@keyframes mx-bob { 50% { transform: translateY(5px); opacity: 0.5; } }

/* --- Glyph set dock --- */
.mx-dock {
  right: clamp(16px, 2.4vw, 32px);
  bottom: clamp(24px, 4vw, 56px);
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--mx-rule);
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.6);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.mx-dock[hidden] { display: none; }
.mx-dock button {
  font: 500 10.5px/1 var(--mx-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 10px 13px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--mx-soft);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}
.mx-dock button:hover { color: var(--mx-ink); }
.mx-dock button.is-active { background: var(--mx-accent); color: #020617; }
.mx-dock button:focus-visible { outline: 1px solid var(--mx-accent); outline-offset: 2px; }

/* --- Mid-story caption (while the medusae dance) --- */
.mx-caption {
  left: clamp(16px, 2.4vw, 32px);
  bottom: clamp(24px, 4vw, 56px);
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 0 30px rgba(2, 6, 23, 0.9);
}
.mx-caption__kicker {
  margin: 0 0 12px;
  font: 500 10.5px/1 var(--mx-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mx-accent);
}
.mx-caption__title {
  margin: 0;
  font: 400 clamp(40px, 5.6vw, 96px)/0.9 var(--mx-serif);
  letter-spacing: -0.03em;
  color: var(--mx-ink);
}
.mx-caption__title em { color: var(--mx-accent); }

/* --- Loader --- */
.mx-loader {
  inset: 0;
  display: grid;
  place-items: center;
  font: 500 10.5px/1 var(--mx-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mx-soft);
}

/* --- Intro entrance --- */
.mx-top > *, .mx-aside p, .mx-hint, .mx-dock button {
  animation: mx-in 1.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.mx-top > *:nth-child(1) { animation-delay: 0.3s; }
.mx-top > *:nth-child(2) { animation-delay: 0.38s; }
.mx-top > *:nth-child(3) { animation-delay: 0.46s; }
.mx-aside p, .mx-hint { animation-delay: 1s; }
.mx-dock button { animation-delay: 1.1s; }
@keyframes mx-in { from { opacity: 0; transform: translateY(-8px); } }
.mx-hint { animation-name: mx-in-hint; }
@keyframes mx-in-hint { from { opacity: 0; } }

/* --- Site header hides while the intro owns the screen --- */
.site-header, .progress-bar {
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease,
    background var(--transition), border-color var(--transition);
}
body.mx-intro .site-header,
body.mx-intro .progress-bar {
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
}
/* keyboard users tabbing into the menu during the intro get it back */
body.mx-intro .site-header:focus-within {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

/* --- Medium screens: the centre line needs the room, the live readout steps aside --- */
@media (min-width: 701px) and (max-width: 1100px) {
  .mx-live { display: none; }
}

/* --- Narrow screens --- */
@media (max-width: 700px) {
  .mx-top { grid-template-columns: 1fr auto; }
  .mx-top__c { display: none; }
  .mx-log { top: 64px; font-size: 9px; max-height: 30vh; overflow: hidden; }
  .mx-head { bottom: 128px; font-size: clamp(46px, 14vw, 76px); }
  .mx-aside { left: 16px; right: 16px; width: auto; bottom: 72px; }
  .mx-aside p { font-size: 11.5px; }
  .mx-dock { left: 16px; right: auto; bottom: 20px; }
  .mx-dock button { padding: 9px 10px; }
  .mx-hint { display: none; }
  .mx-caption { bottom: 128px; }
}

@media (prefers-reduced-motion: reduce) {
  .mx-track { display: none !important; }
}
