:root {
  --bg: #0b1020;
  --bg-2: #121a33;
  --surface: #182242;
  --surface-2: #1f2c54;
  --line: #2b3a66;
  --text: #eef2ff;
  --muted: #9fb0d8;
  --accent: #ff3366;
  --accent-2: #19d3c5;
  --gold: #ffcf4d;
  --win: #19d3c5;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; overflow-x: hidden; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(255, 51, 102, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(25, 211, 197, 0.14), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

/* ------------------------------- Topbar -------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 16, 32, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand__ball { font-size: 30px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.brand__text { display: flex; flex-direction: column; line-height: 1.05; }
.brand__text strong {
  font-size: 19px; letter-spacing: .5px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand__text span { font-size: 12px; color: var(--muted); letter-spacing: 3px; text-transform: uppercase; }

.user-box { display: flex; align-items: center; gap: 12px; }
.user-box input {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  width: 180px;
  transition: border-color .2s, box-shadow .2s;
}
.user-box input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(25,211,197,.18); }
.save-status {
  font-size: 12px; color: var(--muted);
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line);
  white-space: nowrap;
}
.save-status.is-saving { color: var(--gold); border-color: rgba(255,207,77,.4); }
.save-status.is-saved { color: var(--accent-2); border-color: rgba(25,211,197,.4); }

/* -------------------------------- Steps -------------------------------- */
.steps {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.step {
  flex: 1;
  min-width: 130px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.step span {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted);
  font-size: 12px; font-weight: 700;
}
.step:hover { border-color: var(--accent-2); color: var(--text); }
.step.is-active {
  color: #fff;
  background: linear-gradient(135deg, rgba(255,51,102,.25), rgba(25,211,197,.18));
  border-color: var(--accent);
}
.step.is-active span { background: var(--accent); color: #fff; }
.step.is-complete span { background: var(--accent-2); color: #04201d; }

/* ------------------------------ Container ------------------------------ */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 80px; }

.panel { display: none; animation: fade .25s ease; }
.panel.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel__head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.panel__head h1 { margin: 0 0 4px; font-size: 26px; }
.muted { color: var(--muted); margin: 0; font-size: 14px; max-width: 720px; }
.muted strong { color: var(--text); }

.btn {
  border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--line); color: var(--text);
  background: var(--surface); transition: all .2s;
}
.btn:hover { border-color: var(--accent-2); }
.btn--ghost { background: transparent; }

.counter {
  font-weight: 700; font-size: 16px; padding: 8px 16px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.counter.is-full { color: #04201d; background: var(--accent-2); border-color: var(--accent-2); }

/* -------------------------------- Grupos ------------------------------- */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.group-card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.group-card__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(90deg, rgba(255,51,102,.18), transparent);
  border-bottom: 1px solid var(--line);
}
.group-card__head h2 { margin: 0; font-size: 15px; letter-spacing: 1px; text-transform: uppercase; }
.group-card__hint { font-size: 11px; color: var(--muted); }
.group-card__list { padding: 8px; display: flex; flex-direction: column; gap: 6px; }

/* -------------------------------- Team --------------------------------- */
.team {
  display: grid;
  grid-template-columns: 30px 30px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  transition: transform .12s, border-color .2s, background .2s, opacity .2s;
}
.team:hover { border-color: var(--accent-2); transform: translateX(2px); }
.team__rank {
  width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--bg); color: var(--muted);
  font-weight: 800; font-size: 13px;
  border: 1px solid var(--line);
}
.team__flag {
  width: 30px; height: 20px; border-radius: 3px; object-fit: cover;
  background: var(--bg); box-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.team__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team__code { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: .5px; }

/* Posiciones */
.team[data-pos="1"] { background: linear-gradient(90deg, rgba(255,207,77,.22), var(--surface-2)); border-color: rgba(255,207,77,.5); }
.team[data-pos="1"] .team__rank { background: var(--gold); color: #2a2000; border-color: var(--gold); }
.team[data-pos="2"] { background: linear-gradient(90deg, rgba(25,211,197,.18), var(--surface-2)); border-color: rgba(25,211,197,.45); }
.team[data-pos="2"] .team__rank { background: var(--accent-2); color: #04201d; border-color: var(--accent-2); }
.team[data-pos="3"] { background: linear-gradient(90deg, rgba(159,176,216,.18), var(--surface-2)); border-color: rgba(159,176,216,.4); }
.team[data-pos="3"] .team__rank { background: #6d7fae; color: #fff; }
.team[data-pos="4"] { opacity: .5; }

/* ----------------------------- Terceros -------------------------------- */
.thirds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.third-pick {
  display: grid;
  grid-template-columns: auto 30px 1fr auto;
  align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; cursor: pointer; color: var(--text);
  transition: all .18s;
}
.third-pick:hover { border-color: var(--accent-2); }
.third-pick .pick-box {
  width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 14px; color: transparent;
}
.third-pick__group { font-size: 11px; color: var(--muted); font-weight: 700; }
.third-pick.is-on { border-color: var(--accent-2); background: linear-gradient(90deg, rgba(25,211,197,.16), var(--surface)); }
.third-pick.is-on .pick-box { background: var(--accent-2); border-color: var(--accent-2); color: #04201d; }
.third-pick.is-disabled { opacity: .4; cursor: not-allowed; }
.third-pick .team__flag { width: 28px; height: 19px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 18px; }

/* ----------------------------- Bracket --------------------------------- */
/* El cuadro se rompe a todo el ancho de la ventana y se escala vía JS
   para que SIEMPRE quepa sin scroll horizontal. */
.bracket-scroll {
  position: relative;
  left: 50%;
  width: 100vw;
  margin-left: -50vw;
  overflow: hidden;
  padding: 10px 0 12px;
}
.bracket {
  --c: 18px;          /* unidad de los conectores */
  --tie-w: 168px;     /* ancho de cada llave */
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: calc(var(--c) * 2);
  width: max-content;
  padding: 6px 20px;
  transform-origin: top left;
}
.half { display: flex; gap: calc(var(--c) * 2); }
.col { display: flex; flex-direction: column; min-width: var(--tie-w); }
.round__title {
  text-align: center; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--muted); font-weight: 700; height: 22px; line-height: 22px; margin-bottom: 12px;
}
.matches { flex: 1; display: flex; flex-direction: column; }
.mcell { flex: 1; display: flex; align-items: center; position: relative; }
.mcell > .tie { width: 100%; }

/* Conectores tipo "llave" */
.conn { position: absolute; top: 0; height: 100%; width: calc(var(--c) * 2); pointer-events: none; }
.conn.l { left: calc(var(--c) * -2); }
.conn.r { right: calc(var(--c) * -2); transform: scaleX(-1); }
.conn i { position: absolute; background: var(--line); }
.conn .v  { left: var(--c); width: 2px; top: 25%; height: 50%; }      /* vertical entre el par */
.conn .hm { left: var(--c); width: var(--c); top: 50%; height: 2px; } /* hacia el padre */
.conn .ht { left: 0; width: var(--c); top: 25%; height: 2px; }        /* hacia hijo superior */
.conn .hb { left: 0; width: var(--c); top: 75%; height: 2px; }        /* hacia hijo inferior */

/* Columna central: copa + final + tercer puesto */
.center-col { display: flex; flex-direction: column; justify-content: center; align-items: center; min-width: 200px; gap: 14px; }
.champ-box {
  width: 170px; text-align: center; padding: 14px 12px;
  border: 2px solid var(--gold); border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,207,77,.14), rgba(255,51,102,.08));
  box-shadow: 0 0 0 4px rgba(255,207,77,.08), var(--shadow);
}
.champ-box__cup { font-size: 40px; line-height: 1; filter: drop-shadow(0 4px 10px rgba(0,0,0,.5)); }
.champ-box__label { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold); margin-top: 4px; }
.champ-box__name { font-size: 17px; font-weight: 800; margin-top: 2px; }
.center-final { position: relative; width: var(--tie-w); }
.center-final .tie { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(255,207,77,.3), var(--shadow); }
.center-final::before, .center-final::after {
  content: ''; position: absolute; top: 50%; width: calc(var(--c) * 2); height: 2px; background: var(--line);
}
.center-final::before { left: calc(var(--c) * -2); }
.center-final::after { right: calc(var(--c) * -2); }
.center-third { width: var(--tie-w); }
.center-third .round__title { margin-bottom: 6px; }

.tie {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.tie__meta {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 10px; font-size: 10px; color: var(--muted);
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.tie__no { font-weight: 700; letter-spacing: .5px; }
.tie__slot {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px;
  padding: 9px 11px; cursor: pointer; border: none; width: 100%;
  background: transparent; color: var(--text); font-size: 13px; text-align: left;
  border-bottom: 1px solid var(--line);
  transition: background .15s;
}
.tie__slot:last-child { border-bottom: none; }
.tie__slot:hover:not(.is-empty) { background: var(--surface-2); }
.tie__slot .team__flag { width: 26px; height: 17px; }
.tie__slot .slot-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tie__slot.is-empty { color: var(--muted); cursor: default; font-style: italic; }
.tie__slot.is-winner {
  background: linear-gradient(90deg, rgba(25,211,197,.22), transparent);
  font-weight: 800;
}
.tie__slot.is-winner::after { content: "✓"; color: var(--win); font-weight: 800; }
.tie__slot.is-loser { opacity: .45; }

.champion-chip {
  display: flex; flex-direction: column; align-items: flex-end;
  background: linear-gradient(135deg, rgba(255,207,77,.18), rgba(255,51,102,.12));
  border: 1px solid var(--gold); border-radius: 12px; padding: 8px 16px;
}
.champion-chip span { font-size: 11px; color: var(--gold); letter-spacing: 1px; text-transform: uppercase; }
.champion-chip strong { font-size: 18px; }

.btn--sm { padding: 7px 11px; font-size: 12px; }
.btn--danger { border-color: rgba(255,51,102,.5); color: #ff7d9c; background: rgba(255,51,102,.08); }
.btn--danger:hover { border-color: var(--accent); color: #fff; background: rgba(255,51,102,.2); }
.btn--locked { border-color: var(--gold); color: var(--gold); background: rgba(255,207,77,.1); }

.board-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: #04201d; background: var(--accent-2); padding: 5px 10px; border-radius: 999px;
}
#adminBtn.is-on { border-color: var(--accent-2); color: var(--accent-2); }

.board-card__del {
  position: absolute; top: 10px; right: 10px;
  width: 26px; height: 26px; border-radius: 8px; line-height: 1;
  border: 1px solid rgba(255,51,102,.5); background: rgba(255,51,102,.12); color: #ff7d9c;
  cursor: pointer; font-size: 13px; display: grid; place-items: center; z-index: 2;
}
.board-card__del:hover { background: var(--accent); color: #fff; }
.board-card { position: relative; }
.lock-tag { font-size: 12px; color: var(--gold); }

/* -------------------------------- Tablero ------------------------------ */
.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.board-card {
  text-align: left;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  color: var(--text);
  transition: transform .12s, border-color .2s, box-shadow .2s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.board-card:hover { transform: translateY(-2px); border-color: var(--accent-2); box-shadow: var(--shadow); }
.board-card.is-current { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(255,207,77,.3); }
.board-card__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.board-card__name { font-weight: 800; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-card__date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.board-card__champ {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 13px;
}
.board-card__champ img { width: 26px; height: 17px; border-radius: 3px; object-fit: cover; }
.board-card__champ .lbl { font-size: 10px; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; }
.board-card__champ b { font-weight: 700; }
.board-card__progress { display: flex; gap: 8px; }
.chip {
  font-size: 11px; padding: 4px 9px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}
.chip.ok { color: #04201d; background: var(--accent-2); border-color: var(--accent-2); }

/* --------------------------------- Toast ------------------------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--accent-2);
  color: var(--text); padding: 12px 20px; border-radius: 12px;
  box-shadow: var(--shadow); font-size: 14px; z-index: 50;
  animation: fade .2s ease;
}

/* ------------------------------ Responsive ----------------------------- */
@media (max-width: 640px) {
  .panel__head h1 { font-size: 21px; }
  .user-box input { width: 120px; }
  .step { min-width: 0; font-size: 12px; padding: 9px 8px; }
  .step span { display: none; }
  .bracket { --c: 12px; --tie-w: 150px; }
  .champ-box { width: 150px; }
}
