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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  user-select: none;
}

/* ── Main canvas ── */
#canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: grab;
}
#canvas.grabbed { cursor: grabbing; }

/* ── Loading overlay ── */
#loading {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: #0a0a14;
  z-index: 100;
  gap: 20px;
  transition: opacity 0.4s;
}
#loading.hidden { opacity: 0; pointer-events: none; }

.spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: #4af;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#loading-text {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.04em;
}

/* ── HUD ── */
#hud {
  position: fixed;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  z-index: 10;
  pointer-events: none;
}

#position-display {
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 6px 18px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: #4af;
}

#controls-hint {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.04em;
}

/* ── Minimap ── */
#minimap-wrap {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 10;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}

#minimap {
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  background: rgba(0,0,0,0.5);
  image-rendering: pixelated;
}

#minimap-label {
  font-size: 0.62rem;
  color: rgba(255,255,255,0.3);
  letter-spacing: 0.05em;
}

/* ── Crosshair ── */
#crosshair {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  color: rgba(255,255,255,0.35);
  pointer-events: none;
  z-index: 10;
  text-shadow: 0 0 6px rgba(0,0,0,0.8);
}

/* ── Transition fade overlay ── */
#fade {
  position: fixed; inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.18s;
}
#fade.visible { opacity: 1; }

/* ── Click-to-enter overlay ── */
#click-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  z-index: 40;
  cursor: pointer;
  transition: opacity 0.3s;
}
#click-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.click-prompt {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px;
  padding: 32px 48px;
  text-align: center;
}
.click-icon { font-size: 2.4rem; line-height: 1; }
.click-prompt > span:nth-child(2) {
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.02em;
}
.click-hint {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.04em;
}

/* ── Nav arrows ── */
#nav-arrows {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: grid;
  grid-template-areas:
    ". up    ."
    "left fwd right"
    ". back  ."
    ". down  .";
  gap: 6px;
}

.nav-btn {
  width: 44px; height: 44px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  color: rgba(255,255,255,0.85);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, transform 0.1s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn:hover  { background: rgba(68,170,255,0.35); border-color: rgba(68,170,255,0.5); }
.nav-btn:active { transform: scale(0.92); }
.nav-btn.nav-hidden { opacity: 0; pointer-events: none; }

.nav-forward  { grid-area: fwd;   }
.nav-backward { grid-area: back;  }
.nav-left     { grid-area: left;  }
.nav-right    { grid-area: right; }
.nav-up       { grid-area: up;    }
.nav-down     { grid-area: down;  }

@media (max-width: 480px) {
  .nav-btn { width: 40px; height: 40px; font-size: 0.9rem; }
}

/* ── Weather effects ── */
#lens-rain,
#fog-overlay {
  /* canvas overlays — sized by JS */
}

#lightning-flash {
  /* div overlay — styled by JS */
}

#weather-hud {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(200,225,255,0.85);
  text-shadow: 0 1px 8px rgba(0,0,0,0.9);
  background: rgba(0,0,0,0.35);
  padding: 3px 12px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}

/* ── Gyro toggle button ── */
#gyro-btn {
  position: fixed;
  bottom: 100px;
  right: 16px;
  z-index: 25;
  width: 50px; height: 50px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
#gyro-btn.gyro-on {
  background: rgba(68,170,255,0.45);
  border-color: rgba(68,170,255,0.8);
  box-shadow: 0 0 12px rgba(68,170,255,0.5);
}

/* ── Virtual joystick (mobile walk buttons) ── */
#joy-wrap {
  position: fixed;
  bottom: 24px;
  left: 20px;
  z-index: 25;
  display: grid;
  grid-template-columns: 64px 64px 64px;
  grid-template-rows: 64px 64px;
  gap: 6px;
}

.joy-btn {
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 14px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  color: rgba(255,255,255,0.9);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.joy-btn:active { background: rgba(68,170,255,0.45); transform: scale(0.9); }

/* Grid layout: row 1 = fwd (center col); row 2 = left/bwd/right */
.joy-fwd  { grid-column: 2; grid-row: 1; }
.joy-left { grid-column: 1; grid-row: 2; }
.joy-bwd  { grid-column: 2; grid-row: 2; }
.joy-right{ grid-column: 3; grid-row: 2; }

/* On mobile: push minimap up so it doesn't clash with joystick */
@media (max-width: 768px) and (pointer: coarse) {
  #minimap-wrap { bottom: 24px; right: 16px; }
  #nav-arrows { display: none; } /* joystick replaces nav arrows on mobile */
  #controls-hint { display: none; }
  .click-prompt { padding: 24px 32px; }
}

/* ── Multiplayer sprite overlay ── */
.sprite-wrap {
  position: fixed;
  display: none;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 30;
  /* bottom-anchor: wrap bottom edge sits at the projected point */
  transform-origin: bottom center;
}

.player-sprite {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  /* vertically center bottom of feet at projection point */
  transform: translateY(-100%) translateX(0);
}

.sprite-label {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  background: rgba(0,0,0,0.45);
  padding: 2px 7px;
  border-radius: 4px;
  pointer-events: none;
}
