:root {
  --azul-institucional: #075476;
  --azul-oscuro: #173f55;
  --crema: #fff1dc;
  --crema-suave: #f4ead5;
  --naranja-pastel: #ee7b72;
  --verde-pastel: #bfe3c0;
  --verde-pastel-borde: #78b97b;
  --amarillo: #ffd34e;
  --amarillo-intenso: #ffc400;
  --blanco: #ffffff;
  --gris-claro: #f6f8f7;
  --gris-azulado: #647680;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: "Segoe UI", sans-serif;
  color: var(--azul-oscuro);
  background: var(--crema);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* HEADER */
header {
  background: var(--azul-institucional);
  color: var(--blanco);
  min-height: 96px;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  position: relative;
}
header h1 {
  flex: 1;
  text-align: center;
  font-size: 2rem;
}
.logo-img {
  width: 100px;
  height: 80px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.24));
}
.score {
  width: 270px;
  white-space: nowrap;
  font-size: 1.08rem;
}
.score strong {
  font-size: 1.3rem;
}

/* BOTÓN VOLVER AL MENÚ */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.25);
  color: var(--blanco);
  font-weight: 700;
  font-size: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 50px;
  text-decoration: none;
  cursor: pointer;
  transition:
    background 0.18s,
    transform 0.18s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-back:hover {
  background: rgba(255, 255, 255, 0.45);
  transform: translateX(-2px);
}
.btn-back:active {
  transform: scale(0.95);
}

/* MAIN */
main {
  flex: 1;
  max-width: 1120px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 24px;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  align-items: start;
  gap: 40px;
}
.hint {
  text-align: center;
  color: var(--gris-azulado);
  font-size: 0.85rem;
}

/* CARD — más grande */
.card-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding-top: 24px;
  padding-left: 10px;
  gap: 20px;
}
.card {
  width: 350px;
  height: 350px;
  perspective: 800px;
  cursor: grab;
}
.card.dragging {
  opacity: 0.5;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s ease;
  border-radius: 0;
}
.card.flipped .card-inner {
  transform: rotateY(180deg);
}

/* Mientras se arrastra, fijamos la cara frontal visible */
.card.dragging .card-inner {
  transform: none !important;
}

.card-front,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: none;
  padding: 0;
}
.card-front {
  background: transparent;
  border: 0;
}
.card-back {
  background: transparent;
  border: 0;
  transform: rotateY(180deg);
}

.card-img {
  font-size: 3.5rem;
  line-height: 1;
}
.card-img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
  border-radius: 0;
}
.back-img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
  border-radius: 0;
}
.card-img,
.back-img {
  width: 100%;
  height: 100%;
}
#card-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--azul-oscuro);
  text-align: center;
  display: none;
}

.card-back .lbl,
#back-portion,
#back-cat,
.feedback-message {
  display: none;
}

.lbl {
  font-size: 0.65rem;
  color: var(--gris-azulado);
  text-transform: uppercase;
  letter-spacing: 1px;
}
#back-portion {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}
.cat-badge {
  color: var(--blanco);
  font-size: 0.75rem;
  font-weight: 800;
  border-radius: 50px;
  padding: 4px 14px;
  margin-top: 2px;
  text-align: center;
}
.feedback-message {
  min-height: 18px;
  font-size: 0.78rem;
  font-weight: 900;
  text-align: center;
}
.card.correct .feedback-message {
  color: #3f7d43;
}
.card.wrong .feedback-message {
  color: #a53f37;
}

/* Correct/wrong ring after flip */
.card.correct .card-back {
  box-sizing: border-box;
  border: 8px solid var(--verde-pastel-borde);
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(191, 227, 192, 0.65);
}
.card.wrong .card-back {
  box-sizing: border-box;
  border: 8px solid var(--naranja-pastel);
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(238, 123, 114, 0.35);
}

/* END */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  font-size: 1.1rem;
}
.empty button {
  padding: 10px 28px;
  background: var(--amarillo-intenso);
  color: var(--azul-oscuro);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: transform 0.15s;
}
.empty button:hover {
  transform: scale(1.05);
}

.result-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--azul-oscuro);
  text-align: center;
}

.result-stats {
  display: flex;
  gap: 24px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--blanco);
  border-radius: 14px;
  padding: 16px 28px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.1);
  min-width: 110px;
}
.stat-num {
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1;
}
.stat-lbl {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gris-azulado);
}
.stat-ok .stat-num {
  color: var(--verde-pastel-borde);
}
.stat-err .stat-num {
  color: var(--naranja-pastel);
}
.hidden {
  display: none !important;
}

/* DROP ZONES */
.zones {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 18px;
  width: 100%;
  margin-top: 17px;
}
.drop-zone {
  position: relative;
  background: var(--blanco);
  border: 2px solid var(--crema-suave);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 280px;
  min-height: 0;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  box-shadow: 0 5px 16px rgba(23, 63, 85, 0.08);
}
.wrong-card-preview {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(88%, 240px);
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  overflow: hidden;
  border: 0;
  border-radius: 50%;
  background: transparent;
  opacity: 0.82;
  pointer-events: none;
  animation: wrong-card-preview-in 0.2s ease-out;
}

.wrong-card-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

.chip.err {
  cursor: pointer;
}

@keyframes wrong-card-preview-in {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }

  to {
    opacity: 0.82;
    transform: translate(-50%, -50%) scale(1);
  }
}

.drop-zone.over {
  border-color: var(--azul-institucional);
  box-shadow: 0 0 0 3px rgba(7, 84, 118, 0.2);
}

.zh {
  padding: 12px 8px;
  text-align: center;
  color: var(--blanco);
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1.1;
}
.zh.blue {
  background: var(--azul-institucional);
}
.zh.green {
  background: var(--verde-pastel-borde);
  color: var(--azul-oscuro);
}
.zh.amber {
  background: var(--amarillo);
  color: var(--azul-oscuro);
}
.zh.red {
  background: var(--naranja-pastel);
  color: var(--azul-oscuro);
}

.zb {
  flex: 1;
  min-height: 0;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.zc {
  background: var(--crema);
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--azul-oscuro);
  padding: 3px;
  border-top: 1px solid var(--crema-suave);
}

/* Chips in zone */
.chip {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 20px;
  width: 100%;
  text-align: center;
  border: 1px solid var(--crema-suave);
  background: var(--crema);
  color: var(--azul-oscuro);
  transition: transform 0.2s;
}
.chip:hover {
  transform: scale(1.08);
  cursor: default;
}
.chip.ok {
  background: var(--verde-pastel);
  border-color: var(--verde-pastel-borde);
  color: var(--azul-oscuro);
}
.chip.err {
  background: var(--naranja-pastel);
  border-color: var(--naranja-pastel);
  color: var(--blanco);
}

/* PROGRESS */
.prog-wrap {
  height: 16px;
  background: var(--crema-suave);
}
#prog {
  height: 100%;
  background: var(--amarillo-intenso);
  transition: width 0.4s;
  width: 0;
}

.question-counter {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  min-width: 68px;
  padding: 9px 14px;
  border: 2px solid var(--amarillo);
  border-radius: 50px;
  background: var(--azul-institucional);
  color: var(--blanco);
  box-shadow: 0 4px 14px rgba(23, 63, 85, 0.22);
  font-size: 1rem;
  font-weight: 900;
  text-align: center;
}

@media (max-width: 1000px) {
  main {
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
  }
  .card-area {
    padding: 0;
  }
  .zones {
    width: min(100%, 720px);
    margin-top: 0;
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  body {
    background: #f1efe9;
  }

  header {
    min-height: 62px;
    padding: 6px 12px;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
  }

  header h1 {
    font-size: 0.76rem;
    line-height: 1.2;
    flex: 1;
    text-align: center;
    margin: 0 auto;
  }

  .logo-img {
    width: 62px;
    height: 56px;
  }

  .btn-back {
    padding: 6px 10px;
    font-size: 0.72rem;
  }

  .score {
    width: auto;
    font-size: 0.72rem;
    white-space: normal;
  }

  .score strong {
    font-size: 0.85rem;
  }

  main {
    padding: 12px 16px 18px;
    display: block;
  }

  .hint {
    display: none;
  }

  .card-area {
    width: 100%;
    padding: 0 0 12px;
    gap: 14px;
  }

  .card {
    width: min(82vw, 360px);
    height: min(82vw, 360px);
    margin: 0 auto;
  }

  .card-front,
  .card-back {
    border-radius: 0;
    border-width: 0;
    background: transparent;
    box-shadow: none;
  }

  .card-front {
    border-color: #0b4f6d;
  }

  .card-back {
    border-color: #0b4f6d;
  }

  .card-img {
    font-size: 4rem;
  }

  .card-img img,
  .back-img img {
    width: 100%;
    height: 100%;
  }

  #card-name {
    font-size: 1.4rem;
    font-weight: 800;
  }

  .zones {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
    gap: 12px 12px;
    width: 100%;
    margin-top: 6px;
    align-items: stretch;
  }

  .drop-zone {
    height: 260px;
    min-height: 0;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: none;
    border-width: 0;
    background: #f1efe9;
  }

  .zh {
    min-height: 95px;
    padding: 12px 10px;
    font-size: 1.2rem;
    line-height: 1.15;
    letter-spacing: 0.02em;
  }

  .zb {
    padding: 10px 8px 0;
  }

  .zc {
    font-size: 0.82rem;
    padding: 6px 0 8px;
    background: transparent;
    border-top: none;
  }

  .question-counter {
    right: 18px;
    bottom: 18px;
    min-width: 74px;
    padding: 10px 16px;
    font-size: 1.05rem;
  }

  .prog-wrap {
    display: none;
  }
}

/* ── DIFFICULTY OVERLAY ───────────────────────────────────────────────────── */
.diff-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background-color: var(--crema) !important;
  background-image: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: diffFadeIn 0.4s ease;
  transition:
    opacity 0.35s ease,
    transform 0.35s ease;
}
.diff-overlay.diff-hide {
  opacity: 0;
  transform: scale(1.04);
  pointer-events: none;
}
.diff-overlay.hidden {
  display: none !important;
}

@keyframes diffFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.diff-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 40px 32px;
  max-width: 580px;
  width: 90%;
  background: rgba(255, 241, 220, 0.84);
  border: 2px solid var(--crema-suave);
  border-radius: 24px;
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: modalSlideUp 0.45s cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.diff-logo {
  height: 64px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}

.diff-title {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--azul-oscuro);
  text-align: center;
  text-shadow: none;
  line-height: 1.2;
}
.diff-sub {
  font-size: 0.95rem;
  color: var(--gris-azulado);
  text-align: center;
  margin-top: -12px;
}

.diff-cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 150px;
  padding: 24px 16px;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  font-family: "Segoe UI", sans-serif;
  transition:
    transform 0.18s,
    box-shadow 0.18s;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
}
.diff-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0);
  transition: background 0.18s;
}
.diff-btn:hover {
  transform: translateY(-5px) scale(1.04);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
}
.diff-btn:hover::after {
  background: rgba(255, 255, 255, 0.12);
}
.diff-btn:active {
  transform: scale(0.96);
}

.diff-easy {
  background: var(--azul-institucional);
}
.diff-medium {
  background: var(--amarillo);
}
.diff-hard {
  background: var(--naranja-pastel);
}
.diff-medium .diff-name,
.diff-medium .diff-desc,
.diff-hard .diff-name,
.diff-hard .diff-desc {
  color: var(--azul-oscuro);
  text-shadow: none;
}

.diff-icon {
  font-size: 2.4rem;
  line-height: 1;
}
.diff-name {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--blanco);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.diff-desc {
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.18);
  border-radius: 50px;
  padding: 2px 10px;
}

.diff-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 22px;
  background: var(--blanco);
  color: var(--azul-oscuro);
  font-weight: 700;
  font-size: 0.9rem;
  border: 2px solid var(--azul-institucional);
  border-radius: 50px;
  text-decoration: none;
  transition:
    background 0.18s,
    transform 0.18s;
}
.diff-back-btn:hover {
  background: var(--crema-suave);
  transform: translateX(-3px);
}
.diff-back-btn:active {
  transform: scale(0.95);
}

@media (max-width: 480px) {
  .diff-btn {
    width: 130px;
    padding: 18px 12px;
  }
  .diff-title {
    font-size: 1.2rem;
  }
}
