:root {
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.86);
  --accent: #22c55e;
  --accent-stop: #ef4444;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

#map { position: absolute; inset: 0; z-index: 1; background: #1e293b; }

/* Live stats panel */
.panel {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 10px;
  right: 10px;
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 10px 6px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.stat { display: flex; flex-direction: column; align-items: center; }
.stat .num { font-size: 1.5rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 0.66rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Status pill */
.status {
  position: absolute;
  top: calc(var(--safe-top) + 92px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  padding: 5px 14px;
  font-size: 0.78rem;
  background: var(--panel);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.good { color: var(--accent); }
.status.warn { color: #fbbf24; }
.status.bad  { color: var(--accent-stop); }

/* Battery pill — bottom-left corner */
.battery {
  position: absolute;
  left: 10px;
  bottom: calc(var(--safe-bottom) + 26px);
  z-index: 1000;
  padding: 5px 12px;
  font-size: 0.74rem;
  background: var(--panel);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}

/* Controls */
#controls {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 18px);
  left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.ctl {
  border: none;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease;
}
.ctl:active { transform: scale(0.94); }
.ctl.primary {
  background: var(--accent);
  color: #052e16;
  padding: 16px 34px;
  font-size: 1.15rem;
}
.ctl.primary.recording { background: var(--accent-stop); color: #fff; }
.ctl.ghost {
  background: var(--panel);
  width: 52px; height: 52px;
  font-size: 1.3rem;
  display: flex; align-items: center; justify-content: center;
}

/* History drawer */
.drawer {
  position: absolute;
  inset: 0;
  z-index: 2000;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 14px calc(var(--safe-bottom) + 10px);
  transition: transform 0.25s ease;
}
.drawer.hidden { transform: translateY(100%); pointer-events: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.drawer-head h2 { margin: 0; font-size: 1.2rem; }
.walk-list { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }

.walk-card {
  background: #1e293b;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.walk-card .mini { width: 72px; height: 56px; border-radius: 8px; background: #0b1220; flex-shrink: 0; }
.walk-card .info { flex: 1; min-width: 0; }
.walk-card .info .title { font-weight: 600; font-size: 0.95rem; }
.walk-card .info .meta { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.walk-card .del { background: none; border: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 6px; }
.walk-card.empty { justify-content: center; color: var(--muted); }

/* Toast */
.toast {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 90px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  background: #1e293b;
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.85rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  max-width: 90vw;
  text-align: center;
}
.hidden { display: none !important; }

/* Pocket dim screen — almost-black so OLED pixels switch off (saves battery)
   while the Wake Lock keeps the screen technically "on" and GPS recording. */
.dim {
  position: absolute;
  inset: 0;
  z-index: 2500;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.dim-stats { text-align: center; font-variant-numeric: tabular-nums; }
#dim-dist { font-size: 2.6rem; font-weight: 700; color: #1f4d33; line-height: 1; }
#dim-dist small { font-size: 1rem; font-weight: 600; margin-left: 5px; color: #143524; }
#dim-dur { font-size: 1.5rem; margin-top: 8px; color: #143524; }
.dim-hint { font-size: 0.72rem; letter-spacing: 0.06em; color: #122a1d; }

/* Make Leaflet attribution subtle on dark UI */
.leaflet-control-attribution { font-size: 9px; opacity: 0.7; }
.leaflet-bottom { margin-bottom: 80px; }
