@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
  .background-animate {
    background-size: 400%;

    -webkit-animation: AnimationName 3s ease infinite;
    -moz-animation: AnimationName 3s ease infinite;
    animation: AnimationName 3s ease infinite;
  }

  @keyframes AnimationName {
    0%,
    100% {
      background-position: 0% 50%;
    }
    50% {
      background-position: 100% 50%;
    }
  }

  .btn {
    @apply px-4 py-2 rounded shadow transition duration-150 ease-in-out;
  }

  .btn-sm {
    @apply px-3 py-1 text-sm;
  }

  .btn-md {
    @apply px-4 py-2;
  }

  .btn-lg {
    @apply px-5 py-3 text-lg;
  }

  .btn:hover {
    @apply bg-primary text-white;
  }

  .btn:focus {
    @apply ring-2 ring-blue-400;
  }

  .btn:active {
    @apply translate-y-0.5;
  }

  .fix {
    backface-visibility: hidden;
    -webkit-font-smoothing: subpixel-antialiased;
    will-change: transform;
  }

  .zoomy {
    backface-visibility: hidden;
    -webkit-font-smoothing: subpixel-antialiased;
    will-change: transform;
    @apply drop-shadow-sm;
  }

  .zoomy:hover {
    transform: scale(1.05) translate3d(0,0,0) perspective(0px);
    @apply drop-shadow-2xl;
  }

  .input {
    @apply border rounded px-3 py-2 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-400;
  }
}

@layer components {
  /* Visual Novel scene viewport */
  .vn-scene {
    aspect-ratio: 16 / 9;
    display: flex;
    flex-direction: column;
  }

  @media (max-width: 639px) {
    .vn-scene {
      aspect-ratio: 3 / 4;
    }
  }
}

@layer utilities {
  .bg-primary {
    background-color: theme('colors.primary');
  }
}

/* Visual Novel reader — scene viewport */
@layer components {
  /* The main VN scene container — 16:9 aspect ratio with flex column for dialogue at bottom */
  .vn-scene {
    aspect-ratio: 16 / 9;
    display: flex;
    flex-direction: column;
    min-height: 300px;
    max-height: 80vh;
  }

  /* On mobile, use a taller aspect ratio so dialogue box has more room */
  @media (max-width: 640px) {
    .vn-scene {
      aspect-ratio: 3 / 4;
      min-height: 0;
      max-height: 80svh;
    }
  }

  /* Background layer fills the scene viewport */
  .vn-background {
    z-index: 0;
  }

  .vn-background img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* Fullscreen-specific layout — fills entire screen */
  :fullscreen {
    background: black;
    display: flex;
    flex-direction: column;
  }

  :fullscreen .vn-scene {
    aspect-ratio: auto;
    min-height: 0;
    max-height: none;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
  }

  :fullscreen .vn-sprite {
    max-height: 85%;
  }

  :-webkit-full-screen {
    background: black;
    display: flex;
    flex-direction: column;
  }

  :-webkit-full-screen .vn-scene {
    aspect-ratio: auto;
    min-height: 0;
    max-height: none;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
  }

  :-webkit-full-screen .vn-sprite {
    max-height: 85%;
  }
}

/* Visual Novel reader transitions */
@layer components {
  /* Portrait enter animation — slides up from below with fade */
  .vn-portrait-enter {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
  }

  .vn-portrait-visible {
    opacity: 1;
    transform: translateY(0);
  }

  /* Choice panel reveal — fades in and slides up */
  .vn-choices-enter {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
  }

  .vn-choices-visible {
    opacity: 1;
    transform: translateY(0);
  }

  /* VN scene fade transition */
  .vn-scene-fade {
    transition: opacity 0.4s ease-in-out;
  }

  /* Blinking text cursor for dialogue */
  .vn-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: currentColor;
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: vn-blink 0.8s step-end infinite;
  }

  @keyframes vn-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
  }

  /* Character sprite positioning */
  .vn-sprite {
    position: absolute;
    bottom: 0;
    max-height: 80%;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.3s ease, filter 0.3s ease;
  }

  /* Scale down portraits on mobile to avoid covering dialogue */
  @media (max-width: 640px) {
    .vn-sprite {
      max-height: 55%;
    }
  }

  .vn-sprite-left {
    left: 2%;
  }

  .vn-sprite-right {
    right: 2%;
  }

  .vn-sprite-center {
    left: 50%;
    transform: translateX(-50%);
  }

  /* Active/inactive speaker states */
  .vn-sprite-active {
    filter: none;
  }

  .vn-sprite-inactive {
    filter: brightness(0.7);
  }
}
