/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #111827;
  --surface:     #1f2937;
  --surface2:    #374151;
  --border:      #374151;
  --text:        #f9fafb;
  --text-muted:  #9ca3af;
  --primary:     #10b981;
  --primary-dk:  #059669;
  --danger:      #ef4444;
  --danger-dk:   #dc2626;
  --amber:       #f59e0b;
  --radius:      12px;
  --radius-lg:   20px;
  font-size:     16px;
}

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

/* ── Layout shell ─────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo svg {
  width: 36px;
  height: 36px;
}

.map-link {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  padding: 6px 12px;
  border-radius: 20px;
  transition: background 0.15s;
}
.map-link:hover { background: color-mix(in srgb, var(--primary) 22%, transparent); }

/* ── Status badge ─────────────────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 12px 0 8px;
}
.status-badge::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
.status-idle      { background: var(--surface2); color: var(--text-muted); }
.status-recording { background: color-mix(in srgb,#ef4444 15%,transparent); color: #f87171; }
.status-recording::before { animation: pulse 1.2s infinite; }
.status-uploading { background: color-mix(in srgb,var(--amber) 15%,transparent); color: var(--amber); }
.status-done      { background: color-mix(in srgb,var(--primary) 15%,transparent); color: var(--primary); }

@keyframes pulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(1.4); }
}

/* ── GPS row ──────────────────────────────────────────────────────────────── */
#gps-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 0.875rem;
}

#gps-row svg { width: 18px; height: 18px; flex-shrink: 0; }

.gps-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

#accuracy-text { font-weight: 600; }
#accuracy-text.good { color: var(--primary); }
#accuracy-text.poor { color: var(--amber); }

#point-count { color: var(--text-muted); font-size: 0.8125rem; }

/* ── Stats grid ───────────────────────────────────────────────────────────── */
#stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.stat-value {
  font-size: 1.625rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.stat-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Time card spans full width */
.stat-card:first-child {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.stat-card:first-child .stat-value {
  font-size: 2rem;
}

/* ── Main button ──────────────────────────────────────────────────────────── */
.btn-container {
  display: flex;
  justify-content: center;
  margin: 12px 0 20px;
}

.main-btn {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  transition: transform 0.12s, box-shadow 0.12s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.main-btn svg { width: 44px; height: 44px; }

.main-btn:active { transform: scale(0.94); }
.main-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-start {
  background: linear-gradient(145deg, #10b981, #059669);
  box-shadow: 0 0 0 6px color-mix(in srgb,#10b981 20%,transparent),
              0 12px 40px color-mix(in srgb,#10b981 35%,transparent);
}
.btn-start:hover:not(:disabled) {
  box-shadow: 0 0 0 10px color-mix(in srgb,#10b981 20%,transparent),
              0 16px 48px color-mix(in srgb,#10b981 40%,transparent);
}

.btn-stop {
  background: linear-gradient(145deg, #ef4444, #dc2626);
  box-shadow: 0 0 0 6px color-mix(in srgb,#ef4444 20%,transparent),
              0 12px 40px color-mix(in srgb,#ef4444 35%,transparent);
  animation: btn-pulse 2s infinite;
}
@keyframes btn-pulse {
  0%, 100% { box-shadow: 0 0 0 6px color-mix(in srgb,#ef4444 20%,transparent), 0 12px 40px color-mix(in srgb,#ef4444 35%,transparent); }
  50%       { box-shadow: 0 0 0 16px color-mix(in srgb,#ef4444 10%,transparent), 0 16px 48px color-mix(in srgb,#ef4444 45%,transparent); }
}

/* ── Upload status ────────────────────────────────────────────────────────── */
#upload-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--surface2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result card ──────────────────────────────────────────────────────────── */
#result-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  margin-bottom: 16px;
  text-align: center;
}

.result-icon {
  width: 56px; height: 56px;
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  color: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin: 0 auto 12px;
}

#result-card h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  font-size: 0.9375rem;
  border-bottom: 1px solid var(--border);
}
.result-row:last-child { border-bottom: none; }
.result-row.muted span, .result-row.muted strong { color: var(--text-muted); font-size: 0.8125rem; }

.view-map-btn {
  display: inline-block;
  margin-top: 18px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  padding: 10px 28px;
  border-radius: 24px;
  font-weight: 600;
  font-size: 0.9375rem;
  transition: background 0.15s;
}
.view-map-btn:hover { background: var(--primary-dk); }

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash-msg {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.875rem;
  margin-bottom: 12px;
  line-height: 1.4;
}
.flash-error { background: color-mix(in srgb,#ef4444 15%,transparent); color: #fca5a5; }
.flash-info  { background: color-mix(in srgb,var(--primary) 15%,transparent); color: #6ee7b7; }

/* ── Utility ──────────────────────────────────────────────────────────────── */
[hidden] { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════════════
   MAP PAGE
   ═══════════════════════════════════════════════════════════════════════════ */
#map-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
  z-index: 10;
}

#map-header .logo { font-size: 1.125rem; }

#map-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

#route-count {
  background: var(--surface);
  padding: 4px 12px;
  border-radius: 16px;
  font-weight: 600;
  color: var(--text);
}

.record-link {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  padding: 6px 14px;
  border-radius: 20px;
  transition: background 0.15s;
}
.record-link:hover { background: color-mix(in srgb, var(--primary) 22%, transparent); }

#map { flex: 1; }

#map-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  padding: 16px 24px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.9375rem;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 100;
  pointer-events: none;
}
