/* ───────────────────────────────────────────────
   Reset & Base
   ─────────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: #0a0a0f;
  color: #e0e0e6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ───────────────────────────────────────────────
   Canvas Container
   ─────────────────────────────────────────────── */
#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 0;
  /* subtle radial vignette behind the 3-D scene */
  background:
    radial-gradient(ellipse at center, #12121a 0%, #08080d 100%);
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
  user-select: none;
}

/* ───────────────────────────────────────────────
   Loading Screen
   ─────────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0d0d14 0%, #111119 50%, #0a0a10 100%);
  transition: opacity 0.8s ease, visibility 0.8s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-content {
  text-align: center;
  max-width: 360px;
  width: 90%;
}

.loader-title {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, #7eb4ff 0%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.4rem;
}

.loader-logo {
  display: block;
  width: min(180px, 55vw);
  height: auto;
  margin: 0 auto 0.8rem;
}

.loader-subtitle {
  font-size: 0.9rem;
  font-weight: 300;
  color: #888;
  margin-bottom: 2rem;
}

/* Progress bar track */
.progress-track {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, #7eb4ff, #c084fc);
  transition: width 0.25s ease;
  box-shadow: 0 0 12px rgba(126, 180, 255, 0.4);
}

.progress-text {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: #aaa;
  font-variant-numeric: tabular-nums;
}

/* ───────────────────────────────────────────────
   Error Overlay
   ─────────────────────────────────────────────── */
#error-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#error-overlay.hidden {
  display: none;
}

/* ───────────────────────────────────────────────
   Initial Movement Tutorial
   ─────────────────────────────────────────────── */
#movement-tutorial {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

#movement-tutorial.hidden {
  display: none;
}

.tutorial-frame {
  display: none;
  width: min(92vw, 560px);
  height: 340px;
  min-height: 0;
  padding: 1.25rem 1.35rem 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  background: radial-gradient(circle at 50% 43%, rgba(255,255,255,0.12), transparent 48%), linear-gradient(145deg, #1b1d1f, #0c0e11);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  animation: tutorialFrameIn 0.55s ease both;
}

.tutorial-controls {
  position: absolute;
  bottom: calc(50% - 150px);
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(92vw, 560px);
  transform: translateX(-50%);
  padding: 0 1.35rem;
}

.tutorial-controls button {
  min-width: 5.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  color: #dfe2e5;
  font: 500 0.7rem/1 'Inter', system-ui, sans-serif;
  cursor: pointer;
}

.tutorial-controls button:hover:not(:disabled),
.tutorial-controls button:focus-visible {
  border-color: rgba(143, 216, 255, 0.7);
  background: rgba(143, 216, 255, 0.14);
  outline: none;
}

.tutorial-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

.tutorial-dots {
  display: flex;
  gap: 0.35rem;
}

.tutorial-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
}

.tutorial-dots span.active {
  background: #8fd8ff;
  box-shadow: 0 0 8px rgba(143, 216, 255, 0.65);
}

.tutorial-frame.active {
  display: block;
}

.tutorial-heading {
  display: flex;
  align-items: center;
  gap: 2rem;
  color: #dfe2e5;
  letter-spacing: 0.2em;
}

.tutorial-heading span {
  font-size: 1.55rem;
  letter-spacing: 0;
}

.tutorial-heading strong {
  font-size: 0.72rem;
  font-weight: 500;
  color: #aeb2b7;
}

.tutorial-stage {
  position: relative;
  height: calc(100% - 3.7rem);
  overflow: hidden;
  margin-top: 0.8rem;
  background: repeating-linear-gradient(90deg, transparent 0 35px, rgba(143, 216, 255, 0.055) 36px 37px), repeating-linear-gradient(0deg, transparent 0 24px, rgba(143, 216, 255, 0.055) 25px 26px);
  background-position: 0 100%;
  background-size: 100% 46%, 100% 46%;
  background-repeat: no-repeat;
}

.tutorial-stage::after {
  content: '';
  position: absolute;
  inset: 57% 0 0;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.18));
  border-top: 1px solid rgba(255,255,255,0.04);
}

.record-frame {
  position: absolute;
  z-index: 2;
  top: 23%;
  left: 6%;
  width: 19%;
  aspect-ratio: 1.45;
  border: 1px solid rgba(238, 240, 242, 0.72);
  box-shadow: 0 0 18px rgba(255,255,255,0.05);
}

.record-frame.targeted {
  animation: framePulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 22px rgba(255,255,255,0.24);
}

.tutorial-pointer {
  position: absolute;
  z-index: 3;
  top: 46%;
  left: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  background: linear-gradient(#fff, #fff) center / 2px 100% no-repeat, linear-gradient(#fff, #fff) center / 100% 2px no-repeat;
  filter: drop-shadow(0 0 4px rgba(255,255,255,0.7));
}

.tutorial-frame-one .tutorial-pointer {
  animation: pointerToFrame 2.35s ease-in-out both;
}

.tutorial-pointer.on-frame {
  top: 32%;
  left: 15.5%;
}

.tutorial-pointer.clicking {
  animation: clickPulse 1.2s ease-in-out infinite;
}

.click-indicator {
  position: absolute;
  z-index: 4;
  top: 72%;
  left: 31%;
  padding: 0.55rem 0.8rem;
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 5px;
  color: #e7e9eb;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  animation: clickPulse 1.2s ease-in-out infinite;
}

.click-indicator small {
  margin-left: 1rem;
  color: #b9bdc2;
  font-size: 0.62rem;
}

.move-trail {
  position: absolute;
  top: 32%;
  left: 15%;
  width: 60%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  box-shadow: 0 10px 0 rgba(255,255,255,0.08), 0 -10px 0 rgba(255,255,255,0.08);
  animation: moveTrail 2.2s ease-in-out infinite;
}

.tutorial-frame p {
  position: absolute;
  right: 1.6rem;
  bottom: 0.85rem;
  left: 1.6rem;
  color: #b5b8bd;
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  text-align: center;
}

@keyframes tutorialFrameIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
@keyframes pointerToFrame { from { left: 50%; } to { left: 15.5%; } }
@keyframes framePulse { 0%, 100% { opacity: 0.72; } 50% { opacity: 1; } }
@keyframes clickPulse { 0%, 100% { transform: scale(1); opacity: 0.78; } 50% { transform: scale(0.94); opacity: 1; } }
@keyframes moveTrail { 0%, 100% { transform: translateX(0); opacity: 0.35; } 50% { transform: translateX(10%); opacity: 0.9; } }

.error-card {
  background: rgba(20, 20, 30, 0.85);
  border: 1px solid rgba(255, 80, 80, 0.25);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.error-card h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: #ff6b6b;
  margin-bottom: 0.6rem;
}

.error-card p {
  font-size: 0.85rem;
  color: #999;
  line-height: 1.55;
  margin-bottom: 1.5rem;
}

.error-card button {
  padding: 0.55rem 1.6rem;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #7eb4ff, #c084fc);
  color: #fff;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.error-card button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(126, 180, 255, 0.35);
}

/* ───────────────────────────────────────────────
   Header Bar (glassmorphism)
   ─────────────────────────────────────────────── */
#header-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.25rem;
  background: rgba(14, 14, 22, 0.55);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  opacity: 0;
  transition: opacity 0.6s ease 0.3s;
}

#header-bar.visible {
  opacity: 1;
}

.header-title {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #7eb4ff 0%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-hint {
  font-size: 0.7rem;
  font-weight: 300;
  color: #666;
}

/* ───────────────────────────────────────────────
   Play Overlay (click to start)
   ─────────────────────────────────────────────── */
#play-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

#play-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.play-card {
  background: rgba(14, 14, 22, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 2.5rem 2.5rem 2rem;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

.play-icon {
  font-size: 3rem;
  margin-bottom: 0.8rem;
  color: #8fd8ff;
  -webkit-text-fill-color: currentColor;
}

.play-card h2 {
  font-size: 1.4rem;
  font-weight: 600;
  color: #e0e0e6;
  margin-bottom: 0.3rem;
}

.play-card > p {
  font-size: 0.8rem;
  color: #8fd8ff;
  margin-bottom: 1.5rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem 1.2rem;
  text-align: center;
  position: relative;
}

.control-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.controls-grid .control-item:last-child {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max-content;
  transform: translate(-50%, -50%);
}

.controls-grid .control-item:last-child kbd {
  color: #08243d;
  background: #8fd8ff;
  border-color: #b9e9ff;
  box-shadow: 0 0 12px rgba(143, 216, 255, 0.45);
}

.controls-grid .control-item:last-child span {
  color: #777;
}

.controls-grid .control-item:nth-child(2) kbd .arrow-symbol {
  display: inline-block;
  color: #c8c8d0;
  font-size: 0.7rem;
  font-weight: 700;
}

.controls-grid .control-item:nth-child(2) kbd .arrow-left {
  transform: rotate(-90deg);
}

.controls-grid .control-item:nth-child(2) kbd .arrow-right {
  transform: rotate(90deg);
}

.control-item span {
  font-size: 0.7rem;
  color: #777;
  font-weight: 400;
}

kbd {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  color: #c8c8d0;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  margin: 0 0.1rem;
  min-width: 1.6rem;
}

/* ───────────────────────────────────────────────
   Crosshair (visible during pointer lock)
   ─────────────────────────────────────────────── */
body::after {
  content: '';
  position: fixed;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: #063b78;
  border: 1px solid #39ff88;
  z-index: 9999;
  pointer-events: none;
  transition: all 0.2s ease;
}

body:has(#loading-screen:not(.fade-out))::after {
  display: none;
}

body:has(#play-overlay:not(.hidden))::after {
  display: none;
}

body:has(#movement-tutorial:not(.hidden))::after {
  display: none;
}

body.hover-interact::after {
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  background: #0755a3;
  border-color: #39ff88;
  box-shadow: 0 0 8px rgba(7, 85, 163, 0.8);
}

/* ───────────────────────────────────────────────
   Interaction Prompt
   ─────────────────────────────────────────────── */
#interact-prompt {
  position: fixed;
  top: 55%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

#interact-prompt.hidden {
  opacity: 0;
  visibility: hidden;
}

.interact-label {
  padding: 0.55rem 1.25rem;
  background: rgba(6, 27, 53, 0.88);
  border: 1px solid #0b5cab;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  color: #ffffff;
  white-space: nowrap;
}

.interact-hint {
  font-size: 0.7rem;
  font-weight: 700;
  color: #39ff88;
  letter-spacing: 0.03em;
  text-shadow: 0 0 6px rgba(57, 255, 136, 0.9);
  animation: promptPulse 1.8s ease-in-out infinite;
}

@keyframes promptPulse {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

#mobile-controls {
  display: none;
  visibility: hidden;
  opacity: 0;
}

#mobile-joystick {
  position: fixed;
  left: 1.25rem;
  bottom: 1.25rem;
  z-index: 20;
  width: 7rem;
  height: 7rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(8, 20, 38, 0.5);
  box-shadow: inset 0 0 0 1rem rgba(255, 255, 255, 0.04), 0 8px 24px rgba(0, 0, 0, 0.35);
  touch-action: none;
  user-select: none;
}

#mobile-joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2.8rem;
  height: 2.8rem;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: rgba(57, 255, 136, 0.65);
  box-shadow: 0 0 18px rgba(57, 255, 136, 0.35);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

#mobile-center-action {
  position: fixed;
  right: 1.25rem;
  bottom: 1.5rem;
  z-index: 20;
  width: 3.5rem;
  height: 3.5rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(8, 20, 38, 0.55);
  touch-action: manipulation;
}

@media (pointer: coarse), (max-width: 700px) {
  #canvas-container {
    touch-action: none;
  }

  #header-bar,
  body.hover-interact::after {
    display: none;
  }

  body::after {
    display: none;
  }

  body.mobile-exploring::after,
  body.mobile-exploring.hover-interact::after {
    display: block;
  }

  #interact-prompt {
    pointer-events: auto;
  }

  #mobile-center-action {
    display: none;
  }

  .play-card {
    width: auto;
    max-width: none;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .play-icon,
  .play-card > p,
  .controls-grid {
    display: none;
  }

  .play-card h2 {
    margin: 0;
    padding: 0.9rem 1.35rem;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background: linear-gradient(135deg, #0b5cab, #063b78);
    color: #ffffff;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  }

  #mobile-controls {
    display: block;
  }

  #mobile-controls.mobile-active {
    display: block;
    visibility: visible;
    opacity: 1;
  }
}

/* ───────────────────────────────────────────────
   Responsive tweaks
   ─────────────────────────────────────────────── */
@media (max-width: 520px) {
  .loader-title {
    font-size: 1.8rem;
  }
  .header-hint {
    display: none;
  }
  #header-bar {
    justify-content: center;
  }
  .controls-grid {
    grid-template-columns: 1fr;
  }
  .play-card {
    padding: 1.5rem;
  }
}
