:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --line: #243049;
  --text: #eef3ff;
  --muted: #93a0b8;
  --accent: #ff3b3b;
  --gold: #f5c542;
  --silver: #c9d2e3;
  --bronze: #d0884a;
  --ok: #2dd4a8;
  --input: #0a101c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a2744, transparent),
    radial-gradient(900px 500px at 100% 0%, #2a1020, transparent),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 20px; }
.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  justify-content: space-between; margin-bottom: 18px;
}
.brand h1 { margin: 0; font-size: 1.55rem; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

button, .btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 10px 14px; border-radius: 10px; cursor: pointer;
  font-weight: 600; font-size: 0.95rem;
}
button.primary { background: var(--accent); border-color: #ff5a5a; }
button:hover { filter: brightness(1.08); }
.status { color: var(--muted); font-size: 0.85rem; }
.status.ok { color: var(--ok); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer; font-weight: 600;
}
.tab.active { background: #1c2942; color: var(--text); border-color: #3a4d73; }
.tab.tab-final { border-color: var(--gold); color: var(--gold); }
.tab.tab-final.active { background: #2a2410; color: var(--gold); border-color: var(--gold); }

.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 1.15rem; }
.panel-head span { color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

input[type="text"], input[type="number"] {
  width: 100%; min-width: 58px; max-width: 100px;
  background: var(--input); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 1rem; font-weight: 600;
}
input.nome { max-width: none; font-weight: 500; }
input:focus { outline: 2px solid #3b82f6; border-color: transparent; }
.peso { color: var(--muted); white-space: nowrap; }
.pts { font-weight: 800; color: var(--gold); }
.rank-pos { font-weight: 800; width: 42px; }
.pos-1 { color: var(--gold); }
.pos-2 { color: var(--silver); }
.pos-3 { color: var(--bronze); }

/* TV */
body.tv { background: #05080f; overflow: hidden; }
.tv-wrap {
  padding: 28px 36px; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
}
.tv-header {
  display: flex; justify-content: space-between; align-items: end; gap: 16px;
}
.tv-header h1 {
  margin: 0; font-size: clamp(1.6rem, 4vw, 3.2rem); font-weight: 900;
  letter-spacing: -0.02em;
}
.tv-header .sub { color: var(--muted); font-size: clamp(0.85rem, 1.6vw, 1.25rem); }
.tv-clock { font-size: clamp(1.1rem, 2.2vw, 1.9rem); font-weight: 700; color: var(--ok); white-space: nowrap; }

.tv-main {
  flex: 1; min-height: 0;
  display: flex;
}
.tv-card {
  background: linear-gradient(180deg, #121a2b, #0c1320);
  border: 1px solid #243049; border-radius: 20px;
  overflow: hidden; display: flex; flex-direction: column; min-height: 0;
  width: 100%;
}
.tv-card h2 {
  margin: 0; padding: 16px 20px;
  font-size: clamp(1.05rem, 2vw, 1.6rem);
  border-bottom: 1px solid #243049;
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.tv-hint { color: #93a0b8; font-weight: 600; font-size: 0.75em; }
.tv-scroll { overflow: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.tv-table { width: 100%; border-collapse: collapse; }
.tv-table th, .tv-table td {
  padding: 12px 16px; border-bottom: 1px solid #1c2740;
  font-size: clamp(0.95rem, 1.6vw, 1.45rem);
}
.tv-table th { color: #8b98b3; font-size: 0.82rem; text-transform: uppercase; position: sticky; top: 0; background: #121a2b; z-index: 1; }
.tv-table .nome { font-weight: 700; }
.tv-table .big { font-weight: 900; font-size: 1.12em; }
.pts-tv { color: #f5c542; }
.tv-empty { color: #93a0b8; text-align: center; padding: 28px !important; }

.row-finalista td {
  background: rgba(34, 197, 94, 0.18);
  box-shadow: inset 4px 0 0 #22c55e;
}
.nome-wrap {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.tarja-finalista {
  display: inline-block;
  background: #22c55e;
  color: #04140a;
  font-size: 0.62em;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  line-height: 1.2;
  vertical-align: middle;
}

.flash { animation: flash 0.55s ease; }
@keyframes flash {
  0% { background: rgba(245, 197, 66, 0.28); }
  100% { background: transparent; }
}

/* Sorteio */
.sorteio-setup { margin-bottom: 0; }
.sorteio-form {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sorteio-form label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.karts-input {
  max-width: none !important;
  width: 100% !important;
  font-size: 1.05rem !important;
}
.sorteio-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.kart-num { font-weight: 900; font-size: 1.2rem; color: var(--gold); }
.tem-kart td { background: rgba(45, 212, 168, 0.06); }

.sorteio-stage {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #1a1020, #0c1320);
  padding: 28px 16px;
  text-align: center;
}
.sorteio-reveal { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.reveal-piloto {
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  font-weight: 800;
}
.reveal-kart {
  font-size: clamp(3.5rem, 12vw, 6rem);
  font-weight: 900;
  color: var(--gold);
  line-height: 1;
  min-width: 1.4em;
}
.reveal-kart.spinning { opacity: 0.7; filter: blur(0.5px); }

@media (max-width: 700px) {
  body.tv { overflow: auto; }
  .tv-wrap {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 14px 12px 20px;
    gap: 12px;
  }
  .tv-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
  .tv-header h1 { font-size: 1.45rem; line-height: 1.15; }
  .tv-header .sub { font-size: 0.82rem; }
  .tv-clock { font-size: 1rem; }
  .tv-main { flex: none; }
  .tv-card { border-radius: 14px; }
  .tv-card h2 {
    padding: 12px 14px;
    font-size: 1rem;
  }
  .tv-hint { font-size: 0.72rem; }
  .tv-table th, .tv-table td {
    padding: 10px 8px;
    font-size: 0.92rem;
  }
  .tv-table th { font-size: 0.68rem; letter-spacing: 0.03em; }
  .tv-table .nome { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hide-xs { display: none; }
}
