/* === Palmarés Antiliga - Estilos inspirados en antiliga.org === */
:root {
  --bg: #f4f6fa;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef2f7;
  --border: #d9e1ec;
  --text: #1a2233;
  --text-dim: #5b6678;
  --primary: #1e6cb6;     /* Azul Antiliga */
  --primary-2: #155290;
  --primary-soft: #e6eff8;
  --accent: #ffcc29;      /* Amarillo trofeo */
  --danger: #d6453d;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(20, 50, 90, .08);
  --font: 'Open Sans', 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100vh; line-height: 1.5; -webkit-font-smoothing: antialiased; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* HEADER (estilo antiliga.org: barra azul + barra de tabs azul claro) */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--primary);
  border-bottom: 4px solid var(--primary-2);
  color: #fff;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 18px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 56px; height: 56px; border-radius: 8px;
  background: #fff;
  display: grid; place-items: center;
  padding: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-title { font-weight: 800; letter-spacing: .5px; color: #fff; font-size: 18px; text-transform: uppercase; }
.brand-title small { display: block; font-weight: 400; color: rgba(255,255,255,.8); font-size: 12px; text-transform: none; letter-spacing: 0; margin-top: 2px; }

.tabs {
  display: flex; gap: 0; flex-wrap: wrap;
  background: rgba(255,255,255,.08);
  border-radius: 4px;
  padding: 4px;
}
.tab {
  background: transparent; color: rgba(255,255,255,.85);
  border: none; padding: 10px 18px; border-radius: 3px;
  cursor: pointer; font-weight: 600; font-size: 14px; transition: all .15s ease;
  font-family: inherit;
}
.tab:hover { color: #fff; background: rgba(255,255,255,.12); }
.tab.active { color: var(--primary); background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15); }

/* LAYOUT */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from {opacity:0; transform: translateY(4px);} to {opacity:1; transform:none;} }

.view-header { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-header h1 { margin: 0; font-size: 26px; letter-spacing: .2px; color: var(--primary-2); }
.view-header p  { margin: 4px 0 0; color: var(--text-dim); font-size: 14px; }

/* TABLA PALMARÉS */
.table-wrap {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: visible;
}
.table-scroll { overflow: visible; }
table.palmares { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 880px; }
table.palmares th, table.palmares td {
  padding: 12px 14px; text-align: center; font-size: 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.palmares th {
  background: var(--primary); color: #fff;
  font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: .8px;
  cursor: pointer; user-select: none;
  position: sticky; top: 92px; z-index: 5;
}
table.palmares th:hover { background: var(--primary-2); }

/* Modo compacto para temporadas con muchas columnas */
table.palmares.compact { min-width: 0; }
table.palmares.compact th,
table.palmares.compact td {
  padding: 8px 6px;
  font-size: 12px;
  white-space: nowrap;
}
table.palmares.compact th {
  font-size: 10px;
  letter-spacing: 0.4px;
}
table.palmares.compact td.jugador {
  font-size: 12px;
}
table.palmares.compact .rank-medal {
  width: 18px; height: 18px; line-height: 18px;
  font-size: 10px; margin-right: 4px;
}
table.palmares th.sort-asc::after  { content: ' ▲'; color: var(--accent); }
table.palmares th.sort-desc::after { content: ' ▼'; color: var(--accent); }
table.palmares td { color: #b8c2d1; }
table.palmares td.jugador { text-align: left; font-weight: 700; color: var(--text); }
table.palmares tbody tr:nth-child(even) { background: var(--bg-elev-2); }
table.palmares tbody tr:hover { background: var(--primary-soft); }
table.palmares tbody tr:last-child td { border-bottom: none; }
table.palmares td.nonzero { color: var(--text); font-weight: 700; }
table.palmares td.total { color: var(--primary-2); font-weight: 800; }
table.palmares td.total.nonzero { color: var(--primary-2); }

.rank-medal { display: inline-block; width: 22px; height: 22px; line-height: 22px;
  border-radius: 50%; font-size: 11px; font-weight: 800; margin-right: 8px; color: #001b0e; }
.rank-1 { background: #ffcc29; }
.rank-2 { background: #c7d0d9; }
.rank-3 { background: #cd7f32; color: #fff; }
.rank-x { background: var(--bg-elev-2); color: var(--text-dim); }

/* INSIGHTS */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(20,50,90,.12); }
.card .label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; font-weight: 700; }
.card .player { font-size: 22px; font-weight: 800; color: var(--text); }
.card .value  { font-size: 14px; color: var(--primary-2); font-weight: 700; }
.card .icon   { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-size: 18px; margin-bottom: 4px; }

/* COMPARADOR */
.compare {
  margin-top: 28px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.compare h2 { margin: 0 0 6px; font-size: 18px; color: var(--primary-2); }
.compare p  { margin: 0 0 16px; color: var(--text-dim); font-size: 13px; }
.compare-selectors { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; margin-bottom: 18px; }
.compare-selectors .vs { font-weight: 800; color: var(--primary); }
select {
  width: 100%; background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; padding: 9px 12px;
  font-size: 14px; font-family: var(--font); cursor: pointer;
}
select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.compare-chart-wrap { height: 360px; }

/* DASHBOARD */
.charts-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.chart-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.chart-card h3 { margin: 0 0 4px; font-size: 16px; color: var(--primary-2); }
.chart-card p  { margin: 0 0 14px; color: var(--text-dim); font-size: 12px; }
.chart-wrap { position: relative; height: 300px; }
.chart-wrap.tall { height: 360px; }

/* Bloque Evolución: gráficos más grandes, apilados */
.evol-block .charts-grid { grid-template-columns: 1fr; gap: 20px; }
.evol-block .chart-card { padding: 22px; }
.evol-block .chart-card h3 { font-size: 18px; margin-bottom: 10px; }
.evol-block .chart-wrap,
.evol-block .chart-wrap.tall { height: 460px; }
@media (max-width: 700px) {
  .evol-block .chart-wrap,
  .evol-block .chart-wrap.tall { height: 360px; }
}

/* Tabla de Puntuación al pie del Palmarés */
.puntuacion-card-bottom {
  display: block;
  width: 100%;
  max-width: 520px;
  margin: 24px auto 0;
}


/* FOOTER */
footer { text-align: center; color: var(--text-dim); font-size: 12px; padding: 24px; }
footer code { background: var(--bg-elev-2); padding: 2px 6px; border-radius: 3px; }

/* RESPONSIVE */
@media (max-width: 640px) {
  .topbar-inner { flex-direction: column; align-items: stretch; }
  .tabs { justify-content: center; }
  .view-header h1 { font-size: 22px; }
  .compare-selectors { grid-template-columns: 1fr; }
  .compare-selectors .vs { text-align: center; }
}

/* ===== Años de Antiliga ===== */
.antiliga-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 18px;
  margin-bottom: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.antiliga-label {
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: .08em;
}
.antiliga-value {
  font-weight: 800;
  font-size: 20px;
  color: var(--primary-2);
}

/* ===== Selector de temporada ===== */
.season-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  margin-bottom: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.season-bar label {
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: .08em;
}
.season-bar select {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.season-bar select:focus { outline: 2px solid var(--primary); }
.btn-historico {
  background: #fff;
  color: var(--primary-2);
  border: 1px solid var(--primary);
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.btn-historico:hover { background: var(--primary-soft); }
.btn-historico.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.season-label {
  margin-left: auto;
  font-weight: 700;
  color: var(--primary-2);
  font-size: 14px;
}
@media (max-width: 640px) {
  .season-label { margin-left: 0; width: 100%; }
}

/* ===== Meta bar: última actualización + botón ayuda ===== */
.meta-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px; padding: 10px 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px; color: var(--text-dim);
}
.meta-bar .updated-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary); box-shadow: 0 0 0 3px rgba(30,108,182,.18);
}
.meta-bar .updated-text strong { color: var(--text); font-weight: 700; }
.meta-bar .updated-link { margin-left: 4px; }
.meta-actions { margin-left: auto; display: inline-flex; gap: 8px; align-items: center; }
.btn-refresh {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #2b2200;
  border: 1px solid #e6b324;
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 13px; font-weight: 700; cursor: pointer;
  font-family: inherit;
}
.btn-refresh:hover { background: #ffd84d; }
.btn-refresh:disabled { opacity: .6; cursor: progress; }
.btn-help-icon {
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff; color: var(--primary-2);
  border: 1px solid var(--primary);
  font-weight: 800; cursor: pointer; font-family: inherit;
}
.btn-help-icon:hover { background: var(--primary-soft); }
@media (max-width: 640px) {
  .meta-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
}

/* ===== Modales ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 30, 55, .55);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; color: var(--text);
  width: 100%; max-width: 680px;
  border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
  overflow: hidden;
}
.modal.narrow { max-width: 420px; }
.modal-head {
  background: var(--primary); color: #fff;
  padding: 16px 20px; display: flex; align-items: center; justify-content: space-between;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close {
  background: transparent; border: none; color: #fff;
  font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.modal-body { padding: 20px 24px; font-size: 14px; line-height: 1.6; }
.modal-body h3 { color: var(--primary-2); font-size: 15px; margin: 18px 0 8px; }
.modal-body h3:first-child { margin-top: 0; }
.modal-body ol, .modal-body ul { padding-left: 22px; margin: 8px 0; }
.modal-body li { margin: 4px 0; }
.modal-body .tip {
  background: var(--primary-soft); border-left: 3px solid var(--primary);
  padding: 10px 14px; border-radius: 4px; margin: 12px 0;
}

.pass-input {
  width: 100%; padding: 14px;
  font-size: 26px; text-align: center; letter-spacing: 12px;
  border: 1px solid var(--border); border-radius: 6px;
  margin: 14px 0 6px;
  font-family: inherit;
}
.pass-input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.pass-error { color: var(--danger); font-size: 13px; min-height: 18px; font-weight: 700; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.btn-primary {
  background: var(--primary); color: #fff; border: none;
  padding: 10px 18px; border-radius: 4px; font-weight: 700; cursor: pointer;
  font-family: inherit; font-size: 14px;
}
.btn-primary:hover { background: var(--primary-2); }
.btn-secondary {
  background: #fff; color: var(--text); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 4px; font-weight: 700; cursor: pointer;
  font-family: inherit; font-size: 14px;
}
.btn-secondary:hover { background: var(--bg-elev-2); }

/* ===== Tabla de Puntuación ===== */
.puntuacion-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow);
  min-width: 240px;
}
.puntuacion-card h3 { margin: 0 0 8px; font-size: 14px; color: var(--primary-2); text-transform: uppercase; letter-spacing: .8px; }
.puntuacion-card table { width: 100%; border-collapse: collapse; }
.puntuacion-card td { padding: 4px 0; font-size: 13px; }
.puntuacion-card td:first-child { color: var(--text); font-weight: 600; }
.puntuacion-card td:last-child { text-align: right; color: var(--primary-2); font-weight: 800; }
.puntuacion-card td.negative { color: var(--danger); }
.puntuacion-card .hint { margin: 8px 0 0; color: var(--text-dim); font-size: 11px; }

/* ===== Vista jugador ===== */
.player-select-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 14px 18px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.player-select-bar label { font-weight: 700; color: var(--text-dim); text-transform: uppercase; font-size: 12px; letter-spacing: .08em; }
.player-select-bar select { min-width: 220px; }
.player-summary {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  margin-bottom: 18px;
}
.player-summary .ps-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.player-summary .ps-card .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); font-weight: 700; }
.player-summary .ps-card .val { font-size: 22px; font-weight: 800; color: var(--primary-2); margin-top: 2px; }
.player-summary .ps-card.accent { border-top-color: var(--accent); }
.player-summary .ps-card.danger { border-top-color: var(--danger); }
.player-summary .ps-card.danger .val { color: var(--danger); }

.evol-block { margin-top: 28px; }
.evol-block h2 { font-size: 18px; color: var(--primary-2); margin: 0 0 4px; }
.evol-block > p { margin: 0 0 14px; color: var(--text-dim); font-size: 13px; }

/* ===== Fila inferior del Palmarés: tabla puntuación + botón Viva ===== */
.palmares-footer-row {
  position: relative;
  margin-top: 24px;
  min-height: 60px;
}
.palmares-footer-row .puntuacion-card-bottom {
  margin: 0 auto;
}

/* ===== Viva la antiliga (botón discreto pero visible) ===== */
.viva-wrap {
  position: absolute;
  right: 0;
  bottom: 8px;
  margin: 0;
}
.viva-link {
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  color: var(--primary-2);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3px;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 4px;
  transition: background .2s, color .2s, transform .15s;
  font-family: inherit;
  box-shadow: 0 1px 3px rgba(20,50,90,.08);
}
.viva-link:hover { background: var(--primary); color: #fff; transform: translateY(-1px); }
.viva-link.playing { background: var(--accent); color: #2b2200; border-color: #e6b324; animation: viva-pulse 1.2s ease-in-out infinite; }
@keyframes viva-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,204,41,.6); }
  50% { box-shadow: 0 0 0 8px rgba(255,204,41,0); }
}

@media (max-width: 720px) {
  .palmares-footer-row { display: flex; flex-direction: column; align-items: center; gap: 12px; }
  .viva-wrap { position: static; }
}

/* ===== Navegación gráficos de evolución (ventana de 10 temporadas) ===== */
.evol-nav {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 12px;
}
.evol-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: #fff; color: var(--primary-2);
  border-radius: 4px; cursor: pointer;
  font-size: 18px; font-weight: 800; line-height: 1;
  font-family: inherit;
}
.evol-btn:hover { background: var(--primary-soft); }
.evol-range { flex: 1; accent-color: var(--primary); cursor: pointer; }
.evol-range-label {
  font-size: 12px; color: var(--text-dim); font-weight: 700;
  min-width: 130px; text-align: right;
}

