/* Régua — tela de muro de box: sempre escura, legível à distância. */
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");

:root {
  --bg: #121418;
  --panel: #1b1e24;
  --panel-border: #2a2f38;
  --text: #e8eaed;
  --muted: #9aa3ad;
  --team: #ff9800;
  --other: #4a90e2;
  --sim: #f44336;
  --ok: #4caf50;
  --warn: #ffc107;
  --danger: #f44336;
  --line: #ffffff;
  --nav-height: 64px;
}

html,
body.regua-page {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", system-ui, sans-serif;
}

.regua {
  padding: calc(var(--nav-height) + 12px) 16px 24px;
  max-width: 1600px;
  margin: 0 auto;
  box-sizing: border-box;
}

/* Cabeçalho: cards + status de atualização */
.regua-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 140px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
}

.card-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.card-value.flag-green { color: var(--ok); }
.card-value.flag-yellow { color: var(--warn); }
.card-value.flag-red { color: var(--danger); }
.card-value.is-over { color: var(--danger); }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
}

.status.is-stale .status-dot { background: var(--warn); }
.status.is-error .status-dot { background: var(--danger); }
.status.is-replay .status-dot { background: var(--danger); }
.status.is-replay { color: var(--text); }
.status.is-stale,
.status.is-error { color: var(--text); }

/* Corpo: painel de classificação + pista */
.regua-body {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 700;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
}

.segmented-option {
  padding: 6px 12px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.segmented-option.is-active {
  background: var(--other);
  color: #fff;
}

.table-wrap {
  max-height: min(60vh, 640px);
  overflow: auto;
}

.standings {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.standings th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-align: right;
  padding: 6px 8px;
  border-bottom: 1px solid var(--panel-border);
}

.standings td {
  padding: 7px 8px;
  text-align: right;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  white-space: nowrap;
}

.standings th:nth-child(2),
.standings td:nth-child(2) { text-align: left; }

.standings .kart-number { font-weight: 700; }
.standings tr.is-team .kart-number { color: var(--team); }
.standings tr.is-sim { background: rgba(244, 67, 54, 0.12); }
.standings tr.is-sim .kart-number { color: var(--sim); }
.standings .ok { color: var(--ok); font-weight: 700; }
.standings .muted { color: var(--muted); }

.hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.hint .ok { color: var(--ok); }

/* Pista */
.track-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

#track {
  width: 100%;
  max-width: 1000px;
  height: auto;
}

.track-path { stroke: #3a4250; stroke-width: 6; fill: none; stroke-linejoin: round; }
.track-center { stroke: #556070; stroke-width: 1; stroke-dasharray: 6 8; fill: none; }
.start-line { stroke: var(--line); stroke-width: 4; }
.direction-arrow { fill: var(--muted); }
.track-message { fill: var(--muted); font-size: 22px; text-anchor: middle; }
.kart-label { fill: #fff; font-weight: 700; font-size: 12px; text-anchor: middle; pointer-events: none; }
.kart-dim { opacity: 0.45; }
.sim-ring { fill: none; stroke: var(--sim); stroke-width: 2; stroke-dasharray: 4 3; }
.sim-label { fill: var(--sim); font-weight: 700; font-size: 11px; text-anchor: middle; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
}

.legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.dot-team { background: var(--team); }
.dot-other { background: var(--other); }
.dot-sim { background: transparent; border: 2px dashed var(--sim); box-sizing: border-box; }
.dot-line { background: var(--line); border-radius: 1px; width: 4px; }

.controls {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 10px 18px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.btn:hover { border-color: var(--other); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--other); border-color: var(--other); color: #fff; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }

.sim-result {
  width: 100%;
  max-width: 1000px;
  padding: 12px 16px;
  border-left: 4px solid var(--sim);
  background: rgba(244, 67, 54, 0.1);
  border-radius: 6px;
  font-size: 15px;
  line-height: 1.5;
  box-sizing: border-box;
}

.sim-result strong { font-variant-numeric: tabular-nums; }
.sim-result .ok { color: var(--ok); }
.sim-result .bad { color: var(--danger); }

/* Modal de simulação */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  padding: 16px;
  box-sizing: border-box;
}

.modal-overlay[hidden] { display: none; }

.modal {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 20px;
  box-sizing: border-box;
}

.modal-title { margin: 0 0 4px; font-size: 18px; }
.modal-hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

.kart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.kart-option {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.kart-option.is-selected { border-color: var(--team); background: rgba(255, 152, 0, 0.12); }
.kart-option .kart-number { font-weight: 700; color: var(--team); }
.kart-option .kart-meta { display: block; font-size: 12px; color: var(--muted); }

.field { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

#sim-seconds {
  width: 100px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.presets { display: flex; flex-wrap: wrap; gap: 6px; }

.preset {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.preset.is-active { border-color: var(--other); color: var(--other); }

.modal-buttons { display: flex; justify-content: flex-end; gap: 10px; }

.debug {
  margin-top: 16px;
  padding: 12px;
  background: #000;
  color: #9f9;
  font-size: 11px;
  overflow: auto;
  max-height: 300px;
}

@media (max-width: 900px) {
  :root { --nav-height: 56px; }
  .regua-body { grid-template-columns: 1fr; }
  .track-area { order: -1; }
  .card { min-width: 120px; }
  .card-value { font-size: 18px; }
}
