/* Stockport Run Calendar — one stylesheet, no build step, no dependencies. */

:root {
  --accent: #0f9b76;
  --accent-strong: #0b7a5c;
  --accent-soft: rgba(15, 155, 118, 0.12);
  --accent-contrast: #ffffff;

  --bg: #f5f7f6;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, rgba(15, 155, 118, 0.13), transparent 60%),
             radial-gradient(900px 500px at 95% 0%, rgba(245, 158, 11, 0.10), transparent 55%);
  --surface: #ffffff;
  --surface-2: #f0f3f1;
  --text: #10201a;
  --muted: #5d6e67;
  --line: #dce4e0;
  --line-strong: #c3cfc9;
  --shadow: 0 1px 2px rgba(16, 32, 26, 0.05), 0 8px 24px -12px rgba(16, 32, 26, 0.18);
  --shadow-lg: 0 2px 4px rgba(16, 32, 26, 0.06), 0 20px 40px -20px rgba(16, 32, 26, 0.30);

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 22px;
  --wrap: 1220px;

  --t-parkrun: #0f9b76;
  --t-race: #2563eb;
  --t-social: #d97706;
  --t-training: #7c3aed;
  --t-series: #db2777;
  --t-challenge: #475569;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] { color-scheme: dark; }
}
:root[data-theme="auto"], :root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

:root[data-theme="dark"],
:root[data-theme="auto"] {
  --dark-bg: #0b100e;
  --dark-surface: #141b18;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --accent: #35d6a4;
    --accent-strong: #5fe6bb;
    --accent-soft: rgba(53, 214, 164, 0.14);
    --accent-contrast: #052018;
    --bg: #0b100e;
    --bg-grad: radial-gradient(1100px 560px at 12% -12%, rgba(53, 214, 164, 0.14), transparent 62%),
               radial-gradient(900px 520px at 96% -4%, rgba(251, 191, 36, 0.08), transparent 58%);
    --surface: #141b18;
    --surface-2: #1b2420;
    --text: #e6efea;
    --muted: #93a49c;
    --line: #263230;
    --line-strong: #35433f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 10px 30px -16px rgba(0, 0, 0, 0.8);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.55), 0 26px 50px -24px rgba(0, 0, 0, 0.9);
    --t-parkrun: #35d6a4;
    --t-race: #6ea8ff;
    --t-social: #f5b544;
    --t-training: #b18cff;
    --t-series: #ff79b8;
    --t-challenge: #9fb0c0;
  }
}

:root[data-theme="dark"] {
  --accent: #35d6a4;
  --accent-strong: #5fe6bb;
  --accent-soft: rgba(53, 214, 164, 0.14);
  --accent-contrast: #052018;
  --bg: #0b100e;
  --bg-grad: radial-gradient(1100px 560px at 12% -12%, rgba(53, 214, 164, 0.14), transparent 62%),
             radial-gradient(900px 520px at 96% -4%, rgba(251, 191, 36, 0.08), transparent 58%);
  --surface: #141b18;
  --surface-2: #1b2420;
  --text: #e6efea;
  --muted: #93a49c;
  --line: #263230;
  --line-strong: #35433f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 10px 30px -16px rgba(0, 0, 0, 0.8);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.55), 0 26px 50px -24px rgba(0, 0, 0, 0.9);
  --t-parkrun: #35d6a4;
  --t-race: #6ea8ff;
  --t-social: #f5b544;
  --t-training: #b18cff;
  --t-series: #ff79b8;
  --t-challenge: #9fb0c0;
}

* { box-sizing: border-box; }

/* JS toggles .hidden on the backdrop, the active-filter bar and the filter
   count. A class rule like `.sheet-backdrop { display: block }` beats the
   browser's own [hidden] rule, which is how the backdrop once covered the
   whole page permanently. This settles it for every such element. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "cv05", "ss01";
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.018em; margin: 0; }

a { color: inherit; }

.wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-contrast);
  padding: 0.7rem 1.1rem; border-radius: 0 0 var(--radius-sm) 0; font-weight: 600;
}
.skip-link:focus { left: 0; }

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

.site-header {
  position: sticky; top: 0; z-index: 40;
  backdrop-filter: saturate(180%) blur(14px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex; align-items: center; gap: 1rem;
  min-height: 68px; padding-block: 0.6rem;
}

.brand {
  display: flex; align-items: center; gap: 0.75rem;
  text-decoration: none; margin-right: auto; min-width: 0;
}

.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex: none;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: var(--accent-contrast);
  box-shadow: var(--shadow);
}
.brand-mark svg { width: 24px; height: 24px; }

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong {
  font-size: 1.06rem; letter-spacing: -0.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.brand-text small {
  color: var(--muted); font-size: 0.78rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.header-actions { display: flex; align-items: center; gap: 0.5rem; flex: none; }

/* ------------------------------------------------------------------ button */

.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.55rem 0.95rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 0.9rem; font-weight: 560;
  text-decoration: none; cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}
.btn:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  border-color: transparent; color: var(--accent-contrast);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.83rem; }
.btn-icon { padding: 0.55rem; border-radius: 50%; }
.btn-label-short { display: none; }
.icon { width: 17px; height: 17px; flex: none; }

#theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] #theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] #theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] #theme-toggle .icon-sun { display: none; }
  :root[data-theme="auto"] #theme-toggle .icon-moon { display: block; }
}

.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent); font: inherit; font-size: 0.85rem; font-weight: 560;
  text-decoration: underline; text-underline-offset: 3px;
}

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

/* ------------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 288px) minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
  padding-block: 2rem 4rem;
}

@media (max-width: 940px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
}

/* ----------------------------------------------------------------- filters */

.filters {
  position: sticky; top: 88px;
  min-width: 0;
  display: flex; flex-direction: column; gap: 1.35rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.filters-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.sheet-close, .sheet-footer, .sheet-backdrop { display: none; }
.filters-head h2 { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }

.field { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.field > legend, .field > label {
  padding: 0; font-size: 0.82rem; font-weight: 620; letter-spacing: -0.005em;
}
.field > legend { margin-bottom: 0.15rem; }

.search-wrap { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 0.7rem; color: var(--muted); }

input[type="search"], input[type="date"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit; font-size: 0.9rem;
}
input[type="search"] { padding-left: 2.1rem; }
input[type="search"]:focus, input[type="date"]:focus { border-color: var(--accent); outline: none; }
input[type="date"] { color-scheme: inherit; }

/* A date input will not shrink below about 120px, and the sidebar is 246px
   inside its padding — so give each field its own row unless there is room. */
.date-range { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.5rem; }
.date-field {
  display: flex; flex-direction: column; gap: 0.25rem;
  font-size: 0.76rem; font-weight: 620; color: var(--muted); min-width: 0;
}
.date-field input { min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chips-scroll { max-height: 168px; overflow-y: auto; padding-right: 2px; }

.chip {
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit; font-size: 0.82rem; font-weight: 520;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}
.chip-sm { padding: 0.28rem 0.55rem; font-size: 0.76rem; }
.chip .count { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 0.25rem; }
.chip[aria-pressed="true"] .count { color: inherit; opacity: 0.75; }

.range-pair { display: flex; flex-direction: column; gap: 0.2rem; }
.range-pair label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.8rem; color: var(--muted);
}
.range-pair output { color: var(--text); font-weight: 620; font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; cursor: pointer; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 999px; background: var(--line-strong);
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 999px; background: var(--line-strong); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 17px; height: 17px; margin-top: -6px;
  border-radius: 50%; background: var(--accent);
  border: 2px solid var(--surface); box-shadow: var(--shadow);
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
}

.switch { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; font-size: 0.88rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 38px; height: 22px; flex: none;
  border-radius: 999px; background: var(--line-strong);
  padding: 3px; transition: background 0.16s ease;
}
.switch-thumb {
  display: block; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow);
  transition: transform 0.16s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----------------------------------------------------------------- results */

.results { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

.results-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.results-title { font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2.1rem); }
.results-meta { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9rem; }
.results-tools { display: flex; gap: 0.5rem; }

#filters-toggle { display: none; }
@media (max-width: 700px) {
  .wrap { width: min(100% - 1.6rem, var(--wrap)); }
  .header-inner { gap: 0.5rem; min-height: 60px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .brand-mark svg { width: 20px; height: 20px; }
  .brand-text small { display: none; }
  .brand-text strong { font-size: 0.98rem; }
  .header-actions { gap: 0.35rem; }
  .btn { padding: 0.5rem 0.7rem; font-size: 0.85rem; }
  .btn-label-short { display: inline; }
  #submit-link .btn-label { display: none; }
  #subscribe-link .btn-label { display: none; }
  #subscribe-link { padding: 0.5rem; border-radius: 50%; }
  .layout { padding-block: 1.2rem 3rem; }
  .card { grid-template-columns: 56px minmax(0, 1fr); gap: 0.8rem; padding: 0.9rem 1rem; }
  .card-day { font-size: 1.35rem; }
  .results-head { align-items: flex-start; }
}

@media (max-width: 940px) {
  #filters-toggle { display: inline-flex; }

  /* The filters used to open in the page flow, below the whole event list —
     which looked like the button doing nothing. On small screens they are a
     sheet over the page instead. */
  .filters {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    z-index: 60; display: none;
    width: auto; max-width: none; margin: 0;
    max-height: min(85vh, 40rem);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -14px 44px -18px rgba(0, 0, 0, 0.45);
    animation: sheet-up 0.18s ease-out;
  }
  .filters.open { display: flex; }

  .sheet-backdrop:not([hidden]) {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(8, 16, 13, 0.45);
    backdrop-filter: blur(2px);
  }

  .filters-head {
    position: sticky; top: 0; z-index: 2;
    margin: -1.25rem -1.25rem 0; padding: 1.1rem 1.25rem 0.7rem;
    background: var(--surface);
    align-items: center;
  }

  .sheet-close {
    display: inline-grid; place-items: center;
    width: 32px; height: 32px; flex: none;
    border: 0; border-radius: 50%;
    background: var(--surface-2); color: var(--text);
    font: inherit; font-size: 0.85rem; cursor: pointer;
  }
  .sheet-close:hover { background: var(--line); }

  .sheet-footer {
    display: block;
    position: sticky; bottom: calc(-1rem - env(safe-area-inset-bottom, 0px));
    margin: 0 -1.25rem -1.25rem; padding: 0.8rem 1.25rem;
    padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(transparent, var(--surface) 35%);
  }
  .sheet-footer .btn { width: 100%; justify-content: center; padding-block: 0.7rem; }

  body.sheet-open { overflow: hidden; }
}

@keyframes sheet-up { from { transform: translateY(12px); opacity: 0.6; } }

.badge {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: var(--accent-contrast);
  font-size: 0.7rem; font-weight: 700;
}

.active-filters { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.35rem 0.25rem 0.65rem;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong);
  font-size: 0.78rem; font-weight: 560;
}
.pill button {
  border: 0; background: none; cursor: pointer; color: inherit;
  line-height: 1; padding: 0.15rem; border-radius: 50%; font-size: 0.9rem;
}
.pill button:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.event-list { display: flex; flex-direction: column; gap: 0.7rem; }

.month-heading {
  position: sticky; top: 78px; z-index: 10;
  margin: 1.4rem 0 0.2rem;
  padding: 0.35rem 0;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase;
  color: var(--muted);
  background: linear-gradient(var(--bg) 65%, transparent);
}
.month-heading:first-child { margin-top: 0; }

.card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 1.1rem;
  padding: 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.14s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--line-strong); }

.card.is-today { border-color: var(--accent); }
.card.is-today .card-date { background: var(--accent); color: var(--accent-contrast); }

.card-date {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0.55rem 0.2rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  height: fit-content;
  text-align: center;
}
.card-dow { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.card.is-today .card-dow, .card.is-today .card-month { color: inherit; opacity: 0.85; }
.card-day { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.card-month { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.card-body { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.card-heading { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; }
.card-title { font-size: 1.08rem; font-weight: 650; }
.card-title a { text-decoration: none; }
.card-title a:hover { text-decoration: underline; text-underline-offset: 3px; }

.type-badge {
  padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--badge, var(--muted));
  background: color-mix(in srgb, var(--badge, var(--muted)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--badge, var(--muted)) 32%, transparent);
}

.card-where { margin: 0; color: var(--muted); font-size: 0.88rem; }

.card-facts { display: flex; flex-wrap: wrap; gap: 0.35rem 0.5rem; list-style: none; margin: 0.15rem 0 0; padding: 0; }
.card-facts li {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.79rem; font-weight: 540;
}
.card-facts li.fact-free { color: var(--accent-strong); background: var(--accent-soft); }
.card-facts .fact-icon { width: 13px; height: 13px; opacity: 0.7; }

.card-desc {
  margin: 0.25rem 0 0; color: var(--muted); font-size: 0.88rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.card-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.55rem; }
.card-actions .btn { font-size: 0.79rem; padding: 0.33rem 0.7rem; }

/* --------------------------------------------------------- states & footer */

.skeleton {
  height: 118px; border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 250% 100%;
  animation: shimmer 1.4s infinite linear;
  border: 1px solid var(--line);
}
@keyframes shimmer { to { background-position: -250% 0; } }

.empty {
  display: grid; place-items: center; gap: 0.6rem;
  padding: 3.5rem 1.5rem; text-align: center;
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius-lg);
}
.empty h3 { font-size: 1.15rem; }
.empty p { margin: 0; color: var(--muted); max-width: 44ch; }

.site-footer { border-top: 1px solid var(--line); padding-block: 2rem 3rem; }
.footer-inner { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.87rem; }
.footer-inner p { margin: 0; }
.muted { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 1.6rem; transform: translate(-50%, 1rem);
  padding: 0.6rem 1rem; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: 0.85rem; font-weight: 560;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media print {
  .site-header, .filters, .results-tools, .card-actions, .site-footer { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
}
