@font-face {
  font-family: PixelText;
  src: url(https://assets.codepen.io/36869/Grand9KPixel.ttf);
}

/* Partículas de corazones y murciélagos 🖤🦇 */
.particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
}

.particle {
  position: absolute;
  top: -30px;
  animation: fall linear forwards;
  z-index: 1000;
}

@keyframes fall {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  100% {
    transform: translateY(110vh) rotate(360deg);
  }
}

/* Botones de navegación personalizados (estilo pixel art) */
.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  background: linear-gradient(180deg, rgba(25, 16, 38, 0.92), rgba(10, 7, 16, 0.92));
  color: #ffe6f6;
  border: 2px solid rgba(248, 64, 168, 0.7);
  width: 50px;
  height: 50px;
  font-size: 2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  text-shadow: 
    2px 2px 0 #000,
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000,
    0 3px 0 #000;
  filter: drop-shadow(0 0 10px rgba(248, 64, 168, 0.65));
  box-shadow: inset 0 0 0 2px rgba(255, 209, 102, 0.25), 0 5px 0 rgba(0, 0, 0, 0.45);
  opacity: 0.9;
}

.nav-btn:hover {
  transform: translateY(-50%) scale(1.2);
  filter: drop-shadow(0 0 15px rgba(248, 64, 168, 1));
  opacity: 1;
}

.nav-btn:active {
  transform: translateY(-50%) scale(0.95);
  box-shadow: inset 0 0 0 2px rgba(255, 209, 102, 0.2), 0 2px 0 rgba(0, 0, 0, 0.45);
}

.nav-btn-left {
  left: -60px;
}

.nav-btn-right {
  right: -60px;
}

@media (width < 748px) {
  .nav-btn {
    width: 45px;
    height: 45px;
    font-size: 1.8rem;
  }
  
  .nav-btn-left {
    left: -50px;
  }
  
  .nav-btn-right {
    right: -50px;
  }
}

:root {
  --bg-deep: #0d101a;
  --bg-mid: #171d2b;
  --bg-glow: #2b1235;
  --ui-paper: #f1e2b2;
  --ui-ink: #28241b;
  --ui-primary: #f840a8;
  --ui-primary-soft: #ff78c3;
  --ui-accent: #ffd166;
  --ui-border: #2a1b2e;
  --pixel-shadow: 0 0 0 2px #000, 4px 4px 0 rgba(0, 0, 0, 0.55);

  font-family: 'PixelText', serif;
  font-optical-sizing: auto;
  line-height: 1.5;
  font-weight: 400;

  color-scheme: dark;
  color: rgba(255, 255, 255, 0.87);
  background-color: var(--bg-deep);

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;

  /* sprite image */
  --sprite-image: url(https://assets.codepen.io/36869/book.webp);

  /* sprite animation settings */
  /* animation duration */
  --sprite-as: .8s;
  /* animation direction */
  --sprite-ad: normal;
  /* animation fill mode */
  --sprite-af: none;
  /* animation play state */
  --sprite-ap: running;
  /* animation iteration count */
  --sprite-ai: infinite;
  /* animation timing function */
  --sprite-at: linear;
  /* animation frame rate */
  --sprite-fr: 12;
}

@layer base {
  *{
    box-sizing: border-box;
  }
  body {
    position: relative;
    margin: 0;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 1rem;
    background:
      radial-gradient(circle at 20% 20%, rgba(248, 64, 168, 0.12) 0%, rgba(248, 64, 168, 0) 35%),
      radial-gradient(circle at 78% 76%, rgba(255, 209, 102, 0.12) 0%, rgba(255, 209, 102, 0) 40%),
      linear-gradient(180deg, var(--bg-mid) 0%, var(--bg-deep) 60%, #090b12 100%);
  }

  body::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.2;
    background-image:
      linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
    background-size: 8px 8px;
    z-index: 0;
  }

  body::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at center, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.5) 100%);
    z-index: 0;
  }

  .sprite-wrapper {
    position: relative;
    width: 100%;
    margin: 0 auto;
    z-index: 2;
  }

  .container {
    position: relative;
    z-index: 2;
  }
}

@layer main {
  /* Frame start position */
  @property --sprite-fs {
    syntax: "<integer>";
    initial-value: 0;
    inherits: true
  }
  @property --_progress {
    syntax: "<percentage>";
    inherits: false;
    initial-value: 0%;
  }

  .container {
    display: flex;
    flex-direction: column;
    gap: 3rem;

    /* sprite columns */
    --sprite-c: 5;
    /* sprite image height */
    --sprite-h: 3000;
    /* sprite image width */
    --sprite-w: 9600;
    /* sprite frames */
    --sprite-f: 7;
    /* animation duration based on frame rate */
    --sprite-as: calc(var(--sprite-f) / var(--sprite-fr) * 1s);

    /* frame rows */
    --sprite-r: round(up, calc(var(--sprite-f) / var(--sprite-c)), 1);
    /* frame height */
    --sprite-sh: calc(var(--sprite-h) / var(--sprite-r));
    /* frame target height, width */
    --sprite-th: calc(var(--sprite-sh) / 2);

    /* aspect ratio */
    --sprite-ar: calc(var(--sprite-th) / var(--sprite-sh));
    --sprite-uh: calc(var(--sprite-h) * var(--sprite-ar));
    --sprite-uw: calc(var(--sprite-w) * var(--sprite-ar));

    /* frame width */
    --sprite-tw: calc(var(--sprite-uw) / var(--sprite-c));

    > h1 {
      color: #f6edf7;
      margin: 0;
      width: fit-content;
      font-weight: 500;
      font-size: 1.75rem;
      text-align: center;
      letter-spacing: 0.03em;
      text-shadow: 2px 2px 0 #1b1020, 4px 4px 0 #09070c;
    }

    .book {
      position: relative;
      display: grid;
      grid-template-areas:
            "left scroll right"
            "left markers right";
      grid-template-columns: auto 1fr auto;
      gap: 0.5rem;
      align-items: center;
      filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.6));

      .sprite {
        position: absolute;
        display: flex;
        align-items: center;
        justify-content: center;
        height: calc(1px * var(--sprite-th));
        width: calc(1px * var(--sprite-tw));
        margin: calc(-1px * calc((var(--sprite-th) - (var(--sprite-th) * 0.6107)) / 2)) calc(-1px * calc((var(--sprite-tw) - (var(--sprite-tw) * 0.7042)) / 2));
        background-image: var(--sprite-image);
        transform-origin: center center;
        background-repeat: no-repeat;
        background-size: calc(1px * var(--sprite-uw)) calc(1px * var(--sprite-uh));
        z-index: -1;

        /* Frame end position */
        --sprite-fe: calc(var(--sprite-f) * (var(--slides) - 1));
        --sprite-fs-n: mod(var(--sprite-fs), var(--sprite-f));
        /* calculate the row and column position */
        --row: calc(round(down, calc(calc(var(--sprite-tw) * var(--sprite-fs-n)) / var(--sprite-uw)), 1) * var(--sprite-th));
        --col: mod(calc(var(--sprite-tw) * var(--sprite-fs-n)), var(--sprite-uw));

        background-position: calc(-1px * var(--col)) calc(-1px * var(--row));
        animation: frame var(--sprite-as) var(--sprite-at) 0s var(--sprite-ad) var(--sprite-af) var(--sprite-ap);
        animation-timeline: --carousel-timeline;
      }

      .carousel {
        counter-increment: curpage;
        grid-area: scroll;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        overscroll-behavior-x: contain;

        display: grid;
        margin: 0 auto;
        width: calc(1px * (var(--sprite-tw) * 0.7042));
        height: calc(1px * (var(--sprite-th) * 0.6107));
        grid: 1fr / auto-flow 100%;
        scroll-timeline: --carousel-timeline x;
        scroll-behavior: smooth;
        scrollbar-width: none;
        scroll-marker-group: after;

        /* Ocultar botones CSS nativos (usamos botones JS personalizados) */
        &::scroll-button(*) {
          display: none;
        }

        &::scroll-marker-group {
          content: "";
          width: 100%;
          height: 8px;
          padding: 2px 0;
          display: grid;
          position: relative;
          grid-area: markers;
          margin-top: 0.5rem;

          grid-auto-flow: column;
          place-self: center;
          overflow: hidden;
          border: 1px solid #000;

          background: linear-gradient(90deg, var(--ui-paper) 0%) no-repeat left center;
          --_progress: calc(calc(100 / var(--slides)) * 1%);
          background-size: var(--_progress, 20%) 100%;

          animation: progress linear both;
          animation-timeline: --carousel-timeline;
        }

        & > .carousel-item {
          scroll-snap-stop: always;
          scroll-snap-align: start;
          animation: count-before linear forwards;
          animation-range: exit;
          counter-increment: page;
          animation-timeline: view(x);

          position: relative;
          box-sizing: border-box;
          color: var(--ui-ink);

          &::scroll-marker {
            content: '';
            position: relative;
            left: -1px;
            width: 100%;
            height: 100%;
            display: block;
            box-sizing: border-box;
            box-shadow: 2px 0 0 #000;
          }

          &:last-of-type{
            &::scroll-marker {
              box-shadow: none;
            }
          }

          .page-container {
            display: flex;
            gap: 3rem;
            height: 100%;

            animation: stay-centered linear both;
            animation-timeline: view(x);
            timeline-scope: --parallax-item;
          }

          .left-page, .right-page {
            flex: 1;
            font-size: small;
            overflow: hidden;
            display: grid;
            grid-template-rows: 1fr auto;

            &:after {
              bottom: 15px;
              color: hsl(45.71deg 69.23% 30%);
            }

            > div {
              text-align: justify;
              hyphens: auto;
              line-height: normal;
              display: block;
              word-wrap: break-word;
              text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
            }
          }

          .left-page {
            padding: 20px 0 20px 20px;
            &:after {
              content: counter(curpage);
            }
          }

          .right-page {
            padding: 20px 20px 20px 0;
            counter-increment: curpage;
            &:after {
              content: counter(curpage);
              place-self: self-end;
            }
          }
        }
      }
    }
  }
}

.book-title {
  margin-inline: auto;
  padding: 0.45rem 0.85rem;
  border: 2px solid rgba(248, 64, 168, 0.55);
  background: linear-gradient(180deg, rgba(37, 17, 42, 0.72), rgba(15, 10, 24, 0.72));
  box-shadow: var(--pixel-shadow);
}

.title-accent {
  color: var(--ui-primary-soft);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.running-cats {
  text-align: center;
  margin-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.running-cat {
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.65));
}

.running-cat-main {
  width: 80px;
  animation: cat-bob 1.8s steps(2, end) infinite;
}

.running-cat-side {
  width: 60px;
  animation: cat-bob 1.8s steps(2, end) infinite reverse;
}

@keyframes cat-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@media (width < 748px) {
  .container {
    --sprite-th: calc(var(--sprite-sh) / 1.5);
    gap: 1rem;

    > h1 {
      font-size: 1rem;
      padding: 0 0.5rem;
    }

    .page {
      > div {
        font-size: .65rem;
      }
    }

    .book {
      .carousel {
        &::scroll-button(*) {
          inline-size: 50px;
        }
      }
    }
  }
}

@media (width < 560px) {
  body {
    padding: 0.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
    min-height: 100vh;
  }

  .container {
    --sprite-th: calc(var(--sprite-sh) / 0.9);
    gap: 0.8rem;
    padding: 0;
    width: 100%;
    max-width: 100vw;

    > h1 {
      font-size: 0.75rem;
      line-height: 1.3;
      padding: 0 2.5rem;
    }

    .book {
      gap: 0.3rem;
      width: 100%;
      
      .carousel {
        width: calc(1px * (var(--sprite-tw) * 0.7042));
        height: calc(1px * (var(--sprite-th) * 0.6107));
        
        &::scroll-button(*) {
          display: none;
        }
      }
    }

    .page-container {
      gap: 1.5rem !important;
    }

    .page {
      > div {
        font-size: .55rem;
        line-height: 1.5;
      }

      &:after {
        font-size: .4rem;
      }
    }

    .left-page {
      padding: 15px 8px 15px 15px !important;
    }

    .right-page {
      padding: 15px 15px 15px 8px !important;
    }
  }
  
  .sprite-wrapper {
    width: auto;
    max-width: 90vw;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  
  .nav-btn {
    width: 35px;
    height: 35px;
    font-size: 1.2rem;
  }
  
  .nav-btn-left {
    left: -40px;
  }
  
  .nav-btn-right {
    right: -40px;
  }

  .book-title {
    padding: 0.35rem 0.6rem;
  }

  .running-cat-main {
    width: 64px;
  }

  .running-cat-side {
    width: 50px;
  }
}

@media (width < 400px) {
  body {
    padding: 0.3rem;
  }

  .container {
    --sprite-th: calc(var(--sprite-sh) / 0.75);
    gap: 0.5rem;

    > h1 {
      font-size: 0.65rem;
      padding: 0 2rem;
    }

    .book {
      .carousel {
        &::scroll-button(*) {
          display: none;
        }
      }
    }

    .page-container {
      gap: 1rem !important;
    }

    .page {
      > div {
        font-size: .5rem;
        line-height: 1.4;
      }
      
      &:after {
        font-size: .35rem;
      }
    }

    .left-page {
      padding: 12px 5px 12px 12px !important;
    }

    .right-page {
      padding: 12px 12px 12px 5px !important;
    }
  }
  
  .nav-btn {
    width: 30px;
    height: 30px;
    font-size: 1rem;
  }
  
  .nav-btn-left {
    left: -35px;
  }
  
  .nav-btn-right {
    right: -35px;
  }

  .running-cat-main {
    width: 54px;
  }

  .running-cat-side {
    width: 42px;
  }
}

/* Para pantallas muy pequeñas (iPhone SE, etc) */
@media (width < 350px) {
  .container {
    --sprite-th: calc(var(--sprite-sh) / 0.65);
    
    > h1 {
      font-size: 0.55rem;
      padding: 0 1.5rem;
    }

    .page {
      > div {
        font-size: .45rem;
      }
    }
  }
  
  .nav-btn {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }
  
  .nav-btn-left {
    left: -32px;
  }
  
  .nav-btn-right {
    right: -32px;
  }
}

/* Orientación landscape en móviles - libro más grande */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 0.3rem 0.5rem;
    overflow: hidden;
    height: 100vh;
    align-items: center;
  }

  .container {
    --sprite-th: calc(var(--sprite-sh) / 2.6);
    gap: 0.3rem;
    justify-content: center;

    > h1 {
      font-size: 0.7rem;
      padding: 0 1rem;
      line-height: 1.2;
    }

    .page {
      > div {
        font-size: .55rem;
        line-height: 1.4;
      }

      &:after {
        font-size: .35rem;
      }
    }

    .left-page {
      padding: 12px 6px 12px 12px !important;
    }

    .right-page {
      padding: 12px 12px 12px 6px !important;
    }

    .page-container {
      gap: 1.5rem !important;
    }
  }

  .nav-btn {
    width: 38px;
    height: 38px;
    font-size: 1.3rem;
  }

  .nav-btn-left {
    left: -45px;
  }

  .nav-btn-right {
    right: -45px;
  }
  
  /* Ocultar gatos corriendo en landscape para ganar espacio */
  .running-cats {
    display: none;
  }
}

/* Landscape en pantallas más pequeñas */
@media (max-height: 400px) and (orientation: landscape) {
  .container {
    --sprite-th: calc(var(--sprite-sh) / 3.2);
    
    > h1 {
      font-size: 0.6rem;
    }

    .page {
      > div {
        font-size: .5rem;
      }
    }

    .left-page {
      padding: 10px 5px 10px 10px !important;
    }

    .right-page {
      padding: 10px 10px 10px 5px !important;
    }
  }

  .nav-btn {
    width: 32px;
    height: 32px;
    font-size: 1.1rem;
  }

  .nav-btn-left {
    left: -38px;
  }

  .nav-btn-right {
    right: -38px;
  }
}

@keyframes stay-centered {
  entry 0% {
    opacity: 0;
    translate: -100%;
  }
  entry 75%  {
    opacity: 0;
    translate: -25%;
  }
  entry 100% {
    opacity: 1;
    translate: 0%;
  }
  exit 0% {
    opacity: 1;
    translate: 0%;
  }
  exit 50% {
    opacity: 0;
    translate: 50%;
  }
  exit 100% {
    opacity: 0;
    translate: 100%;
  }
}

@keyframes count-before {
  1%,
  100% {
    counter-increment: page curpage;
  }
}

@keyframes progress {
  100% {
    --_progress: 100%;
  }
}

@keyframes frame {
  to {
    --sprite-fs: var(--sprite-fe);
  }
}

@media (prefers-reduced-motion) {
  * {
    animation: none;
  }

  .running-cat,
  .magic-btn,
  .rotate-hint span {
    animation: none !important;
  }
}

/* Hint de rotación para móviles */
.rotate-hint {
  display: none;
  text-align: center;
  color: #f840a8;
  font-size: 0.7rem;
  margin-top: 1rem;
  padding: 0.5rem;
  opacity: 0.8;
  animation: pulse-hint 2s ease-in-out infinite;
}

.rotate-hint span {
  display: inline-block;
  animation: rotate-phone 1.5s ease-in-out infinite;
}

@keyframes pulse-hint {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes rotate-phone {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(90deg); }
  50% { transform: rotate(90deg); }
  75% { transform: rotate(0deg); }
}

/* Mostrar hint solo en móviles portrait */
@media (max-width: 560px) and (orientation: portrait) {
  .rotate-hint {
    display: block;
  }
}

/* Ocultar en landscape */
@media (orientation: landscape) {
  .rotate-hint {
    display: none;
  }
}

/* Diálogo modal */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: 1rem;
}

.dialog-overlay.active {
  display: flex;
}

.dialog-box {
  background: linear-gradient(135deg, #1a1a2e 0%, #0f0f23 100%);
  border: 3px solid #f840a8;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  text-align: center;
  animation: dialogAppear 0.3s ease;
  box-shadow: 0 0 30px rgba(248, 64, 168, 0.3);
}

@keyframes dialogAppear {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.dialog-box h2 {
  color: #f840a8;
  margin: 0 0 1rem 0;
  font-size: 1.2rem;
}

.dialog-box p {
  color: #e0e0e0;
  line-height: 1.6;
  margin: 0 0 1.5rem 0;
  font-size: 0.85rem;
  text-align: justify;
}

.dialog-close {
  font-family: 'PixelText', serif;
  background: #f840a8;
  color: #1a1a2e;
  border: none;
  padding: 0.6rem 1.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.dialog-close:hover {
  background: #ff69b4;
  transform: scale(1.05);
}

@media (width < 560px) {
  .dialog-box {
    padding: 1.5rem;
  }
  
  .dialog-box h2 {
    font-size: 1rem;
  }
  
  .dialog-box p {
    font-size: 0.7rem;
  }
}

.magic-btn {
  font-family: 'PixelText', serif;
  background: linear-gradient(180deg, #3f1c4a, #291231);
  color: #ffd6ef;
  border: 2px solid #f840a8;
  padding: 0.55rem 1.1rem;
  font-size: 0.68rem;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 0.5), 0 3px 0 rgba(0, 0, 0, 0.45), 0 0 12px rgba(248, 64, 168, 0.5);
  animation: magic-pulse 2s ease-in-out infinite;
}

.magic-btn:hover {
  background: linear-gradient(180deg, #f840a8, #bd1f75);
  color: #1a1a2e;
  box-shadow: 0 0 25px #f840a8;
  transform: scale(1.03);
}

@keyframes magic-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(248, 64, 168, 0.4); }
  50% { box-shadow: 0 0 25px rgba(248, 64, 168, 0.9); }
}

/* Modal Te amo */
.teamo-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 3000;
  padding: 1rem;
}

.teamo-overlay.active {
  display: flex;
}

.teamo-box {
  background: linear-gradient(135deg, #1a1a2e 0%, #0f0f23 100%);
  border: 3px solid #f840a8;
  padding: 2rem;
  max-width: 480px;
  width: 100%;
  text-align: center;
  animation: dialogAppear 0.3s ease;
  box-shadow: 0 0 40px rgba(248, 64, 168, 0.5);
}

.teamo-msg {
  color: #f840a8;
  font-size: 1.4rem;
  margin: 0 0 1.2rem 0;
  text-shadow: 0 0 10px rgba(248, 64, 168, 0.7);
}

.teamo-img {
  width: 100%;
  max-width: 360px;
  height: auto;
  display: block;
  margin: 0 auto 1.5rem auto;
  border: 2px solid #f840a8;
  box-shadow: 0 0 20px rgba(248, 64, 168, 0.4);
}

@media (width < 560px) {
  .magic-btn {
    font-size: 0.8rem;
    padding: 0.6rem 1.2rem;
  }

  .teamo-msg {
    font-size: 1rem;
  }

  .teamo-box {
    padding: 1.5rem;
  }
}