:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d1b17;
  --muted: #6b665c;
  --line: #e6e1d6;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #e0e9ff;
  --win: #15803d;
  --win-soft: #dcfce7;
  --loss: #b91c1c;
  --loss-soft: #fee2e2;
  --doubt: #a16207;
  --doubt-soft: #fef3c7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14130f; --card: #1f1d18; --ink: #f2efe8; --muted: #a8a294; --line: #343128;
    --accent: #7aa2ff; --accent-ink: #0b1220; --accent-soft: #1b2745;
    --win: #4ade80; --win-soft: #14301f; --loss: #f87171; --loss-soft: #3a1717;
    --doubt: #fbbf24; --doubt-soft: #3a2f10;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14130f; --card: #1f1d18; --ink: #f2efe8; --muted: #a8a294; --line: #343128;
  --accent: #7aa2ff; --accent-ink: #0b1220; --accent-soft: #1b2745;
  --win: #4ade80; --win-soft: #14301f; --loss: #f87171; --loss-soft: #3a1717;
  --doubt: #fbbf24; --doubt-soft: #3a2f10; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }
h2 { font-size: 1rem; margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Cabecera */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.equipo-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0;
  background: none; border: 0; padding: 0; cursor: pointer; text-align: left; width: 100%;
}
.equipo-nombre { font-size: 1.25rem; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.equipo-nombre::after { content: "▾"; font-size: .9rem; color: var(--muted); }
.equipo-cat { font-size: .85rem; color: var(--muted); }

main { max-width: 640px; margin: 0 auto; padding: 14px 16px 24px; }
.vista { display: none; }
.vista.activa { display: block; }

/* Tarjetas */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.etiqueta { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--ink);
}
.chip.win { background: var(--win-soft); color: var(--win); }
.chip.loss { background: var(--loss-soft); color: var(--loss); }
.chip.aviso { background: var(--loss-soft); color: var(--loss); }

.prox-rival { font-size: 1.35rem; font-weight: 700; margin: 2px 0 6px; line-height: 1.2; }
.prox-cuando { font-size: 1.05rem; font-weight: 600; }
.prox-cuando .hora { color: var(--accent); }
.filas { display: grid; gap: 8px; margin-top: 12px; }
.fila { display: flex; gap: 10px; align-items: center; font-size: .95rem; }
.fila svg { width: 18px; height: 18px; flex: none; stroke: var(--muted); fill: none; stroke-width: 1.8; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); flex: none; }
a { color: var(--accent); }

.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.sec { background: transparent; color: var(--ink); border-color: var(--line); }
.btn:disabled { opacity: .5; cursor: default; }

/* Resultado grande */
.marcador-final { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.marcador-final .eq { flex: 1; font-weight: 600; }
.marcador-final .eq.der { text-align: right; }
.marcador-final .num { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Lista partidos */
.jornada { display: grid; grid-template-columns: 44px 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line); }
.jornada:last-child { border-bottom: 0; }
.jornada .j { font-weight: 700; color: var(--muted); font-size: .85rem; }
.jornada .vs { font-weight: 600; line-height: 1.25; }
.jornada .meta { grid-column: 2 / 4; font-size: .82rem; color: var(--muted); }
.jornada .res { font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.jornada.propio .vs b { color: var(--accent); }
.res.win { color: var(--win); } .res.loss { color: var(--loss); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; cursor: pointer; min-height: 40px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Tabla */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 4px; text-align: center; border-bottom: 1px solid var(--line); font-size: .92rem; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
td.eq, th.eq { text-align: left; }
td.pts { font-weight: 800; }
tr.ampa td { background: var(--accent-soft); }
tr.yo td { background: var(--accent-soft); font-weight: 700; }
tr.yo td.eq::before { content: "● "; color: var(--accent); }

/* Convocatoria */
.conv-cuenta { display: flex; gap: 8px; margin: 4px 0 12px; }
.conv-cuenta span { flex: 1; text-align: center; border-radius: 10px; padding: 8px 4px; font-weight: 700; }
.c-si { background: var(--win-soft); color: var(--win); }
.c-no { background: var(--loss-soft); color: var(--loss); }
.c-duda { background: var(--doubt-soft); color: var(--doubt); }
.conv-form { display: grid; gap: 8px; }
.conv-form input {
  min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px;
  background: var(--bg); color: var(--ink); font: inherit; width: 100%;
}
.conv-opc { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.conv-opc button { min-height: 48px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); font-weight: 700; cursor: pointer; }
.conv-opc button[data-r="si"].on { border-color: var(--win); background: var(--win-soft); color: var(--win); }
.conv-opc button[data-r="no"].on { border-color: var(--loss); background: var(--loss-soft); color: var(--loss); }
.conv-opc button[data-r="duda"].on { border-color: var(--doubt); background: var(--doubt-soft); color: var(--doubt); }
.conv-lista { list-style: none; padding: 0; margin: 12px 0 0; }
.conv-lista li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.conv-lista li:last-child { border-bottom: 0; }
.conv-lista .tag { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.conv-lista .nota { color: var(--muted); font-size: .85rem; }
.conv-lista .x { margin-left: auto; border: 0; background: none; color: var(--loss); cursor: pointer; font-size: .85rem; min-height: 32px; }

/* Selector de equipo */
dialog { border: 0; border-radius: var(--radius); padding: 18px; width: min(92vw, 420px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.lista-equipos { display: grid; gap: 8px; margin-bottom: 14px; }
.lista-equipos button {
  text-align: left; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer; min-height: 52px;
}
.lista-equipos button.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.lista-equipos b { display: block; }
.lista-equipos span { font-size: .85rem; color: var(--muted); }

/* Pestañas */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: .72rem; color: var(--muted); cursor: pointer;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.activa { color: var(--accent); font-weight: 700; }

/* Marcador */
.sb { display: grid; gap: 10px; }
.sb-sets { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.sb-sets span { font-size: .85rem; padding: 3px 9px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); }
.sb-sets span.act { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.sb-campo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sb-lado {
  border-radius: 18px; border: 0; cursor: pointer; padding: 14px 8px 18px; min-height: 46vh;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  background: var(--card); box-shadow: var(--shadow); outline: 1px solid var(--line);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.sb-lado.a { background: var(--accent); color: var(--accent-ink); outline: 0; }
.sb-nombre { font-weight: 700; font-size: 1rem; text-align: center; line-height: 1.2; min-height: 2.4em; }
.sb-puntos { font-size: clamp(5rem, 28vw, 9rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.sb-setsg { font-size: .9rem; font-weight: 600; opacity: .85; }
.sb-saque { font-size: .8rem; font-weight: 700; min-height: 1.2em; }
.sb-ctrl { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sb-ctrl button { min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: .85rem; font-weight: 600; }
.sb-menos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sb-menos button { min-height: 40px; border-radius: 10px; border: 1px dashed var(--line); background: transparent; cursor: pointer; color: var(--muted); }
.sb-fin { text-align: center; }
.sb-fin .grande { font-size: 1.6rem; font-weight: 800; }
.sb-cfg { display: grid; gap: 10px; }
.sb-cfg label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.sb-cfg input, .sb-cfg select { min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--bg); color: var(--ink); font: inherit; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw;
}
#toast.on { opacity: 1; }
.pie { text-align: center; font-size: .75rem; color: var(--muted); margin-top: 18px; }
@media (min-width: 700px) { .sb-lado { min-height: 380px; } }

.buscar { width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px;
  background: var(--bg); color: var(--ink); font: inherit; margin-bottom: 12px; }
.lista-equipos { max-height: 55vh; overflow-y: auto; }
.lista-equipos .grupo-tit { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 6px 2px 0; }
.fav { border: 0; background: none; cursor: pointer; font-size: 1.4rem; line-height: 1; color: var(--muted); min-width: 44px; min-height: 44px; }
.fav.on { color: #f59e0b; }
.top { display: flex; align-items: center; gap: 8px; }
.top .equipo-btn { flex: 1; min-width: 0; }
.equipo-nombre { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.favs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px 0; max-width: 640px; margin: 0 auto; scrollbar-width: none; }
.favs button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: .82rem; cursor: pointer; min-height: 36px; }
.favs button.on { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.bienvenida { text-align: center; padding: 28px 16px; }
.bienvenida h1 { font-size: 1.5rem; margin: 8px 0 6px; }
.sb-mas2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sb-mas2 button { min-height: 44px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--ink); cursor: pointer; font-weight: 700; }
.buscar:focus, .sb-cfg input:focus, .sb-cfg select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
