:root {
  --accent: #ffc857;
  --accent2: #2a9d8f;
  --bg: #0a0818;
  --fg: #f4e4bc;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  cursor: default;
}

/* On touch devices: stop the browser from hijacking drags as scroll/zoom
   and kill the tap-highlight flash on our custom controls. */
body.touch {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hidden { display: none !important; }

/* ------------------------- Start prompt ------------------------- */
/* The 3D cosmos is already live behind this; one click is only
   needed to satisfy the browser's audio + pointer-lock gesture. */
#start-prompt {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(4, 6, 13, 0.15), rgba(4, 6, 13, 0.55) 80%);
  transition: opacity 0.9s ease;
}
#start-prompt.fade { opacity: 0; }

.sp-inner {
  text-align: center;
  padding: 2rem;
}

.sp-title {
  font-size: clamp(2.6rem, 10vw, 6rem);
  font-weight: 700;
  letter-spacing: 0.45rem;
  line-height: 1;
  position: relative;
  color: var(--fg);
  text-shadow: 0 0 36px rgba(122, 247, 255, 0.55);
}
/* Very slight cyber chromatic-split: two faint colored ghosts that
   only flicker for a few frames now and then — no harsh stutter. */
.sp-title::before, .sp-title::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0.22;
  mix-blend-mode: screen;
  pointer-events: none;
}
.sp-title::before { color: var(--accent); animation: glitch 9s infinite; left: 1px; }
.sp-title::after { color: var(--accent2); animation: glitch 11s infinite reverse; left: -1px; }
@keyframes glitch {
  0%, 96%, 100% { clip-path: inset(0 0 100% 0); transform: translateX(0); opacity: 0.22; }
  97% { clip-path: inset(30% 0 55% 0); transform: translateX(-0.8px); opacity: 0.35; }
  98% { clip-path: inset(60% 0 28% 0); transform: translateX(0.8px); opacity: 0.3; }
  99% { clip-path: inset(42% 0 40% 0); transform: translateX(-0.5px); opacity: 0.28; }
}

.loading {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  letter-spacing: 0.2rem;
  color: rgba(122, 247, 255, 0.6);
  margin: 1.2rem 0;
  min-height: 1.2em;
}
.loading.done { color: rgba(199, 125, 255, 0.85); }

.sp-cue {
  pointer-events: auto;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.32rem;
  color: var(--bg);
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  border: none;
  padding: 0.9rem 2.4rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.25s;
  box-shadow: 0 0 40px rgba(122, 247, 255, 0.4);
  animation: cuePulse 2.2s ease-in-out infinite;
}
.sp-cue:hover:not(:disabled) { transform: scale(1.06); box-shadow: 0 0 60px rgba(199, 125, 255, 0.6); }
.sp-cue:disabled { opacity: 0.4; cursor: progress; animation: none; }
@keyframes cuePulse {
  0%, 100% { box-shadow: 0 0 36px rgba(122, 247, 255, 0.35); }
  50% { box-shadow: 0 0 64px rgba(199, 125, 255, 0.6); }
}

.sp-controls {
  margin-top: 1.6rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.16rem;
  color: rgba(232, 247, 255, 0.5);
}

.enter-btn {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.3rem;
  color: var(--bg);
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  border: none;
  padding: 1rem 2.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.25s;
  box-shadow: 0 0 40px rgba(122, 247, 255, 0.35);
}
.enter-btn:hover:not(:disabled) { transform: scale(1.05); box-shadow: 0 0 60px rgba(199, 125, 255, 0.55); }
.enter-btn:disabled { opacity: 0.35; cursor: progress; }

.controls-legend {
  margin-top: 2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.4rem;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: rgba(232, 247, 255, 0.45);
}
.controls-legend b { color: var(--accent); font-weight: 500; }

/* ----------------------------- HUD ----------------------------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

#nowplaying {
  position: absolute;
  left: 2.2rem;
  bottom: 2.2rem;
  min-width: 240px;
}
.np-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.3rem;
  color: var(--accent);
  opacity: 0.7;
}
.np-title {
  font-size: 1.45rem;
  font-weight: 500;
  margin: 0.2rem 0 0.6rem;
  text-shadow: 0 0 18px rgba(122, 247, 255, 0.4);
  transition: opacity 0.4s;
}
.np-meter {
  width: 200px;
  height: 3px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
}
#np-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  box-shadow: 0 0 12px var(--accent);
  transition: width 0.1s linear;
}

#compass {
  position: absolute;
  top: 2rem;
  right: 2rem;
  width: 152px;
  height: 152px;
  border: 1px solid rgba(122, 247, 255, 0.28);
  border-radius: 50%;
  box-shadow: 0 0 24px rgba(4, 6, 13, 0.65), inset 0 0 18px rgba(122, 247, 255, 0.06);
  overflow: hidden;
  background: rgba(4, 6, 13, 0.55);
}
#nav-map {
  display: block;
  width: 100%;
  height: 100%;
}

.hint {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.18rem;
  color: rgba(232, 247, 255, 0.4);
  white-space: nowrap;
}

/* Crosshair */
#crosshair {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  width: 22px; height: 22px;
  pointer-events: none;
}
#crosshair span {
  position: absolute;
  background: rgba(122, 247, 255, 0.6);
}
#crosshair span:first-child { top: 50%; left: 0; width: 100%; height: 1px; transform: translateY(-50%); }
#crosshair span:last-child { left: 50%; top: 0; height: 100%; width: 1px; transform: translateX(-50%); }

/* Paused */
.paused-overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6rem;
  background: rgba(4, 6, 13, 0.78);
  backdrop-filter: blur(6px);
}
.paused-overlay p {
  font-size: 2rem;
  letter-spacing: 0.6rem;
  color: var(--accent);
}

/* ------------------------- Touch controls ------------------------- */
/* Full-screen invisible surface that captures drag-to-look. Disabled
   by default (desktop uses pointer lock); enabled when body.touch. */
#look-layer {
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  touch-action: none;
}
body.touch #look-layer { pointer-events: auto; }

#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 22;
  pointer-events: none;
}

/* Virtual movement joystick (bottom-left) */
#joystick {
  position: absolute;
  left: max(1.4rem, env(safe-area-inset-left));
  bottom: max(1.6rem, env(safe-area-inset-bottom));
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 1px solid rgba(122, 247, 255, 0.3);
  background: radial-gradient(circle, rgba(122, 247, 255, 0.08), rgba(4, 6, 13, 0.35));
  box-shadow: inset 0 0 24px rgba(122, 247, 255, 0.12);
  pointer-events: auto;
  touch-action: none;
}
#joystick-nub {
  position: absolute;
  top: 50%; left: 50%;
  width: 56px; height: 56px;
  margin: -28px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--accent), var(--accent2));
  box-shadow: 0 0 20px rgba(122, 247, 255, 0.5);
  transition: transform 0.05s linear;
  will-change: transform;
}

/* Action buttons (bottom-right) */
#touch-buttons {
  position: absolute;
  right: max(1.4rem, env(safe-area-inset-right));
  bottom: max(1.6rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: flex-end;
}
.touch-btn {
  pointer-events: auto;
  touch-action: manipulation;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.18rem;
  color: var(--fg);
  background: rgba(4, 6, 13, 0.45);
  border: 1px solid rgba(122, 247, 255, 0.35);
  padding: 0.95rem 1.2rem;
  min-width: 96px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: transform 0.1s ease, background 0.1s ease, box-shadow 0.1s ease;
}
.touch-btn:active { transform: scale(0.94); }
.touch-btn.active {
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  color: var(--bg);
  border-color: transparent;
  box-shadow: 0 0 24px rgba(122, 247, 255, 0.5);
}

/* --------------------------- Responsive --------------------------- */
@media (max-width: 720px) {
  #compass { top: 1rem; right: 1rem; width: 112px; height: 112px; }
  #nowplaying {
    left: max(1.1rem, env(safe-area-inset-left));
    bottom: auto;
    top: max(1rem, env(safe-area-inset-top));
    min-width: 0;
    max-width: 56vw;
  }
  .np-title { font-size: 1.1rem; }
  .np-meter { width: 140px; max-width: 50vw; }
  /* The desktop key hints don't apply on touch; the on-screen pads do. */
  .hint { display: none; }
  .sp-controls { display: none; }
  .sp-title { letter-spacing: 0.28rem; }
}

/* When touch controls are active, hide the now-playing meter overlap by
   keeping it clear of the joystick (already moved to the top above). */
body.touch .hint { display: none; }
