/* ==========================================================================
   Rally Hub · 8&Pico Soluções Audiovisuais
   Linguagem visual: road-book e placas de PEC. Mobile-first, legível ao sol.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  --font-text: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-display: "Big Shoulders Display", "Archivo", "Arial Narrow", sans-serif;

  --bg: #f2f0ea;
  --bg-2: #e8e5dc;
  --surface: #fbfaf6;
  --ink: #131311;
  --ink-2: #393732;
  --muted: #6a665d;
  --faint: #99948a;
  --rule: #dbd7cc;
  --rule-2: #c3beb2;
  --signal: #ffc21a;
  --signal-2: #ffd45a;
  --signal-ink: #131311;
  --red: #d42419;
  --red-soft: #fbe2df;
  --green: #11804a;
  --plate-bg: #ffffff;
  --plate-ink: #131311;
  --plate-line: #131311;
  --shadow: 0 1px 0 rgba(19, 19, 17, 0.04), 0 8px 24px -12px rgba(19, 19, 17, 0.18);
  --map-filter: none;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r1: 3px; --r2: 6px;
  --gutter: 16px;
  --appbar-h: 54px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0e0e0d;
  --bg-2: #171715;
  --surface: #1b1b19;
  --ink: #f2efe7;
  --ink-2: #d3cfc5;
  --muted: #9d988d;
  --faint: #6e6a62;
  --rule: #2a2926;
  --rule-2: #3c3a36;
  --red: #ff5d50;
  --red-soft: #3b1714;
  --green: #44cf88;
  --plate-bg: #f2efe7;
  --plate-line: #f2efe7;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 30px -14px rgba(0, 0, 0, 0.7);
  --map-filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e0d;
    --bg-2: #171715;
    --surface: #1b1b19;
    --ink: #f2efe7;
    --ink-2: #d3cfc5;
    --muted: #9d988d;
    --faint: #6e6a62;
    --rule: #2a2926;
    --rule-2: #3c3a36;
    --red: #ff5d50;
    --red-soft: #3b1714;
    --green: #44cf88;
    --plate-bg: #f2efe7;
    --plate-line: #f2efe7;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 10px 30px -14px rgba(0, 0, 0, 0.7);
    --map-filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.6);
    color-scheme: dark;
  }
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.45;
  font-stretch: 96%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0; line-height: 1.1; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
dl, dd { margin: 0; }
::selection { background: var(--signal); color: var(--signal-ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: var(--s2); top: -60px; z-index: 100;
  background: var(--signal); color: var(--signal-ink); padding: var(--s2) var(--s3);
  font-weight: 700; border-radius: var(--r1); text-decoration: none;
}
.skip:focus { top: var(--s2); }

/* ---------- 3. Ícones ---------- */
.i {
  width: 1.25em; height: 1.25em; flex: none;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -0.25em;
}
.i--fill { fill: currentColor; stroke: none; }

/* ---------- 4. Estrutura ---------- */
.appbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--appbar-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--rule);
}
.appbar-inner {
  height: 100%; max-width: 1240px; margin: 0 auto;
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--gutter);
}
.brand { display: flex; align-items: center; gap: var(--s3); min-width: 0; text-decoration: none; flex: 1; }
.brand-logo { height: 22px; width: auto; flex: none; }
.brand-logo--dark { display: none; }
:root[data-theme="dark"] .brand-logo--light, :root[data-theme="dark"] .logo--light { display: none; }
:root[data-theme="dark"] .brand-logo--dark, :root[data-theme="dark"] .logo--dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-logo--light, :root:not([data-theme="light"]) .logo--light { display: none; }
  :root:not([data-theme="light"]) .brand-logo--dark, :root:not([data-theme="light"]) .logo--dark { display: block; }
}
.logo--dark { display: none; }
.brand-sep { width: 1px; height: 22px; background: var(--rule-2); flex: none; }
.brand-event {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-display); font-weight: 800; font-size: 1.1rem;
  text-transform: uppercase; letter-spacing: .02em;
}
.appbar-actions { display: flex; align-items: center; gap: var(--s1); }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: var(--r2); color: var(--ink);
}
.icon-btn:hover { background: var(--bg-2); }
/* Menu "Mais": painel sobreposto à página (por baixo da barra inferior, que continua visível). */
.moremenu { position: fixed; left: 0; right: 0; top: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 1100; }
.moremenu-backdrop { position: absolute; inset: 0; background: rgba(10, 10, 9, .5); opacity: 0; transition: opacity .2s var(--ease); }
.moremenu-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: calc(100% - 24px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-top: 1px solid var(--rule-2); border-radius: 14px 14px 0 0;
  box-shadow: 0 -12px 32px -14px rgba(0, 0, 0, .45); padding: 6px var(--gutter) var(--s4);
  transform: translateY(100%); transition: transform .22s var(--ease);
}
.moremenu.is-open .moremenu-backdrop { opacity: 1; }
.moremenu.is-open .moremenu-panel { transform: none; }
.moremenu-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0 var(--s3); }
.moremenu-head h2 { font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: 1.9rem; line-height: 1; }
.moremenu-close { border: 1px solid var(--rule-2); }
.moremenu .access-card { margin-bottom: var(--s4); }
.moremenu-list a:last-child { border-bottom: 0; }
body.is-menu-open { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .moremenu-backdrop, .moremenu-panel { transition: none; } }
/* Ecrãs largos (sem barra inferior): só é aberto pela indicação "Estúdio"; painel junto ao topo. */
@media (min-width: 1080px) {
  .moremenu-panel {
    left: auto; right: max(16px, calc((100vw - 1240px) / 2)); bottom: auto; top: calc(var(--appbar-h) + 8px); width: 400px;
    max-height: calc(100% - var(--appbar-h) - 24px); border: 1px solid var(--rule-2); border-radius: var(--r2);
    transform: translateY(-8px); opacity: 0; transition: transform .18s var(--ease), opacity .18s var(--ease);
  }
  .moremenu.is-open .moremenu-panel { opacity: 1; }
  .moremenu-list { display: none; }
}
.icon-btn .i { width: 22px; height: 22px; }

.livepill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 9px 0 8px; border-radius: 13px;
  background: var(--signal); color: var(--signal-ink);
  font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  text-decoration: none; white-space: nowrap;
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none;
  box-shadow: 0 0 0 0 rgba(212, 36, 25, .55);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(212, 36, 25, .55); }
  70% { box-shadow: 0 0 0 7px rgba(212, 36, 25, 0); }
  100% { box-shadow: 0 0 0 0 rgba(212, 36, 25, 0); }
}

/* Faixa de estado (PEC ao vivo / próxima) */
.ticker {
  display: block; text-decoration: none;
  background: var(--ink); color: var(--bg);
  border-bottom: 1px solid var(--ink);
}
.ticker-inner {
  max-width: 1240px; margin: 0 auto; padding: 9px var(--gutter);
  display: flex; align-items: center; gap: var(--s3); min-width: 0;
  font-size: .86rem;
}
.ticker .sstag { flex: none; }
.ticker-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticker-text strong { font-weight: 700; }
.ticker-meta { flex: none; font-variant-numeric: tabular-nums; opacity: .8; }
.ticker .i { opacity: .7; }

.announce { border-bottom: 1px solid var(--rule); background: var(--surface); }
.announce-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px var(--gutter);
  display: flex; gap: var(--s3); align-items: flex-start; font-size: .92rem;
}
.announce-inner .i { margin-top: 1px; }
.announce-text { flex: 1; white-space: pre-line; }
.announce-text a { font-weight: 700; }
.announce--warning { background: var(--signal); color: var(--signal-ink); border-color: transparent; }
.announce--alert { background: var(--red); color: #fff; border-color: transparent; }

.netbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px); z-index: 70;
  max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); border-radius: 20px;
  padding: 8px 14px; font-size: .82rem; font-weight: 600; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
}

.main { min-height: calc(100dvh - var(--appbar-h) - 160px); }
body { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
body.is-map { overflow: hidden; }
body.is-map .footer { display: none; }
.main:focus { outline: none; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 var(--gutter); }
.view { animation: viewIn .28s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Barra de separadores (telemóvel) */
.tabbar {
  /* Por cima do menu "Mais" (z-index 1100), para o botão "Fechar" estar sempre acessível. */
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1200;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--rule);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
}
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted);
  font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}
button.tab { border: 0; background: none; padding: 0; font-family: inherit; cursor: pointer; }
.tab[aria-expanded="true"] { color: var(--ink); }
.tab .i { width: 24px; height: 24px; stroke-width: 1.7; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"]::before {
  content: ""; position: absolute; top: -1px; left: 22%; right: 22%; height: 3px;
  background: var(--signal); border-radius: 0 0 2px 2px;
}
/* Secção visível só com acesso de estúdio */
.tab-lock {
  position: absolute; top: 5px; left: calc(50% - 24px); width: 16px; height: 16px; display: grid; place-items: center;
  border-radius: 50%; background: var(--ink); color: var(--bg);
}
.tab-lock .i { width: 10px; height: 10px; stroke-width: 2.4; }
.i-lock { width: 14px; height: 14px; margin-left: 4px; opacity: .65; vertical-align: -2px; }
.accesspill {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px 0 8px; border-radius: 13px;
  background: var(--ink); color: var(--bg); text-decoration: none; white-space: nowrap;
  font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
}
button.accesspill { border: 0; font-family: inherit; cursor: pointer; }
.accesspill .i { width: 14px; height: 14px; }
.access-card .eyebrow { display: flex; align-items: center; gap: 6px; }
.access-card .eyebrow .i { width: 15px; height: 15px; }
.access-card h2, .access-card h3 { font-size: 1.2rem; margin: 6px 0 2px; }
.access-card p + p { margin-top: 8px; }
.access-card .btn { margin-top: 14px; }
.tab-dot {
  position: absolute; top: 9px; left: calc(50% + 8px);
  width: 8px; height: 8px; border-radius: 50%; background: var(--red);
  border: 2px solid var(--surface);
}

/* Navegação superior (ecrãs largos) */
.topnav { display: none; }

.footer {
  max-width: 1240px; margin: var(--s7) auto 0; padding: var(--s5) var(--gutter) var(--s6);
  border-top: 1px solid var(--rule);
  display: flex; flex-wrap: wrap; gap: var(--s4); align-items: center; justify-content: space-between;
  color: var(--muted); font-size: .8rem;
}
.footer-brand { display: flex; align-items: center; gap: var(--s3); text-decoration: none; }
.footer-brand img { height: 34px; width: auto; }
.footer-dev { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
/* "Portal desenvolvido por" + logótipo 8&Pico, separado do logótipo Rally Hub por um filete. */
.footer-by { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding-left: var(--s4); border-left: 1px solid var(--rule-2); text-decoration: none; color: var(--muted); }
.footer-by img { height: 30px; width: auto; }
.footer-text { display: grid; gap: var(--s1); max-width: 62ch; text-wrap: pretty; }
.footer-text strong { color: var(--ink); }

/* ---------- 5. Tipografia ---------- */
.eyebrow {
  font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.view-head { padding: var(--s5) 0 var(--s4); display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.view-title {
  font-family: var(--font-display); font-weight: 800; text-transform: uppercase;
  font-size: clamp(2.1rem, 9vw, 3.2rem); letter-spacing: .01em; line-height: .95;
}
.view-sub { color: var(--muted); font-size: .92rem; margin-top: 6px; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.muted { color: var(--muted); }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }

/* Cabeçalho de secção estilo folha de tempos */
.sec { margin-top: var(--s6); }
.sec:first-child { margin-top: var(--s4); }
.sec-h {
  display: flex; align-items: center; gap: var(--s3);
  margin-bottom: var(--s3);
}
.sec-h::after { content: ""; flex: 1; height: 1px; background: var(--rule); order: 2; }
.sec-h-label { order: 1; font-size: .74rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.sec-h-meta { order: 3; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.sec-h a.sec-h-meta { color: var(--ink); font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; gap: 2px; }
.sec-h a.sec-h-meta:hover { text-decoration: underline; }

/* ---------- 6. Componentes ---------- */

/* Placa de número (porta do carro) */
.plate {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.3em; height: 1.7em; padding: 0 .3em;
  background: var(--plate-bg); color: var(--plate-ink);
  border: 1.5px solid var(--plate-line); border-radius: var(--r1);
  font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; line-height: 1;
  letter-spacing: .01em; font-variant-numeric: tabular-nums;
}
.plate--lg { font-size: 1.6rem; min-width: 2.1em; }
.plate--xl { font-size: clamp(3.4rem, 18vw, 5rem); min-width: 1.9em; height: 1.5em; border-width: 3px; border-radius: var(--r2); }
.plate--fav { box-shadow: 0 0 0 2px var(--signal); }

/* Placa de PEC */
.sstag {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 24px; padding: 0 7px; border-radius: var(--r1);
  font-family: var(--font-display); font-weight: 800; font-size: 1rem; letter-spacing: .03em;
  border: 1.5px solid var(--ink); color: var(--ink); background: transparent;
  white-space: nowrap; line-height: 1;
}
.sstag[data-state="live"] { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.sstag[data-state="finished"] { background: var(--ink); color: var(--bg); }
.sstag[data-state="upcoming"], .sstag[data-state="waiting"] { border-style: solid; }
.sstag[data-state="notimes"] { border-style: dashed; color: var(--muted); border-color: var(--rule-2); }
/* Neutralizada: tem resultados, mas distingue-se da concluída. Cancelada: sem resultados, riscada. */
.sstag[data-state="neutralized"] { background: var(--muted); border-color: var(--muted); color: var(--bg); }
.sstag[data-state="cancelled"] { border-style: dashed; color: var(--muted); border-color: var(--rule-2); text-decoration: line-through; }
.sstag--lg { height: 34px; font-size: 1.45rem; padding: 0 10px; }
.ticker .sstag:not([data-state="live"]) { border-color: var(--bg); color: var(--bg); }
.ticker .sstag[data-state="finished"] { background: var(--bg); color: var(--ink); }

/* Chips de filtro / seleção: sem scroll horizontal, passam a várias linhas quando não cabem. */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); padding: 2px 0; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: var(--r2);
  border: 1px solid var(--rule-2); background: var(--surface); color: var(--ink);
  font-size: .86rem; font-weight: 600; white-space: nowrap; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"], .chip[aria-current="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .sstag { height: 20px; font-size: .9rem; padding: 0 5px; }
.chip[aria-pressed="true"] .sstag[data-state="finished"], .chip[aria-current="true"] .sstag[data-state="finished"] { background: var(--bg); color: var(--ink); border-color: var(--bg); }
.chip[aria-pressed="true"] .sstag:not([data-state="live"]):not([data-state="finished"]),
.chip[aria-current="true"] .sstag:not([data-state="live"]):not([data-state="finished"]) { border-color: var(--bg); color: var(--bg); }
.chip-count { font-size: .75rem; opacity: .7; font-variant-numeric: tabular-nums; }
.chip--stage { height: 40px; padding: 0 10px 0 6px; }
.chip-sub { font-size: .72rem; font-weight: 500; opacity: .75; }
/* Telemóvel: PEC só pelo código (cabem todas em poucas linhas); campeonato numa lista de seleção. */
@media (max-width: 719px) {
  .chip-sub { display: none; }
  .chip--stage { padding: 0 6px; }
  .chips--champ { display: none; }
  /* Sobre o mapa: um pouco mais compactas, para ocuparem menos mapa. */
  .map-top .chips { gap: 6px; }
  .map-top .chip { height: 34px; padding: 0 10px; }
  .map-top .chip--stage { padding: 0 4px; }
}
.select--champ { flex: 1 1 220px; min-width: 0; max-width: 100%; text-overflow: ellipsis; }
@media (min-width: 720px) { .select--champ { display: none; } }

/* Controlo segmentado */
.seg {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--bg-2); border-radius: var(--r2); padding: 3px; gap: 3px;
}
.seg button {
  border: 0; background: transparent; border-radius: 4px; height: 34px; padding: 0 14px;
  font-size: .86rem; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: var(--r2);
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  font-weight: 700; font-size: .92rem; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--bg-2); }
.btn--primary { background: var(--ink); color: var(--bg); }
.btn--primary:hover { background: var(--ink-2); }
.btn--signal { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.btn--signal:hover { background: var(--signal-2); }
.btn--sm { min-height: 34px; padding: 0 12px; font-size: .84rem; }
.btn--block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* Distintivos */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px;
  border-radius: var(--r1); font-size: .7rem; font-weight: 800; letter-spacing: .04em;
  text-transform: uppercase; white-space: nowrap; vertical-align: middle;
  background: var(--bg-2); color: var(--ink-2);
}
.badge--pen { background: var(--red-soft); color: var(--red); }
.badge--dnf { background: var(--red); color: #fff; }
.badge--live { background: var(--signal); color: var(--signal-ink); }
.badge--line { background: transparent; border: 1px solid var(--rule-2); color: var(--muted); }
.badge--champ { background: transparent; border: 1px solid var(--rule-2); color: var(--ink-2); font-weight: 700; letter-spacing: .02em; text-transform: none; }

.flag { width: 18px; height: 13px; object-fit: cover; border-radius: 1px; display: inline-block; vertical-align: -1px; box-shadow: 0 0 0 1px rgba(0,0,0,.12); flex: none; }

/* Lista de classificação */
.rk-list { border-top: 1px solid var(--rule); }
.rk {
  display: grid; align-items: center;
  grid-template-columns: 2.1rem 3.1rem minmax(0, 1fr) auto;
  gap: 0 var(--s3); min-height: 64px; padding: 9px 0;
  border-bottom: 1px solid var(--rule);
  text-decoration: none; color: inherit; position: relative;
  -webkit-tap-highlight-color: transparent;
}
a.rk:hover { background: color-mix(in srgb, var(--bg-2) 60%, transparent); }
.rk.is-fav::before {
  content: ""; position: absolute; left: calc(var(--gutter) * -1); top: 8px; bottom: 8px; width: 3px;
  background: var(--signal); border-radius: 0 2px 2px 0;
}
.rk.is-flash { animation: flash 1.6s var(--ease); }
@keyframes flash { 0% { background: color-mix(in srgb, var(--signal) 55%, transparent); } 100% { background: transparent; } }
.rk-pos {
  font-family: var(--font-display); font-weight: 800; font-size: 1.55rem; line-height: 1; text-align: right;
  font-variant-numeric: tabular-nums;
}
.rk-pos small { display: block; font-family: var(--font-text); font-size: .64rem; font-weight: 600; color: var(--muted); margin-top: 2px; }
.rk-pos--dim { color: var(--faint); }
.rk-plate { justify-self: start; }
.rk-crew { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.rk-name {
  display: flex; align-items: flex-start; gap: 6px; min-width: 0;
  font-weight: 700; font-size: .95rem; line-height: 1.2;
}
/* Com nomes em duas linhas, a bandeira acompanha a primeira linha. */
.rk-name > .flag { margin-top: 3px; }
.rk-co > .flag { margin-top: 3px; }
.rk-name span { overflow-wrap: break-word; }
.rk-co { display: flex; align-items: flex-start; gap: 6px; color: var(--ink-2); font-size: .84rem; min-width: 0; }
.rk-co span { overflow-wrap: break-word; }
.rk-car {
  color: var(--muted); font-size: .74rem; font-stretch: 85%; text-transform: uppercase; letter-spacing: .02em;
  overflow-wrap: break-word;
}
.rk-time { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.rk-t { font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rk-gap { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rk-extra { grid-column: 3 / -1; display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 6px; }
.delta { font-size: .72rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta--up { color: var(--green); }
.delta--down { color: var(--red); }

/* Linhas de parciais */
.splits { display: flex; gap: 4px; flex-wrap: wrap; }
.split {
  display: inline-flex; align-items: baseline; gap: 4px; padding: 2px 6px;
  border-radius: var(--r1); background: var(--bg-2); font-size: .72rem; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.split b { font-weight: 800; color: var(--muted); }
.split i { font-style: normal; color: var(--muted); }
.split--best { background: var(--signal); color: var(--signal-ink); }
.split--best b, .split--best i { color: var(--signal-ink); }

/* Relógio a correr */
.running { font-weight: 700; font-variant-numeric: tabular-nums; }
.running::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--red); margin-right: 6px; vertical-align: 2px; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

/* Barra de progresso */
.bar { height: 4px; background: var(--bg-2); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ink); border-radius: 2px; width: var(--p, 0%); transition: width .8s var(--ease); }
.bar--signal > i { background: var(--signal); }

/* Folhas (blocos de conteúdo) */
.sheet { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r2); }
.sheet-pad { padding: var(--s4); }

/* Pares chave/valor */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--r2); overflow: hidden; }
.kv > div { background: var(--surface); padding: 12px 14px; min-width: 0; }
.kv dt { font-size: .7rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.kv dd { font-weight: 700; font-size: 1.05rem; margin-top: 2px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.kv dd small { font-weight: 500; color: var(--muted); font-size: .8rem; }

/* Números-resumo */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--r2); overflow: hidden; }
.stat { background: var(--surface); padding: 14px 14px 12px; text-decoration: none; color: inherit; }
a.stat:hover { background: var(--bg-2); }
.stat b { display: block; font-family: var(--font-display); font-weight: 800; font-size: 2.1rem; line-height: 1; font-variant-numeric: tabular-nums; }
.stat span { display: block; font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.stat--alert b { color: var(--red); }

/* Estado vazio */
.empty { padding: var(--s6) var(--s4); text-align: center; color: var(--muted); border: 1px dashed var(--rule-2); border-radius: var(--r2); }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }
.empty .btn { margin-top: var(--s4); }

/* Esqueleto de carregamento */
.skel { border-radius: var(--r1); background: linear-gradient(90deg, var(--bg-2) 0%, color-mix(in srgb, var(--bg-2) 40%, var(--surface)) 50%, var(--bg-2) 100%); background-size: 200% 100%; animation: skel 1.3s linear infinite; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skel-row { height: 64px; margin-bottom: 1px; }
.skel-board { height: 260px; border-radius: var(--r2); margin-top: var(--s4); }

/* Pesquisa */
.search { position: relative; }
.search input {
  width: 100%; height: 46px; padding: 0 44px 0 42px;
  border: 1.5px solid var(--rule-2); border-radius: var(--r2); background: var(--surface);
  font-size: 1rem;
}
.search input:focus { outline: none; border-color: var(--ink); }
.search > .i { position: absolute; left: 13px; top: 13px; color: var(--muted); width: 20px; height: 20px; }
.search-clear { position: absolute; right: 4px; top: 3px; }

/* Barra de filtros */
.filters { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s3) 0; }
.filters-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.select {
  height: 36px; padding: 0 30px 0 12px; border-radius: var(--r2);
  border: 1px solid var(--rule-2); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23888' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 10px center;
  -webkit-appearance: none; appearance: none; font-size: .86rem; font-weight: 600;
}
.sticky-tools {
  position: sticky; top: var(--appbar-h); z-index: 20;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter);
  border-bottom: 1px solid var(--rule);
}
.updated { font-size: .78rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.updated button { border: 0; background: none; padding: 4px; color: var(--ink); border-radius: var(--r1); }
.updated button .i { width: 16px; height: 16px; }
.updated.is-loading button .i { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 6b. Cabeçalhos de PEC, ferramentas e variantes de linhas ---------- */
.stage-head { padding: var(--s5) 0 var(--s2); }
.stage-head-top { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; min-height: 34px; margin-bottom: var(--s3); }
.stage-head-top:empty { display: none; }
.stage-head .view-title { font-size: clamp(2rem, 9vw, 3rem); }
.tools-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s4); }
.tools-spacer { flex: 1; }
.seg a {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  border-radius: 4px; height: 34px; padding: 0 16px; font-size: .86rem; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.seg a[aria-current="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.rk-pos .pulse { display: inline-block; margin-right: 6px; }
.rk.is-running { background: color-mix(in srgb, var(--signal) 10%, transparent); }
.rk-progress { display: flex; flex-wrap: wrap; gap: 4px var(--s3); align-items: center; font-size: .74rem; color: var(--muted); }
.rk-progress .bar { height: 5px; flex: 1 1 120px; }
/* Tempos → mapa */
.stage-head-map { margin-left: auto; }
.rk-maplink {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 4px;
  font-size: .76rem; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.rk-maplink:hover { text-decoration: underline; }
.rk-maplink .i { width: 15px; height: 15px; }
.rk.is-running:hover { background: color-mix(in srgb, var(--signal) 18%, transparent); }

/* Variantes com dupla classe: a regra base .rk é redefinida mais abaixo (ecrãs largos) e, com a
   mesma especificidade, venceria por ordem — o que deixaria estas linhas com as colunas erradas. */
.rk.rk--start { grid-template-columns: 3.1rem 3.1rem minmax(0, 1fr) auto; }
.rk-pos.rk-pos--time { font-family: var(--font-text); font-size: .95rem; font-weight: 800; text-align: left; }

.rk.rk--entry { grid-template-columns: 3.1rem minmax(0, 1fr) auto; }
.rk--entry .rk-extra { grid-column: 2 / -1; }
.rk-link { text-decoration: none; color: inherit; min-width: 0; }
.rk-link::after { content: ""; position: absolute; inset: 0; }
.rk--entry:hover { background: color-mix(in srgb, var(--bg-2) 60%, transparent); }
.fav-star { position: relative; z-index: 1; color: var(--faint); }
.fav-star[aria-pressed="true"] { color: var(--ink); }
.fav-star[aria-pressed="true"] .i { fill: var(--signal); stroke: var(--ink); }

.crew-photo-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); }
.crew-photo-empty .i { width: 40%; height: 40%; stroke-width: 1; }

/* ---------- 7. Placa da PEC (destaque da página inicial) ---------- */
.board {
  position: relative; margin-top: var(--s4);
  border-radius: var(--r2); overflow: hidden;
  background: var(--surface); border: 2px solid var(--ink); color: var(--ink);
}
.board--live { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.board--done { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.board-top {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: 9px var(--s4); background: var(--ink); color: var(--bg);
  font-size: .74rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
}
.board--done .board-top { background: var(--bg); color: var(--ink); }
.board-top span { display: inline-flex; align-items: center; gap: 8px; }
.board-top .board-tabs { gap: 6px; margin-left: var(--s2); flex-wrap: wrap; }
.board-tab {
  height: 30px; min-width: 3.2em; padding: 0 10px; border-radius: var(--r1); cursor: pointer;
  border: 1.5px solid color-mix(in srgb, var(--bg) 40%, transparent); background: transparent; color: var(--bg);
  font-family: var(--font-display); font-weight: 800; font-size: 1rem; letter-spacing: .02em;
}
.board-tab:hover { border-color: var(--bg); }
.board-tab[aria-pressed="true"] { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.board-body { padding: var(--s4) var(--s4) var(--s5); }
.board-code {
  font-family: var(--font-display); font-weight: 900; text-transform: uppercase;
  font-size: clamp(4.6rem, 27vw, 8.5rem); line-height: .8; letter-spacing: -.01em;
}
.board-name {
  font-family: var(--font-display); font-weight: 800; text-transform: uppercase;
  font-size: clamp(1.5rem, 7vw, 2.4rem); line-height: 1; margin-top: var(--s2);
}
.board-when { margin-top: var(--s2); font-weight: 600; font-size: .95rem; }
.board-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: var(--s5); border-top: 2px solid currentColor; }
.board-meta--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* Ecrãs estreitos: quatro valores em duas linhas, para os rótulos não serem cortados. */
@media (max-width: 519px) {
  .board-meta--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: var(--s3); }
  .board-meta.board-meta--4 > div:nth-child(odd) { padding-left: 0; border-left: 0; }
}
.board-meta > div { padding: 10px 8px 0 0; min-width: 0; }
.board-meta > div + div { padding-left: 10px; border-left: 1px solid color-mix(in srgb, currentColor 30%, transparent); }
.board-meta dt { font-size: .66rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; opacity: .75; }
.board-meta dd { font-family: var(--font-display); font-weight: 800; font-size: 1.7rem; line-height: 1.05; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-meta dd small { font-size: .55em; margin-left: 3px; text-transform: uppercase; }
.board-cta { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s5); }
.board--live .btn { border-color: var(--signal-ink); color: var(--signal-ink); }
.board--live .btn--primary { background: var(--signal-ink); color: var(--signal); }
.board--done .btn { border-color: var(--bg); color: var(--bg); }
.board--done .btn:hover { background: color-mix(in srgb, var(--bg) 12%, transparent); }
.board--done .btn--primary { background: var(--bg); color: var(--ink); }
.board-countdown {
  font-family: var(--font-display); font-weight: 800; font-size: clamp(2.6rem, 13vw, 4rem);
  line-height: 1; font-variant-numeric: tabular-nums; margin-top: var(--s4); letter-spacing: .01em;
}
.board-countdown small { display: block; font-family: var(--font-text); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; opacity: .7; margin-bottom: 4px; }
.board-leader { margin-top: var(--s4); display: flex; align-items: center; gap: var(--s3); font-weight: 600; }
.board-leader .plate { border-color: var(--signal-ink); }

/* ---------- 8. Faixa de progresso na PEC ---------- */
.strip { padding: var(--s4) 0 var(--s2); }
.strip-track { position: relative; height: 56px; margin: 0 14px; }
.strip-line { position: absolute; left: 0; right: 0; top: 34px; height: 4px; background: var(--ink); border-radius: 2px; }
.strip-tick { position: absolute; top: 28px; width: 2px; height: 16px; background: var(--ink); transform: translateX(-1px); }
.strip-tick span { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font-size: .64rem; font-weight: 800; color: var(--muted); white-space: nowrap; }
.strip-end { position: absolute; top: 24px; width: 12px; height: 24px; transform: translateX(-6px); }
.strip-end--start { left: 0; background: var(--green); border-radius: 2px; }
.strip-end--finish { left: 100%; background-image: conic-gradient(var(--ink) 25%, var(--bg) 0 50%, var(--ink) 0 75%, var(--bg) 0); background-size: 8px 8px; border: 1px solid var(--ink); border-radius: 2px; }
.strip-car {
  position: absolute; top: 0; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; transition: left 1s linear;
}
.strip-car .plate { font-size: .82rem; height: 22px; min-width: 2.2em; }
.strip-car::after { content: ""; width: 2px; height: var(--stem, 10px); background: var(--ink); }
.strip-car.is-fav .plate { background: var(--signal); }
.strip-legend { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin: 18px 14px 0; font-variant-numeric: tabular-nums; }

/* ---------- 9. Programa (road-book) ---------- */
.sched-day { margin-top: var(--s5); }
.sched-day-h { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding-bottom: var(--s2); border-bottom: 2px solid var(--ink); }
.sched-day-h h3 { font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; text-transform: uppercase; }
.sched-day-h span { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.sched-row {
  display: grid; grid-template-columns: 3.6rem minmax(0, 1fr) auto; gap: var(--s3); align-items: center;
  padding: 12px var(--s3); border-bottom: 1px solid var(--rule); text-decoration: none; color: inherit; position: relative;
}
.sched-row:hover { background: color-mix(in srgb, var(--bg-2) 60%, transparent); }
.sched-time { font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.sched-time small { display: block; font-size: .68rem; font-weight: 600; color: var(--muted); }
.sched-main { min-width: 0; }
.sched-title { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.sched-name { font-weight: 700; text-transform: uppercase; font-stretch: 88%; letter-spacing: .01em; }
.sched-meta { font-size: .8rem; color: var(--muted); margin-top: 2px; display: flex; gap: var(--s2); flex-wrap: wrap; }
.sched-km { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sched-km small { display: block; font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.sched-row.is-live { background: color-mix(in srgb, var(--signal) 22%, transparent); }
.sched-row.is-live::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--signal); }
.sched-row.is-done .sched-name, .sched-row.is-done .sched-time { color: var(--muted); }

/* ---------- 10. Ficha de equipa ---------- */
.crew-hero { display: grid; gap: var(--s4); padding-top: var(--s5); }
.crew-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.crew-names h1 { font-family: var(--font-display); font-weight: 800; text-transform: uppercase; font-size: clamp(1.9rem, 8.5vw, 2.8rem); line-height: .95; }
.crew-names h1 + p { margin-top: 6px; font-size: 1.05rem; font-weight: 600; color: var(--ink-2); }
.crew-person { display: flex; align-items: center; gap: 8px; }
.crew-photos { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.crew-photo { position: relative; margin: 0; aspect-ratio: 4 / 5; background: linear-gradient(180deg, var(--bg-2), var(--surface)); border-radius: var(--r2); overflow: hidden; border: 1px solid var(--rule); }
.crew-photo > img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.crew-photo figcaption { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 10px 8px; background: linear-gradient(transparent, rgba(0,0,0,.72)); color: #fff; font-size: .78rem; font-weight: 700; display: flex; gap: 6px; align-items: center; }
.crew-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.fav-btn[aria-pressed="true"] { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.fav-btn[aria-pressed="true"] .i { fill: currentColor; }

/* Tabela de resultados por PEC */
.res-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.res-table th { text-align: left; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 800; padding: 8px 6px; border-bottom: 2px solid var(--ink); white-space: nowrap; }
.res-table td { padding: 10px 6px; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; vertical-align: middle; }
.res-table td.r, .res-table th.r { text-align: right; }
.res-table .pos { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; }
.res-table a { text-decoration: none; }
.table-scroll { overflow-x: auto; margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter); }

/* ---------- 11. Meteorologia ---------- */
.wx { display: grid; grid-template-columns: auto 1fr; gap: var(--s2) var(--s4); align-items: center; padding: var(--s4); }
.wx-icon { width: 56px; height: 56px; }
.wx-temp { font-family: var(--font-display); font-weight: 800; font-size: 3rem; line-height: 1; font-variant-numeric: tabular-nums; }
.wx-desc { font-weight: 600; text-transform: lowercase; }
.wx-desc::first-letter { text-transform: uppercase; }
.wx-place { color: var(--muted); font-size: .84rem; }
.wx-grid { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); border-top: 1px solid var(--rule); padding-top: var(--s3); margin-top: var(--s1); }
.wx-grid div { font-size: .8rem; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.wx-grid b { color: var(--ink); font-size: .95rem; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; }
.wind-arrow { display: inline-block; transition: transform .3s; }

/* ---------- 12. Listas genéricas ---------- */
.list-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s3); align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--rule); text-decoration: none; color: inherit;
}
.list-row:first-child { border-top: 1px solid var(--rule); }
.list-row-title, .list-row-sub, .list-row-text { display: block; }
.list-row-title { font-weight: 700; }
.list-row-sub { font-size: .84rem; color: var(--muted); margin-top: 2px; }
.list-row-text { font-size: .88rem; color: var(--ink-2); margin-top: 6px; white-space: pre-line; }
.list-row .i-chev { color: var(--faint); }

.more-list a {
  display: grid; grid-template-columns: 28px 1fr auto; gap: var(--s3); align-items: center;
  padding: 16px 0; border-bottom: 1px solid var(--rule); text-decoration: none; font-weight: 700; font-size: 1.05rem;
}
.more-list a:first-child { border-top: 1px solid var(--rule); }
.more-list a small { display: block; font-weight: 500; font-size: .82rem; color: var(--muted); }
.more-list .i { width: 24px; height: 24px; }
.more-list .i-chev { color: var(--faint); width: 20px; height: 20px; }

.prose { max-width: 68ch; }
.prose p + p { margin-top: var(--s3); }
.info-block { padding: var(--s4); }
.info-block h3 { font-size: 1.05rem; margin-bottom: 6px; }
.info-block p { white-space: pre-line; color: var(--ink-2); font-size: .94rem; }
.info-block a { display: inline-flex; margin-top: var(--s3); font-weight: 700; }
.grid-auto { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Barras de estatística */
.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(0, 7.5rem) 1fr 2.2rem; gap: var(--s2); align-items: center; font-size: .84rem; }
.hbar span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.hbar .bar { height: 10px; border-radius: 2px; }
.hbar .bar > i { border-radius: 2px; }
.hbar b { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 13. Mapa ---------- */
.view--map { position: fixed; left: 0; right: 0; top: var(--appbar-h); bottom: calc(var(--tabbar-h) + var(--safe-b)); animation: none; }
.map-canvas { position: absolute; inset: 0; background: var(--bg-2); }
/* PEC e mensagens à esquerda dos botões do mapa (a mensagem fica sempre por baixo das PEC). */
.map-top { position: absolute; left: 0; right: 64px; top: 0; z-index: 500; padding: 10px 0 0; pointer-events: none; }
.map-top .chips { pointer-events: auto; margin: 0; padding: 0 12px; }
.map-top .chip { box-shadow: var(--shadow); }
.map-fabs { position: absolute; right: 12px; top: 10px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.fab {
  width: 44px; height: 44px; border-radius: var(--r2); border: 1px solid var(--rule-2);
  background: var(--surface); color: var(--ink); display: grid; place-items: center; box-shadow: var(--shadow);
}
.fab[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.fab .i { width: 22px; height: 22px; }
.map-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 600;
  background: var(--surface); border-top: 1px solid var(--rule-2);
  border-radius: 14px 14px 0 0; box-shadow: 0 -10px 30px -14px rgba(0,0,0,.35);
  max-height: 34%; display: flex; flex-direction: column; transition: max-height .3s var(--ease);
}
.map-sheet.is-open { max-height: 72%; }
.map-sheet-h {
  display: flex; align-items: center; gap: var(--s3); padding: 6px var(--gutter) 10px; border: 0; background: none; width: 100%; text-align: left;
}
.map-sheet-h::before { content: ""; position: absolute; left: 50%; top: 6px; width: 38px; height: 4px; border-radius: 2px; background: var(--rule-2); transform: translateX(-50%); }
.map-sheet-h { position: relative; padding-top: 18px; }
.map-sheet-title { flex: 1; min-width: 0; }
.map-sheet-title strong { display: block; font-size: 1rem; }
.map-sheet-title span { font-size: .8rem; color: var(--muted); }
.map-sheet-body { overflow-y: auto; padding: 0 var(--gutter) var(--s4); -webkit-overflow-scrolling: touch; }
.mcar {
  display: grid; grid-template-columns: 3.1rem minmax(0, 1fr) auto; gap: var(--s3); align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--rule); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left;
}
.mcar-main { min-width: 0; }
.mcar-main > span { display: block; }
a.mcar { text-decoration: none; color: inherit; }
a.mcar:hover, button.mcar:hover { background: color-mix(in srgb, var(--bg-2) 60%, transparent); }
.mcar--rank { grid-template-columns: 1.6rem 2.9rem minmax(0, 1fr) auto; position: relative; }
.mcar--rank.is-fav::before { content: ""; position: absolute; left: calc(var(--gutter) * -1); top: 4px; bottom: 4px; width: 3px; background: var(--signal); border-radius: 0 2px 2px 0; }
.mcar-pos { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; text-align: right; font-variant-numeric: tabular-nums; }
.mcar .splits { margin-top: 5px; }
.mcar .split { font-size: .68rem; padding: 1px 5px; }
/* Separador de secção dentro do painel do mapa */
.sheet-sec {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  position: sticky; top: 0; z-index: 1; margin: 0 0 2px;
  padding: 10px 0 6px; background: var(--surface); border-bottom: 1px solid var(--rule);
  font-size: .68rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; color: var(--muted);
}
.sheet-sec b { color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: 0; }
.btn--block { width: 100%; }
.mcar-name { font-weight: 700; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcar-sub { font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.mcar .bar { margin-top: 6px; }
.mcar-right { text-align: right; font-size: .8rem; font-variant-numeric: tabular-nums; }
.mcar-right b { display: block; font-size: .95rem; }

/* Marcadores Leaflet */
.leaflet-container { font-family: var(--font-text); background: var(--bg-2); }
.tiles-street { filter: var(--map-filter); }
.leaflet-control-attribution { font-size: 10px; background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-control-zoom { display: none; }
.car-mk { position: relative; width: 34px; height: 24px; }
.car-mk .plate {
  position: absolute; inset: 0; font-size: .8rem; height: 22px; min-width: 32px;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.car-mk.is-race .plate { background: var(--signal); border-color: #131311; color: #131311; }
.car-mk.is-stale { opacity: .45; }
.car-mk.is-fav .plate { box-shadow: 0 0 0 2px var(--signal), 0 2px 6px rgba(0,0,0,.35); }
.car-mk .dirwrap { position: absolute; inset: -12px -4px; pointer-events: none; }
.car-mk .dir {
  position: absolute; left: 50%; top: 0; width: 0; height: 0; margin-left: -5px;
  border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 8px solid #131311;
  filter: drop-shadow(0 0 1px #fff);
}
.map-anim .mk-car { transition: transform 1s linear; }
.car-dot { width: 12px; height: 12px; border-radius: 50%; background: #131311; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.45); }
.car-dot.is-stale { opacity: .55; }
.pt-mk {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 900; font-size: .85rem; color: #fff;
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.pt-mk--start { background: var(--green); }
.pt-mk--finish { background-color: #131311; background-image: conic-gradient(#131311 25%, #fff 0 50%, #131311 0 75%, #fff 0); background-size: 10px 10px; }
.pt-mk--split { width: 24px; height: 22px; border-radius: 4px; background: #131311; font-family: var(--font-text); font-weight: 800; font-size: .66rem; letter-spacing: -.02em; }
.poi-mk {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: #131311; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); display: grid; place-items: center;
}
.poi-mk svg { transform: rotate(45deg); width: 16px; height: 16px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.poi-mk--spectator { background: #1f5fcc; }
.poi-mk--service { background: #131311; }
.poi-mk--medical { background: var(--red); }
.poi-mk--podium, .poi-mk--hq { background: #7a4dd1; }
.poi-mk--regroup, .poi-mk--refuel, .poi-mk--parking { background: #11804a; }
/* Etiquetas dos troços (posicionadas por maplabels.js, sempre fora dos traçados) */
.ss-label {
  position: absolute; display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 7px; white-space: nowrap; cursor: pointer;
  background: #fff; color: #131311; border: 1.5px solid #131311; border-radius: 3px;
  font-family: var(--font-text); font-weight: 700; font-size: .7rem; letter-spacing: .02em; line-height: 1;
  box-shadow: 0 2px 6px rgba(0,0,0,.22);
}
.ss-label b { font-family: var(--font-display); font-weight: 800; font-size: .95rem; letter-spacing: .02em; }
.ss-label.is-sel { background: var(--signal); }
.ss-label--probe { left: -9999px; top: -9999px; visibility: hidden; pointer-events: none; }
.ss-leader { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.ss-leader line { stroke: #131311; stroke-width: 1.5; }
.mk-label { overflow: visible; }
.leaflet-popup-content-wrapper { border-radius: var(--r2); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 12px 14px; font-size: .88rem; line-height: 1.4; }
.pop-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.pop-h strong { font-size: .95rem; }
.pop-meta { color: var(--muted); font-size: .8rem; }
.pop-link { display: inline-block; margin-top: 8px; font-weight: 700; }
.map-msg { margin: 8px 12px 0; }
.map-msg:empty { display: none; }

/* Avisos de chegada à meta (PEC selecionada) */
.toasts {
  position: absolute; left: 12px; right: 12px; z-index: 650;
  bottom: calc(var(--sheet-h, 120px) + 10px);
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--s3); align-items: center; width: 100%; text-align: left;
  padding: 9px 12px; border: 1.5px solid var(--ink); border-radius: var(--r2);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  animation: toastIn .28s var(--ease) both;
}
.toast.is-out { animation: toastOut .26s var(--ease) both; }
.toast .plate { font-size: .95rem; height: 1.6em; }
.toast-main { min-width: 0; }
.toast-main strong { display: block; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-main span { display: block; font-size: .76rem; color: var(--muted); }
.toast-time { text-align: right; font-weight: 800; font-size: 1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.toast-time small { display: block; font-weight: 600; font-size: .74rem; color: var(--muted); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
.map-msg div { display: inline-block; background: var(--surface); border: 1px solid var(--rule-2); border-radius: var(--r2); padding: 8px 12px; font-size: .82rem; box-shadow: var(--shadow); }
.minimap { height: 300px; border-radius: var(--r2); overflow: hidden; border: 1px solid var(--rule); background: var(--bg-2); }

/* ---------- 14. Página inicial ---------- */
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--s6); }
.home-grid > *, .split-2 > * { min-width: 0; }
.leader-row { display: flex; align-items: center; gap: var(--s3); }
.podium { display: grid; gap: 0; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.quick a {
  display: flex; flex-direction: column; gap: 10px; padding: 14px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r2); font-weight: 700;
}
.quick a:hover { border-color: var(--ink); }
.quick a small { font-weight: 500; color: var(--muted); font-size: .78rem; }
.quick .i { width: 24px; height: 24px; }
.event-hero { padding: var(--s5) 0 0; display: flex; align-items: center; gap: var(--s4); }
.event-hero-text { min-width: 0; }
/* Placa da prova: JPEG com fundo branco, por isso o cartão é branco também no tema escuro. */
.event-plate { flex: none; margin: 0; padding: 6px; background: #fff; border: 1px solid var(--rule); border-radius: var(--r2); }
.event-plate img { height: 60px; width: auto; max-width: 112px; object-fit: contain; }
@media (min-width: 720px) {
  .event-hero { gap: var(--s5); }
  .event-plate { padding: 10px; }
  .event-plate img { height: 104px; max-width: 220px; }
}
.event-plate--info { display: inline-block; margin-bottom: var(--s4); padding: 10px; }
.event-plate--info img { height: 96px; max-width: 220px; }
.event-hero h1 { font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: clamp(2.3rem, 11vw, 4.4rem); line-height: .9; letter-spacing: -.005em; }
.event-hero p { margin-top: var(--s2); color: var(--muted); font-weight: 600; display: flex; flex-wrap: wrap; gap: 4px 12px; }
/* Telemóvel: a placa da prova em destaque, a toda a largura; o nome por baixo, mais pequeno. */
@media (max-width: 719px) {
  .event-hero { flex-direction: column; align-items: stretch; gap: var(--s3); }
  .event-hero .event-plate { display: flex; justify-content: center; padding: 14px; }
  .event-hero .event-plate img { height: 132px; max-width: 100%; }
  .event-hero h1 { font-size: clamp(1.6rem, 7.5vw, 2rem); line-height: .95; }
}

/* ---------- 15. Ecrãs maiores ---------- */
@media (min-width: 720px) {
  :root { --gutter: 28px; }
  .rk { grid-template-columns: 2.6rem 3.4rem minmax(0, 1fr) auto; min-height: 60px; }
  .rk-pos { font-size: 1.7rem; }
  .crew-hero { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .crew-photos { grid-row: span 3; grid-column: 2; }
  .quick { grid-template-columns: repeat(4, 1fr); }
  /* Painel com toda a altura do mapa; as PEC, os botões e as mensagens ficam à esquerda dele. */
  .map-sheet { left: auto; right: 12px; bottom: 12px; top: 12px; width: 360px; max-height: none; border-radius: var(--r2); border: 1px solid var(--rule-2); }
  .map-sheet.is-open { max-height: none; }
  .map-sheet-h::before { display: none; }
  .map-sheet-h > .i:last-child { display: none; }
  .map-sheet-h { padding-top: 12px; }
  .map-fabs { right: 384px; }
  .map-top { right: 440px; }
  .toasts { right: auto; width: 350px; bottom: 12px; }

  .netbar { bottom: 24px; }
}

@media (min-width: 1080px) {
  :root { --tabbar-h: 0px; }
  .tabbar { display: none; }
  .topnav {
    display: block; border-bottom: 1px solid var(--rule); background: var(--bg);
    position: sticky; top: var(--appbar-h); z-index: 45;
  }
  .topnav ul { max-width: 1240px; margin: 0 auto; padding: 0 var(--gutter); display: flex; gap: var(--s1); }
  .topnav a {
    display: inline-flex; align-items: center; gap: 8px; height: 46px; padding: 0 12px;
    text-decoration: none; font-weight: 700; font-size: .9rem; color: var(--muted); position: relative; white-space: nowrap;
  }
  .topnav a:hover { color: var(--ink); }
  .topnav a[aria-current="page"] { color: var(--ink); }
  .topnav a[aria-current="page"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 3px; background: var(--signal); }
  .topnav .i { width: 18px; height: 18px; }
  .sticky-tools { top: calc(var(--appbar-h) + 47px); }
  .view--map { top: calc(var(--appbar-h) + 47px); bottom: 0; }
  .home-grid { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; }
  .home-grid > .home-side { position: sticky; top: calc(var(--appbar-h) + 64px); }
  .board-code { font-size: 8.5rem; }
  .split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s6); }
}

/* Ecrãs entre 1080 e 1279 px: menu sem ícones para caber numa só linha, sem scroll */
@media (min-width: 1080px) and (max-width: 1279px) {
  .topnav ul { gap: 0; }
  .topnav a { padding: 0 10px; }
  .topnav a[aria-current="page"]::after { left: 10px; right: 10px; }
  .topnav .i { display: none; }
}

/* ---------- 16. Movimento reduzido e impressão ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media print {
  .appbar, .tabbar, .topnav, .ticker, .netbar, .footer, .sticky-tools, .btn { display: none !important; }
  body { background: #fff; color: #000; }
  .main { padding: 0; }
}
