/* Circuit Track Days — mobile-first, dark-first.
 *
 * Two things this stylesheet is built around:
 *   1. Phones. Most people check this standing next to a car, one-handed. So
 *      the layout is a card list at small widths and only becomes a row at
 *      desktop — never a table squeezed onto a 390px screen.
 *   2. Dark mode as a first-class theme, not an inverted afterthought. The
 *      dark palette is a warm-neutral ramp with a real accent, and every
 *      state (sold out, warning, pill) is defined in both themes.
 *
 * Theme resolution: system preference by default, overridden by
 * html[data-theme] which the toggle sets and localStorage persists.
 */

:root {
  --bg: #ffffff;
  --bg-sunk: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --ink: #14161a;
  --ink-2: #4a4f59;
  --muted: #767d89;
  --line: #e2e5ea;
  --line-2: #eef0f3;
  --accent: #c8362b;
  --accent-ink: #ffffff;
  --accent-soft: #fdecea;
  --ok: #15803d;
  --warn: #b45309;
  --fail: #c8362b;
  --car: #1d6fd0;
  --bike: #b45309;
  --shadow: 0 1px 2px rgba(16, 18, 22, .06), 0 4px 12px rgba(16, 18, 22, .05);
  --r: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f13;
    --bg-sunk: #090b0e;
    --panel: #161a20;
    --panel-2: #1c2128;
    --ink: #e8eaee;
    --ink-2: #b6bcc6;
    --muted: #8b94a1;
    --line: #262c35;
    --line-2: #1e232b;
    --accent: #ff5c4d;
    --accent-ink: #14161a;
    --accent-soft: #2a1714;
    --ok: #46d18a;
    --warn: #e5a54b;
    --fail: #ff5c4d;
    --car: #5aa9f8;
    --bike: #e5a54b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bg: #0d0f13;
  --bg-sunk: #090b0e;
  --panel: #161a20;
  --panel-2: #1c2128;
  --ink: #e8eaee;
  --ink-2: #b6bcc6;
  --muted: #8b94a1;
  --line: #262c35;
  --line-2: #1e232b;
  --accent: #ff5c4d;
  --accent-ink: #14161a;
  --accent-soft: #2a1714;
  --ok: #46d18a;
  --warn: #e5a54b;
  --fail: #ff5c4d;
  --car: #5aa9f8;
  --bike: #e5a54b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg-sunk);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 max(1rem, env(safe-area-inset-left));
}

.muted { color: var(--muted); }
.link-btn {
  background: none; border: 0; padding: 0; font: inherit;
  color: var(--accent); text-decoration: underline; cursor: pointer;
}

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

.site-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding-top: 1rem; padding-bottom: 1rem;
}
.brand { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.flag { font-size: 1.7rem; line-height: 1; }
.site-header h1 {
  margin: 0; font-size: 1.25rem; letter-spacing: -.02em; line-height: 1.2;
}
.tagline { margin: .15rem 0 0; color: var(--muted); font-size: .84rem; }

.theme-toggle {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  font-size: 1.15rem;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}
.theme-toggle:active { transform: scale(.94); }

/* --- sticky controls ------------------------------------------------------ */

.controls-bar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: .6rem 0;
}
.filters { display: flex; flex-direction: column; gap: .5rem; }
.row-1 { display: flex; gap: .5rem; }
.row-2 {
  display: flex; gap: .5rem;
  overflow-x: auto; scrollbar-width: none;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.row-2::-webkit-scrollbar { display: none; }

#q {
  flex: 1 1 auto; min-width: 0;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  padding: .6rem .8rem;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px;
}
#q::placeholder { color: var(--muted); }
.reset {
  flex: none; font: inherit; font-size: .88rem;
  padding: .5rem .9rem;
  color: var(--ink-2); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
}

.row-2 select {
  flex: none; font: inherit; font-size: .88rem;
  padding: .45rem 1.9rem .45rem .75rem;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px;
  appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 1rem center, right .72rem center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.chip {
  flex: none; display: flex; align-items: center; gap: .4rem;
  font-size: .88rem; white-space: nowrap;
  padding: .45rem .85rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; cursor: pointer;
}
.chip:has(input:checked) {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}
.chip input { accent-color: var(--accent); margin: 0; }

:where(#q, select, button, input):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* --- status --------------------------------------------------------------- */

.status {
  margin: .9rem 0 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.status-toggle {
  width: 100%; display: flex; align-items: center; gap: .55rem;
  padding: .6rem .8rem; font: inherit; font-size: .86rem;
  color: var(--ink-2); background: none; border: 0;
  text-align: left; cursor: pointer;
}
.status-toggle #status-summary { flex: 1; }
.chev { color: var(--muted); transition: transform .15s; }
.status-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); flex: none;
}
.status[data-level="warn"] .status-toggle > .dot { background: var(--warn); }
.status[data-level="fail"] .status-toggle > .dot { background: var(--fail); }

.source-list { list-style: none; margin: 0; padding: 0 .8rem .6rem; }
.source-list li {
  display: flex; align-items: baseline; gap: .5rem;
  padding: .4rem 0; font-size: .84rem;
  border-top: 1px solid var(--line-2);
}
li[data-level="warn"] .dot { background: var(--warn); }
li[data-level="fail"] .dot { background: var(--fail); }

.count { color: var(--muted); font-size: .84rem; margin: .9rem 0 .5rem; }

/* --- day list ------------------------------------------------------------- */

.days { list-style: none; margin: 0; padding: 0; }

.month-sep {
  position: sticky; top: 104px; z-index: 10;
  margin: 1.2rem 0 .5rem;
  padding: .3rem 0;
  font-size: .76rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent);
  background: var(--bg-sunk);
}
.month-sep:first-child { margin-top: .2rem; }

.day {
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-areas: "date main" "cta cta";
  gap: .1rem .85rem;
  padding: .85rem;
  margin-bottom: .55rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.date {
  grid-area: date;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  padding: .35rem 0;
  background: var(--panel-2);
  border-radius: 10px;
  line-height: 1.1;
}
.dow { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dom { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.mon { font-size: .68rem; text-transform: uppercase; color: var(--muted); }

.main { grid-area: main; min-width: 0; }
.circuit { margin: 0; font-size: 1.02rem; font-weight: 650; letter-spacing: -.01em; }
.layout { font-weight: 400; font-size: .84rem; color: var(--muted); }
.ops {
  margin: .2rem 0 0; font-size: .84rem; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.pills { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.pill {
  font-size: .72rem; padding: .1rem .5rem;
  border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); background: var(--panel-2);
  white-space: nowrap;
}
.pill.car  { color: var(--car);  border-color: color-mix(in srgb, var(--car) 40%, var(--line)); }
.pill.bike { color: var(--bike); border-color: color-mix(in srgb, var(--bike) 40%, var(--line)); }

.cta {
  grid-area: cta;
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; margin-top: .7rem;
  padding-top: .7rem; border-top: 1px solid var(--line-2);
}
.price { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.price .from { font-size: .72rem; font-weight: 400; color: var(--muted); }
.sellers { font-size: .74rem; color: var(--muted); font-weight: 400; }

.book {
  display: inline-block; padding: .45rem 1.1rem;
  font-size: .88rem; font-weight: 600; text-decoration: none;
  color: var(--accent-ink); background: var(--accent);
  border-radius: 999px; white-space: nowrap;
}
.book:active { transform: scale(.97); }

.sold {
  font-size: .78rem; font-weight: 600; color: var(--muted);
  padding: .45rem .8rem; border: 1px dashed var(--line);
  border-radius: 999px;
}
.day[data-status="sold_out"], .day[data-status="cancelled"] { opacity: .62; }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 0; }

/* --- footer --------------------------------------------------------------- */

.site-footer {
  margin: 2rem auto 3rem; padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: .82rem;
}
.site-footer a { color: var(--accent); }
.foot-links {
  display: flex; flex-wrap: wrap; gap: .35rem 1rem; align-items: center;
}

/* --- desktop -------------------------------------------------------------- */

@media (min-width: 720px) {
  .site-header h1 { font-size: 1.45rem; }
  .tagline { font-size: .9rem; }

  .filters { flex-direction: row; align-items: center; }
  .row-1 { flex: 1 1 20rem; }
  .row-2 { overflow: visible; }

  .month-sep { top: 62px; font-size: .8rem; }

  .day {
    grid-template-columns: 62px 1fr auto;
    grid-template-areas: "date main cta";
    align-items: center;
    gap: 1rem;
    padding: .8rem 1rem;
  }
  .cta {
    margin-top: 0; padding-top: 0; border-top: 0;
    flex-direction: column; align-items: flex-end; gap: .35rem;
    min-width: 8.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Non-UK circuits get a flag pill — several operators sell European days
   alongside British ones, and the difference matters before you book a ferry. */
.pill.eu {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}
