:root {
  /* paleta de IFX Networks (variables de ifxnetworks.com): azul #003cde, celeste #00e0ff, azul noche #11153d */
  --bg: #070a26;
  --panel: #0f1445;
  --panel-2: #161c5c;
  --line: #28308a;
  --text: #f3f5ff;
  --muted: #a8beff;
  --primary: #003cde;
  --primary-hover: #2864ff;
  --accent: #00e0ff;
  --accent-ink: #050824;
  --gold: #ffd25a;
  --danger: #ef6b51;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #0a2a9e 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
header.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
header.top h1 { margin: 0; font-size: 1.5rem; letter-spacing: .02em; flex: 1 1 auto; }
header.top h1 small { display: block; color: var(--muted); font-size: .8rem; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; }

.tabs { display: flex; gap: 6px; margin: 8px 0 16px; overflow-x: auto; }
.tabs button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px; cursor: pointer; white-space: nowrap; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--primary); color: #fff; border-color: var(--primary-hover); font-weight: 700; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
a.btn { color: inherit; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { border-color: #6b2b2b; color: #ffb3b3; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 1.1rem; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 32px 8px; }

/* ── llave ─────────────────────────────────────────────────────────── */
.bracket { display: flex; gap: 18px; overflow-x: auto; padding: 4px 4px 16px; scroll-snap-type: x proximity; }
.round { display: flex; flex-direction: column; min-width: 230px; flex: 0 0 230px; scroll-snap-align: start; }
.round h3 { margin: 0 0 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); text-align: center; }
.round .slots { display: flex; flex-direction: column; justify-content: space-around; flex: 1; gap: 12px; }

.match {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  text-align: left; padding: 0; width: 100%;
}
button.match { cursor: pointer; }
button.match:hover { border-color: var(--accent); }
.match .side { display: flex; align-items: center; gap: 8px; padding: 7px 10px; min-height: 46px; }
.match .side + .side { border-top: 1px solid var(--line); }
.match .who { flex: 1; min-width: 0; }
.match .who b, .match .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match .who span { color: var(--muted); font-size: .8rem; }
.match .goals { font-weight: 800; font-size: 1.15rem; min-width: 1.6em; text-align: right; font-variant-numeric: tabular-nums; }
.match .side.win { background: linear-gradient(90deg, rgba(0, 224, 255, .18), transparent); }
.match .side.win .goals { color: var(--accent); }
.match .side.lose { opacity: .55; }
.match .side.tbd .who b { color: var(--muted); font-weight: 500; font-style: italic; padding-right: .2em; }
.match .extra { font-size: .75rem; color: var(--gold); padding: 4px 10px; border-top: 1px dashed var(--line); background: rgba(255, 210, 90, .05); }
.match.bye .extra { color: var(--muted); background: none; }
.match.pending { border-style: dashed; }

.champion {
  text-align: center; padding: 18px; margin-bottom: 16px; border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 210, 90, .25), rgba(0, 60, 222, .25)); border: 1px solid #6d5a1f;
}
.champion .cup { font-size: 2.4rem; }
.champion b { display: block; font-size: 1.5rem; color: var(--gold); }

/* ── sorteo ────────────────────────────────────────────────────────── */
.draw-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.draw-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
}
.draw-card .n { grid-column: 1 / -1; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.draw-card .p b, .draw-card .p span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draw-card .p span { color: var(--muted); font-size: .8rem; }
.draw-card .p.r { text-align: right; }
.draw-card .vs { color: var(--accent); font-weight: 800; }
.draw-card.reveal { animation: pop .5s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes pop { from { opacity: 0; transform: scale(.7) translateY(12px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .draw-card.reveal { animation: none; } }

/* ── participantes ─────────────────────────────────────────────────── */
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.players li { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.players .num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.6em; }
.players .who { flex: 1; min-width: 0; }
.players .who b, .players .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .who span { color: var(--muted); font-size: .85rem; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 160px; }
.row > .btn { flex: 0 0 auto; }
input[type="text"], input[type="password"], input[type="number"] {
  background: #070b30; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label.f { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }

/* ── diálogos ──────────────────────────────────────────────────────── */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog h2 { margin: 0 0 14px; font-size: 1.1rem; }
.score-grid { display: grid; grid-template-columns: 1fr 72px 72px; gap: 8px; align-items: center; }
.score-grid .h { font-size: .75rem; color: var(--muted); text-align: center; text-transform: uppercase; }
.score-grid .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-grid input { text-align: center; font-size: 1.2rem; font-weight: 700; padding: 8px 4px; }
.stage { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.stage[hidden] { display: none; }
.stage .t { font-size: .8rem; color: var(--gold); margin-bottom: 8px; }
.err { color: var(--danger); margin-top: 10px; min-height: 1.2em; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.qr-box { text-align: center; }
.qr-box img { width: min(320px, 80vw); height: auto; background: #fff; border-radius: 12px; padding: 8px; }
.qr-box p { word-break: break-all; }

footer { text-align: center; color: var(--muted); font-size: .75rem; padding: 24px 0 8px; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px;
  max-width: calc(100vw - 32px);
}
.toast.bad { border-color: var(--danger); color: #ffd0d0; }

@media (max-width: 600px) {
  .wrap { padding: 12px 16px; }
  header.top h1 { font-size: 1.25rem; }
  .round { min-width: 200px; flex-basis: 200px; }
}

/* ── modo pantalla (PC/TV): todo entra en una pantalla, sin scroll ─────────── */
.tv-only { display: none; }
body.tv { overflow: hidden; }
body.tv .wrap { max-width: none; height: 100vh; display: flex; flex-direction: column; padding: 1.2vh 1.6vw; }
body.tv header.top { margin-bottom: .6vh; }
body.tv header.top h1 { font-size: clamp(1.2rem, 2.6vh, 2.4rem); }
body.tv .tabs { margin: 0 0 1vh; }
body.tv .tabs button, body.tv header.top .btn { padding: .5vh 1vw; font-size: clamp(.8rem, 1.5vh, 1.3rem); }
body.tv footer { display: none; }
body.tv .view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
body.tv .bracket {
  flex: 1; min-height: 0; overflow: hidden auto; gap: 1.2vw; padding: 0;
  /* --n = partidos de la columna más larga: la letra se achica para que entre en el alto (≈7,4 em por
     partido con nombre, equipo, pie de alargue y separación). Con 64 jugadores el piso de 10px no
     alcanza y queda scroll vertical antes que letra ilegible. */
  font-size: clamp(10px, calc((100vh - 24vh) / (var(--n, 4) * 7.4)), 26px);
}
body.tv .round { flex: 1 1 0; min-width: 0; }
body.tv .round.final { flex-grow: 1.15; }
body.tv .round.final .match { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 24px rgba(0, 224, 255, .25); }
body.tv .round.right .side { flex-direction: row-reverse; text-align: right; }
body.tv .round.right .goals { text-align: left; }
body.tv .round.right .side.win { background: linear-gradient(270deg, rgba(0, 224, 255, .18), transparent); }
body.tv .round h3 { font-size: .8em; margin-bottom: .4em; }
body.tv .round .slots { gap: .5em; }
body.tv .match .side { min-height: 0; padding: .3em .6em; }
body.tv .match .who b { font-size: 1em; }
body.tv .match .who span { font-size: .78em; }
body.tv .match .goals { font-size: 1.25em; }
body.tv .match .extra { font-size: .72em; padding: .2em .6em; }
body.tv .champion { padding: 1vh; margin-bottom: 1vh; display: flex; align-items: center; justify-content: center; gap: 1.2vw; }
body.tv .champion .cup { font-size: 4vh; }
body.tv .champion b { display: inline; font-size: 3.4vh; }
body.tv .draw-list { grid-template-columns: repeat(auto-fill, minmax(min(30vw, 420px), 1fr)); font-size: clamp(12px, 2vh, 26px); overflow: hidden; }
body.tv .draw-card { padding: 1.2vh 1vw; }
body.tv .tv-only { display: block; }
body.tv .tv-hide { display: none; }
.tv-qr { display: flex; align-items: center; gap: .8vw; }
.tv-qr img { display: block; width: 9vh; height: 9vh; background: #fff; border-radius: 6px; padding: 3px; }
.tv-qr span { color: var(--muted); font-size: 1.6vh; max-width: 9vw; text-align: right; }
body.tv .players { grid-template-columns: repeat(auto-fill, minmax(22vw, 1fr)); font-size: clamp(10px, 1.8vh, 22px); }
@media (max-width: 700px) { .tv-btn { display: none; } }
