/* Hallmark · shape: app screen · genre: modern-minimal · theme: Cobalt, slate adaptation by request · redesign: full */
/* Hallmark · pre-emit critique: P4 H4 E4 S4 R5 V3 · weakest: V, shared app screens stay familiar */
/* Hallmark · nav: account bar + Map/Runners/Info tabs · signature: course map + linked runner roster · states: loading/empty/error/full · axes: light/grotesk-sans/neutral · posture: restrained */
/* Hallmark · dropped https://cdn.jsdelivr.net/npm/motion@14.6.0/dist/motion.js · Anime.js replaces Motion at the user's request */
/* Hallmark · dismissed F4 · Cancel is transparent and outlined; only Save event has a graphite fill */
/* Hallmark · finish-review: subagent · 5 findings · 5 resolved · contrast: measured · v2.0.0 */

@import url("tokens.css");
@import url("base.css");

/* ---------------------------------------------------------------- header -- */

.skip-link {
  position: absolute; left: var(--space-xs); top: -80px; z-index: var(--z-tooltip);
  padding: var(--space-xs) var(--space-sm); border-radius: var(--r-sm);
  background: var(--color-graphite); color: var(--color-graphite-ink);
}
.skip-link:focus { top: var(--space-xs); }

.site-header {
  position: sticky; top: 0; z-index: var(--z-sticky-nav);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm);
  height: var(--header-h);
  padding: 0 max(var(--pad), env(safe-area-inset-right)) 0 max(var(--pad), env(safe-area-inset-left));
  border-bottom: var(--rule-hair) solid var(--color-rule);
  background: var(--color-paper);
}

.brand {
  display: inline-flex; align-items: center; gap: var(--space-xs);
  min-width: 0; min-height: var(--tap);
  font-size: var(--text-lg); font-weight: 600; letter-spacing: -0.025em; text-decoration: none;
}
.brand-copy { display: inline; }
.brand-eyebrow { display: none; }
.brand-mark { position: relative; flex: none; width: 14px; height: 14px; border: 2px solid var(--color-ink); border-radius: 50%; }
.brand-mark::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--color-accent); }

.account-menu { display: none; position: relative; margin: 0; }
.account-menu > summary { display: grid; place-items: center; list-style: none; cursor: pointer; }
.account-menu > summary::-webkit-details-marker { display: none; }
.avatar {
  display: grid; place-items: center; width: 38px; height: 38px;
  border-radius: 50%; background: var(--color-graphite); color: var(--color-graphite-ink);
  font-size: var(--text-sm); font-weight: 600;
}
.avatar--guest { background: var(--color-paper-2); color: var(--color-ink-2); }
.avatar svg { width: 20px; height: 20px; }
.account-menu__panel {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: var(--z-dropdown);
  display: grid; gap: 2px; width: 220px; padding: var(--space-xs);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--r-lg);
  background: var(--color-surface); box-shadow: 0 12px 32px oklch(21% 0.028 262 / 0.16);
}
.account-menu__name { margin: 0 0 var(--space-2xs); padding: var(--space-xs); border-bottom: var(--rule-hair) solid var(--color-rule); color: var(--color-muted); font-size: var(--text-xs); }
.account-menu__panel a, .account-menu__panel .link-button {
  display: flex; align-items: center; width: 100%; min-height: 44px; padding: 0 var(--space-sm);
  border-radius: var(--r-sm); font-size: var(--text-sm); font-weight: 500; text-decoration: none;
}
.account-menu__panel a:hover, .account-menu__panel .link-button:hover { background: var(--color-paper-2); }
.account-menu__panel form { margin: 0; }
.account-menu__panel .link-button { justify-content: flex-start; text-align: left; }

.site-nav { display: flex; align-items: center; gap: var(--space-sm); font-size: var(--text-xs); }
.site-nav a, .site-nav .link-button { display: inline-flex; align-items: center; justify-content: center; min-width: var(--tap); min-height: var(--tap); text-decoration: none; }
.site-nav a:hover, .site-nav .link-button:hover { color: var(--color-accent-2); }

.inline-form { display: inline; margin: 0; }
.link-button {
  padding: 0; border: 0; background: var(--color-clear); color: inherit; font: inherit;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.link-button:hover { color: var(--color-accent-2); }

#main { min-height: calc(100vh - var(--header-h)); min-height: calc(100dvh - var(--header-h)); }

/* ------------------------------------------------------------------ pages -- */

.page {
  width: 100%; max-width: 1120px; margin: 0 auto;
  padding: var(--space-xl) max(var(--pad), env(safe-area-inset-right)) var(--space-2xl) max(var(--pad), env(safe-area-inset-left));
}
.page--narrow { max-width: 560px; }

.auth {
  display: grid; align-content: center; gap: var(--space-lg);
  min-height: calc(100vh - var(--header-h)); min-height: calc(100dvh - var(--header-h));
}

.page-heading { display: flex; flex-direction: column; align-items: stretch; gap: var(--space-md); margin-bottom: var(--space-lg); }
.page-heading .button { width: 100%; }

.lede { margin: var(--space-xs) 0 0; max-width: 52ch; color: var(--color-muted); font-size: var(--text-sm); }
.muted { color: var(--color-muted); }
code, .mono { font-family: var(--font-outlier); font-size: 0.9em; }

/* ---------------------------------------------------------------- buttons -- */

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  min-height: var(--tap); padding: var(--space-sm) var(--space-md);
  border: var(--rule-hair) solid var(--color-rule-2); border-radius: var(--r);
  background: var(--color-clear); color: var(--color-ink);
  font: 600 var(--text-sm)/1.2 var(--font-body); text-decoration: none; cursor: pointer;
  transition: transform var(--dur-micro) var(--ease-out), opacity var(--dur-micro) var(--ease-out);
}
.button:hover { background: var(--color-paper-2); border-color: var(--color-muted); }
.button:active { transform: translateY(1px); }
.button:disabled, .button[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.button[aria-busy="true"] { opacity: 0.7; cursor: progress; }

.button--primary { border-color: var(--color-graphite); background: var(--color-graphite); color: var(--color-graphite-ink); }
.button--primary:hover { background: var(--color-graphite-2); border-color: var(--color-graphite-2); }
.button--ghost { border-color: var(--color-muted); }

.button--danger { border-color: color-mix(in oklab, var(--color-error) 45%, var(--color-clear)); color: var(--color-error); }
.button--danger:hover { border-color: var(--color-error); background: var(--color-error); color: var(--color-accent-ink); }

.button--small { padding: var(--space-xs) var(--space-sm); font-size: var(--text-sm); }

.text-link { color: var(--color-ink); font-size: var(--text-sm); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.text-link:hover { color: var(--color-accent-2); }

.card-link {
  display: inline-flex; align-items: center; gap: var(--space-2xs);
  min-height: var(--tap); color: var(--color-accent-2);
  font-size: var(--text-sm); font-weight: 600; white-space: nowrap;
}
.card-link:hover { color: var(--color-ink); }

/* ------------------------------------------------------------------ pills --- */

/* Plain readable label; a wash appears only for an actual live/closed state. */
.status {
  display: inline-flex; align-items: center; padding: var(--space-3xs) var(--space-xs);
  border-radius: var(--r-full); color: var(--color-ink-2);
  font-size: var(--text-sm); font-weight: 600; line-height: 1.3;
}
.status--open { background: var(--color-live-wash); color: var(--color-success); }
.status--closed { background: var(--color-error-wash); color: var(--color-error); }
.status--draft { background: var(--color-paper-2); color: var(--color-ink-2); }
.status--registration { background: var(--color-accent-wash); color: var(--color-accent-2); }

/* ------------------------------------------------------------- event list --- */

.event-tools { display: grid; gap: var(--space-sm); margin: 0 0 var(--space-lg); }
.event-search {
  display: flex; align-items: center; gap: var(--space-xs);
  min-height: 52px; padding: 0 var(--space-md);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--r-full);
  background: var(--color-surface); box-shadow: 0 6px 20px oklch(21% 0.028 262 / 0.05);
}
.event-search svg { flex: none; width: 20px; height: 20px; color: var(--color-muted); }
.event-search input {
  flex: 1; min-width: 0; padding: var(--space-sm) 0;
  border: 0; outline: 0; background: var(--color-clear); color: var(--color-ink);
  font: 500 var(--text-md)/1.3 var(--font-body);
}
.event-search:focus-within { border-color: var(--color-focus); box-shadow: 0 0 0 3px var(--color-accent-wash); }

.event-filters { display: flex; gap: var(--space-2xs); overflow-x: auto; scrollbar-width: none; }
.event-filters::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: none; min-height: 44px; padding: var(--space-xs) var(--space-md);
  border: 0; border-radius: var(--r-full); background: var(--color-clear);
  color: var(--color-ink-2); font: 500 var(--text-sm)/1 var(--font-body); cursor: pointer;
}
.filter-chip:hover { background: var(--color-paper-2); }
.filter-chip.is-active { background: var(--color-graphite); color: var(--color-graphite-ink); font-weight: 600; }

.heading-action {
  display: inline-flex; align-items: center; align-self: flex-start;
  min-height: 44px; color: var(--color-ink-2);
  font-size: var(--text-sm); font-weight: 600; text-decoration: none;
}
.heading-action:hover { color: var(--color-ink); }

.event-carousel {
  display: grid; grid-auto-flow: column; grid-auto-columns: 86%;
  gap: var(--space-sm); margin: 0; padding: var(--space-2xs);
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory;
  scroll-padding-inline: var(--space-2xs); list-style: none;
}
.event-carousel:has(> :only-child) { grid-auto-columns: minmax(0, 1fr); }
.event-card {
  display: flex; flex-direction: column; gap: var(--space-2xs); min-width: 0;
  scroll-snap-align: start;
}
.event-card__cover {
  position: relative; height: min(118vw, 560px); overflow: hidden;
  border-radius: 20px; background:
    radial-gradient(90% 70% at 82% 10%, color-mix(in oklab, var(--color-accent-2) 55%, transparent), transparent 60%),
    var(--color-graphite);
  color: var(--color-graphite-ink); box-shadow: var(--shadow-card);
}
.event-card__cover::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(to top, color-mix(in oklab, var(--color-graphite) 94%, transparent) 0%, transparent 58%);
}
.event-card__link { position: absolute; inset: 0; z-index: 2; border-radius: inherit; }
.event-card__link:focus-visible { outline: 3px solid var(--color-focus); outline-offset: -3px; }
.event-card__cover > .status {
  position: absolute; top: var(--space-md); left: var(--space-md); z-index: 4;
  background: color-mix(in oklab, var(--color-surface) 88%, transparent);
  color: var(--color-ink); pointer-events: none; backdrop-filter: blur(8px);
}
.event-card__date {
  position: absolute; top: var(--space-md); right: var(--space-md); z-index: 4;
  display: grid; justify-items: center; min-width: 52px; padding: var(--space-xs) var(--space-sm);
  border-radius: var(--r-lg); background: var(--color-surface); color: var(--color-ink);
  line-height: 1; box-shadow: var(--shadow-card); pointer-events: none;
}
.event-card__date strong { font-size: var(--text-xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.event-card__date span { margin-top: var(--space-3xs); color: var(--color-muted); font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.event-card .route-preview {
  position: absolute; top: 64px; left: var(--space-lg); right: var(--space-lg); z-index: 1;
  width: calc(100% - 2 * var(--space-lg)); height: auto; color: var(--color-graphite-ink); opacity: 0.9;
}
.event-card .route-preview path { stroke-width: 2.5; }
.event-card .route-preview-empty {
  position: absolute; inset: 30% var(--space-lg) 34%; z-index: 1;
  display: grid; place-items: center; height: auto;
  color: var(--color-graphite-muted); text-align: center;
}
.event-card__caption { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; padding: var(--space-lg); color: var(--color-graphite-ink); pointer-events: none; }
.event-card__caption h2 { max-width: none; color: inherit; font-size: var(--text-lg); line-height: 1.25; }
.event-card__caption h2 a { color: inherit; text-decoration: none; pointer-events: auto; }
.event-card__caption h2 a:hover { text-decoration: underline; text-underline-offset: 3px; }
.event-card__caption p { margin-top: var(--space-2xs); color: color-mix(in oklab, var(--color-graphite-ink) 82%, transparent); font-size: var(--text-sm); }
.event-card .event-details { border-top: 0; padding: 0 var(--space-xs); }
.event-card .event-details summary { min-height: 40px; color: var(--color-muted); font-size: var(--text-xs); }
.event-card .event-meta { margin-bottom: var(--space-sm); }
.event-filter-empty { margin: var(--space-lg) 0 0; color: var(--color-ink-2); font-size: var(--text-sm); }
.route-preview { display: block; flex: none; width: 100%; height: 200px; color: var(--color-route); }
.route-preview path { fill: var(--color-clear); stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.route-preview path.route-preview-arrow { fill: currentColor; stroke: var(--color-surface); stroke-width: 1.5; paint-order: stroke; }
.route-preview-empty { display: grid; place-items: center; height: 200px; color: var(--color-muted); font-size: var(--text-sm); }
.event-details { border-top: var(--rule-hair) solid var(--color-rule); }
.event-details summary { display: list-item; align-content: center; min-height: var(--tap); color: var(--color-ink-2); font-size: var(--text-sm); cursor: pointer; }
.event-details summary:hover { color: var(--color-ink); }
.event-meta { display: grid; gap: var(--space-sm); margin: var(--space-xs) 0 var(--space-md); font-size: var(--text-sm); }
.event-meta > div { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: var(--space-xs); }
.event-meta dt { color: var(--color-muted); font-size: var(--text-xs); }
.event-meta dd { margin: 0; min-width: 0; overflow-wrap: break-word; }

/* ------------------------------------------------------- runner dashboard --- */

.page--dashboard { max-width: 960px; }
.dashboard-section { display: grid; gap: var(--space-sm); margin-top: var(--space-xl); }

/* Runner cards reuse the events cover carousel and overlay the participation details. */
.event-card--runner .event-card__cover { height: min(126vw, 600px); }
.event-card--runner .event-card__cover::after {
  background: linear-gradient(
    to top,
    color-mix(in oklab, var(--color-graphite) 95%, transparent) 0%,
    color-mix(in oklab, var(--color-graphite) 70%, transparent) 48%,
    transparent 86%
  );
}
.event-card__caption--runner { display: grid; gap: var(--space-xs); }
.event-card__caption--runner h3 { color: inherit; font-size: var(--text-lg); line-height: 1.25; }
.event-card__schedule { font-size: var(--text-sm); }
.event-card__stats {
  display: flex; gap: var(--space-lg); padding-top: var(--space-xs);
  border-top: 1px solid color-mix(in oklab, var(--color-graphite-ink) 20%, transparent);
}
.event-card__stats > div { display: grid; gap: 2px; }
.event-card__stats .stat-value { color: var(--color-graphite-ink); font-size: var(--text-lg); }
.event-card__stats .stat-label { color: var(--color-graphite-muted); }
.event-card__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-md); }
.event-card__actions form { margin: 0; }
.overlay-link {
  min-height: 32px; padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--color-graphite-ink); font-size: var(--text-sm); font-weight: 600;
  text-decoration: underline; text-underline-offset: 3px; pointer-events: auto;
}
.overlay-note { color: var(--color-graphite-muted); font-size: var(--text-xs); }
@media (min-width: 640px) {
  .event-card--runner .event-card__cover { height: 460px; }
}
@media (min-width: 900px) {
  .event-card--runner .event-card__cover { height: 420px; }
}

.stat-value { font-size: var(--text-xl); font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { color: var(--color-muted); font-size: var(--text-xs); }

.join-route { max-width: 320px; height: auto; margin: 0 auto var(--space-lg); color: var(--color-route); }
.join-note {
  display: grid; gap: var(--space-sm); margin-bottom: var(--space-lg);
  padding: var(--space-md); border-radius: var(--r-lg);
  background: var(--color-surface); border: var(--rule-hair) solid var(--color-rule);
  font-size: var(--text-sm);
}
.live-guide {
  display: grid; gap: var(--space-xs);
  padding: var(--space-md); border: var(--rule-hair) solid var(--color-rule);
  border-radius: var(--r-lg); background: var(--color-paper-2);
  font-size: var(--text-sm);
}
.live-guide h3 { margin: 0; font-size: var(--text-sm); }
.live-guide ol { margin: 0; padding-left: var(--space-md); color: var(--color-ink-2); }
.live-guide li + li { margin-top: var(--space-3xs); }
.live-guide .help { margin: 0; }
.auth-switch { margin: 0; text-align: center; color: var(--color-muted); font-size: var(--text-sm); }
.auth-switch a { color: var(--color-ink); font-weight: 600; }
.help ul, .auth .helptext { margin: var(--space-2xs) 0 0; padding-left: var(--space-md); color: var(--color-muted); font-size: var(--text-xs); }
.lap-form { padding-top: var(--space-md); border-top: var(--rule-hair) solid var(--color-rule); }
.lap-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); }
.lap-row p { margin: 0; color: var(--color-ink-2); font-size: var(--text-sm); }
.lap-row strong { color: var(--color-ink); font-size: var(--text-lg); font-variant-numeric: tabular-nums; }

.empty {
  padding: var(--space-2xl) var(--space-lg);
  border: var(--rule-hair) dashed var(--color-rule-2); border-radius: var(--r-lg);
  background: var(--color-surface); text-align: center;
}
.empty p { max-width: 46ch; margin: var(--space-md) auto; color: var(--color-ink-2); }
.empty .button { margin-top: var(--space-sm); width: 100%; }

/* --------------------------------------------------------------- messages --- */

.messages {
  width: 100%; max-width: 1120px; margin: 0 auto;
  padding: var(--space-sm) max(var(--pad), env(safe-area-inset-right)) 0 max(var(--pad), env(safe-area-inset-left));
}
.message {
  margin: 0 0 var(--space-xs); padding: var(--space-sm) var(--space-md);
  border-radius: var(--r); background: var(--color-surface); box-shadow: var(--shadow-card);
  font-size: var(--text-sm);
}
.message--error { background: var(--color-error-wash); color: var(--color-error); box-shadow: none; }
.message--success { background: var(--color-live-wash); color: var(--color-success); box-shadow: none; }

/* ------------------------------------------------------------------ forms --- */

/* Flat form: sections separated by hairlines, no outer card. */
.form-card { display: grid; gap: var(--space-lg); }
.field { display: grid; gap: var(--space-xs); }

.field label, .share-block label, .runner-tools label, .rename-form label {
  color: var(--color-ink-2); font-size: var(--text-sm); font-weight: 500;
}

.field input, .field select, .share-block input, .runner-tools input, .rename-row input {
  width: 100%; min-height: var(--tap); padding: var(--space-xs) var(--space-sm);
  border: var(--rule-hair) solid var(--color-muted); border-radius: var(--r-sm);
  background: var(--color-surface); color: var(--color-ink);
  font: 400 var(--text-md)/1.4 var(--font-body);
}
.field input[type="file"] { padding: var(--space-sm); font-size: var(--text-sm); }
.field input:focus, .field select:focus, .share-block input:focus, .runner-tools input:focus, .rename-row input:focus {
  outline: 2px solid var(--color-focus); outline-offset: 1px;
}

.schedule-grid { display: grid; gap: var(--space-md); }

.config-note { display: grid; gap: var(--space-sm); padding-top: var(--space-md); border-top: var(--rule-hair) solid var(--color-rule); }
.config-note h2 { font-size: var(--text-title); }
.config-note > div { display: grid; gap: var(--space-2xs); }

.help { margin: 0; color: var(--color-muted); font-size: var(--text-sm); }
.field-error { margin: 0; color: var(--color-error); font-size: var(--text-sm); font-weight: 500; }
.form-errors { padding: var(--space-sm) var(--space-md); border-radius: var(--r-sm); background: var(--color-error-wash); color: var(--color-error); }
.form-errors p { font-size: var(--text-sm); }

.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); }
.form-actions .button { flex: 1 1 auto; }

/* -------------------------------------------------------------- map shell --- */

.map-page #main { display: flex; flex-direction: column; max-width: 1600px; margin-inline: auto; }
.map-shell { display: grid; flex: 1; min-height: 0; grid-template-columns: minmax(0, 1fr); }
.map-heading {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-md);
  padding: var(--space-md) max(var(--pad), env(safe-area-inset-left));
  border-bottom: var(--rule-hair) solid var(--color-rule); background: var(--color-surface);
}
.map-heading > div { min-width: 0; }
.event-title { font-size: var(--text-section); max-width: none; line-height: 1.3; }

/* Phone: panel content flows above the map; tabs take over once ui.js adds html.js. */
.map-panel { display: contents; }
.panel-inner {
  display: grid; gap: var(--space-lg); align-content: start;
  padding: var(--space-lg) max(var(--pad), env(safe-area-inset-right)) var(--space-2xl) max(var(--pad), env(safe-area-inset-left));
}
.panel-section { display: grid; gap: var(--space-md); align-content: start; }
.panel-section + .panel-section { padding-top: var(--space-lg); border-top: var(--rule-hair) solid var(--color-rule); }

.map-wrap { position: relative; min-height: 0; background: var(--color-map); }
html:not(.js) .map-wrap { height: 60dvh; min-height: 320px; }
#map { position: absolute; inset: 0; z-index: var(--z-base); }

.map-warning {
  position: absolute; bottom: var(--space-lg); left: var(--space-md); right: var(--space-md); z-index: var(--z-toast);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--r-sm); background: var(--color-stale-wash); color: var(--color-stale);
  font-size: var(--text-sm); box-shadow: var(--shadow-card);
}
.map-noscript {
  position: absolute; inset: var(--space-md); z-index: var(--z-toast); max-width: 42ch;
  padding: var(--space-lg); border-radius: var(--r);
  background: var(--color-surface); color: var(--color-ink-2);
  font-size: var(--text-sm); box-shadow: var(--shadow-card);
}

.map-overlay {
  position: absolute; top: var(--space-sm); right: var(--space-sm); z-index: var(--z-toast);
  display: flex; gap: var(--space-xs); max-width: calc(100% - var(--space-lg));
}

.map-chip {
  display: inline-flex; align-items: center; gap: var(--space-xs);
  min-height: var(--tap); padding: var(--space-xs) var(--space-md);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--r-full);
  background: var(--color-surface); color: var(--color-ink);
  font: 600 var(--text-sm)/1 var(--font-body); box-shadow: var(--shadow-card); cursor: pointer;
  transition: transform var(--dur-micro) var(--ease-out), opacity var(--dur-micro) var(--ease-out);
}
.map-chip:hover { background: var(--color-paper-2); }
.map-chip:active { transform: translateY(1px); }
.map-chip__count { font-variant-numeric: tabular-nums; font-weight: 600; }
.map-chip[data-state="live"] .map-chip__count, .map-chip[data-state="ok"] .map-chip__count { color: var(--color-success); }
.map-chip[data-state="stale"] .map-chip__count, .map-chip[data-state="offline"] .map-chip__count { color: var(--color-stale); }
.map-chip[data-state="ended"] .map-chip__count { color: var(--color-error); }

.route-stats {
  position: absolute; bottom: var(--space-sm); left: var(--space-sm); z-index: var(--z-toast);
  display: grid; gap: var(--space-xs); width: 280px; max-width: calc(100% - 2 * var(--space-sm));
  padding: var(--space-xs) var(--space-md) var(--space-sm);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--r);
  background: var(--color-surface); box-shadow: var(--shadow-card);
}
.route-stats__row { display: flex; gap: var(--space-md); }
.route-stats__row > div { display: grid; gap: 1px; }
.route-stats__value { color: var(--color-ink); font-size: var(--text-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
.route-stats__label { color: var(--color-muted); font-size: var(--text-xs); line-height: 1.2; }
.route-elevation {
  display: grid; gap: var(--space-2xs);
  padding-top: var(--space-xs); border-top: var(--rule-hair) solid var(--color-rule);
}
.route-elevation__head { display: flex; align-items: center; gap: var(--space-xs); }
.route-elevation__title { color: var(--color-muted); font-size: var(--text-xs); }
.route-elevation__scale {
  width: 48px; height: 4px; border-radius: var(--r-full);
  background: linear-gradient(90deg, rgb(43, 108, 176), rgb(56, 161, 105) 45%, rgb(214, 158, 46) 72%, rgb(197, 48, 48));
}
.route-elevation__value { margin-left: auto; color: var(--color-ink); font-size: var(--text-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
.route-elevation__profile { display: block; width: 100%; height: 52px; }
.route-elevation__area { fill: url(#route-elevation-fill); }
.route-elevation__line { fill: none; stroke: var(--color-route); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.route-elevation__cursor { stroke: var(--color-ink); stroke-width: 1; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }
.route-elevation__dot { fill: var(--color-surface); stroke: var(--color-ink); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.route-elevation__slider { width: 100%; min-height: 24px; margin: 0; accent-color: var(--color-accent-2); }
.route-elevation__meta {
  display: flex; justify-content: space-between; gap: var(--space-xs);
  color: var(--color-muted); font-size: var(--text-xs); line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* Tabs progressively enhance the readable, script-free panel layout. */
.tabbar { display: none; }

/* Phone-only tab behaviour, gated on html.js so no-JS keeps full content. */
@media (max-width: 899.98px) {
  html.js .map-page #main {
    height: calc(100vh - var(--header-h)); height: calc(100dvh - var(--header-h));
    min-height: 0; overflow: hidden;
  }
  html.js .map-shell { height: 100%; min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto; }
  html.js .map-heading { grid-row: 1; }
  html.js .panel-inner { grid-row: 2; min-height: 0; overflow-y: auto; }
  html.js .map-wrap { grid-row: 2; }
  html.js .panel-section { display: none; }
  html.js .map-shell[data-tab="info"] .panel-section[data-section="info"],
  html.js .map-shell[data-tab="runners"] .panel-section[data-section="runners"] { display: grid; }
  html.js .panel-section + .panel-section { padding-top: 0; border-top: 0; }
  html.js .map-shell[data-tab="map"] .panel-inner { display: none; }
  html.js .map-shell[data-tab="info"] .map-wrap,
  html.js .map-shell[data-tab="runners"] .map-wrap { display: none; }

  html.js .tabbar {
    grid-row: 3; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2xs);
    padding: var(--space-xs) var(--space-xs) calc(var(--space-xs) + env(safe-area-inset-bottom));
    border-top: var(--rule-hair) solid var(--color-rule); background: var(--color-surface);
  }
}

.tabbar__item {
  position: relative; display: grid; justify-items: center; align-content: center; gap: var(--space-2xs);
  min-height: var(--tap); padding: var(--space-xs) var(--space-2xs);
  border: 0; border-radius: var(--r-sm); background: var(--color-clear); color: var(--color-muted);
  font: 500 var(--text-sm)/1.2 var(--font-body); cursor: pointer;
  transition: transform var(--dur-micro) var(--ease-out), opacity var(--dur-micro) var(--ease-out);
}
.tabbar__item::after {
  content: ""; position: absolute; left: var(--space-md); right: var(--space-md); bottom: var(--space-2xs);
  height: 2px; border-radius: 2px; background: var(--color-clear);
}
.tabbar__item[aria-selected="true"] { color: var(--color-ink); font-weight: 600; }
.tabbar__item[aria-selected="true"]::after { background: var(--color-graphite); }
.tabbar__item[aria-selected="true"] .tabbar__badge { display: none; }
.tabbar__item svg { width: 20px; height: 20px; }
.tabbar__icon { position: relative; display: block; }
.tabbar__badge {
  position: absolute; top: calc(-1 * var(--space-xs)); left: 100%; margin-left: calc(-1 * var(--space-xs));
  min-width: 16px; padding: 0 var(--space-2xs); border-radius: var(--r-full);
  background: var(--color-graphite); color: var(--color-graphite-ink);
  font-size: 11px; font-weight: 600; line-height: 16px; text-align: center;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- info pane -- */

.event-status { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: var(--space-xs); margin: 0; font-size: var(--text-sm); }
.view-label { margin-top: var(--space-2xs); color: var(--color-muted); font-size: var(--text-sm); }
.refresh-label { font-size: var(--text-xs); }

.event-schedule { display: grid; gap: var(--space-sm); margin: 0; padding-top: var(--space-md); border-top: var(--rule-hair) solid var(--color-rule); }
.event-schedule > div { display: grid; grid-template-columns: 56px minmax(0, 1fr); align-items: baseline; gap: var(--space-sm); }
.event-schedule dt { color: var(--color-muted); font-size: var(--text-sm); }
.event-schedule dd { margin: 0; }
.event-schedule time { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-3xs) var(--space-xs); font-size: var(--text-sm); }
.schedule-date { color: var(--color-ink); font-weight: 500; }
.schedule-time { color: var(--color-ink-2); }
.schedule-empty { color: var(--color-muted); font-size: var(--text-sm); }

.control-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); }
.control-actions .button { flex: 1 1 auto; }
.control-actions .inline-form { display: contents; }

.share-block { display: grid; gap: var(--space-xs); }
.share-block input { text-overflow: ellipsis; }

.panel-note { margin: 0; color: var(--color-ink-2); font-size: var(--text-sm); line-height: 1.55; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-sm); }

/* -------------------------------------------------------------- summary ----- */

/* Three plain figures with hairline dividers, not cards. */
.summary {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0;
  padding: var(--space-sm) 0;
  border-top: var(--rule-hair) solid var(--color-rule); border-bottom: var(--rule-hair) solid var(--color-rule);
}
.summary > div { display: grid; gap: var(--space-3xs); padding: 0 var(--space-sm); border-left: var(--rule-hair) solid var(--color-rule); }
.summary > div:first-child { border-left: 0; padding-left: 0; }
.summary__value { font-size: var(--text-xl); font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.summary__label { color: var(--color-muted); font-size: var(--text-xs); }
.summary > div[data-tone="live"] .summary__value { color: var(--color-success); }
.summary > div[data-tone="stale"] .summary__value { color: var(--color-stale); }

.connection { color: var(--color-ink-2); font-size: var(--text-sm); font-weight: 600; }
.connection[data-state="ok"] { color: var(--color-success); }
.connection[data-state="offline"] { color: var(--color-stale); }
.connection[data-state="ended"] { color: var(--color-error); }

.refresh-line { margin: var(--space-2xs) 0 0; color: var(--color-muted); font-size: var(--text-sm); }

/* ------------------------------------------------------------ runner list --- */

.runner-tools { display: grid; gap: var(--space-xs); }

.runner-list { list-style: none; margin: 0; padding: 0; border-top: var(--rule-hair) solid var(--color-rule); }
.runner-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-2xs);
  border-bottom: var(--rule-hair) solid var(--color-rule);
}
.runner-row__lap {
  min-width: 44px; min-height: 44px; padding: 0 var(--space-xs);
  border: var(--rule-hair) solid var(--color-rule-2); border-radius: var(--r-full);
  background: var(--color-surface); color: var(--color-ink-2);
  font: 600 var(--text-xs)/1 var(--font-body); cursor: pointer;
}
.runner-row__lap:hover { background: var(--color-paper-2); color: var(--color-ink); }
.runner-row__button {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-sm);
  width: 100%; min-height: 56px; padding: var(--space-sm) var(--space-xs);
  border: var(--rule-hair) solid var(--color-clear); border-radius: var(--r-sm);
  background: var(--color-clear); color: inherit; font: inherit; text-align: left; cursor: pointer;
  transition: transform var(--dur-micro) var(--ease-out), opacity var(--dur-micro) var(--ease-out);
}
.runner-row__button:hover { background: var(--color-paper-2); }
.runner-row.is-selected .runner-row__button { border-color: var(--color-accent-2); background: var(--color-accent-wash); }
.runner-row__number { min-width: 2ch; color: var(--color-muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.runner-row__identity { min-width: 0; }
.runner-row__name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.runner-row__meta { display: block; margin-top: var(--space-3xs); color: var(--color-muted); font-size: var(--text-sm); }
.runner-row__status {
  padding: var(--space-3xs) var(--space-xs); border-radius: var(--r-full);
  color: var(--color-ink-2); font-size: var(--text-sm); font-weight: 600; line-height: 1.3; white-space: nowrap;
}
.status-text--live { background: var(--color-live-wash); color: var(--color-success); }
.status-text--stale { background: var(--color-stale-wash); color: var(--color-stale); }
.status-text--expired { background: var(--color-error-wash); color: var(--color-error); }
.status-text--stopped { color: var(--color-muted); text-decoration: line-through; }
.status-text--registered { background: var(--color-accent-wash); color: var(--color-accent-2); }

.empty-list { margin: var(--space-md) 0 0; color: var(--color-ink-2); font-size: var(--text-sm); }

.rename-form { display: grid; gap: var(--space-xs); padding-top: var(--space-md); border-top: var(--rule-hair) solid var(--color-rule); }
.rename-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-xs); }

/* ---------------------------------------------------------------- markers --- */

.runner-marker { display: grid; place-items: center; background: var(--color-clear); border: 0; }
.runner-marker__number {
  display: grid; place-items: center; width: 32px; height: 32px;
  border: 2px solid var(--color-surface); border-radius: 50%;
  background: var(--color-graphite); color: var(--color-graphite-ink);
  box-shadow: var(--shadow-card);
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.runner-marker__pointer { position: absolute; inset: 0; pointer-events: none; }
.runner-marker__pointer::before {
  content: ""; position: absolute; top: -5px; left: 50%; margin-left: -7px;
  width: 0; height: 0;
  border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-bottom: 11px solid var(--color-graphite);
  filter: drop-shadow(0 1px 1px oklch(21% 0.028 262 / 0.35));
}
.runner-marker--live .runner-marker__number { background: var(--color-success); }
.runner-marker--live .runner-marker__pointer::before { border-bottom-color: var(--color-success); }
.runner-marker--stale .runner-marker__number { background: var(--color-stale); }
.runner-marker--stale .runner-marker__pointer::before { border-bottom-color: var(--color-stale); }
.runner-marker:hover .runner-marker__number { background: var(--color-accent-2); }
.runner-marker:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.route-arrow-icon { background: none; border: 0; }
.route-arrow { display: block; width: 22px; height: 22px; color: var(--color-route); }
.route-arrow svg { width: 100%; height: 100%; overflow: visible; }
.elevation-cursor {
  display: grid; place-items: center;
  border: 2px solid var(--color-surface); border-radius: 50%;
  background: var(--color-clear); box-shadow: 0 1px 5px oklch(21% 0.028 262 / 0.35);
}
.elevation-cursor span { display: block; width: 10px; height: 10px; border-radius: 50%; }
.route-endpoint {
  border: 2px solid var(--color-surface); border-radius: 50%;
  background: var(--color-graphite); box-shadow: var(--shadow-card);
}
.route-endpoint--start { background: var(--color-success); }
.route-endpoint--finish {
  background: repeating-conic-gradient(var(--color-graphite) 0 25%, var(--color-surface) 0 50%) 50% / 8px 8px;
}
.leaflet-tooltip.route-endpoint-tip {
  padding: 2px 8px; border: 0; border-radius: var(--r-full);
  background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-card);
  font: 600 0.6875rem/1.5 var(--font-body);
}
.leaflet-tooltip.route-endpoint-tip::before { display: none; }

.map-popup { display: grid; gap: var(--space-2xs); color: var(--color-ink); }
.map-popup strong { font-size: var(--text-md); font-weight: 600; }
.map-popup span { color: var(--color-ink-2); font-size: var(--text-sm); }

/* Leaflet theme overrides (vendor CSS untouched, tiles unfiltered). */
.leaflet-container { max-width: 100%; background: var(--color-map); color: var(--color-ink); font-family: var(--font-body); font-size: var(--text-sm); }
.leaflet-bar { border: var(--rule-hair) solid var(--color-rule-2); border-radius: var(--r-sm); box-shadow: var(--shadow-card); overflow: hidden; }
.leaflet-bar a, .leaflet-touch .leaflet-bar a {
  width: var(--tap); height: var(--tap); line-height: var(--tap);
  border-bottom: var(--rule-hair) solid var(--color-rule);
  background: var(--color-surface); color: var(--color-ink);
}
.leaflet-bar a:last-child { border-bottom: 0; }
.leaflet-bar a:hover { background: var(--color-paper-2); }
.leaflet-control-attribution {
  padding: var(--space-3xs) var(--space-xs);
  background: color-mix(in oklab, var(--color-surface) 85%, var(--color-clear));
  color: var(--color-muted); font-size: var(--text-xs);
}
.leaflet-control-attribution a { color: inherit; }
.leaflet-popup-content-wrapper {
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--r);
  background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-card);
}
.leaflet-popup-tip { background: var(--color-surface); box-shadow: none; }
.leaflet-popup-content { margin: var(--space-sm) var(--space-md); font-family: var(--font-body); font-size: var(--text-sm); line-height: 1.45; }
.leaflet-container a.leaflet-popup-close-button {
  width: 44px; height: 44px; line-height: 44px; color: var(--color-ink-2);
}
.leaflet-popup-content { padding-right: var(--space-lg); }

button:disabled, input:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
button[aria-busy="true"] { cursor: progress; }
input[aria-invalid="true"] { border-color: var(--color-error); }
input::placeholder { color: var(--color-muted); opacity: 1; }
.link-button, .text-link { min-height: var(--tap); display: inline-flex; align-items: center; }
.link-button:active, .text-link:active, .site-nav a:active { opacity: 0.7; }
.tabbar__item:active, .runner-row__button:active { transform: translateY(1px); }
.help { min-height: 1lh; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ============================================================ wider screens */

@media (min-width: 640px) {
  .page-heading { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .page-heading .button { width: auto; }
  .site-nav { gap: var(--space-md); font-size: var(--text-sm); }

  .schedule-grid { grid-template-columns: 1fr 1fr; }
  .form-actions .button { flex: 0 1 auto; }
  .empty .button { width: auto; }
  .config-note { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .event-carousel { grid-auto-columns: calc((100% - var(--space-sm)) / 2); }
  .event-card__cover { height: 400px; }
  .heading-action {
    min-height: 48px; padding: 0 var(--space-md);
    border-radius: var(--r); background: var(--color-graphite); color: var(--color-graphite-ink);
  }
  .heading-action:hover { background: var(--color-graphite-2); color: var(--color-graphite-ink); }
}

@media (min-width: 900px) {
  :root { --header-h: 72px; }

  .event-card__cover { height: 360px; }
  .event-card__caption h2 { font-size: var(--text-section); }
  .event-tools { grid-template-columns: minmax(0, 360px) minmax(0, 1fr); align-items: center; }
  .event-filters { justify-content: flex-end; }

  /* Desk targets 44px; phones keep 48px. */
  .button, .map-chip, .card-link { min-height: 44px; }
  .brand, .site-nav a, .site-nav .link-button { min-height: 44px; }
  .field input, .field select, .share-block input, .runner-tools input, .rename-row input { min-height: 44px; }
  .leaflet-bar a, .leaflet-touch .leaflet-bar a { width: 44px; height: 44px; line-height: 44px; }

  /* Control room: fixed left panel, live map right, capped at 1600px. */
  .map-page #main {
    height: calc(100vh - var(--header-h)); height: calc(100dvh - var(--header-h));
    min-height: 0; overflow: hidden;
  }
  .map-shell { grid-template-columns: 360px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: 100%; }
  .map-heading { grid-column: 1 / -1; grid-row: 1; }
  .map-panel {
    grid-column: 1; grid-row: 2; display: block; min-height: 0; overflow: hidden;
    border-right: var(--rule-hair) solid var(--color-rule); background: var(--color-surface);
  }
  .panel-inner { height: 100%; min-height: 0; overflow-y: auto; padding: var(--space-lg) var(--space-lg) var(--space-2xl); }
  .panel-section[data-section="runners"] { order: -1; padding-top: 0; border-top: 0; }
  .panel-section[data-section="info"] { padding-top: var(--space-lg); border-top: var(--rule-hair) solid var(--color-rule); }
  .map-wrap { grid-column: 2; grid-row: 2; }
  .map-overlay { top: var(--space-md); right: var(--space-md); }
}

/* ============================================================= phone shell */

.app-tabbar { display: none; }

@media (max-width: 899.98px) {
  .site-header { gap: var(--space-sm); }
  .site-nav { display: none; }
  .brand-copy { display: grid; gap: 1px; line-height: 1.15; }
  .brand-eyebrow { display: block; color: var(--color-muted); font-size: 0.6875rem; font-weight: 500; letter-spacing: 0; }
  .brand-mark { width: 16px; height: 16px; }
  .account-menu { display: block; }
  .account-menu > summary { min-width: var(--tap); min-height: var(--tap); }

  .app-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky-nav);
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px;
    padding: var(--space-xs) var(--space-xs) calc(var(--space-xs) + env(safe-area-inset-bottom));
    border-top: var(--rule-hair) solid var(--color-rule);
    background: var(--color-surface); box-shadow: 0 -8px 24px oklch(21% 0.028 262 / 0.05);
  }
  .app-tab {
    position: relative; display: grid; justify-items: center; align-content: center; gap: 2px;
    width: 100%; min-height: 52px; padding: var(--space-2xs);
    border: 0; border-radius: var(--r-sm); background: var(--color-clear);
    color: var(--color-muted); font: 600 0.6875rem/1.2 var(--font-body);
    text-decoration: none; cursor: pointer;
  }
  .app-tab svg { width: 22px; height: 22px; }
  .app-tab.is-active { color: var(--color-ink); }
  .app-tab.is-active::after {
    content: ""; position: absolute; bottom: 2px; width: 16px; height: 3px;
    border-radius: var(--r-full); background: var(--color-graphite);
  }
  .app-tabbar__form { display: contents; }
  body:has(.app-tabbar) #main { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  .page { padding-top: var(--space-lg); padding-bottom: var(--space-xl); }
  .page--list { padding-top: var(--space-md); }
  h1 { font-size: 1.75rem; }
  .page-heading { margin-bottom: var(--space-md); }
  .page--list .page-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: var(--space-sm); }
  .page--list .heading-action { min-height: 44px; margin-bottom: 2px; }
  .page--dashboard .page-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: var(--space-sm); }
  .page--dashboard .heading-action { min-height: 44px; margin-bottom: 2px; }

  .event-filters { margin: 0 calc(-1 * var(--space-xs)); padding: 0 var(--space-xs); }
  .event-card__cover { border-radius: 18px; }

  .form-card { gap: 20px; }
  .field label, .share-block label, .runner-tools label, .rename-form label { font-size: 0.8125rem; font-weight: 600; }
  .field input, .field select, .share-block input, .runner-tools input, .rename-row input {
    min-height: 52px; padding: var(--space-sm) 14px;
    border-color: var(--color-rule-2); border-radius: 12px; background: var(--color-surface);
  }
  .field input[type="file"] { padding: var(--space-sm) 14px; }
  .form-actions { flex-direction: column; }
  .form-actions .button { width: 100%; flex: none; }
  .auth { min-height: calc(100dvh - var(--header-h) - 2 * var(--space-lg)); }
  .auth h1 { font-size: 1.75rem; }
  .auth .button { width: 100%; }

  .map-heading { padding-top: var(--space-sm); padding-bottom: var(--space-sm); }
  .event-title { font-size: 1.375rem; }
  .tabbar__item { font-size: 0.6875rem; font-weight: 600; color: var(--color-muted); }
  .tabbar__item[aria-selected="true"] { color: var(--color-ink); }
  .tabbar__item[aria-selected="true"]::after { height: 3px; }
}

/* ---------------------------------------------------------- track review --- */

.track-page { max-width: 960px; }
.track-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-sm); padding: var(--space-sm) 0 var(--space-md);
  border-bottom: var(--rule-hair) solid var(--color-rule);
}
.track-summary > div { display: grid; gap: var(--space-3xs); }
.track-map-wrap {
  position: relative; height: 60vh; height: min(60dvh, 520px); min-height: 320px;
  margin-top: var(--space-md); overflow: hidden;
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--r-lg);
  background: var(--color-map);
}
#track-map { position: absolute; inset: 0; }
.track-controls { display: grid; gap: var(--space-xs); margin-top: var(--space-md); }
.track-controls input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--color-accent-2); }
.track-controls .button { justify-self: start; }
.track-controls__meta {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-xs);
  color: var(--color-muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums;
}
