/*
 * Crew Pitboard theme on top of Pico.css v2.
 *
 * A dark "timing screen" look: near-black background, high-contrast text and
 * one accent colour (racing red). The layout forces dark mode with
 * <html data-theme="dark">, so only the dark variables are set here.
 *
 * Classes:
 *   .site-header        header bar with the wordmark and the navigation
 *   .wordmark           the "Crew Pitboard" logo text (.wordmark-lg: big, centred)
 *   .centered, .narrow  body / container for the signed-out card pages
 *   .nav-link           a <button> that looks like a nav link (log out)
 *   .inline             a form that sits inline in text or a list
 *   .btn-small          a compact secondary button (e.g. "Remove")
 *   .muted, .lead       secondary text, intro text
 *   .accent             text in the accent colour
 *
 * Landing page:
 *   .hero, .actions     intro block and its row of buttons
 *   ol.steps            numbered "how it works" cards; a grid on wide screens
 *   ol.guide            numbered setup instructions
 *   article.download    download card: text on the left, button on the right
 *
 * Leaderboard (#7):
 *   form.filter         track and class pickers in a row (.filter-actions: buttons)
 *   section.board       one track layout + car class (.board-head: its heading)
 *   td.driver           driver name; .driver-meta under it shows car and date
 *                       on phones, where .col-car and .col-date are hidden
 *   tr.me               the signed-in driver's row
 *   .badge-record       the "Record" tag on the track record holder's row
 *   .empty              the "no laps yet" / "nothing matches" notice
 *   .laptime            a lap or sector time: monospace, tabular figures
 *   .gap                a gap to the leader ("+0.412"), muted .laptime
 *   table.timing        a timing-screen table
 *   tr.p1 / .p2 / .p3   podium rows: gold, silver and bronze edge + position
 *   .pos                the position cell
 *   .badge              car-class badge; colour by class with
 *                       .badge-hypercar, .badge-lmp2, .badge-lmgt3 (GT3),
 *                       .badge-gte; plain .badge for anything else
 */

:root[data-theme="dark"] {
  --rb-accent: #e10600;
  --rb-accent-hover: #ff2419;
  --rb-accent-text: #ff4d42;
  --rb-bg: #0b0b0d;
  --rb-surface: #141418;
  --rb-surface-2: #1c1c22;
  --rb-line: #2a2a32;
  --rb-text: #f2f2f4;
  --rb-muted: #8d8d99;
  --rb-gold: #ffc72c;
  --rb-silver: #c9d1d9;
  --rb-bronze: #d9814a;

  --pico-background-color: var(--rb-bg);
  --pico-color: var(--rb-text);
  --pico-h1-color: #fff;
  --pico-h2-color: #fff;
  --pico-h3-color: #fff;
  --pico-muted-color: var(--rb-muted);
  --pico-muted-border-color: var(--rb-line);

  --pico-primary: var(--rb-accent-text);
  --pico-primary-background: var(--rb-accent);
  --pico-primary-border: var(--rb-accent);
  --pico-primary-underline: rgba(255, 77, 66, 0.5);
  --pico-primary-hover: #ff7a71;
  --pico-primary-hover-background: var(--rb-accent-hover);
  --pico-primary-hover-border: var(--rb-accent-hover);
  --pico-primary-hover-underline: var(--pico-primary-hover);
  --pico-primary-focus: rgba(225, 6, 0, 0.45);
  --pico-primary-inverse: #fff;

  --pico-secondary: var(--rb-muted);
  --pico-secondary-background: var(--rb-surface-2);
  --pico-secondary-border: var(--rb-line);
  --pico-secondary-hover: var(--rb-text);
  --pico-secondary-hover-background: #26262e;
  --pico-secondary-hover-border: #3a3a44;
  --pico-secondary-inverse: var(--rb-text);

  --pico-card-background-color: var(--rb-surface);
  --pico-card-sectioning-background-color: var(--rb-surface-2);
  --pico-card-box-shadow: none;
  --pico-form-element-background-color: var(--rb-bg);
  --pico-form-element-border-color: var(--rb-line);
  --pico-form-element-active-background-color: var(--rb-surface-2);
  --pico-form-element-focus-color: var(--rb-accent);
  --pico-table-border-color: var(--rb-line);
  --pico-table-row-stripped-background-color: rgba(255, 255, 255, 0.025);
  --pico-code-background-color: var(--rb-surface-2);
  --pico-code-color: var(--rb-text);
  --pico-mark-background-color: var(--rb-accent);
  --pico-mark-color: #fff;
}

:root {
  --rb-font-display: "Titillium Web", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --rb-font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --pico-font-family-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pico-font-family-monospace: var(--rb-font-mono);
  --pico-border-radius: 0.2rem;
  --pico-font-weight: 400;
}

/* Pico rounds search forms into pills; keep the theme's tight corners. */
[role="search"] {
  --pico-border-radius: 0.2rem;
}

body {
  background: var(--rb-bg);
}

h1, h2, h3, h4 {
  font-family: var(--rb-font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
}

h1 {
  text-transform: uppercase;
  font-style: italic;
}

h2 {
  font-size: 1.25rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--rb-muted);
}

/* Section heading with a short accent bar, like a timing-screen panel. */
h2::before {
  content: "";
  display: inline-block;
  width: 0.25rem;
  height: 0.9em;
  margin-right: 0.5rem;
  vertical-align: -0.1em;
  background: var(--rb-accent);
  transform: skewX(-15deg);
}

button, [role="button"], input[type="submit"] {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.875rem;
}

article {
  border: 1px solid var(--rb-line);
  border-top: 3px solid var(--rb-accent);
}

pre {
  border: 1px solid var(--rb-line);
}

/* ---- Header ------------------------------------------------------------ */

.site-header {
  background: var(--rb-surface);
  border-bottom: 1px solid var(--rb-line);
  margin-bottom: var(--pico-spacing);
  position: relative;
}

/* Thin accent stripe along the top edge. */
.site-header nav {
  --pico-nav-element-spacing-vertical: 0.6rem;
}

.site-header::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--rb-accent);
}

.site-header nav a:not(.wordmark),
.nav-link {
  color: var(--rb-muted);
  font-weight: 600;
  text-decoration: none;
}

.site-header nav a:not(.wordmark):hover,
.nav-link:hover {
  color: var(--rb-text);
}

/* A button that looks like a nav link. */
/* button[type=submit] (Pico: full width) needs the element in the selector. */
button.nav-link,
button.nav-link:is(:hover, :active, :focus) {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  width: auto;
  font-size: inherit;
  text-transform: none;
  letter-spacing: normal;
}

.nav-link:focus-visible {
  outline: 2px solid var(--rb-accent);
  outline-offset: 2px;
}

.wordmark {
  font-family: var(--rb-font-display);
  font-weight: 700;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-size: 1.35rem;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}

.wordmark span {
  color: var(--rb-accent);
}

.wordmark:hover {
  color: #fff;
  text-decoration: none;
}

.wordmark-lg {
  text-align: center;
  margin-bottom: 1.5rem;
}

.wordmark-lg .wordmark {
  font-size: 2.25rem;
}

/* ---- Signed-out pages: a centred card ----------------------------------- */

body.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  /* Faint diagonal "track" stripes in the background. */
  background:
    repeating-linear-gradient(-55deg, transparent 0 3rem, rgba(255, 255, 255, 0.015) 3rem 6rem),
    radial-gradient(ellipse at top, #1d0a0a, var(--rb-bg) 60%);
}

.narrow {
  max-width: 26rem;
  padding-block: 2rem;
}

.narrow article {
  margin: 0;
}

.narrow h1 {
  font-size: 1.5rem;
}

.narrow form button {
  width: 100%;
}

/* ---- Small helpers ------------------------------------------------------- */

form.inline {
  display: inline;
  margin: 0;
}

button.btn-small {
  padding: 0.1rem 0.5rem;
  margin: 0 0 0 0.5rem;
  font-size: 0.75rem;
  width: auto;
}

.muted {
  color: var(--rb-muted);
}

.lead {
  font-size: 1.125rem;
  color: var(--rb-muted);
}

.accent {
  color: var(--rb-accent);
}

/* ---- Landing page -------------------------------------------------------- */

.hero {
  padding-block: 1.5rem 1rem;
  max-width: 48rem;
}

.hero h1 {
  font-size: clamp(2.25rem, 7vw, 3.5rem);
  line-height: 1.05;
  margin-bottom: 1rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.actions [role="button"] {
  margin: 0;
}

h3 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

ol.steps {
  list-style: none;
  padding: 0;
  counter-reset: step;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}

ol.steps li {
  counter-increment: step;
  list-style: none;
  margin: 0;
  padding: 1.25rem;
  background: var(--rb-surface);
  border: 1px solid var(--rb-line);
  border-left: 3px solid var(--rb-accent);
}

/* Big italic step number, like a car's race number. */
ol.steps li::before {
  content: counter(step, decimal-leading-zero);
  display: block;
  font-family: var(--rb-font-display);
  font-style: italic;
  font-weight: 700;
  font-size: 2rem;
  line-height: 1;
  color: var(--rb-accent);
  margin-bottom: 0.5rem;
}

ol.steps h3 {
  margin-bottom: 0.4rem;
}

ol.steps p {
  margin: 0;
  color: var(--rb-muted);
}

article.download {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

article.download h3 {
  margin-bottom: 0.25rem;
}

article.download p {
  margin: 0;
}

article.download :is(button, [role="button"]) {
  width: auto;
  margin: 0;
}

ol.guide {
  padding-left: 1.25rem;
}

ol.guide li {
  margin-bottom: 0.6rem;
}

ol.guide li::marker {
  color: var(--rb-accent);
  font-weight: 700;
}

/* ---- Leaderboard --------------------------------------------------------- */

.laptime {
  font-family: var(--rb-font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  white-space: nowrap;
}

.gap {
  font-family: var(--rb-font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--rb-muted);
  white-space: nowrap;
}

/*
 * Fixed layout, so every board on the page has the same column positions
 * instead of each table sizing its columns from its own content. The driver
 * column takes the space left over.
 */
table.timing {
  table-layout: fixed;
}

table.timing .col-car { width: 32%; }
table.timing .col-time { width: 7.5rem; }
table.timing .col-gap { width: 7rem; }
table.timing .col-date { width: 7.5rem; }

table.timing td.col-car {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.timing td.driver {
  overflow-wrap: anywhere;
}

table.timing th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rb-muted);
}

table.timing td {
  border-bottom-color: var(--rb-line);
}

table.timing .pos {
  width: 3rem;
  font-family: var(--rb-font-mono);
  font-weight: 700;
  text-align: center;
}

/* Keep "POS" on one line in the narrow column. */
table.timing th.pos {
  white-space: nowrap;
  letter-spacing: 0;
  padding-inline: 0;
}

table.timing tr.p1 td:first-child { box-shadow: inset 4px 0 0 var(--rb-gold); }
table.timing tr.p2 td:first-child { box-shadow: inset 4px 0 0 var(--rb-silver); }
table.timing tr.p3 td:first-child { box-shadow: inset 4px 0 0 var(--rb-bronze); }
table.timing tr.p1 .pos { color: var(--rb-gold); }
table.timing tr.p2 .pos { color: var(--rb-silver); }
table.timing tr.p3 .pos { color: var(--rb-bronze); }
table.timing tr.p1 .laptime { color: var(--rb-gold); font-weight: 700; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: var(--pico-border-radius);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.4;
  vertical-align: middle;
  white-space: nowrap;
  color: #fff;
  background: #3a3a44;
}

.badge-hypercar { background: #c8102e; }
.badge-lmp2 { background: #1f5fd1; }
.badge-lmgt3 { background: #1e8c45; }
.badge-gte { background: #d97a00; }

.badge-record {
  margin-left: 0.4rem;
  background: var(--rb-gold);
  color: #111;
}

form.filter {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0 1rem;
  margin-bottom: 1rem;
}

form.filter label {
  flex: 1 1 12rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--rb-muted);
}

form.filter select {
  margin-top: 0.25rem;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: var(--pico-spacing);
}

.filter-actions :is(button, [role="button"]) {
  width: auto;
  margin: 0;
}

section.board {
  margin-bottom: 2rem;
}

.board-head h2 {
  margin-bottom: 0.25rem;
  color: #fff;
}

.board-head h2 .badge {
  margin-left: 0.5rem;
}

.board-head p {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
}

td.driver {
  font-weight: 600;
}

.driver-meta {
  display: none;
  font-weight: 400;
  color: var(--rb-muted);
}

/* Through Pico's variables, so it also beats the striped rows. */
table.timing tr.me td {
  --pico-background-color: rgba(225, 6, 0, 0.12);
  --pico-table-row-stripped-background-color: rgba(225, 6, 0, 0.12);
}

.empty {
  color: var(--rb-muted);
}

article.empty h3 {
  color: #fff;
}

/* Wide tables scroll sideways on phones instead of breaking the page. */
.table-scroll {
  overflow-x: auto;
}

@media (max-width: 576px) {
  .site-header nav {
    flex-wrap: wrap;
  }
  /* Phones: car and date move under the driver's name. */
  table.timing .col-car,
  table.timing .col-date {
    display: none;
  }
  .driver-meta {
    display: block;
  }
  table.timing :is(th, td) {
    padding-inline: 0.4rem;
  }
  table.timing .pos {
    width: 2rem;
  }
  table.timing .col-time { width: 5.5rem; }
  table.timing .col-gap { width: 5rem; }
  .wordmark {
    font-size: 1.15rem;
  }
}
