:root {
  color-scheme: light;
  --bg: #f7efe6;
  --bg-soft: #fffaf4;
  --card: rgba(255, 255, 255, 0.8);
  --line: rgba(176, 137, 108, 0.22);
  --text: #2b1f1a;
  --muted: #7f6457;
  --accent: #d87f5d;
  --accent-2: #b86fbe;
  --good: #2c8a67;
  --track-bg: rgba(176, 137, 108, 0.2);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #071020;
  --bg-soft: #0d1a2e;
  --card: rgba(18, 29, 48, 0.74);
  --line: rgba(151, 191, 255, 0.25);
  --text: #eaf1ff;
  --muted: #aab9d8;
  --accent: #53b9ff;
  --accent-2: #7dffdb;
  --good: #88ffb5;
  --track-bg: #2a3a58;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 12%, #ffd9c8 0%, transparent 34%),
    radial-gradient(circle at 88% 22%, #e6cbff 0%, transparent 30%),
    radial-gradient(circle at 35% 85%, #ffd7a6 0%, transparent 28%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-soft) 100%);
  color: var(--text);
  min-height: 100vh;
}

.background-glow {
  position: fixed;
  inset: -20%;
  background: radial-gradient(circle at 85% 20%, #ff8e6f2d 0%, transparent 45%),
    radial-gradient(circle at 20% 80%, #c984ff2b 0%, transparent 35%);
  pointer-events: none;
  z-index: -1;
  filter: blur(8px);
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: grid;
  gap: 18px;
}

.top-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 200ms ease, filter 200ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff8f2;
}

.btn.secondary {
  background: transparent;
  color: var(--text);
}

.btn-live {
  min-height: 46px;
  padding: 11px 18px;
  font-size: 1rem;
  border-width: 2px;
}

.btn-warn {
  border-color: rgba(201, 107, 116, 0.6);
  color: #fff8f2;
  background: linear-gradient(135deg, #c96b74, #ef9ea6);
}

.btn-warn:hover {
  filter: brightness(1.08);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 14px 36px rgba(107, 74, 51, 0.12);
}

.hero h1 {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  letter-spacing: 0.01em;
  line-height: 1.02;
}

.hero-main {
  display: block;
  font-size: clamp(2.8rem, 7vw, 5.2rem);
  font-weight: 700;
}

.hero-sub {
  display: block;
  margin-top: 0.2rem;
  font-size: clamp(1.35rem, 2.7vw, 2.25rem);
  font-weight: 600;
  color: var(--muted);
}

.kicker {
  margin: 0 0 10px;
  color: var(--accent-2);
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 0.8rem;
}

.hero-text {
  color: var(--muted);
  max-width: 70ch;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.hero-badges span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.controls h2,
.timeline h2,
.nutrition h2,
.strategy h2 {
  margin: 0 0 12px;
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.gpx-tools {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.gpx-upload input[type="file"] {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px;
  background: transparent;
  color: var(--muted);
}

.gpx-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.input-group {
  display: grid;
  gap: 6px;
}

.input-group span {
  color: var(--muted);
  font-size: 0.9rem;
}

input[type="time"],
input[type="range"] {
  width: 100%;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
  align-items: center;
}

input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  padding: 7px 8px;
  font: inherit;
}

[data-theme="dark"] input[type="number"] {
  background: rgba(16, 29, 50, 0.72);
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

[data-theme="dark"] select {
  background: rgba(16, 29, 50, 0.72);
}

output {
  color: var(--accent-2);
  font-weight: 600;
  font-size: 0.92rem;
}

.metrics {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.metric .value {
  margin: 8px 0 4px;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--good);
}

.metric small {
  color: var(--muted);
}

.terrain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.terrain-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.terrain-grid h3 {
  margin: 0 0 10px;
  color: var(--accent-2);
}

.dist-list {
  display: grid;
  gap: 8px;
}

.dist-item {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 0.88rem;
}

.dist-item .label {
  color: var(--text);
}

.dist-item .bar {
  height: 7px;
  border-radius: 999px;
  background: var(--track-bg);
  overflow: hidden;
}

.dist-item .fill {
  height: 100%;
  background: linear-gradient(90deg, #f4a88a, var(--accent-2));
  border-radius: 999px;
}

.dist-item .val {
  color: var(--muted);
  white-space: nowrap;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
}

.section-head p {
  margin: 0;
  color: var(--muted);
}

.timeline-track {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.map-frame-wrap {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.route-map {
  width: 100%;
  min-height: 360px;
  display: block;
}

.leaflet-container {
  font-family: "Inter", system-ui, sans-serif;
  background: rgba(255, 255, 255, 0.6);
}

.probe-panel {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.probe-panel article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.42);
}

[data-theme="dark"] .probe-panel article {
  background: rgba(16, 29, 50, 0.52);
}

.probe-panel h3 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.probe-panel p {
  margin: 6px 0 0;
  font-size: 1.12rem;
  font-weight: 800;
}

.probe-pin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(184, 111, 190, 0.26);
  position: relative;
}

[data-theme="dark"] .probe-pin {
  border-color: #102038;
}

.probe-pin::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
}

.map-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-start;
}

.profile-track {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.elevation-chart-wrap {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.45);
}

#elevationChart {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
}

#elevationLine {
  fill: none;
  stroke: #4b2e83;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.band-easy {
  fill: rgba(88, 173, 134, 0.24);
}

.band-medium {
  fill: rgba(213, 159, 91, 0.24);
}

.band-hard {
  fill: rgba(201, 107, 116, 0.24);
}

.vps-line {
  stroke: rgba(75, 46, 131, 0.45);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.vps-label {
  fill: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.vps-active {
  stroke: #6f42c1 !important;
  fill: #6f42c1 !important;
  opacity: 1 !important;
}

.vps-hover-popup {
  font-size: 0.8rem;
  line-height: 1.25;
}

.vps-hover-popup ul {
  margin: 6px 0 0;
  padding-left: 16px;
}

#profileCursorLine {
  stroke: #b86fbe;
  stroke-width: 2;
  stroke-dasharray: 6 5;
  opacity: 0.9;
}

#profileCursorHit {
  fill: transparent;
  cursor: grab;
}

#profileCursorHit:active {
  cursor: grabbing;
}

#profileCursorDot {
  fill: #d87f5d;
  stroke: #fff;
  stroke-width: 2;
  pointer-events: none;
}

.profile-probe-panel {
  margin-top: 10px;
}

.profile-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.profile-row h3 {
  margin: 0;
  font-size: 0.98rem;
}

.seg-zone {
  font-weight: 700;
  font-size: 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 3px 8px;
}

.seg-meta {
  margin: 6px 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.effort-wrap {
  height: 10px;
  border-radius: 999px;
  background: var(--track-bg);
  overflow: hidden;
}

.effort-bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  transition: width 850ms cubic-bezier(0.2, 0.8, 0, 1);
}

.zone-easy {
  background: linear-gradient(90deg, #58ad86, #9de0c2);
}

.zone-medium {
  background: linear-gradient(90deg, #d59f5b, #f4cd98);
}

.zone-hard {
  background: linear-gradient(90deg, #c96b74, #ef9ea6);
}

.profile-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.timeline-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  align-items: start;
}

.timeline-item .node {
  margin-top: 8px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 4px #89ccff1e;
}

.timeline-item .content {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.title-row h3 {
  margin: 0;
  font-size: 1rem;
}

.title-row .distance {
  color: var(--accent-2);
  font-weight: 600;
  font-size: 0.86rem;
}

.window {
  color: var(--muted);
  margin: 8px 0 10px;
}

.progress-wrap {
  height: 8px;
  border-radius: 999px;
  background: var(--track-bg);
  overflow: hidden;
}

.progress {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f0a16b, var(--accent-2));
  transition: width 900ms cubic-bezier(0.2, 0.7, 0, 1);
}

.race-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.race-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin: 10px 0 14px;
}

.race-live-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.race-tile {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 174, 137, 0.16) 0%, transparent 58%),
    rgba(255, 255, 255, 0.42);
}

.race-tile h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.race-value {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.7rem);
  font-weight: 800;
  line-height: 1.12;
  color: var(--text);
}

.race-minimal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background:
    radial-gradient(circle at 20% 10%, #ffd5c7 0%, transparent 35%),
    radial-gradient(circle at 90% 20%, #e1c3ff 0%, transparent 32%),
    linear-gradient(165deg, #fff7f1 0%, #fff0ea 45%, #f8ecff 100%);
  padding: 18px 14px 20px;
  display: none;
  overflow: auto;
}

[data-theme="dark"] .race-minimal {
  background:
    radial-gradient(circle at 20% 10%, #2b4e7a 0%, transparent 35%),
    radial-gradient(circle at 90% 20%, #3f2f61 0%, transparent 32%),
    linear-gradient(165deg, #0e1728 0%, #102038 45%, #1a1730 100%);
}

.race-minimal.is-open {
  display: block;
}

.race-minimal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.race-minimal h1 {
  margin: 8px 0 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1.04;
}

.race-minimal-sub {
  margin: 6px 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
}

.race-minimal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin: 0 0 12px;
}

.race-minimal-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.race-minimal-tile {
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
  padding: 14px 14px 16px;
  box-shadow: 0 8px 22px rgba(75, 46, 35, 0.1);
}

[data-theme="dark"] .race-minimal-tile {
  background: rgba(16, 29, 50, 0.72);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24);
}

.race-minimal-tile h2 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.race-minimal-value {
  margin: 8px 0 0;
  font-size: clamp(1.4rem, 6vw, 2.25rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.nutrition-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.nutrition-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.nutrition-grid h3 {
  margin: 0 0 6px;
  color: var(--accent-2);
}

.nutrition-grid p {
  margin: 0;
  color: var(--muted);
}

.vps-controls {
  margin-top: 8px;
  max-width: 260px;
}

.vps-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.vps-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.vps-grid h3 {
  margin: 0 0 8px;
  color: var(--accent-2);
}

.vps-grid ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.tagged-item {
  list-style: none;
  margin-left: -18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.tag {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--line);
}

.tag.snack {
  background: rgba(213, 159, 91, 0.2);
}

.tag.drink {
  background: rgba(88, 173, 134, 0.2);
}

.strategy ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.footer {
  color: var(--muted);
  text-align: center;
  padding: 2px;
}

.footer-links {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.footer-link-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  text-decoration: none;
  color: #fff8f2;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition: transform 200ms ease, filter 200ms ease;
}

.footer-link-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.print-sheet {
  display: none;
}

.reveal {
  opacity: 0;
  transform: translateY(14px);
  animation: reveal 550ms ease forwards;
}

.reveal:nth-child(2) {
  animation-delay: 70ms;
}

.reveal:nth-child(3) {
  animation-delay: 130ms;
}

.reveal:nth-child(4) {
  animation-delay: 180ms;
}

.reveal:nth-child(5) {
  animation-delay: 230ms;
}

.reveal:nth-child(6) {
  animation-delay: 280ms;
}

@keyframes reveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .app {
    padding: 16px 10px 24px;
  }

  .top-actions {
    justify-content: stretch;
    flex-direction: column;
  }

  .race-minimal {
    padding: 14px 10px 14px;
  }
}

@media print {
  body {
    background: #fff;
    color: #111;
  }

  .background-glow,
  .app {
    display: none !important;
  }

  .print-sheet {
    display: block;
    padding: 10mm;
    font-family: "Inter", Arial, sans-serif;
  }

  .print-sheet h1 {
    margin: 0 0 6px;
    font-size: 18pt;
  }

  .print-sheet .meta {
    margin: 3px 0;
    font-size: 10pt;
  }

  .print-sheet table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 9pt;
  }

  .print-sheet th,
  .print-sheet td {
    border: 1px solid #333;
    padding: 5px 6px;
    text-align: left;
  }

  .print-sheet th {
    background: #f1f1f1;
  }
}
