:root {
  color-scheme: light;
  --bg: #f8faf9;
  --ink: #1a1c1b;
  --muted: #64748b;
  --panel: rgba(255, 255, 255, 0.82);
  --line: rgba(0, 0, 0, 0.08);
  --accent: #0f766e;
  --accent-2: #e4572e;
  --shadow: 0 12px 40px -12px rgba(0, 0, 0, 0.15);
  --radius: 12px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --panel: rgba(30, 41, 59, 0.85);
  --line: rgba(255, 255, 255, 0.1);
  --accent: #2dd4bf;
  --accent-2: #fb923c;
  --shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family:
    "Inter var", Inter, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  transition: background-color 0.5s ease;
}

button,
input,
select {
  font: inherit;
  transition: var(--transition);
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#mapCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#mapCanvas.is-dragging {
  cursor: grabbing;
}

/* Glassmorphism utility */
.glass {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  transition: var(--transition);
}

.topbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border: 3.5px solid var(--accent);
  border-right-color: var(--accent-2);
  border-bottom-color: #3b82f6;
  border-radius: 50%;
  flex: 0 0 auto;
  animation: spin-pulse 4s infinite linear;
}

@keyframes spin-pulse {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.05); }
  100% { transform: rotate(360deg) scale(1); }
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
}

.control {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.control.compact { width: 160px; }
.control.small { width: 100px; }
.control.slider { width: 110px; }
.control.toggle { width: 48px; justify-items: center; }

.control select,
.control input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  outline: none;
}

.control input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
  height: 24px;
}

.control.toggle input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  outline: none;
  font-size: 18px;
}

.icon-button:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-2px);
}

.stats-panel {
  position: absolute;
  left: 16px;
  top: 96px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 180px;
  border-radius: var(--radius);
  overflow: hidden;
  max-height: calc(100vh - 200px);
  z-index: 90;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
}

.stats-panel .stat-item {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.stats-panel .stats-note {
  padding: 8px 14px;
  color: var(--muted);
  font-size: 10px;
  font-style: italic;
  line-height: 1.4;
}

.stat-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.detail-panel {
  position: absolute;
  right: 16px;
  top: 96px;
  width: 320px;
  max-height: calc(100vh - 220px);
  overflow: auto;
  padding: 20px;
  border-radius: var(--radius);
  z-index: 90;
}

.detail-panel h2 {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.detail-body {
  display: grid;
  gap: 12px;
}

.detail-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.detail-key {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.detail-value {
  font-size: 13px;
  font-weight: 500;
  min-width: 0;
  overflow-wrap: anywhere;
}

.route-panel {
  display: none;
}

body.route-search-enabled .route-panel {
  display: block;
}

.detail-value a {
  color: var(--accent);
  text-decoration: none;
}

.detail-value a:hover {
  text-decoration: underline;
}

.line-info-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.line-info-card h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
}

.line-info-card .detail-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.route-panel {
  position: absolute;
  left: 16px;
  top: 430px;
  bottom: 110px;
  width: min(360px, calc(100vw - 32px));
  overflow: auto;
  padding: 16px;
  border-radius: var(--radius);
  z-index: 90;
}

.route-panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.route-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.route-fields label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.route-fields input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  outline: none;
}

.route-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.route-actions button {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
}

.route-actions button:first-child {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
}

.route-result {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.route-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.route-kpis div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.route-kpis strong {
  display: block;
  font-size: 16px;
}

.route-kpis span,
.route-note {
  color: var(--muted);
  font-size: 11px;
}

.route-line-list {
  margin: 0;
  padding-left: 16px;
}

.map-buttons {
  position: absolute;
  right: 16px;
  bottom: 110px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
}

.attribution {
  position: absolute;
  right: 16px;
  bottom: 80px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 500;
}

.timeline {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  border-radius: var(--radius);
  z-index: 100;
}

.timeline-controls {
  display: flex;
  gap: 8px;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.speed-control select {
  height: 32px;
  width: 70px;
}

.year-control {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-grow: 1;
}

#yearLabel {
  font-size: 32px;
  font-weight: 900;
  color: var(--accent-2);
  min-width: 80px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 10px rgba(228, 87, 46, 0.2);
}

#yearRange {
  flex-grow: 1;
}

.year-jumps {
  display: flex;
  gap: 6px;
  margin-right: 8px;
}

.year-jumps button {
  height: 28px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
}

.year-jumps button.is-active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Mobile Optimizations */
@media (max-width: 768px) {
  .topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    flex-direction: column;
    align-items: stretch;
  }

  .brand { width: 100%; justify-content: center; }

  .toolbar {
    overflow-x: auto;
    padding: 8px 4px;
    justify-content: flex-start;
  }

  .stats-panel {
    display: none; /* Hide on mobile for better view */
  }

  .detail-panel {
    left: 8px;
    right: 8px;
    bottom: 90px;
    top: auto;
    width: auto;
    max-height: 25vh;
    padding: 12px;
  }

  .timeline {
    left: 8px;
    right: 8px;
    bottom: 8px;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .timeline-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .year-control {
    width: 100%;
  }

  .year-jumps {
    display: none;
  }

  .map-buttons {
    right: 8px;
    bottom: 220px;
  }

  .route-panel {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 340px;
    width: auto;
    max-height: 24vh;
    padding: 12px;
  }

  .route-fields {
    grid-template-columns: 1fr;
  }
}

