/* ── Course Grabber ────────────────────────────────────────────────────────
   Mobile-first. Night-ride palette: deep indigo road, chartreuse kit accent,
   sunset coral for the secondary action.
   ────────────────────────────────────────────────────────────────────────── */

:root {
  --ink-900: #070b17;
  --ink-800: #0b1020;
  --ink-700: #121a30;
  --ink-600: #1a2440;
  --line: rgba(148, 176, 255, 0.14);
  --line-strong: rgba(148, 176, 255, 0.26);

  --text: #eef2ff;
  --text-dim: #a8b4d8;
  --text-faint: #7484ac;

  --lime: #c6f24e;
  --lime-deep: #9fd318;
  --coral: #ff7a59;
  --coral-deep: #f2542d;
  --sky-1: #1b2a5e;
  --sky-2: #3b2a6b;
  --sun: #ffb25c;

  --grad-flat: #4fd1c5;
  --grad-mid: #f6c445;
  --grad-steep: #ff6b6b;

  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 18px 46px rgba(3, 6, 18, 0.55);
  --shadow-lift: 0 10px 28px rgba(3, 6, 18, 0.45);

  --pad: clamp(16px, 4.5vw, 26px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  position: relative;
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background: var(--ink-900);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap {
  width: min(680px, 100%);
  margin-inline: auto;
  padding-inline: var(--pad);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Sky backdrop ───────────────────────────────────────────────────────── */

.sky {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: min(62vh, 520px);
  background:
    radial-gradient(120% 90% at 78% 6%, rgba(255, 178, 92, 0.30), transparent 58%),
    radial-gradient(110% 80% at 12% 0%, rgba(120, 96, 220, 0.32), transparent 62%),
    linear-gradient(180deg, var(--sky-2) 0%, var(--sky-1) 42%, var(--ink-900) 100%);
  z-index: -2;
}

.sun {
  position: absolute;
  top: 166px; right: 8%;
  width: clamp(84px, 26vw, 128px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #ffe0a8, var(--sun) 55%, rgba(255, 138, 76, 0) 72%);
  filter: blur(1px);
  opacity: 0.7;
  animation: sun-pulse 9s ease-in-out infinite;
}

@keyframes sun-pulse {
  0%, 100% { transform: scale(1); opacity: 0.82; }
  50%      { transform: scale(1.06); opacity: 0.95; }
}

.cloud {
  position: absolute;
  height: 22px;
  border-radius: 999px;
  background: rgba(226, 234, 255, 0.16);
  filter: blur(6px);
  animation: drift linear infinite;
}
.cloud::after {
  content: "";
  position: absolute;
  left: 24%; top: -12px;
  width: 52%; height: 30px;
  border-radius: 999px;
  background: inherit;
}
.cloud-a { width: 190px; top: 16%; left: -30%; animation-duration: 62s; }
.cloud-b { width: 130px; top: 30%; left: -30%; animation-duration: 88s; animation-delay: -20s; opacity: 0.7; }
.cloud-c { width: 240px; top: 46%; left: -40%; animation-duration: 110s; animation-delay: -55s; opacity: 0.45; }

@keyframes drift { to { transform: translateX(190vw); } }

/* ── Hero ───────────────────────────────────────────────────────────────── */

.hero { position: relative; padding-top: calc(env(safe-area-inset-top) + 26px); }

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 52px; height: 52px;
  flex: none;
  color: var(--lime);
  filter: drop-shadow(0 4px 14px rgba(198, 242, 78, 0.32));
}
.brand-mark circle:first-of-type,
.brand-mark circle:nth-of-type(2) { animation: roll 2.6s linear infinite; transform-origin: center; }

.brand-text h1 {
  margin: 0;
  font-size: clamp(27px, 7.6vw, 38px);
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-weight: 800;
  background: linear-gradient(96deg, #ffffff 8%, var(--lime) 96%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-text p {
  margin: 5px 0 0;
  font-size: 13.5px;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

.ridge {
  display: block;
  width: 100%;
  height: clamp(90px, 22vw, 150px);
  margin-top: 22px;
}
.ridge-far  { fill: rgba(88, 108, 190, 0.30); }
.ridge-mid  { fill: rgba(52, 68, 140, 0.55); }
.ridge-near { fill: rgba(18, 26, 48, 0.92); }

.road {
  position: relative;
  height: 92px;
  margin-top: -2px;
  background: linear-gradient(180deg, #151d33 0%, #0d1425 100%);
  border-top: 2px solid rgba(198, 242, 78, 0.22);
  overflow: hidden;
}
.road-dashes {
  position: absolute;
  left: 0; right: 0; bottom: 24px;
  height: 3px;
  background: repeating-linear-gradient(90deg, rgba(238, 242, 255, 0.42) 0 26px, transparent 26px 60px);
  animation: dash-run 1.4s linear infinite;
}
@keyframes dash-run { to { transform: translateX(-60px); } }

.rider {
  position: absolute;
  bottom: 14px;
  left: 7%;
  width: clamp(104px, 28vw, 140px);
  color: var(--lime);
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.5));
  animation: rider-bob 1.1s ease-in-out infinite;
}
.rider .wheel {
  transform-box: fill-box;
  transform-origin: center;
  animation: roll 0.72s linear infinite;
}
.rider-body { color: #ffffff; }
.rider-body .leg {
  transform-box: fill-box;
  transform-origin: 0% 0%;
  animation: pedal 0.72s ease-in-out infinite;
}

@keyframes pedal {
  0%, 100% { transform: rotate(-9deg); }
  50%      { transform: rotate(9deg); }
}

@keyframes roll { to { transform: rotate(360deg); } }
@keyframes rider-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

/* ── Panels ─────────────────────────────────────────────────────────────── */

main { padding-top: 26px; }

.panel {
  background: linear-gradient(168deg, rgba(26, 36, 64, 0.92), rgba(12, 18, 36, 0.94));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  backdrop-filter: blur(10px);
}

.panel-title {
  display: flex; align-items: center; gap: 11px;
  margin: 0 0 16px;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.step-dot {
  display: grid; place-items: center;
  width: 27px; height: 27px;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(150deg, var(--lime), var(--lime-deep));
  color: #12210a;
  font-size: 13.5px;
  font-weight: 800;
}

/* ── Input ──────────────────────────────────────────────────────────────── */

.field { position: relative; display: flex; }

.field input {
  flex: 1;
  min-width: 0;
  padding: 16px 56px 16px 17px;
  font-size: 16px; /* keeps iOS from zooming on focus */
  font-family: var(--font);
  color: var(--text);
  background: rgba(6, 10, 22, 0.72);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.field input::placeholder { color: var(--text-faint); }
.field input:focus {
  border-color: var(--lime);
  box-shadow: 0 0 0 4px rgba(198, 242, 78, 0.16);
}

.paste-btn {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: transparent;
  border: 0;
  border-radius: 11px;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.paste-btn svg { width: 21px; height: 21px; fill: currentColor; }
.paste-btn:active { background: rgba(198, 242, 78, 0.14); color: var(--lime); }

.help {
  margin: 11px 2px 17px;
  font-size: 12.8px;
  line-height: 1.5;
  color: var(--text-faint);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-height: 54px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 15px 20px;
  font-family: var(--font);
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}
.btn:active { transform: scale(0.982); }

.btn-primary {
  color: #101c06;
  background: linear-gradient(135deg, #ddff77 0%, var(--lime) 42%, var(--lime-deep) 100%);
  box-shadow: 0 10px 26px rgba(159, 211, 24, 0.30);
}
.btn-primary[disabled] { opacity: 0.55; cursor: progress; }
.btn-arrow { width: 21px; height: 21px; transition: transform 0.2s ease; }
.btn-primary:active .btn-arrow { transform: translateX(3px); }

.btn-ghost {
  margin-top: 14px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 600;
  min-height: 48px;
}

/* ── Loading ────────────────────────────────────────────────────────────── */

.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-block: 34px; }
.chainring { width: 62px; height: 62px; color: var(--lime); }
.chainring-spin { transform-origin: 50px 50px; animation: roll 2.1s linear infinite; }
.loading-text { margin: 0; font-size: 14.5px; font-weight: 600; color: var(--text-dim); }

/* ── Alert ──────────────────────────────────────────────────────────────── */

.alert {
  display: flex; gap: 13px; align-items: flex-start;
  border-color: rgba(255, 122, 89, 0.42);
  background: linear-gradient(168deg, rgba(64, 26, 26, 0.92), rgba(28, 14, 20, 0.94));
}
.alert-icon { width: 24px; height: 24px; flex: none; color: var(--coral); margin-top: 1px; }
.alert-title { margin: 0; font-size: 15.5px; font-weight: 700; }
.alert-hint  { margin: 5px 0 0; font-size: 13.4px; line-height: 1.5; color: var(--text-dim); }
.alert-title, .alert-hint { overflow-wrap: anywhere; }

/* ── Course card ────────────────────────────────────────────────────────── */

.result[hidden], .panel[hidden] { display: none !important; }

.course-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 11px; }

.badge {
  display: inline-flex; align-items: center;
  padding: 6px 13px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--lime);
  background: rgba(198, 242, 78, 0.13);
  border: 1px solid rgba(198, 242, 78, 0.32);
  border-radius: 999px;
}

.unit-toggle {
  display: inline-flex;
  padding: 3px;
  background: rgba(6, 10, 22, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.unit-toggle span {
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-faint);
  border-radius: 999px;
  transition: color 0.15s ease, background 0.15s ease;
}
.unit-toggle span.on { color: #12210a; background: var(--lime); }

.course-name {
  margin: 0;
  font-size: clamp(21px, 5.6vw, 27px);
  line-height: 1.18;
  letter-spacing: -0.025em;
  font-weight: 800;
  overflow-wrap: anywhere;
}
.course-meta { margin: 7px 0 18px; font-size: 13px; color: var(--text-faint); }

/* ── Map ────────────────────────────────────────────────────────────────── */

.map-frame {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background:
    radial-gradient(120% 100% at 30% 12%, rgba(80, 108, 200, 0.22), transparent 62%),
    linear-gradient(160deg, #101a33, #070c1a);
  border: 1px solid var(--line);
  aspect-ratio: 4 / 3;
}
.route-map { display: block; width: 100%; height: 100%; }
.map-grain {
  position: absolute; inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(148, 176, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 176, 255, 0.05) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: radial-gradient(120% 100% at 50% 50%, #000 45%, transparent 100%);
}

.route-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: var(--len);
  stroke-dashoffset: var(--len);
  animation: draw 1.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }

.route-glow { stroke: rgba(198, 242, 78, 0.24); stroke-width: 9; filter: blur(4px); }
.route-core { stroke: url(#routeGrad); stroke-width: 3.4; }

.pin-start circle, .pin-end circle { animation: pop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) 1.5s both; transform-box: fill-box; transform-origin: center; }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }

.pin-label { font: 700 10px var(--font); letter-spacing: 0.08em; }

/* ── Stats ──────────────────────────────────────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin: 16px 0 0;
}
.stats > div {
  padding: 13px 10px;
  text-align: center;
  background: rgba(6, 10, 22, 0.6);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.stats dt {
  margin: 0 0 5px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.stats dd {
  margin: 0;
  font-size: clamp(17px, 4.8vw, 21px);
  font-weight: 800;
  letter-spacing: -0.028em;
  font-variant-numeric: tabular-nums;
}
.stats dd span { font-size: 0.6em; font-weight: 700; color: var(--text-dim); margin-left: 2px; }

/* ── Elevation profile ──────────────────────────────────────────────────── */

.profile-block { margin-top: 20px; }
.profile-block[hidden] { display: none; }
.profile-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.profile-head h3 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-dim); }
.profile-legend { font-size: 10.5px; color: var(--text-faint); display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.sw + .sw { margin-left: 7px; }
.sw-flat  { background: var(--grad-flat); }
.sw-mid   { background: var(--grad-mid); }
.sw-steep { background: var(--grad-steep); }

.profile {
  display: block;
  width: 100%;
  height: 128px;
  background: linear-gradient(180deg, rgba(10, 16, 32, 0.5), rgba(6, 10, 22, 0.8));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.profile-area { animation: rise 0.9s cubic-bezier(0.2, 0.9, 0.3, 1) both; transform-origin: bottom; }
@keyframes rise { from { transform: scaleY(0.05); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }

/* ── Downloads ──────────────────────────────────────────────────────────── */

.dl-grid { display: grid; gap: 11px; }

.dl-card {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  padding: 16px;
  min-height: 76px;
  text-decoration: none;
  color: var(--text);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(6, 10, 22, 0.62);
  overflow: hidden;
  transition: transform 0.12s ease, border-color 0.18s ease, box-shadow 0.2s ease;
}
.dl-card::before {
  content: "";
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.dl-gpx::before { background: linear-gradient(110deg, rgba(198, 242, 78, 0.16), transparent 62%); }
.dl-tcx::before { background: linear-gradient(110deg, rgba(255, 122, 89, 0.16), transparent 62%); }
.dl-card:active { transform: scale(0.985); }
.dl-card:active::before { opacity: 1; }
.dl-gpx:active { border-color: rgba(198, 242, 78, 0.6); }
.dl-tcx:active { border-color: rgba(255, 122, 89, 0.6); }

.dl-ext {
  position: relative;
  display: grid; place-items: center;
  width: 54px; height: 54px;
  flex: none;
  border-radius: 15px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.dl-gpx .dl-ext { color: #101c06; background: linear-gradient(140deg, #ddff77, var(--lime-deep)); }
.dl-tcx .dl-ext { color: #2a0d05; background: linear-gradient(140deg, #ffb199, var(--coral-deep)); }

.dl-copy { position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.dl-copy strong { font-size: 15.5px; font-weight: 700; letter-spacing: -0.01em; }
.dl-copy small { font-size: 12px; line-height: 1.35; color: var(--text-faint); }

.dl-icon { position: relative; width: 21px; height: 21px; margin-left: auto; flex: none; color: var(--text-faint); }

/* ── Spoke burst on download ────────────────────────────────────────────── */

.burst { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.spoke {
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 2px;
  will-change: transform, opacity;
  animation: fling 900ms cubic-bezier(0.15, 0.75, 0.3, 1) forwards;
}
@keyframes fling {
  0%   { transform: translate(0, 0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.4); opacity: 0; }
}

/* ── Footer ─────────────────────────────────────────────────────────────── */

.site-foot { padding-block: 8px 34px; }
.site-foot p { margin: 0; font-size: 11.8px; line-height: 1.6; color: var(--text-faint); text-align: center; }

/* ── Larger screens ─────────────────────────────────────────────────────── */

@media (min-width: 620px) {
  .dl-grid { grid-template-columns: 1fr 1fr; }
  .dl-card { flex-direction: column; align-items: flex-start; padding: 20px; }
  .dl-icon { margin-left: 0; position: absolute; top: 20px; right: 20px; }
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .route-line { stroke-dashoffset: 0; }
}
