/* AlephZero /tour — a cinematic, unlisted flight through the catalog.
   The static rules are the resilient no-JS / reduced-motion version. Once
   Three.js starts, html.tour-live turns the document into a pinned 3D scene. */

:root {
  --tour-bg: #edf1f8;
  --tour-bg-deep: #dfe7f4;
  --tour-panel: rgba(250, 252, 255, .78);
  --tour-panel-solid: #f8faff;
  --tour-line: rgba(25, 39, 62, .19);
  --tour-faint: rgba(25, 39, 62, .08);
  --tour-glow: rgba(74, 116, 255, .16);
  --tour-signal: #315ed4;
}

html[data-theme="dark"] {
  --tour-bg: #070b13;
  --tour-bg-deep: #03060c;
  --tour-panel: rgba(11, 17, 29, .76);
  --tour-panel-solid: #0d1421;
  --tour-line: rgba(194, 211, 236, .19);
  --tour-faint: rgba(194, 211, 236, .07);
  --tour-glow: rgba(70, 113, 255, .22);
  --tour-signal: #7e9dff;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --tour-bg: #070b13;
    --tour-bg-deep: #03060c;
    --tour-panel: rgba(11, 17, 29, .76);
    --tour-panel-solid: #0d1421;
    --tour-line: rgba(194, 211, 236, .19);
    --tour-faint: rgba(194, 211, 236, .07);
    --tour-glow: rgba(70, 113, 255, .22);
    --tour-signal: #7e9dff;
  }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tour-body { background: var(--tour-bg); }

/* ================= STATIC / ACCESSIBLE FALLBACK ================= */
.tour-stage { max-width: 1120px; margin: 0 auto; padding: 42px 24px 64px; }
.tour-cv, .fin-label, .mission-route, .flight-telemetry, .frame-corners, .cosmic-haze { display: none; }

.system { position: relative; display: flex; align-items: baseline; justify-content: center; margin: 5vh 0 3vh; }
.sun { font-family: var(--font-serif); font-size: 24vmin; line-height: 1; }
.zero { font-family: var(--font-serif); font-size: 9vmin; line-height: 1; margin-left: .6vmin; }

.mission-intro { max-width: 780px; margin: 0 auto 80px; text-align: center; }
.intro-index, .mission-kicker, .mission-actions, .mission-manifest, .wl-index, .wl-small, .wl-orbit, .tp-cap, .tp-open, .te-kicker {
  font-family: var(--font-mono); text-transform: uppercase;
}
.intro-index { font-size: .66rem; letter-spacing: .18em; color: var(--ghost); margin-bottom: 18px; }
.mission-kicker { display: flex; justify-content: center; gap: 14px; margin: 0 0 18px; font-size: .66rem; letter-spacing: .17em; color: var(--ink-muted); }
.mission-kicker span + span::before { content: "//"; margin-right: 14px; color: var(--ghost); }
.mission-intro h1 { margin: 0; font-family: var(--font-serif); font-size: clamp(3.1rem, 9vw, 7rem); font-weight: 400; line-height: .87; letter-spacing: -.065em; }
.mission-copy { max-width: 620px; margin: 30px auto 0; font-family: var(--font-serif); font-size: clamp(1.08rem, 2vw, 1.35rem); line-height: 1.5; color: var(--ink-muted); }
.mission-copy em { color: var(--ink); }
.mission-actions { display: flex; align-items: center; justify-content: center; gap: 24px; margin-top: 28px; font-size: .69rem; letter-spacing: .11em; }
.mission-launch { display: inline-flex; align-items: center; gap: 26px; padding: 14px 16px; border: 1px solid var(--ink); border-radius: 2px; background: var(--ink); color: var(--paper); text-transform: uppercase; cursor: pointer; }
.mission-launch:hover { transform: translateY(-2px); }
.mission-bypass { color: var(--ink-muted); text-decoration: underline; text-decoration-color: var(--ghost); text-underline-offset: 5px; }
.mission-bypass:hover { color: var(--ink); }
.mission-manifest { display: grid; grid-template-columns: repeat(3, 1fr); max-width: 620px; margin: 34px auto 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.mission-manifest div { padding: 14px; border-right: 1px solid var(--rule); }
.mission-manifest div:last-child { border-right: 0; }
.mission-manifest dt { font-size: .58rem; letter-spacing: .14em; color: var(--ghost); }
.mission-manifest dd { margin: 4px 0 0; font-size: .76rem; color: var(--ink); }

.world { padding: 54px 0 58px; border-top: 1px solid var(--rule); }
.w-label { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; align-items: end; margin-bottom: 20px; }
.wl-index { grid-row: 1 / 4; align-self: stretch; padding: 6px 14px 0 0; border-right: 1px solid currentColor; font-size: .64rem; letter-spacing: .11em; }
.wl-small { font-size: .62rem; letter-spacing: .18em; color: var(--ink-muted); }
.wl-big { font-family: var(--font-serif); font-weight: 400; letter-spacing: -.035em; font-size: clamp(2rem, 5vw, 3.6rem); line-height: .95; color: currentColor; }
.wl-orbit { font-size: .59rem; letter-spacing: .12em; color: var(--ink-muted); }
.world[data-world="math"] .w-label { color: var(--ink-math); }
.world[data-world="prog"] .w-label { color: var(--ink-prog); }
.world[data-world="cs"] .w-label { color: var(--ink-cs); }
.world[data-world="ai"] .w-label { color: var(--ink-ai); }

.w-panel { max-width: 680px; border: 1px solid var(--rule); background: var(--paper-raised); }
.tp-cap { display: flex; justify-content: space-between; gap: 16px; padding: 11px 14px; border-bottom: 1px solid var(--rule); font-size: .58rem; letter-spacing: .14em; color: var(--ink-muted); }
.tp-row { display: grid; grid-template-columns: 5rem minmax(0, 1fr) auto; gap: 0 14px; align-items: baseline; padding: 10px 14px; border-bottom: 1px solid color-mix(in srgb, var(--rule) 70%, transparent); }
.tp-row:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.tp-row .aleph { font-size: .79rem; }
.tp-t { font-family: var(--font-serif); font-size: 1rem; line-height: 1.25; color: var(--ink); }
.tp-meta { display: flex; gap: 16px; padding: 10px 14px; font-family: var(--font-mono); font-size: .68rem; color: var(--ink-muted); border-bottom: 1px solid var(--rule); }
.tp-open { display: flex; justify-content: space-between; padding: 12px 14px; font-size: .61rem; letter-spacing: .12em; }
.tp-open:hover { background: color-mix(in srgb, currentColor 7%, transparent); }

.tour-end { padding: 80px 0 30px; text-align: center; border-top: 1px solid var(--rule); }
.te-kicker { font-size: .62rem; letter-spacing: .17em; color: var(--ink-muted); }
.tour-end h2 { margin: 18px 0 14px; font-family: var(--font-serif); font-size: clamp(2.8rem, 7vw, 6rem); font-weight: 400; line-height: .9; letter-spacing: -.055em; }
.tour-end p { margin: 0 auto 24px; max-width: 520px; font-family: var(--font-serif); color: var(--ink-muted); }
.te-link { display: inline-flex; gap: 32px; padding: 13px 15px; border: 1px solid var(--ink); font-family: var(--font-mono); font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; }
.te-link:hover { background: var(--ink); color: var(--paper); }

/* ================= THREE.JS FLIGHT ================= */
html.tour-live, html.tour-live body { scroll-behavior: auto; }
html.tour-live body { overflow-x: hidden; background: var(--tour-bg); }

html.tour-live header.site {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  background: color-mix(in srgb, var(--tour-bg) 74%, transparent);
  backdrop-filter: blur(18px) saturate(125%);
  -webkit-backdrop-filter: blur(18px) saturate(125%);
  transform: translateY(-110%);
  transition: transform .7s cubic-bezier(.2,.75,.2,1);
}
html.tour-live.tour-hdr header.site { transform: translateY(0); }

html.tour-live .tour-scroll { height: 1080vh; }
html.tour-live .tour-stage { position: fixed; inset: 0; height: 100vh; max-width: none; padding: 0; margin: 0; overflow: hidden; isolation: isolate; }
html.tour-live .tour-stage::before {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(circle at 72% 46%, var(--tour-glow), transparent 26%),
    radial-gradient(circle at 18% 88%, color-mix(in srgb, var(--ink-ai) 10%, transparent), transparent 32%),
    linear-gradient(135deg, var(--tour-bg), var(--tour-bg-deep));
}
html.tour-live .tour-stage::after {
  content: ""; position: absolute; inset: 0; z-index: 7; pointer-events: none; opacity: .33;
  background: linear-gradient(90deg, color-mix(in srgb, var(--tour-bg-deep) 42%, transparent), transparent 24%, transparent 77%, color-mix(in srgb, var(--tour-bg-deep) 54%, transparent));
  mix-blend-mode: multiply;
}
html[data-theme="dark"].tour-live .tour-stage::after { mix-blend-mode: normal; opacity: .5; }

html.tour-live .tour-cv { display: block; position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; }
html.tour-live .system { display: none; }
html.tour-live .cosmic-haze { display: block; position: absolute; inset: -20%; z-index: 1; pointer-events: none; opacity: .8; filter: blur(70px); transform: translate3d(calc(var(--tour-p, 0) * -4%), calc(var(--tour-p, 0) * 3%), 0); background: radial-gradient(ellipse at 62% 44%, var(--tour-glow), transparent 28%); }

html.tour-live .frame-corners { display: block; position: absolute; inset: 18px; z-index: 12; pointer-events: none; opacity: .66; }
.frame-corners i { position: absolute; width: 28px; height: 28px; border-color: var(--tour-line); }
.frame-corners i:nth-child(1) { left: 0; top: 0; border-left: 1px solid; border-top: 1px solid; }
.frame-corners i:nth-child(2) { right: 0; top: 0; border-right: 1px solid; border-top: 1px solid; }
.frame-corners i:nth-child(3) { right: 0; bottom: 0; border-right: 1px solid; border-bottom: 1px solid; }
.frame-corners i:nth-child(4) { left: 0; bottom: 0; border-left: 1px solid; border-bottom: 1px solid; }

/* launch composition */
html.tour-live .mission-intro {
  position: absolute; left: clamp(34px, 6vw, 104px); top: 50%; z-index: 9;
  width: min(43rem, 46vw); max-width: none; margin: 0; text-align: left;
  opacity: calc(1 - var(--intro-out, 0));
  transform: translateY(calc(-50% - var(--intro-out, 0) * 26px));
  pointer-events: auto;
  transition: opacity .12s linear;
}
html.tour-live.tour-flight .mission-intro { pointer-events: none; }
html.tour-live .intro-index { display: flex; align-items: center; gap: 12px; margin: 0 0 5vh; color: var(--tour-signal); }
html.tour-live .intro-index::before { content: ""; width: 38px; height: 1px; background: currentColor; }
html.tour-live .mission-kicker { justify-content: flex-start; margin-bottom: 18px; }
html.tour-live .mission-intro h1 { font-size: clamp(4.8rem, 7.4vw, 9.2rem); line-height: .79; letter-spacing: -.075em; text-wrap: balance; }
html.tour-live .mission-copy { max-width: 38rem; margin: 28px 0 0; font-size: clamp(1rem, 1.25vw, 1.25rem); line-height: 1.5; }
html.tour-live .mission-actions { justify-content: flex-start; margin-top: 30px; }
html.tour-live .mission-launch { transition: color .25s ease, background .25s ease, transform .25s ease, box-shadow .25s ease; }
html.tour-live .mission-launch:hover { box-shadow: 0 14px 36px color-mix(in srgb, var(--ink) 15%, transparent); }
html.tour-live .mission-manifest { max-width: 34rem; margin: 5vh 0 0; }

/* route / navigation telemetry */
html.tour-live .mission-route {
  display: grid; grid-template-columns: 1px auto; gap: 17px; position: absolute; right: clamp(26px, 3.3vw, 62px); top: 50%; z-index: 10;
  height: 47vh; transform: translateY(-50%) translateX(16px); opacity: 0; pointer-events: none;
  transition: opacity .6s ease, transform .6s ease;
}
html.tour-live.tour-flight .mission-route { opacity: 1; transform: translateY(-50%); }
.route-rail { position: relative; width: 1px; background: var(--tour-line); overflow: hidden; }
.route-fill { position: absolute; inset: 0 0 auto; height: calc(var(--tour-p, 0) * 100%); background: var(--ink); box-shadow: 0 0 12px var(--tour-signal); }
.mission-route ol { display: flex; flex-direction: column; justify-content: space-between; list-style: none; margin: -7px 0; padding: 0; }
.mission-route li { display: grid; grid-template-columns: 24px auto; align-items: center; gap: 10px; min-height: 14px; font-family: var(--font-mono); font-size: .59rem; letter-spacing: .11em; text-transform: uppercase; color: var(--ghost); transition: color .35s ease, transform .35s ease; }
.mission-route li::before { content: ""; position: absolute; left: -20px; width: 7px; height: 7px; border: 1px solid var(--tour-line); border-radius: 50%; background: var(--tour-bg); transition: background .35s ease, box-shadow .35s ease, border-color .35s ease; }
.mission-route li.active { color: var(--ink); transform: translateX(-4px); }
.mission-route li.active::before { background: var(--tour-signal); border-color: var(--tour-signal); box-shadow: 0 0 12px var(--tour-signal); }
.route-code { color: var(--tour-signal); }

html.tour-live .flight-telemetry {
  display: flex; align-items: center; gap: 13px; position: absolute; left: clamp(28px, 3vw, 54px); bottom: 27px; z-index: 10;
  font-family: var(--font-mono); font-size: .57rem; letter-spacing: .14em; color: var(--ink-muted); opacity: 0; transition: opacity .5s ease;
}
html.tour-live.tour-flight .flight-telemetry { opacity: .86; }
.telemetry-pulse { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-prog); box-shadow: 0 0 10px var(--ink-prog); animation: signal 1.8s ease-in-out infinite; }
@keyframes signal { 50% { opacity: .25; transform: scale(.65); } }

/* knowledge-world fly-bys */
html.tour-live .world { position: absolute; inset: 0; border: 0; padding: 0; pointer-events: none; z-index: 8; }
html.tour-live .w-label {
  position: absolute; left: clamp(26px, 5vw, 88px); top: 16vh; width: max-content; max-width: 44vw; margin: 0;
  display: grid; opacity: 0; transform: translateY(28px); filter: blur(7px);
  transition: opacity .7s ease, transform .8s cubic-bezier(.18,.75,.2,1), filter .7s ease;
}
html.tour-live .world.on .w-label { opacity: 1; transform: none; filter: none; }
html.tour-live .wl-index { min-width: 55px; }
html.tour-live .wl-big { font-size: clamp(3.2rem, 6vw, 7rem); text-shadow: 0 0 42px color-mix(in srgb, currentColor 12%, transparent); }
html.tour-live .wl-orbit { margin-top: 5px; }

html.tour-live .w-panel {
  position: absolute; left: clamp(26px, 5vw, 88px); bottom: 10vh; width: min(430px, 37vw); max-width: none; z-index: 9;
  border: 1px solid var(--tour-line); border-top-color: color-mix(in srgb, currentColor 48%, var(--tour-line)); border-radius: 2px;
  background: var(--tour-panel); box-shadow: 0 24px 70px rgba(0,0,0,.12); backdrop-filter: blur(22px) saturate(120%); -webkit-backdrop-filter: blur(22px) saturate(120%);
  opacity: 0; transform: translateY(36px) scale(.98); pointer-events: auto;
  transition: opacity .65s ease .08s, transform .8s cubic-bezier(.18,.75,.2,1) .08s;
}
html.tour-live .world.on .w-panel { opacity: 1; transform: none; }
html.tour-live .tp-cap { color: var(--ink-muted); }
html.tour-live .tp-row { padding-block: 9px; }
html.tour-live .tp-row:last-of-type { border-bottom: 1px solid var(--tour-line); }
html.tour-live .tp-open { color: currentColor; }

/* system-map finale */
html.tour-live .fin-label {
  display: inline-flex; align-items: baseline; gap: 8px; position: absolute; left: 0; top: 0; z-index: 10;
  padding: 6px 10px; border: 1px solid var(--tour-line); border-radius: 2px; background: var(--tour-panel);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-family: var(--font-mono); font-size: .63rem; letter-spacing: .09em; text-transform: uppercase;
  opacity: 0; transform: translate(0, -50%) scale(.96); transition: opacity .5s ease, transform .5s ease; pointer-events: none; white-space: nowrap;
}
html.tour-live .fin-label.fl-left { transform: translate(-100%, -50%) scale(.96); }
html.tour-live.tour-fin .fin-label { opacity: 1; transform: translate(0, -50%) scale(1); pointer-events: auto; }
html.tour-live.tour-fin .fin-label.fl-left { transform: translate(-100%, -50%) scale(1); }
html.tour-live .fin-label .fl-n { color: var(--ink-muted); }
html.tour-live .fin-label:hover { border-color: currentColor; }

html.tour-live .tour-end {
  position: absolute; left: 50%; bottom: 4.5vh; z-index: 10; width: min(720px, 78vw); padding: 0; border: 0;
  opacity: 0; transform: translateX(-50%) translateY(24px); pointer-events: none;
  transition: opacity .75s ease .2s, transform .75s ease .2s;
}
html.tour-live.tour-fin .tour-end { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
html.tour-live .tour-end h2 { margin: 10px 0 8px; font-size: clamp(2.6rem, 5vw, 5.4rem); }
html.tour-live .tour-end p { margin-bottom: 16px; font-size: .96rem; }
html.tour-live .te-link { background: var(--tour-panel); backdrop-filter: blur(14px); }
html.tour-live .te-link:hover { background: var(--ink); }

/* responsive flight controls */
@media (max-width: 900px) {
  html.tour-live .mission-intro { width: min(38rem, 62vw); }
  html.tour-live .mission-intro h1 { font-size: clamp(4.3rem, 10vw, 7rem); }
  html.tour-live .route-name { display: none; }
  html.tour-live .mission-route { right: 28px; }
  html.tour-live .w-panel { width: min(400px, 48vw); }
  html.tour-live .w-label { max-width: 58vw; }
}

@media (max-width: 700px) {
  .tour-stage { padding-inline: 18px; }
  .mission-manifest { grid-template-columns: 1fr; }
  .mission-manifest div { border-right: 0; border-bottom: 1px solid var(--rule); }
  .mission-manifest div:last-child { border-bottom: 0; }
  .tp-row { grid-template-columns: 4.5rem minmax(0, 1fr) auto; padding-inline: 10px; gap: 8px; }

  html.tour-live .frame-corners { inset: 10px; }
  html.tour-live .mission-intro { left: 22px; top: 47%; width: calc(100vw - 44px); }
  html.tour-live .mission-intro::before { content: ""; position: absolute; inset: -24px -14px -30px; z-index: -1; pointer-events: none; background: linear-gradient(90deg, color-mix(in srgb, var(--tour-bg) 96%, transparent) 0%, color-mix(in srgb, var(--tour-bg) 91%, transparent) 76%, transparent 100%); filter: blur(2px); }
  html.tour-live .intro-index { margin-bottom: 4vh; }
  html.tour-live .mission-intro h1 { max-width: 92vw; font-size: clamp(4rem, 18vw, 6.3rem); }
  html.tour-live .mission-copy { max-width: 87vw; margin-top: 22px; font-size: .96rem; }
  html.tour-live .mission-actions { gap: 16px; margin-top: 22px; }
  html.tour-live .mission-launch { gap: 17px; padding: 12px; }
  html.tour-live .mission-bypass { font-size: .6rem; }
  html.tour-live .mission-manifest { display: none; }
  html.tour-live .mission-route { display: none; }
  html.tour-live .flight-telemetry { left: 18px; right: 18px; bottom: 16px; justify-content: space-between; font-size: .51rem; }

  html.tour-live .w-label { left: 20px; top: 11vh; max-width: calc(100vw - 40px); }
  html.tour-live .wl-big { font-size: clamp(2.9rem, 13vw, 5rem); }
  html.tour-live .w-panel { left: 14px; right: 14px; bottom: 6.5vh; width: auto; }
  html.tour-live .tp-cap { padding: 9px 10px; }
  html.tour-live .tp-row { padding-block: 7px; }
  html.tour-live .tp-row .aleph { font-size: .72rem; }
  html.tour-live .tp-t { font-size: .88rem; }
  html.tour-live .tp-open { padding: 10px; }
  html.tour-live .tour-end { bottom: 4vh; width: calc(100vw - 32px); }
  html.tour-live .tour-end h2 { font-size: clamp(2.5rem, 12vw, 4rem); }
  html.tour-live .tour-end p { display: none; }
  html.tour-live .fin-label { font-size: .53rem; padding: 4px 6px; }
  html.tour-live.tour-fin .fin-label { transform: none !important; }
  html.tour-live .fin-label[data-world="math"] { left: 14px !important; top: 53vh !important; }
  html.tour-live .fin-label[data-world="prog"] { left: auto !important; right: 14px !important; top: 53vh !important; }
  html.tour-live .fin-label[data-world="cs"] { left: 14px !important; top: 58vh !important; }
  html.tour-live .fin-label[data-world="ai"] { left: auto !important; right: 14px !important; top: 58vh !important; }
}

@media (max-height: 690px) and (min-width: 701px) {
  html.tour-live .mission-intro { top: 53%; }
  html.tour-live .intro-index { margin-bottom: 2.5vh; }
  html.tour-live .mission-intro h1 { font-size: clamp(4.3rem, 6.8vw, 7rem); }
  html.tour-live .mission-copy { margin-top: 18px; }
  html.tour-live .mission-manifest { margin-top: 3vh; }
  html.tour-live .w-label { top: 13vh; }
  html.tour-live .w-panel { bottom: 7vh; }
}

@media (prefers-reduced-motion: reduce) {
  .mission-launch, .telemetry-pulse { animation: none; transition: none; }
}
