:root {
  --bg: #0a0f1c;
  --surface: #121a2c;
  --surface-2: #0d1424;
  --surface-3: #1a2440;
  --border: #24304d;
  --border-strong: #33415f;
  --text: #e9eef8;
  --muted: #8a96b2;

  --accent-red: #ef4444;
  --accent-green: #22c55e;
  --accent-yellow: #facc15;
  --accent-orange: #f97316;
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  --accent-purple-bright: #c084fc;
  --clock: #facc15;
  --pit-clock: #4ade80;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px rgba(0,0,0,0.25);
  --mono: ui-monospace, 'Cascadia Mono', 'SF Mono', Consolas, monospace;
  --tap: 48px;
  --gap: 10px;
  --bottom-nav: 0px;

  /* Padrão listrado: reforça estados de alerta sem depender só da cor */
  --stripes: repeating-linear-gradient(-45deg, rgba(0,0,0,0.28) 0 4px, transparent 4px 8px);
}

body.day-mode {
  --bg: #e9edf3;
  --surface: #ffffff;
  --surface-2: #f3f5f9;
  --surface-3: #e4e9f1;
  --border: #cfd6e2;
  --border-strong: #b5bfd0;
  --text: #0b1220;
  --muted: #4a5568;
  --accent-yellow: #eab308;
  --clock: #b45309;
  --pit-clock: #15803d;
  --accent-blue: #1d4ed8;
  --accent-purple-bright: #7e22ce;
  --shadow: 0 1px 2px rgba(15,23,42,0.08), 0 6px 18px rgba(15,23,42,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; zoom: 0.7; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 12px;
  padding-bottom: calc(12px + var(--bottom-nav) + env(safe-area-inset-bottom));
  line-height: 1.35;
  min-height: calc(100vh / 0.7);
  transition: background 0.25s, color 0.25s;
}
input, select, button, textarea { font-family: inherit; }
[hidden] { display: none !important; }

.eyebrow { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

/* ---------- Inputs ---------- */
input[type="number"], input[type="text"], select, textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 40px;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-blue); box-shadow: 0 0 0 3px rgba(59,130,246,0.25); }
input[type="number"] { font-variant-numeric: tabular-nums; text-align: center; }
input.is-invalid { border-color: var(--accent-red) !important; color: var(--accent-red) !important; box-shadow: 0 0 0 3px rgba(239,68,68,0.2); }
input:disabled, select:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Botões ---------- */
.btn {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  min-height: var(--tap);
  padding: 8px 14px;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s, opacity 0.15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(60%); }
.btn-danger { background: var(--accent-red); }
.btn-success { background: var(--accent-green); color: #052e12; }
.btn-warning { background: var(--accent-yellow); color: #1f1600; }
.btn-purple { background: var(--accent-purple); color: #fff; }
.btn-purple.is-on { background: #d946ef; box-shadow: 0 0 0 3px rgba(217,70,239,0.3); }
.btn-ghost { background: var(--surface-3); color: var(--text); border: 1px solid var(--border); }
.btn-ghost.danger-text { color: var(--accent-red); }
.btn-icon { width: var(--tap); padding: 0; font-size: 1.15rem; }
.btn-block { width: 100%; font-size: 0.9rem; }

/* Segurar para confirmar */
.btn[data-hold] { position: relative; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.btn[data-hold]::after {
  content: ""; position: absolute; inset: 0;
  background: rgba(255,255,255,0.4);
  transform: scaleX(0); transform-origin: left;
  pointer-events: none;
}
.btn[data-hold].holding::after { transform: scaleX(1); transition: transform var(--hold-ms, 600ms) linear; }
.btn[data-hold] .hold-hint { font-size: 0.6rem; font-weight: 700; opacity: 0.75; letter-spacing: 0.06em; }
.btn[data-hold].nudge { animation: nudge 0.35s; }
@keyframes nudge { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- Cadeado ---------- */
.master-lock-btn {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border-strong); border-radius: 50%;
  font-size: 1.3rem; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
  transition: all 0.2s ease;
}
.master-lock-btn.locked { color: var(--accent-red); border-color: var(--accent-red); background: #3b0d0d; box-shadow: 0 0 0 4px rgba(239,68,68,0.25); }

body.ui-locked main .btn, body.ui-locked .topbar .btn:not(.keep-unlocked) { pointer-events: none; opacity: 0.35; filter: grayscale(80%); }
body.ui-locked main input, body.ui-locked main select { pointer-events: none; opacity: 0.55; }

/* ---------- Topbar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: var(--gap);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.topbar::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: linear-gradient(180deg, var(--accent-red), var(--accent-yellow)); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; overflow: hidden; }
.brand > div { min-width: 0; }
.brand h1, .brand p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1279px) { .hide-sm { display: none; } }
.brand-mark {
  flex: none; width: 80px; height: 80px; border-radius: 10px;
  display: block; object-fit: contain;
}
.brand h1 { font-size: 1.02rem; font-weight: 800; letter-spacing: 0.01em; text-transform: uppercase; }
.brand h1 span { color: var(--muted); font-weight: 600; }
.brand p { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.clock-block { text-align: right; }
.race-clock { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: clamp(1.6rem, 3.2vw, 2.2rem); font-weight: 800; color: var(--clock); line-height: 1; margin-top: 2px; }
.race-clock.paused { opacity: 0.55; }
.race-clock.paused::after { content: " ⏸"; font-size: 0.5em; vertical-align: middle; }
.race-sub { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); margin-top: 3px; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
#btnStartRace { min-width: 128px; }
.status-chip { font-size: 0.66rem; font-weight: 800; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: var(--surface-2); cursor: pointer; min-height: 32px; display: inline-flex; align-items: center; gap: 4px; }
.status-chip.ok { color: var(--accent-green); border-color: rgba(34,197,94,0.4); }
.status-chip.bad { color: var(--accent-orange); border-color: rgba(249,115,22,0.5); }

/* ---------- Abas ---------- */
.tabs {
  display: flex; gap: 6px; margin-bottom: var(--gap);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 5px; box-shadow: var(--shadow);
}
.tab {
  flex: 1; min-height: 44px; border: none; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--muted);
  font-weight: 800; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 -3px 0 var(--accent-yellow); }
.tab .tab-ico { font-size: 1rem; }

.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: var(--gap); box-shadow: var(--shadow);
}
.panel h2, .panel-head h2 { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-blue); }
.panel-sub { font-size: 0.78rem; color: var(--muted); margin: 3px 0 10px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Próximas ações ---------- */
.next-actions {
  position: sticky; top: 0; z-index: 50;
  display: flex; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 8px; margin-bottom: var(--gap);
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
  overflow-x: auto; scrollbar-width: none;
}
.next-actions::-webkit-scrollbar { display: none; }
.na-label { flex: none; font-size: 0.62rem; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); writing-mode: vertical-rl; transform: rotate(180deg); padding: 0 2px; }
.na-chip {
  flex: none; min-height: 44px; padding: 6px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-weight: 800; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 8px;
}
.na-chip .na-lvl { font-size: 0.58rem; font-weight: 900; letter-spacing: 0.08em; padding: 2px 6px; border-radius: 4px; background: var(--surface-3); color: var(--muted); }
.na-chip.lvl-0 { border-color: var(--accent-red); background: rgba(239,68,68,0.16); animation: pulse 0.8s infinite alternate; }
.na-chip.lvl-0 .na-lvl { background: var(--accent-red); color: #fff; }
.na-chip.lvl-0.go { border-color: var(--accent-green); background: rgba(34,197,94,0.18); }
.na-chip.lvl-0.go .na-lvl { background: var(--accent-green); color: #052e12; }
.na-chip.lvl-1 { border-color: rgba(250,204,21,0.6); background: rgba(250,204,21,0.08); }
.na-chip.lvl-1 .na-lvl { background: var(--accent-yellow); color: #1f1600; }
.na-empty { font-size: 0.82rem; font-weight: 700; color: var(--accent-green); padding: 10px 6px; }

/* ---------- Estratégia ---------- */
.box-status { font-size: 0.72rem; font-weight: 800; padding: 5px 10px; border-radius: 999px; border: 1px solid; }
.box-status.open { color: var(--accent-green); background: rgba(34,197,94,0.1); border-color: rgba(34,197,94,0.35); }
.box-status.closing { color: var(--accent-orange); background: rgba(249,115,22,0.12); border-color: rgba(249,115,22,0.45); }
.box-status.closed { color: var(--accent-red); background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.45); }
.strategy-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.strategy-card { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--accent-blue); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 0.76rem; display: flex; flex-direction: column; gap: 5px; }
.strategy-card .sc-title { font-weight: 800; display: flex; justify-content: space-between; color: var(--accent-yellow); }
body.day-mode .strategy-card .sc-title { color: var(--clock); }
.strategy-card.done { border-left-color: var(--accent-green); }
.strategy-card.alert-risk { border-color: var(--accent-red); border-left-color: var(--accent-red); background: var(--stripes), rgba(239,68,68,0.14); }

/* ---------- Barras ---------- */
.stop-segs { display: flex; gap: 3px; }
.stop-segs span { flex: 1; height: 7px; border-radius: 3px; background: transparent; border: 1px solid var(--border-strong); transition: background 0.3s; }
.stop-segs span.on { background: var(--accent-yellow); border-color: transparent; }
.stop-segs span.bad { background: var(--stripes), var(--accent-red); border-color: transparent; }
.stop-segs span.warn { background: var(--stripes), var(--accent-orange); border-color: transparent; }
.kart-strategy { display: none; font-size: 0.72rem; font-weight: 700; color: var(--muted); margin-top: -2px; }

/* Janela da próxima parada */
.kart-window { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--accent-blue); border-radius: var(--radius-sm); padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; }
.kart-window.warn { border-left-color: var(--accent-orange); background: rgba(249,115,22,0.08); }
.kart-window.bad { border-left-color: var(--accent-red); background: var(--stripes), rgba(239,68,68,0.12); }
.kw-row { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.kw-status { font-size: 0.68rem; font-weight: 800; color: var(--muted); white-space: nowrap; }
.kart-window.warn .kw-status { color: var(--accent-orange); }
.kart-window.bad .kw-status { color: var(--accent-red); }
.kw-range { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 0.86rem; font-weight: 800; }
.kw-plan { font-size: 0.7rem; font-weight: 700; color: var(--accent-purple-bright); }
.kw-plan.late { color: var(--accent-orange); }
.kw-plan.late::before { content: "⚠ "; }

/* Lastro */
.ballast-tag { font-size: 0.68rem; font-weight: 800; color: var(--muted); white-space: nowrap; }
.ballast-hint, .plan-hint { font-size: 0.8rem; font-weight: 700; margin-top: 6px; }
.plan-hint { color: var(--accent-purple-bright); }
.ballast-hint { color: var(--accent-green); }
.ballast-hint.unknown { color: var(--muted); font-weight: 600; }
.ballast-hint.over { color: var(--accent-red); }
.rd-ballast { grid-column: 1 / -1; font-size: 0.7rem; font-weight: 700; color: var(--accent-green); }

/* Bandeira vermelha */
.redflag-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--stripes), #991b1b; color: #fff; border: 2px solid #ef4444; border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: var(--gap); font-size: 0.85rem; box-shadow: 0 0 0 3px rgba(239,68,68,0.3);
}
.redflag-banner strong { font-size: 1rem; letter-spacing: 0.04em; }
.redflag-banner .btn { min-width: 180px; flex-direction: column; gap: 0; }
.pit-timer-box.frozen { border-color: var(--accent-red); background: var(--stripes), rgba(239,68,68,0.1); }
.pit-timer-box.frozen .pit-timer-display { color: var(--accent-red); }
.pit-timer-box.frozen .pit-hint { color: var(--accent-red); }

/* Plano de stints */
.plan-table th, .plan-table td { padding: 4px; }
.plan-table select { width: 100%; min-width: 120px; min-height: 36px; padding: 4px 6px; font-size: 0.8rem; }
.plan-table input { width: 64px; min-height: 36px; padding: 4px; }
.plan-table tr.bad-row td { background: rgba(239,68,68,0.1); }
.stop-segs.complete span.on { background: var(--accent-green); }
.meter { height: 7px; background: var(--border); border-radius: 3px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent-blue); border-radius: 3px; transition: width 0.4s linear, background 0.3s; }
.meter.warn i { background: var(--stripes), var(--accent-orange); }
.meter.limit i { background: var(--stripes), var(--accent-red); }
.meter.go i { background: var(--accent-green); }

/* ---------- Karts ---------- */
.grid-karts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); margin-bottom: var(--gap); }

.kart-card {
  --status: var(--accent-green);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  position: relative;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
  min-width: 0;
}
.kart-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: var(--status); transition: background 0.2s; }
.kart-card[data-phase="1"], .kart-card[data-phase="2"] { --status: var(--accent-yellow); }
.kart-card[data-phase="3"] { --status: var(--accent-red); }
.kart-card.is-support[data-phase="0"] { --status: var(--accent-purple-bright); }
.kart-card.at-risk { border-color: var(--accent-red); }
.kart-card.at-risk::before { background: var(--stripes), var(--accent-red); }
.kart-card.flash { animation: flash 0.9s 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 4px var(--accent-yellow); } }

/* Hora de soltar: o card inteiro avisa, sem bloquear a tela */
.kart-card.releasing { border: 2px solid var(--accent-green); box-shadow: 0 0 0 4px rgba(34,197,94,0.35), var(--shadow); }
.kart-card.releasing::before { height: 8px; background: var(--accent-green); animation: pulse 0.5s infinite alternate; }

.kart-card.is-support { border: 2px solid var(--accent-purple-bright); background: linear-gradient(160deg, #2a1160 0%, #161538 100%); }
.kart-card.is-support .kart-title { color: var(--accent-yellow); }
body.day-mode .kart-card.is-support { background: #f5edff; border-color: #7e22ce; }
body.day-mode .kart-card.is-support .kart-title { color: #581c87; }

.kart-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; padding-top: 2px; }
.kart-id { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kart-title { font-size: 1.3rem; font-weight: 900; color: var(--text); letter-spacing: 0.02em; white-space: nowrap; }
.kart-title .hash { color: var(--muted); font-weight: 700; }
.kart-tools { display: flex; gap: 4px; flex: none; }
.btn-tool { min-width: var(--tap); padding: 4px 8px; flex-direction: column; gap: 0; font-size: 1rem; line-height: 1.1; }
.btn-tool span { font-size: 0.56rem; letter-spacing: 0.06em; }

.status-badge { display: inline-flex; align-items: center; gap: 5px; align-self: flex-start; padding: 3px 8px; border-radius: 999px; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.bg-green { background: rgba(34,197,94,0.15); color: #4ade80; border: 1px solid rgba(34,197,94,0.4); }
.bg-yellow { background: rgba(250,204,21,0.15); color: #fde047; border: 1px solid rgba(250,204,21,0.45); }
.bg-red { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.45); }
.bg-purple { background: var(--accent-purple-bright); color: #1a0b2e; }
body.day-mode .bg-green { color: #15803d; }
body.day-mode .bg-yellow { color: #854d0e; }
body.day-mode .bg-red { color: #b91c1c; }
body.day-mode .bg-purple { color: #fff; }

/* Banners */
.banner { display: none; font-size: 0.72rem; font-weight: 800; line-height: 1.3; padding: 6px 8px; border-radius: 6px; color: #fff; }
.banner.show { display: block; }
.banner-signal { background: #a16207; animation: pulse 0.9s infinite alternate; }
.banner-slow { background: #b91c1c; }
.banner-track-warn { background: var(--stripes), #c2410c; }
.banner-track-limit { background: var(--stripes), #991b1b; box-shadow: 0 0 0 2px #ef4444; animation: pulse 0.9s infinite alternate; }
.banner-strategy-risk { background: var(--stripes), #7c2d12; border: 1px solid #ea580c; }
@keyframes pulse { from { opacity: 0.72; } to { opacity: 1; } }

.driver-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; min-width: 0; }
.driver-line strong { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.driver-key { flex: none; font-family: var(--mono); font-size: 0.7rem; font-weight: 800; color: var(--muted); border: 1px solid var(--border-strong); border-radius: 4px; padding: 1px 5px; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 8px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.stat strong { display: block; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.05rem; font-weight: 800; }
.stat-hist strong { font-size: 0.74rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-stops strong { color: var(--accent-yellow); }
body.day-mode .stat-stops strong { color: var(--clock); }
.stat-track strong { color: var(--accent-blue); }
.stat-track.warn strong { color: var(--accent-orange); }
.stat-track.warn strong::after { content: " ⚠"; }
.stat-track.limit strong { color: var(--accent-red); }
.stat-track.limit strong::after { content: " ⛔"; }

.telemetry-box { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-items: end; }
.telemetry-box label, .telemetry-box .tele-ref { display: flex; flex-direction: column; gap: 3px; }
.telemetry-box input { width: 100%; font-weight: 800; }
.tele-ref strong { font-family: var(--mono); font-size: 1rem; min-height: 40px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); border: 1px dashed var(--border); border-radius: 8px; }

.pit-timer-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; text-align: center; display: flex; flex-direction: column; gap: 5px; transition: background 0.2s, border-color 0.2s; }
.pit-timer-display { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: clamp(1.9rem, 3vw, 2.5rem); font-weight: 800; color: var(--pit-clock); line-height: 1.05; }
.pit-hint { font-size: 0.74rem; font-weight: 800; color: var(--muted); min-height: 1.1em; }
.pit-timer-box.idle .pit-timer-display { color: var(--muted); opacity: 0.6; }
.pit-timer-box.active { border-color: rgba(250,204,21,0.5); background: rgba(250,204,21,0.06); }
.pit-timer-box.active .pit-hint { color: var(--accent-yellow); }
body.day-mode .pit-timer-box.active .pit-hint { color: var(--clock); }
.pit-timer-box.release { border-color: var(--accent-green); background: rgba(34,197,94,0.16); }
.pit-timer-box.release .pit-hint { color: var(--accent-green); font-size: 0.95rem; animation: pulse 0.5s infinite alternate; }
.pit-timer-box.last-ok .pit-hint { color: var(--accent-green); }
.pit-timer-box.last-bad .pit-hint { color: var(--accent-red); }

.step-dots { display: flex; gap: 4px; }
.step-dots span { flex: 1; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; text-align: center; padding: 4px 0; border-radius: 5px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.step-dots span.done { color: var(--accent-green); border-color: rgba(34,197,94,0.4); }
.step-dots span.done::before { content: "✓ "; }
.step-dots span.current { background: var(--accent-yellow); color: #1f1600; border-color: transparent; font-weight: 900; }
.step-dots span.current::before { content: "▶ "; }

.steps { display: flex; flex-direction: column; gap: 6px; margin-top: auto; }
.steps .btn { width: 100%; min-height: 56px; font-size: 0.9rem; flex-direction: column; gap: 1px; }

/* ---------- Modais ---------- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(3,6,14,0.78); backdrop-filter: blur(3px); z-index: 1000; justify-content: center; align-items: center; padding: 16px; }
.modal-overlay.open { display: flex; }
.modal-content {
  background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--accent-blue);
  border-radius: 14px; padding: 18px; width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  animation: pop 0.15s ease-out;
}
@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-content.tone-yellow { border-top-color: var(--accent-yellow); }
.modal-content.tone-green { border-top-color: var(--accent-green); }
.modal-content.tone-red { border-top-color: var(--accent-red); }
.modal-content h3 { font-size: 1rem; font-weight: 800; letter-spacing: 0.02em; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-sub { font-size: 0.8rem; color: var(--muted); margin-bottom: 12px; }
.modal-section { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.modal-section > label, .modal-section .section-title { display: block; font-size: 0.85rem; font-weight: 700; margin-bottom: 6px; }
.modal-section p { font-size: 0.76rem; color: var(--muted); margin-bottom: 8px; }
.modal-section select { width: 100%; font-weight: 700; }
.field-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field-inline input { width: 110px; font-weight: 700; }
.field-inline select { flex: 1; min-width: 160px; }
.field-hint { font-size: 0.74rem; font-weight: 700; color: var(--accent-red); }
.modal-footer { display: flex; gap: 8px; margin-top: 4px; }
.modal-footer .btn { flex: 1; }
.modal-footer .btn.grow { flex: 2; }
#notifModalText { font-size: 1rem; margin: 14px 0 18px; line-height: 1.5; white-space: pre-line; }
.queue-note { font-size: 0.72rem; color: var(--muted); margin: -8px 0 10px; }

.checklist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.checklist-item { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; min-height: var(--tap); padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; user-select: none; }
.checklist-item:has(input:checked) { border-color: rgba(34,197,94,0.55); background: rgba(34,197,94,0.08); }
.checklist-item:has(input:checked)::after { content: "✓"; margin-left: auto; font-weight: 900; color: var(--accent-green); }
.checklist-item input[type="checkbox"] { width: 24px; height: 24px; cursor: pointer; accent-color: var(--accent-green); flex: none; }
.checklist-progress { font-size: 0.74rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 50%; top: 12px; transform: translateX(-50%); z-index: 1100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 440px); }
.toast { pointer-events: auto; background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); border-left: 5px solid var(--accent-blue); padding: 10px 14px; border-radius: 10px; font-size: 0.85rem; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,0.4); animation: toastIn 0.2s ease-out; width: 100%; display: flex; gap: 10px; align-items: center; }
.toast .btn { min-height: 36px; padding: 4px 10px; margin-left: auto; }
.toast.ok { border-left-color: var(--accent-green); }
.toast.warn { border-left-color: var(--accent-yellow); }
.toast.bad { border-left-color: var(--accent-red); background: var(--stripes), var(--surface-3); }
.toast.hide { opacity: 0; transform: translateY(-6px); transition: all 0.25s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Tabelas ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.8rem; vertical-align: middle; }
th { color: var(--muted); font-size: 0.66rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
td.num, th.num { text-align: center; font-variant-numeric: tabular-nums; }
.bad-txt { color: var(--accent-red); font-weight: 800; }
.bad-txt::before { content: "❌ "; }
.ok-txt { color: var(--accent-green); font-weight: 700; }
.ok-txt::before { content: "✅ "; }

/* Pilotos (aba) */
.drivers-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.driver-group h3 { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.driver-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 6px; }
.driver-row .dr-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.driver-row .dr-meta { grid-column: 1 / -1; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.driver-row.on-track { border-color: var(--accent-green); background: rgba(34,197,94,0.08); }
.tag { font-size: 0.62rem; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; align-self: center; }
.tag.on { background: var(--accent-green); color: #052e12; }
.tag.none { border: 1px dashed var(--border-strong); color: var(--muted); }

/* Preparação */
.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--gap); }
.config-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.config-field { display: flex; flex-direction: column; gap: 4px; }
.config-field input, .config-field select { width: 100%; font-weight: 700; }
.target-pill { display: inline-block; margin-top: 10px; font-family: var(--mono); font-size: 0.82rem; font-weight: 700; color: var(--accent-green); background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.35); padding: 7px 12px; border-radius: 999px; }
.roster-edit { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.roster-kart { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.roster-kart h3 { font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.roster-driver { display: grid; grid-template-columns: auto 1fr; gap: 6px 8px; align-items: center; padding-top: 8px; border-top: 1px solid var(--border); }
.roster-driver .rd-key { font-family: var(--mono); font-weight: 800; font-size: 0.75rem; color: var(--muted); }
.roster-driver input[type="text"] { width: 100%; font-weight: 700; }
.roster-driver .rd-times { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.roster-driver .rd-times label { display: flex; flex-direction: column; gap: 2px; }
.roster-driver .rd-times input { width: 100%; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }
.notice { font-size: 0.78rem; font-weight: 700; padding: 8px 10px; border-radius: 8px; background: rgba(250,204,21,0.1); border: 1px solid rgba(250,204,21,0.4); color: var(--text); margin-bottom: 10px; }

/* Relatório */
.report-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 10px; }
.report-summary .stat strong { font-size: 1.25rem; }
.event-log td { font-size: 0.76rem; }
.event-log tr.undone td { text-decoration: line-through; opacity: 0.55; }

/* ---------- Placa (pitboard) ---------- */
.pitboard { position: fixed; inset: 0; z-index: 1200; background: #000; color: #fff; display: flex; flex-direction: column; }
.pitboard.theme-yellow { background: #facc15; color: #000; }
.pitboard.theme-white { background: #fff; color: #000; }
.pb-display { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; cursor: pointer; overflow: hidden; padding: 2vh 2vw; user-select: none; }
.pb-kart { font-family: var(--mono); font-weight: 900; font-size: 9vh; line-height: 1; opacity: 0.85; }
.pb-text { font-weight: 900; line-height: 0.95; letter-spacing: -0.01em; white-space: pre-line; word-break: break-word; }
.pb-controls { background: #0d1424; color: #e9eef8; padding: 10px; display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; border-top: 1px solid #33415f; }
.pb-controls .btn-ghost { background: #1a2440; color: #e9eef8; border-color: #33415f; }
.pb-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pb-row input[type="text"] { flex: 1; min-width: 140px; }
.pb-row input[type="number"] { width: 80px; }
.pb-presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.pb-presets .btn { white-space: normal; line-height: 1.1; }
.pitboard.controls-hidden .pb-controls { display: none; }
.pb-tap-hint { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; font-size: 0.75rem; opacity: 0.45; pointer-events: none; }

#printArea { display: none; }
.print-check { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 0.85rem; font-weight: 600; }
.print-check input { width: 20px; height: 20px; accent-color: var(--accent-green); }
.print-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 10px; }

@media print {
  @page { size: A4 landscape; margin: 0; }
  body { background: #fff !important; color: #000 !important; padding: 0 !important; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  .print-page { width: 297mm; height: 210mm; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; font-family: 'Arial Black', 'Segoe UI', sans-serif; font-weight: 900; line-height: 0.95; page-break-after: always; break-after: page; overflow: hidden; white-space: pre-line; color: #000; }
  .print-page.inv { background: #000 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ======================================================
   RESPONSIVO
   ====================================================== */

/* Tablet deitado / notebook: 4 colunas compactas para caber sem rolar */
@media (min-width: 1000px) and (max-height: 860px) {
  body { padding: 6px 8px; }
  :root { --gap: 6px; }
  .topbar { padding: 6px 12px; }
  .brand p { display: none; }
  .brand-mark { width: 58px; height: 58px; }
  .race-clock { font-size: 1.6rem; }
  .tabs { padding: 3px; }
  .tab { min-height: 38px; }
  .panel { padding: 8px 12px; }
  .strategy-grid { margin-top: 6px; }
  .strategy-card { padding: 5px 8px; gap: 3px; }
  .kart-card { padding: 9px; gap: 6px; }
  .kart-title { font-size: 1.1rem; }
  .stat { padding: 4px 7px; gap: 2px; }
  .stat strong { font-size: 0.95rem; }
  .pit-timer-display { font-size: 1.8rem; }
  .pit-timer-box { padding: 5px 8px; gap: 3px; }
  .steps .btn { min-height: 50px; }
  .telemetry-box input, .tele-ref strong { min-height: 36px; padding: 4px; }

  /* Planejamento vira uma linha dentro de cada card; detalhes ficam no Relatório */
  .brand h1 span { display: none; }
  #strategyGrid { display: none; }
  #view-race > .panel { padding: 6px 12px; }
  .kw-row .eyebrow { display: none; }
  .kart-window { padding: 4px 8px; gap: 2px; }
  /* Em pista, a janela da próxima parada ocupa o lugar do cronômetro parado */
  .kart-card[data-phase="0"] .pit-timer-box { display: none; }
  .stats-grid .stat:nth-child(3), .stats-grid .stat-hist, .step-dots { display: none; }
  .na-label { display: none; }
  .next-actions { padding: 5px; }
  .na-chip { min-height: 40px; }
  .driver-line { padding: 4px 8px; }
  .driver-line strong { font-size: 0.88rem; }
  .banner { padding: 4px 6px; font-size: 0.66rem; }
}

/* Entre tablet em pé e notebook pequeno: 2 colunas */
@media (max-width: 999px) {
  .grid-karts, .roster-edit, .drivers-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { grid-template-columns: 1fr auto; }
  .actions { grid-column: 1 / -1; justify-content: stretch; }
  .actions .btn { flex: 1; }
}

/* Celular em pé */
@media (max-width: 640px) {
  .hide-sm { display: none; }
  :root { --bottom-nav: 64px; --gap: 8px; }
  body { padding: 8px; padding-bottom: calc(8px + var(--bottom-nav) + env(safe-area-inset-bottom)); }
  .grid-karts, .roster-edit, .drivers-grid { grid-template-columns: 1fr; }
  .strategy-grid { grid-template-columns: 1fr 1fr; }
  .topbar { grid-template-columns: 1fr auto; gap: 8px; padding: 8px 10px; }
  .brand p, .brand h1 span { display: none; }
  .brand-mark { width: 58px; height: 58px; }
  .brand h1 { font-size: 0.9rem; }
  .actions { gap: 6px; }
  .actions .btn { padding: 6px 8px; font-size: 0.74rem; }
  #btnStartRace { min-width: 0; flex: 1 1 55%; }
  #btnUndo { flex: 1 1 38%; }
  #btnRedFlag { flex: 1 1 0; }
  .actions .btn-icon, .actions [data-action="pitboard"] { flex: 1 1 0; }
  .status-chip .chip-txt { display: none; }
  .status-chip { min-height: var(--tap); padding: 0 12px; font-size: 1rem; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 800;
    margin: 0; border-radius: 0; border-width: 1px 0 0;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .tab { flex-direction: column; gap: 2px; font-size: 0.6rem; min-height: 54px; }
  .tab .tab-ico { font-size: 1.2rem; }
  .tab[aria-selected="true"] { box-shadow: inset 0 3px 0 var(--accent-yellow); }
  .na-label { display: none; }
  body { padding-bottom: calc(80px + var(--bottom-nav) + env(safe-area-inset-bottom)); }
  .master-lock-btn { position: fixed; right: 14px; bottom: calc(12px + var(--bottom-nav) + env(safe-area-inset-bottom)); z-index: 900; width: 56px; height: 56px; }
  .modal-overlay { padding: 8px; align-items: flex-end; }
  .modal-content { max-height: calc(100dvh - 16px); }
}

/* Celular deitado: pouca altura, 2 colunas, cabeçalho enxuto */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --bottom-nav: 0px; --gap: 6px; }
  body { padding: 6px 8px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .grid-karts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strategy-grid { grid-template-columns: repeat(4, 1fr); }
  .topbar { grid-template-columns: auto 1fr auto; padding: 4px 10px; gap: 8px; }
  .brand p, .brand h1 span { display: none; }
  .brand h1 { display: none; }
  .brand-mark { width: 48px; height: 48px; }
  .clock-block { text-align: left; display: flex; align-items: baseline; gap: 8px; }
  .clock-block .eyebrow { display: none; }
  .race-clock { font-size: 1.4rem; }
  .actions { grid-column: auto; flex-wrap: nowrap; }
  .actions .btn { min-height: 40px; padding: 4px 8px; font-size: 0.7rem; flex: none; }
  #btnStartRace { min-width: 0; }
  .tabs { position: static; border-radius: var(--radius); border-width: 1px; padding: 3px; }
  .tab { flex-direction: row; min-height: 36px; font-size: 0.66rem; }
  .tab .tab-ico { font-size: 0.9rem; }
  .next-actions { padding: 5px; }
  .na-label { display: none; }
  .na-chip { min-height: 38px; font-size: 0.74rem; }
  #strategyGrid { display: none; }
  #view-race > .panel { padding: 5px 10px; }
  .kw-row .eyebrow { display: none; }
  .kart-window { padding: 4px 8px; gap: 2px; }
  .kart-card[data-phase="0"] .pit-timer-box { display: none; }
  .hide-sm { display: none; }
  .strategy-card { padding: 4px 6px; font-size: 0.68rem; }
  .kart-card { padding: 8px; gap: 6px; }
  .pit-timer-display { font-size: 1.7rem; }
  .steps .btn { min-height: 48px; }
  .master-lock-btn { position: static; width: 40px; height: 40px; }
}

/* Telas largas: mais respiro */
@media (min-width: 1600px) {
  body { padding: 16px 24px; }
  :root { --gap: 14px; }
  .kart-card { padding: 16px; gap: 10px; }
  .pit-timer-display { font-size: 2.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
