/*
 * Shared readability and colour-mode layer.
 * Loaded after page-specific styles so legacy pages can adopt the same
 * accessible tokens without rewriting each product surface at once.
 */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-elevated: #182430;
  --bg-card: #192734;
  --panel: #121922;
  --panel-2: #192734;
  --panel-3: #16212b;
  --border: #344654;
  --border-light: #415463;
  --text: #f2f4f5;
  --text-secondary: #b6c1cb;
  --text-muted: #93a4b4;
  --muted: #aebbc7;
  --muted-2: #91a3b3;
  --accent: #3ba8f2;
  --accent-hover: #2498e6;
  --accent-2: #a9dafd;
  --green: #29d36c;
  --done: #70d79b;
  --upcoming: #b0beca;
  --gold: #ffdf45;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fa;
  --bg-elevated: #eef2f6;
  --bg-card: #ffffff;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --panel-3: #f1f4f8;
  --border: #cad5df;
  --border-light: #bac8d4;
  --text: #172431;
  --text-secondary: #46586a;
  --text-muted: #5d7082;
  --muted: #526577;
  --muted-2: #607386;
  --accent: #0879ca;
  --accent-hover: #0767ad;
  --accent-2: #075e9d;
  --green: #08783a;
  --done: #126f3d;
  --upcoming: #56697a;
  --gold: #946b00;
  --vinnare: #805c00;
  --live: #a33d17;
  --red: #c52a37;
}

body {
  font-size: 16px;
}

:root[data-theme="light"] body {
  background: var(--bg) !important;
}

nav {
  border-color: var(--border) !important;
}

:root[data-theme="dark"] nav {
  background: rgba(15, 20, 25, 0.94) !important;
}

:root[data-theme="light"] nav {
  background: rgba(255, 255, 255, 0.94) !important;
  box-shadow: 0 1px 10px rgba(31, 47, 63, 0.06);
}

.nav-links a {
  font-size: max(0.86rem, 14px) !important;
}

.nav-flag {
  box-shadow: 0 0 0 1px var(--border-light) !important;
}

.theme-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  min-height: 38px;
  padding: 0.4rem 0.62rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.theme-toggle__mark {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 50%;
  position: relative;
  flex: 0 0 auto;
}

.theme-toggle__mark::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.28;
}

:root[data-theme="light"] .theme-toggle__mark::after {
  opacity: 1;
}

:root[data-theme="dark"] .theme-toggle__mark {
  border-color: var(--accent-2);
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Metadata remains secondary, but it must stay readable in data-heavy views. */
.meta, .tip-meta, .race-meta, .meeting-meta, .section-sub, .footer-note,
.article-date, .article-excerpt, .stat-label, .filter-label, td.muted,
.hero-meta, .updated-at {
  color: var(--text-muted) !important;
}

.badge, .chip, .filter-chip, .pill, .formlines-pill {
  font-size: max(0.78rem, 13px);
}

.metric-label, .filter-label, .race-subtitle, .game-id, .time-pill,
.tip-meta, .metric-chip, .summary-label, .summary-sub, .updated-at,
.section-eyebrow, .formlines-filter-label, .swish-tier-period,
.swish-recap-label, .article-meta, .meta-bar, th {
  font-size: max(0.78rem, 13px) !important;
}

.race-title, .tip-title, .pick-horse, .article-excerpt,
.filter-copy, .hero-note, .meeting-result {
  font-size: max(0.9rem, 15px);
}

.results-table, .recent-table, table.racecard {
  font-size: max(0.88rem, 14px) !important;
}

.col-key-item, .weight-val, .weight-reset, .fl-rank,
.cm-total-label, .history-empty, .coupon-leg-pill {
  font-size: max(0.75rem, 12px) !important;
}

table, .race-card, .meeting-card, .tip-card {
  font-variant-numeric: tabular-nums;
}

:root[data-theme="light"] :where(.hero-panel, .stats-grid > *, .stat-card,
  .meeting-card, .race-card, .race-row, .filter-card, .filter-panel,
  .beta-card, .feedback-card, .tip-card, .article-card, .pricing-card,
  .auth-card, .signup-card, .summary-card, .table-wrap, .table-container,
  .top20-card, .info-box, .modal-content, #coupon-bar, #coupon-modal) {
  background-color: var(--bg-card) !important;
  border-color: var(--border) !important;
}

:root[data-theme="light"] :where(.hero-card, .meeting-row, .starter-row,
  .race-table, .game-tabs, .toolbar, .control-panel, .col-key,
  .content-card, .modal, .member-panel) {
  background-color: var(--bg-card) !important;
  border-color: var(--border) !important;
}

:root[data-theme="light"] :where(.hero-card, .summary-card, .toolbar > .section,
  .section-card, .featured, .card, .product-card, .about-cell, .about-full,
  .roadmap-card, .results-cta-card, .results-model-switcher,
  .results-model-panel, .wrap-card, .coupon-card, .filter-card,
  .type-filter-card, .cta-card, .rolling-card, .empty-card, .lab-promo,
  .formlines-filter-card, .account-bar, .beta-panel, .weight-bar,
  .leg-header, .cm-game-row, .cm-calc, .cm-total) {
  background: var(--bg-card) !important;
  border-color: var(--border) !important;
}

:root[data-theme="light"] :where(#coupon-bar, .image-modal-panel) {
  background: rgba(255, 255, 255, 0.97) !important;
}

:root[data-theme="light"] .nav-mobile-menu {
  background: var(--bg-card) !important;
  border-color: var(--border) !important;
  box-shadow: 0 8px 24px rgba(31, 47, 63, 0.12) !important;
}

:root[data-theme="light"] :where(.filter-label) {
  background: transparent !important;
}

:root[data-theme="light"] :where(th, .table-header, .section-sticky) {
  background-color: var(--bg-elevated) !important;
}

:root[data-theme="light"] tbody tr:hover {
  background: rgba(8, 121, 202, 0.06) !important;
}

:root[data-theme="light"] :where(.nav-cta, .btn-primary, .auth-button) {
  color: #fff !important;
}

:root[data-theme="light"] .footer-responsible a {
  text-decoration-color: rgba(23, 36, 49, 0.35) !important;
}

@media (max-width: 920px) {
  .nav-links {
    gap: 0.65rem !important;
  }

  .theme-toggle {
    padding: 0.38rem 0.5rem;
  }

  .theme-toggle__label {
    display: none;
  }
}

@media (max-width: 1200px) {
  .theme-toggle__label {
    display: none;
  }
}

@media (max-width: 1040px) {
  .nav-badge {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
