:root {
  --bg: #0d1016;
  --panel: #161b24;
  --line: #262e3b;
  --text: #e8ecf3;
  --muted: #8b97ab;
  --accent: #ffd23f;
  --ok: #3ddc84;
  --warn: #ffa53f;
  --bad: #ff5c5c;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 48px 20px 32px;
  background:
    radial-gradient(1100px 520px at 50% -10%, #1c2434 0%, transparent 70%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { width: 100%; max-width: 560px; }

header { text-align: center; margin-bottom: 28px; }

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  letter-spacing: -0.03em;
  font-weight: 800;
}
h1 em { color: var(--accent); font-style: italic; }

.tagline { margin: 8px auto 0; max-width: 42ch; color: var(--muted); }

form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.row { display: flex; gap: 14px; }
.row .field { flex: 1; min-width: 0; }

.field { display: flex; flex-direction: column; gap: 6px; }

label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  color: var(--text);
  background: #0f131b;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #55617a; }

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 4px;
}

.units {
  display: flex;
  padding: 3px;
  background: #0f131b;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.unit {
  padding: 7px 13px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}
.unit.is-on { color: #0d1016; background: var(--accent); font-weight: 600; }

#go {
  flex: 1;
  padding: 12px;
  font: inherit;
  font-weight: 700;
  color: #0d1016;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
#go:hover { filter: brightness(1.08); }
#go[disabled] { opacity: 0.55; cursor: progress; }

#result {
  margin-top: 20px;
  padding: 26px 22px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.speed {
  font-size: clamp(3rem, 16vw, 5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--verdict, var(--accent));
  font-variant-numeric: tabular-nums;
}
.speed span { font-size: 0.3em; font-weight: 600; margin-left: 6px; letter-spacing: 0; }

.verdict { margin: 10px 0 0; font-size: 1.05rem; font-weight: 600; color: var(--verdict, var(--text)); }

.detail { margin: 18px 0 0; font-size: 0.92rem; color: var(--muted); }
.detail b { color: var(--text); font-weight: 600; }

.legs {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  text-align: left;
}
.leg { flex: 1; min-width: 0; }
.leg dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.leg dd { margin: 3px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.note { margin: 14px 0 0; font-size: 0.85rem; color: var(--muted); }
.error { color: var(--bad); font-weight: 600; margin: 0; }

footer {
  max-width: 560px;
  font-size: 0.8rem;
  text-align: center;
  color: #5c6779;
}

@media (max-width: 460px) {
  .row { flex-direction: column; }
  .legs { flex-direction: column; gap: 12px; }
}

/* ---- route map ---- */

.map {
  height: 260px;
  margin: 20px 0 4px;
  background: #0f131b;
  border: 1px solid var(--line);
  border-radius: 10px;
  /* Leaflet panes are positioned; keep them inside the rounded corners. */
  overflow: hidden;
  z-index: 0;
}

/* Leaflet's default control chrome is white-on-white; tone it for the dark card. */
.leaflet-container { background: #0f131b; font: inherit; }

.leaflet-control-attribution {
  background: rgba(13, 16, 22, 0.82) !important;
  color: var(--muted) !important;
  font-size: 0.68rem;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

.leaflet-bar a {
  background: #161b24;
  color: var(--text);
  border-bottom-color: var(--line);
}
.leaflet-bar a:hover { background: #1d2430; color: var(--text); }

/* ---- loading state ---- */

.loading { padding: 12px 0 6px; }

.loading-road { display: block; width: 100%; height: auto; }

.road-base { stroke: var(--line); stroke-width: 3; stroke-linecap: round; }

.road-dash {
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 14 18;
  animation: road-march 0.7s linear infinite;
}

.road-car {
  fill: var(--accent);
  /* transform, not cx: SVG geometry properties aren't animatable everywhere. */
  animation: road-drive 1.9s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

@keyframes road-march {
  to { stroke-dashoffset: -32; }
}

@keyframes road-drive {
  0% { transform: translateX(0); }
  100% { transform: translateX(464px); }
}

.loading-text {
  margin: 16px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

@media (prefers-reduced-motion: reduce) {
  .road-dash, .road-car { animation: none; }
  .road-car { transform: translateX(232px); }
}

.warn-note {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 0.85rem;
  text-align: left;
  color: var(--warn);
  background: rgba(255, 165, 63, 0.09);
  border: 1px solid rgba(255, 165, 63, 0.25);
  border-radius: 8px;
}
.warn-note b { color: var(--text); }

.suggest-intro { margin: 14px 0 8px; font-size: 0.88rem; color: var(--muted); }

.suggestions { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.suggestions button {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  color: var(--text);
  background: #0f131b;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.suggestions button:hover { border-color: var(--accent); color: var(--accent); }
