/* ============================================================
   MEMORAMA · ACELERA TU FORTUNA — PROGRESSA
   ------------------------------------------------------------
   Se conserva la identidad que ya tenía el juego: fondo azul
   marino con la imagen de Progressa, paneles claros, texto en
   azul de marca y verde limón como acento.
   Todo el look se controla desde el bloque :root de abajo.
   ============================================================ */

:root {
  /* --- Color de marca --- */
  --pgm-blue:       #0073C4;   /* azul Progressa: texto y acentos   */
  --pgm-blue-dark:  #005A9A;   /* hover                              */
  --pgm-navy:       #001C34;   /* fondo base                         */
  --pgm-navy-2:     #122341;   /* halo del fondo                     */
  --pgm-lime:       #C1E877;   /* acento: botón y parejas encontradas */
  --pgm-lime-dark:  #A9D45B;

  /* --- Superficies claras --- */
  --pgm-panel:      #F2F2F2;   /* barra lateral, tablero y modal      */
  --pgm-panel-2:    #E7EBEF;   /* fichas e inputs sobre el panel      */
  --pgm-line:       #C9D3DC;   /* bordes sobre superficie clara       */
  --pgm-line-soft:  #DDE3E9;

  /* --- Cartas --- */
  --pgm-card-front: #056AA8;   /* reverso (tapada)                    */
  --pgm-card-back:  #4CB409;   /* anverso (icono)                     */

  /* --- Texto --- */
  --pgm-text:       #0073C4;
  --pgm-text-dark:  #103A5C;
  --pgm-text-soft:  #5B7B95;
  --pgm-error:      #C0392B;

  --pgm-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI",
              Roboto, Arial, sans-serif;

  --pgm-radius:     12px;
  --pgm-radius-lg:  18px;
  --pgm-radius-xl:  24px;
  --pgm-shadow:     0 24px 60px rgba(0, 0, 0, .45);
}

/* ============================================================
   BASE
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }
body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--pgm-font);
  font-size: 16px;
  color: var(--pgm-text);
  background: var(--pgm-navy);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1400px 900px at 50% -200px,
      rgba(18, 35, 65, .85) 0%, rgba(0, 28, 52, 0) 60%),
    var(--pgm-navy) url("../img/bg-progressa.png") center / cover no-repeat;
}

img { max-width: 100%; display: block; }
button { font: inherit; }

/* El atributo hidden debe ganarle a cualquier display de clase. */
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--pgm-blue);
  outline-offset: 2px;
}

/* ============================================================
   LAYOUT DEL JUEGO
   ============================================================ */

.pgm-wrap {
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 18px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

.pgm-sidebar,
.pgm-board {
  background: var(--pgm-panel);
  border: 1px solid var(--pgm-line);
  border-radius: var(--pgm-radius-lg);
  box-shadow: var(--pgm-shadow);
}

.pgm-sidebar {
  position: sticky;
  top: 20px;
  align-self: start;
  padding: 20px 18px;
}

.pgm-logo { width: 165px; margin-bottom: 16px; }

.pgm-hello {
  margin: 0 0 6px;
  font-size: 23px;
  font-weight: 800;
  line-height: 1.15;
  color: var(--pgm-text-dark);
}

.pgm-muted {
  margin: 0 0 18px;
  color: var(--pgm-text-soft);
  font-size: 14.5px;
  line-height: 1.55;
}

.pgm-stats { display: flex; gap: 10px; }

.pgm-tile {
  flex: 1 1 0;
  padding: 12px;
  text-align: center;
  /* Fondo propio: antes usaba rgba(255,255,255,.03), que sobre el
     panel claro resultaba invisible. */
  background: var(--pgm-panel-2);
  border: 1px solid var(--pgm-line-soft);
  border-radius: var(--pgm-radius);
}

.pgm-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--pgm-text-soft);
}

.pgm-val {
  margin-top: 4px;
  font-size: 27px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--pgm-blue);
}

.pgm-board { padding: 18px; }

/* ============================================================
   TABLERO
   ============================================================ */

.pgm-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.pgm-card { perspective: 1000px; }

.pgm-card button {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .35s cubic-bezier(.2, .8, .3, 1);
}

.pgm-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--pgm-line);
  border-radius: var(--pgm-radius);
  backface-visibility: hidden;
}

.pgm-front { background: var(--pgm-card-front); }
.pgm-front img { width: 62%; }

.pgm-back {
  background: var(--pgm-card-back);
  transform: rotateY(180deg);
}

.pgm-back img { width: 72%; object-fit: contain; }

.pgm-flipped button { transform: rotateY(180deg); }

.pgm-matched .pgm-back {
  border-color: var(--pgm-lime);
  box-shadow: 0 0 0 3px var(--pgm-lime) inset, 0 0 22px rgba(193, 232, 119, .5);
}

.pgm-matched button { animation: pgm-pop .4s ease; }

@keyframes pgm-pop {
  50% { transform: rotateY(180deg) scale(1.06); }
}

/* ============================================================
   OVERLAY / FORMULARIO
   ============================================================ */

.pgm-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow-y: auto;
  background: rgba(2, 6, 23, .72);
}

.pgm-modal {
  width: min(760px, 100%);
  margin: auto;
  padding: 26px 26px 20px;
  background: var(--pgm-panel);
  border: 1px solid var(--pgm-line);
  border-radius: var(--pgm-radius-xl);
  box-shadow: var(--pgm-shadow);
}

.pgm-modal-logo { width: 190px; margin: 0 auto 16px; }

.pgm-title {
  margin: 0 0 8px;
  font-size: clamp(23px, 3.6vw, 30px);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  color: var(--pgm-text-dark);
}

.pgm-lead {
  margin: 0 auto 22px;
  max-width: 56ch;
  color: var(--pgm-text-soft);
  font-size: 15px;
  line-height: 1.6;
  text-align: center;
}

.pgm-field { margin-bottom: 13px; }

.pgm-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
}

.pgm-field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--pgm-text-soft);
}

.pgm-field input[type="text"],
.pgm-field input[type="tel"],
.pgm-field input[type="email"],
.pgm-field select {
  width: 100%;
  padding: 13px 14px;
  font-family: inherit;
  font-size: 15px;
  /* Fondo sólido: el original era rgba(255,255,255,.04) sobre panel
     claro, así que los campos se perdían contra el fondo. */
  color: var(--pgm-text-dark);
  background: #FFFFFF;
  border: 1px solid var(--pgm-line);
  border-radius: var(--pgm-radius);
  appearance: none;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.pgm-field select {
  padding-right: 38px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--pgm-text-soft) 50%),
    linear-gradient(135deg, var(--pgm-text-soft) 50%, transparent 50%);
  background-position: right 18px center, right 13px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.pgm-field input::placeholder { color: #93A7B8; }

.pgm-field input:focus,
.pgm-field select:focus {
  border-color: var(--pgm-blue);
  box-shadow: 0 0 0 3px rgba(0, 115, 196, .22);
}

.pgm-field.is-invalid input,
.pgm-field.is-invalid select { border-color: var(--pgm-error); }

.pgm-msg {
  display: none;
  margin-top: 6px;
  font-size: 13px;
  color: var(--pgm-error);
}

.pgm-field.is-invalid .pgm-msg,
.pgm-msg.is-visible { display: block; }

/* --- Consentimiento --- */

.pgm-field > label.pgm-consent,
.pgm-consent {
  margin-bottom: 0;
  font-size: 13.5px;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
}

.pgm-consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 6px 0 14px;
  line-height: 1.5;
  color: var(--pgm-text-soft);
  cursor: pointer;
}

.pgm-consent input[type="checkbox"] {
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
  margin: 1px 0 0;
  accent-color: var(--pgm-blue);
  cursor: pointer;
}

.pgm-consent a {
  color: var(--pgm-blue);
  text-decoration: underline;
}

/* --- Botones --- */

.pgm-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 15px 20px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  text-decoration: none;
  color: var(--pgm-blue);
  background: var(--pgm-lime);
  border: 1px solid var(--pgm-lime);
  border-radius: var(--pgm-radius);
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(2, 132, 199, .25);
  transition: background .16s, border-color .16s, transform .05s;
}

.pgm-btn:hover:not(:disabled) {
  background: var(--pgm-lime-dark);
  border-color: var(--pgm-lime-dark);
}

.pgm-btn:active:not(:disabled) { transform: translateY(1px); }
.pgm-btn:disabled { opacity: .6; cursor: not-allowed; }

.pgm-btn--ghost {
  color: var(--pgm-blue);
  background: transparent;
  border-color: var(--pgm-line);
  box-shadow: none;
}

.pgm-btn--ghost:hover:not(:disabled) {
  background: var(--pgm-panel-2);
  border-color: var(--pgm-blue);
}

.pgm-btn + .pgm-btn { margin-top: 10px; }

.pgm-form-error {
  min-height: 20px;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--pgm-error);
  text-align: center;
}

/* ============================================================
   RESULTADO
   ============================================================ */

/* La pantalla de resultado no muestra tiempo ni clics: sólo el mensaje.
   Ese bloque de estadísticas se retiró a propósito. */

/* ============================================================
   PANTALLA DE CIERRE
   ============================================================ */

.pgm-closed {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}

.pgm-closed .pgm-modal { padding: 40px 28px 32px; }
.pgm-closed .pgm-btn { width: auto; margin: 0 auto; padding: 14px 28px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Hasta 1023px: una sola columna. El corte es 1023 y no 1024 porque el
   bloque de escritorio empieza en 1024: si ambos dijeran 1024, a ese
   ancho exacto se aplicarían los dos a la vez y el tablero se montaría
   encima de la barra lateral. */
@media (max-width: 1023px) {
  .pgm-wrap { grid-template-columns: 1fr; }
  .pgm-sidebar { position: static; }
  .pgm-logo { width: 145px; margin-bottom: 12px; }
  .pgm-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
}

@media (max-width: 560px) {
  .pgm-wrap { padding: 10px; gap: 10px; }
  .pgm-sidebar { padding: 16px 14px; }
  .pgm-board { padding: 10px; }
  .pgm-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
  .pgm-hello { font-size: 20px; }
  .pgm-muted { margin-bottom: 14px; font-size: 14px; }
  .pgm-val { font-size: 22px; }
  .pgm-modal { padding: 20px 16px 18px; }
  .pgm-modal-logo { width: 155px; }
  .pgm-row { grid-template-columns: 1fr; gap: 13px; }
}

/* ============================================================
   ESCRITORIO: el tablero 5x4 completo cabe en una sola pantalla
   ------------------------------------------------------------
   Dos decisiones que conviene no deshacer:

   1) El umbral de altura es bajo (480px) A PROPÓSITO. En Windows, con
      el escalado del sistema al 125% o 150%, un monitor 1080p deja un
      viewport de ~600px de alto. Con umbrales altos la regla no se
      activa y las cartas obligan a hacer scroll; en Mac no se nota
      porque el viewport siempre es más alto.

   2) Las reglas de TAMAÑO no dependen de ninguna clase en el body: se
      apoyan en `.pgm-wrap`, `.pgm-board` y `.pgm-grid`, que sólo
      existen en juego.html, así que no pueden filtrarse a ranking.html
      ni a cerrado.html. Sólo `overflow: hidden` va atado a la clase
      `pgm-juego`, porque ése sí rompería el scroll de esas páginas.

   En escritorio la rejilla llena el tablero y cada carta ocupa su
   celda completa, como hacía la versión original: así se aprovecha
   todo el espacio y nunca hay desbordamiento.
   ============================================================ */
@media (min-width: 1024px) and (min-height: 480px) {
  body.pgm-juego {
    height: 100vh;              /* respaldo para navegadores sin dvh */
    height: 100dvh;
    overflow: hidden;
  }

  .pgm-wrap {
    height: 100vh;
    height: 100dvh;
    /* En ventanas bajas el ancho también se recorta: si no, la rejilla
       —limitada por la altura— queda centrada en una columna enorme
       y sobra aire muerto a los lados. */
    max-width: min(1280px, calc(350px + 115vh));
    max-width: min(1280px, calc(350px + 115dvh));
  }

  .pgm-sidebar {
    max-height: calc(100dvh - 40px);
    overflow: auto;
  }

  .pgm-board {
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
    min-height: 0;
    overflow: hidden;           /* red de seguridad: nunca desborda */
  }

  /* La rejilla ocupa todo el tablero y cada carta llena su celda, igual
     que hacía la versión original en su modo "sin scroll". Se prefiere
     esto a fijar la proporción 2:3: limitada por la altura, la rejilla
     quedaba de apenas 65px de ancho por carta y los iconos se perdían. */
  .pgm-grid {
    height: 100%;
    width: 100%;
    min-width: 0;               /* sin esto, como hijo flex no encoge */
    margin: 0 auto;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
  }

  /* La carta llena su celda: así nunca desborda, sea cual sea la altura. */
  .pgm-card button { height: 100%; aspect-ratio: auto; }
}

/* Ventanas bajas en escritorio: apretar márgenes para ganar altura útil
   antes de que las cartas se vuelvan diminutas. */
@media (min-width: 1024px) and (max-height: 720px) {
  .pgm-wrap { gap: 12px; padding: 12px; }
  .pgm-board { padding: 10px; height: calc(100dvh - 24px); }
  .pgm-sidebar { padding: 16px 14px; max-height: calc(100dvh - 24px); }
  .pgm-logo { width: 135px; margin-bottom: 10px; }
  .pgm-hello { font-size: 20px; }
  .pgm-muted { margin-bottom: 12px; font-size: 13.5px; }
  .pgm-val { font-size: 22px; }
  .pgm-grid { gap: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .pgm-card button, .pgm-matched button { transition: none; animation: none; }
}
