/* Kart Entre Amigos — dark race-night theme (dark-only por decisão de design) */
@font-face {
  font-family: 'Racing Sans One';
  src: url('/fonts/racing-sans-one.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #0d0f14;
  --surface: #171a21;
  --surface-2: #1e222c;
  --ink: #f2f3f5;
  --ink-2: #a8adb8;
  --muted: #7c8391;
  --grid: #262b36;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #e8352e;
  --accent-2: #f5b301;
  --gold: #f5b301;
  --silver: #c0c6d1;
  --bronze: #cd7f45;
  --good: #0ca30c;
  --error: #d03b3b;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --display: 'Racing Sans One', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px 48px; }

/* ---------- header ---------- */
header.top {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(180deg, rgba(13,15,20,.97) 75%, rgba(13,15,20,0));
  padding: calc(10px + env(safe-area-inset-top)) 0 14px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  max-width: 720px; margin: 0 auto; padding: 0 16px;
}
.brand h1 {
  font-family: var(--display);
  font-size: 1.35rem; margin: 0; letter-spacing: .5px; font-weight: 400;
}
.brand h1 em { font-style: normal; color: var(--accent); }
.brand .flag { font-size: 1.4rem; }
.brand a.adm {
  margin-left: auto; color: var(--muted); text-decoration: none; font-size: 1.2rem;
  padding: 6px; border-radius: 8px;
}
.brand a.adm:active { background: var(--surface-2); }

/* faixa quadriculada */
.checker {
  height: 6px; margin-top: 8px; opacity: .5;
  background:
    repeating-conic-gradient(#fff 0% 25%, transparent 0% 50%) 0 0 / 12px 12px;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 20% 80%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 20% 80%, transparent);
}

/* ---------- seletor ---------- */
.controls { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 20px; }
select.race-select {
  width: 100%;
  appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%23a8adb8' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat right 14px center;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 40px 13px 14px;
  font-size: 1rem; font-weight: 600;
}
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 15px; font-size: .85rem; font-weight: 600; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- pódio ---------- */
.podium-card {
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(232,53,46,.14), transparent 55%),
    var(--surface);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 22px 12px 0; overflow: hidden; position: relative;
}
.podium-title {
  text-align: center; font-size: .78rem; letter-spacing: 2.5px;
  text-transform: uppercase; color: var(--muted); margin: 0 0 6px;
}
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 8px; }
.pod { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.pod .ava {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-size: 1.5rem; color: #fff;
  background: var(--surface-2); overflow: hidden; flex-shrink: 0;
  border: 3px solid var(--grid);
  box-shadow: 0 4px 18px rgba(0,0,0,.45);
}
.pod .ava img { width: 100%; height: 100%; object-fit: cover; }
.pod.p1 .ava { width: 84px; height: 84px; border-color: var(--gold); }
.pod.p2 .ava { border-color: var(--silver); }
.pod.p3 .ava { border-color: var(--bronze); }
.pod .crown { font-size: 1.3rem; height: 1.5rem; margin-bottom: -4px; }
.pod .name {
  font-family: var(--display); font-weight: 400; font-size: .92rem; margin-top: 8px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: center;
}
.pod.p1 .name { font-size: 1.05rem; }
.pod .sub { font-size: .78rem; color: var(--ink-2); margin-top: 1px; }
.pod .sub b { color: var(--accent-2); font-weight: 700; }
.pod .block {
  margin-top: 10px; width: 100%; border-radius: 10px 10px 0 0;
  display: flex; align-items: flex-start; justify-content: center;
  font-family: var(--display); font-size: 1.6rem; padding-top: 8px;
  color: rgba(255,255,255,.85);
  animation: rise .55s cubic-bezier(.2,.8,.3,1) both;
  transform-origin: bottom;
}
.pod.p1 .block { height: 86px; background: linear-gradient(180deg, #8a6a00, #4d3c05); animation-delay: .25s; }
.pod.p2 .block { height: 60px; background: linear-gradient(180deg, #4c5566, #2b303c); animation-delay: .1s; }
.pod.p3 .block { height: 44px; background: linear-gradient(180deg, #7a4a22, #40270f); animation-delay: .4s; }
@keyframes rise { from { transform: scaleY(0); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .pod .block { animation: none; } }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px 14px 12px; min-width: 0;
}
.tile .lbl { font-size: .72rem; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.tile .val {
  font-family: var(--display); font-size: 1.55rem; margin-top: 4px; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .val small { font-size: .95rem; color: var(--ink-2); }
.tile .who { font-size: .8rem; color: var(--ink-2); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.hot .val { color: var(--accent-2); }

/* ---------- seções / cards ---------- */
section.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px; margin-top: 16px;
}
section.card h2 {
  font-size: .8rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--muted); margin: 0 0 12px; font-weight: 600;
}

/* ---------- tabelas ---------- */
.tbl-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; min-width: 480px; font-size: .875rem; }
th {
  text-align: left; color: var(--muted); font-size: .7rem; letter-spacing: 1px;
  text-transform: uppercase; font-weight: 600; padding: 6px 8px;
  border-bottom: 1px solid var(--grid); white-space: nowrap;
}
td { padding: 9px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 8px;
  font-family: var(--display); font-size: .95rem;
  background: var(--surface-2); color: var(--ink-2);
}
.pos-badge.g { background: rgba(245,179,1,.18); color: var(--gold); }
.pos-badge.s { background: rgba(192,198,209,.15); color: var(--silver); }
.pos-badge.b { background: rgba(205,127,69,.16); color: var(--bronze); }
.pilot-cell { display: flex; align-items: center; gap: 9px; min-width: 0; }
.mini-ava {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; color: #fff; overflow: hidden;
  background: var(--surface-2);
}
.mini-ava img { width: 100%; height: 100%; object-fit: cover; }
.pilot-cell .nm { overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.pilot-cell .kn { color: var(--muted); font-size: .75rem; }
.pts { font-family: var(--display); font-size: 1.05rem; color: var(--accent-2); }
.lapbar { display: flex; align-items: center; gap: 8px; }
.lapbar .bar {
  height: 4px; border-radius: 4px 4px 4px 0; background: var(--s1);
  min-width: 3px;
}
.flag-chip { font-size: .78rem; }
.best-tag { color: var(--accent-2); font-size: .72rem; margin-left: 5px; }

/* ---------- gráfico ---------- */
.chart-box { position: relative; }
.chart-box svg { display: block; width: 100%; height: auto; font-family: var(--sans); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; }
.legend .li { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--ink-2); }
.legend .sw { width: 14px; height: 3px; border-radius: 2px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 20;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: .78rem;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); display: none; min-width: 140px;
}
.tooltip .t { color: var(--muted); margin-bottom: 4px; font-size: .7rem; }
.tooltip .row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.tooltip .row .sw { width: 8px; height: 8px; border-radius: 50%; }
.tooltip .row .v { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ---------- observações ---------- */
.obs-list { margin: 0; padding: 0; list-style: none; }
.obs-list li {
  padding: 9px 0 9px 26px; position: relative; font-size: .85rem;
  color: var(--ink-2); border-bottom: 1px solid var(--grid);
}
.obs-list li:last-child { border-bottom: 0; }
.obs-list li::before { content: '🏴'; position: absolute; left: 0; top: 8px; font-size: .85rem; }

/* ---------- perfil do piloto ---------- */
.backrow { margin-bottom: 10px; }
.profile { display: flex; align-items: center; gap: 16px; }
.ava-big {
  width: 84px; height: 84px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-size: 1.8rem; color: #fff;
  background: var(--surface-2); overflow: hidden; border: 3px solid var(--accent);
  box-shadow: 0 4px 18px rgba(0,0,0,.45);
}
.ava-big img { width: 100%; height: 100%; object-fit: cover; }
.pinfo { min-width: 0; }
.pname { font-family: var(--display); font-size: 1.35rem; line-height: 1.15; }
.pmeta { color: var(--muted); font-size: .85rem; margin-top: 3px; }
.field-size { color: var(--muted); font-size: .72rem; margin-left: 2px; }
[data-pilot] { cursor: pointer; }
tr[data-race] { cursor: pointer; }
tr[data-pilot]:hover td, tr[data-race]:hover td { background: rgba(255,255,255,.03); }

/* ---------- FAQ / notas ---------- */
.score-note {
  color: var(--muted); font-size: .78rem; line-height: 1.55; margin: 12px 0 0;
}
.score-note b { color: var(--accent-2); }
.pdf-link { display: flex; justify-content: center; margin-top: 16px; }
.pdf-link .btn { text-decoration: none; }
.faq details { border-bottom: 1px solid var(--grid); }
.faq details:last-child { border-bottom: 0; }
.faq summary {
  cursor: pointer; padding: 12px 0; font-weight: 700; font-size: .9rem;
  list-style: none; position: relative; padding-right: 26px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: '▾'; position: absolute; right: 4px; color: var(--muted);
  transition: transform .2s;
}
.faq details[open] summary::after { transform: rotate(180deg); }
.faq .a { padding: 0 0 14px; color: var(--ink-2); font-size: .86rem; line-height: 1.6; }
.faq .a p { margin: 0 0 8px; }
.faq .a p:last-child { margin-bottom: 0; }
.faq .a b { color: var(--accent-2); }
.score-scale {
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.faq dl { margin: 0; }
.faq dt { font-weight: 700; color: var(--ink); margin-top: 8px; }
.faq dt:first-child { margin-top: 0; }
.faq dd { margin: 1px 0 0; }

/* ---------- estados ---------- */
.empty {
  text-align: center; color: var(--muted); padding: 40px 20px; font-size: .9rem;
}
.empty .big { font-size: 2.2rem; display: block; margin-bottom: 8px; }
.skeleton { animation: pulse 1.2s ease-in-out infinite; color: var(--muted); text-align: center; padding: 40px; }
@keyframes pulse { 50% { opacity: .4; } }

/* ---------- admin ---------- */
.login-card {
  max-width: 360px; margin: 12vh auto 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px;
  text-align: center;
}
.login-card h1 { font-family: var(--display); font-weight: 400; font-size: 1.4rem; margin: 0 0 18px; }
input[type=password], input[type=text], input[type=date] {
  width: 100%; background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 13px; font-size: 1rem; font-family: var(--sans);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 12px 18px; font-size: .95rem; font-weight: 700; cursor: pointer;
  font-family: var(--sans);
}
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); }
.btn.small { padding: 8px 12px; font-size: .8rem; border-radius: 8px; }
.btn.danger { background: transparent; border: 1px solid var(--error); color: var(--error); }
.form-grid { display: flex; flex-direction: column; gap: 10px; }
.race-row {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; margin-top: 10px;
}
.race-row .head { display: flex; align-items: center; gap: 10px; }
.race-row .ttl { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.race-row .dt { color: var(--muted); font-size: .8rem; }
.race-row .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.status {
  font-size: .72rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.status.awaiting_pdf { background: rgba(245,179,1,.15); color: var(--accent-2); }
.status.processing { background: rgba(57,135,229,.15); color: var(--s1); }
.status.done { background: rgba(12,163,12,.15); color: var(--good); }
.status.error { background: rgba(208,59,59,.18); color: var(--error); }
.err-msg { color: var(--error); font-size: .8rem; }
.pilot-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--grid);
}
.pilot-row:last-child { border-bottom: 0; }
.pilot-row .info { flex: 1; min-width: 0; }
.pilot-row .info .n { font-weight: 700; }
.pilot-row .info .s { color: var(--muted); font-size: .78rem; }
.tabs { display: flex; gap: 8px; margin: 14px 0; }
.tab {
  flex: 1; text-align: center; padding: 11px; border-radius: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); color: var(--ink-2);
  font-weight: 700; font-size: .9rem;
}
.tab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink);
  border-radius: 12px; padding: 12px 18px; font-size: .9rem;
  box-shadow: 0 8px 30px rgba(0,0,0,.55); display: none; max-width: 90vw;
}
.spin {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: spin .8s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .controls { flex-direction: row; align-items: center; }
  select.race-select { width: auto; flex: 1; }
  .race-row { flex-direction: row; align-items: center; }
  .race-row .head { flex: 1; }
  table { min-width: 0; }
}
