/* =========================================================
   SPRINT 2 — MEMORAMA Y CLASIFICA

   Uso:
   Estilos compartidos por .screen-memory-game y .screen-classify-game.
   Los tableros ocupan el espacio restante y se reorganizan al cambiar la
   orientación sin provocar scroll en la página o gestos del navegador.
========================================================= */

.screen-memory-game,
.screen-classify-game {
  overflow: hidden !important;
}

.learning-game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: clamp(5px, 1.2vh, 10px);
}

.learning-game-topbar {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(100px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.learning-game-title {
  min-width: 0;
  display: grid;
  text-align: center;
}

.learning-game-title strong {
  font-size: clamp(18px, 4.5vw, 27px);
}

.learning-game-title span {
  overflow: hidden;
  font-size: clamp(11px, 2.8vw, 14px);
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: .76;
}

.learning-game-stats {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
}

.learning-game-stats > span {
  padding: 6px 9px;
  border: 3px solid white;
  border-radius: 999px;
  background: rgba(255,255,255,.88);
  font-size: clamp(10px, 2.5vw, 13px);
  white-space: nowrap;
}

.memory-message,
.classify-message {
  min-height: 34px;
  display: grid;
  place-items: center;
  padding: 5px 12px;
  border: 3px solid rgba(255,255,255,.85);
  border-radius: 16px;
  background: rgba(255,246,190,.9);
  font-size: clamp(13px, 3.2vw, 17px);
  font-weight: 900;
  text-align: center;
}

.learning-game-loading,
.learning-game-error {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 150px;
  font-weight: 900;
  text-align: center;
}

.learning-level-complete {
  position: absolute;
  z-index: 80;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: inherit;
  background: rgba(33,2,91,.38);
  backdrop-filter: blur(4px);
}

.learning-level-complete > div {
  width: min(100%, 410px);
  display: grid;
  gap: 12px;
  padding: 22px;
  border: 5px solid white;
  border-radius: 26px;
  background: #fff8d2;
  box-shadow: 0 12px 28px rgba(33,2,91,.28);
  text-align: center;
}

.learning-level-complete strong {
  font-size: clamp(22px, 5vw, 30px);
}

.learning-level-complete button {
  min-height: 50px;
  border: 0;
}

.learning-symbol {
  font-size: clamp(28px, 8vmin, 68px);
  line-height: 1;
}

/* =========================================================
   MEMORAMA
========================================================= */

.memory-board {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--memory-columns, 2), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: clamp(5px, 1.5vmin, 12px);
  padding: clamp(6px, 1.4vmin, 12px);
  overflow: hidden;
  border: 4px solid rgba(255,255,255,.86);
  border-radius: clamp(20px, 4vmin, 30px);
  background: rgba(255,255,255,.34);
  touch-action: none;
}

.memory-card {
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: clamp(13px, 2.5vmin, 22px);
  background: transparent;
  perspective: 800px;
}

.memory-card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  transform-style: preserve-3d;
  transition: transform .4s cubic-bezier(.2,.75,.3,1.2);
}

.memory-card.is-open .memory-card-inner,
.memory-card.is-matched .memory-card-inner {
  transform: rotateY(180deg);
}

.memory-card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 4px solid white;
  border-radius: inherit;
  box-shadow: 0 6px 0 rgba(33,2,91,.16);
  backface-visibility: hidden;
}

.memory-card-back {
  background: linear-gradient(145deg,#7957e8,#3f8cff);
  color: white;
  font-size: clamp(24px, 7vmin, 56px);
}

.memory-card-front {
  padding: clamp(4px, 1vmin, 9px);
  transform: rotateY(180deg);
  background: white;
}

.memory-card-front img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.memory-card.is-matched .memory-card-face {
  border-color: #70df88;
  box-shadow: 0 0 15px rgba(88,204,107,.7);
}

/* =========================================================
   CLASIFICA
========================================================= */

.classify-play-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
}

.classify-items {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(105px, 28%), 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: clamp(6px, 1.4vmin, 11px);
  padding: clamp(7px, 1.5vmin, 12px);
  overflow: hidden;
  border: 4px solid rgba(255,255,255,.86);
  border-radius: 25px;
  background: rgba(255,255,255,.36);
  touch-action: none;
}

.classify-card {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 3px;
  padding: 6px;
  overflow: hidden;
  border: 4px solid white;
  border-radius: clamp(15px, 3vmin, 22px);
  background: white;
  box-shadow: 0 6px 0 rgba(33,2,91,.13);
  transition: transform .18s, opacity .3s, border-color .18s;
}

.classify-card img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  pointer-events: none;
}

.classify-card > span {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(10px, 2.6vmin, 15px);
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.classify-card.is-selected {
  z-index: 3;
  border-color: #ffcf55;
  transform: scale(1.06);
  box-shadow: 0 0 15px rgba(255,207,85,.75);
}

.classify-card.is-wrong {
  animation: classifyWrong .35s linear;
  border-color: #ff758f;
}

.classify-card.is-placed {
  opacity: 0;
  transform: scale(.55);
  pointer-events: none;
}

@keyframes classifyWrong {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.classify-bins {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.classify-bin {
  min-width: 0;
  min-height: clamp(68px, 11vh, 100px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  align-items: center;
  padding: 8px 14px;
  border: 5px solid white;
  border-radius: 24px;
  color: #21025b;
  box-shadow: 0 7px 0 rgba(33,2,91,.16);
}

.classify-bin.bin-blue {
  background: linear-gradient(#8edfff,#42bff4);
}

.classify-bin.bin-green {
  background: linear-gradient(#9cf4aa,#58cc6b);
}

.classify-bin-icon {
  grid-row: 1 / -1;
  margin-right: 8px;
  font-size: clamp(30px, 7vmin, 52px);
}

.classify-bin strong {
  min-width: 0;
  overflow: hidden;
  font-size: clamp(15px, 3.8vw, 22px);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.classify-bin small {
  font-weight: 800;
}

.classify-bin.is-correct {
  animation: classifyBinCorrect .4s ease;
}

@keyframes classifyBinCorrect {
  50% { transform: scale(1.035); filter: brightness(1.12); }
}

/* =========================================================
   ORIENTACIÓN HORIZONTAL Y PANTALLAS COMPACTAS
========================================================= */

@media (orientation: landscape) {
  .classify-play-area {
    grid-template-columns: minmax(0, 1fr) minmax(190px, 30%);
    grid-template-rows: minmax(0, 1fr);
  }

  .classify-bins {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }

  .classify-bin {
    min-height: 0;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .learning-game-shell {
    gap: 4px;
  }

  .learning-game-topbar .btn-circ {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .learning-game-title strong {
    font-size: 18px;
  }

  .learning-game-stats > span {
    padding: 4px 7px;
  }

  .memory-message,
  .classify-message {
    min-height: 27px;
    padding: 2px 8px;
  }

  .classify-card {
    padding: 3px;
  }
}

@media (max-width: 520px) and (orientation: portrait) {
  .learning-game-topbar {
    grid-template-columns: auto minmax(70px, 1fr);
  }

  .learning-game-stats {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .learning-game-title span {
    white-space: normal;
  }

  .classify-items {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .classify-bin {
    padding: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .memory-card-inner,
  .classify-card {
    transition: none;
  }
}
