:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1d232c;
  --line: #2a313c;
  --text: #e8ecf1;
  --muted: #8b95a3;
  --accent: #e8b931;
  --accent-ink: #1a1400;
  --green: #2fbf71;
  --red: #e5484d;
  --blue: #3b82f6;
  --side-a: #2563eb;
  --side-b: #d97706;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.4; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; letter-spacing: .02em; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; }
.tab { background: none; border: 0; padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--panel-2); color: var(--accent); }
.spacer { flex: 1; }
.save-status { font-size: 13px; color: var(--muted); }
.save-status.error { color: var(--red); font-weight: 600; }
.page { padding: 20px; max-width: 1500px; margin: 0 auto; }
.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head h2 { font-size: 20px; }

/* ---------- Botões e formulários ---------- */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=number], input[type=password], input[type=date], select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Avatar e card de atleta ---------- */
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none; object-fit: cover;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  background: hsl(var(--h, 210) 45% 32%); color: #fff;
}
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.avatar.lg { width: 84px; height: 84px; font-size: 28px; }
.avatar.xl { width: 150px; height: 150px; font-size: 52px; }
.avatar.empty { background: var(--panel-2); border: 2px dashed var(--line); }

.ath-card {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 8px;
  background: var(--panel-2); border: 1px solid var(--line); border-left: 5px solid #f5f5f5;
  border-radius: 10px; min-width: 0; position: relative; user-select: none;
}
.ath-card.belt-azul { border-left-color: var(--blue); }
.ath-card.belt-roxa { border-left-color: #8b5cf6; }
.ath-card.belt-marrom { border-left-color: #92400e; }
.ath-card.belt-preta { border-left-color: #000; }
.ath-card[draggable=true] { cursor: grab; }
.ath-card[draggable=true]:active { cursor: grabbing; }
.ath-card.dragging { opacity: .4; }
.ath-text { min-width: 0; flex: 1; }
.ath-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ath-sub { font-size: 12px; color: var(--muted); }

/* ---------- Lista de atletas ---------- */
.athlete-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.athlete-tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; gap: 14px; align-items: center; }
.athlete-tile .avatar { width: 64px; height: 64px; font-size: 22px; }
.athlete-tile .info { flex: 1; min-width: 0; }
.athlete-tile .ath-name { white-space: normal; }
.athlete-tile .cat { font-size: 12px; color: var(--accent); margin-top: 2px; }

/* ---------- Chave ---------- */
.cat-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 600; }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pool {
  background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 18px; min-height: 70px;
}
.pool-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.pool-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.pool.drag-over { border-color: var(--accent); background: #1c1a10; }
.bracket-wrap { overflow-x: auto; padding-bottom: 10px; }
.bracket { display: flex; gap: 22px; min-width: max-content; }
.round { width: 250px; display: flex; flex-direction: column; }
.round-title { text-align: center; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; padding-bottom: 8px; }
.third-title { margin-top: 28px; }
.round-body { display: flex; flex-direction: column; justify-content: space-around; flex: 1; gap: 12px; }
.final-col .round-body { justify-content: center; }
.match { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; display: grid; gap: 6px; }
.match.is-live { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.match-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag.live { background: var(--red); color: #fff; animation: pulse 1.4s infinite; }
.tag.done { background: #133222; color: var(--green); }
@keyframes pulse { 50% { opacity: .55; } }
.slot { min-height: 50px; border-radius: 10px; display: flex; flex-direction: column; justify-content: center; }
.slot.vacant { border: 1px dashed var(--line); }
.slot-empty { font-size: 12px; color: var(--muted); text-align: center; }
.slot.drag-over { outline: 2px solid var(--accent); outline-offset: 1px; background: #1c1a10; }
.slot.won .ath-card { border-color: var(--green); border-left-width: 5px; }
.slot.lost .ath-card { opacity: .5; }
.slot-score { font-weight: 800; font-size: 18px; min-width: 22px; text-align: right; }
.win-mark { color: var(--green); font-weight: 900; }
.match-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Placar ---------- */
.board { display: grid; gap: 16px; }
.board-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.board-head h2 { font-size: 18px; }
.board-main { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: stretch; }
.fighter { background: var(--panel); border-radius: var(--radius); padding: 18px; display: grid; gap: 14px; justify-items: center; border-top: 8px solid var(--side-a); }
.fighter.b { border-top-color: var(--side-b); }
.fighter-name { font-size: 26px; font-weight: 800; text-align: center; }
.big-points { font-size: clamp(80px, 11vw, 160px); font-weight: 900; line-height: .9; font-variant-numeric: tabular-nums; }
.subscores { display: flex; gap: 22px; }
.subscore { text-align: center; }
.subscore .n { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.subscore.adv .n { color: var(--green); }
.subscore.pen .n { color: var(--red); }
.subscore .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.score-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; max-width: 360px; }
.score-btns .btn { padding: 12px 0; font-size: 18px; }
.score-btns .btn.pt { background: #1e2a3d; }
.score-btns .btn.adv { color: var(--green); }
.score-btns .btn.pen { color: var(--red); }
.score-btns .minus { font-size: 14px; padding: 6px 0; color: var(--muted); }
.clock-col { display: grid; align-content: center; justify-items: center; gap: 12px; min-width: 260px; }
.clock { font-size: clamp(72px, 9vw, 140px); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
.clock.running { color: var(--green); }
.clock.over { color: var(--red); }
.clock-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.clock-btns .btn.big { font-size: 20px; padding: 12px 26px; }
.rules-note { font-size: 12px; color: var(--muted); text-align: center; max-width: 900px; margin: 0 auto; }
.queue { display: grid; gap: 10px; max-width: 760px; }
.queue-item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; grid-template-columns: 70px 1fr auto 1fr auto; gap: 12px; align-items: center; }
.queue-item .vs { color: var(--muted); font-weight: 700; }
.board:fullscreen { background: var(--bg); padding: 24px; overflow: auto; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: grid; gap: 16px; }
.modal h3 { font-size: 19px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.photo-edit { display: flex; gap: 16px; align-items: center; }
.winner-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.winner-pick label { display: flex; gap: 10px; align-items: center; padding: 10px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; }
.winner-pick input { display: none; }
.winner-pick label:has(input:checked) { border-color: var(--green); background: #133222; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px; width: min(380px, 100%); display: grid; gap: 14px; }
.error-msg { color: var(--red); font-size: 14px; min-height: 1em; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; z-index: 200; box-shadow: 0 8px 30px #0008; }

/* ---------- Pódio ---------- */
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 12px; align-items: end; max-width: 640px; margin: 0 auto; }
.podium-place { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 8px; display: grid; justify-items: center; gap: 6px; text-align: center; }
.podium-place.p1 { border-color: var(--accent); padding-top: 24px; padding-bottom: 24px; }
.podium-place.pending { opacity: .5; }
.podium-medal { font-weight: 800; }
.podium-name { font-weight: 700; }

/* ---------- Página pública ---------- */
.pub-header { padding: 22px 16px 10px; text-align: center; }
.pub-header h1 { font-size: 24px; }
.pub-section { padding: 12px 16px 20px; max-width: 1200px; margin: 0 auto; }
.pub-section > h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 12px; }
.live-card { background: var(--panel); border: 1px solid var(--red); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.live-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.live-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: start; }
.live-grid .live-clock { align-self: center; }
.live-side { display: grid; justify-items: center; gap: 6px; text-align: center; min-width: 0; grid-template-rows: auto minmax(2.6em, auto) auto auto; align-items: center; }
.live-side .name { font-weight: 800; font-size: 17px; overflow-wrap: anywhere; }
.live-side .pts { font-size: 54px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.live-side .va { font-size: 13px; color: var(--muted); }
.live-side.a .avatar { box-shadow: 0 0 0 4px var(--side-a); }
.live-side.b .avatar { box-shadow: 0 0 0 4px var(--side-b); }
.live-clock { font-size: 34px; font-weight: 900; font-variant-numeric: tabular-nums; text-align: center; }
.list { display: grid; gap: 8px; }
.list-item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 4px; }
.list-item .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.list-item .meta { font-size: 12px; color: var(--muted); }
.list-item .w { font-weight: 700; color: var(--green); }
.footer { text-align: center; padding: 30px 16px; font-size: 13px; color: var(--muted); }

@media (max-width: 900px) {
  .board-main { grid-template-columns: 1fr 1fr; }
  .clock-col { grid-column: 1 / -1; grid-row: 1; }
  .queue-item { grid-template-columns: 1fr; text-align: center; }
}
@media (max-width: 600px) {
  .page { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .podium { gap: 6px; }
  .podium .avatar.lg { width: 56px; height: 56px; font-size: 20px; }
  .live-side .avatar.lg { width: 60px; height: 60px; font-size: 20px; }
  .live-side .pts { font-size: 42px; }
  .live-clock { font-size: 26px; }
}
