@import url("https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&family=Nunito:wght@400;700&display=swap");

@layer reset, tokens, base, layout, cube, ui, cards, reveal, theme, responsive;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
}

@layer tokens {
  :root {
    color-scheme: light;

    /* Zuki Theme Colors (Vibrant, kid-friendly) */
    --light-bg: #fff0f5; /* Soft pinkish background */
    --light-fg: #4a2b6b; /* Deep purple text */
    --light-muted: #8b6b9e;
    --accent-light: #ff6b6b; /* Vibrant coral red */
    --card-bg-light: rgba(255, 255, 255, 0.85);
    --card-border-light: rgba(255, 107, 107, 0.4);

    --dark-bg: #2a1542; /* Deep purple background */
    --dark-fg: #fff0f5; 
    --dark-muted: #bda3d1;
    --accent-dark: #ffcf54; /* Sunny yellow */
    --card-bg-dark: rgba(28, 14, 46, 0.85);
    --card-border-dark: rgba(255, 207, 84, 0.4);

    --bg: var(--light-bg);
    --fg: var(--light-fg);
    --muted: var(--light-muted);
    --accent: var(--accent-light);
    --card-bg: var(--card-bg-light);
    --card-border: var(--card-border-light);

    /* Rounded, playful fonts */
    --font-display: "Fredoka", sans-serif;
    --font-mono: "Nunito", sans-serif;
    
    --hairline: 0.15rem; /* Thicker borders for playful look */
    --ui-inset: 2rem;
    --nav-x: calc(var(--ui-inset) + 0.125rem);
    --reveal-offset: 0.8rem;
    --reveal-duration: 0.5s;
    --z-ui: 10;
  }
}

@layer base {
  html {
    color-scheme: light;
  }

  body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-mono);
    overflow-x: hidden;
    transition: background 0.4s ease, color 0.4s ease;
  }
}

@layer layout {
  #bg_layer {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--bg);
  }

  .bg-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    opacity: 0;
    transition: opacity 0.8s ease-in-out;
    /* Un ligero desenfoque para que el fondo no compita con el cubo */
    filter: blur(4px); 
    transform: scale(1.05); /* Evita bordes blancos por el blur */
  }

  .bg-image.active {
    opacity: 1;
  }

  .bg-overlay {
    position: absolute;
    inset: 0;
    /* Capa semitransparente que se adapta al modo claro/oscuro */
    background: color-mix(in srgb, var(--bg) 75%, transparent);
    transition: background 0.4s ease;
  }

  #scene {
    position: fixed;
    inset: 0;
    z-index: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1100px;
    pointer-events: none;
  }

  #scroll_container {
    position: relative;
    z-index: 1;
  }

  section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: 6rem calc(5rem + var(--ui-inset)) 6rem 5rem;
  }
}

@layer cube {
  #cube {
    --s: min(70vw, 70vh, 480px);
    width: var(--s);
    height: var(--s);
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(90deg) rotateY(0deg);
    will-change: transform;
  }

  .face {
    position: absolute;
    inset: 0;
    overflow: hidden;
    backface-visibility: hidden;
    background: linear-gradient(135deg, var(--accent) 0%, transparent 100%), var(--bg);
    border: 4px solid var(--card-border);
    border-radius: 24px; /* Rounded corners for the cube faces! */

    img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
      border-radius: 20px;
    }

    &:has(img) .face-ph {
      display: none;
    }
  }

  .face-ph {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 700;
    color: var(--fg);
    opacity: 0.8;
    pointer-events: none;
    user-select: none;
    text-shadow: 2px 2px 0px var(--card-border);
  }

  /* Translate Z with a slight adjustment since faces are rounded */
  .face[data-face="front"] { transform: translateZ(calc(var(--s) / 2)); }
  .face[data-face="back"] { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
  .face[data-face="right"] { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
  .face[data-face="left"] { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
  .face[data-face="top"] { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
  .face[data-face="bottom"] { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
}

@layer ui {
  #hud {
    position: fixed;
    top: var(--ui-inset);
    right: var(--ui-inset);
    z-index: var(--z-ui);
    text-align: right;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--muted);
    text-transform: uppercase;

    .progress-bar {
      width: 8rem;
      height: 6px;
      border-radius: 6px;
      background: var(--card-border);
      margin-block-start: 0.5rem;
      margin-inline-start: auto;
      position: relative;
      overflow: hidden;
    }

    .progress-fill {
      position: absolute;
      inset-block: 0;
      inset-inline-start: 0;
      width: 0%;
      background: var(--accent);
      transition: width 0.1s linear;
      border-radius: 6px;
    }

    .scene-label {
      font-size: 0.75rem;
      color: var(--accent);
      margin-block-start: 0.5rem;
      font-family: var(--font-display);
      letter-spacing: 1px;
    }
  }

  #scene_strip {
    position: fixed;
    left: var(--nav-x);
    top: 50%;
    translate: -50% -50%;
    z-index: var(--z-ui);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
  }

  .scene-dot {
    position: relative;
    display: block;
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: var(--muted);
    transition: background 0.3s, scale 0.3s;
    cursor: pointer;

    &::before {
      content: "";
      position: absolute;
      inset: -0.3rem;
    }

    &.active {
      background: var(--accent);
      scale: 1.8;
    }
  }

  #theme_toggle {
    position: fixed;
    bottom: var(--ui-inset);
    left: var(--nav-x);
    translate: -50% 0;
    z-index: var(--z-ui);
    width: 3rem;
    height: 3rem;
    border: none;
    background: var(--card-border);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, transform 0.2s;

    &:hover {
      background: var(--accent);
      transform: scale(1.1);
    }
    &:hover svg {
      color: var(--bg);
    }

    svg {
      width: 1.2rem;
      height: 1.2rem;
      position: absolute;
      transition: opacity 0.3s ease, rotate 0.3s ease, color 0.3s ease;
      color: var(--fg);
    }

    .icon-sun { opacity: 1; rotate: 0deg; }
    .icon-moon { opacity: 0; rotate: 90deg; }
  }

  .btn-support-global {
    position: fixed;
    top: var(--ui-inset);
    left: var(--ui-inset);
    z-index: var(--z-ui);
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1.8rem;
    background: linear-gradient(135deg, #ff6b6b 0%, #ff4757 100%);
    color: white;
    text-decoration: none;
    border-radius: 50px;
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 800;
    box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7);
    animation: support-pulse 2s infinite cubic-bezier(0.66, 0, 0, 1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), filter 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 2px solid rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(5px);
  }

  .btn-support-global:hover {
    transform: translateY(-5px) scale(1.05);
    animation: none;
    box-shadow: 0 15px 30px rgba(255, 71, 87, 0.6);
    filter: brightness(1.1);
  }

  @keyframes support-pulse {
    0% {
      transform: scale(0.98);
      box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7);
    }
    70% {
      transform: scale(1.02);
      box-shadow: 0 0 0 20px rgba(255, 107, 107, 0);
    }
    100% {
      transform: scale(0.98);
      box-shadow: 0 0 0 0 rgba(255, 107, 107, 0);
    }
  }

  .btn-support-global i {
    font-size: 1.3rem;
    animation: heart-beat 1s infinite alternate;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
  }

  @keyframes heart-beat {
    0% { transform: scale(1); }
    100% { transform: scale(1.25); }
  }

  #face_caption {
    position: fixed;
    bottom: var(--ui-inset);
    left: 50%;
    translate: -50% 0;
    z-index: var(--z-ui);
    text-align: center;
    pointer-events: none;
    user-select: none;
  }

  #face_caption_num {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--accent);
    text-transform: uppercase;
    margin-block-end: 0.2rem;
    font-family: var(--font-display);
  }

  #face_caption_name {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 3.8rem);
    font-weight: 700;
    color: var(--muted);
    opacity: 0.4;
    line-height: 1;
  }

  #credit {
    position: fixed;
    right: var(--ui-inset);
    top: 50%;
    transform: translateY(-50%) rotate(-90deg);
    transform-origin: right center;
    z-index: var(--z-ui);
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;

    a {
      color: var(--accent);
      text-decoration: none;
      font-weight: 700;
    }
  }
}

@layer cards {
  .text-card {
    max-width: 28rem;
    padding: 3rem 2.5rem;
    background: var(--card-bg);
    border-radius: 24px;
    border: 3px solid var(--card-border);
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    backdrop-filter: blur(8px) saturate(120%);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    overflow: hidden;
    transition: background 0.3s ease, border-color 0.3s ease;

    &.center {
      text-align: center;
      .h-line {
        margin-inline: auto;
      }
      .cta-row {
        justify-content: center;
      }
      .stat-row {
        justify-content: center;
      }
    }

    &.shape-0 { border-radius: 40px 100px 40px 100px; }
    &.shape-1 { border-radius: 100px 40px 100px 40px; }
    &.shape-2 { border-radius: 60px 120px 50px 100px; }
    &.shape-3 { border-radius: 120px 60px 100px 50px; }
    &.shape-4 { border-radius: 80px 100px 60px 120px; }
    &.shape-5 { border-radius: 100px 80px 120px 60px; }

    &.right {
      margin-inline-start: auto;

      .h-line {
        transform-origin: right;
      }
    }
  }

  .tag {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
    margin-block-end: 1rem;
    background: var(--card-border);
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
  }

  :where(h1, h2) {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    color: var(--fg);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.03);
  }

  h1 { font-size: clamp(2.5rem, 6vw, 4.5rem); }
  h2 { font-size: clamp(2rem, 5vw, 3.5rem); }

  .body-text {
    font-size: 1.05rem;
    line-height: 1.6;
    color: var(--muted);
    font-weight: 600;
    margin-block-start: 1rem;
  }

  .stat-row {
    display: flex;
    gap: 2rem;
    margin-block-start: 1.5rem;
    flex-wrap: wrap;
  }

  .stat {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
  }

  .stat-num {
    font-family: var(--font-display);
    font-size: 2.5rem;
    color: var(--accent);
    line-height: 1;
  }

  .stat-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
  }

  .h-line {
    width: 4rem;
    height: 4px;
    border-radius: 4px;
    background: var(--accent);
    margin-block-end: 1.5rem;
    transform-origin: left;
  }

  .cta-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
    margin-block-start: 1.75rem;
  }

  .text-card.right .cta-row {
    justify-content: flex-end;
  }

  .cta {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1.5rem;
    background: var(--accent);
    color: var(--bg);
    border-radius: 30px;
    font-family: var(--font-display);
    font-size: 1.1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;

    &:hover {
      transform: translateY(-3px);
      box-shadow: 0 8px 20px var(--card-border);
    }

    svg {
      width: 1rem;
      height: 1rem;
    }
  }

  .cta-back {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1.5rem;
    border: 2px solid var(--muted);
    border-radius: 30px;
    color: var(--muted);
    font-family: var(--font-display);
    font-size: 1.1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-decoration: none;
    transition: background 0.2s, color 0.2s, border-color 0.2s;

    &:hover {
      background: var(--muted);
      color: var(--bg);
    }

    svg {
      width: 1rem;
      height: 1rem;
    }
  }
}

@layer reveal {
  :is(.tag, h1, h2, .body-text, .stat-row, .cta, .cta-back) {
    opacity: 0;
    translate: 0 var(--reveal-offset);
  }

  :is(h1, h2) {
    translate: 0 1.125rem;
    transition: opacity var(--reveal-duration) ease 0.08s,
      translate var(--reveal-duration) ease 0.08s;
  }

  .tag {
    transition: opacity var(--reveal-duration) ease,
      translate var(--reveal-duration) ease;
  }

  .body-text {
    transition: opacity var(--reveal-duration) ease 0.2s,
      translate var(--reveal-duration) ease 0.2s;
  }

  .stat-row {
    transition: opacity var(--reveal-duration) ease 0.3s,
      translate var(--reveal-duration) ease 0.3s;
  }

  :is(.cta, .cta-back) {
    transition: opacity var(--reveal-duration) ease 0.35s,
      translate var(--reveal-duration) ease 0.35s, transform 0.2s, box-shadow 0.2s, background 0.2s, color 0.2s;
  }

  .h-line {
    opacity: 0;
    scale: 0 1;
    transition: opacity 0.4s ease, scale 0.4s ease;
  }

  :is(.tag, h1, h2, .body-text, .stat-row, .cta, .cta-back).visible {
    opacity: 1;
    translate: 0 0;
  }

  .h-line.visible {
    opacity: 1;
    scale: 1 1;
  }
}

@layer theme {
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: var(--dark-bg);
    --fg: var(--dark-fg);
    --muted: var(--dark-muted);
    --accent: var(--accent-dark);
    --card-bg: var(--card-bg-dark);
    --card-border: var(--card-border-dark);

    #theme_toggle {
      .icon-sun { opacity: 0; rotate: -90deg; }
      .icon-moon { opacity: 1; rotate: 0deg; }
    }
  }
}

@layer responsive {
  @media (max-width: 768px) {
    #hud {
      top: 1rem;
      right: 1.5rem;
      font-size: 0.7rem;
    }
    
    .progress-bar {
      width: 5rem;
    }

    #scene_strip { display: none; }

    #theme_toggle {
      bottom: 1rem;
      left: 1.5rem;
      width: 2.5rem;
      height: 2.5rem;
    }

    #face_caption { 
      bottom: 1rem; 
      width: 100%;
    }

    .btn-support-global {
      top: 1rem;
      left: 1rem;
      padding: 0.5rem 0.8rem;
      font-size: 0.8rem;
      gap: 0.4rem;
    }
    
    .btn-support-global i {
      font-size: 1rem;
    }
    
    #face_caption_name {
      font-size: 2.5rem;
    }

    #cube {
      --s: min(70vw, 35vh, 280px) !important;
      top: 20vh; /* Positioned in the upper half */
      margin: 0 auto;
    }

    #scene {
      align-items: flex-start; /* Align scene content to top on mobile */
    }

    section {
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      padding: 0 1rem 8vh; /* Space from bottom */
    }

    #s0 {
      justify-content: flex-end;
      padding: 0 1rem 8vh;
    }

    :is(.text-card, .text-card.right, .text-card.center) {
      max-width: 90%;
      margin-inline: auto;
      padding: 1rem 0.8rem;
      border-radius: 20px;
      text-align: center;
      border: 2px solid var(--card-border);
      max-height: none; /* Removed to avoid internal scroll */
      overflow-y: visible;
    }

    #s5 {
      min-height: 160vh; /* Extra space to scroll and see the video */
      padding-bottom: 5vh;
    }

    #s5 .text-card {
      max-height: none; /* Allow card to grow to fit video */
      overflow-y: visible;
    }
    
    .text-card.right .h-line, .text-card.center .h-line {
      margin-inline: auto;
    }

    .text-card .cta-row {
      justify-content: center;
    }

    h1 { font-size: clamp(1.8rem, 8vw, 2.4rem); }
    h2 { font-size: clamp(1.5rem, 6vw, 1.8rem); }

    .body-text { 
      font-size: 0.8rem;
      line-height: 1.3; 
    }
    
    .stat-row { 
      gap: 1rem; 
      justify-content: center !important;
      margin-block-start: 1rem; 
    }
    
    .stat-num { font-size: 1.5rem; }

    .tag {
      display: none; /* Hidden to save space on mobile */
    }

    .cta-back {
      display: none; /* Hidden to save space and simplify navigation */
    }

    .h-line {
      width: 2.5rem;
      height: 3px;
      margin-block-end: 1rem;
    }

    .video-wrapper {
      max-width: 220px !important;
      margin-top: 1rem !important;
    }
    
    #credit {
      display: none; /* Hide rotated credit on mobile to save space */
    }
  }

  /* Extra small devices */
  @media (max-width: 480px) {
    #hud {
      top: 3.5rem; /* Move HUD down if support button is present */
      right: 1rem;
    }
    
    .btn-support-global {
      width: auto;
      left: 10px;
      top: 10px;
      translate: 0 0;
      padding: 0.4rem 0.6rem;
      font-size: 0.7rem;
    }
    
    #hud {
        top: 10px;
        right: 10px;
        font-size: 0.6rem;
    }

    #theme_toggle {
        bottom: 10px;
        left: 10px;
        width: 2.2rem;
        height: 2.2rem;
    }
    
    #face_caption {
        bottom: 10px;
    }

    h1 { font-size: 1.4rem; }
    h2 { font-size: 1.2rem; }
    
    .text-card {
      padding: 0.8rem;
    }
    
    .cta, .cta-back {
      padding: 0.5rem 0.8rem;
      font-size: 0.85rem;
    }

    .cta-row {
      flex-direction: column;
      gap: 0.75rem;
      width: 100%;
    }

    .cta, .cta-back {
      width: 100%;
      justify-content: center;
      padding: 0.7rem 1rem;
      font-size: 0.95rem;
    }
  }

  @media (max-width: 380px) {
    #cube { 
      --s: 220px !important; 
      top: -10vh;
    }
    #face_caption_name {
      font-size: 1.8rem;
    }
  }
}
