:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #fbfcfe;
  --surface-muted: #f3f6fa;

  --border: #e4e8ee;
  --border-strong: #d7dde7;
  --border-soft: #edf1f5;

  --text: #16202f;
  --muted: #667085;
  --muted-soft: #8b96a7;

  --chip-bg: #ffffff;
  --chip-border: #d3dae5;
  --chip-active-bg: #eef4ff;
  --chip-active-border: #bfd0ef;
  --chip-active-text: #274c87;

  --reminder-on-bg: #f8efc9;
  --reminder-on-border: #e3d08d;
  --reminder-on-text: #6a5600;

  --reminder-off-bg: #f9fafb;
  --reminder-off-border: #d8dee7;
  --reminder-off-text: #6b7280;

  --status-upcoming-bg: #eef4ff;
  --status-upcoming-border: #cfddf5;
  --status-upcoming-text: #486998;

  --status-live-bg: #fdf1f1;
  --status-live-border: #f2d0d0;
  --status-live-text: #9a3c3c;

  --status-finished-bg: #f4f5f7;
  --status-finished-border: #e2e6eb;
  --status-finished-text: #6d7480;

  --success-bg: #edf8f0;
  --success-border: #d3e9d8;
  --success-text: #2f6f42;

  --error-bg: #fdf2f2;
  --error-border: #f2d2d2;
  --error-text: #9d3a3a;

  --shadow-soft: 0 1px 2px rgba(16, 24, 40, 0.03), 0 8px 24px rgba(16, 24, 40, 0.04);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 30px rgba(16, 24, 40, 0.05);

  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  --content-width: 1180px;
  --content-narrow: 980px;
  --content-tight: 900px;

  --font: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top, #ffffff 0%, #f8fafc 42%, #f8fafc 100%);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img {
  max-width: 100%;
  display: block;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ---------- GLOBAL SHELL ---------- */

.page-shell,
.app-shell,
main {
  width: min(100% - 36px, var(--content-width));
  margin: 0 auto;
}

.page-shell,
.app-shell {
  padding: 28px 0 44px;
}

footer,
.footer {
  width: min(100% - 36px, var(--content-width));
  margin: 18px auto 26px;
  color: var(--muted-soft);
  font-size: 11px;
}

/* ---------- TYPOGRAPHY ---------- */

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 48px;
  line-height: 0.98;
  font-weight: 650;
  letter-spacing: -0.045em;
}

h2,
#today-title,
#weekend-title {
  font-size: 19px;
  line-height: 1.15;
  font-weight: 620;
  letter-spacing: -0.02em;
}

h3 {
  font-size: 14px;
  line-height: 1.25;
  font-weight: 600;
}

.hero-subtitle,
.subtext,
.muted,
#local-note,
.race-line-2,
.nearby-track-location,
.nearby-track-event-date,
.empty-state {
  color: var(--muted);
}

/* ---------- HERO / TOP ---------- */

header,
.hero,
.topbar,
.header-card {
  width: 100%;
}

.hero,
.header-card {
  max-width: var(--content-tight);
  margin: 0 auto 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hero h1,
.header-card h1 {
  width: 100%;
  text-align: center;
}

.hero-subtitle,
.subtext {
  margin-top: 8px;
  max-width: 620px;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
}

/* ---------- FILTERS ---------- */

#filter-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 18px auto 22px;
  max-width: var(--content-tight);
}

.filter-chip {
  appearance: none;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 8px 15px;
  min-height: 36px;
  font-size: 13px;
  font-weight: 500;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.filter-chip:hover {
  border-color: #bcc8d9;
  background: #fafcff;
}

.filter-chip.is-active {
  background: var(--chip-active-bg);
  border-color: var(--chip-active-border);
  color: var(--chip-active-text);
}

.filter-chip:focus-visible,
.reminder-btn:focus-visible,
#local-zip:focus-visible,
#local-radius:focus-visible,
#local-setup-form button:focus-visible,
#clear-local-btn:focus-visible,
.nearby-track-distance.is-link:focus-visible {
  outline: 2px solid #8ab4f8;
  outline-offset: 2px;
}

/* ---------- LAYOUT BLOCKS ---------- */

.section-block {
  margin-top: 20px;
}

.section-card,
.panel,
#local-setup-card,
#nearby-tracks-card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 18px 20px;
  box-shadow: var(--shadow-soft);
}

#today-title,
#weekend-title,
#local-note,
#local-setup-card,
#nearby-tracks-card,
#today-list,
#weekend-list {
  max-width: var(--content-narrow);
  margin-left: auto;
  margin-right: auto;
}

#today-title,
#weekend-title {
  margin-bottom: 12px;
}

#local-note {
  margin-top: 2px;
  margin-bottom: 0;
  text-align: center;
  font-size: 13px;
}

.section-header-row,
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.small-label,
.meta-label {
  color: var(--muted-soft);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- RACE LIST ---------- */

#today-list,
#weekend-list {
  display: grid;
  gap: 12px;
  width: 100%;
}

.race-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
  box-shadow: var(--shadow-card);
}

.race-line-1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.race-line-2 {
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.series-wrap {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1 1 auto;
}

.series-logo {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: 0 0 auto;
}

.series-logo.is-broken {
  display: none;
}

.series-text {
  font-size: 14px;
  line-height: 1.35;
  font-weight: 560;
  color: var(--text);
  word-break: break-word;
}

.actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 29px;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 550;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-upcoming {
  background: var(--status-upcoming-bg);
  border-color: var(--status-upcoming-border);
  color: var(--status-upcoming-text);
}

.status-live {
  background: var(--status-live-bg);
  border-color: var(--status-live-border);
  color: var(--status-live-text);
}

.status-finished {
  background: var(--status-finished-bg);
  border-color: var(--status-finished-border);
  color: var(--status-finished-text);
}

.reminder-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 29px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--reminder-off-border);
  background: var(--reminder-off-bg);
  color: var(--reminder-off-text);
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.reminder-btn:hover {
  transform: translateY(-1px);
}

.reminder-btn.is-on {
  background: var(--reminder-on-bg);
  border-color: var(--reminder-on-border);
  color: var(--reminder-on-text);
}

.reminder-btn.is-off {
  background: var(--reminder-off-bg);
  border-color: var(--reminder-off-border);
  color: var(--reminder-off-text);
}

.reminder-btn.is-disabled,
.reminder-btn:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  transform: none;
}

.bell-icon {
  width: 13px;
  height: 13px;
  fill: currentColor;
  flex: 0 0 auto;
}

.reminder-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  min-height: 17px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 650;
  background: rgba(255, 255, 255, 0.6);
  color: currentColor;
}

.reminder-btn.is-off .reminder-badge,
.reminder-badge.is-off,
.reminder-badge.is-disabled {
  background: rgba(255, 255, 255, 0.72);
}

.empty-state {
  padding: 13px 14px;
  border: 1px dashed #d7dde7;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fcfdff 0%, #f8fafc 100%);
  font-size: 13px;
}

/* ---------- LOCAL SETUP ---------- */

#local-setup-card,
#nearby-tracks-card {
  margin-top: 14px;
}

#local-setup-form {
  display: grid;
  grid-template-columns: minmax(130px, 150px) minmax(118px, 140px) auto auto;
  gap: 8px;
  align-items: end;
}

#local-setup-form label,
.local-form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 550;
  color: var(--muted);
}

#local-zip,
#local-radius {
  appearance: none;
  width: 100%;
  min-height: 37px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  padding: 7px 10px;
}

#local-zip::placeholder {
  color: var(--muted-soft);
}

#local-setup-form button,
#clear-local-btn {
  appearance: none;
  min-height: 37px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  padding: 7px 12px;
  font-weight: 550;
  background: #fff;
  color: var(--text);
}

#local-setup-form button[type="submit"] {
  background: var(--chip-active-bg);
  border-color: var(--chip-active-border);
  color: #325a95;
}

#clear-local-btn {
  color: var(--muted);
}

#local-status {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 12px;
}

#local-status.is-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

#local-status.is-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

/* ---------- NEARBY TRACKS ---------- */

#nearby-tracks-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.nearby-track-card {
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-soft);
  background: linear-gradient(180deg, #ffffff 0%, #fafcff 100%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 150px;
}

.nearby-track-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.nearby-track-title {
  font-weight: 560;
  color: var(--text);
  line-height: 1.3;
  font-size: 13px;
}

.nearby-track-distance {
  white-space: nowrap;
  font-size: 11px;
  color: #46638f;
  background: #f3f6fb;
  border: 1px solid #d4deef;
  border-radius: var(--radius-pill);
  padding: 3px 7px;
}

.nearby-track-distance.is-link {
  cursor: pointer;
  color: #1a73e8;
  background: #eef4ff;
  border-color: #bcd0f7;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.nearby-track-distance.is-link:hover {
  background: #e4efff;
  border-color: #9fbdf2;
  color: #1558c0;
}

.nearby-track-location,
.nearby-track-event-date {
  font-size: 12px;
  line-height: 1.35;
}

.nearby-track-next-label {
  font-size: 10px;
  font-weight: 650;
  color: var(--muted-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nearby-track-next {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nearby-track-event-name {
  color: var(--text);
  font-weight: 550;
  font-size: 12px;
  line-height: 1.35;
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 960px) {
  .page-shell,
  .app-shell,
  main,
  footer,
  .footer {
    width: min(100% - 28px, var(--content-width));
  }

  h1 {
    font-size: 40px;
  }

  #local-setup-form {
    grid-template-columns: 1fr 1fr;
  }

  #local-setup-form button,
  #clear-local-btn {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .page-shell,
  .app-shell,
  main,
  footer,
  .footer {
    width: min(100% - 18px, var(--content-width));
  }

  .page-shell,
  .app-shell {
    padding: 16px 0 28px;
  }

  .hero,
  .header-card {
    margin-bottom: 14px;
  }

  h1 {
    font-size: 32px;
  }

  h2,
  #today-title,
  #weekend-title {
    font-size: 16px;
  }

  .section-card,
  .panel,
  #local-setup-card,
  #nearby-tracks-card {
    padding: 14px;
  }

  .race-row {
    padding: 12px 13px;
  }

  .race-line-1 {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .actions {
    justify-content: space-between;
  }

  .series-wrap {
    align-items: flex-start;
  }

  #local-setup-form {
    grid-template-columns: 1fr;
  }

  #nearby-tracks-list {
    grid-template-columns: 1fr;
  }
}
