/**
 * MindRead Advanced Animations
 * 고급 애니메이션 및 시각 효과
 *
 * 포함 기능:
 * - Parallax 효과
 * - 모바일 파티클 최적화
 * - 버튼 피드백 강화
 * - View Transitions API
 * - 고급 마이크로인터랙션
 * - SVG 애니메이션
 */

/* ========================================
 * 1. View Transitions API 지원
 * ======================================== */

/* 페이지 전환 기본 설정 */
@view-transition {
    navigation: auto;
}

::view-transition-old(root) {
    animation: fade-out 0.25s ease-out both;
}

::view-transition-new(root) {
    animation: fade-in 0.25s ease-in both;
}

@keyframes fade-out {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.98); }
}

@keyframes fade-in {
    from { opacity: 0; transform: scale(1.02); }
    to { opacity: 1; transform: scale(1); }
}

/* 슬라이드 전환 */
::view-transition-old(slide) {
    animation: slide-out-left 0.3s ease-out both;
}

::view-transition-new(slide) {
    animation: slide-in-right 0.3s ease-out both;
}

@keyframes slide-out-left {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-30px); opacity: 0; }
}

@keyframes slide-in-right {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* View Transition 미지원 브라우저용 폴백 */
.page-enter {
    animation: pageSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.page-exit {
    animation: pageSlideOut 0.3s ease-in forwards;
}

@keyframes pageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pageSlideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* ========================================
 * 2. Parallax 효과
 * ======================================== */

.parallax-container {
    position: relative;
    overflow: hidden;
    perspective: 1px;
    transform-style: preserve-3d;
    height: 100vh;
}

.parallax-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.parallax-layer--back {
    transform: translateZ(-1px) scale(2);
}

.parallax-layer--base {
    transform: translateZ(0);
}

.parallax-layer--front {
    transform: translateZ(0.5px) scale(0.5);
}

/* JavaScript 기반 Parallax */
[data-parallax] {
    will-change: transform;
    transition: transform 0.1s linear;
}

[data-parallax="slow"] {
    --parallax-speed: 0.3;
}

[data-parallax="medium"] {
    --parallax-speed: 0.5;
}

[data-parallax="fast"] {
    --parallax-speed: 0.8;
}

/* 히어로 섹션 Parallax */
.hero-parallax {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
}

.hero-parallax .hero-bg {
    position: absolute;
    inset: -50px;
    background-size: cover;
    background-position: center;
    will-change: transform;
}

.hero-parallax .hero-content {
    position: relative;
    z-index: 1;
}

/* ========================================
 * 3. 모바일 파티클 최적화
 * ======================================== */

/* 기본 파티클 스타일 */
.particles-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: var(--particle-size, 4px);
    height: var(--particle-size, 4px);
    background: var(--color-primary);
    border-radius: 50%;
    opacity: var(--particle-opacity, 0.3);
    animation: particleFloat var(--particle-duration, 15s) linear infinite;
}

@keyframes particleFloat {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: var(--particle-opacity, 0.3);
    }
    90% {
        opacity: var(--particle-opacity, 0.3);
    }
    100% {
        transform: translateY(-100vh) rotate(360deg);
        opacity: 0;
    }
}

/* 모바일 최적화: 파티클 수 줄이기 */
@media (max-width: 768px) {
    .particles-container .particle:nth-child(n+16) {
        display: none;
    }

    .particle {
        --particle-size: 3px;
    }
}

/* 저사양 기기: 파티클 더 줄이기 */
@media (max-width: 480px) {
    .particles-container .particle:nth-child(n+9) {
        display: none;
    }
}

/* 배터리 절약 모드 */
@media (prefers-reduced-motion: reduce) {
    .particles-container {
        display: none;
    }
}

/* GPU 가속 최적화 */
.particle {
    will-change: transform, opacity;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ========================================
 * 4. 버튼 피드백 강화
 * ======================================== */

/* 버튼 터치 피드백 */
.btn-feedback {
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* 리플 이펙트 개선 */
.btn-feedback::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.5) 0%, transparent 70%);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease, opacity 0.6s ease;
    opacity: 0;
    pointer-events: none;
}

.btn-feedback:active::before {
    width: 300%;
    height: 300%;
    opacity: 1;
    transition: width 0s, height 0s, opacity 0s;
}

/* 버튼 누름 효과 */
.btn-press {
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                box-shadow 0.15s ease;
}

.btn-press:active {
    transform: scale(0.96);
}

/* 버튼 호버 글로우 */
.btn-glow {
    position: relative;
}

.btn-glow::after {
    content: '';
    position: absolute;
    inset: -2px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    border-radius: inherit;
    z-index: -1;
    opacity: 0;
    filter: blur(12px);
    transition: opacity 0.3s ease;
}

.btn-glow:hover::after {
    opacity: 0.6;
}

/* 선택 버튼 특수 피드백 (플레이어용) */
.choice-btn-enhanced {
    position: relative;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: center;
}

.choice-btn-enhanced:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow:
        0 12px 24px rgba(var(--color-primary-rgb), 0.2),
        0 4px 8px rgba(0, 0, 0, 0.1);
}

.choice-btn-enhanced:active {
    transform: translateY(-2px) scale(0.98);
}

/* 선택됨 상태 */
.choice-btn-enhanced.selected {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: white;
    border-color: transparent;
    animation: selectPulse 0.5s ease;
}

@keyframes selectPulse {
    0% { transform: scale(1); }
    25% { transform: scale(1.05); }
    50% { transform: scale(0.98); }
    100% { transform: scale(1); }
}

/* 선택 완료 체크마크 애니메이션 */
.choice-btn-enhanced.selected::after {
    content: '';
    position: absolute;
    right: 16px;
    top: 50%;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transform: translateY(-50%) scale(0);
    animation: checkmarkAppear 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.1s forwards;
}

@keyframes checkmarkAppear {
    to {
        transform: translateY(-50%) scale(1);
    }
}

/* ========================================
 * 5. 스크롤 기반 애니메이션 강화
 * ======================================== */

/* Reveal 방향 변형 */
.reveal-up {
    opacity: 0;
    transform: translateY(60px);
}

.reveal-down {
    opacity: 0;
    transform: translateY(-60px);
}

.reveal-left {
    opacity: 0;
    transform: translateX(-60px);
}

.reveal-right {
    opacity: 0;
    transform: translateX(60px);
}

.reveal-scale {
    opacity: 0;
    transform: scale(0.8);
}

.reveal-rotate {
    opacity: 0;
    transform: rotate(-10deg) translateY(40px);
}

/* Reveal 활성화 */
.reveal-up.revealed,
.reveal-down.revealed,
.reveal-left.revealed,
.reveal-right.revealed,
.reveal-scale.revealed,
.reveal-rotate.revealed {
    opacity: 1;
    transform: translateY(0) translateX(0) scale(1) rotate(0deg);
    transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Stagger 딜레이 유틸리티 */
[data-reveal-delay="1"] { transition-delay: 0.1s; }
[data-reveal-delay="2"] { transition-delay: 0.2s; }
[data-reveal-delay="3"] { transition-delay: 0.3s; }
[data-reveal-delay="4"] { transition-delay: 0.4s; }
[data-reveal-delay="5"] { transition-delay: 0.5s; }
[data-reveal-delay="6"] { transition-delay: 0.6s; }

/* 스크롤 진행 표시기 */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    z-index: 9999;
    transition: width 0.1s linear;
}

/* ========================================
 * 6. 고급 호버 효과
 * ======================================== */

/* 카드 3D 틸트 (마우스 추적) */
.tilt-card {
    transform-style: preserve-3d;
    perspective: 1000px;
    transition: transform 0.1s ease-out;
}

.tilt-card-inner {
    transform: translateZ(20px);
    transition: transform 0.3s ease;
}

.tilt-card:hover .tilt-card-inner {
    transform: translateZ(40px);
}

/* 마그넷 효과 */
.magnet-btn {
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* 빛 반사 효과 */
.shine-effect {
    position: relative;
    overflow: hidden;
}

.shine-effect::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(255, 255, 255, 0) 40%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 60%,
        transparent 100%
    );
    transform: rotate(25deg) translateX(-100%);
    transition: transform 0.6s ease;
    pointer-events: none;
}

.shine-effect:hover::before {
    transform: rotate(25deg) translateX(100%);
}

/* ========================================
 * 7. 로딩 애니메이션 강화
 * ======================================== */

/* 브랜드 로딩 - 하트비트 */
.brand-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.brand-loader-heart {
    font-size: 64px;
    animation: brandHeartbeat 1.4s ease-in-out infinite;
    filter: drop-shadow(0 0 20px rgba(var(--color-primary-rgb), 0.5));
}

@keyframes brandHeartbeat {
    0%, 100% { transform: scale(1); }
    14% { transform: scale(1.2); }
    28% { transform: scale(1); }
    42% { transform: scale(1.15); }
    56% { transform: scale(1); }
}

/* 물결 로딩 */
.wave-loader {
    display: flex;
    gap: 4px;
    align-items: flex-end;
    height: 30px;
}

.wave-loader span {
    width: 4px;
    height: 10px;
    background: var(--color-primary);
    border-radius: 2px;
    animation: waveBar 1.2s ease-in-out infinite;
}

.wave-loader span:nth-child(1) { animation-delay: 0s; }
.wave-loader span:nth-child(2) { animation-delay: 0.1s; }
.wave-loader span:nth-child(3) { animation-delay: 0.2s; }
.wave-loader span:nth-child(4) { animation-delay: 0.3s; }
.wave-loader span:nth-child(5) { animation-delay: 0.4s; }

@keyframes waveBar {
    0%, 100% { height: 10px; }
    50% { height: 30px; }
}

/* 원형 프로그레스 */
.circular-progress {
    width: 60px;
    height: 60px;
    position: relative;
}

.circular-progress svg {
    transform: rotate(-90deg);
}

.circular-progress circle {
    fill: none;
    stroke-width: 4;
    stroke-linecap: round;
}

.circular-progress .track {
    stroke: var(--color-bg-subtle);
}

.circular-progress .progress {
    stroke: var(--color-primary);
    stroke-dasharray: 157;
    stroke-dashoffset: 157;
    animation: circularFill 2s ease-out forwards;
}

@keyframes circularFill {
    to {
        stroke-dashoffset: 0;
    }
}

/* ========================================
 * 8. 텍스트 애니메이션
 * ======================================== */

/* 타이핑 효과 */
.typing-text {
    overflow: hidden;
    border-right: 2px solid var(--color-primary);
    white-space: nowrap;
    animation:
        typing 3s steps(30, end),
        blink-caret 0.75s step-end infinite;
}

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: var(--color-primary); }
}

/* 글자 개별 애니메이션 */
.text-reveal span {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px) rotateX(-90deg);
    animation: letterReveal 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.text-reveal span:nth-child(1) { animation-delay: 0.05s; }
.text-reveal span:nth-child(2) { animation-delay: 0.1s; }
.text-reveal span:nth-child(3) { animation-delay: 0.15s; }
.text-reveal span:nth-child(4) { animation-delay: 0.2s; }
.text-reveal span:nth-child(5) { animation-delay: 0.25s; }
.text-reveal span:nth-child(6) { animation-delay: 0.3s; }
.text-reveal span:nth-child(7) { animation-delay: 0.35s; }
.text-reveal span:nth-child(8) { animation-delay: 0.4s; }
.text-reveal span:nth-child(9) { animation-delay: 0.45s; }
.text-reveal span:nth-child(10) { animation-delay: 0.5s; }

@keyframes letterReveal {
    to {
        opacity: 1;
        transform: translateY(0) rotateX(0);
    }
}

/* 그라데이션 텍스트 애니메이션 */
.gradient-text-animated {
    background: linear-gradient(
        90deg,
        var(--color-primary),
        var(--color-secondary),
        var(--color-primary)
    );
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 3s linear infinite;
}

@keyframes gradientShift {
    to {
        background-position: 200% center;
    }
}

/* ========================================
 * 9. SVG 애니메이션
 * ======================================== */

/* SVG 라인 드로우 */
.svg-draw path,
.svg-draw line,
.svg-draw circle,
.svg-draw rect {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: svgDraw 2s ease forwards;
}

@keyframes svgDraw {
    to {
        stroke-dashoffset: 0;
    }
}

/* SVG 아이콘 호버 */
.svg-icon-animated {
    transition: all 0.3s ease;
}

.svg-icon-animated:hover {
    transform: scale(1.1);
    filter: drop-shadow(0 4px 8px rgba(var(--color-primary-rgb), 0.3));
}

/* SVG 맥박 */
.svg-pulse {
    animation: svgPulse 2s ease-in-out infinite;
}

@keyframes svgPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

/* ========================================
 * 10. 특수 효과
 * ======================================== */

/* 글래스모피즘 강화 */
.glass-enhanced {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.1),
        inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* 네온 글로우 */
.neon-glow {
    text-shadow:
        0 0 5px var(--color-primary),
        0 0 10px var(--color-primary),
        0 0 20px var(--color-primary),
        0 0 40px var(--color-primary);
    animation: neonPulse 2s ease-in-out infinite;
}

@keyframes neonPulse {
    0%, 100% {
        text-shadow:
            0 0 5px var(--color-primary),
            0 0 10px var(--color-primary),
            0 0 20px var(--color-primary),
            0 0 40px var(--color-primary);
    }
    50% {
        text-shadow:
            0 0 2px var(--color-primary),
            0 0 5px var(--color-primary),
            0 0 10px var(--color-primary),
            0 0 20px var(--color-primary);
    }
}

/* 플로팅 애니메이션 변형 */
.float-slow {
    animation: floatSlow 6s ease-in-out infinite;
}

.float-medium {
    animation: floatMedium 4s ease-in-out infinite;
}

.float-fast {
    animation: floatFast 2s ease-in-out infinite;
}

@keyframes floatSlow {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-15px) rotate(2deg); }
}

@keyframes floatMedium {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes floatFast {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* 흔들림 효과 */
.wiggle {
    animation: wiggle 0.5s ease-in-out;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

/* 바운스 인 */
.bounce-in {
    animation: bounceIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* 성공 체크 애니메이션 */
.success-check {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--color-success);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: successPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.success-check svg {
    width: 40px;
    height: 40px;
    stroke: white;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.success-check svg path {
    stroke-dasharray: 50;
    stroke-dashoffset: 50;
    animation: checkDraw 0.4s ease 0.2s forwards;
}

@keyframes successPop {
    0% { transform: scale(0); }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes checkDraw {
    to { stroke-dashoffset: 0; }
}

/* ========================================
 * 11. 성능 최적화 유틸리티
 * ======================================== */

/* GPU 가속 강제 */
.gpu-accelerate {
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* 애니메이션 일시정지 */
.animation-paused {
    animation-play-state: paused !important;
}

/* 뷰포트 밖 요소 최적화 */
.offscreen {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* ========================================
 * 12. 다크모드 애니메이션 조정
 * ======================================== */

body.dark-mode .particle {
    background: var(--color-primary-light);
    opacity: 0.2;
}

body.dark-mode .glass-enhanced {
    background: rgba(30, 30, 40, 0.7);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .shine-effect::before {
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(255, 255, 255, 0) 40%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0) 60%,
        transparent 100%
    );
}
