/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-bg:        #f4f6f9;
  --clr-surface:   #ffffff;
  --clr-primary:   #1a6ef5;
  --clr-primary-d: #1356c4;
  --clr-accent:    #f97316;
  --clr-success:   #16a34a;
  --clr-danger:    #dc2626;
  --clr-text:      #1e293b;
  --clr-muted:     #64748b;
  --clr-border:    #e2e8f0;
  --clr-upcoming-bg: #eff6ff;
  --clr-upcoming-border: #93c5fd;
  --radius:        10px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08);
  --shadow-md:     0 4px 12px rgba(0,0,0,.10);
  --transition:    0.2s ease;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--clr-bg);
  color: var(--clr-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Hero ===== */
.hero {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 60%, #1a6ef5 100%);
  color: #fff;
  padding: 56px 24px 48px;
  text-align: center;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}
.hero h1 span { color: #60a5fa; }
.hero p {
  color: #93c5fd;
  font-size: 1.05rem;
}

.hero-actions {
  margin-top: 18px;
}

.hero-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
}

.hero-link:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.32);
  transform: translateY(-1px);
}

.gallery-page {
  padding-top: 32px;
}

.gear-page {
  padding-top: 32px;
}

.hero-gallery p {
  max-width: 36rem;
  margin: 0 auto;
}

.hero-gear p {
  max-width: 36rem;
  margin: 0 auto;
}

/* ===== Stats bar ===== */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 24px;
  background: var(--clr-surface);
  padding: 20px 24px;
  border-bottom: 1px solid var(--clr-border);
  box-shadow: var(--shadow-sm);
}
.stat-item { text-align: center; }
.stat-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--clr-primary);
  line-height: 1.1;
}
.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--clr-muted);
}

/* ===== Personal bests ===== */
.pbs-section {
  max-width: 1200px;
  margin: 24px auto 0;
  padding: 0 20px;
}

.pbs-header {
  margin-bottom: 14px;
}

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

.pb-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
}

.pb-label {
  color: var(--clr-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.pb-value {
  font-size: 1.35rem;
  line-height: 1.2;
  font-weight: 800;
  color: var(--clr-primary);
  font-variant-numeric: tabular-nums;
}

.pb-meta {
  margin-top: 5px;
  color: var(--clr-muted);
  font-size: 0.78rem;
}

/* ===== Main layout ===== */
main { max-width: 1200px; margin: 0 auto; padding: 40px 20px 60px; }

/* ===== Section headings ===== */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.section-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-upcoming { background: #dbeafe; color: #1d4ed8; }
.badge-past     { background: #f1f5f9; color: #475569; }

/* ===== Upcoming Race Cards ===== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 52px;
}
.race-card {
  background: var(--clr-surface);
  border: 1.5px solid var(--clr-upcoming-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.race-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.race-card .card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.race-card .card-name {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}
.race-card .card-name a { color: var(--clr-text); text-decoration: none; }
.race-card .card-name a:hover { color: var(--clr-primary); }
.distance-pill {
  white-space: nowrap;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #dbeafe;
  color: #1d4ed8;
  flex-shrink: 0;
}
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.82rem;
  color: var(--clr-muted);
}
.meta-row span { display: flex; align-items: center; gap: 4px; }
.card-target {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.85rem;
}
.calendar-date-button {
  border: 0;
  background: transparent;
  color: var(--clr-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.calendar-date-button:hover {
  color: var(--clr-primary-d);
}

.card-target .label { color: var(--clr-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.card-target .value { font-weight: 700; color: var(--clr-success); font-size: 1rem; }
.card-target .subvalue { margin-top: 2px; color: var(--clr-muted); font-size: 0.78rem; }
.card-notes { font-size: 0.8rem; color: var(--clr-muted); font-style: italic; border-top: 1px solid var(--clr-border); padding-top: 8px; }

.race-tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.race-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.race-tag-road {
  background: #e0f2fe;
  color: #0369a1;
}

.race-tag-trail {
  background: #ecfccb;
  color: #3f6212;
}

.race-tag-strava {
  background: #fc4c02;
  color: #fff;
  text-decoration: none;
}

.race-tag-strava:hover {
  background: #de4301;
  color: #fff;
}

/* ===== Race map ===== */
.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.map-legend,
.map-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  color: var(--clr-muted);
  font-size: 0.84rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.legend-dot-raced { background: #16a34a; }
.legend-dot-planned { background: #f97316; }
.legend-dot-both { background: #1a6ef5; }

.map-toggles input {
  accent-color: var(--clr-primary);
}

.map-wrapper {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 10px;
}

#race-map {
  width: 100%;
  height: clamp(280px, 45vw, 460px);
  border-radius: 8px;
  overflow: hidden;
}

/* ===== Race galleries ===== */
.gallery-grid {
  display: grid;
  gap: 18px;
}

.gallery-race-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.gallery-race-head {
  margin-bottom: 12px;
}

.gallery-race-head h3 {
  font-size: 1rem;
  line-height: 1.3;
  margin-bottom: 6px;
}

.gallery-race-head h3 a {
  color: var(--clr-text);
  text-decoration: none;
}

.gallery-race-head h3 a:hover {
  color: var(--clr-primary);
}

.gallery-race-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.82rem;
  color: var(--clr-muted);
}

.gallery-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.gallery-photo {
  display: block;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--clr-border);
  text-decoration: none;
  background: #f8fafc;
}

.gallery-photo img {
  display: block;
  width: 100%;
  height: 145px;
  object-fit: cover;
}

.gallery-photo-caption {
  padding: 6px 8px;
  font-size: 0.74rem;
  line-height: 1.35;
  color: var(--clr-muted);
}

/* ===== Gear ===== */
.gear-grid {
  display: grid;
  gap: 18px;
}

.gear-item-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gear-category-section + .gear-category-section {
  margin-top: 28px;
}

.gear-category-header {
  margin-bottom: 16px;
}

.gear-category-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.gear-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  width: 100%;
}

.gear-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.gear-card-head > div {
  min-width: 0;
}

.gear-card h4 {
  font-size: 1rem;
  line-height: 1.35;
}

.gear-card h4 a {
  color: var(--clr-text);
  text-decoration: none;
}

.gear-card h4 a:hover {
  color: var(--clr-primary);
}

.gear-status {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 700;
}

.gear-status-active {
  background: #dcfce7;
  color: #166534;
}

.gear-status-retired {
  background: #e2e8f0;
  color: #475569;
}

.gear-status-neutral {
  background: #e0f2fe;
  color: #0369a1;
}

.gear-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 10px 12px;
}

.gear-meta div {
  min-width: 0;
}

.gear-meta dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--clr-muted);
  margin-bottom: 2px;
}

.gear-meta dd {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--clr-text);
  word-break: break-word;
}

.gear-notes {
  margin-top: 12px;
  color: var(--clr-muted);
  font-size: 0.88rem;
}

/* ===== Lightbox ===== */
body.lightbox-open {
  overflow: hidden;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 20px;
}

.lightbox[hidden] {
  display: none !important;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
}

.lightbox-dialog {
  position: relative;
  z-index: 1;
  width: min(980px, 100%);
  max-height: calc(100vh - 40px);
  background: #0b1220;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lightbox-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lightbox-nav,
.lightbox-close {
  align-self: flex-end;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.8);
  color: #e2e8f0;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.82rem;
  cursor: pointer;
}

.lightbox-nav:hover,
.lightbox-close:hover {
  background: rgba(26, 110, 245, 0.35);
}

.lightbox-nav:disabled {
  opacity: 0.45;
  cursor: default;
}

.lightbox-counter {
  color: #cbd5e1;
  font-size: 0.82rem;
  min-width: 64px;
  text-align: center;
}

.lightbox-close {
  margin-left: auto;
}

#lightbox-image {
  display: block;
  width: 100%;
  max-height: calc(100vh - 170px);
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-caption {
  color: #cbd5e1;
  font-size: 0.88rem;
  line-height: 1.4;
  text-align: center;
}

.map-popup-list {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 0.8rem;
}

.map-popup-title {
  margin-top: 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--clr-muted);
}

.map-popup-list li {
  margin-bottom: 2px;
}

/* ===== Progress chart ===== */

/* ===== Filters ===== */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.filters-bar label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.82rem;
  color: var(--clr-muted);
}

.filter-tags {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  padding: 6px 10px;
}

.filter-tags-label {
  color: var(--clr-muted);
  font-size: 0.82rem;
  margin-right: 2px;
}

.filter-tags label {
  border: none;
  padding: 0;
  gap: 6px;
  background: transparent;
  color: var(--clr-text);
}

.filter-tags input {
  accent-color: var(--clr-primary);
}

.filters-bar select,
.filters-bar button {
  border: 1px solid var(--clr-border);
  border-radius: 6px;
  background: #fff;
  color: var(--clr-text);
  font-size: 0.82rem;
  padding: 6px 8px;
}

.filters-bar button {
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.filters-bar button:hover {
  background: var(--clr-primary);
  color: #fff;
}

/* ===== Past Races Table ===== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--clr-border);
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--clr-surface);
  font-size: 0.875rem;
}
thead th {
  background: #f8fafc;
  color: var(--clr-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--clr-border);
  white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--clr-primary); }
thead th.sorted { color: var(--clr-primary); }
thead th.sorted::after { content: " ↓"; font-size: 0.7rem; }
thead th.sorted.asc::after { content: " ↑"; }
tbody tr { border-bottom: 1px solid var(--clr-border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
td { padding: 12px 14px; vertical-align: middle; }
td.race-name-cell { font-weight: 600; }
td.race-name-cell a { color: var(--clr-text); text-decoration: none; }
td.race-name-cell a:hover { color: var(--clr-primary); }
td.race-name-cell .sub { font-size: 0.76rem; color: var(--clr-muted); font-weight: 400; margin-top: 2px; }

/* Time comparison cells */
.time-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.time-faster { color: var(--clr-success); font-weight: 600; }
.time-slower  { color: var(--clr-danger); font-weight: 600; }
.time-neutral { color: var(--clr-muted); }

/* Position badge */
.pos-badge { font-size: 0.78rem; color: var(--clr-muted); white-space: nowrap; }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 48px 16px; color: var(--clr-muted); }
.empty-state p { margin-top: 8px; font-size: 0.9rem; }

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 24px;
  font-size: 0.8rem;
  color: var(--clr-muted);
  border-top: 1px solid var(--clr-border);
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .hero { padding: 40px 16px 32px; }
  .stats-bar { gap: 16px; }
  .stat-value { font-size: 1.3rem; }
  #race-map { height: 300px; }
  .filters-bar label { width: 100%; justify-content: space-between; }
  .gallery-photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lightbox { padding: 12px; }
  .lightbox-dialog { padding: 10px; }
  .lightbox-toolbar { flex-wrap: wrap; }
  .lightbox-counter { order: 3; width: 100%; }
  #lightbox-image { max-height: calc(100vh - 130px); }
}
