/* The WebGL layer, scroll-driven stages, stage annotations and their fallbacks. */

/* One canvas, fixed to the viewport, above the content. It draws only inside empty
   stage frames and the travelling page, never over the header. */
.world-layer {
  position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none;
  clip-path: inset(var(--header) 0 0 0); visibility: hidden; contain: strict;
}
.world-layer.is-visible { visibility: visible; }
.world-layer canvas { width: 100%; height: 100%; }
.world-failed .world-layer { display: none; }

/* Scroll-driven stage: the sticky frame stays while its runway is scrolled. */
.scene-track { --scene-runway: 700px; --sticky-size: 640px; position: relative; height: calc(var(--sticky-size) + var(--scene-runway)); }
.scene-sticky { position: sticky; top: max(calc(var(--header) + 14px), calc((100svh + var(--header) - var(--sticky-size)) / 2)); }
.motion-reduced .scene-track { height: auto; }
.motion-reduced .scene-sticky { position: relative; top: auto; }

.stage-frame {
  position: relative; margin: 0; min-height: 420px; height: min(64svh, 620px);
  border-radius: var(--r-l); border: 1px solid var(--hair); overflow: hidden; isolation: isolate;
  background:
    radial-gradient(90% 70% at 50% 92%, rgba(36, 111, 241, 0.2), transparent 62%),
    linear-gradient(180deg, rgba(156, 193, 255, 0.035), rgba(156, 193, 255, 0) 55%),
    var(--ink-0);
}
.stage-frame::before {
  content: ""; position: absolute; inset: 0; z-index: -1; opacity: 0.55; pointer-events: none;
  background-image: linear-gradient(rgba(156, 193, 255, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(156, 193, 255, 0.06) 1px, transparent 1px);
  background-size: 48px 48px; background-position: center;
  -webkit-mask-image: radial-gradient(70% 60% at 50% 40%, #000, transparent); mask-image: radial-gradient(70% 60% at 50% 40%, #000, transparent);
}
.stage-frame.is-wide { height: min(66svh, 640px); }
.scene-viewport { position: absolute; inset: 0; }
/* Registration marks at the four corners, as on a printer's proof. */
.crop {
  position: absolute; inset: 16px; pointer-events: none; --c: rgba(156, 193, 255, 0.4); --l: 16px;
  background:
    linear-gradient(var(--c), var(--c)) top left / var(--l) 1px no-repeat, linear-gradient(var(--c), var(--c)) top left / 1px var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) top right / var(--l) 1px no-repeat, linear-gradient(var(--c), var(--c)) top right / 1px var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom left / var(--l) 1px no-repeat, linear-gradient(var(--c), var(--c)) bottom left / 1px var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) bottom right / var(--l) 1px no-repeat, linear-gradient(var(--c), var(--c)) bottom right / 1px var(--l) no-repeat;
}
.stage-caption {
  position: absolute; left: 30px; bottom: 26px; right: 30px; z-index: 1;
  font: 500 13px/1.6 var(--sans); letter-spacing: 0.04em; color: var(--text-2); pointer-events: none;
}
.stage-caption::before { content: "图示 · "; font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: var(--blue-soft); }

/* Without WebGL a line drawing names the same handoff. */
.world-fallback { display: none; position: absolute; inset: 0; place-content: center; justify-items: center; gap: 18px; color: var(--text-2); font-size: 14px; }
.world-fallback svg { width: min(360px, 70%); stroke: var(--blue-soft); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.world-failed .world-fallback { display: grid; }

/* Stage tools: state, play / pause, loop. */
.scene-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 4px; }
.scene-state { flex: 1 1 100%; font: 500 12px/1.6 var(--mono); letter-spacing: 0.04em; color: var(--text-3); margin-bottom: 4px; }
.scene-state::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 8px; border-radius: 50%; background: var(--text-4); vertical-align: 1px; transition: background var(--t-base), box-shadow var(--t-base); }
.scene-track[data-cadence="scroll"] .scene-state::before { background: var(--blue-soft); }
.scene-track[data-cadence="playing"] .scene-state::before { background: var(--blue-bright); box-shadow: 0 0 0 4px rgba(76, 139, 255, 0.2); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(76, 139, 255, 0); } }
.scene-play, .scene-loop {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--hair-2); font-size: 13px; color: var(--text-1); transition: background var(--t-base), border-color var(--t-base);
}
.scene-play svg { width: 14px; height: 14px; fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.scene-play:hover:not(:disabled), .scene-loop:hover:not(:disabled) { background: rgba(156, 193, 255, 0.08); border-color: var(--hair-3); }
.scene-loop { color: var(--text-2); }
.scene-loop[aria-pressed="true"] { color: var(--paper-ink); background: var(--paper); border-color: var(--paper); }
.network-bar .scene-tools { flex-wrap: nowrap; }
.network-bar .scene-state { flex: none; margin: 0 10px 0 0; }

/* Annotations that follow the stage's objects (positioned by the director). */
.stage-notes { position: fixed; inset: 0; z-index: 6; pointer-events: none; clip-path: inset(var(--header) 0 0 0); }
.stage-note { position: absolute; left: 0; top: 0; opacity: 0; will-change: transform, opacity; }
.stage-note i { position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%; background: var(--blue-mist); box-shadow: 0 0 0 4px rgba(156, 193, 255, 0.18), 0 0 18px rgba(156, 193, 255, 0.6); }
.stage-note span {
  position: absolute; bottom: 40px; white-space: nowrap; padding: 7px 12px; border-radius: 999px;
  font: 500 12px/1 var(--sans); letter-spacing: 0.06em; color: var(--text-1);
  background: rgba(3, 7, 15, 0.72); border: 1px solid var(--hair-3); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.stage-note span::after { content: ""; position: absolute; top: 100%; width: 1px; height: 36px; background: linear-gradient(var(--hair-3), transparent); }
.stage-note[data-side="start"] span { right: -14px; }
.stage-note[data-side="start"] span::after { right: 13px; }
.stage-note[data-side="end"] span { left: -14px; }
.stage-note[data-side="end"] span::after { left: 13px; }
.motion-reduced .stage-notes, .world-failed .stage-notes { display: none; }

/* ---------------------------------------------------------------- tablet / phone */
@media (max-width: 900px) {
  .stage-frame, .stage-frame.is-wide { height: min(54svh, 520px); min-height: 340px; }
  .network-bar { justify-content: center; }
  .network-bar .scene-tools { flex-wrap: wrap; justify-content: center; }
  .network-bar .scene-state { flex: 1 1 100%; text-align: center; margin: 0; }
  .network-steps { justify-content: center; width: 100%; }
}
@media (max-width: 520px) {
  .stage-frame, .stage-frame.is-wide { height: min(48svh, 420px); min-height: 280px; border-radius: var(--r-m); }
  .growth-stage .stage-frame { height: min(44svh, 380px); }
  .crop { inset: 10px; --l: 12px; }
  .stage-caption { left: 18px; bottom: 16px; font-size: 12px; }
  .scene-play, .scene-loop { padding: 0 14px; }
  .network-steps li + li::before { width: 12px; margin: 0 6px; }
}

/* Step legend: three named parts of the stage's action, driven by the same progress. */
.stage-steps { --action: 0; position: relative; display: grid; gap: 2px; padding-left: 22px; }
.stage-steps::before, .stage-steps::after { content: ""; position: absolute; left: 5px; top: 10px; bottom: 10px; width: 1px; }
.stage-steps::before { background: var(--hair-2); }
.stage-steps::after { background: var(--blue-soft); transform-origin: top; transform: scaleY(var(--action)); }
.stage-steps li { position: relative; display: flex; align-items: baseline; gap: 12px; padding: 7px 0; font-size: 14px; color: var(--text-3); transition: color var(--t-base); }
.stage-steps li::before { content: ""; position: absolute; left: -21px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; background: var(--ink-1); border: 1px solid var(--hair-3); transition: background var(--t-base), border-color var(--t-base), box-shadow var(--t-base); }
.stage-steps b { font: 500 11px/1 var(--mono); color: var(--text-4); }
.scene-track[data-step="0"] .stage-steps li:nth-child(1),
.scene-track[data-step="1"] .stage-steps li:nth-child(-n+2),
.scene-track[data-step="2"] .stage-steps li { color: var(--text-2); }
.scene-track[data-step="0"] .stage-steps li:nth-child(1)::before,
.scene-track[data-step="1"] .stage-steps li:nth-child(2)::before,
.scene-track[data-step="2"] .stage-steps li:nth-child(3)::before { background: var(--blue-soft); border-color: var(--blue-soft); box-shadow: 0 0 0 4px rgba(156, 193, 255, 0.16); }
.scene-track[data-step="0"] .stage-steps li:nth-child(1),
.scene-track[data-step="1"] .stage-steps li:nth-child(2),
.scene-track[data-step="2"] .stage-steps li:nth-child(3) { color: var(--text-1); }
.scene-track[data-step="1"] .stage-steps li:nth-child(1)::before,
.scene-track[data-step="2"] .stage-steps li:nth-child(-n+2)::before { background: var(--blue); border-color: var(--blue); }
.motion-reduced .stage-steps::after { transform: scaleY(1); }
.motion-reduced .stage-steps li { color: var(--text-2); }
@media (max-width: 900px) {
  .stage-steps { grid-template-columns: repeat(3, 1fr); padding: 14px 0 0; gap: 8px; }
  .stage-steps::before, .stage-steps::after { left: 0; right: 0; top: 0; bottom: auto; width: auto; height: 1px; }
  .stage-steps::after { transform-origin: left; transform: scaleX(var(--action)); }
  .stage-steps li { display: grid; gap: 4px; padding: 0; font-size: 13px; }
  .stage-steps li::before { left: 0; top: -14px; margin-top: -4px; }
}

/* Short phones (≤ 640px tall): the pinned stage and its controls must fit one screen. */
@media (max-width: 520px) and (max-height: 700px) {
  .stage-frame, .stage-frame.is-wide, .growth-stage .stage-frame { height: 42svh; min-height: 220px; }
  .work-panel .stage-steps, .growth-panel .stage-steps, .growth-note p { display: none; }
  .scene-tools .scene-state { display: none; }
  .work-modes button { padding: 10px 8px; }
  .network-bar { gap: 10px; margin-top: 10px; }
  .network-steps { display: none; }
}
@media (max-width: 520px) and (max-height: 700px) { .stage-caption { display: none; } }
