:root {
  /* Tema B · Bandeira Quadriculada */
  --bg: #0b0b0c;
  --panel: #1d1e21;
  --line: #2e3034;
  --text: #f2f2f2;
  --muted: #8a8f98;
  --accent: #e10600;   /* vermelho de corrida */
  --ok: #2fbf71;
  --bad: #e10600;
  --box: #26282c;
  --pilot-bg: #ffffff;
  --pilot-fg: #0b0b0c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { height: 100dvh; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 3px solid var(--accent);
  background: #000;
}
header h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 800; letter-spacing: .06em; }
header h1 .tag { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--muted); margin-left: 6px; }
.status { display: flex; gap: 10px; font-size: 13px; color: var(--muted); }
.status i { font-style: normal; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); margin-right: 4px; }
.dot.on { background: var(--ok); }
main { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 12px 16px; gap: 12px; }
.log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
}
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; word-wrap: break-word; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg.box { background: var(--box); align-self: flex-end; }
.msg.pilot { background: var(--pilot-bg); color: var(--pilot-fg); border-left: 5px solid var(--accent); align-self: flex-start; font-size: 20px; font-weight: 700; }
.msg.pilot .meta { color: #55585e; }
.msg.system { align-self: center; color: var(--muted); font-size: 13px; background: none; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button:active { transform: scale(0.97); }
button.primary { background: #fff; border-color: #fff; color: #000; font-weight: 800; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.quick button { font-weight: 600; }
form.send { display: flex; gap: 8px; }
input[type=text], input[type=password], textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}
form.send input { flex: 1; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.meter { position: relative; height: 18px; background: #000; border-radius: 6px; overflow: hidden; }
.meter .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ok); transition: width 60ms linear; }
.meter .bar.speech { background: var(--accent); }
.meter .thr { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; }
.big { font-size: 22px; font-weight: 700; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; max-width: 420px; width: calc(100% - 32px); }
dialog textarea { width: 100%; min-height: 180px; }
a { color: #fff; }

/* ---------- Página do box ---------- */
button.icon { padding: 8px 10px; font-size: 18px; line-height: 1; }
.box-page header { padding-top: max(10px, env(safe-area-inset-top)); }
.box-page main { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.last {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--pilot-bg);
  color: var(--pilot-fg);
  border-left: 7px solid var(--accent);
}
.last.empty { background: var(--panel); color: var(--text); border-left-color: var(--line); }
.last.empty .last-text { color: var(--muted); font-size: 16px; font-weight: 400; }
.last.empty .last-label { color: var(--muted); }
.last-label { font-size: 12px; color: #55585e; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.last-text { font-size: 24px; font-weight: 700; line-height: 1.25; margin-top: 2px; word-wrap: break-word; }
.last-time { font-size: 12px; color: #55585e; margin-top: 2px; }
.last.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { background: var(--accent); color: #fff; }
  100% { background: var(--pilot-bg); color: var(--pilot-fg); }
}
.box-page .quick {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.box-page .quick button { min-height: 56px; font-size: 16px; padding: 8px 10px; }
.quick button.hot { background: var(--accent); border-color: var(--accent); color: #fff; }
.quick button.sent { background: var(--ok); border-color: var(--ok); color: #fff; }
.box-page form.send button { min-width: 88px; }

@media (max-width: 640px) {
  header { gap: 6px; padding-left: 12px; padding-right: 12px; }
  header h1 { font-size: 17px; }
  .status { gap: 6px; font-size: 12px; }
  main { padding: 10px 12px; gap: 10px; }
  .last { margin: 10px 12px 0; }
  .last-text { font-size: 22px; }
  .box-page .quick { grid-template-columns: 1fr 1fr; max-height: 42dvh; overflow-y: auto; }
  .box-page .quick button { min-height: 60px; font-size: 17px; }
  .msg { max-width: 92%; }
  body.typing .quick { display: none; }
}
input[type=range] { accent-color: var(--accent); }

/* ---------- Cronometragem (box) ---------- */
.timing {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 10px 16px 0;
  cursor: pointer;
}
.timing[hidden] { display: none; }
.timing .tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 4px;
  text-align: center;
  min-width: 0;
}
.timing .tile span { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.timing .tile b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.timing .tile.best b { color: #fff; }
.timing .tile.best { border-color: var(--accent); }
.timing .tile.flash { animation: tileflash 1.5s ease-out; }
@keyframes tileflash { 0% { background: var(--accent); } 100% { background: var(--panel); } }
.map-dialog { max-width: 520px; }
.map { width: 100%; aspect-ratio: 1; background: #000; border-radius: 10px; margin: 8px 0; }
.map .trace { fill: none; stroke: #8a8f98; stroke-width: 0.8; stroke-linejoin: round; }
.map .finish { fill: #fff; stroke: var(--accent); stroke-width: 0.8; }
.map .kart { fill: var(--accent); stroke: #fff; stroke-width: 0.8; }
.lap-list { margin: 8px 0 0; padding-left: 22px; max-height: 30vh; overflow-y: auto; font-variant-numeric: tabular-nums; }
.lap-list li.best { color: #fff; font-weight: 700; }
@media (max-width: 640px) {
  .timing { margin: 8px 12px 0; gap: 4px; }
  .box-page .status i { display: none; }
  .box-page .status { flex-direction: column; gap: 2px; }
  .box-page .status .dot { width: 10px; height: 10px; }
  .box-page button.icon { padding: 7px 8px; font-size: 17px; }
  .timing .tile b { font-size: 16px; }
}

.timing .tile.faster { background: #123d25; border-color: var(--ok); }
.timing .tile.faster b { color: var(--ok); }
.timing .tile.slower { background: #3d1412; border-color: #ff5a52; }
.timing .tile.slower b { color: #ff5a52; }
.lap-list .secs { display: inline-flex; gap: 10px; margin-left: 10px; color: var(--muted); font-size: 13px; }
.lap-list .secs i { font-style: normal; }
.lap-list .secs i.pb { color: #b56cff; font-weight: 700; }

.satmap { aspect-ratio: 1; min-height: 260px; }
.satmap[hidden], .map[hidden] { display: none; }
.finish-icon { font-size: 22px; line-height: 26px; text-align: center; filter: drop-shadow(0 0 2px #000); }
.leaflet-container { background: #111; font: inherit; }
.leaflet-control-attribution { font-size: 9px; }
#mapSearch { margin-top: 8px; } #mapSearch input { font-size: 16px; }

/* ---------- Ícones e abas (box) ---------- */
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; flex: none; }
button .ico { margin-right: 2px; }
button.icon { display: inline-flex; align-items: center; justify-content: center; padding: 8px; color: var(--text); }
button.icon .ico { margin: 0; }
button.icon.off { color: var(--muted); }
button.icon.off .ico { opacity: .45; }
.box-page { height: 100dvh; overflow: hidden; }
.box-page .panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.box-page[data-tab="radio"] .panel[data-panel="radio"],
.box-page[data-tab="tempos"] .panel[data-panel="tempos"],
.box-page[data-tab="mapa"] .panel[data-panel="mapa"] { display: flex; }
.box-page .panel main { flex: 1; min-height: 0; }
.strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 16px 0; }
.strip div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; text-align: center; padding: 6px 4px; }
.strip span { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.strip b { font-size: 18px; font-variant-numeric: tabular-nums; }
.strip .faster { background: #123d25; border-color: var(--ok); }
.strip .faster b { color: var(--ok); }
.strip .slower { background: #3d1412; border-color: #ff5a52; }
.strip .slower b { color: #ff5a52; }
.panel[data-panel="tempos"] .timing { margin: 10px 16px 0; cursor: default; }
.panel[data-panel="tempos"] .scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 16px; }
.panel[data-panel="tempos"] .lap-list { max-height: none; }
.panel[data-panel="mapa"] { padding: 10px 12px 8px; gap: 8px; }
.mapwrap { position: relative; flex: 1; min-height: 0; }
.mapwrap .map { width: 100%; height: 100%; aspect-ratio: auto; margin: 0; }
.speed-badge { position: absolute; right: 8px; top: 8px; z-index: 500; background: #000c; color: #fff; border-radius: 8px; padding: 4px 10px; font-weight: 700; font-variant-numeric: tabular-nums; }
.speed-badge:empty { display: none; }
#mapSearch button { display: inline-flex; align-items: center; justify-content: center; padding: 10px 12px; }
#mapSearch button .ico { margin: 0; }
.tabbar { display: grid; grid-template-columns: repeat(3, 1fr); background: #000; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { background: none; border: 0; border-top: 2px solid transparent; border-radius: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 10px; font-size: 12px; }
.tabbar button .ico { margin: 0; }
.tabbar button.on { color: #fff; border-top-color: var(--accent); }
.box-page .last { margin-top: 10px; }
@media (max-width: 640px) {
  .strip { margin: 8px 12px 0; }
  .panel[data-panel="tempos"] .timing { margin: 8px 12px 0; }
  .panel[data-panel="tempos"] .scroll { padding: 8px 12px 16px; }
}

.panel[data-panel="tempos"] .lap-list { list-style: none; padding-left: 0; }
.panel[data-panel="tempos"] .lap-list li { padding: 8px 4px; border-bottom: 1px solid var(--line); }

/* Teclado aberto (digitando no box): só a conversa, o campo e o Enviar */
.box-page.typing .tabbar,
.box-page.typing .strip,
.box-page.typing .last { display: none; }
.box-page .log { min-height: 0; }
.box-page.typing .panel[data-panel="radio"] main { padding-bottom: 6px; }

.mapwrap .leaflet-top.leaflet-right { top: 44px; }
.leaflet-control-layers { font: 14px/1.4 system-ui, sans-serif; }
.leaflet-control-layers-expanded { padding: 8px 10px; }

/* Situação da mensagem enviada ao piloto */
.msg .status[data-st="sent"] { color: #c9a227; }
.msg .status[data-st="heard"] { color: #2ecc71; font-weight: 700; }
.msg .status[data-st="offline"] { color: #e5534b; }
#pilotTag.muted { color: #e5534b; font-weight: 700; }

/* Fala do piloto em destaque: aparece e some sozinha depois de alguns segundos */
.last { transition: opacity .4s ease; cursor: pointer; }
.last.hiding { opacity: 0; }
.last.gone { display: none; }

/* ---------- Equipes: login do box e barra de pilotos ---------- */
.login { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto; }
.login[hidden] { display: none; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.login-logo { width: 72px; height: 72px; border-radius: 18px; }
.login h2 { margin: 4px 0 0; font-size: 28px; letter-spacing: .06em; }
.login h2 .tag { font-size: 13px; vertical-align: middle; }
.login label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.login label[hidden] { display: none; }
.login input { font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login .big { padding: 14px; font-size: 17px; }
.login .link { background: none; border: none; color: var(--muted); text-decoration: underline; font-size: 13px; }
.lg-msg { color: #ff6b63; min-height: 1.2em; margin: 0; font-size: 14px; }
.seg { display: flex; background: var(--panel); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: none; background: none; color: var(--muted); padding: 10px; border-radius: 9px; font-weight: 700; }
.seg button.on { background: #fff; color: #000; }
.code { font: 800 34px/1.2 ui-monospace, Menlo, monospace; letter-spacing: .18em; text-align: center; padding: 14px; border-radius: 14px; background: var(--panel); border: 1px dashed var(--line); }
.pilotbar { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; background: #000; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.pilotbar[hidden] { display: none; }
.pchip { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 99px; font-weight: 700; font-size: 14px; }
.pchip i { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.pchip.online i { background: #2fbf71; }
.pchip.muted i { background: #e10600; }
.pchip.all i { display: none; }
.pchip.on { background: #fff; color: #000; border-color: #fff; }

/* Logo da equipe e fotos dos pilotos */
.team-logo { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; margin-right: 8px; vertical-align: middle; }
.pchip .avatar { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; margin-left: -6px; }
.tm-head { display: flex; gap: 12px; align-items: center; }
.tm-head p { margin: 0; }
.logo-pick { display: flex; align-items: center; justify-content: center; width: 72px; height: 72px; flex: none; border-radius: 16px; border: 1px dashed var(--line); background: var(--panel); color: var(--muted); font-size: 12px; cursor: pointer; overflow: hidden; }
.logo-pick img { width: 100%; height: 100%; object-fit: cover; }
.logo-pick.wide { width: auto; height: 64px; padding: 0 14px; gap: 10px; }
.logo-pick.wide img { width: 48px; height: 48px; border-radius: 12px; }
.last-avatar { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; vertical-align: middle; margin-right: 6px; }
.last-label { display: flex; align-items: center; }
.msg-avatar { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; vertical-align: -3px; margin-right: 5px; }
.login .slogan { margin: 0; font-size: 17px; font-weight: 700; }
.login .descr { margin: -6px 0 0; font-size: 12px; letter-spacing: .14em; }
