/* ==========================================================================
   KLÍNOVEC — 3D Terrain Grid Map · HUD stylesheet
   Modern dark topographic HUD for the Three.js terrain shell.

   Contract ids styled here (renderer depends on them):
   #scene, #scene-fallback, #header, #title, #coords-text, #elev-readout,
   #legend, #legend-bar, #legend-min, #legend-max, #stats, #stats-grid,
   #stats-source, #stats-resolution, #loading, #error-hud, #error-msg.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Surfaces — deep navy family so the 3D canvas blends */
  --bg-0: #0d1426;
  --bg-1: #101a30;
  --bg-2: #16223c;

  /* HUD panels — frosted glass */
  --panel-bg: rgba(16, 22, 40, 0.55);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-blur: 10px;
  --panel-radius: 12px;
  --panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);

  /* Text */
  --text-hi: rgba(255, 255, 255, 0.92);
  --text-mid: rgba(255, 255, 255, 0.6);
  --text-low: rgba(255, 255, 255, 0.45);

  /* Accents */
  --accent: #8fd0d8;
  --accent-soft: #a8dde2;
  --danger: #ff7a7a;
  --danger-bg: rgba(30, 14, 18, 0.6);
  --danger-border: rgba(255, 122, 122, 0.28);

  /* Topographic ramp (navy → slate → ice) used as small accents */
  --ramp-deep: #2b4668;
  --ramp-mid: #6f9aa6;
  --ramp-peak: #e9f1f1;

  /* Type — system stacks only, no external font fetches */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo,
               Consolas, "Liberation Mono", monospace;

  /* Z-order */
  --z-scene: 0;
  --z-hud: 10;
  --z-overlay: 100;
}

/* --------------------------------------------------------------------------
   2. Base / reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden; /* full-viewport app — no scrollbars */
}

body {
  font-family: var(--font-sans);
  color: var(--text-hi);
  background:
    radial-gradient(1200px 800px at 72% -10%, rgba(143, 208, 216, 0.05), transparent 60%),
    radial-gradient(1000px 700px at 8% 110%, rgba(43, 70, 104, 0.12), transparent 60%),
    var(--bg-0);
  cursor: default;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: rgba(143, 208, 216, 0.25);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   3. Scene — Three.js mount container
   -------------------------------------------------------------------------- */
#scene {
  position: fixed;
  inset: 0;
  z-index: var(--z-scene);
  overflow: hidden;
}

#scene canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none; /* pointer-drag terrain navigation on touch */
}

/* Renderer toggles .grabbing on the canvas (or #scene) while dragging */
#scene canvas.grabbing,
#scene.grabbing {
  cursor: grabbing;
}

/* Visible pre-WebGL message; main.js removes this node */
#scene-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-low);
  font-size: 13px;
  font-weight: 300;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  pointer-events: none;
  animation: pulse 2.4s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   4. Shared HUD panel — frosted glass
   -------------------------------------------------------------------------- */
.hud-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--panel-radius);
  backdrop-filter: blur(var(--panel-blur)) saturate(1.2);
  -webkit-backdrop-filter: blur(var(--panel-blur)) saturate(1.2);
  box-shadow: var(--panel-shadow);
  user-select: none;
}

/* --------------------------------------------------------------------------
   5. Header — top-left identity panel
   -------------------------------------------------------------------------- */
#header {
  position: fixed;
  top: 24px;
  left: 24px;
  z-index: var(--z-hud);
  padding: 18px 22px 16px;
}

#title {
  margin: 0;
  font-size: clamp(1.5rem, 2.6vw, 2.1rem);
  font-weight: 200; /* thin, premium cartographic */
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--text-hi);
  line-height: 1.1;
}

/* Thin topographic ramp rule under the title */
.title-rule {
  width: 100%;
  height: 2px;
  margin: 12px 0 12px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--ramp-deep) 0%, var(--ramp-mid) 55%, var(--ramp-peak) 100%);
  opacity: 0.85;
}

#coords-text {
  margin: 0;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-low);
}

/* --------------------------------------------------------------------------
   6. Elevation readout — floating top-center chip
   -------------------------------------------------------------------------- */
#elev-readout {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-hud);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--accent);
  white-space: nowrap;
}

/* Accent dot — survives renderer textContent writes (pseudo-element) */
#elev-readout::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(143, 208, 216, 0.6);
}

/* --------------------------------------------------------------------------
   7. Bottom-right stack — stats above legend
   -------------------------------------------------------------------------- */
.bottom-stack {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: var(--z-hud);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* --------------------------------------------------------------------------
   8. Stats panel
   -------------------------------------------------------------------------- */
#stats {
  padding: 12px 16px;
  min-width: 240px;
}

.stat-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 3px 0;
}

.stat-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-low);
}

.stat-row span:last-child {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-mid);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   9. Legend — elevation ramp
   -------------------------------------------------------------------------- */
#legend {
  padding: 12px 14px 10px;
}

#legend-bar {
  display: block;
  width: 220px;
  height: 14px;
  border-radius: 3px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text-low);
}

/* --------------------------------------------------------------------------
   10. Loading overlay — full-screen, centered
   -------------------------------------------------------------------------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.5s ease;
}

/* Renderer toggles .fade-out, then sets display:none */
#loading.fade-out {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

.loading-text {
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.5em;
  text-indent: 0.5em; /* re-center tracked text */
  text-transform: uppercase;
  color: var(--text-mid);
}

/* --------------------------------------------------------------------------
   11. Error HUD — full-screen, red-tinged, hidden by default
   -------------------------------------------------------------------------- */
#error-hud {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 14, 20, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#error-hud.hidden {
  display: none !important;
}

.error-panel {
  max-width: 420px;
  padding: 28px 32px;
  text-align: center;
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.error-icon {
  display: block;
  margin-bottom: 12px;
  font-size: 28px;
  line-height: 1;
  color: var(--danger);
}

#error-msg {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-mid);
  user-select: text; /* errors should be copyable */
}

/* --------------------------------------------------------------------------
   12. Motion
   -------------------------------------------------------------------------- */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner,
  #scene-fallback {
    animation: none;
  }
  #loading {
    transition: none;
  }
}

/* --------------------------------------------------------------------------
   13. Responsive — compact below 800px
   -------------------------------------------------------------------------- */
@media (max-width: 800px) {
  #header {
    top: 16px;
    left: 16px;
    padding: 14px 16px 12px;
  }

  #title {
    font-size: 1.25rem;
    letter-spacing: 0.28em;
  }

  .title-rule {
    margin: 10px 0;
  }

  #coords-text {
    font-size: 10px;
    letter-spacing: 0.12em;
  }

  /* Chip drops to bottom-left to clear the header on narrow screens */
  #elev-readout {
    top: auto;
    bottom: 16px;
    left: 16px;
    transform: none;
    font-size: 16px;
    padding: 6px 12px;
  }

  .bottom-stack {
    right: 16px;
    bottom: 16px;
    gap: 10px;
  }

  #stats {
    min-width: 200px;
    padding: 10px 14px;
  }

  #legend {
    padding: 10px 12px 8px;
  }

  .loading-text {
    font-size: 11px;
    letter-spacing: 0.4em;
    text-indent: 0.4em;
  }

  .error-panel {
    padding: 22px 24px;
  }
}