:root {
  --ink: #102f2d;
  --muted: #65736f;
  --paper: #f5f0e5;
  --white: #fffdf8;
  --coral: #f06445;
  --teal: #07817a;
  --yellow: #efbd3d;
  --line: rgba(16, 47, 45, 0.15);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html, body, .app-shell, #map { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { position: relative; }
#map { background: #dbe5df; }

.panel {
  position: absolute;
  z-index: 2;
  top: 18px;
  bottom: 18px;
  left: 18px;
  width: min(390px, calc(100% - 36px));
  padding: 25px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 22px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 24px 70px rgba(16, 47, 45, 0.2);
  backdrop-filter: blur(15px);
}

.kicker {
  margin: 0 0 7px;
  color: var(--coral);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h2, p { margin-top: 0; }
h2 { margin-bottom: 0; font-size: 0.9rem; }
.intro { margin-bottom: 0; color: var(--muted); font-size: 0.9rem; }

.controls { margin-top: 25px; padding-top: 20px; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 15px; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.78rem; }
label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 0.74rem; font-weight: 700; }

.pace-row { display: flex; gap: 8px; }
input {
  min-width: 0;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: var(--white);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(7, 129, 122, 0.12); }
#start-time { width: 100%; padding: 0 10px; font-size: 0.85rem; }

.location-button, .dev-button {
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: var(--white);
  cursor: pointer;
  font-weight: 800;
}
.location-button:hover, .dev-button:hover { background: var(--teal); }
.location-button:active, .dev-button:active { transform: translateY(1px); }

.number-field {
  display: flex;
  flex: 1;
  align-items: center;
  height: 44px;
  padding-right: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
}
.number-field:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(7, 129, 122, 0.12); }
.number-field input { width: 100%; height: 42px; padding: 0 0 0 12px; border: 0; background: transparent; font-weight: 800; }
.number-field input:focus { box-shadow: none; }
.number-field span { color: var(--muted); font-size: 0.73rem; }

.progress-card {
  margin-top: 20px;
  padding: 18px;
  border-radius: 15px;
  background: var(--ink);
  color: var(--white);
}
.status-line { display: flex; align-items: center; justify-content: space-between; font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.status-pill { padding: 4px 8px; border-radius: 999px; background: var(--yellow); color: var(--ink); font-weight: 900; text-transform: uppercase; }
.status-pill.racing { background: var(--coral); color: var(--white); }
.status-pill.finished { background: var(--teal); color: var(--white); }
.distance { display: block; margin: 17px 0 12px; font: 500 3.4rem/0.9 Georgia, serif; letter-spacing: -0.05em; }
.distance small { font: 700 0.85rem/1 Inter, sans-serif; letter-spacing: 0; }
.progress-track { height: 5px; overflow: hidden; border-radius: 5px; background: rgba(255, 255, 255, 0.16); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--coral); transition: width 0.4s ease; }
.metrics { display: grid; grid-template-columns: 1fr 1.25fr 1fr; gap: 9px; margin-top: 17px; }
.metrics span, .metrics strong { display: block; }
.metrics span { margin-bottom: 3px; color: rgba(255, 255, 255, 0.58); font-size: 0.61rem; }
.metrics strong { font-size: 0.76rem; font-variant-numeric: tabular-nums; }

.location-card, .nearby-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 20px; }
.location-card p, .nearby-card p { margin: 3px 0 0; color: var(--muted); font-size: 0.72rem; }
.location-button { display: flex; align-items: center; gap: 7px; padding: 10px 12px; font-size: 0.75rem; }
.nearby-card { align-items: flex-start; padding-top: 17px; border-top: 1px solid var(--line); }
.nearby-card > div { flex: 1; }
.dev-button { flex: none; padding: 9px 10px; background: transparent; border: 1px solid var(--line); color: var(--ink); font-size: 0.7rem; }
.dev-button[aria-pressed="true"] { border-color: var(--yellow); background: var(--yellow); }
.target-icon { width: 11px; height: 11px; border: 2px solid currentColor; border-radius: 50%; box-shadow: 0 0 0 2px var(--ink), 0 0 0 3px currentColor; }
.location-button:hover .target-icon { box-shadow: 0 0 0 2px var(--teal), 0 0 0 3px currentColor; }

.quick-controls {
  position: absolute;
  z-index: 4;
  top: 18px;
  left: 50%;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 13px;
  background: rgba(255, 253, 248, 0.95);
  box-shadow: 0 8px 30px rgba(16, 47, 45, 0.18);
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
}
.quick-controls button {
  min-width: 58px;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: var(--ink);
  color: var(--white);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 900;
}
.quick-controls button:hover { background: var(--coral); }
.quick-controls span { min-width: 104px; padding: 0 10px; text-align: center; color: var(--muted); font-size: 0.7rem; font-variant-numeric: tabular-nums; }

.panel-toggle {
  position: absolute;
  z-index: 4;
  bottom: 18px;
  left: 30px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  background: var(--ink);
  color: var(--white);
  box-shadow: 0 8px 24px rgba(16, 47, 45, 0.18);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 800;
}
.panel-toggle:hover { background: var(--teal); }
.panel { transition: opacity 0.2s ease, transform 0.25s ease; }
.panel-hidden .panel { pointer-events: none; opacity: 0; transform: translateX(calc(-100% - 30px)); }
.panel-hidden .panel-toggle { left: 18px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 15px; margin-top: 20px; padding-top: 17px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.67rem; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.legend-dot.wife { background: var(--coral); }
.legend-dot.me { background: var(--teal); }
.legend-line { width: 16px; height: 3px; border-radius: 3px; background: var(--coral); }
.error { margin: 16px 0 0; padding: 10px; border-radius: 8px; background: #ffe2dc; color: #8b2917; font-size: 0.75rem; }
footer { margin-top: 17px; color: var(--muted); font-size: 0.65rem; }

.runner-marker, .user-marker { display: grid; place-items: center; border: 3px solid var(--white); border-radius: 50%; box-shadow: 0 4px 14px rgba(16, 47, 45, 0.32); }
.runner-marker { width: 38px; height: 38px; background: var(--coral); }
.runner-marker::before { content: "K"; color: white; font-size: 0.8rem; font-weight: 900; }
.runner-marker::after { content: ""; position: absolute; z-index: -1; width: 48px; height: 48px; border: 2px solid rgba(240, 100, 69, 0.6); border-radius: 50%; animation: pulse 2s infinite; }
.user-marker { width: 30px; height: 30px; background: var(--teal); }
.user-marker::before { content: "ME"; color: white; font-size: 0.52rem; font-weight: 900; }
.accuracy-ring { position: absolute; border: 1px solid rgba(7, 129, 122, 0.38); border-radius: 50%; background: rgba(7, 129, 122, 0.09); pointer-events: none; }
.nearby-time-label {
  padding: 5px 9px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  background: var(--white);
  box-shadow: 0 3px 10px rgba(16, 47, 45, 0.2);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

@keyframes pulse {
  0% { opacity: 0.9; transform: scale(0.75); }
  70%, 100% { opacity: 0; transform: scale(1.35); }
}

.maplibregl-ctrl-top-right { top: 12px; right: 12px; }
.maplibregl-ctrl-group { overflow: hidden; border: 1px solid var(--line); border-radius: 10px !important; box-shadow: 0 6px 20px rgba(16, 47, 45, 0.13) !important; }

@media (max-width: 700px) {
  .panel { top: auto; right: 10px; bottom: 10px; left: 10px; width: auto; max-height: 56vh; padding: 19px; border-radius: 19px; }
  #map { height: 53vh; }
  .app-shell { background: var(--paper); }
  .intro, .legend, footer { display: none; }
  .controls { margin-top: 17px; padding-top: 14px; }
  .progress-card { margin-top: 15px; }
  .distance { margin: 13px 0 10px; font-size: 2.7rem; }
  .location-card { margin-top: 14px; }
  .nearby-card { margin-top: 14px; }
  .quick-controls { top: 10px; }
  .quick-controls span { display: none; }
  .panel-toggle { right: 10px; bottom: calc(56vh + 20px); left: auto; }
  .panel-hidden .panel { transform: translateY(calc(100% + 20px)); }
  .panel-hidden .panel-toggle { right: 10px; bottom: 10px; left: auto; }
  .panel-hidden #map { height: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .runner-marker::after { animation: none; }
  .progress-track span { transition: none; }
}
