/* ==========================================================================
   Terrafall — a cinematic descent from orbit to you
   ========================================================================== */

:root {
  --bg: #05070d;
  --accent: #5eead4;
  --accent-2: #a5f3fc;
  --text: #e7ecf5;
  --dim: rgba(231, 236, 245, 0.55);
  --panel: rgba(10, 16, 28, 0.55);
  --panel-border: rgba(255, 255, 255, 0.09);
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
   Map
   -------------------------------------------------------------------------- */
#map {
  position: fixed;
  inset: 0;
  background: #05070d;
}

.maplibregl-canvas { outline: none; }

/* Cinematic layers */
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.42) 100%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.35), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.4));
}

.grain {
  position: fixed;
  inset: -50%;
  pointer-events: none;
  z-index: 4;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 8s steps(10) infinite;
}

@keyframes grain {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -2%); }
  80% { transform: translate(3%, 3%); }
}

/* --------------------------------------------------------------------------
   Crosshair / reticle
   -------------------------------------------------------------------------- */
#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 1.2s var(--ease), transform 1.2s var(--ease);
}

#crosshair.fade { opacity: 0; transform: translate(-50%, -50%) scale(1.8); }

.reticle {
  position: relative;
  width: 96px;
  height: 96px;
  color: var(--accent);
}

.reticle .line {
  position: absolute;
  background: currentColor;
  opacity: 0.65;
}
.reticle .line.h { left: 50%; top: 0; width: 1px; height: 100%; margin-left: -0.5px; }
.reticle .line.v { top: 50%; left: 0; height: 1px; width: 100%; margin-top: -0.5px; }

.reticle .ring {
  position: absolute;
  inset: 0;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: 0.5;
  animation: reticle-pulse 3s var(--ease) infinite;
}

.reticle .dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 12px currentColor;
}

@keyframes reticle-pulse {
  0%, 100% { transform: scale(0.82); opacity: 0.55; }
  50% { transform: scale(1.02); opacity: 0.2; }
}

/* --------------------------------------------------------------------------
   HUD
   -------------------------------------------------------------------------- */
.hud {
  position: fixed;
  z-index: 10;
  color: var(--text);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}

.hud-tl { top: 26px; left: 28px; }
.hud-tr { top: 26px; right: 28px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.hud-bl { bottom: 26px; left: 28px; }
.hud-br { bottom: 26px; right: 28px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }

/* Brand */
.wordmark {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}
.wordmark span { color: var(--accent); }

.tagline {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--dim);
}

/* Chips */
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chip.mono { font-family: var(--font-mono); font-weight: 400; }
.chip-label { color: var(--dim); text-transform: uppercase; font-size: 10px; letter-spacing: 0.14em; }

.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 0 10px #fbbf24;
  animation: blink 1.4s ease-in-out infinite;
}
.chip.locked .dot { background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: none; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* Coordinates */
.coords {
  font-size: 16px;
  letter-spacing: 0.04em;
}
.dim { color: var(--dim); }
.hud-bl .mono { margin: 0 0 4px; font-family: var(--font-mono); }

/* Controls */
.ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 15px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.15s var(--ease);
}
.ghost:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.2); }
.ghost:active { transform: scale(0.96); }
.ghost svg { flex: none; }

.hidden { display: none !important; }

/* Controls reveal state */
#controls, #coordsPanel, .hint { opacity: 0; transform: translateY(12px); transition: opacity 0.8s var(--ease), transform 0.8s var(--ease); }
body.arrived #controls, body.arrived #coordsPanel, body.arrived .hint { opacity: 1; transform: translateY(0); }

/* Hint */
.hint {
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 10;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Location marker
   -------------------------------------------------------------------------- */
.marker {
  position: relative;
  width: 26px;
  height: 26px;
}
.marker-ping {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.7;
  animation: ping 2.4s var(--ease) infinite;
}
.marker-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 13px;
  margin: -6.5px 0 0 -6.5px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 0 18px rgba(94, 234, 212, 0.9);
}

@keyframes ping {
  0% { transform: scale(0.6); opacity: 0.8; }
  70%, 100% { transform: scale(2.6); opacity: 0; }
}

/* --------------------------------------------------------------------------
   Loader
   -------------------------------------------------------------------------- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(120% 100% at 50% 20%, #0b1120 0%, #05070d 60%);
  transition: opacity 1.1s var(--ease), visibility 1.1s;
}
#loader.done { opacity: 0; visibility: hidden; pointer-events: none; }

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 12% 22%, rgba(255,255,255,0.8) 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 14%, rgba(255,255,255,0.6) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 34% 68%, rgba(255,255,255,0.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 62% 82%, rgba(255,255,255,0.7) 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 52%, rgba(255,255,255,0.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 20% 88%, rgba(255,255,255,0.4) 50%, transparent 51%);
  opacity: 0.6;
}

.loader-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 24px;
}

.globe {
  position: relative;
  width: 120px;
  height: 120px;
  color: var(--accent);
  margin-bottom: 26px;
}
.globe svg { width: 100%; height: 100%; }

.globe-ring {
  position: absolute;
  inset: -18px;
  border-radius: 50%;
  border: 1px dashed rgba(94, 234, 212, 0.35);
  animation: spin 22s linear infinite;
}
.globe-ring::after {
  content: "";
  position: absolute;
  top: -4px;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

@keyframes spin { to { transform: rotate(360deg); } }

.loader-title {
  margin: 0;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.loader-title::first-letter { color: var(--accent); }

.loader-status {
  margin: 14px 0 22px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--dim);
  min-height: 1.2em;
  transition: opacity 0.3s;
}

.loader-bar {
  width: 240px;
  height: 2px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  overflow: hidden;
}
.loader-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px var(--accent);
  transition: width 0.6s var(--ease);
}

/* --------------------------------------------------------------------------
   Attribution polish
   -------------------------------------------------------------------------- */
.maplibregl-ctrl-bottom-right { margin: 0 12px 10px 0; }
.maplibregl-ctrl-attrib {
  background: rgba(10, 16, 28, 0.5) !important;
  color: var(--dim) !important;
  font-family: var(--font-mono);
  font-size: 10px;
  border-radius: 8px;
}
.maplibregl-ctrl-attrib a { color: var(--dim) !important; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .hud-tl { top: 18px; left: 18px; }
  .hud-tr { top: 18px; right: 18px; }
  .hud-bl { bottom: 18px; left: 18px; }
  .hud-br { bottom: 18px; right: 18px; }
  .wordmark { font-size: 24px; }
  .tagline { display: none; }
  .coords { font-size: 13px; }
  .ghost span { display: none; }
  .ghost { padding: 10px; }
  .hint { bottom: 20px; font-size: 10px; }
}
