@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

/* --- Mini Motorways Theme Variables --- */
:root {
  /* Default: Dark Mode (Night City) */
  --bg-primary: #1c2426;       /* Sandy dark slate land */
  --bg-secondary: #283133;     /* Sleek dark panel bg */
  --bg-tertiary: #202729;
  --text-primary: #ffffff;
  --text-secondary: #8b9496;
  
  --accent-red: #ff5e6c;       /* Salida Route - bold coral red */
  --accent-cyan: #00e5ff;      /* Retorno Route - bold cyan */
  --accent-grey: #485254;      /* Normal roads */
  --border-color: rgba(255, 255, 255, 0.08);
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  
  --font-title: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
  --transition-speed: 0.2s;
  
  /* High contrast, minimalist vector map filter for Dark Mode */
  --map-filter: invert(100%) hue-rotate(180deg) brightness(85%) contrast(100%) saturate(60%);
}

[data-theme="light"] {
  /* Light Mode (Day City) */
  --bg-primary: #efece1;       /* Classic Mini Motorways warm sand land */
  --bg-secondary: #ffffff;     /* Flat white panel bg */
  --bg-tertiary: #f9f8f4;
  --text-primary: #1e2426;     /* Dark charcoal text */
  --text-secondary: #687173;   /* Muted grey */
  
  --accent-red: #f14e5a;       /* Salida Route - solid flat red */
  --accent-cyan: #1cb3c9;      /* Retorno Route - solid flat cyan */
  --accent-grey: #ced5db;      /* Clean grey roads */
  --border-color: rgba(0, 0, 0, 0.06);
  --card-shadow: 0 8px 24px rgba(30, 36, 38, 0.08);
  
  /* Minimalist sepia-tinted map filter to make standard tiles look flat and sandy */
  --map-filter: sepia(0.3) grayscale(0.4) contrast(1.1) brightness(0.98) saturate(90%);
}

/* --- Reset & Layout --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  position: relative;
  transition: background-color var(--transition-speed);
}

/* --- Full Screen Map Wrapper --- */
.map-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#map {
  width: 100%;
  height: 100%;
}

/* --- Floating Game Title Panel (Top-Left) --- */
.game-title-panel {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  border-radius: 12px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
  transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

.motorways-icon {
  width: 24px;
  height: 24px;
  background-color: var(--accent-red);
  border-radius: 6px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: logo-bounce 2s infinite alternate ease-in-out;
}

.motorways-icon::before {
  content: '';
  width: 12px;
  height: 12px;
  border: 2px solid var(--bg-secondary);
  border-radius: 3px;
}

.title-text-container {
  display: flex;
  flex-direction: column;
}

.game-title-panel h1 {
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  line-height: 1.1;
}

.game-subtitle {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

/* --- Floating Sidebar panel (Floating Left) --- */
.floating-sidebar {
  position: fixed;
  top: 90px;
  left: 20px;
  width: 360px;
  max-height: calc(100vh - 120px);
  z-index: 10;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all var(--transition-speed) ease;
}

/* Tabs: Selector de Rutas (Salida vs Retorno) */
.tab-container {
  display: flex;
  background-color: var(--bg-tertiary);
  padding: 6px;
  border-bottom: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.tab-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-secondary);
  transition: transform 0.2s ease, background-color 0.2s;
}

/* Active tab styles matching Mini Motorways road colors */
.tab-btn.active[data-route="salida"] {
  color: var(--accent-red);
  background-color: var(--bg-secondary);
}
.tab-btn.active[data-route="salida"] .tab-indicator {
  background-color: var(--accent-red);
  transform: scale(1.3);
}

.tab-btn.active[data-route="retorno"] {
  color: var(--accent-cyan);
  background-color: var(--bg-secondary);
}
.tab-btn.active[data-route="retorno"] .tab-indicator {
  background-color: var(--accent-cyan);
  transform: scale(1.3);
}

/* Sidebar Scrollable Panel */
.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.panel-content::-webkit-scrollbar {
  width: 5px;
}
.panel-content::-webkit-scrollbar-track {
  background: transparent;
}
.panel-content::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 10px;
}

/* Flat Stats Container */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  background-color: var(--bg-tertiary);
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.stat-val {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.stat-unit {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* --- Itinerary List (Flat Mini Motorways list style) --- */
.itinerary-list {
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: 22px;
}

.itinerary-list::before {
  content: '';
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 6px;
  width: 3px;
  background-color: var(--border-color);
}

.itinerary-list.route-salida::before {
  background-color: var(--accent-red);
  opacity: 0.4;
}
.itinerary-list.route-retorno::before {
  background-color: var(--accent-cyan);
  opacity: 0.4;
}

.itinerary-item {
  position: relative;
  padding-bottom: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: transform 0.2s ease;
}

.itinerary-item:last-child {
  padding-bottom: 0;
}

.itinerary-item:hover {
  transform: translateX(4px);
}

/* Timeline dot styled as mini road intersection */
.itinerary-dot {
  position: absolute;
  left: -22px;
  top: 50%;
  transform: translateY(-50%);
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background-color: var(--bg-secondary);
  border: 2px solid var(--text-secondary);
  z-index: 2;
  transition: all 0.2s ease;
}

.route-salida .itinerary-item:hover .itinerary-dot,
.route-salida .itinerary-item.active-stop .itinerary-dot {
  border-color: var(--accent-red);
  background-color: var(--accent-red);
  transform: translateY(-50%) scale(1.3);
}

.route-retorno .itinerary-item:hover .itinerary-dot,
.route-retorno .itinerary-item.active-stop .itinerary-dot {
  border-color: var(--accent-cyan);
  background-color: var(--accent-cyan);
  transform: translateY(-50%) scale(1.3);
}

/* Tag indicator for direction action (INI, FTE, VD, etc.) */
.item-tag {
  display: inline-block;
  font-size: 0.55rem;
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 700;
  margin-right: 6px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.itinerary-es {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
}

.itinerary-item.active-stop .itinerary-es {
  font-weight: 700;
}

.route-salida .itinerary-item.active-stop .itinerary-es {
  color: var(--accent-red);
}
.route-retorno .itinerary-item.active-stop .itinerary-es {
  color: var(--accent-cyan);
}

/* --- Floating Game HUD controls (Top-Right) --- */
.game-hud-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

/* Score Panel: Contador de Pasajeros */
.score-panel {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  border-radius: 12px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background-color var(--transition-speed);
}

.score-pin {
  font-size: 1.1rem;
  color: var(--accent-red);
  animation: pulse-pin 2s infinite ease-in-out;
}

.score-panel.route-retorno .score-pin {
  color: var(--accent-cyan);
}

.score-value {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text-primary);
  min-width: 40px;
  text-align: right;
  letter-spacing: 0.5px;
}

/* Control de Tiempo / Velocidad (Clock + Speed Controls) */
.time-controls {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Mini Clock Widget */
.clock-widget {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid var(--text-secondary);
  position: relative;
  margin: 0 4px;
}

.clock-widget::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 12px;
  width: 2.5px;
  height: 12px;
  background-color: var(--text-primary);
  border-radius: 2px;
  transform-origin: bottom center;
  animation: clock-spin 10s linear infinite;
}

.clock-widget.paused::before {
  animation-play-state: paused;
}
.clock-widget.speed-2::before {
  animation-duration: 4s;
}

/* HUD Round buttons */
.hud-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.hud-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.hud-btn.active {
  background-color: var(--text-primary);
  color: var(--bg-secondary);
}

/* --- Floating Utilities Controls (Bottom-Right) --- */
.bottom-controls {
  position: fixed;
  bottom: 25px;
  right: 20px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-circle-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.hud-circle-btn:hover {
  transform: scale(1.08);
  border-color: var(--text-primary);
}

/* --- MAP ELEMENTS STYLING (Mini Motorways flat assets) --- */

.leaflet-tile-container img {
  filter: var(--map-filter);
  transition: filter var(--transition-speed) ease;
}

/* Flat rounded tooltip popups */
.leaflet-popup-content-wrapper {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 8px !important;
  box-shadow: var(--card-shadow) !important;
}

.leaflet-popup-tip {
  background-color: var(--bg-secondary) !important;
  border: 1px solid var(--border-color);
}

/* Leaflet Zoom control override */
.leaflet-bar {
  border: 1px solid var(--border-color) !important;
  box-shadow: var(--card-shadow) !important;
  border-radius: 8px !important;
  overflow: hidden;
}

.leaflet-bar a {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-bottom: 1px solid var(--border-color) !important;
}

.leaflet-bar a:hover {
  background-color: var(--bg-tertiary) !important;
  color: var(--text-primary) !important;
}

/* --- CUSTOM GAME-STYLE MARKERS (Houses & Offices) --- */

/* Destination Office (Large rounded colored squares) */
.office-destination {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.office-card {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background-color: var(--bg-secondary);
  border: 3px solid var(--accent-red);
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  animation: kawaii-marker-bounce 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

.office-card::after {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--accent-red);
  border: 2.5px solid var(--bg-secondary);
}

.office-card.retorno {
  border-color: var(--accent-cyan);
}
.office-card.retorno::after {
  background-color: var(--accent-cyan);
}

/* Pin indicator on destination */
.office-pin {
  position: absolute;
  top: -12px;
  font-size: 0.8rem;
  color: var(--accent-red);
  animation: logo-bounce 1s infinite alternate ease-in-out;
}
.office-card.retorno .office-pin {
  color: var(--accent-cyan);
}

/* Spawned Houses (Tiny colored squares with triangles) */
.spawned-houses {
  display: flex;
  gap: 4px;
  align-items: flex-end;
}

.house-item {
  width: 12px;
  height: 10px;
  background-color: var(--accent-red);
  position: relative;
  border-radius: 1px;
  animation: kawaii-house-bounce 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

/* Triangle roof */
.house-item::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 0;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--accent-red);
}

.house-item.retorno {
  background-color: var(--accent-cyan);
}
.house-item.retorno::before {
  border-bottom-color: var(--accent-cyan);
}

/* --- Simulated Vehicle / Tiny Capsule Coche --- */
.sim-car-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.mini-car {
  width: 22px;
  height: 11px;
  border-radius: 4px;
  background-color: var(--accent-red);
  border: 2px solid var(--bg-secondary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  position: relative;
  transition: transform 0.15s linear;
}

/* Headlights */
.mini-car::after {
  content: '';
  position: absolute;
  right: -2px;
  top: 1.5px;
  width: 2px;
  height: 4px;
  background-color: #ffd54f;
  border-radius: 1px;
}

.mini-car.retorno {
  background-color: var(--accent-cyan);
}

/* --- Animations --- */
@keyframes clock-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes logo-bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-4px); }
}

@keyframes logo-bounce-rotate {
  0% { transform: rotate(-5deg); }
  100% { transform: rotate(5deg) scale(1.05); }
}

@keyframes pulse-pin {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px rgba(255, 94, 108, 0.4)); }
  50% { transform: scale(1.25); filter: drop-shadow(0 0 8px rgba(255, 94, 108, 0.8)); }
}

/* --- Responsive Adjustments --- */
@media (max-width: 767px) {
  .floating-sidebar {
    width: calc(100% - 40px);
    top: auto;
    bottom: 20px;
    left: 20px;
    max-height: 260px;
  }
  
  .game-title-panel {
    width: calc(100% - 40px);
  }
  
  .game-hud-container {
    top: 80px;
    right: 20px;
  }
  
  .bottom-controls {
    bottom: 290px;
  }
}

/* --- Route Selector Dropdown --- */
.game-route-select {
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-primary);
  background-color: transparent;
  border: none;
  cursor: pointer;
  outline: none;
  padding-right: 22px;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b9496' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
  background-size: 14px;
  transition: color var(--transition-speed);
}

.game-route-select:hover {
  color: var(--accent-red);
}

[data-theme="light"] .game-route-select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23687173' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

.game-route-select option {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  text-transform: none;
  font-weight: 500;
}

/* --- Welcome Panel & Disabled states --- */
.welcome-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  height: 100%;
  color: var(--text-secondary);
}

.welcome-icon {
  font-size: 3.5rem;
  color: var(--accent-red);
  margin-bottom: 20px;
  animation: logo-bounce 2s infinite alternate ease-in-out;
}

.welcome-panel h3 {
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.welcome-panel p {
  font-size: 0.85rem;
  line-height: 1.6;
}

.hud-disabled {
  pointer-events: none !important;
  opacity: 0.35 !important;
  filter: grayscale(0.5);
  transition: opacity var(--transition-speed), filter var(--transition-speed);
}

/* Pulsing effect for the route selector in the beginning */
.pulse-selector {
  animation: select-pulse 1.5s infinite alternate ease-in-out;
  border-color: var(--accent-red) !important;
}

@keyframes select-pulse {
  0% { box-shadow: var(--card-shadow); }
  100% { box-shadow: 0 0 15px rgba(241, 78, 90, 0.4); }
}

/* --- Etiquetas de Leyendas Flotantes en el Mapa --- */
.map-marker-label {
  font-family: var(--font-title);
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 3px 7px;
  box-shadow: var(--card-shadow);
  white-space: nowrap;
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 10;
  transition: background-color var(--transition-speed), border-color var(--transition-speed);
  animation: kawaii-label-bounce 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

/* --- Kawaii Animations & Elastic Pop Effects --- */
.kawaii-pop {
  animation: kawaii-panel-bounce 0.7s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes kawaii-panel-bounce {
  0% {
    transform: scale(0.92);
    opacity: 0.85;
  }
  45% {
    transform: scale(1.04);
  }
  70% {
    transform: scale(0.98);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes kawaii-marker-bounce {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  55% {
    transform: scale(1.25);
  }
  78% {
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes kawaii-house-bounce {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  55% {
    transform: scale(1.35);
  }
  78% {
    transform: scale(0.85);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes kawaii-label-bounce {
  0% {
    transform: translateX(-50%) scale(0);
    opacity: 0;
  }
  55% {
    transform: translateX(-50%) scale(1.2);
  }
  78% {
    transform: translateX(-50%) scale(0.9);
  }
  100% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

/* --- Sidebar Footer Credits --- */
.sidebar-footer {
  text-align: center;
  padding: 12px;
  background-color: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.sidebar-footer a {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 700;
  transition: color var(--transition-speed);
}

.sidebar-footer a:hover {
  color: var(--accent-red);
}

/* --- Beta Badge --- */
.beta-badge {
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 850;
  color: var(--bg-secondary);
  background-color: var(--accent-red);
  padding: 2px 4px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.5px;
  line-height: 1;
}
