/* =========================================================
   Astral Studio · Creator Quest v2
   ========================================================= */

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #050010;
  color: #e8e3ff;
  font-family: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(120% 80% at 80% -10%, rgba(255, 58, 140, 0.18), transparent 60%),
    radial-gradient(100% 70% at 0% 100%, rgba(0, 231, 255, 0.16), transparent 60%),
    radial-gradient(70% 70% at 50% 110%, rgba(174, 90, 255, 0.18), transparent 70%),
    linear-gradient(180deg, #060018 0%, #0a0026 50%, #04001a 100%);
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== Cosmos canvas (Three.js) ===== */
#cosmos {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ===== Aurora bands ===== */
.aurora {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
  filter: blur(60px) saturate(140%);
  opacity: 0.55;
}
.aurora-band {
  position: absolute;
  inset: -10%;
  background: conic-gradient(from 200deg at 50% 50%, transparent 0deg, rgba(255, 58, 140, 0.45) 60deg, transparent 140deg, rgba(0, 231, 255, 0.45) 220deg, transparent 320deg);
  animation: aurora-spin 28s linear infinite;
  mix-blend-mode: screen;
}
.band-b { animation-duration: 42s; animation-direction: reverse; opacity: 0.6; transform: scale(1.2); }
.band-c { animation-duration: 60s; opacity: 0.4; transform: scale(0.8) translateY(20%); background: conic-gradient(from 30deg at 50% 50%, transparent 0deg, rgba(174, 90, 255, 0.5) 80deg, transparent 200deg, rgba(255, 200, 80, 0.4) 260deg, transparent 360deg); }
@keyframes aurora-spin { to { transform: rotate(360deg); } }

/* ===== Film grain ===== */
.grain {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.08;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' seed='7'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.7'/></svg>");
}

/* ===== Layout ===== */
.app {
  position: relative;
  z-index: 5;
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 36px) clamp(16px, 4vw, 48px) 80px;
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 3vw, 36px);
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ff3a8c 0%, #b026ff 50%, #00e7ff 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 12px 38px -12px rgba(255, 58, 140, 0.6), 0 0 0 1px rgba(255,255,255,0.1) inset;
  position: relative;
  isolation: isolate;
}
.brand-mark::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  background: linear-gradient(135deg, #ff3a8c, #00e7ff);
  filter: blur(14px);
  opacity: 0.7;
  z-index: -1;
}
.brand-mark svg {
  width: 22px;
  height: 22px;
  fill: #050010;
  filter: drop-shadow(0 0 4px rgba(0,0,0,0.4));
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand-text strong {
  font-family: "Orbitron", "Space Grotesk", sans-serif;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: linear-gradient(90deg, #fff, #ffd2e7 60%, #b3f0ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-text small {
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(232, 227, 255, 0.62);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.status-pill {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(255, 58, 140, 0.12);
  border: 1px solid rgba(255, 58, 140, 0.4);
  color: #ffb6d3;
  white-space: nowrap;
  position: relative;
}
.status-pill::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #ff3a8c;
  margin-right: 8px;
  vertical-align: middle;
  box-shadow: 0 0 12px #ff3a8c;
  animation: pulse-dot 1.6s ease-in-out infinite;
}
.status-pill.open {
  background: rgba(0, 231, 168, 0.12);
  border-color: rgba(0, 231, 168, 0.5);
  color: #9bffd9;
}
.status-pill.open::before { background: #00e7a8; box-shadow: 0 0 14px #00e7a8; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.8); } }

.ghost-button, .solid-button {
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 12px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.04);
  color: #e8e3ff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.18s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  text-decoration: none;
}
.ghost-button svg { width: 14px; height: 14px; color: currentColor; }
.ghost-button:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.3);
  transform: translateY(-1px);
}
.solid-button {
  background: linear-gradient(135deg, #ff3a8c 0%, #b026ff 60%, #00e7ff 120%);
  color: #07001a;
  border: none;
  padding: 12px 22px;
  font-weight: 700;
  box-shadow: 0 18px 42px -16px rgba(255, 58, 140, 0.6), 0 0 0 1px rgba(255,255,255,0.18) inset;
}
.solid-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 50px -14px rgba(255, 58, 140, 0.8), 0 0 0 1px rgba(255,255,255,0.3) inset;
}
.solid-button[disabled], .ghost-button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

/* ===== Hero ===== */
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 32px;
  align-items: center;
}
.hero-copy { max-width: 720px; }
.kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(232, 227, 255, 0.55);
  font-weight: 600;
}
.hero h1 {
  margin: 12px 0 16px;
  font-family: "Orbitron", "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 52px);
  line-height: 1.05;
  letter-spacing: -0.01em;
}
.hero .grad {
  background: linear-gradient(90deg, #ff8fc1, #b884ff 50%, #6becff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(176, 132, 255, 0.4);
}
.hero .lede {
  margin: 0;
  color: rgba(232, 227, 255, 0.75);
  font-size: clamp(14px, 1.4vw, 17px);
  max-width: 56ch;
  line-height: 1.55;
}

.hero-meter {
  display: flex;
  align-items: center;
  gap: 20px;
}
.orbit-ring {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
  background: radial-gradient(closest-side, rgba(176,132,255,0.18), transparent 70%);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 0 60px -10px rgba(176, 132, 255, 0.4) inset;
}
.orbit-core {
  position: absolute;
  inset: 38%;
  border-radius: 50%;
  background: radial-gradient(circle, #fff, #ff3a8c 40%, #b026ff 80%);
  box-shadow: 0 0 30px rgba(255, 58, 140, 0.7);
  animation: orbit-pulse 2.6s ease-in-out infinite;
}
@keyframes orbit-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(0.9); filter: hue-rotate(40deg); } }
.orbit-node {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.22);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  transition: background 0.4s ease, box-shadow 0.4s ease, border-color 0.4s ease;
}
.orbit-node[data-orbit="0"] { transform: translate(-50%, -50%) translateY(-58px); }
.orbit-node[data-orbit="1"] { transform: translate(-50%, -50%) translateX(58px); }
.orbit-node[data-orbit="2"] { transform: translate(-50%, -50%) translateY(58px); }
.orbit-node[data-orbit="3"] { transform: translate(-50%, -50%) translateX(-58px); }
.orbit-node.lit {
  background: linear-gradient(135deg, #ff3a8c, #00e7ff);
  border-color: transparent;
  box-shadow: 0 0 20px rgba(255, 58, 140, 0.85);
}
.hero-meter-text strong {
  display: block;
  font-family: "Orbitron", sans-serif;
  font-size: 28px;
  letter-spacing: 0.08em;
  margin-top: 4px;
  background: linear-gradient(90deg, #fff, #b3f0ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ===== Stage nav ===== */
.stage-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.stage-tab {
  position: relative;
  text-align: left;
  padding: 14px 16px 14px 18px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.12);
  background: linear-gradient(180deg, rgba(20,8,40,0.78), rgba(10,4,28,0.82));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: inherit;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  isolation: isolate;
}
.stage-tab::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,58,140,0.18), rgba(0,231,255,0.14));
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}
.stage-tab:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.22); }
.stage-tab.active { border-color: rgba(255, 58, 140, 0.7); box-shadow: 0 18px 50px -22px rgba(255, 58, 140, 0.6); }
.stage-tab.active::before { opacity: 1; }
.stage-tab.complete { border-color: rgba(0, 231, 168, 0.45); }
.stage-tab.complete .tab-rune { background: linear-gradient(135deg, #00e7a8, #00e7ff); color: #051a14; }
.stage-tab[disabled] { opacity: 0.45; cursor: not-allowed; }

.tab-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tab-rune {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.08);
  font-family: "Orbitron", sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.tab-state {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(232,227,255,0.6);
}
.stage-tab strong {
  font-family: "Orbitron", sans-serif;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ===== Quest shell ===== */
.quest-shell {
  position: relative;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(20,8,40,0.92), rgba(8,4,24,0.95));
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 50px 120px -50px rgba(0,0,0,0.8),
              0 0 0 1px rgba(255,255,255,0.04) inset,
              0 0 80px -40px rgba(176, 132, 255, 0.4) inset;
  overflow: hidden;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.quest-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 90% at 0% 0%, rgba(255, 58, 140, 0.12), transparent 60%),
    radial-gradient(60% 90% at 100% 100%, rgba(0, 231, 255, 0.12), transparent 60%);
  pointer-events: none;
}

.stage-layout {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 0;
  min-height: 520px;
}
.visual-panel {
  position: relative;
  padding: clamp(20px, 3vw, 36px);
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(255,255,255,0.06);
  overflow: hidden;
}
.control-panel {
  padding: clamp(20px, 3vw, 36px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}
.stage-title {
  margin: 6px 0 0;
  font-family: "Orbitron", sans-serif;
  font-size: clamp(22px, 2.5vw, 30px);
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #fff, #ffd2e7 60%, #b3f0ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stage-copy {
  margin: 0;
  color: rgba(232,227,255,0.75);
  line-height: 1.55;
}
.clue {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px dashed rgba(0, 231, 255, 0.35);
  background: rgba(0, 231, 255, 0.06);
  color: #cdf6ff;
  font-size: 13px;
  line-height: 1.5;
}
.complete-banner, .error-banner {
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 13px;
  letter-spacing: 0.04em;
  border: 1px solid;
}
.complete-banner {
  background: rgba(0, 231, 168, 0.1);
  border-color: rgba(0, 231, 168, 0.45);
  color: #b6ffe2;
}
.error-banner {
  background: rgba(255, 58, 140, 0.1);
  border-color: rgba(255, 58, 140, 0.5);
  color: #ffb8d2;
}

.shake { animation: shake 0.5s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  30%, 70% { transform: translateX(4px); }
  50% { transform: translateX(-4px); }
}

/* ===== Stage 1 — CTR Crystals ===== */
.crystal-stage {
  width: 100%;
  display: grid;
  place-items: center;
  perspective: 900px;
}
.crystal-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 460px;
}
.crystal-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  position: relative;
}
.crystal-col::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 100%;
  background: linear-gradient(180deg, transparent, rgba(255,255,255,0.18), transparent);
  transform: translate(-50%, -50%);
}
.crystal-half {
  display: grid;
  grid-template-columns: repeat(3, 18px);
  grid-auto-rows: 18px;
  gap: 4px;
  padding: 10px 8px;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
}
.crystal-half.bottom { transform: scaleY(-1); }
.crystal-pip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
}
.crystal-pip.lit {
  background: radial-gradient(circle, #fff 0%, #ff8fc1 30%, #b026ff 70%, transparent 95%);
  border-color: transparent;
  box-shadow: 0 0 12px rgba(255, 58, 140, 0.7);
  animation: pip-twinkle 3s ease-in-out infinite;
}
.crystal-col:nth-child(1) .crystal-pip.lit { background: radial-gradient(circle, #fff 0%, #ffd591 30%, #ff8038 70%, transparent 95%); box-shadow: 0 0 12px rgba(255, 128, 56, 0.7); }
.crystal-col:nth-child(2) .crystal-pip.lit { background: radial-gradient(circle, #fff 0%, #d3a8ff 30%, #b026ff 70%, transparent 95%); box-shadow: 0 0 12px rgba(176, 38, 255, 0.7); }
.crystal-col:nth-child(3) .crystal-pip.lit { background: radial-gradient(circle, #fff 0%, #ff8fc1 30%, #ff3a8c 70%, transparent 95%); box-shadow: 0 0 12px rgba(255, 58, 140, 0.7); }
.crystal-col:nth-child(4) .crystal-pip.lit { background: radial-gradient(circle, #fff 0%, #a3eaff 30%, #00b7ff 70%, transparent 95%); box-shadow: 0 0 12px rgba(0, 183, 255, 0.7); }
@keyframes pip-twinkle { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

.dials {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 4px;
}
.dial {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 8px;
}
.dial-button {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: #fff;
  border-radius: 10px;
  height: 36px;
  font-size: 18px;
  font-family: "Orbitron", sans-serif;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.dial-button:hover { background: rgba(255,255,255,0.12); }
.dial-button:active { transform: scale(0.93); }
.dial-readout {
  font-family: "Orbitron", sans-serif;
  font-size: 28px;
  text-align: center;
  padding: 6px 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  text-shadow: 0 0 20px rgba(255, 58, 140, 0.5);
}

/* ===== Stage 2 — Algorithm Maze ===== */
.maze-wrap {
  width: 100%;
  display: grid;
  place-items: center;
  perspective: 1100px;
}
.maze {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: 1fr;
  gap: 6px;
  width: min(420px, 90%);
  aspect-ratio: 1 / 1;
  padding: 12px;
  background: linear-gradient(135deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 22px;
  transform: rotateX(8deg);
  box-shadow: 0 30px 60px -30px rgba(0,0,0,0.7), 0 0 80px -30px rgba(0, 231, 255, 0.4) inset;
}
.maze-cell {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: "Orbitron", sans-serif;
  font-size: 18px;
  color: rgba(232,227,255,0.55);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}
.maze-cell.playable:hover { background: rgba(0, 231, 255, 0.08); color: #cdf6ff; transform: translateY(-2px); }
.maze-cell.path {
  background: linear-gradient(135deg, rgba(0, 231, 255, 0.22), rgba(176, 38, 255, 0.18));
  color: #fff;
  border-color: rgba(0, 231, 255, 0.5);
  box-shadow: 0 0 20px rgba(0, 231, 255, 0.3);
}
.maze-cell.current {
  background: linear-gradient(135deg, #00e7ff, #b026ff);
  color: #051022;
  border-color: transparent;
  box-shadow: 0 0 30px rgba(0, 231, 255, 0.7);
  animation: cell-pulse 1.4s ease-in-out infinite;
}
.maze-cell.bad {
  background: rgba(255, 58, 140, 0.3);
  color: #fff;
  border-color: rgba(255, 58, 140, 0.7);
  animation: shake 0.5s ease;
}
@keyframes cell-pulse { 0%,100% { box-shadow: 0 0 30px rgba(0, 231, 255, 0.7); } 50% { box-shadow: 0 0 50px rgba(0, 231, 255, 0.9); } }

.direction-tape {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
}
.tape-chip {
  font-family: "Orbitron", sans-serif;
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(232,227,255,0.7);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tape-chip svg { width: 12px; height: 12px; }
.tape-chip.active {
  background: linear-gradient(135deg, #ff3a8c, #00e7ff);
  color: #07001a;
  border-color: transparent;
}

/* ===== Stage 3 — Pulse Core ===== */
.pulse-stage {
  position: relative;
  width: 100%;
  display: grid;
  place-items: center;
}
.pulse-core {
  width: min(280px, 80%);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.1), transparent 60%),
    radial-gradient(circle at 50% 50%, rgba(176,38,255,0.4), rgba(8,4,24,0) 70%);
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 0 80px -10px rgba(176, 38, 255, 0.5);
  transition: filter 0.4s ease;
}
.pulse-core::before, .pulse-core::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  inset: -8%;
  animation: ring-spin 12s linear infinite;
}
.pulse-core::after { inset: -16%; animation-duration: 18s; animation-direction: reverse; border-color: rgba(255,255,255,0.06); }
@keyframes ring-spin { to { transform: rotate(360deg); } }
.pulse-core.active-cyan { box-shadow: 0 0 90px -5px #00e7ff; filter: hue-rotate(0deg); }
.pulse-core.active-amber { box-shadow: 0 0 90px -5px #ffb547; filter: hue-rotate(0deg); }
.pulse-core.active-rose { box-shadow: 0 0 90px -5px #ff3a8c; filter: hue-rotate(0deg); }
.pulse-core.active-green { box-shadow: 0 0 90px -5px #00e7a8; filter: hue-rotate(0deg); }
.pulse-glyph {
  font-family: "Orbitron", sans-serif;
  font-size: 56px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 30px rgba(255,255,255,0.5);
}
.tone-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.tone-button {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: #fff;
  border-radius: 16px;
  padding: 14px;
  font-family: "Orbitron", sans-serif;
  font-size: 13px;
  letter-spacing: 0.1em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  transition: transform 0.18s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.tone-button[disabled] { opacity: 0.5; cursor: wait; }
.tone-button:hover { transform: translateY(-2px); }
.tone-button .tone-aura {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}
.tone-button[data-tone="cyan"] .tone-aura { background: radial-gradient(circle, #fff, #00e7ff); box-shadow: 0 0 18px #00e7ff; }
.tone-button[data-tone="amber"] .tone-aura { background: radial-gradient(circle, #fff, #ffb547); box-shadow: 0 0 18px #ffb547; }
.tone-button[data-tone="rose"] .tone-aura { background: radial-gradient(circle, #fff, #ff3a8c); box-shadow: 0 0 18px #ff3a8c; }
.tone-button[data-tone="green"] .tone-aura { background: radial-gradient(circle, #fff, #00e7a8); box-shadow: 0 0 18px #00e7a8; }
.tone-button[data-tone="cyan"]:hover { border-color: #00e7ff; box-shadow: 0 16px 40px -16px #00e7ff; }
.tone-button[data-tone="amber"]:hover { border-color: #ffb547; box-shadow: 0 16px 40px -16px #ffb547; }
.tone-button[data-tone="rose"]:hover { border-color: #ff3a8c; box-shadow: 0 16px 40px -16px #ff3a8c; }
.tone-button[data-tone="green"]:hover { border-color: #00e7a8; box-shadow: 0 16px 40px -16px #00e7a8; }

.pips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  min-height: 44px;
  align-items: center;
}
.pip {
  width: 14px; height: 14px;
  border-radius: 50%;
  position: relative;
}
.pip.cyan { background: #00e7ff; box-shadow: 0 0 12px #00e7ff; }
.pip.amber { background: #ffb547; box-shadow: 0 0 12px #ffb547; }
.pip.rose { background: #ff3a8c; box-shadow: 0 0 12px #ff3a8c; }
.pip.green { background: #00e7a8; box-shadow: 0 0 12px #00e7a8; }
.pip-empty {
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: rgba(232,227,255,0.5);
}

/* ===== Stage 4 — Cipher ===== */
.cipher-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}
.cipher-wheel {
  width: min(360px, 90%);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
  background:
    conic-gradient(from 0deg, rgba(255,58,140,0.15), rgba(176,38,255,0.18), rgba(0,231,255,0.15), rgba(255,58,140,0.15));
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 0 80px -20px rgba(176, 38, 255, 0.5);
  animation: wheel-spin 90s linear infinite;
}
@keyframes wheel-spin { to { transform: rotate(360deg); } }
.cipher-readout {
  position: absolute;
  inset: 16% 12%;
  border-radius: 50%;
  background: rgba(8, 4, 24, 0.85);
  border: 1px solid rgba(255,255,255,0.1);
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  font-family: "Orbitron", sans-serif;
  font-size: clamp(13px, 1.6vw, 18px);
  letter-spacing: 0.16em;
  line-height: 1.4;
  color: #fff;
  text-shadow: 0 0 16px rgba(255, 58, 140, 0.4);
  animation: wheel-spin-counter 90s linear infinite;
}
@keyframes wheel-spin-counter { to { transform: rotate(-360deg); } }

.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}
.shift-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 20px;
  display: grid;
  place-items: center;
  padding: 0;
}
.range-row input[type="range"] {
  flex: 1;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff3a8c, #b026ff, #00e7ff);
  outline: none;
}
.range-row input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 58, 140, 0.3), 0 6px 16px -4px rgba(0,0,0,0.5);
  cursor: grab;
  border: none;
}
.range-row input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 58, 140, 0.3);
  cursor: grab;
  border: none;
}
.shift-value {
  font-family: "Orbitron", sans-serif;
  font-size: 18px;
  min-width: 40px;
  text-align: right;
}

.answer {
  margin-top: 4px;
  padding: 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(0, 231, 168, 0.18), rgba(0, 231, 255, 0.12));
  border: 1px solid rgba(0, 231, 168, 0.4);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.answer strong {
  font-family: "Orbitron", sans-serif;
  font-size: 22px;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, #fff, #b6ffe2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ===== Inventory ===== */
.inventory {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(20,8,40,0.78), rgba(10,4,28,0.82));
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.inventory-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.integrity {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(232,227,255,0.6);
}
.fragments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  font-family: "Orbitron", sans-serif;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  letter-spacing: 0.16em;
  color: #fff;
  position: relative;
  transition: all 0.3s ease;
}
.chip.lit {
  background: linear-gradient(135deg, rgba(255,58,140,0.3), rgba(0,231,255,0.3));
  border-color: rgba(255,255,255,0.3);
  box-shadow: 0 0 22px -6px rgba(255, 58, 140, 0.6);
}
.chip.locked { color: rgba(232,227,255,0.4); }

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(232,227,255,0.4);
  padding-top: 12px;
  flex-wrap: wrap;
}

/* ===== Portal overlay ===== */
.portal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 0, 16, 0.78);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}
.portal.show { display: flex; animation: portal-in 0.55s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes portal-in { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: scale(1); } }
.portal-ring {
  width: min(520px, 100%);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #ff3a8c, #b026ff, #00e7ff, #00e7a8, #ffb547, #ff3a8c);
  display: grid;
  place-items: center;
  animation: wheel-spin 14s linear infinite;
  box-shadow: 0 0 120px rgba(255, 58, 140, 0.5), 0 0 200px rgba(0, 231, 255, 0.3);
}
.portal-ring-inner {
  width: 92%;
  height: 92%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(20, 8, 40, 0.95), rgba(8, 4, 24, 1));
  display: grid;
  place-items: center;
  animation: wheel-spin-counter 14s linear infinite;
}
.portal-core {
  text-align: center;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  max-width: 80%;
}
.portal-kicker {
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: #b6ffe2;
}
.portal-core strong {
  font-family: "Orbitron", sans-serif;
  font-size: clamp(20px, 3vw, 30px);
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #fff, #ffd2e7 50%, #b3f0ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.portal-core p { margin: 0; color: rgba(232,227,255,0.8); font-size: 14px; }

/* ===== Mobile ===== */
@media (max-width: 880px) {
  .hero { grid-template-columns: 1fr; }
  .hero-meter { justify-self: start; }
  .stage-layout { grid-template-columns: 1fr; min-height: 0; }
  .visual-panel { border-right: none; border-bottom: 1px solid rgba(255,255,255,0.06); padding: 24px 20px; }
  .stage-nav { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-wrap: wrap; }
}

@media (max-width: 520px) {
  .app { padding: 14px 14px 80px; }
  .brand-text strong { font-size: 16px; }
  .brand-text small { font-size: 10px; }
  .hero h1 { font-size: 26px; }
  .stage-tab { padding: 12px; }
  .stage-tab strong { font-size: 12px; }
  .crystal-half { grid-template-columns: repeat(3, 14px); grid-auto-rows: 14px; gap: 3px; padding: 8px 6px; }
  .crystal-pip { width: 14px; height: 14px; }
  .dial-readout { font-size: 22px; }
  .dial-button { height: 32px; font-size: 16px; }
  .pulse-glyph { font-size: 42px; }
  .tone-grid { grid-template-columns: 1fr; }
  .foot { font-size: 10px; flex-direction: column; }
  .stage-nav { grid-template-columns: 1fr 1fr; }
}

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