:root {
  --bg: #0c1014;
  --bg-2: #151b22;
  --panel: rgba(12, 16, 20, 0.86);
  --line: rgba(232, 195, 106, 0.28);
  --gold: #e8c36a;
  --mud: #c45c26;
  --ice: #7ec8c5;
  --text: #ece7d8;
  --muted: #9aa4b2;
  --danger: #e07058;
  --ok: #8fbf7a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --sans: "IBM Plex Sans", "PingFang SC", "Noto Sans SC", sans-serif;
  --serif: "Source Serif 4", "Songti SC", "Noto Serif SC", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { overflow: hidden; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
a { color: var(--gold); }
button, input { font-family: inherit; }

.skip {
  position: absolute; left: -999px; top: 0;
}
.skip:focus { left: 8px; top: 8px; z-index: 80; background: var(--gold); color: #111; padding: 8px 12px; }

.topbar {
  position: absolute; inset: 0 0 auto 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: linear-gradient(to bottom, rgba(12,16,20,.92), rgba(12,16,20,.4) 70%, transparent);
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand h1 {
  font-family: var(--serif);
  font-size: clamp(16px, 2.1vw, 22px);
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.02em;
}
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.topbar nav { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.topbar a, .icon-btn {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.icon-btn:hover, .topbar a:hover { border-color: var(--gold); }
.menu-btn { display: none; }

.map-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
}
#map {
  position: absolute;
  inset: 0;
  background: #1d2833 url("../assets/images/Landsat_Nepal_flood_2026-08-26.png") center / cover no-repeat;
}

.rail, .card, .compare, .legend {
  position: absolute;
  z-index: 15;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.rail {
  top: 72px; left: 12px; width: 228px;
  max-height: calc(100% - 360px);
  overflow: auto;
  border-radius: 12px;
  padding: 10px;
}
.rail h2, .card h2, .sources-drawer h2 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}
.site-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-left: 2px solid transparent;
  padding: 7px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.site-btn small { color: var(--muted); font-size: 11px; }
.site-btn.active { border-left-color: var(--gold); background: rgba(232, 195, 106, 0.08); }
.site-btn.hit small { color: var(--mud); }
.site-btn.source small { color: var(--ice); }

.card {
  top: 72px; right: 12px; width: min(360px, calc(100vw - 24px));
  border-radius: 12px;
  padding: 14px 14px 12px;
  max-height: calc(100% - 360px);
  overflow: auto;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.card-more { display: none; flex-shrink: 0; }
.card h3 { font-family: var(--serif); margin: 0 0 6px; font-size: 20px; }
.card .meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.card p { margin: 0; font-size: 13.5px; line-height: 1.55; }
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}
.stat b { display: block; font-size: 16px; color: var(--gold); }
.stat span { font-size: 11px; color: var(--muted); }
.warn {
  margin-top: 10px;
  font-size: 12px;
  color: var(--danger);
  line-height: 1.45;
}

.compare {
  left: 12px; right: 12px; bottom: 12px;
  height: 318px;
  border-radius: 14px;
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-rows: 76px 1fr;
  overflow: hidden;
}
.filmstrip {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 12, 16, 0.35);
}
.film-item {
  flex: 0 0 auto;
  width: 124px;
  background: #10161c;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  overflow: hidden;
  text-align: left;
}
.film-item img {
  display: block;
  width: 124px;
  height: 42px;
  object-fit: cover;
  background: #000;
}
.film-item span {
  display: block;
  padding: 4px 6px 6px;
  font-size: 10px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.film-item.active { border-color: var(--gold); color: var(--gold); }
.compare-view {
  position: relative;
  overflow: hidden;
  background: #000;
  cursor: ew-resize;
  touch-action: none;
}
.compare-view img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}
#after-img { clip-path: inset(0 0 0 50%); }
.handle {
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 2px;
  background: var(--gold);
  transform: translateX(-1px);
  pointer-events: none;
}
.handle::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: rgba(12,16,20,.7);
  transform: translate(-50%, -50%);
}
.tag {
  position: absolute;
  top: 10px;
  padding: 3px 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  background: rgba(0,0,0,.55);
  border-radius: 999px;
}
.tag.before { left: 10px; color: var(--ice); }
.tag.after { right: 10px; color: var(--mud); }
.pins { position: absolute; inset: 0; pointer-events: none; }
.pin {
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(232,195,106,.25);
  transform: translate(-50%, -50%);
}
.pin label {
  position: absolute;
  left: 12px; top: -6px;
  white-space: nowrap;
  font-size: 11px;
  color: #fff;
  text-shadow: 0 1px 4px #000;
}

.compare-side {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}
.compare-lead { margin: 0; font-size: 13px; line-height: 1.45; color: var(--muted); }
.compare-side label { font-size: 11px; color: var(--muted); display: block; }
.compare-side select {
  width: 100%;
  margin-top: 4px;
  background: #1c242e;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
}
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row button, .pair-btn {
  background: #1c242e;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 12px;
}
.row button.active, .pair-btn.active { border-color: var(--gold); color: var(--gold); }
input[type="range"] { width: 100%; accent-color: var(--gold); }

.orbit {
  position: absolute;
  right: 18px;
  bottom: 338px;
  z-index: 16;
  width: 118px;
  user-select: none;
  touch-action: none;
}
.orbit-tire {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background:
    repeating-conic-gradient(from 0deg,
      #161410 0deg 7deg,
      #3d3428 7deg 9deg,
      #1c1814 9deg 16deg,
      #8a7344 16deg 18deg);
  box-shadow:
    0 10px 28px rgba(0,0,0,.55),
    inset 0 0 0 11px #241f18,
    inset 0 0 0 14px var(--gold);
  cursor: grab;
}
.orbit-tire:active { cursor: grabbing; }
.orbit-hub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: radial-gradient(circle at 40% 32%, #2a3340, #10151b);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 0;
}
.orbit-hub small {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.12em;
}
.orbit-hint {
  margin: 6px 0 0;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.35;
}

.site-step { display: none; }

.legend {
  left: 248px; top: 72px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 11px;
  color: var(--muted);
}
.legend i {
  display: inline-block;
  width: 18px; height: 3px;
  background: var(--mud);
  vertical-align: middle;
  margin-right: 6px;
}

.marker {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(0,0,0,.35);
}
.marker.source { background: var(--ice); }
.marker.hit { background: var(--mud); }
.marker.landmark { background: #9bb0c9; }
.marker.downstream { background: var(--gold); }
.marker.active { transform: scale(1.35); }

.sources-drawer {
  position: absolute;
  inset: 72px 12px 340px auto;
  width: min(420px, 92vw);
  z-index: 25;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
  display: none;
}
.sources-drawer.open { display: block; }
.sources-drawer ol { padding-left: 18px; }
.sources-drawer li { margin: 0 0 10px; font-size: 13px; line-height: 1.4; }
.sources-drawer small { color: var(--muted); }

.toast {
  position: absolute;
  bottom: 340px; left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  display: none;
}

.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-popup-content {
  background: #151b22;
  color: var(--text);
  border-radius: 8px;
  font-size: 12px;
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #151b22; }

@media (max-width: 860px) {
  html, body {
    overflow: auto;
    height: auto;
    min-height: 100dvh;
  }
  body {
    display: flex;
    flex-direction: column;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .kbd-help { display: none; }
  .menu-btn {
    display: inline-flex;
    margin-left: auto;
    min-height: 40px;
    align-items: center;
    flex-shrink: 0;
    border-color: var(--gold);
    color: var(--gold);
  }
  .brand { max-width: calc(100% - 92px); }
  .topbar {
    position: sticky;
    top: 0;
    flex-wrap: nowrap;
    background: var(--bg);
    z-index: 40;
    order: 0;
    align-items: center;
    padding: 10px 12px;
  }
  .brand { min-width: 0; flex: 1; }
  .brand h1 { font-size: 17px; }
  .brand p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #top-nav {
    display: none;
    position: absolute;
    left: 12px;
    right: 12px;
    top: calc(100% - 4px);
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
  }
  #top-nav.open { display: flex; }
  #top-nav a, #top-nav .icon-btn { width: 100%; justify-content: flex-start; text-align: left; }
  .topbar a, .icon-btn { padding: 10px 12px; font-size: 14px; min-height: 40px; }

  .map-stage {
    order: 1;
    position: relative;
    height: 42dvh;
    min-height: 280px;
    margin: 0;
  }
  #map { position: absolute; inset: 0; height: 100%; }
  .orbit {
    z-index: 18;
    right: 10px;
    bottom: 36px;
    top: auto;
    transform: none;
    width: 92px;
  }
  .orbit-tire { width: 92px; height: 92px; }
  .orbit-hub { width: 46px; height: 46px; margin: -23px 0 0 -23px; font-size: 12px; }
  .orbit-hint { font-size: 9px; }
  .legend {
    left: 10px;
    top: auto;
    bottom: 10px;
    max-width: calc(100% - 120px);
    font-size: 10px;
  }
  .site-step {
    display: flex;
    gap: 6px;
    position: absolute;
    left: 10px;
    top: 10px;
    z-index: 16;
  }
  .site-step button {
    min-height: 40px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    font-size: 13px;
  }
  .site-step button:disabled { opacity: 0.4; }
  .maplibregl-ctrl-bottom-right { display: none; }

  .rail {
    order: 2;
    position: relative;
    top: auto;
    left: auto;
    width: auto;
    max-height: none;
    margin: 8px 12px 0;
    padding: 10px 10px 8px;
  }
  #site-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 4px;
  }
  .site-btn {
    flex: 0 0 auto;
    width: 148px;
    border: 1px solid var(--line);
    border-left: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    scroll-snap-align: start;
  }
  .site-btn.active { border-color: var(--gold); }

  .compare {
    order: 3;
    position: relative;
    left: auto; right: auto; bottom: auto;
    height: auto;
    margin: 8px 12px 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(260px, 46dvh) auto;
  }
  .compare-view { min-height: 260px; height: 42dvh; }
  .filmstrip {
    grid-column: 1;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding: 10px;
  }
  .film-item {
    width: 132px;
    scroll-snap-align: start;
  }
  .film-item img { height: 56px; }
  .film-item span { font-size: 11px; padding: 6px 8px 8px; }
  .handle::after { width: 44px; height: 44px; }
  .compare-lead { display: none; }
  .compare-side { padding: 10px 12px 12px; }
  .row button {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }
  .compare-side select { font-size: 16px; min-height: 40px; }
  input[type="range"] { min-height: 28px; }

  .card {
    order: 4;
    position: relative;
    top: auto; right: auto;
    max-height: none;
    width: auto;
    margin: 8px 12px 0;
  }
  .card-more { display: inline-flex; }
  .card:not(.expanded) .card-extra { display: none; }
  .card.expanded .card-more { color: var(--gold); border-color: var(--gold); }
  .card h3 { font-size: 18px; margin: 0; }

  .sources-drawer {
    order: 6;
    inset: 12px 12px auto 12px;
    top: calc(env(safe-area-inset-top) + 56px);
    bottom: 12px;
    width: auto;
    max-height: calc(100dvh - 80px);
  }
  .toast { position: relative; bottom: auto; left: auto; transform: none; margin: 8px 12px; }
  .pins label { font-size: 10px; }
  .marker { width: 18px; height: 18px; }
}
