/* Thursday Night Thunder — league site, "Pit Wall" look (v1.1).
   Dark navy timing-screen style. config.json colors set --navy (header/nav) and --red (highlights). */
:root {
  --navy: #0d1e41;          /* header, nav (config: colors.primary) */
  --red: #c5113e;           /* highlights (config: colors.accent) */
  --ground: #08132b;        /* page background */
  --panel: #10214a;         /* cards and panels */
  --raise: #1b2b52;         /* badges, tracks, chips */
  --line: #24365f;          /* panel borders */
  --rule: #16264b;          /* row dividers */
  --text: #e8ecf5;
  --muted: #a3aec8;
  --link: #ff8fa6;          /* red tuned for dark backgrounds */
  --red-tint: rgba(197, 17, 62, .16);
  --radius: 8px;
  --tab-h: 60px;
  --strong: #ffffff;        /* points, emphasized numbers */
  --hover: rgba(255, 255, 255, .03);
  --ghost: rgba(255, 255, 255, .06);
  --t5-bg: #c9d2e6;  --t5-fg: #08132b;
  --bar: #c9d2e6;
  --no-bg: #1b2b52;  --no-fg: #ffffff;
  --footer: #060f22;
  --gain-up: #6cb4ff; --gain-down: #ffa05c;
  --link-hover: #ffb8c7;
  --banner-bg: #3a2a05; --banner-line: #7a5a10; --banner-fg: #ffe2a3;
  --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  color-scheme: dark;
  font-family: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--ground);
}
/* Light theme: same look, light surfaces. Header and nav stay navy in both. */
:root[data-theme="light"] {
  --ground: #f2f4f8; --panel: #ffffff; --raise: #e4e8f0; --line: #d3d9e5; --rule: #e6e9f0;
  --text: #0d1e41; --muted: #55607a; --link: #c5113e; --link-hover: #9c0d31;
  --red-tint: rgba(197, 17, 62, .08); --strong: #0d1e41;
  --hover: rgba(13, 30, 65, .035); --ghost: rgba(13, 30, 65, .06);
  --t5-bg: #0d1e41; --t5-fg: #ffffff; --bar: #0d1e41; --no-bg: #0d1e41; --no-fg: #ffffff;
  --footer: #ffffff; --gain-up: #1d5fbf; --gain-down: #b4530b;
  --banner-bg: #fff7e6; --banner-line: #f3d38a; --banner-fg: #6b4a00;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; background: var(--ground); color: var(--text); }
a { color: var(--link); }
a:hover { color: var(--link-hover); }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--panel); color: var(--text); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { font-family: var(--cond); font-weight: 700; letter-spacing: .03em; text-transform: uppercase; margin: 0; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
.site-header { background: var(--navy); border-bottom: 4px solid var(--red); }
.header-inner { display: flex; align-items: center; gap: 20px; min-height: 76px; }
.brand { display: flex; align-items: center; flex: none; }
.brand img { height: 56px; width: auto; display: block; }
.top-nav { display: flex; gap: 2px; flex: 1; }
.top-nav a {
  color: #a3aec8; text-decoration: none; font-family: var(--cond); font-weight: 600; font-size: 17px;
  letter-spacing: .06em; text-transform: uppercase; padding: 10px 14px;
}
.top-nav a:hover { color: #fff; }
.top-nav a.active { color: #fff; box-shadow: inset 0 -3px 0 var(--red); }
.header-tools { display: flex; align-items: center; gap: 10px; }
.theme-btn {
  flex: none; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  background: transparent; color: #c9d2e6; border: 1px solid rgba(255, 255, 255, .22); border-radius: 6px; padding: 0;
}
.theme-btn:hover { color: #fff; border-color: rgba(255, 255, 255, .45); }
.theme-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-btn .sun { display: none; }
:root[data-theme="light"] .theme-btn .sun { display: block; }
:root[data-theme="light"] .theme-btn .moon { display: none; }
.season-pick { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: #a3aec8; }
.season-pick select {
  font: 600 14px 'Barlow', sans-serif; color: #e8ecf5; background: #08132b; border: 1px solid #24365f; border-radius: 6px;
  padding: 8px 10px; min-height: 40px; max-width: 220px;
  color-scheme: dark; /* the header is navy in both themes, so the dropdown list stays dark too */
}
.season-pick option { background: #08132b; color: #e8ecf5; }

/* ---------- Bottom tab bar (phones) ---------- */
.tab-bar { display: none; }
@media (max-width: 759px) {
  .header-inner { flex-direction: column; gap: 8px; padding: 10px 16px 12px; min-height: 0; }
  .brand img { height: 64px; }
  .top-nav { display: none; }
  .header-tools { width: 100%; justify-content: center; }
  .season-pick { flex: 1; justify-content: center; }
  .season-pick select { flex: 1; max-width: 280px; }
  body { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
  .tab-bar {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--navy); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20;
  }
  .tab-bar a {
    min-height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: #a3aec8; text-decoration: none; font-family: var(--cond); font-weight: 600; font-size: 12px; letter-spacing: .02em; text-transform: uppercase;
  }
  .tab-bar a.active { color: #fff; box-shadow: inset 0 -3px 0 var(--red); }
  .tab-bar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
}

/* ---------- Page ---------- */
#main { flex: 1; padding-top: 24px; padding-bottom: 32px; }
#main:focus { outline: none; }
.loading, .notice { color: var(--muted); padding: 24px 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 16px; margin-bottom: 16px; }
.page-head h1 { font-size: 40px; line-height: 1; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.eyebrow { font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.banner { background: var(--banner-bg); border: 1px solid var(--banner-line); color: var(--banner-fg); border-radius: 6px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 22px; }
.card-head a { font-family: var(--mono); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; text-decoration: none; white-space: nowrap; }

.grid-home { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack .card + .card { margin-top: 0; }
@media (min-width: 960px) {
  .grid-home { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; }
}

/* Next race panel */
.next { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.next .tag { align-self: flex-start; background: var(--red); color: #fff; font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .08em; padding: 3px 7px; border-radius: 3px; }
.next h2 { font-size: 32px; line-height: 1.02; margin-top: 4px; }
.next .when { color: var(--muted); font-size: 15px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 10px; margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.facts .k { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.facts .v { font-family: var(--mono); font-weight: 600; font-size: 16px; }

/* Progress */
.progress { height: 4px; background: var(--raise); border-radius: 2px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--red); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th {
  text-align: left; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  font-weight: 500; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.tbl tbody tr:hover { background: var(--hover); }
.tbl tr.lead { background: var(--red-tint); }
.tbl tbody tr.cutline:hover { background: none; }
.tbl tr.cutline td { padding: 0; border-bottom: 2px solid var(--red); }
.tbl tr.cutline span {
  display: block; padding: 6px 8px 3px; font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--red);
}
.tbl .r { text-align: right; }
.tbl .c { text-align: center; }
.tbl .pos { width: 46px; }
.pb {
  display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 26px; padding: 0 4px;
  border-radius: 4px; background: var(--raise); font-weight: 600; font-size: 14px; color: var(--text);
}
.tbl tr.lead .pb { background: var(--red); color: #fff; }
.tbl .pts { font-weight: 600; color: var(--strong); }
.tbl .who { font-weight: 600; }
.tbl .who a { color: var(--text); text-decoration: none; }
.tbl .who a:hover { color: var(--link); text-decoration: underline; }
.tbl .team-sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.car { font-family: var(--mono); font-weight: 500; font-size: 13px; color: var(--muted); white-space: nowrap; }
.gain-up { color: var(--gain-up); font-weight: 600; }
.gain-down { color: var(--gain-down); font-weight: 600; }
.muted { color: var(--muted); }
.d-only { display: none; }
.show-d { display: none; }
@media (min-width: 760px) {
  .d-only { display: table-cell; }
  .show-d { display: block; }
  .show-m { display: none; }
  .tbl .team-sub { display: none; }
  .tbl .who { white-space: nowrap; }
}

/* ---------- Tabs (segmented) ---------- */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 14px; }
.seg a {
  text-decoration: none; font-family: var(--cond); font-weight: 700; font-size: 16px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 9px 18px; min-height: 44px; display: inline-flex; align-items: center;
}
.seg a + a { border-left: 1px solid var(--line); }
.seg a.on { background: var(--red); color: #fff; }

/* ---------- Schedule ---------- */
.sched-sec { font-family: var(--cond); font-weight: 700; font-size: 16px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; padding: 18px 4px 6px; }
.sched-sec:first-child { padding-top: 0; }
.sched { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.sched li + li { border-top: 1px solid var(--rule); }
.sched .row { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 16px; color: var(--text); text-decoration: none; min-height: 54px; }
a.row:hover { background: var(--hover); color: var(--text); }
.sched .rno { font-family: var(--mono); font-weight: 600; font-size: 15px; }
.sched .trk { font-weight: 600; }
.sched .meta { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.sched .right { text-align: right; font-size: 13px; color: var(--muted); }
.sched .right b { display: block; color: var(--text); font-size: 14px; }
.sched li.is-next { background: var(--red-tint); }
.pill { display: inline-block; font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; padding: 2px 6px; border-radius: 3px; background: var(--red); color: #fff; }
.pill.grey { background: var(--raise); color: var(--muted); }

/* ---------- Race page ---------- */
.race-nav { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 12px; font-family: var(--mono); font-size: 13px; text-transform: uppercase; }
.race-nav a { text-decoration: none; }
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile .k { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tile .v { font-weight: 600; font-size: 16px; margin-top: 4px; }
.tile .v small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.tile.hl { background: var(--red-tint); border-color: var(--red); }
.tile.hl a { color: var(--strong); }

/* ---------- Drivers ---------- */
.search { width: 100%; max-width: 360px; font: inherit; color: var(--text); padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; min-height: 44px; background: var(--panel); }
.search::placeholder { color: var(--muted); }
.driver-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-top: 14px; }
.dcard { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-decoration: none; color: var(--text); min-height: 74px; }
.dcard:hover { border-color: var(--red); color: var(--text); }
.dcard .no { flex: none; width: 52px; height: 52px; border-radius: 6px; background: var(--no-bg); color: var(--no-fg); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 600; font-size: 19px; }
.dcard .nm { font-weight: 600; }
.dcard .tm { font-size: 13px; color: var(--muted); }
.dcard .st { font-family: var(--mono); font-size: 12px; margin-top: 2px; color: var(--muted); }

.d-hero { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; position: relative; overflow: hidden; margin-bottom: 16px; }
.d-hero .big-no { position: absolute; right: 12px; top: -10px; font-family: var(--mono); font-weight: 600; font-size: 130px; line-height: 1; color: var(--ghost); }
.d-hero h1 { font-size: 44px; line-height: 1; position: relative; }
.d-hero .tm { color: var(--muted); position: relative; margin-top: 6px; }
.d-hero .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; position: relative; }
.d-hero .chip { background: var(--raise); padding: 5px 10px; border-radius: 4px; font-family: var(--mono); font-weight: 600; font-size: 13px; }
.d-hero .chip.red { background: var(--red); color: #fff; }
.stat-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.stat { background: var(--ground); border: 1px solid var(--line); border-radius: 6px; padding: 12px 8px; text-align: center; }
.stat .v { font-family: var(--mono); font-weight: 600; font-size: 22px; line-height: 1; }
.stat .k { font-size: 12px; color: var(--muted); margin-top: 6px; }
.finishes { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); margin-top: 10px; }
.fin { display: flex; flex-direction: column; align-items: center; gap: 3px; text-decoration: none; color: var(--text); }
.fin b { width: 100%; height: 38px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 600; font-size: 15px; border: 1px solid var(--line); background: var(--ground); }
.fin.win b { background: var(--red); border-color: var(--red); color: #fff; }
.fin.t5 b { background: var(--t5-bg); border-color: var(--t5-bg); color: var(--t5-fg); }
.fin.t10 b { background: var(--raise); }
.fin.dns b { background: transparent; border-style: dashed; color: var(--muted); }
.fin span { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Team bars ---------- */
.bars { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.bar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.bar-top b { font-family: var(--mono); font-weight: 600; }
.bar { height: 6px; background: var(--raise); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--bar); }
.bars .first .bar > span { background: var(--red); }

/* ---------- Roster ---------- */
.team-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.team-grid h3 { font-size: 20px; padding-bottom: 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.team-grid ul { list-style: none; margin: 0; padding: 0; }
.team-grid li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.team-grid li:last-child { border-bottom: 0; }
.team-grid .car { width: 44px; }
.team-grid .who a { color: var(--text); text-decoration: none; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--footer); color: var(--muted); font-family: var(--mono); font-size: 11px; letter-spacing: .03em; padding: 16px 0; }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; }

/* ---------- Small screens ---------- */
@media (max-width: 759px) {
  #main { padding-top: 18px; }
  .page-head h1 { font-size: 32px; }
  .card { padding: 14px; }
  .tbl { font-size: 14px; }
  .tbl th, .tbl td { padding: 8px 6px; }
  .d-hero h1 { font-size: 34px; }
  .d-hero .big-no { font-size: 100px; }
  .sched .row { grid-template-columns: 44px minmax(0, 1fr) auto; padding: 10px 12px; }
}

/* ---------- Export buttons (v1.3) ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; cursor: pointer; white-space: nowrap;
  font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
}
.btn:hover { border-color: var(--red); color: var(--strong); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.head-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.race-nav .btn { text-transform: uppercase; }
@media (max-width: 759px) {
  .head-tools { width: 100%; }
  .head-tools .search { flex: 1 1 200px; max-width: none; }
  .race-nav:has(.btn-row) { flex-direction: column; align-items: flex-start; }
  .btn-row { justify-content: flex-start; width: 100%; }
}
@media (min-width: 760px) { .head-tools { flex-wrap: nowrap; } .head-tools .search { width: 300px; } }
