/* =========================
   Theme variables
========================= */
:root {
  --bg: #070a10;
  --panel: rgba(12, 16, 26, 0.92);
  --panel2: rgba(12, 16, 26, 0.78);
  --text: rgba(245, 247, 255, 0.92);
  --border: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* =========================
   Layout
========================= */
#app {
  height: 100vh;
  display: grid;
  grid-template-columns: 420px 1fr;
}

/* =========================
   Story panel
========================= */
#story {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}

#storyBody {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  -webkit-overflow-scrolling: touch;
}

.step {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  margin-bottom: 14px;
  transition: background 180ms ease, outline 180ms ease, transform 180ms ease;
}

.step h2 {
  margin: 0 0 10px;
  font-size: 1.15rem;
  letter-spacing: 0.2px;
}

.step p {
  margin: 0;
  line-height: 1.55;
  opacity: 0.95;
  white-space: pre-line;
}

.step.active {
  outline: 2px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
  transform: translateY(-1px);
}

/* =========================
   Chapter images (sidebar)
========================= */
.chapter-figure {
  margin: 10px 0 12px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
}

.chapter-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: 240px;
  object-fit: cover;
}

.chapter-credit {
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
  opacity: 0.88;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.chapter-credit a {
  color: rgba(245,247,255,0.92);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chapter-license { opacity: 0.85; }

/* =========================
   Controls
========================= */
#controls {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

button {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
}

button:hover { background: rgba(255,255,255,0.10); }

/* =========================
   Map
========================= */
#mapWrap {
  position: relative;
  height: 100vh;
  width: 100%;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* =========================
   HUD
========================= */
#hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 1000;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  max-width: min(360px, calc(100% - 24px));
}

#hudChapterTitle { font-weight: 700; margin-bottom: 6px; }
#progressText { font-size: 0.9rem; opacity: 0.9; margin-bottom: 8px; }

#progressBar {
  height: 6px;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: rgba(255,255,255,0.7);
}

/* =========================
   Leaflet popup + Place popup media
========================= */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: rgba(12, 16, 26, 0.92);
  color: rgba(245, 247, 255, 0.92);
  border: 1px solid rgba(255,255,255,0.10);
  backdrop-filter: blur(8px);
}

.leaflet-popup-content {
  margin: 10px 12px;
  line-height: 1.45;
}

.popup-image {
  margin-top: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
}

.popup-img {
  display: block;
  width: 100%;
  height: auto;
}

.popup-credit {
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
  opacity: 0.88;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.popup-credit a {
  color: rgba(245,247,255,0.92);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.popup-sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.10);
}

.popup-label {
  font-size: 12px;
  opacity: 0.75;
  margin-bottom: 4px;
}

.popup-links a {
  font-size: 12px;
  opacity: 0.95;
  color: rgba(245,247,255,0.92);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.popup-links a:hover,
.popup-credit a:hover,
.chapter-credit a:hover { opacity: 1; }

/* Leaflet */
.leaflet-control-container * { box-sizing: content-box; }

/* Mobile */
@media (max-width: 980px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 55vh;
  }
  #mapWrap { height: 45vh; }
  #story { border-right: none; border-top: 1px solid var(--border); }
  #hud { top: 10px; bottom: auto; }
}

@media (max-width: 520px) {
  .leaflet-popup-content { max-width: 260px; }
}
