/* =====================================================================
   F1 — fixed "race day" theme.
   Like Redline, this page ignores the center's light/dark mode and the
   shared glass chrome (no glass.css is loaded). Palette: paddock sky,
   white racing livery, F1 red, asphalt grey and chequered-flag trim —
   bright daylight above, pit-wall darkness for the result papers.
   ===================================================================== */
:root {
  --f1-sky:   #7ec3ea;
  --f1-turf:  #4c8a3f;
  --f1-red:   #e02020;
  --f1-amber: #ffd83a;
  --f1-ink:   #1c2028;
  --f1-paper: #f4f7fa;
  --f1-muted: #55606c;
  --f1-line:  rgba(28, 32, 40, .16);
  --f1-asphalt:  #23252c;
  --f1-asphalt2: #17181d;
}

html, body { height: 100%; }
body.f1-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, var(--f1-sky) 0%, #b7dff2 52%, #d3e9c6 100%);
  color: var(--f1-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.f1-page *,
body.f1-page *::before,
body.f1-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar (the pit wall) ---------- */
.c-bar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, .78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(224, 32, 32, .45);
  box-shadow: 0 6px 18px rgba(30, 60, 90, .18);
  z-index: 20;
}
/* chequered flag stripe under the bar */
.c-bar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -6px;
  height: 6px;
  background: repeating-linear-gradient(90deg, #111 0 8px, #eee 8px 16px);
  opacity: .9;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { border-radius: 5px; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-style: italic;
  white-space: nowrap;
  color: var(--f1-red);
  text-shadow: 1px 1px 0 rgba(255, 255, 255, .9);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 14px; font-weight: 700; letter-spacing: .03em; white-space: nowrap; color: var(--f1-muted); }
.stat b { color: var(--f1-red); font-size: 16px; }

/* ---------- Buttons (white livery, red cap) ---------- */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid rgba(28, 32, 40, .35);
  background: var(--f1-paper);
  color: var(--f1-ink);
  box-shadow: 0 3px 0 rgba(28, 32, 40, .3);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.c-btn:hover { background: #ddebf7; border-color: var(--f1-ink); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(28, 32, 40, .3); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(224, 32, 32, .35); }
.c-btn--primary {
  background: linear-gradient(140deg, #ff4a3a, var(--f1-red) 55%, #9c0d0d);
  border-color: #7c0a0a;
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .3);
}
.c-btn--primary:hover {
  background: linear-gradient(140deg, #ff6a5a, #f33 55%, #b01212);
  border-color: var(--f1-ink);
}

/* ---------- Table / stage ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.4vh, 22px);
}
.f1-stage {
  position: relative;
  /* 8:5, capped by viewport height minus the chrome — small screens just
     get a smaller screen, never a horizontal scroll. */
  width: min(96vw, calc((100vh - 176px) * 1.6), 860px);
  aspect-ratio: 8 / 5;
  border-radius: 14px;
  overflow: hidden;
  background: #101425;
  border: 3px solid #fff;
  box-shadow: 0 10px 0 rgba(28, 32, 40, .35), 0 22px 48px rgba(20, 40, 60, .35),
              0 0 0 2px rgba(224, 32, 32, .5);
  touch-action: none;
}
#screen { display: block; width: 100%; height: 100%; }

/* ---------- Ready / safety car / results overlays ---------- */
.f1-overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(226, 238, 246, .35);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  cursor: default;
}
.f1-overlay[hidden] { display: none; }
.f1-card {
  touch-action: manipulation;
  max-width: 380px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  text-align: center;
  padding: 22px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, var(--f1-asphalt), var(--f1-asphalt2));
  border: 2px solid rgba(224, 32, 32, .65);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .45), 0 22px 50px rgba(0, 0, 0, .55);
  color: var(--f1-paper);
  animation: f1Pop .3s ease;
}
@keyframes f1Pop { from { transform: scale(.88); opacity: 0; } }
.f1-card__big { font-size: 40px; line-height: 1.1; }
.f1-card h2 {
  margin: 6px 0;
  font-size: 21px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(224, 32, 32, .55);
}
.f1-card p { margin: 0 0 14px; color: #b9c2cf; font-size: 13.5px; line-height: 1.55; }
.f1-card p b { color: var(--f1-amber); }   /* kbd excluded: its own chip styling */
.f1-card .c-btn { font-size: 14px; }
.f1-card kbd, .c-modal kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: var(--f1-ink);
  background: var(--f1-paper);
  border-radius: 6px;
  border-bottom: 2px solid rgba(0, 0, 0, .5);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .4);
}
.c-win__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Results board ---------- */
.f1-res {
  margin: 0 0 14px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(255, 255, 255, .12);
  font-size: 12.5px;
  text-align: left;
}
.f1-res__row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 2.5px 4px;
  border-radius: 6px;
  color: #b9c2cf;
}
.f1-res__row b { font-weight: 800; letter-spacing: .04em; }
.f1-res__row--me {
  background: rgba(224, 32, 32, .22);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--f1-red);
}
.f1-res__row:nth-child(1) { color: #ffe27a; }   /* the winner's row glows a bit */

/* ---------- Rules modal ---------- */
.c-modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 30, 42, .55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.c-modal__panel {
  position: relative;
  width: min(92vw, 470px);
  max-height: 86vh;
  overflow: auto;
  background: linear-gradient(160deg, var(--f1-asphalt), var(--f1-asphalt2));
  color: var(--f1-paper);
  border-radius: 16px;
  border: 2px solid rgba(224, 32, 32, .55);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .5), 0 24px 60px rgba(0, 0, 0, .65);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, .14);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 900; font-style: italic;
  text-transform: uppercase; letter-spacing: .04em;
  color: #fff; text-shadow: 2px 2px 0 rgba(224, 32, 32, .5);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: var(--f1-paper); font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--f1-red); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .06em;
  color: #ff6a5a;
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--f1-amber); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(224, 32, 32, .12);
  border: 1px solid rgba(224, 32, 32, .4);
  font-size: 13px;
  color: #cfd6e0;
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }

/* ---------- Responsive ---------- */
/* Phones and short windows: tighten the bar's type and padding. The old rule
   pinned it to one row with flex-wrap: nowrap, which starved the control
   group — its buttons then wrapped into a tower taller than the header itself
   while the nowrap title spilled over the score readout. */
@media (max-width: 700px), (max-height: 560px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; }
  .c-bar__stats { gap: 4px 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
}
/* Narrow screens only: the buttons drop to a row of their own and split it
   evenly into full-width thumb targets. A landscape phone still has the width
   for one compact row, so it keeps the shorter header. */
@media (max-width: 700px) {
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
}
/* Smallest phones: four buttons no longer fit side by side, and letting them
   wrap would double the header's height again — so the labels scale down with
   the viewport instead of stacking or clipping. */
@media (max-width: 380px) {
  .c-bar { gap: 5px 8px; }
  .c-bar__title { font-size: 15px; }
  .stat { font-size: 11px; }
  .stat b { font-size: 12px; }
  .c-bar__controls { gap: 4px; }
  .c-bar__controls .c-btn { font-size: clamp(10px, 3.2vw, 12px); padding: 9px 4px; letter-spacing: .01em; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .f1-card { transition: none; animation: none; }
}
