:root {
  --cream: #f4e4c1;
  --red: #d42017;
  --wine: #702319;
  --ink: #251612;
  --safe-x: clamp(16px, 3vw, 56px);
  --safe-y: clamp(12px, 2.4vh, 32px);
  --logo-width: clamp(130px, 15vw, 250px);
  --question-size: clamp(2.2rem, 4.6vw, 5.1rem);
  --answer-size: clamp(0.88rem, 1.25vw, 1.28rem);
  --result-name-size: clamp(2.8rem, 6vw, 6.3rem);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

html {
  overflow-x: clip;
}

body {
  overflow-x: clip;
  background: #6c1b19;
  color: var(--cream);
  font-family: Arial, sans-serif;
  text-align: center;
}

button,
img {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus-visible,
[role="button"]:focus-visible {
  outline: 4px solid #ffffff;
  outline-offset: 4px;
}

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

#loading-screen,
#screen-bienvenida,
#card,
#screen-resultado {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--safe-y) var(--safe-x);
  background: var(--red) url(images/fondo-01.png) center / cover no-repeat;
}

.loading-content {
  width: min(400px, 80vw);
}

.loading-content h2 {
  margin: 0 0 20px;
  color: var(--cream);
  font-family: "Bebas Neue", sans-serif;
  font-size: clamp(2rem, 6vw, 3rem);
}

.loading-track {
  height: 10px;
  margin: 20px 0;
  overflow: hidden;
  border-radius: 999px;
  background: rgb(244 228 193 / 30%);
}

#loading-progress {
  width: 0;
  height: 100%;
  background: var(--cream);
  transition: width 0.3s ease;
}

#loading-text {
  margin: 0;
  color: var(--cream);
  font-size: 1rem;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  margin: 20px auto;
  border: 3px solid rgb(244 228 193 / 30%);
  border-top-color: var(--cream);
  border-radius: 50%;
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Bienvenida */
#screen-bienvenida {
  overflow: hidden;
}

.welcome-layout {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  align-items: center;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--safe-y) var(--safe-x);
  background: var(--red) url(images/fondo-01.png) center / cover no-repeat;
  isolation: isolate;
}

.welcome-logos {
  position: absolute;
  top: var(--safe-y);
  right: var(--safe-x);
  z-index: 4;
  width: var(--logo-width);
}

#btn-conectar-esp {
  position: absolute;
  top: var(--safe-y);
  left: var(--safe-x);
  z-index: 5;
  min-height: 48px;
  padding: 10px 20px;
  border: 2px solid var(--wine);
  border-radius: 10px;
  background: var(--cream);
  color: var(--wine);
  cursor: pointer;
  font-family: "Bebas Neue", sans-serif;
  font-size: clamp(1rem, 1.8vw, 2rem);
}

.welcome-copy {
  z-index: 3;
  align-self: center;
  justify-self: center;
  width: min(760px, 100%);
  text-align: left;
}

.welcome-copy h1 {
  margin: 0;
  color: var(--cream);
  font-family: "Bebas Neue", sans-serif;
  font-size: clamp(4.5rem, 9.5vw, 10rem);
  font-weight: 700;
  line-height: 0.86;
  text-shadow: -3px 2px 2px #464646;
}

#btn-iniciar-juego,
#reiniciar-juego {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

#btn-iniciar-juego {
  width: min(360px, 62%);
  margin-top: clamp(12px, 2vh, 28px);
}

.welcome-illustration {
  z-index: 2;
  align-self: end;
  justify-self: end;
  width: min(44vw, 760px);
  max-height: 82vh;
  max-height: 82dvh;
  pointer-events: none;
}

.welcome-illustration img {
  width: 100%;
  height: auto;
  max-height: 82vh;
  max-height: 82dvh;
  object-fit: contain;
  object-position: right bottom;
}

/* Preguntas */
#card {
  position: relative;
  overflow: hidden;
  padding: var(--safe-y) var(--safe-x);
  background: var(--red) url(images/fondo-02.png) center / cover no-repeat;
  isolation: isolate;
}

.logos {
  position: absolute;
  top: var(--safe-y);
  right: var(--safe-x);
  z-index: 8;
  width: var(--logo-width);
  pointer-events: none;
}

.logos img {
  width: 100%;
  height: auto;
}

#count_pregunta {
  position: absolute;
  top: var(--safe-y);
  left: var(--safe-x);
  z-index: 8;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  color: #ffffff;
  font-size: clamp(1rem, 1.8vw, 2rem);
  line-height: 1;
}

#pregunta {
  position: relative;
  z-index: 5;
  width: min(74vw, 1320px);
  margin: 0 auto;
  padding-top: clamp(60px, 9vh, 100px);
  color: var(--cream);
  font-family: "Bebas Neue", sans-serif;
  font-size: var(--question-size);
  font-weight: 600;
  line-height: 0.98;
  text-wrap: balance;
  text-shadow: -3px 2px 2px #464646;
}

.respuestas {
  position: absolute;
  top: clamp(330px, 52vh, 560px);
  right: var(--safe-x);
  bottom: auto;
  left: var(--safe-x);
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: clamp(20px, 8vw, 220px);
  width: min(1000px, calc(100% - 2 * var(--safe-x)));
  margin: 0 auto;
}

.btn {
  position: static;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  min-height: clamp(150px, 27vh, 300px);
  padding: clamp(18px, 2.4vw, 34px);
  border: 3px solid rgb(255 255 255 / 35%);
  border-radius: 50%;
  box-shadow: 0 12px 24px rgb(0 0 0 / 18%);
  cursor: pointer;
  font-size: var(--answer-size);
  font-weight: 400;
  line-height: 1.25;
  text-wrap: balance;
  transition: translate 0.18s ease, box-shadow 0.18s ease;
}

.respuesta-copy {
  display: block;
  width: 100%;
}

.btn:hover,
.btn:focus-visible {
  box-shadow: 0 16px 30px rgb(0 0 0 / 28%);
  translate: 0 -3px;
}

#btn-respuesta1 {
  background: var(--cream);
  color: var(--wine);
}

#btn-respuesta2 {
  background: var(--wine);
  color: var(--cream);
}

.personajes-1,
.personajes-2 {
  position: absolute;
  bottom: 0;
  z-index: 4;
  width: min(29vw, 450px);
  pointer-events: none;
}

.personajes-1 {
  left: 1vw;
}

.personajes-2 {
  right: 1vw;
}

.personajes-1 img,
.personajes-2 img {
  width: 100%;
  max-height: min(48vh, 450px);
  object-fit: contain;
  object-position: bottom;
}

#resultado {
  display: none;
}

/* Resultados */
#screen-resultado {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2vh, 28px);
  overflow-x: clip;
  overflow-y: auto;
  padding: clamp(76px, 10vh, 110px) var(--safe-x) var(--safe-y);
  background: var(--wine) url(images/fondo-resultado.png) center / cover fixed no-repeat;
}

#resultado-contenido {
  display: grid;
  grid-template-columns: minmax(180px, 0.34fr) minmax(0, 0.66fr);
  align-items: center;
  gap: clamp(24px, 5vw, 70px);
  width: min(1200px, 100%);
  margin: auto;
}

.resultado-imagen {
  display: grid;
  place-items: center;
  min-width: 0;
}

.resultado-imagen img {
  width: auto;
  max-width: 100%;
  height: min(52vh, 520px);
  border-radius: 14px;
  object-fit: contain;
}

.resultado-imagen-placeholder {
  display: grid;
  place-items: center;
  width: min(240px, 100%);
  height: min(52vh, 320px);
  border: 2px dashed rgb(244 228 193 / 65%);
  border-radius: 16px;
  color: var(--cream);
  font-size: 0.9rem;
}

.resultado-info {
  min-width: 0;
  color: var(--cream);
  text-align: left;
}

.copy-resultado {
  margin: 0;
  color: var(--cream);
  font-size: clamp(1rem, 1.7vw, 2rem);
}

.nombre-personaje {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--cream);
  font-family: "Bebas Neue", sans-serif;
  font-size: var(--result-name-size);
  line-height: 0.94;
  text-shadow: -2px 1px 1px #464646;
}

h3.arquetipo-personaje {
  margin: 10px 0 16px;
  color: var(--cream);
  font-size: clamp(1.1rem, 1.7vw, 2rem);
  font-style: italic;
  font-weight: 400;
}

p.descripcion-personaje {
  margin: 0;
  color: var(--cream);
  font-size: clamp(0.95rem, 1.25vw, 1.35rem);
  line-height: 1.45;
  text-shadow: -1px 1px 1px #464646;
}

#reiniciar-juego {
  flex: 0 0 auto;
  width: min(330px, 42vw);
  margin: 0 auto;
}

#resultado-contenido.resultado-contenido-multiple {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: min(1500px, 100%);
  margin: 0 auto;
  overflow: visible;
}

.resultado-multiple-titulo {
  text-align: center;
}

.resultado-lista {
  --resultado-columnas: 3;
  --resultado-gap: clamp(16px, 2vw, 28px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: var(--resultado-gap);
  width: 100%;
}

.resultado-personaje {
  display: flex;
  flex: 0 1 calc(
    (100% - (var(--resultado-columnas) - 1) * var(--resultado-gap))
    / var(--resultado-columnas)
  );
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: clamp(16px, 2vw, 24px);
  border: 1px solid rgb(244 228 193 / 28%);
  border-radius: var(--radius);
  background: rgb(69 20 17 / 76%);
  color: var(--cream);
  text-align: center;
}

.resultado-personaje img,
.resultado-personaje .resultado-imagen-placeholder {
  width: auto;
  max-width: 100%;
  height: clamp(130px, 24vh, 240px);
  margin-bottom: 12px;
  object-fit: contain;
}

.resultado-personaje .resultado-imagen-placeholder {
  width: min(170px, 100%);
}

.resultado-personaje .nombre-personaje {
  font-size: clamp(2rem, 3.2vw, 3.7rem);
}

.resultado-personaje .arquetipo-personaje {
  font-size: clamp(1rem, 1.25vw, 1.35rem);
}

.resultado-personaje .descripcion-personaje {
  margin-top: 10px;
  font-size: clamp(0.9rem, 1vw, 1.05rem);
  line-height: 1.35;
}

#personality-result-debug {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: min(520px, calc(100vw - 24px));
  max-height: min(45dvh, 360px);
  overflow: auto;
  padding: 12px 14px;
  border: 1px solid rgb(255 255 255 / 45%);
  border-radius: 8px;
  background: rgb(14 14 14 / 92%);
  color: #ffffff;
  font: 13px/1.35 monospace;
  text-align: left;
}

#personality-result-debug code {
  overflow-wrap: anywhere;
  color: var(--cream);
}

#personality-result-debug pre {
  margin: 4px 0 0;
  white-space: pre-wrap;
}

/* Orientación */
#orientation-lock {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #0e0e0e;
  color: #ffffff;
  text-align: center;
}

#orientation-lock.active {
  display: flex;
}

.lock-content {
  max-width: 320px;
}

.rotate-icon {
  margin-bottom: 20px;
  font-size: 64px;
  animation: rotateHint 1.6s ease-in-out infinite;
}

@keyframes rotateHint {
  0%,
  100% {
    transform: rotate(0deg);
    opacity: 0.4;
  }
  50% {
    transform: rotate(90deg);
    opacity: 1;
  }
}

/* Tableta y escritorio compacto */
@media (max-width: 1366px) {
  :root {
    --logo-width: clamp(125px, 14vw, 205px);
    --question-size: clamp(1.9rem, 3.5vw, 3rem);
    --result-name-size: clamp(2.5rem, 5.5vw, 5rem);
  }

  #btn-conectar-esp {
    font-size: clamp(1rem, 1.5vw, 1.5rem);
  }

  .respuestas {
    top: clamp(280px, 43vh, 400px);
    gap: clamp(64px, 7vw, 110px);
    width: min(940px, calc(100% - 2 * var(--safe-x)));
  }

  #pregunta {
    width: min(84vw, 1120px);
  }

  .btn {
    min-height: clamp(140px, 22vh, 190px);
  }

  .personajes-1,
  .personajes-2 {
    width: min(22vw, 280px);
  }

  .personajes-1 img,
  .personajes-2 img {
    max-height: 30vh;
  }

  .welcome-copy h1 {
    font-size: clamp(4rem, 9vw, 7.8rem);
  }

  .resultado-lista {
    --resultado-columnas: 2;
  }
}

/* Móvil horizontal */
@media (max-width: 980px) and (orientation: landscape) {
  :root {
    --safe-x: clamp(12px, 2.5vw, 24px);
    --safe-y: clamp(8px, 2vh, 16px);
    --logo-width: clamp(100px, 16vw, 120px);
    --question-size: clamp(1.65rem, 4.3vw, 2.6rem);
    --answer-size: clamp(0.78rem, 1.75vw, 0.98rem);
    --result-name-size: clamp(2rem, 5vw, 3.3rem);
  }

  #btn-conectar-esp {
    display: none;
  }

  .welcome-layout {
    grid-template-columns: minmax(0, 0.9fr) minmax(240px, 1.1fr);
  }

  .welcome-copy h1 {
    font-size: clamp(3.2rem, 8vw, 5.2rem);
  }

  #btn-iniciar-juego {
    width: min(220px, 56%);
    margin-top: 8px;
  }

  .welcome-illustration {
    width: min(54vw, 520px);
  }

  #pregunta {
    width: min(82vw, 780px);
    padding-top: clamp(44px, 11vh, 58px);
  }

  .respuestas {
    top: clamp(168px, 42vh, 220px);
    bottom: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(90px, 19vw, 180px);
    width: min(720px, calc(100% - 2 * var(--safe-x)));
  }

  .btn {
    min-height: clamp(102px, 27vh, 132px);
    padding: 14px 18px;
  }

  .personajes-1,
  .personajes-2 {
    width: min(20vw, 170px);
  }

  .personajes-1 img,
  .personajes-2 img {
    max-height: 27vh;
  }

  #screen-resultado {
    justify-content: flex-start;
    padding-top: clamp(52px, 12vh, 72px);
  }

  #resultado-contenido {
    grid-template-columns: minmax(120px, 0.3fr) minmax(0, 0.7fr);
    gap: 20px;
    margin: 0 auto;
  }

  .resultado-imagen img {
    height: min(44vh, 210px);
  }

  #resultado-contenido > .resultado-imagen-placeholder {
    width: min(150px, 25vw);
    height: min(44vh, 210px);
  }

  p.descripcion-personaje {
    font-size: clamp(0.86rem, 1.7vw, 1rem);
    line-height: 1.32;
  }

  #reiniciar-juego {
    width: min(220px, 34vw);
  }

  .resultado-lista {
    --resultado-columnas: 2;
  }

  .resultado-personaje {
    padding: 14px;
  }
}

/* Altura reducida */
@media (max-height: 760px) and (orientation: landscape) {
  :root {
    --safe-y: clamp(8px, 1.7vh, 14px);
    --question-size: clamp(1.8rem, 4vw, 3.5rem);
  }

  .welcome-copy h1 {
    font-size: clamp(3.3rem, 8.5vh, 6rem);
  }

  #btn-iniciar-juego {
    width: min(250px, 48%);
    margin-top: 6px;
  }

  .welcome-illustration {
    max-height: 86dvh;
  }

  .welcome-illustration img {
    max-height: 86dvh;
  }

  #pregunta {
    padding-top: clamp(42px, 8vh, 56px);
    line-height: 0.92;
  }

  .respuestas {
    top: clamp(160px, 43vh, 330px);
    bottom: auto;
  }

  .btn {
    min-height: clamp(105px, 29vh, 190px);
    padding: clamp(12px, 2vh, 20px);
  }

  .personajes-1 img,
  .personajes-2 img {
    max-height: 27vh;
  }

  #screen-resultado {
    min-height: 100dvh;
    padding-top: clamp(48px, 10vh, 64px);
  }

  .resultado-imagen img {
    height: min(42vh, 300px);
  }

  .resultado-info h3 {
    margin: 6px 0 10px;
  }

  #reiniciar-juego {
    width: min(210px, 30vw);
  }
}

/* Móvil horizontal de altura muy reducida */
@media (max-width: 760px) and (max-height: 430px) and (orientation: landscape) {
  :root {
    --logo-width: clamp(88px, 17vw, 120px);
    --question-size: clamp(1.35rem, 3.8vw, 1.9rem);
    --answer-size: clamp(0.7rem, 1.7vw, 0.84rem);
  }

  .welcome-layout {
    grid-template-columns: minmax(0, 0.86fr) minmax(210px, 1.14fr);
  }

  .welcome-copy h1 {
    font-size: clamp(2.8rem, 12vh, 4rem);
  }

  #btn-iniciar-juego {
    width: min(180px, 54%);
  }

  #pregunta {
    width: min(84vw, 620px);
    padding-top: 42px;
  }

  #count_pregunta {
    min-height: 38px;
    padding: 5px 8px;
    font-size: 0.9rem;
  }

  .respuestas {
    top: clamp(145px, 43vh, 180px);
    bottom: auto;
    gap: clamp(68px, 17vw, 110px);
  }

  .btn {
    min-height: clamp(92px, 27vh, 108px);
    padding: 10px 12px;
  }

  .personajes-1,
  .personajes-2 {
    width: min(18vw, 120px);
  }

  .personajes-1 img,
  .personajes-2 img {
    max-height: 25vh;
  }

  #screen-resultado {
    padding-top: 44px;
  }

  #resultado-contenido {
    grid-template-columns: minmax(90px, 0.25fr) minmax(0, 0.75fr);
    gap: 14px;
  }

  .resultado-imagen img {
    height: min(38vh, 155px);
  }

  #resultado-contenido > .resultado-imagen-placeholder {
    width: min(110px, 22vw);
    height: min(38vh, 155px);
  }

  .resultado-lista {
    --resultado-columnas: 1;
  }

  .resultado-personaje {
    display: grid;
    grid-template-columns: minmax(90px, 0.25fr) minmax(0, 0.75fr);
    column-gap: 14px;
    text-align: left;
  }

  .resultado-personaje img,
  .resultado-personaje .resultado-imagen-placeholder {
    grid-row: 1 / span 3;
    height: 120px;
    margin: 0;
  }

  .resultado-personaje .nombre-personaje,
  .resultado-personaje .arquetipo-personaje,
  .resultado-personaje .descripcion-personaje {
    grid-column: 2;
    text-align: left;
  }

  #reiniciar-juego {
    width: min(180px, 32vw);
  }
}

@media (max-width: 690px) and (orientation: landscape) {
  .respuestas {
    gap: clamp(46px, 12vw, 80px);
  }

  .personajes-1,
  .personajes-2 {
    opacity: 0.72;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
