:root {
  --bg: #0f1419;
  --surface: #1a1f2e;
  --surface-elev: #252b3d;
  --surface-2: #2a3142;
  --primary: #6C5CE7;
  --primary-2: #5e72e4;
  --primary-soft: rgba(108, 92, 231, 0.18);
  --text: #ffffff;
  --text-muted: #8b92a8;
  --text-dim: #5a6178;
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.15);
  --success: #00d2d3;
  --warning: #fdcb6e;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --touch: 64px;
  --touch-lg: 80px;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

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

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.screen.hidden {
  display: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

input {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

.hidden {
  display: none !important;
}

#home-screen {
  padding: calc(var(--safe-top) + 32px) 24px calc(var(--safe-bottom) + 24px);
  overflow-y: auto;
  gap: 32px;
}

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 0 8px;
}

.home-logo {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.home-title {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 1px;
}

.home-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

.home-content {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: var(--touch);
  padding: 0 24px;
  border-radius: var(--radius);
  font-weight: 600;
  transition: transform 0.1s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-2);
}

.btn-huge {
  min-height: var(--touch-lg);
  font-size: 20px;
  padding: 0 32px;
  border-radius: var(--radius-lg);
}

.btn-huge i {
  font-size: 28px;
}

.quick-dest {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 96px;
  padding: 12px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

.quick-btn:active {
  background: var(--surface-elev);
}

.quick-btn i {
  font-size: 32px;
  color: var(--primary);
}

.recent-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  padding: 0 4px 4px;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  width: 100%;
}

.recent-item:active {
  background: var(--surface-elev);
}

.recent-item i {
  font-size: 24px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.recent-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.recent-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-addr {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-empty {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 20px 16px;
  font-style: italic;
}

.recent-empty.hidden {
  display: none;
}

.recent-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  font-size: 18px;
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
}

.recent-remove:hover {
  color: var(--danger);
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#nav-screen {
  background: var(--bg);
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  color: var(--text);
  flex-shrink: 0;
}

.icon-btn:active {
  background: var(--surface-elev);
}

.icon-btn i {
  font-size: 26px;
}

.street-name {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.stats-bar {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  align-items: center;
  gap: 4px;
  padding: 8px 12px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: var(--radius);
  background: var(--surface-elev);
  border: 1px solid var(--border);
  font-family: inherit;
  color: var(--text);
  cursor: default;
  min-height: 76px;
}

.stat-speed {
  color: var(--success);
}

.stat-eta {
  align-items: center;
}

.stat-battery {
  cursor: pointer;
  color: var(--success);
}

.stat-battery:active {
  background: var(--surface-2);
}

.stat-value {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}

.stat-speed .stat-value {
  color: var(--success);
  transition: color 0.2s;
}

.stat-speed .stat-value.warn { color: var(--warning); }
.stat-speed .stat-value.danger { color: var(--danger); }

.stat-unit {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-label {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  line-height: 1;
}

.stat-sub {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stat-battery .stat-value {
  font-size: 30px;
}

.stat-battery i {
  font-size: 22px;
  color: var(--success);
  transition: color 0.2s;
}

.stat-battery.battery-mid i,
.stat-battery.battery-mid .stat-value { color: var(--warning); }
.stat-battery.battery-low i,
.stat-battery.battery-low .stat-value { color: var(--danger); }

.battery-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.battery-chip:hover, .battery-chip:focus {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.battery-chip i {
  font-size: 22px;
  color: var(--success);
  transition: color 0.2s;
}

.battery-chip.battery-mid i { color: var(--warning); }
.battery-chip.battery-low i { color: var(--danger); }

.battery-pct {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--success);
  transition: color 0.2s;
}

.battery-chip.battery-mid .battery-pct { color: var(--warning); }
.battery-chip.battery-low .battery-pct { color: var(--danger); }

.battery-range {
  font-size: 14px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.battery-chip-sm .battery-pct {
  font-size: 15px;
}

.battery-chip-sm i {
  font-size: 18px;
}

.eta-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  padding: 4px 10px 6px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
  line-height: 1.15;
  min-height: 44px;
  justify-content: center;
}

.eta-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  font-weight: 600;
}

.eta-arrival {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.eta-remaining {
  font-size: 14px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.home-top {
  display: flex;
  justify-content: flex-end;
  padding-top: var(--safe-top);
}

#home-screen .battery-chip {
  min-height: 56px;
  padding: 8px 16px;
}

.map-area {
  flex: 1;
  position: relative;
  background: var(--surface);
  overflow: hidden;
}

.map-container {
  position: absolute;
  inset: 0;
}

.map-status {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 10px 16px;
  background: rgba(15, 20, 25, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
}

.vagar-position-dot {
  width: 22px;
  height: 22px;
  position: relative;
}
.vagar-position-dot .dot-core {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.vagar-dest-pin {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.vagar-dest-pin i {
  font-size: 32px;
  color: var(--danger);
}

.recenter-btn {
  display: none;
}

.map-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
  background:
    linear-gradient(135deg, var(--surface) 0%, var(--surface-elev) 100%);
}

.map-placeholder i {
  font-size: 72px;
  color: var(--text-dim);
  opacity: 0.5;
}

.map-placeholder p {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.map-placeholder small {
  font-size: 14px;
  color: var(--text-muted);
}

.nav-card {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 140px;
  padding: 18px 20px;
  padding-bottom: calc(18px + var(--safe-bottom));
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-elev) 100%);
  border-top: 1px solid var(--border-strong);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}

.maneuver-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  border-radius: 26px;
  background: var(--primary);
  color: white;
  flex-shrink: 0;
  box-shadow: 0 4px 16px var(--primary-soft);
}

.maneuver-icon i {
  font-size: 60px;
}

.maneuver-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.maneuver-distance {
  font-size: 48px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -1.5px;
}

.maneuver-instruction {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-top: 4px;
  line-height: 1.1;
}

.maneuver-street {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.action-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 56px;
  padding: 8px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.action-btn:active {
  background: var(--surface-elev);
}

.action-btn i {
  font-size: 20px;
  color: var(--primary);
}

.action-btn.action-danger i {
  color: var(--danger);
}

.action-btn.action-icon-only {
  flex: 0 0 56px;
  min-width: 56px;
  padding: 8px;
}

.action-btn.action-icon-only i {
  font-size: 26px;
}

#search-screen {
  background: var(--bg);
}

.search-input {
  flex: 1;
  height: 48px;
  font-size: 17px;
  background: var(--surface-elev);
  border-radius: var(--radius);
  padding: 0 16px;
  color: var(--text);
}

.search-input::placeholder {
  color: var(--text-dim);
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}

.search-status {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 16px;
  font-size: 14px;
}

.search-status:empty {
  display: none;
}

.result-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.result-item:hover, .result-item:focus {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.result-item i {
  font-size: 22px;
  color: var(--primary);
  flex-shrink: 0;
}

.result-text {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-addr {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-hint {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 16px;
  font-size: 15px;
}

#calc-route-btn:disabled {
  opacity: 0.6;
}

.route-status {
  margin-top: 12px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  min-height: 20px;
}

.route-status.error {
  color: var(--danger);
}

.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 48px);
  padding: 14px 20px;
  background: var(--surface-elev);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: toast-in 0.2s ease;
}

.toast.error {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (min-width: 600px) {
  #home-screen {
    max-width: 480px;
    margin: 0 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
