*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0e1a;
  --surface: #0f1424;
  --surface2: #141a30;
  --border: #1e2740;
  --text: #e2e8f0;
  --text-dim: #9aabc4;
  --text-muted: #6b7fa0;
  --accent-gold: #f0c040;
  --accent-cyan: #38bdf8;
  --glow-gold: 0 0 40px rgba(240,192,64,0.15);
  --glow-cyan: 0 0 40px rgba(56,189,248,0.15);

}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-dim: #475569;
  --text-muted: #64748b;
  --accent-gold: #d97706;
  --accent-cyan: #0284c7;
  --glow-gold: 0 0 40px rgba(217,119,6,0.1);
  --glow-cyan: 0 0 40px rgba(2,132,199,0.1);

}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  display: flex;
  flex-direction: column;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 65%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 15%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 45%, rgba(255,255,255,0.25) 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 80%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 85%, rgba(255,255,255,0.2) 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 50%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 10%, rgba(255,255,255,0.25) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 25% 35%, rgba(240,192,64,0.3) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 75% 60%, rgba(56,189,248,0.2) 0%, transparent 100%);
  animation: twinkle 8s ease-in-out infinite alternate;
}

[data-theme="light"] body::before { display: none; }

@keyframes twinkle {
  0% { opacity: 1; }
  100% { opacity: 0.5; }
}

/* ── Layout ── */
.sidebar, .status-bar, #chartdiv { position: relative; z-index: 1; }

body { padding-top: 36px; }

.main {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ── */
.sidebar-wrap {
  width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar-export {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.section {
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

.section.section-fill {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.section.section-fill .section-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent-cyan);
  font-weight: 600;
  margin: -10px -14px 8px;
  padding: 6px 14px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-title::before {
  content: '\25BC';
  font-size: 7px;
  transition: transform 0.2s;
}

.section.collapsed .section-title::before { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.row:last-child { margin-bottom: 0; }

label.row-label {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 52px;
  flex-shrink: 0;
}

select, input[type="text"] {
  flex: 1;
  min-width: 0;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  outline: none;
  cursor: pointer;
}

select:focus, input[type="text"]:focus { border-color: var(--accent-cyan); }
select option { background: var(--bg); color: var(--text); }

/* ── Checkbox ── */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.checkbox-row:last-child { margin-bottom: 0; }

.row input[type="checkbox"], .checkbox-row input[type="checkbox"] {
  accent-color: var(--accent-cyan);
  cursor: pointer;
  flex-shrink: 0;
}

.checkbox-row label {
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
}

/* ── Settings sub-sections ── */
.settings-divider {
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.settings-subtitle {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.range-row input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.range-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: none;
  cursor: pointer;
}

.range-row input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: none;
  cursor: pointer;
}

.range-value {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  min-width: 42px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Status Picker ── */
/* ── Country List ── */
input.country-filter {
  width: 100%;
  height: 28px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  flex: 0 0 28px;
  outline: none;
  margin-bottom: 6px;
}

.country-filter:focus { border-color: var(--accent-cyan); }
.country-filter::placeholder { color: var(--text-muted); }

.country-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.continent-group {
  flex-shrink: 0;
}

.continent-group.expanded {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.continent-group:first-child .continent-header { margin-top: 0; }

.continent-header {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-cyan);
  font-weight: 600;
  padding: 6px 4px 2px;
  margin-top: 4px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.continent-header:hover { color: var(--text); }

.continent-arrow {
  display: inline-block;
  margin-right: 3px;
  font-size: 8px;
  transition: transform 0.15s;
}

.continent-group.expanded .continent-arrow { transform: rotate(90deg); }

.continent-items {
  display: none;
}

.continent-group.expanded .continent-items {
  display: block;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.continent-group.expanded .continent-items::-webkit-scrollbar { width: 4px; }
.continent-group.expanded .continent-items::-webkit-scrollbar-track { background: transparent; }
.continent-group.expanded .continent-items::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.continent-count {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 9px;
}

.country-item {
  font-size: 11px;
  color: var(--text-dim);
  padding: 3px 4px;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s, color 0.15s;
}
.country-item.visited {
  opacity: 0.5;
}

.country-item:hover,
.country-item.highlighted {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

.country-item .country-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ── */
.btn-export {
  width: 100%;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  background: var(--accent-cyan);
  color: #fff;
  border: 1px solid var(--accent-cyan);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.btn-export:hover {
  box-shadow: var(--glow-cyan);
  filter: brightness(1.15);
}

.btn-export-secondary {
  background: var(--bg);
  color: var(--text-dim);
  border-color: var(--border);
}

.btn-export-secondary:hover {
  color: var(--text);
  border-color: var(--accent-cyan);
  box-shadow: none;
  filter: none;
}

.btn-export.touring {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  animation: pulse-red 1.5s ease-in-out infinite;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ── Download row ── */
.download-row {
  display: flex;
  gap: 6px;
}

.download-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  font-weight: 500;
  padding: 7px 4px;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.download-btn:hover {
  color: var(--text);
  border-color: var(--accent-cyan);
  background: var(--surface);
}

/* ── Share row ── */
.share-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 6px;
}

.share-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
}

.share-icon:hover {
  color: var(--text);
  border-color: var(--accent-cyan);
  background: var(--surface);
}

.btn-record {
  width: 100%;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  border-radius: 8px;
  color: #f87171;
  border: 1px solid #f87171;
  background: rgba(248,113,113,0.05);
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.btn-record:hover {
  background: rgba(248,113,113,0.1);
  box-shadow: 0 0 20px rgba(248,113,113,0.15);
}

.btn-record:disabled {
  opacity: 0.35;
  cursor: default;
}

.btn-record.recording {
  background: #f87171;
  color: #fff;
  animation: pulse-record 1s ease-in-out infinite;
  cursor: default;
}

@keyframes pulse-record {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Sidebar resize handle ── */
.sidebar-resize {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.sidebar-resize:hover,
.sidebar-resize.active {
  background: var(--accent-cyan);
}

/* ── Steps panel ── */
.steps-panel {
  width: 220px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.2s;
}

.steps-panel.collapsed { width: 0; border: none; overflow: hidden; }

.steps-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.steps-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent-cyan);
  font-weight: 600;
}

.steps-header-actions {
  display: flex;
  gap: 4px;
}

.steps-autostep {
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  flex-shrink: 0;
}

.steps-clear-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  height: 22px;
  padding: 0 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  gap: 2px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.steps-clear-btn:hover {
  border-color: #f87171;
  color: #f87171;
}

.steps-add-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  height: 22px;
  padding: 0 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.steps-add-btn:hover {
  border-color: var(--accent-cyan);
  color: var(--text);
}

.steps-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.steps-list::-webkit-scrollbar { width: 4px; }
.steps-list::-webkit-scrollbar-track { background: transparent; }
.steps-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.steps-empty {
  padding: 16px 12px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

/* Step card */
.step-card {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  transition: border-color 0.15s, background 0.15s;
}

.step-card.active {
  background: rgba(56, 189, 248, 0.08);
  border-left: 2px solid var(--accent-cyan);
}

.step-card.active .step-name {
  color: var(--accent-cyan);
  font-weight: 600;
}

.step-card.drag-over {
  border-top: 2px solid var(--accent-cyan);
}

.step-card-header {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.step-name {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  padding: 2px 4px;
  border-radius: 3px;
  outline: none;
}

.step-name:hover { border-color: var(--border); }
.step-name:focus { border-color: var(--accent-cyan); background: var(--surface2); }

.step-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.step-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 18px;
  height: 18px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: all 0.15s;
  padding: 0;
}

.step-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.step-delete:hover { color: #f87171; }

/* Pin & clear-pos: hidden by default, shown only on active step */
.step-save-pos,
.step-clear-pos { display: none; }

.step-card.active .step-save-pos { display: flex; }
.step-card.active .step-clear-pos.visible { display: flex; }

.step-save-pos { font-size: 10px; }
.step-save-pos.has-position { color: #fff; }
.step-clear-pos { font-size: 9px; }
.step-clear-pos:hover { color: #f87171; }

/* Step countries */
.step-countries {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.step-country {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 12px;
  font-size: 10px;
  color: var(--text-dim);
  border-radius: 3px;
  cursor: grab;
  transition: all 0.15s;
}

.step-country:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

.step-country.dragging { opacity: 0.4; }

.step-country .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.step-country-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-country-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 10px;
  padding: 0 2px;
  opacity: 0;
  transition: all 0.15s;
}

.step-country:hover .step-country-remove { opacity: 1; }
.step-country-remove:hover { color: #f87171; }

/* Steps resize handle */
.steps-resize {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.steps-resize:hover,
.steps-resize.active {
  background: var(--accent-cyan);
}

.steps-panel.collapsed + .steps-resize { display: none; }

/* Home position button (map overlay) */
.map-home-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  opacity: 0.8;
}

.map-home-btn:hover { opacity: 1; border-color: var(--accent-cyan); }
.map-home-btn.active {
  border-color: var(--accent-cyan);
  background: rgba(56,189,248,0.15);
  opacity: 1;
}

/* ── Chart area ── */
#chartdiv {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  position: relative;
}

/* ── Status bar ── */
.status-bar {
  display: flex;
  align-items: center;
  padding: 0 14px;
  height: 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 16px;
}

.status-item {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

.status-item span { color: var(--text-dim); }

/* ── Loading overlay ── */
.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  z-index: 100;
  display: none;
  pointer-events: none;
}

.loading.visible { display: block; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1000;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.status-copyright {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 10px;
  white-space: nowrap;
}
.status-copyright a {
  color: var(--text-dim);
  text-decoration: none;
}
.status-copyright a:hover { color: var(--accent-cyan); }

/* ── Embed popup ── */
.embed-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.embed-overlay.visible { display: flex; }

.embed-popup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 480px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.embed-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.embed-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.embed-close:hover { color: var(--text); }

.embed-section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.embed-section:last-child { border-bottom: none; }

.embed-section label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.embed-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.embed-code {
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  resize: none;
  outline: none;
}

.embed-input {
  height: 32px;
}

.embed-code:focus { border-color: var(--accent-cyan); }

.embed-copy {
  margin-top: 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  padding: 5px 14px;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
}

.embed-copy:hover {
  color: var(--text);
  border-color: var(--accent-cyan);
}

/* ── Narrow viewport ── */
@media (max-width: 600px) {
  .sidebar-wrap { width: 180px; }
  .section { padding: 6px 8px; }
  .section-title { font-size: 9px; margin-bottom: 4px; }
  label.row-label { min-width: 32px; font-size: 10px; }
  .row { gap: 4px; margin-bottom: 4px; }
  select, input[type="text"] { font-size: 10px; padding: 3px 5px; }
  .btn-export { font-size: 10px; padding: 6px; }
  .status-bar { height: 20px; padding: 0 8px; gap: 8px; }
  .status-item { font-size: 9px; }
  .country-list { max-height: 180px; }
}
