﻿/* Theme */
:root {
  --bg: #f3f4f6;
  --bg-soft: #f8fafc;
  --card: #ffffff;
  --card-soft: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #4b5563;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #dc3545;
  --danger-hover: #b52634;
  --accent: #06b6d4;
  --shadow: 0 10px 25px rgba(17, 24, 39, 0.08);
  --radius: 12px;
  --drawer-width: min(86vw, 360px);
  --sheet-height: 72vh;
}

/* General */
/* Avoid extra vertical scroll caused by body padding with fixed height */
html { height: 100%; background: var(--bg); }
body { min-height: 100%; }
body {
  margin: 0;
  padding: 0 12px 16px;
  /* Use dynamic viewport units to avoid iOS/Android URL bar issues */
  min-height: 100vh;
  min-height: 100dvh;
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(59,130,246,0.08), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(6,182,212,0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

/* Prevent horizontal scroll */
html, body { overflow-x: hidden; }

/* Topbar */
.topbar {
  width: 100%;
  left: 0;
  right: 0;
  box-sizing: border-box;
  background: #fff;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: clamp(4px, 0.75vw, 7px) clamp(10px, 3vw, 16px);
  box-sizing: border-box;
  position: relative;
}
.tb-left, .tb-right { width: 120px; display:flex; align-items:center; }
.tb-left {
  position: static;
  left: auto;
  top: auto;
}
.tb-left a { display:flex; align-items:center; gap:8px; text-decoration:none; color: var(--text); font-weight:700; }
.tb-left img { height: clamp(22px, 3vw, 34px); width: auto; object-fit: contain; }
.tb-nav {
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 16px;
  flex-wrap: nowrap;
  max-width: none;
  margin: 0;
}
.tb-nav a {
  flex: 0 0 auto;
  text-align: center;
  text-decoration:none;
  color: var(--muted);
  font-weight:700;
  font-size:14px;
  padding:4px 8px;
  border-radius:10px;
}
.tb-nav a:hover { background: var(--bg-soft); color: var(--text); }
.tb-nav a.active { background: var(--primary); color: #fff; }
.tb-left { display:flex; align-items:center; gap:10px; }
.mobile-menu-btn {
  display: none;
  position: relative;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 0; /* avoid stray glyphs */
}
.mobile-menu-btn span {
  position: absolute;
  left: 11px;
  right: 11px;
  height: 2px;
  background: #0f172a;
  border-radius: 999px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.mobile-menu-btn span:nth-child(1) { top: 14px; }
.mobile-menu-btn span:nth-child(2) { top: 21px; }
.mobile-menu-btn span:nth-child(3) { top: 28px; }
.mobile-menu-btn.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.mobile-menu-btn.is-open span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.left-overlay { display: none; }

@media (max-width: 800px) {
  .topbar { padding: 4px 6px; border-radius: 10px; }
  .topbar-inner {
    gap: 12px;
    padding: 4px 6px 8px;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
  }
  .tb-left {
    position: static;
    width: auto !important;
    margin-left: 4px;
  }
  .tb-left img {
    height: 24px !important;
    width: auto !important;
  }
  .tb-nav {
    width: 80%;
    max-width: 520px;
    min-width: 240px;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 12px;
    margin: 4px auto 4px;
  }
  .tb-nav a {
    flex-basis: auto;
    width: 100%;
    border: 1px solid var(--border);
    background: var(--bg-soft);
    border-radius: 10px;
  }
  .tb-nav a.active { background: var(--primary); color: #fff; }
  /* show left collapse button on small screens */
  .ls-collapse { display: block; }
}

/* Mobile: hide the desktop static left sidebar so mobile uses collapsible UI */
@media (max-width: 768px) {
  #left-sidebar { display: block !important; }
  
  /* Mobile: hide report-panel since left-sidebar ls-report already shows it */
  .report-panel { display: none !important; }
  .report-panel .report-body { display: none; }
}

/* Layout */
#layout-container {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0px;
  max-width: 12000px;
  margin: 0 auto;
}

/* Desktop: hide dynamically-inserted left sidebar and show report-panel styled like left card */
@media (min-width: 769px) {
  /* On desktop, show the dynamically-created left sidebar and hide the temporary report-panel */
  #left-sidebar { display: block !important; width: 440px; order: 0; flex-shrink: 0; }
  .report-panel { display: none !important; }
  .report-panel .report-body { display: none; }
  /* ensure layout order: left-sidebar, map, right sidebar */
  #left-sidebar { position: relative; }
  #map-container { order: 1; flex: 1 1 auto; }
  #sidebar { order: 2; width: 350px; flex-shrink: 0; margin-top: 0; padding: 20px; }
}

/* Hide stray aside that reused the same id */
aside#layout-container { display: none !important; }

/* Left Settings Bar */
#topbar { display: none !important; }

#left-sidebar {
  width: 440px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
  position: sticky; 
  top: 88px;  
  max-height: calc(100vh - 8px);
}

#left-sidebar .ls-header { display:flex; align-items:center; justify-content:center; gap:8px; padding: 12px 0; }
#left-sidebar h2 { margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.ls-collapse {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  display: none; /* keep hidden (no mobile reveal) */
}
.ls-collapse:hover { background: var(--bg-soft); }
.collapsed { width: 28px !important; padding: 8px !important; }
.collapsed h2, .collapsed .ls-section { display: none !important; }
.ls-section { margin-top: 10px; }
.ls-toggle { width: 100%; text-align: left; background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-weight: 700; cursor: pointer; display:flex; align-items:center; justify-content:space-between; position: relative; overflow: hidden; }
.ls-toggle::before { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 1.6em; background: var(--card); }
.ls-toggle::after { content: "\25B8"; /* ▸ */ position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.ls-section.open > .ls-toggle::after { content: "\25BE"; /* ▾ */ }
.ls-body { margin-top: 8px; display: none; }
.ls-section.open .ls-body { display: block; }
.ls-body .dropdown-panel { display: grid; gap: 10px; }

/* Submenu inside manual section */
.ls-sub-toggle {
  width: 100%;
  text-align: left;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}
.ls-sub-body { display: none; margin: 8px 0; }
.ls-sub-open + .ls-sub-body { display: block; }

/* Removed topbar styles */

/* Map */
#map-container {
  flex: 2;
  max-width: 400px;
  position: relative;
  width: 100%;
  height: 400px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  box-sizing: border-box;
  overflow: hidden;
  /* Performance: isolate layout/paint to reduce scroll jank */
  contain: layout paint;
  will-change: transform;
  transform: translateZ(0);
}

/* Remove focus outline when map container is focused for keyboard control */
#map-container:focus { outline: none; }

#korea-map {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: calc(var(--radius) - 1px);
}

#coordinates {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  z-index: 10;
}

/* Sidebar */
#sidebar {
  width: 256px;
  padding: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
}

#sidebar h2 {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

#sidebar label {
  display: block;
  margin: 10px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

#sidebar input,
#sidebar select,
#sidebar button {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  box-sizing: border-box;
}

#sidebar input:focus,
#sidebar select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.2);
}

#sidebar button {
  background: linear-gradient(180deg, var(--primary), var(--primary-hover));
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
  transition: transform 0.06s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 6px 16px rgba(59,130,246,0.35);
}
#sidebar button:hover { filter: brightness(1.05); }
#sidebar button:active { transform: translateY(1px); }

/* Reset button emphasis */
#reset-simulation {
  background: linear-gradient(180deg, var(--danger), var(--danger-hover)) !important;
  box-shadow: 0 6px 16px rgba(220,53,69,0.35);
}

/* User mode toggle */
#user-mode-toggle {
  margin-bottom: 10px;
}
#user-mode-toggle #user-mode-btn {
  width: 100%;
  max-width: 220px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 10px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(34,197,94,0.25);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
#user-mode-toggle #user-mode-btn .mode-text {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.2px;
}
body[data-user-mode="basic"] #user-mode-btn .mode-text {
  left: 34px;
  right: auto;
}
body[data-user-mode="advanced"] #user-mode-btn .mode-text {
  left: 12px;
  right: auto;
}
#user-mode-toggle #user-mode-btn .mode-thumb {
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0,0,0,0.18);
  position: absolute;
  top: 3px;
  left: 3px;
  transform: translate(0, 0);
  transition: transform 0.2s ease, background 0.2s ease;
}
body[data-user-mode="basic"] #user-mode-btn {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  box-shadow: 0 6px 16px rgba(34,197,94,0.35);
}
body[data-user-mode="basic"] #user-mode-btn .mode-thumb {
  left: 4px;
  right: auto;
  transform: translateX(0);
}
body[data-user-mode="advanced"] #user-mode-btn {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  box-shadow: 0 6px 16px rgba(185,28,28,0.35);
}
body[data-user-mode="advanced"] #user-mode-btn .mode-thumb {
  left: auto;
  right: 4px;
  transform: translateX(0);
}

/* Sidebar mode label */
.mode-label {
  display: inline-block;
  margin-right: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
  background: #e2e8f0;
  color: #1f2937;
  vertical-align: middle;
}
.mode-label.basic {
  background: #e2f7ec;
  color: #166534;
}
.mode-label.advanced {
  background: #fee2e2;
  color: #991b1b;
}

/* Mode-based visibility helpers */
body[data-user-mode="basic"] .advanced-only {
  display: none !important;
}
body[data-user-mode="advanced"] .basic-only {
  display: none !important;
}

body[data-user-mode="advanced"] #epicenter-location {
  display: none !important;
}
body[data-user-mode="basic"] #toggle-epicenter-click,
body[data-user-mode="basic"] #toggle-observer-info {
  display: none !important;
}
body[data-user-mode="advanced"] #left-sidebar .city-shake-wrap,
body[data-user-mode="advanced"] #left-sidebar .tsunami-photo {
  display: none !important;
}
body[data-user-mode="advanced"] #left-sidebar .hazard-visuals {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}
body[data-user-mode="advanced"] #left-sidebar .top-pga-desc.fineprint {
  display: none !important;
}

/* Dim only the inputs when locked */
#settings input:disabled,
#settings select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.inline-toggle #user-mode-btn {
  min-width: 160px;
  width: 200px;
  max-width: 260px;
  height: 32px;
  padding: 0 14px;
  box-shadow: 0 4px 12px rgba(34,197,94,0.25);
}
.inline-toggle #user-mode-btn .mode-thumb {
  width: 24px;
  height: 24px;
  top: 4px;
  left: 4px;
}
.inline-toggle { display: inline-flex; transform: translateY(2px); }
.inline-toggle #user-mode-btn .mode-text { font-size: 13px; }

/* Preset list */
.preset-list {
  display: grid;
  gap: 8px;
}
.preset-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  box-shadow: none;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.12s ease, filter 0.1s ease;
}
.preset-item:hover { filter: brightness(1.01); box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08); }
.preset-item:active { transform: translateY(1px); }
.preset-title { font-weight: 800; color: var(--text); }
.preset-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Sidebar preset toggle button (keep white, remove neon) */
.preset-toggle {
  background: #fff !important;
  color: #0f172a !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 10px;
  box-shadow: none !important;
}

/* Epicenter & Observer */
.epicenter, .observer {
  position: absolute;
  transform: translate(-50%, -50%);
}
.epicenter {
  width: 20px;
  height: 20px;
  z-index: 20;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.45));
}
.observer {
  width: 10px;
  height: 10px;
  z-index: 15;
    box-sizing: border-box;
    background: transparent;
    color: var(--text);
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20000;
}

/* Epicenter input */
#epicenter-input {
  margin: 10px 0 16px;
  padding: 12px;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
}
#epicenter-input input {
  width: 100%;
  margin-bottom: 10px;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
}
#epicenter-input button {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--primary), var(--primary-hover));
  border: none;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(59,130,246,0.35);
}
#epicenter-input button:hover { filter: brightness(1.05); }

/* Waves */
.p-wave, .s-wave {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  border: 1px solid #ffffff;
}

.t-wave {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  border: 3px solid #1d4ed8;
  box-shadow: 0 0 18px rgba(29, 78, 216, 0.65);
  background: transparent;
  z-index: 955;
}
/* Controls */
#controls {
  margin-top: 12px;
  text-align: center;
  padding: 10px 12px;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#elapsed-time { font-weight: 800; color: var(--text); }

#speed-slider {
  width: 320px;
  max-width: 80vw;
  margin: 10px auto;
  appearance: none;
  height: 8px;
  background: linear-gradient(90deg, #22c55e 0%, #ef4444 100%);
  border-radius: 999px;
  outline: none;
}
#speed-slider::-webkit-slider-runnable-track {
  height: 8px;
  background: linear-gradient(90deg, #22c55e 0%, #ef4444 100%);
  border-radius: 999px;
}
#speed-slider::-moz-range-track {
  height: 8px;
  background: linear-gradient(90deg, #22c55e 0%, #ef4444 100%);
  border-radius: 999px;
}
#speed-slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #111827;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}
#speed-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #111827;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

/* Report */
#report-container {
  flex: 1;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  padding: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}


/* Settings cards */
.setting-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}
.setting-card.setting-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
}
.setting-card label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}
#report-container h2 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}
#report-content p { margin: 6px 0; font-size: 14px; color: var(--muted); }

/* Manual stations */
#manual-stations {
  margin-top: 20px;
  padding: 16px 16px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}
.manual-disabled {
  opacity: 0.6;
  pointer-events: none;
  filter: saturate(0.2);
}
/* Hide manual panel only in the right sidebar; allow it in KES left */
#sidebar #manual-stations { display: none !important; }
#manual-stations h3 { margin: 0; font-size: 16px; font-weight: 800; color: var(--text); }
.manual-header { display:flex; align-items:center; gap:10px; justify-content: space-between; }
.manual-pill { padding: 6px 10px; background: #ecfeff; color: #0ea5e9; border: 1px solid #bae6fd; border-radius: 999px; font-weight: 700; font-size: 12px; }
.manual-subtitle { margin: 0; font-size: 13px; color: var(--muted); }
.manual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: center;
}
.manual-grid .full-span { grid-column: 1 / 3; }
.manual-grid label { font-size: 12px; font-weight: 700; color: var(--muted); }
.manual-grid input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-soft);
  box-sizing: border-box;
}
.manual-grid input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.18); }
.manual-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.manual-actions button {
  flex: 1 1 160px;
  margin: 0;
}
.manual-actions .ghost {
  background: var(--bg-soft) !important;
  color: var(--text);
  border: 1px solid var(--border) !important;
  box-shadow: none !important;
}
.manual-list {
  margin-top: 4px;
  max-height: 180px;
  overflow: auto;
  border: 1px dashed var(--border);
  padding: 8px;
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--muted);
}
#manual-stations-list button,
button[data-remove-index] {
  background: linear-gradient(180deg, var(--danger), var(--danger-hover)) !important;
  color: #fff !important;
  border: none !important;
  padding: 6px 10px !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 12px rgba(220,53,69,0.35);
}

/* Desktop: make the primary add button pop a bit more */
@media (min-width: 769px) {
  #add-manual-station {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    color: #fff;
    border: none;
    box-shadow: 0 6px 16px rgba(14,165,233,0.35);
    font-weight: 800;
    letter-spacing: 0.1px;
    transition: transform 0.08s ease, filter 0.1s ease;
  }
  #add-manual-station:hover { filter: brightness(1.05); }
  #add-manual-station:active { transform: translateY(1px); }
  #add-manual-station:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }
}

/* Scrollbar */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: rgba(30,41,59,0.6); }
*::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.35); border-radius: 999px; }

/* === Station Info Popup (JS-created) === */
.station-popup {
  position: absolute;
  min-width: 110px; /* ~50% of previous 220px */
  max-width: 140px; /* ~50% of previous 280px */
  background: #ffffff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 6px 18px rgba(0,0,0,0.15);
  border-radius: 8px;
  padding: 5px 6px;
  font-size: 10px;
  line-height: 1.3;
  z-index: 1000;
  pointer-events: auto;
}

.station-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.station-popup-title {
  font-size: 11px;
  font-weight: 700;
}

.station-popup-close {
  border: none;
  background: transparent;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: #9ca3af;
}

/* === Wave visuals (shared properties; color set in JS) === */
.p-wave, .s-wave {
  position: absolute;
  border-radius: 50%;
  opacity: 0.5;
  pointer-events: none;
  z-index: 1000;
  box-sizing: border-box;
}

/* Distinct borders for P/S waves */
.p-wave { border: 2px solid blue; }
.s-wave { border: 2px solid red; }


/* Left sidebar banner (title-underline slot) */
.ls-banner {
  margin: 6px 0 12px 0;
  padding: 10px 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
}
.ls-banner-title {
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 4px;
  font-size: 15px;
}
.ls-banner-body {
  font-size: 13px;
  color: #475569;
  line-height: 1.45;
}


/* Left sidebar banner (title-underline slot) */
.ls-banner {
  margin: 6px 0 12px 0;
  padding: 10px 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
}
.ls-banner-title {
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 4px;
  font-size: 15px;
}
.ls-banner-body {
  font-size: 13px;
  color: #475569;
  line-height: 1.45;
}
.top-pga-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}
.top-pga-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #e2e8f0;
  background-size: cover;
  background-position: center;
  border: 1px solid #cbd5e1;
  flex-shrink: 0;
}
.top-pga-text { display:flex; flex-direction:column; gap:2px; }
.top-pga-label { font-size:12px; color:#475569; font-weight:700; }
.top-pga-value { font-size:14px; color:#0f172a; font-weight:800; }
.top-pga-desc.fineprint { color:#94a3b8; font-size:11px; }
.city-shake-wrap {
  margin-top: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  background: #e2e8f0;
}
.city-shake {
  display: block;
  width: 100%;
  height: auto;
  --shake-amp: 0px;
  transform-origin: center;
}
@keyframes city-shake {
  0%   { transform: translate3d(calc(var(--shake-amp) * -0.35), calc(var(--shake-amp) * -0.1), 0) rotate(-0.4deg); }
  25%  { transform: translate3d(calc(var(--shake-amp) * 0.6),  calc(var(--shake-amp) * 0.25), 0) rotate(0.3deg); }
  50%  { transform: translate3d(calc(var(--shake-amp) * -0.45), calc(var(--shake-amp) * 0.3), 0) rotate(-0.25deg); }
  75%  { transform: translate3d(calc(var(--shake-amp) * 0.55), calc(var(--shake-amp) * -0.25), 0) rotate(0.35deg); }
  100% { transform: translate3d(calc(var(--shake-amp) * -0.35), calc(var(--shake-amp) * -0.1), 0) rotate(-0.4deg); }
}
.tsunami-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}
.tsunami-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #e2e8f0;
  background-size: cover;
  background-position: center;
  border: 1px solid #cbd5e1;
  flex-shrink: 0;
}
.tsunami-text { display:flex; flex-direction:column; gap:2px; }
.tsunami-label { font-size:12px; color:#475569; font-weight:700; }
.tsunami-value { font-size:14px; color:#0f172a; font-weight:800; }
.tsunami-desc { color:#64748b; font-size:12px; }
.tsunami-photo {
  margin-top: 10px;
  position: relative;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  background: #e2e8f0;
}
.tsunami-photo img {
  display: block;
  width: 100%;
  height: auto;
}
.tsunami-photo-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--wave-height, 0px);
  /* Uniform fill (no upward gradient) so the blue shape looks solid as it rises */
  background: rgba(59,130,246,0.28);
  pointer-events: none;
  transition: height 180ms ease;
}
.briefing-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  background: var(--card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 30px rgba(17, 24, 39, 0.12);
  z-index: 3000;
  transform: translateY(0%);
  transition: transform 240ms ease, opacity 240ms ease;
}
.briefing-inline {
  position: static;
  left: auto; right: auto; bottom: auto;
  /* Full width of parent container */
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
  transform: none;
}
.briefing-hidden { transform: translateY(110%); opacity: 0; pointer-events: none; }
.briefing-inner {
  max-width: 100%;
  margin: 0 auto;
  padding: 10px 14px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center; /* center horizontally */
  justify-content: center; /* center vertically */
  gap: 4px;
}
.briefing-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; align-items: center; width: 100%; }
.briefing-title { font-weight: 800; font-size: 14px; color: var(--text); text-align: center; }
.briefing-body {
  color: var(--muted);
  font-size: 13px;
  /* Allow multiline so height can grow; keep width fixed */
  white-space: pre-line; /* preserve newlines as line breaks */
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
}

/* Colored lines by MMI level for briefing */
.briefing-body .brief-line {
  display: block;
  margin: 2px 0;
}
.briefing-body .brief-line strong { color: var(--text); }
.brief-lvl-11 { color: #b91c1c; font-weight: 700; } /* deep red */
.brief-lvl-10 { color: #dc2626; font-weight: 700; }
.brief-lvl-9  { color: #f97316; font-weight: 700; }
.brief-lvl-8  { color: #fb923c; font-weight: 700; }
.brief-lvl-7  { color: #f59e0b; font-weight: 700; }
.brief-lvl-6  { color: #ca8a04; font-weight: 700; }
.brief-lvl-5  { color: #475569; font-weight: 700; }
/* Desktop overrides: match 9_simulation.css for screens >= 769px */
@media (min-width: 769px) {
  .topbar {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 4px 8px;
    box-sizing: border-box;
  }
  .topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 1080px;
    margin: 0 auto;
  }
  .tb-left, .tb-right { width: 120px; display:flex; align-items:center; }
  .tb-left a { display:flex; align-items:center; gap:8px; text-decoration:none; color: var(--text); font-weight:700; }
  .tb-left img { height: clamp(22px, 3vw, 34px); width: auto; object-fit: contain; }
  .tb-nav { display:flex; align-items:center; gap: 16px; }
  .tb-nav a { text-decoration:none; color: var(--muted); font-weight:700; padding:4px 8px; border-radius:10px; font-size:14px; }
  .tb-nav a:hover { background: var(--bg-soft); color: var(--text); }
  .tb-nav a.active { background: var(--primary); color: #fff; }

  #layout-container { display:flex; align-items:flex-start; justify-content:flex-start; gap:0; max-width:12000px; margin:0 auto; }

  /* Left Settings Bar */
  #left-sidebar {
    width: 380px;
    padding: 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-y: auto;
    position: sticky;
    top: 88px;
    max-height: calc(100vh - 8px);
    display: block !important;
  }

  /* Map sizing */
  #map-container {
    flex: 2;
    max-width: 400px;
    position: relative;
    width: 100%;
    height: 400px;
    background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    box-sizing: border-box;
    overflow: hidden;
    contain: layout paint;
    will-change: transform;
    transform: translateZ(0);
  }

  #sidebar {
    width: 256px;
    padding: 20px;
    background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-y: auto;
  }

  /* Report panel styled like left card */
  .report-panel {
    width: 380px; /* match left-sidebar width */
    padding: 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    box-sizing: border-box;
    position: relative;
    align-self: flex-start;
    display: none !important;
    min-height: 420px; /* match map height so card fills left column */
    order: 0;
  }
  .report-panel .report-body {
    display: block !important;
  }

  #report-container {
    flex: 1;
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    padding: 14px;
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }

  /* Hide the mobile sheet toggle on desktop */
  #sidebar-toggle { display: none !important; }
}

.mobile-actions {
  display: none;
}

@media (max-width: 768px) {
  #left-sidebar { padding-bottom: 80px; } /* add breathing room at bottom for dropdowns */
  /* Right sidebar as bottom sheet */
  body.sheet-open { overflow: hidden; }
  #sidebar {
    position: fixed !important;
    left: 0;
    right: 0;
    width: 100vw;
    margin: 0 auto;
    bottom: 0;
    max-width: none;
    height: var(--sheet-height);
    max-height: 80vh;
    background: var(--card);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0,0,0,0.15);
    padding: 16px;
    color: var(--text);
    display: block !important;
    transform: translateY(100%);
    transition: transform 0.28s ease;
    z-index: 2100;
    overflow-y: auto;
  }
  #sidebar::before {
    content: "";
    display: block;
    width: 52px;
    height: 5px;
    border-radius: 999px;
    background: #cbd5e1;
    margin: 6px auto 12px;
  }
  #sidebar.open { transform: translateY(0); }
  .sheet-toggle,
  #sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    margin: 12px auto 0;
    width: 80%;
    max-width: 520px;
    box-sizing: border-box;
    background: #0ea5e9;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-weight: 800;
    box-shadow: var(--shadow);
    cursor: pointer;
  }
  /* Ensure the settings open button centers and scales like other mobile buttons */
  #sidebar-toggle,
  .mobile-actions #sidebar-toggle,
  .mobile-sheet-toggle {
    display: block;
    width: 80%;
    max-width: 520px;
    margin: 12px auto 0;
  }
  .sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(1px);
    z-index: 2050;
  }
  .sheet-overlay.show { display: block; }

  /* Mobile off-canvas left sidebar */
  body.menu-open { overflow: hidden; }
  #layout-container { flex-direction: column; gap: 12px; padding: 0 8px; }
  #left-sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    width: var(--drawer-width);
    max-width: 360px;
    height: 100vh;
    max-height: none;
    transform: translateX(-110%);
    transition: transform 0.28s ease, box-shadow 0.28s ease;
    z-index: 2000;
    border-radius: 0 12px 12px 0;
    box-shadow: none;
    padding: 16px;
  }
  #left-sidebar.open {
    transform: translateX(0);
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  }
  #left-sidebar .ls-header { justify-content: flex-start; }
  .left-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(1px);
    z-index: 1500;
  }
  .left-overlay.show { display: block; }
  .mobile-menu-btn {
    display: inline-flex;
    position: fixed;
    top: 14px;
    left: 14px;
    transform: translateX(0);
    z-index: 2200;
    transition: transform 0.28s ease;
  }
  .mobile-menu-btn.is-open {
    transform: translateX(var(--drawer-width));
  }
  /* ensure map and right sidebar order */
  #map-container { order: 1; }
  #sidebar { order: 2; }
}

@media (max-width: 768px) {
  .mobile-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
  }
  .mobile-actions button {
    width: 80%;
    max-width: 520px;
    border: none;
    padding: 12px 16px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 15px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.08s ease, filter 0.08s ease, box-shadow 0.12s ease;
  }
  .mobile-actions #start-simulation {
    background: #0ea5e9;
    color: #fff;
  }
  .mobile-actions #reset-simulation {
    background: #ef4444;
    color: #fff;
  }
  .mobile-actions button:active { transform: translateY(1px); }
  .mobile-actions button:hover { filter: brightness(1.03); }
}

