:root {
  --navy: #001e28;
  --navy-2: #0b2f3c;
  --red: #ff0046;
  --green: #0a9d58;
  --bg: #e9edef;
  --card: #fff;
  --line: #e6eaec;
  --soft: #f5f7f8;
  --text: #001e28;
  --muted: #6f8089;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }

/* ---------- Cabecera y pestañas ---------- */
.topbar { background: var(--navy); color: #fff; }
.topbar-in, .tabs-in { max-width: 720px; margin: 0 auto; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.brand { font-weight: 800; letter-spacing: .04em; font-size: 1.1rem; }
.brand b { color: var(--red); }
.top-actions { display: flex; gap: 8px; align-items: center; font-size: .85rem; }
.pill { border: 1px solid rgba(255, 255, 255, .35); padding: 6px 12px; border-radius: 99px; }
.pill.primary { background: var(--red); border-color: var(--red); font-weight: 700; }
.tabs { background: var(--navy); border-top: 1px solid rgba(255, 255, 255, .08); }
.tabs-in { display: flex; }
.tabs a {
  flex: 1; text-align: center; padding: 12px 8px; font-weight: 600; font-size: .9rem;
  color: rgba(255, 255, 255, .65); border-bottom: 3px solid transparent;
}
.tabs a.on { color: #fff; border-bottom-color: var(--red); }

.wrap {
  max-width: 720px; margin: 0 auto; background: var(--card);
  min-height: calc(100vh - 100px); box-shadow: 1px 0 0 var(--line), -1px 0 0 var(--line);
}

/* ---------- Mensajes ---------- */
.flash { margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.flash.error { background: #ffe8ee; color: #a3002d; }
.flash.ok { background: #e3f6ec; color: #0b6b3b; }

/* ---------- Filtros ---------- */
.filters { padding: 12px 16px 4px; display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  padding: 7px 14px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line);
  font-size: .85rem; font-weight: 600; white-space: nowrap;
}
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip .n { color: var(--red); margin-left: 6px; font-weight: 800; }
.chip.on .n { color: #fff; }
.teamfilter select, .form select, .form input, .form textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 1rem;
}

/* ---------- Listado de partidos ---------- */
.group {
  background: var(--soft); padding: 8px 16px; font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-top: 8px;
}
.group.live { color: var(--red); }
.mrow {
  display: grid; grid-template-columns: 64px 1fr auto; align-items: start; gap: 8px;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
}
.mrow:hover { background: var(--soft); }
.mtime {
  font-size: .75rem; color: var(--muted); text-align: center; font-weight: 600;
  height: 60px; display: flex; align-items: center; justify-content: center;
}
.mrow.live .mtime { color: var(--red); font-weight: 800; }
.mteam { display: flex; align-items: center; gap: 10px; height: 30px; }
.tname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mteam.lose .tname { color: var(--muted); font-weight: 500; }
.mscore { display: flex; flex-direction: column; text-align: right; font-weight: 800; font-size: 1.05rem; min-width: 22px; }
.mscore b { height: 30px; line-height: 30px; font-variant-numeric: tabular-nums; }
.mscore b.lose { color: var(--muted); font-weight: 600; }
.mrow.live .mscore { color: var(--red); }
.mround { font-size: .72rem; color: var(--muted); padding: 2px 0 0 38px; }
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red);
  margin-right: 5px; animation: pulse 1.3s infinite;
}
@keyframes pulse { 50% { opacity: .25; } }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.link { color: var(--red); font-weight: 700; }

/* ---------- Escudos (iniciales) ---------- */
.avatar {
  --s: 28px;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--s); height: var(--s); border-radius: 50%;
  background: hsl(var(--h), 55%, 42%); color: #fff; font-weight: 800;
  font-size: calc(var(--s) * .38); letter-spacing: .02em;
}
.avatar.xl { --s: 76px; }

/* ---------- Cabecera del partido ---------- */
.hero { background: var(--navy); color: #fff; padding: 16px 16px 0; }
.hero-meta { text-align: center; color: rgba(255, 255, 255, .65); font-size: .8rem; margin-bottom: 14px; }
.hero-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: start; padding-bottom: 18px; }
.hero-team { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; font-weight: 700; word-break: break-word; }
.hero-score { text-align: center; min-width: 120px; }
.hero-nums {
  display: flex; gap: 10px; justify-content: center; align-items: center; padding-top: 14px;
  font-size: 3.3rem; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums;
}
.hero-nums i { font-style: normal; color: rgba(255, 255, 255, .35); font-weight: 400; }
.hero-time { padding-top: 18px; font-size: 2rem; font-weight: 800; }
.hero-status { margin-top: 8px; font-size: .78rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: rgba(255, 255, 255, .7); }
.hero-status.live { color: var(--red); }
.bump { animation: bump .6s ease; }
@keyframes bump { 0% { transform: scale(1.4); color: var(--red); } 100% { transform: scale(1); } }
.hero-tabs { display: flex; border-top: 1px solid rgba(255, 255, 255, .1); margin: 0 -16px; }
.hero-tabs a {
  flex: 1; text-align: center; padding: 13px 8px; font-size: .85rem; font-weight: 700;
  color: rgba(255, 255, 255, .6); border-bottom: 3px solid transparent;
}
.hero-tabs a.on { color: #fff; border-bottom-color: var(--red); }

/* ---------- Paneles / controles ---------- */
.panel { padding: 16px; }
.panel + .panel { padding-top: 0; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ctl { border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; background: var(--soft); }
.ctl-name { font-weight: 700; margin-bottom: 10px; word-break: break-word; }
.btn-goal {
  display: block; width: 100%; padding: 22px 0; font-size: 1.3rem; font-weight: 800; border: 0;
  border-radius: 12px; background: var(--green); color: #fff; cursor: pointer;
}
.btn-goal:active { filter: brightness(.9); }
.btn-undo {
  display: block; width: 100%; margin-top: 10px; padding: 13px 0; border-radius: 12px;
  border: 1.5px solid var(--line); background: #fff; color: var(--red); font-weight: 700; cursor: pointer;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.hint { margin: 12px 0 0; font-size: .85rem; color: var(--muted); text-align: center; }
.notice { padding: 14px; border-radius: 12px; background: var(--soft); border: 1px dashed var(--line); color: var(--muted); text-align: center; }
.sect-title { margin: 0; padding: 16px 16px 8px; font-size: 1.1rem; }
.sect-title .count { color: var(--muted); font-weight: 500; font-size: .9rem; margin-left: 4px; }
.sect-title.flat { padding: 0 0 12px; }
.manage { display: flex; flex-wrap: wrap; gap: 10px; }
.manage form { margin: 0; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0;
  border-radius: 10px; padding: 12px 18px; font-weight: 700; cursor: pointer; text-align: center;
}
.btn.primary { background: var(--navy); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.red { background: var(--red); color: #fff; }
.btn.ghost { background: #fff; border: 1.5px solid var(--line); }
.btn.sm { padding: 8px 12px; font-size: .85rem; }
.btn.block { display: flex; width: 100%; padding: 16px; font-size: 1.05rem; }
.btn.danger-text { color: #c4002f; }

/* ---------- Formularios ---------- */
.form { padding: 16px; }
.form label { display: block; margin: 14px 0 6px; font-weight: 700; font-size: .85rem; }
.form label small { font-weight: 400; color: var(--muted); }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .actions { margin-top: 20px; display: flex; gap: 10px; }

/* ---------- Clasificación ---------- */
.table-wrap { overflow-x: auto; }
.stbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.stbl th {
  font-size: .7rem; color: var(--muted); font-weight: 700; text-transform: uppercase;
  padding: 10px 6px; border-bottom: 1px solid var(--line); text-align: center; background: var(--soft);
}
.stbl td { padding: 10px 6px; text-align: center; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.stbl th:first-child, .stbl td:first-child { padding-left: 16px; width: 44px; }
.stbl th:last-child, .stbl td:last-child { padding-right: 16px; }
.stbl .l { text-align: left; }
.stbl .teamcell { display: flex; align-items: center; gap: 10px; font-weight: 600; text-align: left; min-width: 120px; }
.stbl td.pts { font-weight: 800; font-size: 1rem; }
.stbl tr:hover td { background: var(--soft); }
.pos { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; align-items: center; justify-content: center; font-weight: 700; font-size: .8rem; }
.pos.first { background: var(--red); color: #fff; }
.dots { display: inline-flex; gap: 3px; }
.dot { width: 18px; height: 18px; border-radius: 4px; color: #fff; font-size: .62rem; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.dot.g { background: var(--green); }
.dot.e { background: #9aa5ab; }
.dot.p { background: #e2364f; }
.legend { padding: 14px 16px 24px; font-size: .78rem; color: var(--muted); line-height: 1.6; }

/* ---------- Equipos ---------- */
.trow { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.trow .grow { flex: 1; min-width: 0; }
.trow form { margin: 0; }
.trow .rename { display: flex; flex: 1; gap: 8px; min-width: 0; }
.trow .rename input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---------- Diálogo de confirmación y aviso ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(92vw, 380px); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); color: var(--text); }
dialog::backdrop { background: rgba(0, 30, 40, .62); }
dialog form { padding: 22px; }
.dlg-title { margin: 0 0 8px; font-size: 1.2rem; }
.dlg-detail { margin: 0 0 20px; color: var(--muted); font-size: 1.02rem; white-space: pre-line; }
.dlg-actions { display: flex; gap: 10px; }
.dlg-actions .btn { flex: 1; padding: 14px 10px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff;
  padding: 12px 18px; border-radius: 99px; font-weight: 600; z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity .2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--red); }

@media (max-width: 560px) {
  .hide-sm { display: none; }
  .hero-nums { font-size: 2.8rem; }
  .avatar.xl { --s: 64px; }
}
