* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: #f7fbf8;
  background: #0b1512;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main { position: relative; width: 100vw; height: 100vh; }

#terrainCanvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#terrainCanvas:active { cursor: grabbing; }

.map-labels { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
.map-labels .lab {
  position: absolute; transform: translate(-50%, -100%);
  padding: 3px 8px; border-radius: 6px; white-space: nowrap;
  font-size: 11.5px; font-weight: 800; letter-spacing: 0.02em;
  background: rgba(9, 19, 16, 0.82); border: 1px solid rgba(255, 255, 255, 0.22);
  color: #eafaf3; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.map-labels .lab small { display: block; font-size: 9.5px; font-weight: 600; color: #8fd3ff; letter-spacing: 0.04em; text-transform: uppercase; }
.map-labels .lab.source { border-color: rgba(97, 216, 168, 0.7); }
.map-labels .lab.mouth { border-color: rgba(139, 211, 255, 0.7); }

.hud, .panel, footer {
  position: fixed;
  z-index: 2;
  backdrop-filter: blur(12px);
  background: rgba(9, 19, 16, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 14px 45px rgba(0, 0, 0, 0.25);
}

.hud {
  top: 16px; left: 16px; right: 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; padding: 14px 16px; border-radius: 10px;
}

.hud p, h1, h2, footer, .panel p { margin-top: 0; }

.hud p {
  margin-bottom: 3px; color: #7fd8b4;
  font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.04em;
}

h1 { margin-bottom: 0; font-size: clamp(20px, 3.4vw, 34px); line-height: 1; }

.hud nav { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.hud a {
  min-height: 34px; padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 6px;
  color: #f7fbf8; background: rgba(255, 255, 255, 0.08);
  font-size: 14px; font-weight: 800; text-decoration: none;
}
.hud a:hover { background: rgba(255, 255, 255, 0.16); }

.controls {
  left: 16px; bottom: 52px;
  width: min(340px, calc(100vw - 32px));
  padding: 15px 16px; border-radius: 10px;
}

.region { display: flex; gap: 6px; margin-bottom: 14px; }
.region button {
  flex: 1; padding: 8px 6px; border-radius: 7px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06); color: #d9eee5;
  font-size: 13px; font-weight: 800;
}
.region button.on { background: #2f8f6b; border-color: #48b07a; color: #fff; }

label {
  display: grid; gap: 6px; margin-top: 12px;
  color: #d9eee5; font-size: 13.5px; font-weight: 800;
}
output { color: #7fd8b4; font-weight: 700; }
input[type="range"] { width: 100%; accent-color: #61b88d; }

.legend { display: flex; flex-wrap: wrap; gap: 5px 10px; margin: 14px 0 4px; }
.legend button {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 2px 0; cursor: pointer;
  color: #cfe4dc; font-size: 12px; font-weight: 700;
}
.legend button[aria-pressed="false"] { opacity: 0.38; }
.legend .dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .n { color: #8fa8a0; font-weight: 600; }

.readout { color: #b9ccc4; font-size: 12.5px; line-height: 1.45; margin: 10px 0 0; }
.src { color: #6f857d; font-size: 11px; margin: 8px 0 0; }

.detail {
  right: 16px; bottom: 52px;
  width: min(340px, calc(100vw - 32px));
  padding: 16px 18px; border-radius: 10px;
}
.detail .close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: 0; color: #9fb4ac; font-size: 22px; cursor: pointer; line-height: 1;
}
.detail .kicker { font-size: 11.5px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.detail h2 { font-size: 18px; margin-bottom: 8px; }
.detail p { color: #cadfd6; font-size: 13px; line-height: 1.5; }
.detail .meta { margin: 12px 0 0; display: grid; gap: 9px; }
.detail .meta div { display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
.detail dt { color: #8fa8a0; font-size: 12px; font-weight: 700; }
.detail dd { margin: 0; color: #eaf4ef; font-size: 12.5px; }

.loading {
  position: absolute; inset: 0; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  background: #0b1512; color: #7fd8b4; font-weight: 800; font-size: 15px;
}
.loading.done { display: none; }

footer {
  left: 16px; bottom: 16px;
  max-width: min(820px, calc(100vw - 32px));
  margin: 0; padding: 9px 12px; border-radius: 8px;
  color: #9db3aa; font-size: 12px; line-height: 1.4;
}

@media (max-width: 820px) {
  /* Stack instead of overlay: the panel was covering the whole canvas on phones. */
  html, body { overflow-y: auto; height: auto; }
  .hud {
    position: static; display: grid; margin: 0;
    border-radius: 0; border-left: 0; border-right: 0; border-top: 0;
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  main { position: relative; width: 100%; height: auto; }
  #terrainCanvas { height: 56vh; min-height: 300px; display: block; }
  .map-labels { position: absolute; top: 0; bottom: auto; height: 56vh; }
  .loading { position: absolute; top: 0; bottom: auto; height: 56vh; }
  .controls {
    position: static; width: auto; margin: 12px;
    border-radius: 12px; backdrop-filter: none;
  }
  /* hotspot detail becomes a bottom sheet so a tap is always visible */
  .detail {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; margin: 0;
    border-radius: 14px 14px 0 0; max-height: 72vh; overflow-y: auto;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  footer { display: none; }
}
.hud nav a[aria-current="page"] { background: rgba(127,227,196,.9); border-color: rgba(127,227,196,.9); color: #06231b; }
