/* ==========================================================================
   Public pages — front page, live race page, public results
   Depends on theme.css for all tokens.
   ========================================================================== */

.public-main { padding: 28px 0 48px; flex: 1; }

/* ==========================================================================
   Hero
   ========================================================================== */

.hero {
  position: relative;
  overflow: hidden;
  background: var(--hero-bg);
  color: var(--hero-text);
}
.hero::before,
.hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
}
.hero::before {
  width: 620px; height: 620px;
  top: -320px; left: -120px;
  background: var(--hero-glow-1);
}
.hero::after {
  width: 520px; height: 520px;
  bottom: -320px; right: -80px;
  background: var(--hero-glow-2);
}
.hero .wrap { position: relative; z-index: 1; padding-top: 56px; padding-bottom: 56px; }

.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  font-weight: 800;
  color: var(--hero-text);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--hero-line);
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  margin-bottom: 18px;
}

.hero h1 {
  color: var(--hero-text);
  max-width: 16ch;
  font-size: clamp(32px, 5.6vw, 60px);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 14px;
}
.hero-sub {
  color: var(--hero-muted);
  font-size: clamp(16px, 2vw, 20px);
  max-width: 52ch;
  margin-bottom: 26px;
}
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Race hero variant: logo + name + status, used on the public race page */
.hero.race-hero .wrap { padding-top: 40px; padding-bottom: 40px; }

.race-identity {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.race-identity .race-logo {
  box-shadow: var(--shadow-lg);
}
.race-identity .race-logo-fallback {
  background: rgba(255, 255, 255, 0.10);
  border-color: var(--hero-line);
  color: var(--hero-text);
}
.race-identity h1 { margin-bottom: 6px; max-width: none; }
.race-meta {
  display: flex;
  gap: 8px 16px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--hero-muted);
  font-size: 15px;
}
.race-meta b { color: var(--hero-text); font-weight: 700; }
.race-meta .badge { border-color: var(--hero-line); }
.race-meta .badge.active   { background: rgba(255,255,255,.14); color: var(--hero-text); }
.race-meta .badge.active::before { background: var(--hero-text); }
.race-meta .badge.draft    { background: rgba(255,255,255,.08); color: var(--hero-muted); }
.race-meta .badge.finished { background: rgba(255,255,255,.14); color: var(--hero-text); }

/* Live clock strip inside the hero */
.hero-clock {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 1px;
  background: var(--hero-line);
  border: 1px solid var(--hero-line);
  border-radius: var(--radius);
  overflow: hidden;
}
.hero-clock .cell {
  background: rgba(0, 0, 0, 0.22);
  padding: 16px 18px;
}
.hero-clock .cell .label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--hero-muted);
  margin-bottom: 4px;
}
.hero-clock .cell .value {
  display: block;
  font-size: 30px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--hero-text);
}
.hero-clock .cell .value.countdown { font-family: var(--font-mono); letter-spacing: -0.02em; }
.hero-clock .cell .sub { font-size: 12px; color: var(--hero-muted); }

/* The countdown turns red in the last five minutes of a lap */
.hero-clock .cell.urgent .value { color: #ffd7d7; }
.hero-clock .cell.urgent { background: rgba(232, 57, 59, 0.34); }

/* ==========================================================================
   Race cards on the front page
   ========================================================================== */

.race-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: 16px;
}

.race-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.race-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}
.race-card.is-live { border-color: var(--brand-line); }
.race-card.is-live::before {
  content: "";
  display: block;
  height: 3px;
  margin: -18px -18px 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

.race-card-head { display: flex; gap: 14px; align-items: flex-start; }
.race-card-head .title { flex: 1; min-width: 0; }
.race-card-head h3 { margin: 0 0 4px; font-size: 19px; }
.race-card-head .where { font-size: 14px; color: var(--text-muted); }

.race-card-facts {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.race-card-facts .fact .n {
  display: block;
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.race-card-facts .fact .k {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.race-card-leader {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--brand-soft);
  border: 1px solid var(--brand-line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
}
.race-card-leader .k {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 800;
  color: var(--brand);
}
.race-card-leader .v { font-weight: 700; }

/* ==========================================================================
   Leader hero on the live page
   ========================================================================== */

.leader-hero {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  background: linear-gradient(100deg, var(--brand-soft), var(--accent-soft));
  border: 1px solid var(--brand-line);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 20px;
}
.leader-hero .crown {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}
.leader-hero .who { flex: 1; min-width: 200px; }
.leader-hero .k {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  font-weight: 800;
  color: var(--brand);
}
.leader-hero .name { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.leader-hero .n {
  font-size: 40px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--brand);
}
.leader-hero .n small {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ==========================================================================
   "How it works" explainer
   ========================================================================== */

.explainer { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); gap: 16px; }
.explainer .point {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.explainer .point .n {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 10px;
}
.explainer .point h3 { font-size: 16px; margin-bottom: 6px; }
.explainer .point p { font-size: 14px; color: var(--text-muted); margin: 0; }

/* ==========================================================================
   Live-refresh indicator
   ========================================================================== */

.live-note {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-muted);
}
.live-note .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .live-note .dot { animation: none; }
}

/* ==========================================================================
   Public tabs (Standings / Teams)
   ========================================================================== */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}
.tabs button {
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

.tab-panel[hidden] { display: none; }

@media (max-width: 720px) {
  .hero .wrap { padding-top: 36px; padding-bottom: 36px; }
  .leader-hero .name { font-size: 21px; }
}

/* ==========================================================================
   Embedded live stream
   ========================================================================== */

.stream-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  /* Capped so the standings — the reason people are on this page — stay
     within reach instead of being pushed below a full-width video. */
  max-width: 820px;
  margin-inline: auto;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
  border: 1px solid var(--border);
}
.stream-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ==========================================================================
   Search + paging over a long list
   ========================================================================== */

.list-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.list-toolbar .input { flex: 1; min-width: 220px; max-width: 380px; }
.list-count {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.pager[hidden] { display: none; }
.pager-pages {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 5em;
  text-align: center;
}

@media (max-width: 720px) {
  /* The identity block reads better stacked than squeezed side by side. */
  .race-identity { gap: 14px; }
  .race-identity .race-logo.lg,
  .race-identity .race-logo-fallback.lg { width: 76px; height: 76px; font-size: 24px; }
  .race-meta { font-size: 13px; gap: 6px 12px; }

  .hero-clock { grid-template-columns: 1fr 1fr; }
  .hero-clock .cell { padding: 11px 13px; }
  .hero-clock .cell .value { font-size: 24px; }

  .list-toolbar { flex-direction: column; align-items: stretch; }
  .list-toolbar .input { max-width: none; }
  .list-count { white-space: normal; }

  .leader-hero { padding: 14px; gap: 12px; }
  .leader-hero .n { font-size: 30px; }

  .race-card-facts { gap: 12px; }
  .stream-frame { border-radius: var(--radius-sm); }
}

/* ==========================================================================
   Standings on a phone
   --------------------------------------------------------------------------
   A six-column table squeezed into 360px wraps every name onto three lines.
   Below 560px each runner becomes a single compact line instead: place on the
   left, name in the middle, laps on the right, everything else underneath.
   ========================================================================== */

@media (max-width: 560px) {
  .standings thead { display: none; }
  .standings,
  .standings tbody { display: block; }

  .standings tbody tr {
    display: grid;
    grid-template-columns: 2.2em 1fr auto;
    grid-template-areas:
      "lead name laps"
      "lead meta laps";
    align-items: center;
    gap: 1px 10px;
    padding: 11px 2px;
    border-bottom: 1px solid var(--border);
  }
  .standings tbody tr:hover { background: none; }

  .standings tbody td { display: block; border: 0; padding: 0; }

  .standings .cell-name {
    grid-area: name;
    font-weight: 700;
    line-height: 1.25;
    /* An unusually long name would otherwise run to three lines and make
       that one row twice the height of its neighbours. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .standings .laps-cell {
    grid-area: laps;
    align-self: center;
    font-size: 22px;
    padding-left: 8px;
  }

  /* The leading slot is the runner's marker: the running figure while they
     are out, the place number once they have stopped. Never both, and never
     wrapped underneath the name. */
  .standings .cell-status,
  .standings .rank {
    grid-area: lead;
    align-self: center;
    justify-self: start;
  }
  .standings tbody tr:not(.is-dnf) .rank { display: none; }
  .standings tbody tr.is-dnf .cell-status { display: none; }
  .standings .cell-status .badge {
    padding: 0;
    border: 0;
    background: none;
  }
  .standings .cell-status .run-icon { width: 20px; height: 20px; }

  /* Bib and the rest share one quiet line under the name. */
  .standings .bib,
  .standings .cell-team,
  .standings .cell-km,
  .standings .cell-last,
  .standings .cell-notes {
    grid-area: meta;
    display: inline-block;
    font-size: 12px;
    margin-right: 8px;
    vertical-align: middle;
  }
  .standings .cell-km::after { content: " km"; }
  .standings .cell-notes { color: var(--text-muted); font-style: italic; }

  /* Runners who stopped read as a second list, with their distance beside
     the bib rather than on a line of their own. */
  .standings .dnf-km { display: inline; color: var(--text-muted); }

  .standings tbody tr.is-dnf { background: var(--panel-2); }
  .standings tbody tr:not(.is-dnf) + tr.is-dnf {
    grid-template-areas:
      "head head head"
      "lead name laps"
      "lead meta laps";
    margin-top: 14px;
    border-top: 0;
  }
  .standings tbody tr:not(.is-dnf) + tr.is-dnf::before {
    content: attr(data-group-label);
    grid-area: head;
    margin: -11px -2px 8px;
    padding: 5px 10px;
    background: var(--danger-soft);
    color: var(--danger);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  /* The rule between the field and the DNFs still has to read. */
  .standings tbody tr:not(.is-dnf) + tr.is-dnf { border-top: 2px solid var(--border-strong); }
  .standings tbody tr:not(.is-dnf) + tr.is-dnf td { border-top: 0; }
}


/* The DNF distance rides in the bib cell so no column is added; on a wide
   screen the dedicated km column already carries it. */
.dnf-km { display: none; }
