:root {
  --brown: #5a2d1c;
  --warm-light: #ffd66d;
  --cream: #f3ecd8;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  overflow: hidden;
  background-color: #6c3d24;
  background-image: url("images/fondo.png");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  font-family: Arial, Helvetica, sans-serif;
}

.site {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  background: transparent;
}

.artboard {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  isolation: isolate;
  background: transparent;
}

.world {
  position: absolute;
  inset: 0;
  z-index: 1;
  filter: brightness(.48) saturate(.84);
  transition: filter 1.15s ease;
  transform: scale(1.045);
  transform-origin: center center;
}

.scene-base,
.background-mobile {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.scene-base { z-index: 2; }
.background-mobile,
.scene-base-mobile,
.sofa-mobile-overlay { display: none; }

.sofa-mobile-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.book-item {
  --rot: 0deg;
  position: absolute;
  z-index: 4;
  transform-origin: 50% 82%;
  transition: transform .28s cubic-bezier(.2,.75,.2,1), filter .28s ease, opacity .9s ease;
  opacity: .77;
  filter: brightness(.72) saturate(.86);
  will-change: transform, filter;
}

.book-item img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
}

/* Desktop: posiciones aprobadas. */
.item-01 { left: 15.0%; top: 27.1%; width: 13.0%; }
.item-02 { left: 23.4%; top: 25.6%; width: 15.7%; }
.item-03 { left: 44.7%; top: 21.3%; width: 14.1%; }
.item-04 { left: 65.0%; top: 25.2%; width: 14.6%; }
.item-05 { left: 79.3%; top: 29.4%; width: 10.3%; }
.item-06 { left: 13.6%; top: 56.9%; width: 19.6%; z-index: 5; }
.item-07 { left: 27.8%; top: 56.6%; width: 10.2%; z-index: 3; }
.item-08 { left: 62.8%; top: 56.8%; width: 19.2%; z-index: 5; }
.item-09 { left: 77.2%; top: 56.6%; width: 12.4%; z-index: 3; }

.mistika-logo {
  position: absolute;
  z-index: 9;
  left: 7.2%;
  top: 3.6%;
  width: 10.9%;
  height: auto;
  user-select: none;
}

.lamp {
  position: absolute;
  z-index: 12;
  left: 50%;
  top: 0;
  width: 12.6%;
  height: auto;
  transform: translateX(-50%);
  transform-origin: top center;
  filter: brightness(.22) saturate(.55);
  transition: filter .35s ease;
  pointer-events: none;
  user-select: none;
}

.lamp-cable-mobile { display: none; }

.light-beam {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 14.2%;
  width: 62%;
  height: 70%;
  transform: translateX(-50%) scaleY(.18);
  transform-origin: 50% 0;
  clip-path: polygon(48.5% 0, 51.5% 0, 96% 100%, 4% 100%);
  opacity: 0;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(255, 235, 178, .50) 0%,
    rgba(255, 211, 113, .22) 48%,
    rgba(255, 192, 72, .045) 82%,
    rgba(255, 192, 72, 0) 100%
  );
  filter: blur(2px);
  mix-blend-mode: screen;
  transition: opacity .95s ease, transform 1.1s cubic-bezier(.2,.8,.2,1);
}

.buy-button {
  position: absolute;
  z-index: 15;
  top: 8.7%;
  right: 5.3%;
  min-width: 9.2%;
  padding: .40% 1.25%;
  border: 2px solid rgba(255,255,255,.90);
  border-radius: 999px;
  color: #fff;
  text-decoration: none;
  text-align: center;
  font-size: clamp(10px, 1.02vw, 18px);
  font-weight: 400;
  letter-spacing: .02em;
  line-height: 1;
  transition: background .22s ease, color .22s ease, transform .22s ease;
}

.buy-button:hover,
.buy-button:focus-visible {
  background: rgba(255,255,255,.94);
  color: #5b2f20;
  transform: translateY(-2px);
  outline: none;
}

.credit {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: 2.8%;
  margin: 0;
  transform: translateX(-50%);
  width: 90%;
  text-align: center;
  color: rgba(255,255,255,.93);
  font-size: clamp(8px, .87vw, 15px);
  letter-spacing: .26em;
  white-space: nowrap;
}

body.lights-on .world {
  filter: brightness(.91) saturate(1);
}

body.lights-on .lamp {
  animation: lampOn .78s ease-out both;
}

body.lights-on .light-beam {
  opacity: 1;
  transform: translateX(-50%) scaleY(1);
}

body.lights-on .book-item {
  opacity: 1;
  filter: brightness(1.02) saturate(1.02);
}

@keyframes lampOn {
  0% {
    filter: brightness(.22) saturate(.55);
  }
  35% {
    filter: brightness(1.22) saturate(1.08) drop-shadow(0 0 12px rgba(255,220,115,.62));
  }
  52% {
    filter: brightness(.72) saturate(.85) drop-shadow(0 0 5px rgba(255,220,115,.25));
  }
  72% {
    filter: brightness(1.14) saturate(1.04) drop-shadow(0 0 18px rgba(255,220,115,.68));
  }
  100% {
    filter: brightness(1) saturate(1) drop-shadow(0 0 14px rgba(255,220,115,.55));
  }
}

@media (hover: hover) and (pointer: fine) {
  body.lights-on .book-item:hover {
    transform: translateY(-8px) scale(1.028);
    filter: brightness(1.08) saturate(1.05) drop-shadow(0 12px 10px rgba(33,15,8,.34));
  }
}

body.lights-on .book-item.is-touched {
  transform: translateY(-5px) scale(1.02);
  filter: brightness(1.08) saturate(1.05) drop-shadow(0 10px 9px rgba(33,15,8,.30));
}

.page-fade {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #1b0d08;
  opacity: 1;
  pointer-events: none;
  transition: opacity .75s ease;
}

body.loaded .page-fade { opacity: 0; }

@supports (height: 100dvh) {
  body,
  .site { min-height: 100dvh; }

  .artboard {
    width: min(100vw, calc(100dvh * 16 / 9));
  }
}

/* -----------------------------------------------------------
   VERSIÓN VERTICAL APROBADA: celulares y tablets en retrato.
   El lienzo es 1440 × 2560 (9:16).
   ----------------------------------------------------------- */
@media (orientation: portrait) and (max-width: 1024px) {
  html,
  body {
    min-width: 0;
    width: 100%;
    min-height: 100%;
  }

  body {
    overflow-x: hidden;
    overflow-y: auto;
    background-image: url("images/fondo-mobile.png");
    background-size: cover;
    background-position: center center;
  }

  .site {
    width: 100%;
    min-height: 100svh;
    display: grid;
    place-items: center;
    overflow: hidden;
  }

  .artboard {
    width: 100vw;
    max-width: none;
    aspect-ratio: 9 / 16;
    height: auto;
    flex: none;
  }

  .world {
    transform: none;
  }

  .scene-base-desktop { display: none; }
  .background-mobile,
  .scene-base-mobile { display: block; }

  .background-mobile { z-index: 0; }
  .scene-base-mobile { z-index: 2; }

  /* Capa frontal: el sillón y el gato tapan naturalmente los libros inferiores. */
  .sofa-mobile-overlay {
    display: block;
    z-index: 9;
  }

  /* Posiciones tomadas directamente del diseño vertical aprobado. */
  .book-item {
    transform-origin: 0 0;
    transform: rotate(var(--rot));
  }

  .item-01 {
    left: 10.5155%;
    top: 40.8272%;
    width: 27.5297%;
    --rot: -0.063deg;
    z-index: 5;
  }

  .item-02 {
    left: 18.3724%;
    top: 31.6284%;
    width: 34.0428%;
    --rot: 0deg;
    z-index: 4;
  }

  .item-03 {
    left: 30.9616%;
    top: 45.9710%;
    width: 26.1661%;
    --rot: -23.588deg;
    z-index: 6;
  }

  .item-04 {
    left: 48.9462%;
    top: 32.2104%;
    width: 32.0275%;
    --rot: 0deg;
    z-index: 4;
  }

  .item-05 {
    left: 67.2270%;
    top: 42.1764%;
    width: 22.6800%;
    --rot: 0deg;
    z-index: 7;
  }

  /* 10.º y 3.º BGU quedan atrás; 8.º–9.º y 1.º–2.º BGU adelante. */
  .item-07 {
    left: 19.1792%;
    top: 58.5816%;
    width: 22.4432%;
    --rot: 0.064deg;
    z-index: 3;
  }

  .item-09 {
    left: 61.8499%;
    top: 64.9669%;
    width: 27.9006%;
    --rot: -0.184deg;
    z-index: 3;
  }

  .item-08 {
    left: 30.7259%;
    top: 58.3232%;
    width: 46.6391%;
    --rot: 0.182deg;
    z-index: 4;
  }

  .item-06 {
    left: 9.6754%;
    top: 66.2126%;
    width: 43.5763%;
    --rot: -0.015deg;
    z-index: 5;
  }

  /* Movimiento automático muy sutil en móvil.
     Se anima la imagen interior para no alterar la posición/rotación aprobada. */
  body.lights-on .book-item img {
    animation: mobileDriftA 5.8s ease-in-out infinite alternate;
    will-change: transform;
  }

  body.lights-on .item-01 img { animation-name: mobileDriftA; animation-duration: 5.9s; animation-delay: -1.1s; }
  body.lights-on .item-02 img { animation-name: mobileDriftB; animation-duration: 6.7s; animation-delay: -3.2s; }
  body.lights-on .item-03 img { animation-name: mobileDriftC; animation-duration: 5.4s; animation-delay: -2.0s; }
  body.lights-on .item-04 img { animation-name: mobileDriftB; animation-duration: 6.2s; animation-delay: -4.1s; }
  body.lights-on .item-05 img { animation-name: mobileDriftA; animation-duration: 6.8s; animation-delay: -2.7s; }
  body.lights-on .item-06 img { animation-name: mobileDriftC; animation-duration: 6.4s; animation-delay: -3.6s; }
  body.lights-on .item-07 img { animation-name: mobileDriftB; animation-duration: 5.7s; animation-delay: -1.5s; }
  body.lights-on .item-08 img { animation-name: mobileDriftA; animation-duration: 6.9s; animation-delay: -4.8s; }
  body.lights-on .item-09 img { animation-name: mobileDriftC; animation-duration: 6.1s; animation-delay: -2.3s; }

  @keyframes mobileDriftA {
    from { transform: translate3d(-1.5px, 0, 0); }
    to   { transform: translate3d(1.5px, -0.5px, 0); }
  }

  @keyframes mobileDriftB {
    from { transform: translate3d(1.3px, -0.4px, 0); }
    to   { transform: translate3d(-1.3px, 0.4px, 0); }
  }

  @keyframes mobileDriftC {
    from { transform: translate3d(-1px, 0.5px, 0); }
    to   { transform: translate3d(1.8px, -0.5px, 0); }
  }

  .mistika-logo {
    left: 35.8680%;
    top: 3.4250%;
    width: 28.1980%;
    height: auto;
  }

  .lamp-cable-mobile {
    display: block;
    position: absolute;
    z-index: 8;
    left: 50.28%;
    top: 0;
    width: .56%;
    height: 9.35%;
    transform: translateX(-50%);
    background: #35110b;
    pointer-events: none;
  }

  .lamp {
    left: 50.2431%;
    top: 9.2969%;
    width: 22.4306%;
    transform: translateX(-50%);
  }

  .light-beam {
    top: 20.0%;
    width: 90%;
    height: 70%;
    clip-path: polygon(49.2% 0, 50.8% 0, 98% 100%, 2% 100%);
    background: linear-gradient(
      to bottom,
      rgba(255, 235, 178, .48) 0%,
      rgba(255, 211, 113, .20) 46%,
      rgba(255, 192, 72, .04) 82%,
      rgba(255, 192, 72, 0) 100%
    );
  }

  .buy-button {
    left: 50%;
    right: auto;
    top: 90.625%;
    width: 22.9167%;
    min-width: 0;
    padding: .86% 0 .82%;
    transform: translateX(-50%);
    border: 0;
    border-radius: 999px;
    background: rgba(255,255,255,.98);
    color: #6a3c28;
    font-size: clamp(9px, 2.08vw, 30px);
    font-weight: 400;
    line-height: 1;
    letter-spacing: .01em;
  }

  .buy-button::before {
    content: "";
    position: absolute;
    inset: -10px;
  }

  .buy-button:hover,
  .buy-button:focus-visible {
    background: #fff;
    color: #5b2f20;
    transform: translateX(-50%) translateY(-2px);
  }

  .credit {
    left: 50%;
    bottom: 2.42%;
    width: 68%;
    transform: translateX(-50%);
    font-size: clamp(6px, 1.45vw, 21px);
    letter-spacing: .26em;
    line-height: 1;
  }

  body.lights-on .book-item.is-touched {
    transform: translateY(-5px) scale(1.02) rotate(var(--rot));
  }

  @media (hover: hover) and (pointer: fine) {
    body.lights-on .book-item:hover {
      transform: translateY(-7px) scale(1.022) rotate(var(--rot));
    }
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  body { overflow: hidden; }

  .artboard {
    width: min(100vw, calc(100vh * 16 / 9));
  }

  .mistika-logo {
    top: 3.2%;
    width: 10.6%;
  }

  .buy-button {
    top: 7.6%;
    right: 5.4%;
    font-size: clamp(8px, 1.15vw, 13px);
  }

  .credit {
    bottom: 2.4%;
    font-size: clamp(6px, .78vw, 10px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
