:root {
  --bg: #0a0a0a;
  --map-bg: #101010;
  --panel: #151515;
  --panel2: #1d1d1d;
  --panel3: #242424;
  --text: #f4f4f4;
  --muted: #a8a8a8;
  --line: rgba(255,255,255,.13);
  --line-strong: rgba(255,255,255,.23);
  --accent: #2f8cff;
  --danger: #ff4d73;
  --warning: #ffd166;
  --ok: #71f0a2;
  --shadow: 0 14px 34px rgba(0,0,0,.38);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: #000;
  overflow: hidden;
}

button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.app-shell {
  height: 100dvh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transition: background .24s ease;
}

.map-panel {
  position: relative;
  height: 49dvh;
  min-height: 270px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px),
    #101010;
  background-size: 34px 34px;
  overflow: hidden;
  transition: height .32s cubic-bezier(.2,.85,.2,1);
}

.app-shell.compact-mode .map-panel {
  height: 68dvh;
}

#map, .map-view {
  width: 100%;
  height: 100%;
  display: block;
}

.maplibregl-control-container { display: none; }
.maplibregl-canvas { outline: none; }
.user-marker {
  width: 32px;
  height: 32px;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 0 10px rgba(47,140,255,.85));
}
.user-marker::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 3px;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 27px solid #fff;
}
.user-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 13px;
  transform: translateX(-50%);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #2f8cff;
}
.map-error {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  text-align: center;
  color: rgba(255,255,255,.72);
  font-size: 14px;
  line-height: 1.55;
  pointer-events: none;
}

.gps-pill,
.route-pill,
.map-center-btn,
.map-attribution {
  position: absolute;
  z-index: 5;
  backdrop-filter: blur(10px);
  background: rgba(17,17,17,.86);
  border: 1px solid var(--line-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

.gps-pill {
  left: 12px;
  top: calc(12px + env(safe-area-inset-top));
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 800;
  color: var(--warning);
}

.route-pill {
  left: 12px;
  bottom: 30px;
  max-width: calc(100% - 132px);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-center-btn {
  right: 12px;
  bottom: 30px;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 800;
}

.map-attribution {
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  border: 0;
  box-shadow: none;
  background: rgba(0,0,0,.36);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 10px;
  color: rgba(255,255,255,.56);
  white-space: nowrap;
}

.dashboard {
  flex: 1;
  min-height: 0;
  padding: 10px 12px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  background: #0a0a0a;
}

.primary-stats,
.detail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  min-width: 0;
  background: linear-gradient(145deg, #181818, #121212);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.primary-stats .stat-card {
  min-height: 92px;
}

.speed-card { border-color: rgba(47,140,255,.45); }

.compact-card {
  min-height: 66px;
  padding: 10px 12px;
  background: linear-gradient(145deg, #161616, #111111);
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 7px;
  font-weight: 700;
}

.stat-value {
  font-size: clamp(34px, 8.8vw, 56px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.045em;
}

.stat-value small {
  font-size: 13px;
  color: var(--muted);
  margin-left: 4px;
  letter-spacing: 0;
}

.stat-value.compact {
  font-size: clamp(23px, 5.9vw, 34px);
  letter-spacing: -0.035em;
}

.panel-toggle {
  align-self: center;
  width: 52px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #222;
  color: #dcdcdc;
  font-size: 17px;
  line-height: 24px;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px var(--line);
}

.detail-stats {
  max-height: 150px;
  opacity: 1;
  transform: translateY(0);
  overflow: hidden;
  transition: max-height .32s cubic-bezier(.2,.85,.2,1), opacity .2s ease, transform .32s cubic-bezier(.2,.85,.2,1), margin .32s ease;
}

.app-shell.compact-mode .detail-stats {
  max-height: 0;
  opacity: 0;
  transform: translateY(42px);
  margin-top: -8px;
  pointer-events: none;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
  margin-top: auto;
}

.action-row button,
.small-btn,
.icon-btn {
  border: 0;
  border-radius: 14px;
  color: var(--text);
  padding: 13px 10px;
  font-weight: 900;
}

.primary { background: #2f8cff; }
.secondary { background: #2a2a2a; border: 1px solid var(--line-strong) !important; }
.danger { background: #ff4d73; }

.mini-info {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  padding: 0 2px;
}

.route-dialog {
  width: min(560px, calc(100vw - 22px));
  border: 0;
  padding: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--text);
}
.route-dialog::backdrop { background: rgba(0,0,0,.66); backdrop-filter: blur(4px); }
.dialog-card {
  margin: 0;
  background: #141414;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.dialog-header h2 { margin: 0; font-size: 20px; }
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  background: #252525;
  font-size: 24px;
}
.hint { color: var(--muted); font-size: 13px; margin: 12px 0; }
.upload-box {
  display: grid;
  place-items: center;
  min-height: 82px;
  border: 1px dashed rgba(47,140,255,.58);
  border-radius: 16px;
  background: rgba(47,140,255,.08);
  color: #9bcaff;
  font-weight: 900;
}
.upload-box input { display: none; }

.offline-map-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #101010;
}
.offline-map-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}
.offline-map-title span { color: var(--muted); font-weight: 800; }
.offline-map-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.danger-soft { background: rgba(255,77,115,.20) !important; }
.map-progress {
  height: 8px;
  margin-top: 10px;
  border-radius: 999px;
  background: #272727;
  overflow: hidden;
}
.map-progress div {
  width: 0%;
  height: 100%;
  background: #2f8cff;
  transition: width .15s ease;
}

.file-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 0 8px;
}
.small-btn {
  padding: 8px 10px;
  background: #252525;
  font-size: 13px;
}
.route-list {
  max-height: 42vh;
  overflow: auto;
  display: grid;
  gap: 8px;
}
.route-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: #1b1b1b;
  border: 1px solid var(--line);
}
.route-meta { min-width: 0; }
.route-title { font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.route-item button {
  border: 0;
  border-radius: 12px;
  padding: 8px 10px;
  color: var(--text);
  font-weight: 900;
  background: rgba(47,140,255,.22);
}
.route-item button.delete-route { background: rgba(255,77,115,.22); }
.empty-list { color: var(--muted); padding: 12px; text-align: center; }

.reset-dialog {
  width: min(420px, calc(100vw - 34px));
  border: 0;
  padding: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--text);
}
.reset-dialog::backdrop {
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(5px);
}
.reset-card {
  margin: 0;
  padding: 20px 18px 16px;
  border-radius: 20px;
  background: #151515;
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  text-align: center;
}
.reset-title {
  font-size: 18px;
  font-weight: 950;
  line-height: 1.35;
}
.reset-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.reset-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
}
.reset-actions button {
  border: 0;
  border-radius: 14px;
  padding: 12px 10px;
  color: var(--text);
  font-weight: 950;
}
.reset-cancel { background: #2a2a2a; }
.reset-confirm { background: #ff4d73; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  z-index: 20;
  background: rgba(16,16,16,.94);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 24px);
  text-align: center;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 820px) {
  .app-shell { max-width: 520px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

@media (max-height: 700px) {
  .map-panel { min-height: 240px; }
  .app-shell.compact-mode .map-panel { height: 64dvh; }
  .primary-stats .stat-card { min-height: 80px; }
  .compact-card { min-height: 58px; padding: 8px 10px; }
  .stat-label { font-size: 11px; margin-bottom: 4px; }
  .action-row button { padding: 10px 8px; border-radius: 12px; }
}
