:root, :root[data-theme="dark"] {
  --bg: #0f1720; --panel: #18222e; --panel2: #1c2a3a; --line: #2a3a4a;
  --ink: #e8eef4; --muted: #8aa0b4;
  --accent: #18b07a; --accent2: #5aa3ff; --warn: #e0a000; --err: #e0533d;
  --ctl: #243240; --chip: #20303f; --row-alt: rgba(255,255,255,.035);
  --row-hover: rgba(255,255,255,.06);
  --ok-bg: #10362a; --err-bg: #3a1d18; --warn-bg: #3a3110;
  --btn-ink: #04130d; --shadow: rgba(0,0,0,.35);
}
:root[data-theme="light"] {
  --bg: #eef2f6; --panel: #ffffff; --panel2: #f3f7fb; --line: #d6dee7;
  --ink: #16222e; --muted: #5c6b7a;
  --accent: #0c8f63; --accent2: #1668d6; --warn: #a06f00; --err: #c0392b;
  --ctl: #e4ebf2; --chip: #eaf0f6; --row-alt: rgba(15,40,70,.035);
  --row-hover: rgba(15,40,70,.07);
  --ok-bg: #e4f6ee; --err-bg: #fbe9e7; --warn-bg: #fbf3df;
  --btn-ink: #ffffff; --shadow: rgba(20,40,60,.12);
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5;
  transition: background-color .2s ease, color .2s ease;
}
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .7rem 1.2rem; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 400; font-size: 1.15rem; color: var(--ink); display: flex; align-items: center; gap: .55rem; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 34px; height: 34px; object-fit: contain; }
.brand strong { color: var(--accent); }
.topbar nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.topbar nav .who { color: var(--accent); font-weight: 600; }
.topbar nav .adm { color: var(--warn); font-size: .9rem; }
.poolsel { display: inline-flex; align-items: center; gap: .3rem; }
.poolsel .poollbl { color: var(--muted); font-size: .85rem; }
.poolsel select {
  background: var(--ctl); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: .2rem .4rem; font-size: .9rem; max-width: 11rem;
}
.theme-toggle {
  background: var(--ctl); color: var(--ink); border: 1px solid var(--line);
  padding: .15rem .5rem; border-radius: 8px; font-size: 1rem; line-height: 1.4; cursor: pointer;
}
.theme-toggle:hover { filter: brightness(1.1); }

main { max-width: 980px; margin: 0 auto; padding: 1.5rem 1.2rem 2rem; }
.site-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem 1rem 2.5rem; }
h1 { margin-top: .2rem; }
h2 { margin-top: 2rem; border-bottom: 1px solid var(--line); padding-bottom: .3rem; }
h3.grp { margin: 1.2rem 0 .3rem; color: var(--accent); font-size: 1rem; }
.lead { color: var(--muted); max-width: 70ch; }
.muted { color: var(--muted); }

.flash { padding: .6rem 1rem; border-radius: 8px; margin: .5rem 0; border: 1px solid var(--line); }
.flash.ok { background: var(--ok-bg); border-color: var(--accent); }
.flash.error, .flash.err { background: var(--err-bg); border-color: var(--err); }
.flash.warn { background: var(--warn-bg); border-color: var(--warn); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; margin-top: 1.2rem; }
@media (max-width: 720px) { .cols { grid-template-columns: 1fr; } }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.2rem; box-shadow: 0 1px 3px var(--shadow);
}
.card h2 { margin-top: .2rem; border: none; }

.form { display: flex; flex-direction: column; gap: .8rem; max-width: 380px; }
.form.wide { max-width: 560px; }
.form label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); }
.form input {
  padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 1rem;
}
button {
  background: var(--accent); color: var(--btn-ink); border: none; font-weight: 700;
  padding: .6rem 1.1rem; border-radius: 8px; cursor: pointer; font-size: 1rem;
}
button:hover { filter: brightness(1.08); }

table { width: 100%; border-collapse: collapse; }
.ranking th, .ranking td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
.ranking thead th {
  color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 2px solid var(--line);
}
.ranking th.num, .ranking td.num { text-align: right; font-variant-numeric: tabular-nums; }
.ranking td.num { font-weight: 700; }
.ranking tbody tr:nth-child(even) td { background: var(--row-alt); }
.ranking tbody tr:hover td { background: var(--row-hover); }
.ranking tbody td:first-child { color: var(--muted); width: 2.2rem; text-align: right; }
/* Tablas cuya 1ª columna es un nombre (no un nº de posición): ancho normal, a la izquierda. */
.ranking.namecol tbody td:first-child { color: var(--ink); width: auto; text-align: left; white-space: nowrap; }
.ranking.big td, .ranking.big th { padding: .6rem .7rem; }
/* Tabla de puntuación (normas): ocupa todo el ancho de la caja, sin estilo de "posición". */
.ranking.scoring { width: 100%; }
.ranking.scoring td:first-child { width: auto; color: var(--ink); text-align: left; }
.ranking.scoring td.num { width: 3.5rem; }

.matchlist { list-style: none; padding: 0; }
.matchlist li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.matchlist .mn, .matches .mn { color: var(--muted); font-size: .8rem; margin-right: .3rem; }
.matchlist .when { display: block; color: var(--muted); font-size: .8rem; }
.matchlist em, .matches em { color: var(--muted); font-style: normal; }
.matchlist .res { font-variant-numeric: tabular-nums; margin: 0 .15rem; }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: .8rem; }
.pager .pageinfo { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.5rem; text-align: center; }
.pager button { padding: .4rem .8rem; font-size: .9rem; }
.pager button:disabled { opacity: .4; cursor: not-allowed; filter: none; }
.import-self { margin-bottom: 1.2rem; }
.import-form { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.import-form input[type=file] { flex: 1 1 16rem; color: var(--ink); }
.import-form select {
  background: var(--ctl); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: .45rem .5rem; font-size: 1rem; max-width: 16rem;
}

.matches td { padding: .25rem .3rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.matches .home { text-align: right; width: 32%; white-space: nowrap; }
.matches .away { text-align: left; width: 32%; white-space: nowrap; }
.matches .colon { color: var(--muted); }
.matches .sc { text-align: center; }
.matches .when { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.matches tr.locked { opacity: .7; }
.goal {
  width: 3rem; height: 2.6rem; text-align: center; padding: .35rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 1.25rem;
}
/* ocultar las flechas nativas (usamos botones − / + propios) */
.goal::-webkit-outer-spin-button, .goal::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.goal[type=number] { -moz-appearance: textfield; appearance: textfield; }
.goal.ro { display: inline-block; height: auto; border-style: dashed; }

/* Botones − / + grandes alrededor del marcador */
.stepper { display: inline-flex; align-items: stretch; height: 2.6rem; vertical-align: middle; }
.step {
  width: 2.1rem; min-width: 2.1rem; font-size: 1.4rem; line-height: 1; font-weight: 700;
  background: var(--ctl); color: var(--ink); border: 1px solid var(--line); cursor: pointer;
  padding: 0; user-select: none; touch-action: manipulation;
}
.step:hover { background: var(--accent); color: var(--btn-ink); }
.step:active { filter: brightness(.9); }
.step[data-step="-1"] { border-radius: 8px 0 0 8px; border-right: none; }
.step[data-step="1"] { border-radius: 0 8px 8px 0; border-left: none; }
.stepper .goal { border-radius: 0; height: 2.6rem; width: 2.5rem; }
.pen select { background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: .2rem; }
.matches.detail .ptn { text-align: right; font-variant-numeric: tabular-nums; }
.matches.detail .result { color: var(--muted); font-size: .85rem; }

.sticky-save {
  position: sticky; bottom: 0; padding: .8rem 0; margin-top: 1rem;
  background: linear-gradient(transparent, var(--bg) 40%); text-align: right;
}

/* Banderas */
.flag {
  width: 1.35em; height: 1em; object-fit: cover; vertical-align: -0.12em;
  border-radius: 2px; box-shadow: 0 0 0 1px var(--line);
}

/* Hero portada */
.hero {
  display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap;
  background: radial-gradient(circle at 0 0, var(--panel2), var(--panel));
  border: 1px solid var(--line); border-radius: 16px; padding: 1.4rem 1.6rem; margin-bottom: 1.5rem;
}
.hero-logo { width: 96px; height: 96px; flex-shrink: 0; object-fit: contain; }
.hero h1 { margin: 0 0 .2rem; }
.hero .hosts { display: flex; align-items: center; gap: .4rem; margin: .6rem 0; }
.hero .hosts .flag { width: 1.7em; height: 1.25em; }
.hero .cta { margin-bottom: 0; }
.btn {
  display: inline-block; background: var(--accent); color: #04130d; font-weight: 700;
  padding: .5rem 1rem; border-radius: 8px; margin-right: .6rem;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }

/* Etiquetas de grupo / ronda */
.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .5rem;
  border-radius: 999px; background: var(--chip); color: var(--muted); white-space: nowrap;
  border: 1px solid var(--line);
}
.badge.ko { background: transparent; color: var(--warn); border-color: var(--warn); }

/* Tabla de resultados cronológica */
.matches.chrono .time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: .9rem; }
.matches.chrono .grp-tag { text-align: center; }
.matches .dayhdr td {
  background: var(--panel2); color: var(--accent); font-weight: 700; font-size: .85rem;
  padding: .45rem .6rem; border-top: 1px solid var(--line);
  text-transform: capitalize; position: sticky; top: 0;
}
.matches .home .flag, .matches .away .flag { margin: 0 .25rem; }

/* Penaltis en resultados */
.penwrap { display: inline-flex; align-items: center; gap: .2rem; white-space: nowrap; }
.penwrap .penlbl { color: var(--muted); font-size: .75rem; margin-right: .15rem; }
.penwrap .pengoal { width: 2.4rem; padding: .25rem; }
.penwrap .colon { color: var(--muted); }
.penwrap.disabled { opacity: .4; }
.penwrap input:disabled, .penwrap button:disabled { cursor: not-allowed; }
/* La tanda de penaltis ocupa menos que el marcador principal: así la tabla de
   eliminatorias cabe en escritorio y no aparece scroll horizontal. */
.pen .stepper { height: 2.1rem; }
.pen .stepper .goal { width: 1.9rem; height: 2.1rem; font-size: 1rem; }
.pen .step { width: 1.6rem; min-width: 1.6rem; font-size: 1.05rem; }

/* Fair play */
.fpgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.fpcard { padding: .8rem 1rem; }
.fpcard h3.grp { margin: 0 0 .5rem; }
.fprow { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .25rem 0; }
.fprow .goal { width: 3rem; }

/* Checkbox de ajustes */
.form .check { flex-direction: row; align-items: center; gap: .5rem; color: var(--ink); font-size: 1rem; }
.form .check input { width: auto; }

/* Formularios en línea (gestión de usuarios) */
.inline-form { display: flex; gap: .4rem; align-items: center; margin: 0; }
.inline-form input[type="password"] {
  padding: .35rem .5rem; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); width: 8.5rem; font-size: .9rem;
}
.inline-form button { padding: .35rem .7rem; font-size: .85rem; }
button.danger { background: var(--err); color: #fff; }

.login { font-size: .85em; font-weight: 400; }

/* ---------- Responsive / móvil ---------- */
/* Contenedor para tablas anchas: scroll horizontal en lugar de romper la página. */
.tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

@media (max-width: 640px) {
  main { padding: 1rem .7rem 4rem; }
  .topbar { padding: .6rem .8rem; gap: .5rem; }
  .topbar nav { gap: .65rem; font-size: .95rem; }
  .brand { font-size: 1rem; }
  h2 { margin-top: 1.4rem; }
  h1 { font-size: 1.5rem; }
  .hero { padding: 1rem; gap: .8rem; }
  .hero-logo { width: 64px; height: 64px; }

  /* Tabla de partidos más compacta para que quepa (y, si no, que la tabla scrollee). */
  .matches td { padding: .2rem .25rem; }
  .matches .home, .matches .away { width: auto; font-size: .92rem; }
  .matches .when, .matches.chrono .time { font-size: .7rem; }
  .matches .mn { font-size: .72rem; margin-right: .15rem; }
  .goal { width: 2.4rem; height: 2.3rem; font-size: 1.05rem; padding: .2rem; }
  .stepper { height: 2.3rem; }
  .stepper .goal { width: 2.1rem; }
  .step { width: 1.9rem; min-width: 1.9rem; font-size: 1.2rem; }
  .penwrap .penlbl { display: none; }
  .flag { width: 1.2em; }

  /* Clasificación: ocultar el login entre paréntesis para ganar ancho. */
  .ranking .login { display: none; }
}
