/* RaceAura — base stylesheet. Plain modern CSS, no build step.
 * Structure: tokens → reset → layout → components → pages → utilities. */

/* ---------- Tokens ---------- */
:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --c-bg: #f8fafc;
  --c-surface: #ffffff;
  --c-surface-2: #f1f5f9;
  --c-text: #0f172a;
  --c-muted: #64748b;
  --c-border: #e2e8f0;
  --c-ink: #0f172a;
  --c-primary: #ea580c;
  --c-primary-strong: #c2410c;
  --c-accent: #e11d48;
  --c-focus: #2563eb;
  --c-success: #15803d;
  --c-warning: #b45309;
  --c-danger: #b91c1c;
  --grad-aura: linear-gradient(120deg, #f97316 0%, #e11d48 55%, #7c3aed 100%);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 4px 16px rgb(15 23 42 / 6%);
  --container: 1200px;
  --space: 1rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg: #0b1120;
    --c-surface: #111a2e;
    --c-surface-2: #17223a;
    --c-text: #e2e8f0;
    --c-muted: #94a3b8;
    --c-border: #24324d;
    --c-primary: #fb923c;
    --c-primary-strong: #f97316;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--c-text);
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
img, svg { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.75rem, 3vw, 2.5rem); letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
a { color: var(--c-primary-strong); text-underline-offset: 2px; }
@media (prefers-color-scheme: dark) { a { color: var(--c-primary); } }
:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; border-radius: 4px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.container { width: min(100% - 2rem, var(--container)); margin-inline: auto; }
.site-main { flex: 1; }
.section { padding-block: 2.5rem; }
.section__head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }

.skip-link {
  position: absolute; left: -9999px; top: .5rem; z-index: 1000;
  background: var(--c-surface); padding: .5rem 1rem; border-radius: var(--radius-sm);
}
.skip-link:focus { left: .5rem; }

.site-header {
  background: var(--c-ink);
  color: #fff;
  position: sticky; top: 0; z-index: 1100;
  border-bottom: 1px solid rgb(255 255 255 / 8%);
}
.site-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 60px; }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-size: 1.2rem; }
.brand strong { background: var(--grad-aura); -webkit-background-clip: text; background-clip: text; color: transparent; }
.site-nav { display: flex; gap: .25rem; }
.site-nav a { color: #cbd5e1; text-decoration: none; padding: .45rem .75rem; border-radius: 999px; font-weight: 500; }
.site-nav a:hover { color: #fff; background: rgb(255 255 255 / 8%); }
.site-nav a[aria-current="page"] { color: #fff; background: rgb(255 255 255 / 14%); }

.site-footer { background: var(--c-surface); border-top: 1px solid var(--c-border); margin-top: 3rem; padding-block: 2rem; }
.site-footer__nav { display: flex; flex-wrap: wrap; gap: 1rem; }

/* ---------- Buttons ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.2;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.button:active { transform: translateY(1px); }
.button--primary { background: var(--c-primary); color: #fff; }
.button--primary:hover { background: var(--c-primary-strong); color: #fff; }
.button--ghost { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border); }
.button--ghost:hover { border-color: var(--c-muted); }
.button--small { padding: .35rem .75rem; font-size: .9rem; }
.link-button { background: none; border: 0; padding: 0; color: var(--c-primary-strong); text-decoration: underline; cursor: pointer; }

/* ---------- Tags, chips, badges ---------- */
.tags, .chips { display: flex; flex-wrap: wrap; gap: .35rem; list-style: none; padding: 0; margin: 0; }
.tag {
  --disc: #64748b;
  display: inline-block; padding: .15rem .6rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; text-decoration: none;
  color: var(--disc); background: color-mix(in srgb, var(--disc) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--disc) 30%, transparent);
}
@media (prefers-color-scheme: dark) { .tag { color: color-mix(in srgb, var(--disc) 60%, white); } }
.tag--small { font-size: .7rem; padding: .05rem .45rem; margin-left: .35rem; vertical-align: middle; }
.chip {
  font-size: .8rem; padding: .1rem .55rem; border-radius: var(--radius-sm);
  background: var(--c-surface-2); color: var(--c-text); border: 1px solid var(--c-border);
}
.badge {
  display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
  background: var(--c-surface-2); color: var(--c-muted);
}
.badge--reg-open { background: color-mix(in srgb, var(--c-success) 15%, transparent); color: var(--c-success); }
.badge--reg-sold_out, .badge--cancelled { background: color-mix(in srgb, var(--c-danger) 14%, transparent); color: var(--c-danger); }
.badge--reg-waitlist, .badge--reg-lottery, .badge--warning { background: color-mix(in srgb, var(--c-warning) 15%, transparent); color: var(--c-warning); }
@media (prefers-color-scheme: dark) {
  .badge--reg-open { color: #4ade80; }
  .badge--reg-sold_out, .badge--cancelled { color: #f87171; }
  .badge--reg-waitlist, .badge--reg-lottery, .badge--warning { color: #fbbf24; }
}

/* ---------- Forms ---------- */
input[type="search"], input[type="text"], input[type="date"], select {
  width: 100%; padding: .55rem .75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--c-border); background: var(--c-surface);
}
input:focus, select:focus { border-color: var(--c-focus); }
label, legend { font-weight: 600; font-size: .9rem; display: block; margin-bottom: .35rem; }
.field { margin-bottom: 1.1rem; }
.field--inline { display: flex; align-items: center; gap: .5rem; margin: .5rem 0; }
.field--inline label { margin: 0; white-space: nowrap; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.field-row .field { margin: 0; }
.field__hint:empty { display: none; }

.checklist > div { display: grid; gap: .15rem; }
.checklist label { font-weight: 400; display: flex; align-items: center; gap: .5rem; margin: 0; cursor: pointer; padding: .15rem 0; }
.checklist input[type="checkbox"] { width: 1.05rem; height: 1.05rem; accent-color: var(--c-primary); }
.checklist--scroll { max-height: 12rem; overflow: auto; padding: .25rem .5rem; border: 1px solid var(--c-border); border-radius: var(--radius-sm); }
.checklist-details summary { cursor: pointer; font-weight: 600; font-size: .9rem; margin: .5rem 0; }
.near-me { display: flex; align-items: center; gap: .75rem; }

/* ---------- Browse pages (list / map / calendar) ---------- */
.browse { padding-block: 1.75rem; }
.browse__header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; }
.browse__header p { margin: 0; }
.browse__layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.browse__sidebar { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }

.filters { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.filters__head { display: flex; justify-content: space-between; align-items: baseline; }
.filters__title { font-size: 1.05rem; }
.filters__submit { width: 100%; }
.js .filters[hx-get] .filters__submit { display: none; }
.filters-toggle { display: none; margin-bottom: 1rem; }

.view-switcher { display: inline-flex; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 999px; padding: .2rem; }
.view-switcher a { padding: .4rem 1rem; border-radius: 999px; text-decoration: none; color: var(--c-muted); font-weight: 600; font-size: .9rem; }
.view-switcher a[aria-current="page"] { background: var(--c-ink); color: #fff; }
@media (prefers-color-scheme: dark) { .view-switcher a[aria-current="page"] { background: var(--c-primary); color: #111; } }

.results__bar { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.results__count { margin: 0; color: var(--c-muted); }

.race-list { display: grid; gap: .75rem; }
.race-list--grid { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

.race-card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: start;
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); position: relative;
  transition: border-color .15s, transform .15s;
}
.race-card:hover { border-color: color-mix(in srgb, var(--c-primary) 50%, var(--c-border)); }
.race-card:focus-within { border-color: var(--c-focus); }
.race-card.is-cancelled .race-card__title a { text-decoration: line-through; }
.race-card__date {
  display: grid; justify-items: center; min-width: 3.6rem; padding: .4rem .25rem;
  border-radius: var(--radius-sm); background: var(--c-ink); color: #fff; line-height: 1.1;
}
.race-card__day { font-size: 1.45rem; font-weight: 800; }
.race-card__month { font-size: .8rem; text-transform: uppercase; font-weight: 700; color: #fdba74; }
.race-card__year { font-size: .7rem; color: #94a3b8; }
.race-card__title { margin: 0 0 .2rem; font-size: 1.1rem; }
.race-card__title a { color: var(--c-text); text-decoration: none; }
.race-card__title a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); } /* whole card clickable */
.race-card__meta { color: var(--c-muted); font-size: .9rem; margin: 0 0 .5rem; display: flex; flex-wrap: wrap; gap: .35rem; }
.race-card .tags { margin-bottom: .45rem; }

.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.5rem; }

.empty-state { text-align: center; padding: 3rem 1rem; background: var(--c-surface); border: 1px dashed var(--c-border); border-radius: var(--radius); }

.spinner { width: 18px; height: 18px; border: 2px solid var(--c-border); border-top-color: var(--c-primary); border-radius: 50%; animation: spin .8s linear infinite; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Map ---------- */
.race-map { border-radius: var(--radius); border: 1px solid var(--c-border); overflow: hidden; background: var(--c-surface-2); z-index: 0; }
.race-map--large { height: min(72vh, 760px); min-height: 420px; }
.race-map--small { height: 260px; border: 0; border-radius: 0; }
.map-popup { min-width: 200px; font-family: var(--font-sans); }
.map-popup__title { font-weight: 700; font-size: 1rem; display: block; margin-bottom: .2rem; }
.map-popup__meta { color: #475569; font-size: .85rem; }
.map-popup__chips { margin-top: .35rem; font-size: .8rem; font-weight: 600; }
.map-popup__status { margin-top: .35rem; font-size: .8rem; color: #b45309; font-weight: 700; }

/* ---------- Calendar ---------- */
.calendar__nav { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.calendar__nav h2 { margin: 0; min-width: 10ch; text-align: center; }
.calendar__grid { border: 1px solid var(--c-border); border-radius: var(--radius); overflow: hidden; background: var(--c-surface); box-shadow: var(--shadow); }
.calendar__row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar__row + .calendar__row { border-top: 1px solid var(--c-border); }
.calendar__weekday { padding: .5rem; font-size: .8rem; font-weight: 700; text-transform: uppercase; color: var(--c-muted); background: var(--c-surface-2); }
.calendar__day { min-height: 6.5rem; padding: .35rem; display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.calendar__day + .calendar__day { border-left: 1px solid var(--c-border); }
.calendar__day.is-outside { background: var(--c-surface-2); }
.calendar__day.is-outside .calendar__date { color: var(--c-muted); opacity: .6; }
.calendar__date { font-size: .85rem; font-weight: 700; }
.calendar__day.is-today .calendar__date { background: var(--c-primary); color: #fff; border-radius: 999px; width: 1.7rem; height: 1.7rem; display: grid; place-items: center; }
.calendar__event {
  --disc: #64748b;
  display: block; font-size: .75rem; line-height: 1.3; padding: .15rem .35rem; border-radius: 4px;
  text-decoration: none; color: var(--c-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: color-mix(in srgb, var(--disc) 14%, transparent); border-left: 3px solid var(--disc);
}
.calendar__event.is-cancelled { text-decoration: line-through; opacity: .6; }
.calendar__list-title { margin-top: 2rem; }

/* ---------- Race detail ---------- */
.race-hero { background: var(--c-ink); color: #f8fafc; padding-block: 2rem 2.25rem; position: relative; overflow: hidden; }
.race-hero::after { content: ""; position: absolute; inset: auto -10% -60% 40%; height: 120%; background: var(--grad-aura); filter: blur(80px); opacity: .35; pointer-events: none; }
.race-hero .container { position: relative; z-index: 1; }
.race-hero a { color: #fdba74; }
.race-hero .tags { margin-bottom: .75rem; }
.race-hero .tag { color: #fff; background: color-mix(in srgb, var(--disc) 45%, transparent); border-color: color-mix(in srgb, var(--disc) 70%, transparent); }
.race-hero__title { font-size: clamp(2rem, 4.5vw, 3rem); margin-bottom: .4rem; }
.race-hero__year { color: #94a3b8; font-weight: 400; }
.race-hero__meta { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem; color: #cbd5e1; font-size: 1.05rem; }
.race-hero__countdown { font-weight: 700; color: #fdba74; }
.race-hero__actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.25rem; }
.race-hero .button--ghost { background: transparent; color: #fff; border-color: rgb(255 255 255 / 35%); }
.breadcrumbs { color: #94a3b8; margin-bottom: 1rem; }
.breadcrumbs a { color: #cbd5e1; }
.notice { display: inline-block; background: rgb(255 255 255 / 10%); padding: .4rem .8rem; border-radius: var(--radius-sm); }

.race-detail__layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.5rem; margin-top: 1.5rem; align-items: start; }
.race-detail__main { display: grid; gap: 1.5rem; }
.race-detail__aside { display: grid; gap: 1rem; }
.panel { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.panel--flush { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--c-border); vertical-align: top; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--c-muted); }
.table tbody tr:last-child > * { border-bottom: 0; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0; }
.facts dt { color: var(--c-muted); font-size: .9rem; }
.facts dd { margin: 0; font-weight: 500; }
.plain-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.prose { max-width: 70ch; }

/* ---------- Home ---------- */
.hero { background: var(--c-ink); color: #fff; padding-block: 4rem 4.5rem; position: relative; overflow: hidden; }
.hero::before { content: ""; position: absolute; inset: -40% -20% auto 30%; height: 160%; background: var(--grad-aura); filter: blur(110px); opacity: .45; pointer-events: none; }
.hero__inner { position: relative; max-width: 860px; }
.hero__eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .8rem; font-weight: 700; color: #fdba74; }
.hero__title { font-size: clamp(2.25rem, 6vw, 4rem); letter-spacing: -0.03em; margin-bottom: .75rem; }
.hero__accent { background: var(--grad-aura); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero__lead { font-size: 1.15rem; color: #cbd5e1; max-width: 60ch; }
.hero-search { display: grid; grid-template-columns: 1.6fr 1fr auto; gap: .5rem; background: rgb(255 255 255 / 8%); padding: .5rem; border-radius: 999px; border: 1px solid rgb(255 255 255 / 15%); margin-top: 1.5rem; }
.hero-search input, .hero-search select { border-radius: 999px; border: 0; background: #fff; color: #0f172a; padding: .7rem 1rem; }
.hero__links { display: flex; gap: 1.5rem; margin-top: 1.25rem; }
.hero__links a { color: #fdba74; font-weight: 600; }

.discipline-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; }
.discipline-tile {
  --disc: #64748b;
  display: grid; gap: .25rem; padding: 1rem 1.1rem; border-radius: var(--radius); text-decoration: none;
  background: var(--c-surface); border: 1px solid var(--c-border); border-top: 4px solid var(--disc);
  color: var(--c-text); box-shadow: var(--shadow); transition: transform .15s;
}
.discipline-tile:hover { transform: translateY(-2px); }
.discipline-tile__name { font-weight: 700; }
.discipline-tile__count { color: var(--c-muted); font-size: .85rem; }

/* ---------- Leaflet overrides ---------- */
.leaflet-container { font-family: var(--font-sans); }
.leaflet-popup-content a.map-popup__title { color: #c2410c; }

/* ---------- Utilities ---------- */
.muted { color: var(--c-muted); }
.small { font-size: .875rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .browse__layout, .race-detail__layout { grid-template-columns: 1fr; }
  .browse__sidebar { position: static; max-height: none; display: none; }
  .browse__sidebar.is-open { display: block; }
  html:not(.js) .browse__sidebar { display: block; }
  .js .filters-toggle { display: inline-flex; }
}
@media (max-width: 640px) {
  .site-nav a { padding: .4rem .55rem; font-size: .95rem; }
  .brand span { display: none; }
  .hero { padding-block: 2.5rem 3rem; }
  .hero-search { grid-template-columns: 1fr; border-radius: var(--radius); }
  .race-card { grid-template-columns: auto 1fr; }
  .race-card__status { grid-column: 2; }
  .calendar__day { min-height: 4.5rem; padding: .2rem; }
  .calendar__event { font-size: 0; height: .5rem; padding: 0; border-left-width: 0; background: var(--disc); }
  .calendar__more { font-size: .65rem; }
  .calendar__weekday { font-size: .65rem; padding: .35rem .2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Badges on the dark race hero */
.race-hero .badge { background: rgb(255 255 255 / 12%); color: #e2e8f0; }
.race-hero .badge--reg-open { color: #4ade80; }
.race-hero .badge--reg-sold_out, .race-hero .badge--cancelled { color: #fca5a5; }
.race-hero .badge--reg-waitlist, .race-hero .badge--reg-lottery, .race-hero .badge--warning { color: #fcd34d; }

.attribution { margin: 1rem 0 0; }
.prose code, .prose pre { background: var(--c-surface-2); border-radius: 6px; padding: .1rem .35rem; }
.prose pre { padding: .75rem 1rem; overflow-x: auto; }
