:root {
  --amarillo: #ffd200;
  --amarillo-claro: #fff4b8;
  --amarillo-fondo: #fffaeb;
  --azul: #0b3d91;
  --azul-oscuro: #062a66;
  --azul-claro: #e3ecfb;
  --rojo: #e2001a;
  --rojo-oscuro: #b30015;
  --tinta: #10213f;
  --tinta-suave: #4b5a76;
  --superficie: #ffffff;
  --fondo: var(--amarillo-fondo);
  --borde: #e6dcb4;
  --falta-filtro: grayscale(1) contrast(.9);
  --falta-opacidad: .5;
  --sombra: 0 1px 2px rgb(16 33 63 / .12), 0 4px 12px rgb(16 33 63 / .08);
  --radio: 12px;
  --fuente-titulo: "Oswald", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --fuente: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #071a3d;
    --superficie: #0f2a5c;
    --tinta: #f3f6ff;
    --tinta-suave: #a9b8d6;
    --borde: #22417a;
    --azul-claro: #16346d;
    --amarillo-claro: #3d3510;
    --falta-opacidad: .38;
    --sombra: 0 1px 2px rgb(0 0 0 / .4), 0 4px 12px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--fondo);
  color: var(--tinta);
  font-family: var(--fuente);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--rojo); outline-offset: 2px; }

/* ---------- Cabecera ---------- */

.cabecera {
  background:
    linear-gradient(115deg, transparent 0 62%, rgb(255 210 0 / .14) 62% 70%, transparent 70%),
    var(--azul);
  color: #fff;
  padding: 14px 16px 16px;
  border-bottom: 5px solid var(--rojo);
}

.cabecera-fila, .progreso, .herramientas > *, .album, .pie, .sin-resultados {
  max-width: 1280px;
  margin-inline: auto;
}

.cabecera-fila { display: flex; align-items: center; gap: 12px; }

.logo {
  flex: none;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  background: var(--amarillo);
  border: 3px solid var(--rojo);
  border-radius: 10px;
  transform: rotate(-4deg);
  font-family: var(--fuente-titulo);
  font-weight: 700;
  line-height: .95;
  color: var(--rojo);
  box-shadow: 3px 3px 0 var(--azul-oscuro);
}
.logo span:first-child { font-size: 15px; color: var(--azul); }
.logo span:last-child { font-size: 14px; letter-spacing: .02em; }

.titulo { flex: 1; min-width: 0; }
.titulo h1 {
  margin: 0;
  font-family: var(--fuente-titulo);
  font-weight: 700;
  font-size: clamp(20px, 4vw, 28px);
  letter-spacing: .01em;
  text-transform: uppercase;
  line-height: 1.1;
}
.guardado { margin: 2px 0 0; font-size: 13px; color: #c8d6f3; }
.guardado.error { color: var(--amarillo); }

.menu { position: relative; }
.boton-icono {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / .12);
}
.boton-icono svg { width: 22px; height: 22px; fill: #fff; }
.boton-icono:hover { background: rgb(255 255 255 / .22); }

.menu-lista {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  min-width: 250px;
  padding: 6px;
  background: var(--superficie);
  color: var(--tinta);
  border-radius: var(--radio);
  box-shadow: 0 10px 30px rgb(0 0 0 / .25);
}
.menu-lista button {
  display: block;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
}
.menu-lista button:hover { background: var(--azul-claro); }

.progreso { margin-top: 14px; }
.progreso-cifras {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--fuente-titulo);
  font-size: 20px;
}
.progreso-cifras strong { font-size: 34px; line-height: 1; color: var(--amarillo); }
.progreso-pct {
  margin-left: auto;
  padding: 1px 10px;
  border-radius: 99px;
  background: var(--rojo);
  font-size: 18px;
  font-weight: 600;
}
.barra {
  height: 12px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: rgb(255 255 255 / .18);
}
.barra-relleno {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--amarillo);
  transition: width .4s ease;
}
.progreso-detalle { display: flex; gap: 18px; margin-top: 8px; font-size: 14px; color: #dbe5fa; }
.progreso-detalle b { color: #fff; font-size: 16px; }

/* ---------- Barra de herramientas fija ---------- */

.herramientas {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 10px 16px 8px;
  background: var(--amarillo);
  box-shadow: 0 3px 10px rgb(16 33 63 / .18);
  color: #10213f;
}

.buscador {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 50px;
  padding: 6px 44px 6px 42px;
  background: #fff;
  border: 3px solid var(--azul);
  border-radius: 14px;
}
.buscador:focus-within { border-color: var(--rojo); }
.buscador-lupa {
  position: absolute;
  left: 12px;
  top: 13px;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--azul);
  stroke-width: 2.5;
  stroke-linecap: round;
}
.buscador input {
  flex: 1;
  min-width: 140px;
  height: 32px;
  border: 0;
  outline: 0;
  background: none;
  color: #10213f;
  font-size: 17px;
}
.buscador input::-webkit-search-cancel-button { display: none; }
.buscador-limpiar {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #eef1f7;
  color: #10213f;
  font-size: 22px;
  line-height: 1;
}

.chips { display: contents; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 3px 4px 3px 10px;
  border-radius: 99px;
  background: var(--azul);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.chip small { font-weight: 400; opacity: .8; }
.chip[data-tipo="equipo"] { background: var(--rojo); }
.chip button {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / .25);
  color: #fff;
  font-size: 16px;
  line-height: 1;
}

.sugerencias {
  position: absolute;
  left: -3px;
  right: -3px;
  top: calc(100% + 6px);
  z-index: 50;
  max-height: min(60vh, 420px);
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgb(0 0 0 / .25);
}
.sugerencias li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.sugerencias li[aria-selected="true"], .sugerencias li:hover { background: var(--amarillo-claro); }
@media (prefers-color-scheme: dark) {
  .sugerencias li[aria-selected="true"], .sugerencias li:hover { background: #fff4b8; }
}
.sugerencias img { width: 24px; height: 24px; object-fit: contain; }
.sugerencias .tipo {
  margin-left: auto;
  padding: 1px 8px;
  border-radius: 99px;
  background: #e3ecfb;
  color: var(--azul);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.estados {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 8px;
  padding: 4px;
  border-radius: 12px;
  background: rgb(11 61 145 / .12);
}
.estados button {
  min-height: 40px;
  padding: 6px 4px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--azul-oscuro);
  font-family: var(--fuente-titulo);
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.estados button[aria-checked="true"] { background: var(--azul); color: #fff; box-shadow: var(--sombra); }
.estados button[data-estado="faltan"][aria-checked="true"] { background: var(--rojo); }

.atajos {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.atajos::-webkit-scrollbar { display: none; }
.atajo {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 5px;
  border: 2px solid transparent;
  border-radius: 99px;
  background: rgb(255 255 255 / .75);
  color: #10213f;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.atajo img { width: 22px; height: 22px; object-fit: contain; }
.atajo .atajo-cuenta { font-weight: 400; color: #4b5a76; }
.atajo.completo { background: var(--azul); color: #fff; }
.atajo.completo .atajo-cuenta { color: var(--amarillo); }
.atajo[aria-pressed="true"] { border-color: var(--rojo); }
.atajo.sin-escudo { padding-left: 10px; }

/* ---------- Álbum ---------- */

.album { padding: 8px 16px 32px; }

.grupo { margin-top: 20px; scroll-margin-top: 220px; }
.grupo-cabecera {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radio);
  background: var(--azul);
  color: #fff;
  text-align: left;
}
.grupo.especial .grupo-cabecera { background: var(--rojo); }
.grupo-cabecera img { width: 34px; height: 34px; object-fit: contain; filter: drop-shadow(0 1px 1px rgb(0 0 0 / .3)); }
.grupo-titulo {
  flex: 1;
  min-width: 0;
  font-family: var(--fuente-titulo);
  font-size: 20px;
  font-weight: 600;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grupo-cuenta { font-family: var(--fuente-titulo); font-size: 18px; white-space: nowrap; }
.grupo-cuenta b { color: var(--amarillo); }
.grupo-barra { width: 70px; height: 8px; border-radius: 99px; background: rgb(255 255 255 / .25); overflow: hidden; }
.grupo-barra div { height: 100%; background: var(--amarillo); }
.grupo-flecha { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 3; transition: transform .2s; }
.grupo.plegado .grupo-flecha { transform: rotate(-90deg); }
.grupo.plegado .grupo-cromos { display: none; }

.grupo-cromos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

/* ---------- Cromo ---------- */

.cromo { position: relative; display: flex; flex-direction: column; }

.cromo-cara {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: 3px dashed var(--borde);
  border-radius: var(--radio);
  background: var(--superficie);
  text-align: left;
  transition: transform .12s ease, border-color .12s;
}
.cromo-cara:hover { transform: translateY(-2px); }
.cromo-cara:active { transform: scale(.97); }

.cromo-num {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  min-width: 30px;
  padding: 1px 7px;
  border-radius: 7px;
  background: var(--tinta-suave);
  color: #fff;
  font-family: var(--fuente-titulo);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}
.cromo-escudo {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.cromo-foto {
  position: relative;
  display: grid;
  place-items: end center;
  width: 100%;
  /* Proporción de un cromo de la Liga Este (apaisado, 895x643) */
  aspect-ratio: 895 / 643;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 110%, rgb(255 255 255 / .55), transparent 60%),
    linear-gradient(160deg, #ffe45c, var(--amarillo) 55%, #f3b400);
}
.cromo-foto img {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
}
.cromo-foto img.es-escudo { width: 72%; height: 72%; place-self: center; object-position: center; }
/* El cromo escaneado ocupa todo el hueco */
.cromo-foto img.es-cromo { object-fit: cover; object-position: center; }
/* El cromo ya lleva su escudo: el de la esquina sobra */
.cromo:has(img.es-cromo) .cromo-escudo { display: none; }
/* Cromos verticales (escudos y entrenadores, 600x849) */
.cromo.vertical .cromo-foto { aspect-ratio: 600 / 849; }
/* Fila de cabecera de cada equipo: escudo y entrenador, más estrechos que los jugadores */
.vista-cuadricula .grupo-destacados { grid-template-columns: repeat(auto-fill, minmax(150px, 180px)); }
.grupo-destacados:not(:has(> .cromo:not([hidden]))) { display: none; }
.cromo-iniciales {
  grid-area: 1 / 1;
  place-self: center;
  font-family: var(--fuente-titulo);
  font-size: 40px;
  font-weight: 700;
  color: rgb(11 61 145 / .35);
}
.cromo-foto.con-foto .cromo-iniciales { display: none; }
.cromo-foto.cargando::after {
  content: "";
  grid-area: 1 / 1;
  place-self: center;
  width: 26px;
  height: 26px;
  border: 3px solid rgb(11 61 145 / .25);
  border-top-color: var(--azul);
  border-radius: 50%;
  animation: girar 1s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

.cromo-pie {
  display: flex;
  flex-direction: column;
  padding: 6px 8px 8px;
  background: var(--azul);
  color: #fff;
}
.cromo-nombre {
  font-family: var(--fuente-titulo);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.15;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cromo-meta {
  font-size: 12px;
  color: #c8d6f3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Los premios (LaLiga Fantasy) son largos: hasta dos líneas en vez de cortarse */
.cromo.con-premio .cromo-meta {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
  line-height: 1.25;
}

.cromo-sello {
  position: absolute;
  top: 40%;
  left: 50%;
  z-index: 3;
  padding: 2px 10px;
  border: 3px solid var(--rojo);
  border-radius: 8px;
  background: rgb(255 255 255 / .92);
  color: var(--rojo);
  font-family: var(--fuente-titulo);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  transform: translate(-50%, -50%) rotate(-12deg) scale(0);
  opacity: 0;
  pointer-events: none;
}
.cromo.recien .cromo-sello { animation: sello .9s ease forwards; }
@keyframes sello {
  0% { transform: translate(-50%, -50%) rotate(-12deg) scale(1.8); opacity: 0; }
  25% { transform: translate(-50%, -50%) rotate(-12deg) scale(1); opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(-12deg) scale(1); opacity: 0; }
}

/* Me falta: apagado y discontinuo, para que salte a la vista lo que no tienes */
.cromo:not(.tengo) .cromo-foto img,
.cromo:not(.tengo) .cromo-escudo { filter: var(--falta-filtro); opacity: var(--falta-opacidad); }
.cromo:not(.tengo) .cromo-foto { background: repeating-linear-gradient(45deg, var(--azul-claro) 0 8px, var(--superficie) 8px 16px); }
.cromo:not(.tengo) .cromo-pie { background: var(--tinta-suave); }
@media (prefers-color-scheme: dark) {
  .cromo:not(.tengo) .cromo-pie { background: #2a3d63; }
}

/* Lo tengo */
.cromo.tengo .cromo-cara { border: 3px solid var(--amarillo); box-shadow: var(--sombra); }
.cromo.tengo .cromo-num { background: var(--rojo); }

/* Variantes de las colecciones especiales */
.cromo[data-variante="prime"].tengo .cromo-foto { background: linear-gradient(160deg, #1b4fb5, var(--azul-oscuro)); }
.cromo[data-variante="fantasy"].tengo .cromo-foto { background: linear-gradient(160deg, #ff4d5e, var(--rojo-oscuro)); }
.cromo[data-variante="kromix"].tengo .cromo-foto { background: linear-gradient(135deg, #ffd200, #ff6a3d, #e2001a, #7a3cff, #0b3d91); }
.cromo[data-variante="bronce"].tengo .cromo-cara { border-color: #c47a3a; }
.cromo[data-variante="bronce"].tengo .cromo-foto { background: linear-gradient(160deg, #f0b27a, #a9622b); }
.cromo[data-variante="plata"].tengo .cromo-cara { border-color: #a9b3c1; }
.cromo[data-variante="plata"].tengo .cromo-foto { background: linear-gradient(160deg, #f4f6f9, #9aa5b5); }
.cromo[data-variante="oro"].tengo .cromo-cara { border-color: #e8b923; }
.cromo[data-variante="oro"].tengo .cromo-foto { background: linear-gradient(160deg, #fff1a8, #d9a400); }

/* Contador de repetidos */
.cromo-repes {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-top: 6px;
  visibility: hidden;
}
.cromo.tengo .cromo-repes { visibility: visible; }
.cromo-repes button {
  width: 36px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: var(--azul-claro);
  color: var(--tinta);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}
.cromo-repes button.mas { background: var(--azul); color: #fff; }
.cromo-cantidad { font-size: 13px; color: var(--tinta-suave); text-align: center; white-space: nowrap; }
.cromo.repe .cromo-cantidad {
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--rojo);
  color: #fff;
  font-weight: 700;
}

.cromo[hidden], .grupo[hidden] { display: none; }

/* ---------- Vista lista: más compacta para marcar deprisa ---------- */

.vista-lista .grupo-cromos { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 6px; }
.vista-lista .cromo { flex-direction: row; align-items: center; gap: 6px; }
.vista-lista .cromo-cara {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 4px 8px;
  border-width: 2px;
}
.vista-lista .cromo-num { position: static; flex: none; }
.vista-lista .cromo-escudo { position: static; order: 3; margin-left: auto; width: 22px; height: 22px; }
.vista-lista .cromo-foto { display: none; }
.vista-lista .cromo-pie { flex: 1; min-width: 0; padding: 0; background: none !important; color: var(--tinta); }
.vista-lista .cromo-meta { color: var(--tinta-suave); }
.vista-lista .cromo-sello { display: none; }
.vista-lista .cromo-repes { margin: 0; flex: none; }
.vista-lista .cromo.tengo .cromo-cara { background: var(--amarillo-claro); }
.vista-lista .cromo-cara:hover { transform: none; }

/* ---------- Varios ---------- */

.sin-resultados { padding: 40px 16px; text-align: center; color: var(--tinta-suave); font-size: 18px; }

.pie { padding: 16px 16px 90px; font-size: 13px; color: var(--tinta-suave); text-align: center; }
.pie a { color: inherit; }

.aviso {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 10px 12px 10px 16px;
  border-radius: 12px;
  background: var(--tinta);
  color: var(--fondo);
  box-shadow: 0 8px 24px rgb(0 0 0 / .3);
  transform: translateX(-50%);
}
@media (prefers-color-scheme: dark) {
  .aviso { background: #fff; color: #10213f; }
}
.aviso button {
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--amarillo);
  color: #10213f;
  font-weight: 700;
}

@media (max-width: 560px) {
  .cabecera { padding: 10px 16px 12px; }
  .logo { width: 46px; height: 46px; }
  .logo span:first-child { font-size: 12px; }
  .logo span:last-child { font-size: 11px; }
  .progreso { margin-top: 10px; }
  .progreso-cifras strong { font-size: 28px; }
  .grupo-cromos { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .vista-cuadricula .grupo-destacados { grid-template-columns: repeat(2, minmax(0, 150px)); }
  .cromo-nombre { font-size: 15px; }
  .cromo-num { font-size: 14px; min-width: 26px; }
  .cromo-escudo { width: 22px; height: 22px; }
  .cromo-repes button { width: 32px; }
  .estados button { font-size: 14px; }
  .grupo-barra { display: none; }
  .vista-lista .grupo-cromos { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
