:root {
  --bg: #f7f1e4;
  --card: #fffaf0;
  --text: #202020;
  --muted: #6f6658;
  --border: #e3d7c2;
  --yellow: #f2c94c;
  --yellow-dark: #8a6400;
  --green: #2f855a;
  --orange: #b7791f;
  --red: #c53030;
  --shadow: 0 12px 30px rgba(80, 60, 20, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 18px 13px;
  background: rgba(247, 241, 228, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 14px;
  font-size: 20px;
}

h3 {
  margin-bottom: 8px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--yellow-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

.app {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 14px 18px 24px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.stage-switcher {
  position: sticky;
  top: 72px;
  z-index: 15;
  background: rgba(255, 250, 240, 0.96);
  backdrop-filter: blur(12px);
}

.stage-nav {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: end;
}

.stage-picker-wrap {
  display: grid;
  gap: 7px;
}

.stage-mini-label {
  margin: 10px 0 0;
  font-weight: 700;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
  align-items: stretch;
}

.hero-title {
  font-size: clamp(34px, 8vw, 64px);
  line-height: 0.9;
  letter-spacing: -0.075em;
  margin-bottom: 12px;
}

.route {
  font-size: 21px;
  font-weight: 800;
}

.stage-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin-bottom: 12px;
  padding: 7px 11px;
  border-radius: 999px;
  background: #fff2cc;
  color: #5f4300;
  font-weight: 900;
  font-size: 13px;
}

.stage-progress {
  margin-top: 18px;
}

.progress-bar {
  overflow: hidden;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: #e9ddc7;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--yellow);
}

.progress-fill.completed {
  background: var(--green);
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-weight: 800;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fffdf7;
}

.stat strong {
  display: block;
  font-size: 24px;
  letter-spacing: -0.04em;
}

.stat span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fffdf7;
  color: var(--text);
  font: inherit;
}

button,
.import-label {
  border: 0;
  border-radius: 999px;
  padding: 13px 16px;
  background: var(--yellow);
  color: #211800;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
}

button:hover,
.import-label:hover {
  filter: brightness(0.98);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.secondary-button {
  background: #fffdf7;
  border: 1px solid var(--border);
  color: var(--text);
}

.primary-action {
  border: 2px solid rgba(242, 201, 76, 0.45);
}

.gpx-result {
  margin-top: 12px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fffdf7;
}

.gpx-result.success {
  background: #ddf5e8;
  border-color: #9ae6b4;
  color: #22543d;
}

.gpx-result.near {
  background: #fff2cc;
  border-color: #f6d365;
  color: #744210;
}

.gpx-result.partial {
  background: #fce4d6;
  border-color: #f6ad55;
  color: #7b341e;
}

.gpx-result.missed,
.gpx-result.error {
  background: #f5e4df;
  border-color: #feb2b2;
  color: #742a2a;
}

.gpx-result.info {
  background: #fffdf7;
  color: var(--muted);
}

.gpx-result-title {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 18px;
}

.gpx-tick {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  font-weight: 900;
}

.gpx-result p {
  margin: 4px 0 0;
}

details > summary {
  cursor: pointer;
  list-style: none;
  font-size: 20px;
  font-weight: 900;
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary::after {
  content: "▼";
  float: right;
  font-size: 14px;
  color: var(--muted);
  transform: translateY(5px);
}

details[open] > summary::after {
  content: "▲";
}

.manual-inner {
  margin-top: 16px;
}

.ride-form {
  display: grid;
  gap: 12px;
}

.ride-list {
  display: grid;
  gap: 10px;
}

.ride-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 16px;
  background: #fffdf7;
  border: 1px solid var(--border);
}

.ride-item p {
  margin-bottom: 3px;
}

.delete-ride {
  padding: 8px 10px;
  background: #f5e4df;
  color: var(--red);
}

.stage-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 8px;
  scroll-snap-type: x proximity;
}

.stage-dot {
  flex: 0 0 auto;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 999px;
  background: #fffdf7;
  border: 1px solid var(--border);
  color: var(--text);
  scroll-snap-align: center;
}

.stage-dot.completed {
  background: #ddf5e8;
  color: var(--green);
}

.stage-dot.near {
  background: #fff2cc;
  color: var(--orange);
}

.stage-dot.partial {
  background: #fce4d6;
  color: var(--orange);
}

.stage-dot.missed {
  background: #f5e4df;
  color: var(--red);
}

.stage-dot.rest {
  background: #e9ddc7;
  color: var(--muted);
}

.stage-dot.selected {
  outline: 3px solid rgba(242, 201, 76, 0.75);
  background: var(--yellow);
  color: #211800;
}

.progress-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.progress-card {
  padding: 14px;
  border-radius: 16px;
  background: #fffdf7;
  border: 1px solid var(--border);
}

.progress-card strong {
  display: block;
  font-size: 24px;
  letter-spacing: -0.04em;
}

.stage-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.stage-row {
  width: 100%;
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  text-align: left;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fffdf7;
  color: var(--text);
}

.stage-row.selected {
  outline: 3px solid rgba(242, 201, 76, 0.55);
}

.stage-row.rest {
  background: #f4ecdc;
}

.stage-number {
  font-weight: 900;
}

.stage-main strong {
  display: block;
}

.stage-main span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  justify-self: end;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.completed {
  background: #ddf5e8;
  color: var(--green);
}

.badge.near {
  background: #fff2cc;
  color: var(--orange);
}

.badge.partial {
  background: #fce4d6;
  color: var(--orange);
}

.badge.missed {
  background: #f5e4df;
  color: var(--red);
}

.badge.rest {
  background: #e9ddc7;
  color: var(--muted);
}

.data-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.import-label {
  display: block;
  border: 1px solid var(--border);
  background: #fffdf7;
  color: var(--text);
}

.import-label input {
  display: none;
}

.data-status {
  margin-top: 12px;
  margin-bottom: 0;
}

.danger-zone {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.danger-zone h3 {
  color: var(--red);
}

@media (max-width: 760px) {
  .topbar {
    padding: 14px 14px 12px;
  }

  h1 {
    font-size: 24px;
  }

  .app {
    padding: 12px;
  }

  .panel {
    border-radius: 18px;
    padding: 15px;
    margin-bottom: 12px;
  }

  .stage-switcher {
    top: 64px;
  }

  .stage-nav {
    grid-template-columns: 1fr 1.45fr 1fr;
    gap: 7px;
  }

  .stage-nav button {
    padding: 11px 8px;
    font-size: 13px;
  }

  .stage-picker-wrap label {
    font-size: 12px;
  }

  select {
    padding: 11px 9px;
    font-size: 13px;
  }

  .hero-grid {
    grid-template-columns: 1fr;
  }

  .hero-title {
    font-size: 46px;
  }

  .stats-grid,
  .progress-summary,
  .data-tools {
    grid-template-columns: 1fr 1fr;
  }

  .stage-row {
    grid-template-columns: 56px 1fr;
  }

  .badge {
    grid-column: 1 / -1;
    justify-self: start;
  }
}
/* Version 4B visual layer */

.stage-visual-card {
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fffdf7;
}

.stage-visual-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--yellow);
  color: #211800;
  font-weight: 900;
}

.stage-visual-scene {
  position: relative;
  min-height: 150px;
  overflow: hidden;
  background: linear-gradient(#bfe4ff 0%, #eaf7ff 48%, #f3e7b8 49%, #d7be72 100%);
}

.stage-visual-scene::before {
  content: "";
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: 28px;
  height: 78px;
  background:
    radial-gradient(circle at 16% 100%, #89a86b 0 28%, transparent 29%),
    radial-gradient(circle at 44% 100%, #7b9c5c 0 34%, transparent 35%),
    radial-gradient(circle at 78% 100%, #6f8d54 0 31%, transparent 32%);
}

.stage-visual-scene::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 10px;
  height: 38px;
  border-radius: 999px 999px 0 0;
  background: #303030;
  transform: perspective(160px) rotateX(50deg);
  box-shadow: inset 0 4px 0 rgba(255,255,255,0.08);
}

.stage-visual-icon {
  position: absolute;
  z-index: 2;
  right: 26px;
  top: 28px;
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  border: 2px solid rgba(32, 32, 32, 0.12);
  font-size: 36px;
  font-weight: 900;
}

.stage-visual-profile {
  position: absolute;
  z-index: 3;
  left: 18px;
  right: 18px;
  bottom: 26px;
  height: 48px;
}

.stage-visual-profile svg {
  width: 100%;
  height: 100%;
  display: block;
}

.visual-time-trial .stage-visual-scene {
  background: linear-gradient(#d7ecff 0%, #ffffff 48%, #f8d64c 49%, #e8b920 100%);
}

.visual-time-trial .stage-visual-scene::before {
  height: 35px;
  bottom: 42px;
  background: linear-gradient(90deg, transparent, rgba(32,32,32,0.18), transparent);
}

.visual-time-trial .stage-visual-icon {
  content: "⏱";
}

.visual-flat .stage-visual-scene {
  background: linear-gradient(#bfe4ff 0%, #eaf7ff 50%, #f7db70 51%, #d1a83b 100%);
}

.visual-hilly .stage-visual-scene {
  background: linear-gradient(#bfe4ff 0%, #eaf7ff 45%, #e8d281 46%, #b99a45 100%);
}

.visual-mountain .stage-visual-scene {
  background: linear-gradient(#bfe4ff 0%, #eaf7ff 44%, #d3debb 45%, #718d50 100%);
}

.visual-mountain .stage-visual-scene::before {
  bottom: 30px;
  height: 118px;
  clip-path: polygon(0 100%, 18% 45%, 30% 70%, 46% 15%, 63% 78%, 78% 34%, 100% 100%);
  background: linear-gradient(135deg, #4e6f43, #d7c35d);
}

.visual-rest-day .stage-visual-scene {
  background: linear-gradient(#f7f1e4, #e9ddc7);
}

.journey-panel {
  background:
    linear-gradient(180deg, rgba(242, 201, 76, 0.18), rgba(255, 250, 240, 0.75)),
    var(--card);
}

.tour-journey {
  display: grid;
  gap: 14px;
}

.journey-track {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  align-items: start;
}

.journey-track::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 30px;
  height: 8px;
  border-radius: 999px;
  background: #e9ddc7;
}

.journey-track::after {
  content: "";
  position: absolute;
  left: 8%;
  top: 30px;
  width: var(--journey-progress, 0%);
  max-width: 84%;
  height: 8px;
  border-radius: 999px;
  background: var(--yellow);
}

.journey-stop {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 7px;
  text-align: center;
}

.journey-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: #fffdf7;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 28px;
}

.journey-stop.done .journey-icon {
  background: #ddf5e8;
  color: var(--green);
}

.journey-stop.current .journey-icon {
  background: var(--yellow);
  color: #211800;
  outline: 3px solid rgba(242, 201, 76, 0.45);
}

.journey-name {
  font-weight: 900;
  font-size: 13px;
}

.journey-stage {
  color: var(--muted);
  font-size: 12px;
}

.journey-summary {
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fffdf7;
  border: 1px solid var(--border);
  font-weight: 800;
}

@media (max-width: 760px) {
  .stage-visual-scene {
    min-height: 132px;
  }

  .stage-visual-icon {
    right: 18px;
    top: 22px;
    width: 62px;
    height: 62px;
    font-size: 30px;
  }

  .journey-track {
    grid-template-columns: repeat(5, minmax(82px, 1fr));
    overflow-x: auto;
    padding: 4px 2px 10px;
  }

  .journey-track::before,
  .journey-track::after {
    top: 31px;
  }

  .journey-icon {
    width: 54px;
    height: 54px;
  }
}