:root {
  --navy: #0f1e3d;
  --ink: #14264d;
  --orange: #e87722;
  --orange-light: #f5a34a;
  --muted: #6b7280;
  --muted-2: #8a94a6;
  --page-bg: #f6f3ec;
  --card: #ffffff;
  --border: rgba(20, 38, 77, 0.08);
  --border-strong: rgba(20, 38, 77, 0.12);
  --border-stronger: rgba(20, 38, 77, 0.18);
  --radius: 14px;
  --shadow: 0 12px 24px -18px rgba(20, 38, 77, 0.5);
  --control-height: 48px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--page-bg);
  line-height: 1.5;
}

body.has-ride-cover::before,
body.has-ride-cover::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

body.has-ride-cover::before {
  background-image: var(--ride-cover-image);
  background-size: cover;
  background-position: center;
  opacity: .42;
  filter: saturate(.9) contrast(.96);
}

body.has-ride-cover::after {
  background:
    linear-gradient(180deg, rgba(246, 243, 236, .34), rgba(246, 243, 236, .72) 54%, rgba(246, 243, 236, .88)),
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, .2), rgba(255, 255, 255, 0) 42%);
  backdrop-filter: blur(2px);
}

body.has-ride-cover > * {
  position: relative;
  z-index: 1;
}

a { color: var(--orange); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: min(1100px, 92vw); margin: 0 auto; }

/* Header / footer */
.site-header { background: var(--navy); padding: 20px 0; }
body.has-ride-cover .site-header {
  background: rgba(15, 30, 61, .9);
  backdrop-filter: blur(14px);
}
.header-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: #f6ecd6; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 46px;
  height: 46px;
  display: block;
  object-fit: cover;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 1px rgba(246, 236, 214, 0.18);
}
.brand-text strong { display: block; font-size: 1.3rem; font-weight: 800; letter-spacing: 0.02em; }
.brand-text small { color: #9fb0cf; font-weight: 500; }
.anniversary-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(232, 119, 34, 0.16);
  border: 1px solid rgba(232, 119, 34, 0.5);
  color: var(--orange-light);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.site-footer { margin-top: 48px; padding: 24px 0; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); }

main.wrap { padding-top: 28px; }

/* Controls */
.controls { margin-bottom: 24px; }
.search-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
#search {
  flex: 1 1 320px;
  height: var(--control-height);
  padding: 0 16px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
}
#search::placeholder { color: #9aa2b1; }
.sort-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.sort-control select {
  height: var(--control-height);
  min-width: 160px;
  padding: 0 34px 0 12px;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
}
.sort-direction {
  width: var(--control-height);
  height: var(--control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
}
.sort-direction:hover { background: var(--page-bg); }
.sort-direction:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.result-count { color: var(--orange); font-weight: 700; font-size: .9rem; white-space: nowrap; }

.filters { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-end; margin-top: 16px; }
.filter { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); gap: 8px; min-width: min(320px, 100%); }
.filter output { color: var(--ink); font-weight: 800; }
.range-slider {
  --range-low: 0%;
  --range-high: 100%;
  position: relative;
  width: 100%;
  height: 32px;
}
.range-slider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--border-strong) 0 var(--range-low),
    var(--orange) var(--range-low) var(--range-high),
    var(--border-strong) var(--range-high) 100%
  );
  transform: translateY(-50%);
}
.range-slider input[type=range] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 32px;
  margin: 0;
  pointer-events: none;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
}
.range-slider input:first-of-type { z-index: 3; }
.range-slider input:last-of-type { z-index: 2; }
.range-slider input[type=range]::-webkit-slider-runnable-track {
  height: 6px;
  background: transparent;
  border: 0;
}
.range-slider input[type=range]::-moz-range-track {
  height: 6px;
  background: transparent;
  border: 0;
}
.range-slider input[type=range]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -6px;
  pointer-events: auto;
  -webkit-appearance: none;
  border: 2px solid var(--orange);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
  cursor: pointer;
}
.range-slider input[type=range]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  pointer-events: auto;
  border: 2px solid var(--orange);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
  cursor: pointer;
}
.range-slider input[type=range]:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}
.range-slider input[type=range]:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}
.reset {
  padding: 8px 14px; border: 1px solid var(--border-stronger); background: #fff;
  border-radius: var(--radius); cursor: pointer; color: var(--ink); font: inherit; font-size: .85rem; font-weight: 700;
}
.reset:hover { background: var(--page-bg); }

/* Grid of cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .12s ease; }
.card:hover { transform: translateY(-2px); box-shadow: 0 16px 30px -18px rgba(20,38,77,.35); }
.card-link { color: inherit; display: block; }
.card-link:hover { text-decoration: none; }
.card-thumb { aspect-ratio: 5 / 3; background: linear-gradient(160deg, #e4ead6, #d3ddc4); }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-placeholder { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: .9rem; }
.card-body { padding: 14px 16px 18px; }
.card-body h2 { margin: 0 0 8px; font-size: 1.05rem; font-weight: 800; color: var(--ink); }
.card-meta { margin: 0 0 10px; color: var(--muted); font-size: .82rem; font-weight: 600; display: flex; gap: 12px; flex-wrap: wrap; }
.card-stats { margin: 0; display: flex; gap: 8px; }
.stat { background: #f2f4f7; color: var(--ink); border-radius: 9px; padding: 6px 12px; font-size: .82rem; font-weight: 800; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* Detail page */
.breadcrumb { margin-bottom: 16px; font-size: .9rem; font-weight: 700; }
.breadcrumb a { color: var(--orange); }
.detail-head h1 { margin: 0 0 6px; color: var(--ink); font-weight: 800; letter-spacing: -0.01em; }
.detail-meta { color: var(--muted); font-weight: 600; display: flex; gap: 16px; flex-wrap: wrap; margin: 0 0 20px; }
.detail-map { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-strong); box-shadow: var(--shadow); background: #fff; }
.detail-map img { width: 100%; display: block; }
.detail-map iframe { width: 100%; min-width: 100%; height: clamp(420px, 72vh, 700px); border: 0; display: block; }
.detail-map-note { font-size: .78rem; color: var(--muted-2); font-weight: 600; font-style: italic; margin: 8px 0 0; }
.specs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 24px 0; padding: 0; }
.specs div {
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-top: 3px solid var(--orange);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.specs div:last-child { border-top-color: var(--ink); }
.specs dt { color: var(--muted-2); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.specs dd { margin: 4px 0 0; font-size: 1.25rem; font-weight: 700; color: var(--ink); }
.ride-photos {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: -6px 0 24px;
}
.ride-photo-thumb {
  aspect-ratio: 4 / 3;
  width: 100%;
  display: block;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .58);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.ride-photo-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform .16s ease, opacity .16s ease;
}
.ride-photo-thumb:hover img { transform: scale(1.025); opacity: .94; }
.ride-photo-thumb:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 3px;
}
.photo-dialog {
  width: min(1040px, 92vw);
  max-height: 88vh;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .44);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .22);
  box-shadow: 0 28px 80px -30px rgba(15, 30, 61, .58);
  backdrop-filter: blur(18px);
}
.photo-dialog::backdrop {
  background: rgba(15, 30, 61, .42);
  backdrop-filter: blur(8px);
}
.photo-dialog-image {
  width: 100%;
  max-height: 88vh;
  display: block;
  object-fit: contain;
}
.photo-dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, .42);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, .78);
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 28px -18px rgba(15, 30, 61, .8);
}
.photo-dialog-close:hover { background: rgba(255, 255, 255, .92); }
.photo-dialog-close:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}
body.has-ride-cover .detail-map,
body.has-ride-cover .specs div,
body.has-ride-cover .ride-photo-thumb {
  background-color: rgba(255, 255, 255, .68);
  backdrop-filter: blur(12px);
}
.detail-description { margin: 24px 0; }
.detail-links { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.btn { display: inline-block; padding: 10px 18px; border-radius: var(--radius); font-weight: 700; color: #fff; }
.btn:hover { text-decoration: none; opacity: .92; }
.btn-strava { background: #fc4c02; }
.btn-rwgps { background: var(--orange); color: var(--navy); }
.btn-gpx { background: var(--navy); color: #fff; }

@media (max-width: 640px) {
  .ride-photos {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}
