:root {
  --bg: #0f1226;
  --bg-2: #171a35;
  --card: #1e2244;
  --card-2: #262b52;
  --line: #333a6b;
  --text: #eef0ff;
  --muted: #9aa0c7;
  --accent: #00c2a8;
  --accent-2: #ffd23f;
  --green: #2ecc71;
  --red: #ff5d6c;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(160deg, var(--bg), var(--bg-2));
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* --- Login --- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-card h1 { margin: 0 0 8px; font-size: 1.8rem; }
.login-card p { color: var(--muted); margin: 4px 0 20px; }
.login-hint { font-size: .82rem; margin-top: 16px; }
#login-form { display: flex; gap: 10px; }
#name-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
button {
  cursor: pointer;
  border: none;
  font-size: 1rem;
}
#login-form button, .primary-btn {
  background: var(--accent);
  color: #002a25;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 10px;
}

/* --- Topbar / tabs --- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(0,0,0,.2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.brand { font-weight: 800; }
.user-box { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.user-box #user-name { font-weight: 700; color: var(--accent-2); }
.link-btn { background: none; color: var(--muted); text-decoration: underline; padding: 0; font-size: .85rem; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  position: sticky;
  top: 49px;
  background: var(--bg);
  z-index: 9;
  border-bottom: 1px solid var(--line);
}
.tab {
  background: var(--card);
  color: var(--muted);
  padding: 9px 14px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
  font-size: .9rem;
}
.tab.active { color: var(--text); border-color: var(--accent); background: var(--card-2); }

main { padding: 16px; max-width: 1000px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 16px; }

/* --- Generic --- */
h2.section-title { font-size: 1.3rem; margin: 4px 0 16px; }
.muted { color: var(--muted); }
.phase-header {
  margin: 22px 0 10px;
  font-size: .8rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-2);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

/* --- Match card (predict) --- */
.match {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.match.is-live { border-color: rgba(255,93,108,.5); }
.match.is-final { border-color: rgba(46,204,113,.28); }
.match-meta {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 10px;
}
.match-meta .status-live { color: var(--red); font-weight: 700; }
.match-meta .status-final { color: var(--green); font-weight: 700; }
.match-meta .group-chip {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  font-weight: 700;
  color: var(--accent-2);
  letter-spacing: .02em;
}
.match-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}
.team {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.team.away { flex-direction: row-reverse; text-align: right; }
.team img {
  width: 40px; height: 40px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.35));
}
.team .tname {
  font-weight: 700;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.team.winner .tname { color: var(--accent-2); }

/* Inputs de predicción */
.vs { padding: 0 6px; display: flex; gap: 10px; align-items: center; }
.vs-sep { color: var(--muted); font-size: 1.4rem; font-weight: 700; }
.score-input {
  width: 60px;
  height: 60px;
  text-align: center;
  padding: 0;
  font-size: 1.8rem;
  font-weight: 800;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  -moz-appearance: textfield;
}
.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.score-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,194,168,.2); }
.score-input:disabled { opacity: .55; }

/* Resultado (en curso / finalizado) */
.result { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0 6px; }
.result-main {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.result-main .sep { color: var(--muted); font-weight: 700; }
.result.live .result-main { color: var(--red); }
.result.final .result-main { color: var(--text); }
.result-breakdown { display: flex; gap: 10px; margin-top: 2px; }
.result-breakdown .rb {
  font-size: .68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.3;
}
.result-breakdown .rb b { color: var(--text); font-size: .9rem; }
.result-breakdown .rb.reg b { color: var(--accent); }
.result-breakdown .rb.pen b { color: var(--accent-2); }

.match-foot {
  margin-top: 12px;
  font-size: .8rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 18px;
}
.pred-points { font-weight: 700; }
.pts-3 { color: var(--green); }
.pts-1 { color: var(--accent-2); }
.pts-0 { color: var(--red); }
.saved-flash { color: var(--accent); }
.lock-note { color: var(--muted); font-style: italic; }

/* Grupo de partidos finalizados (colapsable) */
.finished-group { margin-bottom: 12px; }
.finished-group > summary {
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
  padding: 10px 14px;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  user-select: none;
}
.finished-group > summary::-webkit-details-marker { display: none; }
.finished-group > summary::before { content: '▸ '; color: var(--accent-2); }
.finished-group[open] > summary::before { content: '▾ '; }
.finished-group[open] > summary { margin-bottom: 12px; border-style: solid; }
.finished-list .match { opacity: .92; }

/* --- Leaderboard --- */
.lb-list { display: flex; flex-direction: column; gap: 8px; }
.lb-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.lb-row.me { border-color: var(--accent); }
.lb-pos { font-size: 1.2rem; font-weight: 800; text-align: center; color: var(--muted); }
.lb-row:nth-child(1) .lb-pos { color: #ffd23f; }
.lb-name { font-weight: 700; }
.lb-detail { font-size: .76rem; color: var(--muted); }
.lb-total { font-size: 1.6rem; font-weight: 800; color: var(--accent); }
.lb-total small { font-size: .7rem; color: var(--muted); display: block; text-align: right; font-weight: 400; }

/* --- Podium card --- */
.podium-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.podium-card h3 { margin: 0 0 4px; }
.podium-grid { display: grid; gap: 14px; margin-top: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.podium-pos { display: flex; flex-direction: column; gap: 6px; }
.podium-pos label { font-weight: 700; color: var(--accent-2); font-size: .9rem; }

/* Combobox con bandera + búsqueda difusa */
.flag-select { position: relative; }
.fs-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 1rem;
  text-align: left;
}
.flag-select.open .fs-btn { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,194,168,.2); }
.fs-btn:disabled { opacity: .6; cursor: default; }
.fs-flag { width: 28px; display: flex; justify-content: center; flex-shrink: 0; }
.fs-flag img { width: 28px; height: 28px; object-fit: contain; }
.fs-label { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-label.placeholder { color: var(--muted); font-weight: 400; }
.fs-caret { color: var(--muted); flex-shrink: 0; transition: transform .15s; }
.flag-select.open .fs-caret { transform: rotate(180deg); }

.fs-pop {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--card-2);
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,.5);
  padding: 8px;
  overflow: hidden;
}
.fs-search {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
  margin-bottom: 6px;
}
.fs-search:focus { outline: none; border-color: var(--accent); }
.fs-options { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.fs-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.fs-option img { width: 24px; height: 24px; object-fit: contain; flex-shrink: 0; }
.fs-option:hover { background: var(--card); }
.fs-option.selected { background: rgba(0,194,168,.18); }
.fs-clear { color: var(--muted); font-weight: 400; font-style: italic; }
.fs-empty { padding: 10px; color: var(--muted); text-align: center; font-size: .85rem; }

/* --- Comparison table --- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table.compare { border-collapse: collapse; width: 100%; font-size: .85rem; }
table.compare th, table.compare td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.compare thead th { background: var(--card-2); position: sticky; top: 0; text-align: center; }
table.compare th.match-col, table.compare td.match-col { text-align: left; position: sticky; left: 0; background: var(--card); z-index: 2; min-width: 160px; }
table.compare thead th.match-col { z-index: 3; }
table.compare td { text-align: center; }
.cell-pred { font-weight: 700; }
.cell-hidden { color: var(--muted); }
.cell-pts { font-size: .68rem; display: block; }
/* Indicador "ya cargó / pendiente" para pronósticos ocultos. */
.cell-status { font-size: .72rem; color: var(--muted); }
.cell-status .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.cell-status.loaded { color: var(--green); }
.cell-status.loaded .dot { background: var(--green); }
.cell-status.pending .dot { background: transparent; border: 1px solid var(--muted); }
.result-badge { font-weight: 800; }
.result-badge.live { color: var(--red); }
.result-badge.final { color: var(--green); }
.result-badge.pending { color: var(--muted); font-weight: 400; }

/* --- Torneo: subtabs --- */
.subtabs { display: flex; gap: 8px; margin-bottom: 16px; }
.subtab {
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: .88rem;
  font-weight: 600;
}
.subtab.active { color: #002a25; background: var(--accent); border-color: var(--accent); }

/* --- Torneo: fase de grupos --- */
.groups-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}
.group-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.group-card h3 { margin: 0 0 10px; font-size: 1rem; color: var(--accent-2); }
table.group-table { border-collapse: collapse; width: 100%; font-size: .82rem; }
table.group-table th, table.group-table td {
  padding: 6px 4px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
table.group-table thead th { color: var(--muted); font-weight: 600; font-size: .72rem; }
table.group-table th.gteam, table.group-table td.gteam { text-align: left; }
table.group-table td.gpos { color: var(--muted); width: 18px; }
table.group-table td.gteam {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; white-space: nowrap; overflow: hidden;
}
table.group-table td.gteam img { width: 22px; height: 22px; object-fit: contain; flex-shrink: 0; }
table.group-table td.gteam span { overflow: hidden; text-overflow: ellipsis; }
table.group-table td.gpts { font-weight: 800; color: var(--accent); }
table.group-table tr.qualifies td.gpos { color: var(--green); font-weight: 800; }
table.group-table tr.qualifies td.gteam { box-shadow: inset 3px 0 0 var(--green); padding-left: 6px; }
table.group-table tbody tr:last-child td { border-bottom: none; }

/* --- Torneo: llaves (bracket) --- */
.bracket-scroll { overflow-x: auto; padding-bottom: 8px; }
.bracket { display: flex; gap: 14px; min-width: min-content; }
.bracket-col {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 10px;
  min-width: 150px;
  flex: 1;
}
.bracket-col-title {
  text-align: center;
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-weight: 700;
  margin-bottom: 2px;
}
.bracket-match {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.bracket-match.in { border-color: rgba(255,93,108,.5); }
.bracket-match.post { border-color: rgba(46,204,113,.28); }
.bm-team {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  font-size: .85rem;
}
.bm-team img { width: 20px; height: 20px; object-fit: contain; flex-shrink: 0; }
.bm-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bm-team.win .bm-name { color: var(--accent-2); font-weight: 800; }
.bm-score { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 14px; text-align: right; }
.bm-meta {
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
  font-size: .68rem;
  color: var(--muted);
  text-align: center;
}
.bm-meta.live { color: var(--red); font-weight: 700; }
.bm-meta.final { color: var(--green); }
.bracket-empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
}
.third-place { margin-top: 18px; max-width: 240px; }
.third-place h3 { font-size: .95rem; margin: 0 0 8px; }

/* --- Rules --- */
.rules { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; line-height: 1.6; }
.rules h3 { color: var(--accent-2); margin-top: 22px; }
.rules ul { padding-left: 20px; }
.rules .points-pill { display: inline-block; background: var(--accent); color: #002a25; font-weight: 700; border-radius: 999px; padding: 1px 10px; font-size: .85rem; }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.toast.error { border-color: var(--red); }

@media (max-width: 520px) {
  /* En mobile el form de login se apila para que el botón no se salga. */
  #login-form { flex-direction: column; }
  #login-form button { width: 100%; }

  /* Achicamos escudos, inputs y gaps para que el nombre del equipo no se corte. */
  .match { padding: 12px 12px; }
  .match-row { gap: 6px; }
  .team { gap: 7px; }
  .team img { width: 28px; height: 28px; }
  .team .tname { font-size: .85rem; }
  .vs { padding: 0 2px; gap: 6px; }
  .score-input { width: 46px; height: 46px; font-size: 1.4rem; }
  .result { padding: 0 2px; }
  .result-main { font-size: 1.9rem; gap: 5px; }
  .lb-total { font-size: 1.3rem; }
  /* La primera columna se achica para dejar ver las de cada persona. */
  table.compare { font-size: .8rem; }
  table.compare th, table.compare td { padding: 7px 8px; }
  table.compare th.match-col, table.compare td.match-col { min-width: 96px; max-width: 110px; white-space: normal; }
  table.compare td.match-col strong { font-size: .82rem; }
}
