:root {
  --ink: #14213d;
  --ink-2: #33415c;
  --muted: #6b7890;
  --paper: #eef1f5;
  --surface: #ffffff;
  --line: #d6dce6;
  --pitch: #1f7a4d;
  --pitch-soft: #e1f1e8;
  --gold: #d9a21b;
  --gold-soft: #fbf1d6;
  --danger: #b93a32;
  --danger-soft: #f8e3e1;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Source Sans 3", "Segoe UI", Arial, sans-serif;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8ecf3; --ink-2: #c3cad8; --muted: #8f9bb2;
    --paper: #0f1626; --surface: #18223a; --line: #2b3754;
    --pitch: #4fbf85; --pitch-soft: #173a2b; --gold: #f0c04a; --gold-soft: #3a3016;
    --danger: #ef7d74; --danger-soft: #3e1f22;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 var(--body); color: var(--ink); background: var(--paper); }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.05; margin: 0 0 .5rem; letter-spacing: .01em; }
h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); }
h2 { font-size: 1.7rem; }
h3 { font-size: 1.3rem; }
.muted { color: var(--muted); }
.loading { padding: 3rem; text-align: center; color: var(--muted); }

/* Barra superior */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 2.5rem); background: #14213d; color: #fff; }
.brand { display: flex; align-items: center; gap: .6rem; font: 700 1.5rem var(--display); text-decoration: none; }
.ball { width: 22px; height: 22px; border-radius: 50%; background:
  radial-gradient(circle at 50% 50%, #14213d 22%, transparent 23%), #fff; box-shadow: inset 0 0 0 2px #fff; }
#auth { display: flex; gap: .5rem; align-items: center; font-size: .95rem; }
#auth .btn { border-color: #53607c; color: #fff; background: transparent; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 4rem; }

/* Botones y formularios */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--pitch); border-color: var(--pitch); color: #fff; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #14213d; }
.btn.danger { color: var(--danger); }
.btn.small { padding: .2rem .6rem; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label { display: grid; gap: .25rem; font-size: .9rem; font-weight: 600; color: var(--ink-2); }
input, select { padding: .5rem .6rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-width: 0; }
input[type="checkbox"] { width: 1.1rem; height: 1.1rem; }
.check { display: flex; align-items: center; gap: .5rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .9rem; align-items: end; }
.hint { font-size: .9rem; color: var(--muted); margin: .4rem 0 0; }
.hint.bad { color: var(--danger); }
.hint.ok { color: var(--pitch); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; margin-bottom: 1.5rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.spread { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: baseline; }

/* Portada */
.hero { padding: 1.5rem 0 2rem; max-width: 60ch; }
.hero p { font-size: 1.15rem; color: var(--ink-2); margin: 0; }
.t-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.t-item { display: block; padding: 1rem 1.1rem; background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--pitch); border-radius: 8px; text-decoration: none; }
.t-item:hover { border-color: var(--ink-2); }
.t-item h3 { margin-bottom: .2rem; }
.t-item[data-status="finished"] { border-left-color: var(--gold); }
.t-item[data-status="setup"] { border-left-color: var(--muted); }
.empty { padding: 2rem; text-align: center; border: 2px dashed var(--line); border-radius: 10px; color: var(--muted); }

/* Cabecera de torneo y etapas */
.t-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; align-items: end; margin-bottom: 1rem; }
.t-head p { margin: 0; color: var(--muted); }
.stages { display: flex; list-style: none; padding: 0; margin: 0 0 1.25rem; counter-reset: st; }
.stages li { flex: 1; counter-increment: st; padding: .45rem .7rem; font-size: .92rem; color: var(--muted);
  border-bottom: 3px solid var(--line); }
.stages li::before { content: counter(st) ". "; }
.stages li.done { color: var(--pitch); border-color: var(--pitch); }
.stages li.now { color: var(--ink); font-weight: 700; border-color: var(--gold); }
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; }
.tabs a { padding: .6rem 1rem; text-decoration: none; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); border-color: var(--ink); }

/* Equipos */
.team { display: inline-flex; align-items: center; gap: .45rem; min-width: 0; }
.team .tname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: .8rem; height: .8rem; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.captain { display: inline-block; width: 1.4rem; height: 1.4rem; line-height: 1.4rem; border-radius: 50%;
  background: var(--gold); color: #14213d; font: 700 .85rem var(--display); }
.good { color: var(--pitch); font-weight: 600; }
.bad { color: var(--danger); font-weight: 600; }
.link { background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; cursor: pointer; text-align: left; }
.notice { background: var(--danger-soft); border-left: 4px solid var(--danger); border-radius: 6px; padding: .6rem .9rem; margin: .75rem 0; }
.notice ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.modes { border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem .9rem; margin: .75rem 0; display: grid; gap: .35rem; }
.modes legend { font-weight: 700; padding: 0 .3rem; }
.rules ul { margin: .25rem 0 1rem; padding-left: 1.2rem; max-width: 75ch; }
.rules li { margin-bottom: .3rem; }
.spread.clickable { cursor: pointer; padding: .35rem; border-radius: 6px; }
.spread.clickable:hover { background: var(--paper); }
.code { font: 600 .8rem var(--display); letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 .3rem; }
.tbd { color: var(--muted); font-style: italic; }
.host { font-size: .75rem; background: var(--gold-soft); color: var(--ink); border-radius: 3px; padding: 0 .35rem; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .45rem .5rem; text-align: center; border-bottom: 1px solid var(--line); }
th { font: 600 .95rem var(--display); color: var(--muted); letter-spacing: .03em; }
td.l, th.l { text-align: left; }
td.pts { font-weight: 700; }
tr.q td:first-child { box-shadow: inset 4px 0 var(--pitch); }
.groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1.25rem; }
.groups .panel { margin: 0; padding: 1rem; }
.form { display: inline-flex; gap: 2px; }
.form i { width: 16px; height: 16px; border-radius: 3px; font: 600 .65rem/16px var(--body); font-style: normal; color: #fff; }
.form .G { background: var(--pitch); } .form .E { background: #8a94a8; } .form .P { background: var(--danger); } .form .W { background: #5b1f1b; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .88rem; color: var(--muted); margin-top: .75rem; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: .35rem; border-radius: 2px; background: var(--pitch); }

/* Marcadores (elemento distintivo) */
.score { display: inline-flex; align-items: center; gap: 2px; font: 700 1.35rem/1 var(--display); }
.score b { display: inline-block; min-width: 1.6rem; padding: .22rem .3rem; text-align: center; background: #14213d; color: #ffd466; border-radius: 3px; }
.score.pending b { background: transparent; color: var(--muted); border: 1px dashed var(--line); }
.pens { font-size: .8rem; color: var(--muted); display: block; text-align: center; }

.match-list { display: grid; gap: .5rem; }
.day-title { font: 600 1.05rem var(--display); color: var(--muted); margin: 1.25rem 0 .25rem; }
.match { display: grid; grid-template-columns: 5.5rem 1fr auto 1fr 9rem; align-items: center; gap: .75rem;
  padding: .6rem .9rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.match .home { justify-self: end; }
.match .meta { font-size: .85rem; color: var(--muted); }
.match .where { font-size: .85rem; color: var(--muted); text-align: right; }
.match.clickable { cursor: pointer; }
.match.clickable:hover { border-color: var(--ink-2); }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.filters label { display: flex; align-items: center; gap: .4rem; }

/* Cuadro eliminatorio */
.bracket { display: flex; gap: 1.5rem; overflow-x: auto; padding-bottom: 1rem; }
.round { display: flex; flex-direction: column; min-width: 230px; }
.round h3 { text-align: center; }
.round .slots { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: .75rem; }
.ko { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ko .line { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .4rem .6rem; }
.ko .line + .line { border-top: 1px solid var(--line); }
.ko .line.win { font-weight: 700; background: var(--pitch-soft); }
.ko .goals { font: 700 1.15rem var(--display); min-width: 2.2rem; text-align: right; }
.ko .goals small { font-size: .75rem; color: var(--muted); font-weight: 600; }
.ko .foot { padding: .2rem .6rem; font-size: .78rem; color: var(--muted); background: var(--paper); }
.ko.clickable { cursor: pointer; }
.ko.clickable:hover { border-color: var(--ink-2); }
.ko.final { border: 2px solid var(--gold); }

.champion { display: flex; align-items: center; gap: 1.25rem; padding: 1.25rem 1.5rem; margin-bottom: 1.5rem;
  background: #14213d; color: #fff; border-radius: 10px; }
.champion .trophy { font-size: 3.2rem; }
.champion h2 { font-size: 2.6rem; margin: 0; color: #ffd466; }
.champion p { margin: 0; color: #c3cad8; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.stat strong { display: block; font: 700 2rem/1 var(--display); }
.stat span { color: var(--muted); font-size: .92rem; }

details.squad { border-top: 1px solid var(--line); }
details.squad summary { cursor: pointer; padding: .5rem 0; color: var(--ink-2); }

/* Modal y avisos */
dialog { border: none; border-radius: 12px; padding: 0; width: min(640px, 94vw); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 16, 30, .6); }
#modal-body { padding: 1.4rem; }
.scoreline { display: grid; grid-template-columns: 1fr auto auto auto 1fr; gap: .6rem; align-items: center; margin: 1rem 0; }
.scoreline input { width: 4rem; text-align: center; font: 700 1.6rem var(--display); }
.scoreline .team:first-child { justify-self: end; }
.events { list-style: none; padding: 0; margin: .5rem 0; }
.events li { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.card-y, .card-b, .card-r { display: inline-block; width: 10px; height: 14px; border-radius: 2px; background: #f2c400; vertical-align: -2px; }
.card-r { background: #d8322a; }
.card-b { background: #1e6fd9; }
.pens.wo { color: var(--danger); font-weight: 600; }
#toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 150%); max-width: 90vw;
  padding: .75rem 1.2rem; border-radius: 8px; background: #14213d; color: #fff; transition: transform .25s; z-index: 10; }
#toast.show { transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }

@media (max-width: 720px) {
  .match { grid-template-columns: 1fr auto 1fr; }
  .match .meta, .match .where { grid-column: 1 / -1; text-align: left; }
  .match .where { order: 5; }
  .stages li { font-size: .8rem; padding: .4rem .3rem; }
  .groups { grid-template-columns: 1fr; }
  .scoreline { grid-template-columns: 1fr auto 1fr; }
  .scoreline .dash { display: none; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* Avisos */
.topbar { position: relative; }
#auth { flex-wrap: wrap; justify-content: flex-end; }
#auth a.btn { border-color: #53607c; color: #fff; background: transparent; }
.bell .count { display: inline-block; min-width: 1.3rem; padding: 0 .3rem; border-radius: 999px;
  background: #ffd466; color: #14213d; font-size: .8rem; text-align: center; }
.feed { position: fixed; top: 3.6rem; right: clamp(.5rem, 3vw, 2.5rem); z-index: 20; width: min(400px, 94vw);
  max-height: 75vh; overflow-y: auto; padding: 1rem; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(10, 16, 30, .25); }
.feed-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.feed-item { display: grid; gap: .1rem; width: 100%; padding: .55rem .3rem; text-align: left; background: none;
  border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.feed-item:hover { background: var(--paper); }
.feed-item small { color: var(--muted); }

/* En vivo */
.live-badge { display: inline-flex; align-items: center; gap: .35rem; font: 600 .85rem var(--body); color: var(--danger); white-space: nowrap; }
.pulse { width: .55rem; height: .55rem; border-radius: 50%; background: var(--danger); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.score.live b { background: var(--danger); color: #fff; }
.match.is-live, .ref-card.is-live { border-color: var(--danger); box-shadow: inset 4px 0 var(--danger); }
.match.mine { box-shadow: inset 4px 0 var(--gold); }
.live-now { border-color: var(--danger); }
.live-panel { margin: 1rem 0; padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.timeline { list-style: none; padding: 0; margin: .6rem 0; display: grid; gap: .15rem; }
.timeline li { display: flex; justify-content: space-between; color: var(--muted); font-size: .92rem; }
.timeline li.done { color: var(--ink); }
.timeline li.done span:first-child::before { content: "✓ "; color: var(--pitch); }
.assign { display: flex; align-items: center; gap: .5rem; margin: .5rem 0; }
.btn.big { padding: .8rem 1.4rem; font-size: 1.1rem; }
.ref-teams { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; font-size: 1.25rem; font-weight: 700; margin: .6rem 0; }
code { font-size: .9em; background: var(--paper); padding: .05rem .3rem; border-radius: 3px; }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

/* Importación CSV */
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 3px solid var(--gold); outline-offset: 2px; }
ul.hint { padding-left: 1.2rem; }

/* Armado de grupos */
.draft-list { list-style: none; padding: 0; margin: 0; }
.draft-list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem;
  padding: .4rem 0; border-bottom: 1px solid var(--line); }
.draft-list select { max-width: 11rem; }

[hidden] { display: none !important; }

details.squad.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .75rem 1.25rem; margin-bottom: 1.5rem; }
details.squad.panel > summary { font-weight: 700; }
.schedule-box { margin-top: 1rem; }
