/* Site header, ticker and theme toggle. */

.site-header {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
}

.site-header::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-strong), color-mix(in srgb, var(--accent-strong) 35%, transparent) 62%, transparent);
}

.header-main {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.86rem 1rem 0.74rem;
}

.header-title-block {
  min-width: 0;
  flex: 1;
}

.header-title {
  margin: 0;
  color: var(--text);
  font-family: var(--display);
  font-size: clamp(1.15rem, 2.7vw, 1.62rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.08;
}

.header-subtitle {
  margin: 0.24rem 0 0;
  color: color-mix(in srgb, var(--muted) 78%, var(--text) 22%);
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.045em;
}

.subtitle-updated-link {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
  color: inherit;
  text-decoration: none;
  opacity: 1;
  cursor: default;
}

.subtitle-updated-extra {
  display: inline-block;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateX(-3px);
  transition: max-width 0.18s ease, opacity 0.16s ease, transform 0.16s ease;
}

.subtitle-updated-link:visited {
  color: inherit;
  text-decoration: none;
}

.subtitle-updated-link:hover .subtitle-updated-extra,
.subtitle-updated-link:focus-visible .subtitle-updated-extra {
  max-width: 18rem;
  opacity: 1;
  transform: translateX(0);
}

.header-meta {
  display: grid;
  grid-template-columns: auto;
  grid-template-rows: auto auto;
  grid-template-areas:
    'toggle'
    'badge';
  align-items: center;
  row-gap: 0.34rem;
  min-width: 0;
  flex-shrink: 0;
  padding-top: 0.92rem;
  margin-right: -0.72rem;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  padding: 0.34rem 0.62rem;
  border-radius: var(--pill);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  background: color-mix(in srgb, var(--accent-dim) 85%, transparent);
  color: var(--accent-strong);
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1;
  grid-area: badge;
  justify-self: end;
}

.live-badge strong {
  color: var(--accent-strong);
  font-weight: 600;
  display: inline-block;
  transform-origin: center;
  font-variant-numeric: tabular-nums;
}

.live-badge strong.header-race-count--updated {
  animation: raceCountPulse 300ms cubic-bezier(0.2, 0.65, 0.25, 1);
}

.header-meta .theme-toggle-btn {
  grid-area: toggle;
  justify-self: end;
  position: absolute;
  top: 0.14rem;
  right: 0.14rem;
  z-index: 3;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-strong);
  flex-shrink: 0;
  animation: headerBlink 2.8s ease-in-out infinite;
}

.ticker-row {
  height: 34px;
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.ticker-label,
.ticker-tag {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0 0.84rem;
  border-right: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.55rem;
  font-weight: 500;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.ticker-label-dot,
.ticker-tag-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-strong);
  animation: headerBlink 2.8s ease-in-out infinite;
}

.ticker-track-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
}

.ticker-track-wrap::before,
.ticker-track-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 34px;
  z-index: 2;
  pointer-events: none;
}

.ticker-track-wrap::before {
  left: 0;
  background: linear-gradient(90deg, var(--surface), transparent);
}

.ticker-track-wrap::after {
  right: 0;
  background: linear-gradient(270deg, var(--surface), transparent);
}

.ticker-track {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  animation: tickerScroll 42s linear infinite;
}

@media (hover: hover) and (pointer: fine) {
  .ticker-track:hover {
    animation-play-state: paused;
  }
}

.ticker-track--static {
  animation: none;
}

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.82rem;
  border-right: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.61rem;
  color: var(--text-soft);
  min-height: 100%;
}

.ticker-item-link {
  text-decoration: none;
  color: inherit;
  transition: background-color 0.15s ease;
}

.ticker-item-link:hover {
  background: color-mix(in srgb, var(--accent-dim) 65%, transparent);
}

.ticker-item-name {
  color: var(--text);
  font-size: 0.63rem;
  font-weight: 500;
}

.ticker-item-date {
  color: var(--accent-strong);
  font-size: 0.57rem;
}

.ticker-sep {
  color: color-mix(in srgb, var(--muted) 80%, transparent);
}

.ticker-city {
  color: var(--muted);
  font-size: 0.58rem;
}

.ticker-distances {
  display: inline-flex;
  align-items: center;
  gap: 0.26rem;
}

.ticker-distance {
  display: inline-flex;
  align-items: center;
  line-height: 1;
  padding: 0.12rem 0.34rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.53rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.ticker-distance.distance-tag--curta {
  color: #d2a24c;
  border-color: rgba(210, 162, 76, 0.38);
  background: rgba(210, 162, 76, 0.14);
}

.ticker-distance.distance-tag--five {
  color: #6f95d7;
  border-color: rgba(111, 149, 215, 0.38);
  background: rgba(111, 149, 215, 0.14);
}

.ticker-distance.distance-tag--ten {
  color: #5fa779;
  border-color: rgba(95, 167, 121, 0.38);
  background: rgba(95, 167, 121, 0.14);
}

.ticker-distance.distance-tag--half {
  color: #dc8b59;
  border-color: rgba(220, 139, 89, 0.38);
  background: rgba(220, 139, 89, 0.14);
}

.ticker-distance.distance-tag--marathon {
  color: #cf7088;
  border-color: rgba(207, 112, 136, 0.38);
  background: rgba(207, 112, 136, 0.14);
}

.ticker-distance.distance-tag--ultra {
  color: #8f78d1;
  border-color: rgba(143, 120, 209, 0.38);
  background: rgba(143, 120, 209, 0.14);
}

.ticker-distance.distance-tag--other {
  color: #8494a8;
  border-color: rgba(132, 148, 168, 0.36);
  background: rgba(132, 148, 168, 0.14);
}

.ticker-distance-more {
  color: var(--muted);
  font-size: 0.54rem;
}

.theme-toggle-btn {
  width: 2.9rem;
  height: 1.62rem;
  border: 1px solid color-mix(in srgb, var(--border-strong) 85%, transparent);
  border-radius: 999px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 94%, #fff), color-mix(in srgb, var(--surface) 96%, #fff));
  position: relative;
  cursor: pointer;
  padding: 0.12rem;
  transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
  box-shadow: 0 3px 9px rgba(15, 23, 42, 0.12) inset, 0 3px 10px rgba(15, 23, 42, 0.08);
}

.theme-toggle-track {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: color-mix(in srgb, var(--surface) 86%, #0f172a 14%);
}

.theme-toggle-thumb {
  position: absolute;
  top: 0.08rem;
  left: 0.08rem;
  width: calc((100% - 0.16rem) / 2);
  height: calc(100% - 0.16rem);
  border-radius: var(--pill);
  background: linear-gradient(180deg, #f8fbff, #e8eef7);
  border: 1px solid color-mix(in srgb, var(--border-strong) 70%, #e2e8f0);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.18);
  transition: transform 0.18s ease, background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  z-index: 1;
}

.theme-toggle-icon {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #8893a7;
  transition: color 0.16s ease;
}

.theme-toggle-icon svg {
  width: 0.78rem;
  height: 0.78rem;
}

.theme-toggle-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 0.2rem var(--accent-ring);
}

.theme-toggle-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--border));
}

.theme-toggle-btn[aria-pressed='true'] {
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 92%, #0f172a), color-mix(in srgb, var(--surface) 94%, #0f172a));
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.theme-toggle-btn[aria-pressed='true'] .theme-toggle-thumb {
  transform: translateX(100%);
  background: linear-gradient(180deg, #ffd7b4, #ffb77f);
  border-color: color-mix(in srgb, var(--accent) 55%, #f59e66);
  box-shadow: 0 2px 8px rgba(249, 115, 22, 0.35);
}

.theme-toggle-btn[aria-pressed='true'] .theme-toggle-icon--moon {
  color: #fef3c7;
}

.theme-toggle-btn[aria-pressed='true'] .theme-toggle-icon--sun {
  color: #6f7d96;
}

.theme-toggle-btn[aria-pressed='false'] .theme-toggle-icon--sun {
  color: #f59e0b;
}

.theme-toggle-btn[aria-pressed='false'] .theme-toggle-icon--moon {
  color: #7f8a9e;
}

@keyframes tickerScroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

@keyframes headerBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

@keyframes raceCountPulse {
  0% {
    transform: translateY(0) scale(1);
    text-shadow: none;
  }
  45% {
    transform: translateY(-1px) scale(1.12);
    text-shadow: 0 0 10px color-mix(in srgb, var(--accent-strong) 42%, transparent);
  }
  100% {
    transform: translateY(0) scale(1);
    text-shadow: none;
  }
}
