:root {
  --bg: #0e0f1a;
  --panel: #171929;
  --panel-2: #1f2236;
  --border: #2c3050;
  --text: #e8e9f3;
  --muted: #9095b5;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --win: #34d399;
  --loss: #f87171;
  --draw: #fbbf24;
  --silver: #c0c7d4;
  --gold: #facc15;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; color: var(--muted); font-weight: 600; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem 1.25rem;
  background: rgba(14, 15, 26, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
nav { display: flex; gap: .25rem; flex-wrap: wrap; }
nav a { color: var(--muted); padding: .35rem .7rem; border-radius: 8px; }
nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
nav a.active { color: var(--text); background: var(--accent); }
.menu-btn { display: none; margin-left: auto; background: none; border: 0; color: var(--text); font-size: 1.4rem; cursor: pointer; }

main { max-width: 1150px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.kpi .v { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; min-width: 0; }
.card + .card { margin-top: 1rem; }
.grid > .card + .card { margin-top: 0; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

form.inline { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
label { display: grid; gap: .3rem; font-size: .85rem; color: var(--muted); }
input, select, textarea {
  width: 100%;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .55rem .65rem; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=color] { padding: .2rem; height: 2.4rem; }
button, .btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: .6rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
button.danger { background: transparent; border: 1px solid var(--loss); color: var(--loss); }
button.sm { padding: .3rem .6rem; font-size: .8rem; }

.avatar {
  display: inline-grid; place-items: center;
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  font-weight: 800; font-size: .8rem; color: #fff; flex: none;
}
.avatar.lg { width: 4rem; height: 4rem; font-size: 1.5rem; }
.pl { display: inline-flex; align-items: center; gap: .5rem; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--panel-2); border: 1px solid var(--border); }
.badge.win { color: var(--win); border-color: var(--win); }
.badge.loss { color: var(--loss); border-color: var(--loss); }
.badge.draw { color: var(--draw); border-color: var(--draw); }
.badge.live { color: var(--accent-2); border-color: var(--accent-2); }
.tier { font-weight: 700; }
.tier-silver { color: var(--silver); }
.tier-gold { color: var(--gold); }

.match-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: .75rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.match-row:last-child { border-bottom: 0; }
.match-row .right { justify-self: end; }
.score { font-weight: 800; font-size: 1.1rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.winner { font-weight: 700; }
.loser { opacity: .6; }

.bracket { display: flex; gap: 1.5rem; overflow-x: auto; padding-bottom: .5rem; }
.bracket-round { display: flex; flex-direction: column; justify-content: space-around; gap: .75rem; min-width: 230px; }
.slot { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.slot .side { display: flex; justify-content: space-between; gap: .5rem; padding: .45rem .65rem; }
.slot .side + .side { border-top: 1px solid var(--border); }
.slot .side.won { background: rgba(52, 211, 153, .12); font-weight: 700; }
.slot .tbd { color: var(--muted); font-style: italic; }
.slot form { display: flex; gap: .35rem; padding: .45rem; border-top: 1px solid var(--border); }
.slot form input { padding: .3rem .4rem; }

.champion { text-align: center; padding: 1.25rem; background: linear-gradient(135deg, rgba(124,92,255,.25), rgba(34,211,238,.15)); border: 1px solid var(--accent); border-radius: var(--radius); margin-bottom: 1rem; }
.champion .big { font-size: 1.5rem; font-weight: 800; }

.h2h { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; text-align: center; align-items: center; }
.h2h .big { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--panel-2); margin-top: 1rem; }
.bar > div { height: 100%; }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .35rem; max-height: 220px; overflow: auto; padding: .5rem; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; }
.checks label { display: flex; flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
.checks input { width: auto; }

.empty { color: var(--muted); text-align: center; padding: 1.5rem; }

#toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(150%);
  background: var(--panel-2); border: 1px solid var(--border); padding: .7rem 1.1rem; border-radius: 10px;
  transition: transform .25s; max-width: calc(100% - 2rem);
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--loss); color: var(--loss); }

@media (max-width: 760px) {
  .menu-btn { display: block; }
  .topbar { flex-wrap: wrap; }
  nav { display: none; width: 100%; flex-direction: column; }
  body.nav-open nav { display: flex; }
  .h2h .big { font-size: 2.2rem; }
}

.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.slot form { flex-direction: column; }
.slot-inputs { display: flex; gap: .35rem; align-items: center; }
.slot-inputs[hidden] { display: none; }
.slot-label { font-size: .75rem; color: var(--muted); }
.slot-detail { font-size: .75rem; color: var(--muted); padding: .3rem .65rem; border-top: 1px solid var(--border); }
tr.qualifies td:first-child { box-shadow: inset 3px 0 0 var(--win); }
details summary { cursor: pointer; }
[hidden] { display: none !important; }

/* Formulario de partida (1 vs 1 y multijugador) */
.form-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.mp-players { margin-top: .75rem; display: grid; gap: .5rem; }
.mp-head, .mp-row { display: grid; grid-template-columns: 1.5rem minmax(0, 2fr) minmax(0, 1fr) 5.5rem; gap: .5rem; align-items: center; }
.mp-n { color: var(--muted); font-size: .85rem; text-align: center; }
.row select { width: auto; }

/* Partidas multijugador en listados */
.match-row.multi { display: block; }
.multi-players { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; margin-bottom: .35rem; }
.multi-entry { display: inline-flex; align-items: center; gap: .4rem; opacity: .75; }
.multi-entry.winner { opacity: 1; font-weight: 700; }
.multi-entry .place { min-width: 1.4rem; text-align: center; }

@media (max-width: 560px) {
  .mp-head { display: none; }
  .mp-row { grid-template-columns: 1.2rem 1fr 4.5rem; }
  .mp-row input { grid-column: 2; }
}

.mp-place { font-weight: 700; color: var(--muted); white-space: nowrap; }
.mp-place.first { color: var(--gold); }

/* Partidas por equipos */
.teams { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; }
.team-box { display: grid; gap: .5rem; padding: .85rem; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; }
.team-box h3 { margin: 0; }
.vs-sep { font-weight: 800; color: var(--muted); text-align: center; padding-top: 1.5rem; }
.team-side { display: flex; flex-direction: column; gap: .35rem; }
.team-side.right { align-items: flex-end; }
.team-side.loser { opacity: .6; }
.team-side.winner { font-weight: 700; }

@media (max-width: 560px) {
  .teams { grid-template-columns: 1fr; }
  .vs-sep { padding: 0; }
}

.form-grid > label, .form-grid input { min-width: 0; }
td.num { white-space: nowrap; }

/* Visitantes (sin sesión de administrador): solo lectura */
body:not(.admin) .admin-only { display: none !important; }

img.avatar { object-fit: cover; background: var(--panel-2); }
.btn { display: inline-block; text-decoration: none; }
.btn:hover { text-decoration: none; filter: brightness(1.1); }
.btn.sm, a.sm { padding: .3rem .6rem; font-size: .8rem; }
.nowrap { white-space: nowrap; }
.card.warn { border-color: var(--draw); color: var(--draw); margin-bottom: 1rem; }
code { font-size: .85em; background: var(--panel-2); padding: .1rem .35rem; border-radius: 4px; }

/* Foto de perfil editable (solo administrador) */
#app:not(.editing) .avatar-overlay, #app:not(.editing) .avatar-del { display: none; }
.avatar-edit { position: relative; display: inline-block; flex: none; }
.avatar-overlay { position: absolute; inset: 0; border-radius: 50%; cursor: pointer; transition: background .15s; }
.avatar-overlay:hover, .avatar-overlay:focus-within { background: rgba(0, 0, 0, .45); }
.avatar-overlay input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.avatar-overlay:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar-cam {
  position: absolute; right: -4px; bottom: -4px; width: 1.7rem; height: 1.7rem; border-radius: 50%;
  display: grid; place-items: center; font-size: .8rem; background: var(--accent); border: 2px solid var(--bg);
}
.avatar-del {
  position: absolute; top: -6px; right: -6px; width: 1.5rem; height: 1.5rem; padding: 0; border-radius: 50%;
  font-size: .7rem; line-height: 1; background: var(--panel-2); color: var(--loss); border: 1px solid var(--loss);
}
.avatar-edit.uploading { opacity: .5; pointer-events: none; }

/* Sin sesión: solo la pantalla de acceso */
body:not(.logged) #nav, body:not(.logged) .menu-btn { display: none !important; }
.auth-wrap { min-height: 70vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { margin-top: .25rem; }
.auth-brand { font-weight: 800; color: var(--muted); }

/* Menú: separador y campana de avisos */
.nav-sep { width: 1px; background: var(--border); margin: .2rem .35rem; }
.bell { position: relative; }
.bell-count {
  position: absolute; top: -2px; right: -2px; min-width: 1.1rem; height: 1.1rem; padding: 0 .25rem;
  border-radius: 999px; background: var(--loss); color: #fff; font-size: .7rem; font-weight: 700;
  display: grid; place-items: center;
}
.bell-count[hidden] { display: none; }

/* Avisos */
.notice { padding: .7rem .2rem; border-bottom: 1px solid var(--border); }
.notice:last-child { border-bottom: 0; }
.notice.unread { border-left: 3px solid var(--accent); padding-left: .6rem; }

/* Forma (últimos 5) y cruces propios */
.form { display: inline-flex; gap: .2rem; }
.form .badge { padding: .05rem .35rem; font-size: .7rem; }
.kpi .form .badge { font-size: .85rem; padding: .1rem .45rem; }
.slot.mine { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2); }
.card.mods { margin-top: 1rem; padding: .8rem 1.1rem; }
code.invite { font-size: 1.15rem; padding: .35rem .7rem; letter-spacing: .05em; }

@media (max-width: 760px) {
  .nav-sep { width: auto; height: 1px; margin: .25rem 0; }
}

/* Con más opciones en el menú, se pasa al menú desplegable antes */
@media (max-width: 1100px) {
  .menu-btn { display: block; }
  .topbar { flex-wrap: wrap; }
  nav { display: none; width: 100%; flex-direction: column; }
  body.nav-open nav { display: flex; }
  .nav-sep { width: auto; height: 1px; margin: .25rem 0; }
}
.bell-label { display: none; }
@media (max-width: 1100px) {
  .bell-label { display: inline; }
  .bell-count { position: static; display: inline-grid; margin-left: .4rem; vertical-align: middle; }
}
