:root {
  --bg: #12181f;
  --surface: #1b2430;
  --surface-2: #242f3d;
  --text: #eef2f6;
  --text-dim: #9aa7b6;
  --accent: #ff6a3d;
  --accent-dim: #7a3722;
  --ok: #35c98f;
  --danger: #ff5a5a;
  --border: #2f3b4a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #0b0f14;
}

#topbar {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  left: 10px;
  right: 10px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

#topbar > * { pointer-events: auto; }

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}

.route-status {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  gap: 12px;
  justify-content: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}

.hidden { display: none !important; }

/* Bottom sheet */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 600;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -4px 24px rgba(0,0,0,.5);
  max-height: 72vh;
  overflow-y: auto;
  padding-bottom: calc(var(--safe-bottom) + 14px);
  transition: transform .25s ease;
}

.sheet.collapsed {
  transform: translateY(calc(100% - 64px));
}

.sheet-handle {
  width: 40px;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin: 10px auto 4px;
}

.sheet-content {
  padding: 4px 18px 8px;
}

.sheet-title {
  font-size: 17px;
  margin: 4px 0 14px;
  color: var(--text);
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 32px;
}

output { color: var(--accent); font-weight: 600; }

.compass-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.compass {
  width: 160px;
  height: 160px;
  touch-action: none;
  user-select: none;
}

.compass-ring {
  fill: var(--surface-2);
  stroke: var(--border);
  stroke-width: 2;
}

.compass-label {
  fill: var(--text-dim);
  font-size: 14px;
  text-anchor: middle;
}

.compass-needle {
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
}

.compass-hub {
  fill: var(--accent);
}

.compass-readout {
  font-size: 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.checkboxes {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  color: var(--text);
}

.checkbox input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.hint {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 16px;
}

.hint strong { color: var(--text); }

.actions-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 14px 10px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #1a0d06;
}

.btn-primary:disabled {
  background: var(--accent-dim);
  color: #6b5347;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.file-btn {
  text-align: center;
}

.error-box {
  background: rgba(255,90,90,.12);
  border: 1px solid var(--danger);
  color: #ffb3b3;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

/* Drive mode */
.drive-overlay {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 700;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  background: linear-gradient(to top, rgba(0,0,0,.85), rgba(0,0,0,0));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.drive-info {
  display: flex;
  align-items: baseline;
  gap: 18px;
  background: rgba(18,24,31,.85);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 22px;
}

.drive-speed {
  font-size: 40px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.drive-speed small {
  font-size: 14px;
  color: var(--text-dim);
  margin-left: 6px;
}

.drive-meta {
  font-size: 13px;
  color: var(--text-dim);
}

.btn-exit {
  width: 100%;
  max-width: 320px;
  background: var(--danger);
  color: #2a0000;
}

/* Spinner */
.spinner {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner-ring {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.leaflet-control-attribution {
  font-size: 10px;
}

/* Marker styles */
.start-marker-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ok);
  border: 3px solid #0b3d2a;
  box-shadow: 0 0 0 4px rgba(53,201,143,.25);
}

.drive-marker-icon {
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.5));
}

@media (min-width: 700px) {
  .sheet {
    left: 16px;
    right: auto;
    width: 360px;
    bottom: 16px;
    border-radius: 18px;
    max-height: 80vh;
  }
  .sheet.collapsed {
    transform: translateY(calc(100% - 200px));
  }
}
