/* 3D Landslide Hazard Viewer - dark dashboard layout. */
:root {
  --bg: #0d1117;
  --panel: rgba(20, 26, 38, 0.86);
  --panel-border: #2b3343;
  --text: #e6ebf5;
  --muted: #94a0b8;
  --accent: #ff5a5a;
  --accent-soft: #ffb27a;
  --accent2: #4ec3ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }

/* Title card */
#title {
  position: fixed;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 22px;
  backdrop-filter: blur(8px);
  pointer-events: none;
  z-index: 10;
  max-width: 780px;
}
#title h1 {
  margin: 0;
  font-size: 16px; font-weight: 700;
  letter-spacing: 0.02em;
}
#title p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* Side panels - flush to the top edge so the full screen height is usable
   without scrolling on common laptop / monitor heights. The centred title
   card stays clear of the left/right panel columns horizontally. */
#panel, #stats {
  position: fixed;
  top: 14px;
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
  backdrop-filter: blur(8px);
  z-index: 10;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
}
#panel { left: 16px; }
#stats { right: 16px; width: 280px; }
#panel section + section { margin-top: 11px; }
#panel section h2, #stats h2 { margin: 0 0 6px; }
.ctrl { margin-bottom: 8px; }

/* Custom scrollbar - matches the dark glass panel theme. WebKit (Chrome,
   Edge, Safari) uses ::-webkit-scrollbar; Firefox uses scrollbar-width /
   scrollbar-color. Both are scoped to the scrollable side panels so the
   rest of the page (which doesn't scroll anyway) is unaffected. */
#panel, #stats {
  scrollbar-width: thin;
  scrollbar-color: #4a5670 transparent;
}
#panel::-webkit-scrollbar,
#stats::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
#panel::-webkit-scrollbar-track,
#stats::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.025);
  border-radius: 8px;
  margin: 4px 0;
}
#panel::-webkit-scrollbar-thumb,
#stats::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #3d4660 0%, #5a6580 100%);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: background 0.2s;
}
#panel::-webkit-scrollbar-thumb:hover,
#stats::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, var(--accent2) 0%, var(--accent) 100%);
  border-color: rgba(255, 255, 255, 0.18);
}
#panel::-webkit-scrollbar-thumb:active,
#stats::-webkit-scrollbar-thumb:active {
  background: var(--accent);
}
#panel::-webkit-scrollbar-corner,
#stats::-webkit-scrollbar-corner {
  background: transparent;
}

h2 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-soft);
}

/* Layer chooser */
.layer {
  display: block;
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.layer:hover { background: rgba(255,255,255,0.04); }
.layer.active { background: rgba(255, 90, 90, 0.15); border-color: var(--accent); }
.layer strong { display: block; }

/* Scenario chooser */
#scenarios { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.scenario {
  text-align: center;
  padding: 7px 6px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.scenario:hover { background: rgba(255,255,255,0.04); }
.scenario.active {
  background: rgba(78, 195, 255, 0.18);
  border-color: var(--accent2);
}
.scenario b { display: block; font-size: 12px; }
.scenario span { color: var(--muted); font-size: 10.5px; }
.scenario-hint { margin-top: 6px; }

/* Legend */
#layer-desc { font-size: 12px; color: var(--muted); margin: 0 0 8px; line-height: 1.4; }
.legend-row { display: flex; align-items: center; font-size: 12px; padding: 3px 0; }
.swatch {
  display: inline-block;
  width: 16px; height: 12px;
  margin-right: 8px;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,0.15);
}

/* View controls */
.ctrl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.ctrl span { color: var(--text); font-weight: 600; }
.ctrl input[type=range] { display: block; width: 100%; margin-top: 4px; accent-color: var(--accent); }
.ctrl.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 4px; margin-bottom: 8px; }
.btn-row:last-of-type { grid-template-columns: 1fr 1fr; }
.btn-row button {
  padding: 7px 4px; font-size: 11px;
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 6px;
  cursor: pointer;
}
.btn-row button:hover { background: rgba(255,255,255,0.08); border-color: var(--accent-soft); }
button#reset { background: var(--accent); color: #fff; border: 0; font-weight: 600; }
button#reset:hover { background: #ff7474; }
button#screenshot { background: var(--accent2); color: #04111f; border: 0; font-weight: 600; }
button#screenshot:hover { background: #7ed3ff; }
button#sim-play { background: linear-gradient(135deg,#ffb05a,#ff6a3d); color: #2a1305; border: 0; font-weight: 700; }
button#sim-play:hover { filter: brightness(1.1); }
button#sim-reset { background: rgba(255,255,255,0.06); }
#sim-status { color: var(--accent-soft); }

button.mode-btn {
  width: 100%;
  padding: 9px;
  background: linear-gradient(135deg, #2b6cb0, #4ec3ff);
  color: #04111f;
  border: 0; border-radius: 6px;
  font-weight: 700; font-size: 13px;
  cursor: pointer;
}
button.mode-btn:hover { filter: brightness(1.08); }
#mode-indicator { color: var(--accent2); }

/* Stats */
.stat {
  display: flex; justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(255,255,255,0.08);
  font-size: 12px;
}
.stat span { color: var(--muted); }
.stat b { color: var(--text); }
.stat.bold b { color: var(--accent-soft); }

.hint { margin-top: 12px; font-size: 11px; color: var(--muted); font-style: italic; }

/* Precision-zoom indicator */
#precision-indicator {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: rgba(78, 195, 255, 0.92);
  color: #04111f;
  padding: 6px 14px;
  border-radius: 18px;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 20;
}
#precision-indicator.on { opacity: 1; }

/* Loader */
#loader {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 100;
}
#loader-text { margin-top: 14px; color: var(--muted); font-size: 13px; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid #243044;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 2D Leaflet minimap (toggleable overlay, bottom-right) */
#minimap-wrap {
  position: fixed;
  right: 16px; bottom: 16px;
  width: 460px; height: 380px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px;
  backdrop-filter: blur(8px);
  z-index: 30;
  display: flex;
  flex-direction: column;
}
#minimap {
  flex: 1;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #1f2733;
}
.minimap-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--accent-soft);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0 2px 6px;
}
.minimap-title a {
  color: var(--muted);
  text-decoration: none;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
}
.minimap-title a:hover { color: var(--accent); }
.minimap-hint {
  margin: 6px 0 0;
  font-size: 10.5px; color: var(--muted); font-style: italic;
  text-align: center;
}
/* Leaflet overrides for dark theme */
.leaflet-container { background: #1a2030; font-family: 'Segoe UI', sans-serif; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: #182030; color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.leaflet-popup-content { font-size: 12px; margin: 8px 12px; }
.leaflet-control-attribution {
  background: rgba(20,26,38,0.85) !important;
  color: var(--muted) !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: var(--accent2); }

/* =========================================================================
   Floating action buttons (mobile only). Hidden on desktop, shown on phones
   to let the user toggle the panels + minimap, which become bottom sheets.
   ========================================================================= */
.fab {
  position: fixed;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 20px; line-height: 1;
  backdrop-filter: blur(8px);
  cursor: pointer;
  display: none;            /* hidden on desktop */
  align-items: center; justify-content: center;
  z-index: 40;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  -webkit-tap-highlight-color: transparent;
}
.fab:active { transform: scale(0.94); }
.fab.active { background: var(--accent); color: #fff; }
.fab svg { width: 22px; height: 22px; }
.fab.active svg { color: #fff; }

.panel-close {
  display: none;            /* hidden on desktop */
  position: absolute;
  top: 6px; right: 8px;
  width: 34px; height: 34px;
  border: 0; border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  cursor: pointer;
  z-index: 2;
  padding: 0;
}
.panel-close:hover { background: rgba(255,90,90,0.25); }
.panel-close svg { width: 18px; height: 18px; }

/* Minimap close link - SVG icon */
.minimap-title a svg { width: 14px; height: 14px; vertical-align: middle; }

/* =========================================================================
   Tablet (1100 - 769px): narrower panels + smaller minimap.
   ========================================================================= */
@media (max-width: 1100px) and (min-width: 769px) {
  #panel { width: 250px; padding: 12px 13px; }
  #stats { width: 240px; padding: 12px 13px; }
  #minimap-wrap { width: 300px; height: 240px; }
  #title { max-width: calc(100vw - 540px); }
}

/* =========================================================================
   Mobile (<=768px): panels become bottom-sheet drawers controlled by FABs.
   The 3D scene goes fullscreen by default; user pops up panels as needed.
   ========================================================================= */
@media (max-width: 768px) {
  /* Compact title bar at the top centre */
  #title {
    top: 10px;
    padding: 6px 14px;
    max-width: calc(100vw - 130px);
    border-radius: 8px;
  }
  #title h1 { font-size: 12px; }
  #title p  { font-size: 9.5px; margin-top: 2px; }

  /* Show the floating buttons */
  .fab        { display: flex; }
  .fab-panel  { top: 12px; left: 12px; }
  .fab-stats  { top: 12px; right: 12px; }
  .fab-mini   { bottom: 14px; right: 14px; }

  /* Show the in-panel close buttons */
  .panel-close { display: flex; align-items: center; justify-content: center; }

  /* Panels become full-width bottom sheets */
  #panel, #stats {
    top: auto;
    left: 0; right: 0;
    bottom: 0;
    width: 100%;
    max-height: 75vh;
    border-radius: 14px 14px 0 0;
    border-bottom: 0;
    padding: 18px 16px 24px;
    transform: translateY(102%);          /* off-screen by default */
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 35;
  }
  #panel.open, #stats.open { transform: translateY(0); }

  /* Stack the 3-up button rows as 2-up to fit narrow screens */
  .btn-row { grid-template-columns: 1fr 1fr; }

  /* Minimap: properly sized for phones, hidden by default; FAB toggles it.
     Sits above the bottom FAB so it doesn't get covered by the button. */
  #minimap-wrap {
    width: calc(100vw - 24px);    /* almost full width */
    max-width: 420px;             /* but cap on bigger phones */
    height: 320px;                /* tall enough to actually read */
    right: 12px; left: 12px;
    bottom: 76px;                 /* clear the bottom-right FAB */
    margin: 0 auto;
    padding: 8px;
    display: none;                /* off by default on phones */
  }
  #minimap-wrap.mobile-show { display: flex; }
  .minimap-title { font-size: 10.5px; padding-bottom: 5px; }
  .minimap-hint { display: none; }

  /* Smaller padding inside sections to fit phone height */
  #panel section + section { margin-top: 10px; }
  h2 { font-size: 10.5px; }
  .layer { padding: 7px 9px; font-size: 12.5px; }
  .scenario { padding: 6px 4px; font-size: 11.5px; }
}

/* Tiny phones (<=380px): squeeze title, keep minimap full-width */
@media (max-width: 380px) {
  #title h1 { font-size: 11px; }
  #title p  { display: none; }
  #minimap-wrap { height: 260px; }
}
