:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5ef;
  --surface: #fcfdf9;
  --surface-raised: #eceee5;
  --line: rgba(20, 23, 15, 0.1);
  --line-strong: rgba(20, 23, 15, 0.22);
  --text: #14170f;
  --muted: #6c7568;
  --accent: #c9f227;
  --accent-hover: #d6fa4a;
  --accent-soft: rgba(160, 200, 20, 0.16);
  --accent-ink: #14170f;
  --ok: #4f7d0a;
  --warn: #a86500;
  --bad: #c0392b;
  --glow-1: rgba(170, 205, 30, 0.16);
  --glow-2: rgba(70, 120, 255, 0.05);
  --map-dot: rgba(20, 23, 15, 0.09);
  --map-fade: rgba(244, 245, 239, 0.6);
  --glass: rgba(252, 253, 249, 0.82);
  --toast-bg: rgba(252, 253, 249, 0.96);
  --route: #4f7d0a;
  --route-halo: rgba(120, 165, 10, 0.2);
  --route-start: rgba(20, 23, 15, 0.45);
  --dot-glow: rgba(79, 125, 10, 0.4);
  --card-shadow: 0 12px 32px rgba(20, 23, 15, 0.06);
  --radius: 24px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #212328;
  --surface: #2b2e34;
  --surface-raised: #353941;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.26);
  --text: #f5f7f1;
  --muted: #aeb5ac;
  --accent: #d8ff3e;
  --accent-hover: #e2ff6b;
  --accent-soft: rgba(216, 255, 62, 0.16);
  --accent-ink: #12150a;
  --ok: #d8ff3e;
  --warn: #ffb648;
  --bad: #ff6b6b;
  --glow-1: rgba(216, 255, 62, 0.14);
  --glow-2: rgba(84, 132, 255, 0.08);
  --map-dot: rgba(255, 255, 255, 0.1);
  --map-fade: rgba(43, 46, 52, 0.55);
  --glass: rgba(43, 46, 52, 0.85);
  --toast-bg: rgba(54, 58, 65, 0.97);
  --route: #d8ff3e;
  --route-halo: rgba(216, 255, 62, 0.16);
  --route-start: rgba(255, 255, 255, 0.75);
  --dot-glow: rgba(216, 255, 62, 0.7);
  --card-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(120% 55% at 50% -10%, var(--glow-1), transparent 60%),
    radial-gradient(80% 40% at 100% 8%, var(--glow-2), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 18px calc(32px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.theme-btn svg {
  display: none;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[data-theme="light"] .theme-btn .icon-moon {
  display: block;
}

[data-theme="dark"] .theme-btn .icon-sun {
  display: block;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.brand-mark {
  color: var(--route);
  font-size: 10px;
  line-height: 1;
  transform: translateY(-1px);
}

.run-card {
  margin-top: 34px;
  padding: 24px 20px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.hero {
  margin-top: 0;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.distance {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: clamp(64px, 19vw, 86px);
  font-weight: 650;
  line-height: 0.95;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: opacity 0.12s ease;
}

.distance:active {
  opacity: 0.75;
}

.distance-unit {
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
  text-decoration: underline dotted var(--line-strong);
  text-underline-offset: 5px;
}

.distance:hover .distance-unit {
  color: var(--text);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.stat {
  min-width: 0;
}

.stat .eyebrow {
  margin-bottom: 5px;
}

.stat-value {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat-unit {
  margin-left: 2px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.map-card {
  position: relative;
  height: 210px;
  margin-top: 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background-color: var(--surface);
  background-image: radial-gradient(var(--map-dot) 1px, transparent 1px);
  background-size: 20px 20px;
}

#routeCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.map-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
  background: radial-gradient(60% 60% at 50% 50%, var(--map-fade), transparent);
  transition: opacity 0.35s ease;
}

.map-empty p {
  margin: 0;
}

.map-empty.is-hidden {
  opacity: 0;
}

.map-empty-icon {
  font-size: 26px;
  line-height: 1;
  color: var(--route);
  opacity: 0.65;
}

.gps-pill {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 24px);
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text);
}

.gps-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5c635c;
}

.gps-pill[data-state="searching"] .gps-dot {
  background: var(--warn);
  animation: pulse 1.2s ease-in-out infinite;
}

.gps-pill[data-state="ok"] .gps-dot {
  background: var(--ok);
  box-shadow: 0 0 8px var(--dot-glow);
}

.gps-pill[data-state="warn"] .gps-dot {
  background: var(--warn);
}

.gps-pill[data-state="bad"] .gps-dot {
  background: var(--bad);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

.controls {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  height: 58px;
  border-radius: 18px;
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

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

.btn-primary {
  flex: 1;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
}

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

.btn-primary.is-secondary {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
}

.btn-primary.is-secondary:hover {
  background: var(--surface-raised);
}

.hint {
  min-height: 17px;
  margin: 12px 2px 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
}

.history {
  margin-top: 36px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-head h2 {
  margin: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.link {
  border: 0;
  background: none;
  padding: 4px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.link:hover {
  color: var(--text);
}

.history-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.run {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.run:first-child {
  border-top: 0;
}

.run-distance {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.run-distance span,
.run-pace span {
  margin-left: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.run-date,
.run-time {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted);
}

.run-right {
  text-align: right;
}

.run-pace {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.history-empty {
  margin: 0;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}

.app-footer {
  margin-top: 30px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  text-align: center;
}

.report-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s ease;
}

.report-btn:hover {
  color: var(--text);
}

.report-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.report-dialog {
  width: min(92vw, 420px);
  max-height: min(90dvh, 620px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.report-dialog::backdrop {
  background: rgba(10, 12, 14, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.report-dialog form {
  padding: 22px;
}

.report-dialog h2 {
  margin: 0 0 10px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.report-summary {
  margin: 0 0 18px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.report-label {
  display: block;
  margin-bottom: 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.report-dialog textarea {
  width: 100%;
  min-height: 92px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  resize: vertical;
}

.report-dialog textarea::placeholder {
  color: var(--muted);
}

.report-dialog textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.report-note {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}

.report-error {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--bad);
}

.report-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.report-cancel {
  height: 48px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.report-cancel:hover {
  background: var(--surface-raised);
}

.report-send {
  flex: 1;
  height: 48px;
  border-radius: 14px;
  font-size: 14px;
}

.report-send:disabled {
  opacity: 0.6;
  cursor: wait;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(88vw, 400px);
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--toast-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 12.5px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-height: 820px) {
  .map-card {
    height: 262px;
  }
}

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