/* 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;
}

/* 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: 16px 12px;
  /* 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%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 12px;
  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: 60px; 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:6px 10px; border-radius:8px; }
.tb-nav a:hover { background: var(--bg-soft); color: var(--text); }
.tb-nav a.active { background: var(--primary); color: #fff; }

/* Layout */
#layout-container {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0px;
  max-width: 12000px;
  margin: 0 auto;
}

/* Hide stray aside that reused the same id */
aside#layout-container { display: none !important; }

/* Left Settings Bar */
#topbar { display: none !important; }

#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);
}

/* Right Settings Bar */
#right-sidebar {
  width: 380px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
  max-height: calc(100vh - 8px);
}

#left-sidebar .ls-header { display:flex; align-items:center; justify-content:space-between; gap:8px; }
#left-sidebar h2 { margin: 0 0 10px; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-collapse {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
}
.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; }

/* Settings rows ??subtle cards */
.setting-row {
  padding: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: grid;
  gap: 6px;
}
.setting-row label { margin: 0; font-size: 12px; color: var(--muted); }
.setting-row input { margin: 0; }

/* 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);
}

/* 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;
  /* Performance: drop-shadows on thousands of nodes are expensive */
  filter: none;
  pointer-events: none;
}

/* 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 */
.coast-outline {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 940;
}
.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: 16px; }
/* Hide manual panel only in the right sidebar; allow it in KES left */
#sidebar #manual-stations { display: none !important; }
#manual-stations h3 {
  margin: 8px 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
#manual-stations-list {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
#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);
}

/* 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; }

.setting-row.setting-dual{display:grid;grid-template-columns:1fr 1fr;gap:12px;align-items:end;} .setting-row.setting-dual input{width:100%;}
/* === 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; }
