/* ===========================================================
   Pokémon Libre · estilos
   La carta manda; la interfaz se aparta. Dos colores con
   significado y ninguno de adorno: violeta para lo que se toca,
   dorado para «la tengo». Lo que falta se ve apagado, como el
   hueco vacío de un álbum.
   =========================================================== */

:root {
  --paper:   #EEF0F4;
  --surface: #FAFBFD;
  --sunk:    #E2E5EC;
  --tx:      #17162A;
  --tx2:     #4E4D66;
  --tx3:     #807F97;
  --line:    #D4D7E1;
  --line2:   #BDC1CF;

  --violeta: #5B4BDB;
  --oro:     #C9930A;
  --oro-viva:#E9B21E;
  --mal:     #B4471B;

  /* colores de tipo, para las fichas de inicio */
  --t-fuego:     #D9532B;
  --t-planta:    #3E9B4F;
  --t-agua:      #2E7DC9;
  --t-electrico: #D9A400;
  --t-fantasma:  #6B4BA8;
  --t-normal:    #8A8A9E;

  --r-sm: 7px;
  --r-md: 12px;
  --r-lg: 18px;

  --nav-h: 58px;
  --sai: env(safe-area-inset-top, 0px);
  --sae: env(safe-area-inset-bottom, 0px);

  --f: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --fm: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    --paper:   #100F1C;
    --surface: #191827;
    --sunk:    #21202F;
    --tx:      #ECEBF5;
    --tx2:     #A9A8BE;
    --tx3:     #7B7A92;
    --line:    #2B2A3C;
    --line2:   #3A3950;
    --violeta: #9D91F0;
    --oro:     #E9B21E;
    --oro-viva:#F5C63F;
    --mal:     #E48A5F;
    --t-fuego: #F07A55; --t-planta: #6BC77C; --t-agua: #66A7EE;
    --t-electrico: #F0C43A; --t-fantasma: #A98BE0; --t-normal: #A5A4BA;
  }
}
:root[data-tema="oscuro"] {
  --paper:   #100F1C;
  --surface: #191827;
  --sunk:    #21202F;
  --tx:      #ECEBF5;
  --tx2:     #A9A8BE;
  --tx3:     #7B7A92;
  --line:    #2B2A3C;
  --line2:   #3A3950;
  --violeta: #9D91F0;
  --oro:     #E9B21E;
  --oro-viva:#F5C63F;
  --mal:     #E48A5F;
  --t-fuego: #F07A55; --t-planta: #6BC77C; --t-agua: #66A7EE;
  --t-electrico: #F0C43A; --t-fantasma: #A98BE0; --t-normal: #A5A4BA;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--tx);
  font-family: var(--f);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
.oculto { display: none !important; }
:focus-visible { outline: 2px solid var(--violeta); outline-offset: 2px; }

/* ---------- carga ---------- */

.cargando {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-content: center; gap: 16px; justify-items: center;
  background: var(--paper); color: var(--tx3); font-size: 14px;
}
.cargando.fuera { display: none; }
.pulso {
  width: 46px; height: 64px; border-radius: 5px;
  background: linear-gradient(150deg, var(--violeta), var(--oro));
  animation: late 1.1s ease-in-out infinite;
}
@keyframes late { 0%,100% { transform: scale(1) rotate(-3deg); opacity: .85 } 50% { transform: scale(1.08) rotate(3deg); opacity: 1 } }

/* ---------- pantallas ---------- */

.pantalla {
  position: fixed; inset: 0;
  bottom: calc(var(--nav-h) + var(--sae));
  display: none; flex-direction: column;
  padding-top: var(--sai);
  overflow-x: hidden;
}
.pantalla > * { min-width: 0; }
.pantalla.viva { display: flex; }

.barra {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 8px 8px; flex: 0 0 auto;
}
.barra-medio { flex: 1 1 auto; min-width: 0; text-align: center; }
.titulo {
  flex: 1 1 auto; margin: 0;
  font-size: 20px; font-weight: 700; letter-spacing: -0.015em;
  padding: 0 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.barra-medio .titulo { padding: 0; }
.subtitulo {
  margin: 1px 0 0; font-size: 12px; color: var(--tx3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.icono {
  flex: 0 0 auto; width: 42px; height: 42px;
  border: 0; background: none; border-radius: 50%;
  display: grid; place-items: center; color: var(--tx2);
}
.icono svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icono:active { background: var(--sunk); }

.cuerpo {
  flex: 1 1 auto; overflow-y: auto;
  padding: 0 12px 28px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- inicio: fichas de Pokémon ---------- */

.pokes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .pokes { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .pokes { grid-template-columns: repeat(4, 1fr); } }

.poke {
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); padding: 12px 13px 13px;
  text-align: left; display: grid; gap: 7px;
  position: relative; overflow: hidden;
}
.poke::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--tipo, var(--tx3));
}
.poke .nom { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.poke .cif {
  font-family: var(--fm); font-size: 12.5px; color: var(--tx2);
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.poke .cif b { color: var(--tx); font-size: 14px; }
.poke .via { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.poke .via i { display: block; height: 100%; background: var(--oro); border-radius: 3px; transition: width .3s ease; }
.poke.completo .via i { background: var(--tipo, var(--oro)); }
.poke.completo .nom::after { content: " ✓"; color: var(--oro); }
.poke:active { transform: scale(.985); }

.grupo-titulo {
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--tx3); margin: 22px 2px 10px;
}
.grupo-titulo:first-child { margin-top: 6px; }

.resumen {
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); padding: 14px 15px; margin: 6px 0 4px;
  display: grid; gap: 8px;
}
.resumen .gr { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.resumen .gr small { font-size: 15px; font-weight: 600; color: var(--tx3); }
.resumen .via { height: 8px; background: var(--sunk); border-radius: 4px; overflow: hidden; }
.resumen .via i { display: block; height: 100%; background: var(--oro); border-radius: 4px; }
.resumen p { margin: 0; font-size: 13px; color: var(--tx2); }

/* ---------- buscador y filtros ---------- */

.buscador { display: flex; gap: 6px; padding: 0 10px 8px; flex: 0 0 auto; }
.buscador input {
  flex: 1 1 auto; min-width: 0;
  padding: 10px 13px; border: 1px solid var(--line2); border-radius: var(--r-md);
  background: var(--surface); color: var(--tx); font: inherit; font-size: 16px;
}

.filtros {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 0 12px 10px; flex: 0 0 auto;
}
.filtros::-webkit-scrollbar { display: none; }
.filtros button {
  flex: 0 0 auto; padding: 7px 13px;
  border: 1.5px solid var(--line2); border-radius: 999px;
  background: var(--surface); font-size: 13px; font-weight: 600; color: var(--tx2);
  white-space: nowrap;
}
.filtros button.viva { background: var(--tx); border-color: var(--tx); color: var(--paper); }

/* ---------- rejilla de cartas ---------- */

.rejilla {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 9px;
}
@media (min-width: 520px) { .rejilla { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); } }

/* Cada hueco de la rejilla lleva la carta y, encima, el botón de su
   ficha. La celda es la que ocupa la casilla; la carta la rellena. */
.celda { position: relative; }
.celda .detalle {
  position: absolute; left: 4px; bottom: 4px; z-index: 2;
  width: 27px; height: 27px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(18,16,38,.78); color: #fff;
  font-size: 15px; font-weight: 800; font-style: italic; line-height: 1;
  display: grid; place-items: center;
  box-shadow: 0 1px 5px rgba(0,0,0,.4);
  touch-action: manipulation;
}
.celda .detalle:active { transform: scale(.88); }
.ayuda { margin: 0 0 10px; }

.carta {
  border: 0; padding: 0; background: none;
  position: relative; display: block;
  border-radius: var(--r-sm); overflow: hidden;
  /* marcar un fajo deprisa: sin retardo de doble toque, sin que el
     toque largo seleccione texto ni saque el menú de guardar imagen */
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  /* Aquí NO va content-visibility: auto. Aplaza la descarga de todo lo
     que hay dentro, así que las imágenes no llegaban a pedirse nunca y
     la rejilla salía en blanco (comprobado en la app publicada).
     De no pedir lo que no se ve ya se encarga el observador de
     js/vistas/cartas.js, que además es predecible. */
}
.carta img {
  display: block; width: 100%;
  /* height:auto es imprescindible: sin él, el atributo height del HTML
     se impone sobre la proporción y las cartas salen estiradas.
     245x337 es el tamaño real de los ficheros, no la proporción
     teórica de una carta: así no se recorta nada. */
  height: auto;
  aspect-ratio: 245 / 337;
  object-fit: cover; border-radius: var(--r-sm);
  background: var(--sunk);
  transition: opacity .18s ease, filter .18s ease;
}
/* las que faltan, apagadas: el hueco vacío del álbum. Lo justo para
   distinguirlas de un vistazo, no tanto como para no poder mirarlas */
.carta.falta img { opacity: .6; filter: grayscale(.42); }
.carta.falta::after {
  content: ""; position: absolute; inset: 0;
  border-radius: var(--r-sm); border: 1px dashed var(--line2);
}
.carta.tengo { box-shadow: 0 0 0 2.5px var(--oro); }
.carta.tengo .tic {
  position: absolute; top: 5px; right: 5px;
  width: 21px; height: 21px; border-radius: 50%;
  background: var(--oro-viva); color: #241c00;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.carta .tic { display: none; }
.carta.tengo .tic { display: grid; }
/* si la foto no llega ni reintentando, la carta enseña su nombre */
.carta .nombre-carta { display: none; }
.carta.sin-foto .nombre-carta {
  display: grid; place-content: center; gap: 4px; text-align: center;
  position: absolute; inset: 0; padding: 8px;
  font-size: 11px; font-weight: 700; line-height: 1.2; color: var(--tx2);
  background: var(--sunk); border-radius: var(--r-sm);
}
.carta.sin-foto .nombre-carta small { font-family: var(--fm); font-weight: 400; font-size: 10px; color: var(--tx3); }
.carta .cant {
  position: absolute; bottom: 5px; right: 5px;
  font-family: var(--fm); font-size: 10px; font-weight: 600;
  background: rgba(20,18,40,.82); color: #fff;
  padding: 1px 6px; border-radius: 999px;
}
.carta:active { transform: scale(.96); }

.set-cab {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin: 20px 2px 9px;
}
.set-cab:first-child { margin-top: 4px; }
.set-cab b { font-size: 14.5px; font-weight: 700; flex: 1 1 auto; min-width: 0; }
/* el logo del set: pequeño y discreto, para reconocer la colección
   de un vistazo sin quitarle sitio a las cartas */
.set-logo {
  height: 22px; width: auto; max-width: 74px; object-fit: contain;
  flex: 0 0 auto; align-self: center;
}
/* Sobre fondo oscuro los logos, pensados para papel blanco, se apagan:
   se aclaran un poco. Solo en oscuro de verdad — en automático con el
   sistema en claro este filtro los lavaba. */
:root[data-tema="oscuro"] .set-logo { filter: brightness(1.35) contrast(1.05); }
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) .set-logo { filter: brightness(1.35) contrast(1.05); }
}
.set-cab span { font-family: var(--fm); font-size: 11.5px; color: var(--tx3); white-space: nowrap; }

.vacio { text-align: center; color: var(--tx3); font-size: 14px; padding: 40px 20px; }

/* ---------- ficha de la carta ---------- */

.ficha-img {
  display: block; width: min(72%, 260px); margin: 0 auto 14px;
  border-radius: 10px; box-shadow: 0 6px 22px rgba(10,8,30,.28);
}
.datos { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; margin-bottom: 14px; }
.datos div { background: var(--surface); padding: 9px 13px; display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.datos dt { color: var(--tx3); margin: 0; }
.datos dd { margin: 0; font-weight: 600; text-align: right; }

.variantes { display: grid; gap: 8px; margin-bottom: 14px; }
.variante {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--line2); border-radius: var(--r-md);
  background: var(--surface); padding: 10px 12px;
}
.variante.tengo { border-color: var(--oro); background: color-mix(in srgb, var(--oro) 10%, var(--surface)); }
.variante .nom { flex: 1 1 auto; font-size: 14.5px; font-weight: 600; text-align: left; }
.variante .menos, .variante .mas {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line2); background: var(--paper);
  display: grid; place-items: center; font-size: 17px; line-height: 1; flex: 0 0 auto;
}
.variante .n { font-family: var(--fm); font-size: 15px; font-weight: 700; min-width: 22px; text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px 16px;
  border: 1px solid var(--line2); border-radius: var(--r-md);
  background: var(--surface); font-size: 15px; font-weight: 600;
}
a.btn { text-decoration: none; color: inherit; }
.btn.principal { background: var(--tx); color: var(--paper); border-color: var(--tx); }
.btn.peligro { color: var(--mal); border-color: var(--mal); }
.btn + .btn { margin-top: 8px; }
.btn:active { transform: scale(.985); }
.botones { display: flex; gap: 8px; }
.botones .btn { margin-top: 0; }

/* ---------- tarjetas de ajustes ---------- */

.tarjeta { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 15px; margin-bottom: 12px; }
.tarjeta h3 { margin: 0 0 10px; font-size: 12.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--tx3); }
.fila { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.fila:last-child { border-bottom: 0; }
.fila small { display: block; font-size: 12.5px; color: var(--tx3); font-weight: 400; }
.fila .v { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--tx2); }
.pista { font-size: 13px; color: var(--tx2); margin: 8px 0 0; }
.pista.chica { font-size: 12px; color: var(--tx3); }
.aviso { display: flex; gap: 10px; align-items: flex-start; background: var(--sunk); border-radius: var(--r-md); padding: 11px 13px; font-size: 13px; line-height: 1.45; color: var(--tx2); }
.aviso b { color: var(--tx); }
.segmentos { display: flex; gap: 3px; background: var(--sunk); border-radius: var(--r-md); padding: 3px; }
.segmentos button { flex: 1; border: 0; background: none; padding: 9px 6px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--tx2); }
.segmentos button.viva { background: var(--surface); color: var(--tx); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.interruptor { width: 22px; height: 22px; flex: 0 0 auto; }

/* ---------- navegación ---------- */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--sae)); padding-bottom: var(--sae);
  display: grid; grid-template-columns: repeat(2, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); z-index: 30;
}
.nav button {
  border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--tx3); font-size: 10.5px; font-weight: 600;
}
.nav button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav button.viva { color: var(--tx); }

/* ---------- hoja inferior ---------- */

.velo { position: fixed; inset: 0; background: rgba(8,6,22,.5); opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 40; }
.velo.viva { opacity: 1; pointer-events: auto; }
.hoja {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: 90vh; overflow-y: auto;
  background: var(--paper); border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 8px 16px calc(20px + var(--sae));
  transform: translateY(102%); transition: transform .25s cubic-bezier(.22,.8,.3,1); z-index: 50;
}
.hoja.viva { transform: translateY(0); }
.hoja .asa { width: 38px; height: 4px; border-radius: 2px; background: var(--line2); margin: 4px auto 12px; }
.hoja h2 { margin: 0 0 3px; font-size: 19px; font-weight: 700; }
.hoja-sub { margin: 0 0 14px; font-size: 13px; color: var(--tx3); }

/* ---------- avisos ---------- */

.tosti {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--sae) + 14px);
  transform: translate(-50%, 14px);
  max-width: min(92vw, 420px);
  background: var(--tx); color: var(--paper);
  padding: 11px 15px; border-radius: var(--r-md);
  font-size: 14px; display: flex; align-items: center; gap: 12px;
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 60;
}
.tosti.viva { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.tosti.buena { background: var(--oro); color: #241c00; }
.tosti.mala { background: var(--mal); color: #fff; }
.tosti button { border: 0; background: rgba(255,255,255,.22); color: inherit; padding: 5px 11px; border-radius: 7px; font-size: 13px; font-weight: 600; flex: 0 0 auto; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .carta:active, .btn:active, .poke:active { transform: none; }
}
