:root {
  --plum: #160B2E;
  --gold: #FFE45E;
  --mint: #3FF6C8;
  --pink: #FF5DA2;
  --violet: #7A5CFF;
  --orange: #FF8A3D;
  --cream: #FFF4D6;
  --shadow: rgba(0, 0, 0, 0.36);
  --display: "Bungee Shade", "Arial Black", Impact, system-ui, sans-serif;
  --chunk: "Unbounded", "Trebuchet MS", system-ui, sans-serif;
  --body: "Nunito Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --pixel: "Press Start 2P", "Courier New", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--cream);
  font-family: var(--body);
  background:
    radial-gradient(circle at 20% 8%, rgba(122, 92, 255, 0.42), transparent 30vw),
    radial-gradient(circle at 84% 34%, rgba(255, 93, 162, 0.32), transparent 28vw),
    radial-gradient(circle at 40% 76%, rgba(63, 246, 200, 0.22), transparent 32vw),
    var(--plum);
  overflow-x: hidden;
}

.stage-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.52;
  background-image:
    linear-gradient(30deg, rgba(255, 244, 214, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(255, 244, 214, 0.05) 87.5%),
    linear-gradient(150deg, rgba(255, 244, 214, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(255, 244, 214, 0.05) 87.5%),
    linear-gradient(30deg, rgba(255, 244, 214, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(255, 244, 214, 0.05) 87.5%),
    linear-gradient(150deg, rgba(255, 244, 214, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(255, 244, 214, 0.05) 87.5%);
  background-size: 82px 142px;
  background-position: 0 0, 0 0, 41px 71px, 41px 71px;
  transform: skewY(-7deg) scale(1.08);
}

.particle-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: var(--gold);
  box-shadow: 0 0 14px currentColor;
  animation: drift 4.8s linear infinite;
}

.quest-hud {
  position: fixed;
  z-index: 20;
  top: 18px;
  left: 22px;
  right: 22px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  pointer-events: none;
}

.hud-brand {
  font-family: var(--pixel);
  font-size: clamp(9px, 1vw, 12px);
  letter-spacing: 0.08em;
  color: var(--gold);
  background: rgba(22, 11, 46, 0.8);
  border: 2px solid rgba(255, 228, 94, 0.54);
  box-shadow: 0 9px 0 rgba(0, 0, 0, 0.22), inset 0 0 18px rgba(255, 228, 94, 0.11);
  padding: 14px 16px;
  border-radius: 16px;
}

.lane-ledger { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.lane-chip {
  pointer-events: auto;
  text-decoration: none;
  color: var(--cream);
  font-family: var(--chunk);
  font-weight: 900;
  font-size: 12px;
  padding: 10px 12px;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: rgba(22, 11, 46, 0.72);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.22);
  transition: transform 180ms ease, background 180ms ease;
}

.lane-chip:hover { transform: translateY(-4px) rotate(-2deg) scale(1.04); background: rgba(255, 244, 214, 0.12); }
.lane-chip.mint { color: var(--mint); }
.lane-chip.pink { color: var(--pink); }
.lane-chip.orange { color: var(--orange); }
.lane-chip.violet { color: var(--violet); }

.quest-board {
  position: relative;
  z-index: 1;
  min-height: 620vh;
  isolation: isolate;
}

.route-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  filter: drop-shadow(0 12px 0 rgba(0,0,0,0.28));
}

.route {
  fill: none;
  stroke-width: 18;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 5 28;
  animation: routeMarch 1.8s linear infinite;
}

.route-scout { stroke: var(--mint); }
.route-mage { stroke: var(--pink); animation-duration: 1.55s; }
.route-tinker { stroke: var(--orange); animation-duration: 2.1s; }
.route-echo { stroke: var(--violet); animation-duration: 1.35s; opacity: 0.8; }

.pawn {
  position: fixed;
  z-index: 12;
  width: clamp(34px, 4.2vw, 58px);
  height: clamp(34px, 4.2vw, 58px);
  border-radius: 50% 50% 45% 45%;
  display: grid;
  place-items: center;
  font-family: var(--chunk);
  font-weight: 1000;
  box-shadow: 0 16px 0 rgba(0,0,0,0.24), inset -8px -9px 0 rgba(0,0,0,0.16), 0 0 26px currentColor;
  transform: translate(-50%, -50%);
  transition: filter 220ms ease;
}

.pawn::after {
  content: "";
  position: absolute;
  bottom: -17px;
  width: 70%;
  height: 14px;
  border-radius: 50%;
  background: rgba(0,0,0,0.34);
  filter: blur(2px);
}

.pawn span { position: relative; z-index: 1; color: var(--plum); }
.scout-pawn { color: var(--mint); background: var(--mint); }
.mage-pawn { color: var(--pink); background: var(--pink); }
.tinker-pawn { color: var(--orange); background: var(--orange); }
.echo-pawn { color: var(--violet); background: var(--violet); }
.echo-ghost { z-index: 10; background: transparent; border: 2px solid var(--violet); color: var(--violet); opacity: 0.38; box-shadow: 0 12px 0 rgba(0,0,0,0.12), 0 0 22px var(--violet); }

.scene {
  position: relative;
  min-height: 100vh;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 7rem clamp(18px, 5vw, 80px);
}

.hero-scene { min-height: 112vh; overflow: hidden; }

.corner-trail {
  position: absolute;
  width: 26vw;
  height: 11px;
  border-radius: 999px;
  border: 3px dashed currentColor;
  opacity: 0.65;
  animation: trailEnter 1.8s ease both;
}
.trail-a { color: var(--mint); top: 16%; left: -4vw; transform: rotate(32deg); }
.trail-b { color: var(--pink); top: 18%; right: -6vw; transform: rotate(146deg); animation-delay: .15s; }
.trail-c { color: var(--orange); bottom: 16%; left: -5vw; transform: rotate(-24deg); animation-delay: .3s; }
.trail-d { color: var(--violet); bottom: 20%; right: -6vw; transform: rotate(205deg); animation-delay: .45s; }

.title-carving {
  position: relative;
  z-index: 5;
  text-align: center;
  padding: clamp(24px, 5vw, 58px);
  border-radius: 38px;
  border: 4px solid rgba(255, 228, 94, 0.66);
  background: linear-gradient(145deg, rgba(255, 244, 214, 0.11), rgba(122, 92, 255, 0.16));
  box-shadow: 0 26px 0 rgba(0,0,0,0.24), inset 0 0 80px rgba(255, 228, 94, 0.1);
  transform: perspective(900px) rotateX(5deg) rotateZ(-1deg);
}

.pixel-kicker, .spell-caption, .room-label, .checkpoint-flag, .item {
  font-family: var(--pixel);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pixel-kicker { color: var(--gold); font-size: clamp(9px, 1vw, 13px); }

h1 {
  margin: 0.08em 0 0.1em;
  font-family: var(--display);
  font-size: clamp(4.5rem, 16vw, 15rem);
  line-height: 0.82;
  color: var(--gold);
  letter-spacing: -0.08em;
  text-shadow: 8px 10px 0 var(--violet), -5px -4px 0 var(--pink), 0 0 38px rgba(255, 228, 94, 0.42);
}

.subtitle-scroll {
  max-width: 680px;
  margin: 0 auto;
  font-family: var(--chunk);
  font-weight: 900;
  font-size: clamp(1rem, 2.2vw, 1.65rem);
  color: var(--cream);
}

.initiative-wheel {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  width: clamp(280px, 45vw, 610px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  opacity: 0.62;
  animation: spinCenteredWheel 18s linear infinite;
}

.wheel-ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 18px solid rgba(255, 228, 94, 0.34);
  outline: 4px dashed rgba(255, 244, 214, 0.22);
  outline-offset: -34px;
  background: conic-gradient(from 10deg, rgba(63,246,200,.55), rgba(255,93,162,.55), rgba(255,138,61,.55), rgba(122,92,255,.55), rgba(63,246,200,.55));
}

.wheel-label {
  position: absolute;
  inset: 36%;
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 50%;
  background: var(--plum);
  color: var(--gold);
  font-family: var(--chunk);
  font-weight: 1000;
}

.wheel-slot { position: absolute; font-family: var(--pixel); font-size: 10px; color: var(--cream); }
.slot-1 { top: 8%; left: 44%; } .slot-2 { right: 6%; top: 48%; } .slot-3 { bottom: 8%; left: 40%; } .slot-4 { left: 5%; top: 48%; }

.inventory-strip {
  position: absolute;
  bottom: 8vh;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.item {
  font-size: 10px;
  color: var(--plum);
  padding: 14px 16px;
  border-radius: 18px 18px 24px 24px;
  box-shadow: 0 11px 0 rgba(0,0,0,0.24), inset -6px -6px 0 rgba(0,0,0,0.13);
  cursor: pointer;
  transition: transform 170ms ease;
}
.item:hover { transform: translateY(-8px) rotate(5deg) scale(1.08); }
.bead-mint { background: var(--mint); } .bead-pink { background: var(--pink); } .bead-orange { background: var(--orange); } .bead-violet { background: var(--violet); }

.encounter { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 8vw, 110px); align-items: center; }

.room {
  max-width: 520px;
  padding: clamp(24px, 4vw, 46px);
  border-radius: 30px;
  border: 4px solid currentColor;
  color: var(--gold);
  background:
    linear-gradient(135deg, rgba(255,244,214,0.16), rgba(22,11,46,0.82)),
    repeating-linear-gradient(45deg, rgba(255,244,214,.04) 0 14px, transparent 14px 28px);
  box-shadow: 18px 26px 0 rgba(0,0,0,0.28), inset 0 0 60px rgba(255,244,214,0.06);
  transform: perspective(900px) rotateX(7deg) rotateY(var(--tilt, -5deg));
}

.room-right { justify-self: end; --tilt: 5deg; }
.room-left { justify-self: start; }
.mint-room { color: var(--mint); } .pink-room { color: var(--pink); } .orange-room { color: var(--orange); } .violet-room { color: var(--violet); }

.room h2, .final-banner h2 {
  font-family: var(--display);
  color: var(--gold);
  font-size: clamp(2.2rem, 6vw, 5.4rem);
  line-height: 0.9;
  margin: 0.18em 0;
  text-shadow: 4px 5px 0 var(--plum), 0 0 22px currentColor;
}

.room p, .final-banner p {
  color: var(--cream);
  font-size: clamp(1rem, 1.5vw, 1.24rem);
  line-height: 1.55;
  font-weight: 800;
}

.room-label { font-size: 10px; color: currentColor; }

.socket-lock {
  margin-top: 24px;
  width: min(100%, 300px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(22,11,46,0.7);
  border: 2px solid rgba(255,244,214,0.18);
}

.socket-lock i, .final-locks i {
  display: block;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255,244,214,0.14);
  border: 3px solid currentColor;
  box-shadow: inset 0 0 18px rgba(0,0,0,0.4);
}
.socket-lock.synced i, .final-locks.synced i { animation: socketFill 1s ease both; }
.socket-lock.synced i:nth-child(2), .final-locks.synced i:nth-child(2) { animation-delay: .15s; }
.socket-lock.synced i:nth-child(3), .final-locks.synced i:nth-child(3) { animation-delay: .3s; }
.socket-lock.synced i:nth-child(4), .final-locks.synced i:nth-child(4) { animation-delay: .45s; }

.route-plaque {
  justify-self: center;
  max-width: 500px;
  padding: 22px;
  border-radius: 18px;
  border: 3px dashed var(--gold);
  background: var(--cream);
  color: var(--plum);
  font-family: var(--chunk);
  font-weight: 1000;
  box-shadow: 14px 18px 0 rgba(0,0,0,0.24);
  transform: rotate(2deg);
}

.forked-labyrinth {
  display: grid;
  grid-template-columns: repeat(3, clamp(70px, 10vw, 130px));
  gap: 10px;
  transform: perspective(700px) rotateX(58deg) rotateZ(-36deg);
}
.tile {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 3px solid rgba(255,244,214,.25);
  border-radius: 18px;
  font-family: var(--chunk);
  font-size: 2rem;
  box-shadow: 10px 14px 0 rgba(0,0,0,.3);
  animation: tileBlink 3s ease-in-out infinite;
}
.dark-tile { background: rgba(22,11,46,.78); } .arrow-tile { background: var(--cream); color: var(--plum); } .pink-tile { background: var(--pink); color: var(--plum); } .gold-tile { background: var(--gold); color: var(--plum); } .violet-tile { background: var(--violet); } .orange-tile { background: var(--orange); color: var(--plum); } .mint-tile { background: var(--mint); color: var(--plum); }
.spell-caption { display: inline-block; margin-top: 16px; color: var(--pink); font-size: 10px; border-bottom: 4px dotted currentColor; }

.bridge-machine {
  width: min(88vw, 620px);
  height: 190px;
  display: grid;
  grid-template-columns: 60px 1fr 1fr 60px;
  align-items: center;
  filter: drop-shadow(0 20px 0 rgba(0,0,0,.25));
}
.hinge { height: 110px; border-radius: 20px; background: var(--gold); border: 5px solid var(--orange); }
.bridge-leaf { height: 112px; border: 5px solid var(--orange); background: repeating-linear-gradient(90deg, #FFE45E 0 28px, #FF8A3D 28px 36px); transform-origin: center; transition: transform 900ms cubic-bezier(.17,.84,.31,1.28); }
.leaf-left { border-radius: 26px 8px 8px 26px; transform-origin: left center; }
.leaf-right { border-radius: 8px 26px 26px 8px; transform-origin: right center; }
.bridge-machine.lowered .leaf-left { transform: rotateZ(7deg) translateY(12px); }
.bridge-machine.lowered .leaf-right { transform: rotateZ(-7deg) translateY(12px); }
.gear-row { display: flex; gap: 12px; margin-top: 20px; }
.gear-row b { width: 46px; aspect-ratio: 1; border-radius: 50%; background: conic-gradient(var(--orange) 0 15%, transparent 15% 25%, var(--orange) 25% 40%, transparent 40% 50%, var(--orange) 50% 65%, transparent 65% 75%, var(--orange) 75% 90%, transparent 90%); animation: spinWheel 4s linear infinite; }

.hourglass-stack { display: grid; gap: 22px; place-items: center; }
.hourglass {
  width: 150px;
  height: 220px;
  position: relative;
  border-top: 16px solid var(--gold);
  border-bottom: 16px solid var(--gold);
  filter: drop-shadow(0 16px 0 rgba(0,0,0,.25));
}
.hourglass::before, .hourglass::after { content: ""; position: absolute; left: 22px; right: 22px; height: 88px; border: 8px solid var(--violet); background: linear-gradient(var(--gold), transparent 58%); }
.hourglass::before { top: 4px; clip-path: polygon(0 0,100% 0,50% 100%); }
.hourglass::after { bottom: 4px; clip-path: polygon(50% 0,100% 100%,0 100%); transform: rotate(180deg); animation: sandPulse 2.6s ease-in-out infinite; }
.checkpoint-flag { color: var(--plum); background: var(--mint); padding: 16px 20px; border-radius: 8px 24px 24px 8px; box-shadow: 10px 12px 0 rgba(0,0,0,.25); }
.echo-runes { display: flex; gap: 8px; margin-top: 18px; }
.echo-runes span { font-family: var(--pixel); font-size: 10px; color: var(--plum); background: var(--violet); padding: 10px; border-radius: 10px; animation: echoPulse 1.8s ease infinite; }

.convergence { min-height: 118vh; grid-template-columns: 1fr 1fr; gap: clamp(26px, 8vw, 110px); }
.final-door { position: relative; width: min(76vw, 480px); aspect-ratio: 1; display: grid; place-items: center; }
.seal-ring { position: absolute; inset: 0; border-radius: 50%; border: 18px dotted var(--gold); animation: spinWheel 9s linear infinite reverse; box-shadow: 0 0 80px rgba(255,228,94,.3); }
.seal-dot { width: 42%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, var(--cream), var(--gold) 38%, var(--pink) 39%, var(--violet) 72%); box-shadow: 0 0 70px var(--gold), 0 24px 0 rgba(0,0,0,.25); }
.final-locks { position: absolute; inset: 18%; display: grid; grid-template-columns: repeat(2, 1fr); gap: 44%; color: var(--gold); }
.final-banner { max-width: 540px; padding: clamp(24px, 5vw, 54px); border-radius: 36px; background: var(--cream); color: var(--plum); border: 5px solid var(--gold); box-shadow: 20px 26px 0 rgba(0,0,0,.28); transform: rotate(-2deg); }
.final-banner p { color: var(--plum); }
.final-banner strong { display: block; font-family: var(--display); font-size: clamp(3rem, 8vw, 7rem); color: var(--violet); line-height: .85; text-shadow: 4px 5px 0 var(--pink); }

.scene.in-view .room, .scene.in-view .route-plaque, .scene.in-view .forked-labyrinth, .scene.in-view .hourglass-stack, .scene.in-view .final-banner { animation: bounceArrive 650ms cubic-bezier(.18,.89,.32,1.28) both; }

@keyframes routeMarch { to { stroke-dashoffset: -33; } }
@keyframes spinWheel { to { transform: rotate(360deg); } }
@keyframes spinCenteredWheel { to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes drift { 0% { transform: translateY(0) rotate(0); opacity: 0; } 15%, 80% { opacity: .8; } 100% { transform: translateY(-120px) rotate(220deg); opacity: 0; } }
@keyframes trailEnter { from { opacity: 0; scale: .2; } to { opacity: .65; scale: 1; } }
@keyframes socketFill { to { background: var(--gold); box-shadow: 0 0 24px var(--gold), inset 0 0 8px rgba(255,255,255,.4); transform: scale(1.08); } }
@keyframes tileBlink { 50% { transform: translateY(-8px); filter: brightness(1.2); } }
@keyframes sandPulse { 50% { filter: hue-rotate(70deg); } }
@keyframes echoPulse { 50% { opacity: .45; transform: translateX(8px); } }
@keyframes bounceArrive { from { opacity: 0; transform: translateY(60px) scale(.86) rotate(-4deg); } to { opacity: 1; } }

@media (max-width: 820px) {
  .quest-hud { align-items: flex-start; }
  .lane-ledger { max-width: 210px; }
  .encounter, .convergence { grid-template-columns: 1fr; }
  .room, .room-right, .room-left { justify-self: center; transform: none; }
  .forked-labyrinth { transform: perspective(700px) rotateX(50deg) rotateZ(-28deg) scale(.82); }
  .route { stroke-width: 12; }
}
