/* =========================================================
   compute-box.tech — global theme + layout primitives
   ========================================================= */

:root {
  /* palette */
  --bg-0: #08121c;
  --bg-1: #0c1a2a;
  --bg-2: #13253a;
  --fg:   #a7e2ff;
  --fg-dim: #6c94b3;
  --accent: #5ed4ff;
  --accent-dim: #2a7aa0;
  --white: #ffffff;
  --warn:   #ff6a4a;

  /* type */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;

  /* motion */
  --beat: 1.6s;

  /* layout */
  --safe: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--fg);
  min-height: 100dvh;
  overflow: hidden;
  touch-action: none;
}

body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

/* ---------- stage root ---------- */
#stage-root {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

.stage {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  grid-template-rows: 1fr;
  opacity: 0;
  transition: opacity 600ms ease;
}
.stage.stage-active {
  display: grid;
  opacity: 1;
}
.stage.stage-entering { opacity: 0; }

/* ---------- HUD type ---------- */
.hud {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.label-safety {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--warn);
}

/* ---------- speaker toggle ---------- */
#speaker-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--fg-dim);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(94, 212, 255, 0.15);
  border-radius: 50%;
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
  z-index: 100;
}
#speaker-toggle:hover { color: var(--accent); border-color: var(--accent-dim); }
#speaker-toggle svg { width: 22px; height: 22px; }
#speaker-toggle .speaker-on { display: none; }
#speaker-toggle[aria-pressed="true"] .speaker-muted { display: none; }
#speaker-toggle[aria-pressed="true"] .speaker-on   { display: block; }
#speaker-toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* ---------- noscript fallback ---------- */
.noscript-fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg-0);
  color: var(--fg);
  font-family: var(--font-mono);
  text-align: center;
  padding: 2rem;
  z-index: 1000;
}
.noscript-fallback p { margin-top: 2rem; font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--fg-dim); }
.noscript-light {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px 4px rgba(94, 212, 255, 0.6);
  animation: blink-slow var(--beat) infinite;
}

@keyframes blink-slow {
  0%, 46% { opacity: 1; }
  50%, 96% { opacity: 0.08; }
  100%    { opacity: 1; }
}

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

/* ---------- small screen safety ---------- */
@media (max-width: 319px), (max-height: 479px) {
  #stage-root::after {
    content: "please rotate or resize.";
    position: fixed; inset: 0; display: grid; place-items: center;
    background: var(--bg-0); color: var(--fg-dim);
    font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase;
    z-index: 2000;
  }
}

/* ========================= stage 1 — dormancy ========================= */
.s1-room {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.s1-light {
  position: absolute;
  top: 18%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow:
    0 0 18px 4px rgba(94, 212, 255, 0.55),
    0 0 40px 10px rgba(94, 212, 255, 0.15);
  animation: blink-slow var(--beat) infinite;
}

.s1-handle-wrap {
  position: absolute;
  bottom: 16%;
  display: grid;
  place-items: center;
  gap: 14px;
  opacity: 0;
  transition: opacity 400ms ease;
  animation: handle-pulse var(--beat) infinite;
}
.s1-handle-wrap[data-state="armed"],
.s1-handle-wrap[data-state="pulled"] {
  opacity: 1;
  animation: none;
}

@keyframes handle-pulse {
  0%, 46%, 100% { opacity: 0.22; }
  50%, 96%      { opacity: 0.02; }
}

.s1-handle-btn {
  display: grid;
  place-items: center;
  gap: 10px;
  cursor: grab;
  touch-action: none;
}
.s1-handle-btn:active { cursor: grabbing; }

.s1-handle {
  width: 60px;
  height: 120px;
  transition: transform 350ms cubic-bezier(.2,.8,.2,1);
  will-change: transform;
}
.s1-handle-wrap[data-state="armed"] .s1-handle {
  transition: none; /* JS drives it while dragging */
}

.s1-label {
  font-size: 11px;
}

.s1-reenter {
  position: absolute;
  top: calc(50% + 120px);
  font-size: 11px;
  color: var(--fg-dim);
  opacity: 0.5;
  transition: opacity 200ms;
  padding: 8px 14px;
  border: 1px solid rgba(94, 212, 255, 0.15);
  border-radius: 999px;
}
.s1-reenter:hover, .s1-reenter:focus-visible { opacity: 1; color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .s1-handle-wrap { opacity: 0.6 !important; animation: none !important; }
  .s1-light       { animation: none !important; opacity: 0.9; }
}

/* ========================= stage 2 — hatch ========================= */
.s2-scene {
  position: relative;
  width: min(70vmin, 520px);
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}
.s2-iris { width: 100%; height: 100%; }
.s2-blade {
  transform-origin: 100px 100px;
  transition: transform 2000ms cubic-bezier(.2,.8,.2,1),
              opacity 1000ms ease;
  opacity: 1;
}
.s2-open .s2-blade:nth-child(1) { transform: rotate(0deg)   translate(-36px, -36px) scale(1.2); opacity: 0; }
.s2-open .s2-blade:nth-child(2) { transform: rotate(60deg)  translate(-36px, -36px) scale(1.2); opacity: 0; }
.s2-open .s2-blade:nth-child(3) { transform: rotate(120deg) translate(-36px, -36px) scale(1.2); opacity: 0; }
.s2-open .s2-blade:nth-child(4) { transform: rotate(180deg) translate(-36px, -36px) scale(1.2); opacity: 0; }
.s2-open .s2-blade:nth-child(5) { transform: rotate(240deg) translate(-36px, -36px) scale(1.2); opacity: 0; }
.s2-open .s2-blade:nth-child(6) { transform: rotate(300deg) translate(-36px, -36px) scale(1.2); opacity: 0; }

.s2-enter {
  position: absolute;
  bottom: -48px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  color: var(--accent);
  letter-spacing: 0.25em;
  opacity: 0;
  transition: opacity 600ms ease 1500ms;
}
.s2-scene.s2-open .s2-enter { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .s2-blade { transition: opacity 400ms ease !important; }
  .s2-open .s2-blade { opacity: 0 !important; transform: none !important; }
  .s2-enter { transition: opacity 300ms ease !important; }
}

/* ========================= stage 3 — tunnel ========================= */
.s3-scene {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, #0c1a2a 0%, #03070d 70%);
}
.s3-rings {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  perspective: 600px;
}
.s3-ring {
  --shift: 0;
  position: absolute;
  width: 120vmin;
  height: 120vmin;
  border-radius: 50%;
  border: 1px solid rgba(94, 212, 255, calc(0.05 + var(--shift) * 0.5));
  transform: scale(calc(0.05 + var(--shift) * 1.6));
  opacity: 0;
  box-shadow: 0 0 20px rgba(94, 212, 255, calc(var(--shift) * 0.1));
}
.s3-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(0,0,0,0.85) 100%);
}

.s3-meter {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: min(60vw, 360px);
}
.s3-meter-bar {
  height: 2px;
  background: var(--accent);
  width: 0%;
  transition: width 80ms linear;
  box-shadow: 0 0 6px rgba(94, 212, 255, 0.6);
}
.s3-meter-label {
  display: block;
  text-align: center;
  margin-top: 6px;
  color: var(--fg-dim);
}

.s3-advance {
  position: absolute;
  bottom: 14%;
  padding: 14px 32px;
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  color: var(--accent);
  letter-spacing: 0.3em;
  font-size: 12px;
  touch-action: none;
  transition: transform 120ms, box-shadow 120ms;
}
.s3-advance:hover { box-shadow: 0 0 16px rgba(94, 212, 255, 0.3); }
.s3-advance:active { transform: scale(0.98); }

.s3-flash {
  animation: s3-flash 650ms ease forwards;
}
@keyframes s3-flash {
  0%   { background: var(--bg-0); }
  30%  { background: #ffffff; }
  60%  { background: #5ed4ff; }
  100% { background: var(--bg-0); }
}

@media (prefers-reduced-motion: reduce) {
  .s3-rings { display: none; }
  .s3-scene { background: radial-gradient(ellipse at center, #13253a 0%, #030913 100%); }
  .s3-flash { animation: none; background: var(--bg-1) !important; }
}

/* ========================= stage 4 — console ========================= */
.s4-scene {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center top, #13253a 0%, #03070d 90%);
  overflow: hidden;
}

.s4-console {
  display: grid;
  place-items: center;
  gap: 28px;
  padding: 32px;
  background: linear-gradient(180deg, #0c1a2a 0%, #07111c 100%);
  border: 1px solid #1e3855;
  border-radius: 14px;
  box-shadow:
    inset 0 1px 0 rgba(94, 212, 255, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.5);
  min-width: min(80vw, 360px);
}

.s4-indicators {
  display: flex;
  gap: 18px;
}
.s4-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #0c1a2a;
  border: 1px solid #2a4b6b;
  transition: background 350ms, box-shadow 350ms, border-color 350ms;
}
.s4-dot.s4-dot-lit {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(94, 212, 255, 0.75);
}

.s4-dial-wrap {
  width: min(55vmin, 260px);
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}
.s4-dial {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  touch-action: none;
  cursor: grab;
}
.s4-dial:active { cursor: grabbing; }
.s4-dial svg { width: 100%; height: 100%; }
.s4-dial-rotor {
  transform-origin: 100px 100px;
  transform: rotate(0deg);
  will-change: transform;
}

.s4-hud {
  color: var(--fg-dim);
  font-size: 11px;
  letter-spacing: 0.2em;
}

.s4-boot {
  animation: s4-boot 1400ms ease forwards;
}
@keyframes s4-boot {
  0%   { filter: brightness(1); }
  50%  { filter: brightness(1.3); }
  100% { filter: brightness(0.4); }
}

@media (prefers-reduced-motion: reduce) {
  .s4-boot { animation: none !important; }
}

/* ========================= stage 5 — awakening ========================= */
.s5-scene {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 6vmin;
  gap: 16px;
  background: #030913;
}

.s5-term {
  font-family: var(--font-mono);
  font-size: clamp(13px, 1.8vmin, 16px);
  color: var(--accent);
  line-height: 1.55;
  white-space: pre;
  overflow: hidden;
  text-shadow: 0 0 6px rgba(94, 212, 255, 0.25);
  padding: 16px;
  border: 1px solid rgba(94, 212, 255, 0.15);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
}

.s5-line {
  opacity: 0.95;
}

.s5-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px;
}
.s5-share {
  padding: 10px 18px;
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  color: var(--accent);
  letter-spacing: 0.2em;
  font-size: 12px;
  transition: box-shadow 150ms, background 150ms;
}
.s5-share:hover { box-shadow: 0 0 14px rgba(94, 212, 255, 0.35); background: rgba(94, 212, 255, 0.05); }
.s5-share-status { color: var(--fg-dim); font-size: 11px; letter-spacing: 0.15em; }

@media (prefers-reduced-motion: reduce) {
  .s5-term { text-shadow: none; }
}
