/*
* Safari Browser Fixes
* Handles Safari-specific issues for macOS and iOS
* Author: GitHub Copilot
* Version: 1.0
*/

/* Safari Detection and Fixes - More specific Safari targeting */
@supports (-webkit-backdrop-filter: blur(1px)) and (not (display: -ms-flexbox)) {
    /* This targets Safari more specifically */
    /* Header/Navbar fixes for Safari */
    .header-area {
        position: absolute !important;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 999;
        background: transparent !important;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        transition: all 0.3s ease;
        opacity: 1;
        visibility: visible;
    }
    
    /* Hide header on scroll down */
    .header-area.hide-on-scroll {
        opacity: 0 !important;
        visibility: hidden !important;
        transform: translateY(-100%) !important;
    }
    
    .main-header {
        background: transparent !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Logo fixes for Safari */
    .main-header .logo {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform;
    }
    
    .main-header .logo .main-logo img,
    .main-header .logo .secondary-logo img {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform, filter;
        -webkit-filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.5));
        filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.5));
    }
    
    /* Disable complex animations on Safari */
    .main-header .logo .main-logo img {
        animation: none !important;
    }
    
    .main-header .logo .secondary-logo img {
        animation: none !important;
    }
    
    /* Rundown section fixes for Safari */
    .rundown-section {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: auto;
    }
    
    /* Minimal Safari fixes for rundown items - keep original animations */
    .rundown-item {
        will-change: transform, opacity;
    }
    
    .rundown-content {
        will-change: transform;
        /* Only remove backdrop-filter for Safari, keep other properties */
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
    
    .marker-circle {
        will-change: transform;
        /* Only remove backdrop-filter for Safari, keep other properties */
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
    
    /* Timeline fixes */
    .timeline-line {
        -webkit-transform: translateX(-50%) translateZ(0) !important;
        transform: translateX(-50%) translateZ(0) !important;
        will-change: transform;
    }
    
    /* Simplify hover effects for Safari */
    .rundown-item:hover .rundown-content {
        -webkit-transform: translateY(-2px) translateZ(0) !important;
        transform: translateY(-2px) translateZ(0) !important;
    }
    
    .rundown-item:hover .marker-circle {
        -webkit-transform: scale(1.02) translateZ(0) !important;
        transform: scale(1.02) translateZ(0) !important;
    }
}

/* Header hide/show behavior for all browsers */
.header-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 999;
    background: transparent;
    transition: all 0.3s ease;
    opacity: 1;
    visibility: visible;
}

.header-area.hide-on-scroll {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-100%);
}

/* Additional Safari detection using user agent */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* This targets Safari specifically */
    .header-area {
        position: absolute !important;
    }
    
    /* Ensure rundown items are visible in Safari */
    .rundown-item {
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* Final Safari-specific fixes - don't change existing animations */
@supports (-webkit-backdrop-filter: blur(1px)) and (not (display: -ms-flexbox)) {
    /* This specifically targets Safari */
    
    /* Force header to disappear on scroll, not sticky */
    .header-area {
        position: absolute !important;
        top: 0 !important;
        width: 100% !important;
        z-index: 999 !important;
        transition: all 0.3s ease !important;
        background: transparent !important;
    }
    
    /* Ensure logos are visible */
    .main-header .logo .main-logo img,
    .main-header .logo .secondary-logo img {
        opacity: 1 !important;
        visibility: visible !important;
        display: block !important;
    }
    
    /* Only remove backdrop-filter for Safari, keep all other rundown animations */
    .rundown-content {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
    
    .marker-circle {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
}

/* Disable sticky header behavior globally */
.header-sticky.sticky-bar,
.header-sticky.sticky {
    position: absolute !important;
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
}

/* Mobile character styling fixes */
@media (max-width: 768px) {
    .png-bubble{ /* Safari PNG specific bubble */
        max-width: 160px !important; 
        padding: 6px 8px !important; 
        bottom: 210px !important; /* Lebih dekat ke character - reduced from 240px */
        right: -48px !important; /* Lebih ke kanan - moved from 25px */
    }
    
    .speech-text{ 
        font-size: 11px !important; 
    }
    
    .graduate-student-img{ 
        max-width: 160px !important; /* Increased from 110px for better visibility */
    }
    
    .opening-character{ 
        gap: 6px !important; 
    }
}

@media (max-width: 420px) {
    .png-bubble{ /* Safari PNG specific bubble */
        max-width: 130px !important; 
        padding: 4px 6px !important; 
        bottom: 180px !important; /* Lebih dekat ke character - reduced from 210px */
        right: -55px !important; /* Lebih ke kanan - moved from -30px */
    }
    
    .speech-text{ 
        font-size: 10px !important; 
    }
    
    .graduate-student-img{ 
        max-width: 130px !important; /* Increased from 92px for better visibility */
        border-radius: 8px !important; 
    }
}

/* Footer logo responsive: ensure logo isn't too large on any device */
.footer-logo img {
    max-width: 350px; /* desktop */
    width: auto;
    height: auto;
    display: block;
}

@media (max-width: 1200px) {
    .footer-logo img { 
        max-width: 140px; 
    }
}

@media (max-width: 768px) {
    .footer-logo img { 
        max-width: 120px; 
        margin: 0 auto; 
    }
}

@media (max-width: 480px) {
    .footer-logo img { 
        max-width: 350px; 
    }
}

/* Graduate student video styling to appear like an image */
.opening-character { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    flex-direction: column; 
    gap: 12px; 
}

.graduate-student-img,
.graduate-student-video { 
    max-width: 250px; /* Increased to match main CSS sizing */
    width: 100%; 
    height: auto; 
    border-radius: 10px; 
    object-fit: cover; 
    display: block; 
}

/* Safari-specific mobile sizing for PNG to reduce gap with speech bubble */
@supports (-webkit-appearance: none) {
    @media (max-width: 576px) {
        .graduate-student-img {
            max-width: 220px; /* Larger specifically for Safari PNG on mobile */
        }
    }
    
    @media (max-width: 420px) {
        .graduate-student-img {
            max-width: 210px; /* Larger specifically for Safari PNG on very small mobile */
        }
    }
}

/* Ensure video element shows no controls and blends as an image */
video.graduate-student-img,
video.graduate-student-video { 
    background: transparent; 
    box-shadow: none; 
}

@media (max-width: 992px) {
    .graduate-student-img,
    .graduate-student-video { 
        max-width: 220px; /* Updated to match main CSS responsive sizing */
    }
}

@media (max-width: 576px) {
    .graduate-student-img { 
        max-width: 210px; /* Increased specifically for PNG in mobile Safari to reduce gap */
    }
    
    .graduate-student-video { 
        max-width: 190px; /* Keep video size as before */
    }
}

/* Character speech bubble: scaled and responsive */
.character-speech-bubble,
.png-bubble,
.video-bubble {
    display: inline-block;
    max-width: 320px;
    width: 100%;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.9); /* slight translucency so webm alpha can show */
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(7, 20, 32, 0.06);
}

.speech-text {
    font-size: 13px;
    line-height: 1.15;
    color: #0b2330;
    font-weight: 600;
    margin: 0;
    text-align: center;
    letter-spacing: 0.2px;
}

/* Tighter sizes for small screens */
@media (max-width: 768px) {
    .character-speech-bubble,
    .png-bubble,
    .video-bubble { 
        max-width: 220px; 
        padding: 7px 10px; 
    }
    
    .speech-text { 
        font-size: 12px; 
    }
    
    .opening-character { 
        gap: 8px; 
    }
}

@media (max-width: 420px) {
    .character-speech-bubble,
    .png-bubble,
    .video-bubble { 
        max-width: 180px; 
        padding: 6px 8px; 
    }
    
    .speech-text { 
        font-size: 11px; 
    }
    
    .graduate-student-img { 
        max-width: 200px; /* Increased specifically for PNG in very small mobile Safari */
    }
    
    .graduate-student-video { 
        max-width: 180px; /* Keep video size as before */
    }
}

.wave-container {
    z-index: 10;
}

.opening-character {
    z-index: 1;
}

/* Safari AOS animation fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Reset AOS initial state for Safari */
    [data-aos] {
        opacity: 0 !important;
        transition: opacity 0.8s ease, transform 0.8s ease !important;
        transition-delay: 0.1s;
    }
    
    [data-aos].aos-animate {
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* Specific AOS animation fixes for Safari */
    [data-aos="fade-up"] {
        transform: translateY(30px) !important;
    }
    
    [data-aos="fade-up"].aos-animate {
        transform: translateY(0) !important;
    }
    
    [data-aos="fade-down"] {
        transform: translateY(-30px) !important;
    }
    
    [data-aos="fade-down"].aos-animate {
        transform: translateY(0) !important;
    }
    
    [data-aos="fade-left"] {
        transform: translateX(30px) !important;
    }
    
    [data-aos="fade-left"].aos-animate {
        transform: translateX(0) !important;
    }
    
    [data-aos="fade-right"] {
        transform: translateX(-30px) !important;
    }
    
    [data-aos="fade-right"].aos-animate {
        transform: translateX(0) !important;
    }
    
    [data-aos="zoom-in"] {
        transform: scale(0.9) !important;
    }
    
    [data-aos="zoom-in"].aos-animate {
        transform: scale(1) !important;
    }
    
    [data-aos="flip-left"] {
        transform: perspective(2500px) rotateY(-100deg) !important;
    }
    
    [data-aos="flip-left"].aos-animate {
        transform: perspective(2500px) rotateY(0deg) !important;
    }
}

/* Safari rundown section specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .rundown-section {
        -webkit-transform-style: flat;
        transform-style: flat;
        -webkit-perspective: none;
        perspective: none;
    }
    
    .rundown-container {
        -webkit-transform-style: flat;
        transform-style: flat;
    }
    
    .rundown-item {
        -webkit-transform-style: flat !important;
        transform-style: flat !important;
        -webkit-perspective: none !important;
        perspective: none !important;
        -webkit-backface-visibility: visible !important;
        backface-visibility: visible !important;
        will-change: transform, opacity;
    }
    
    .rundown-item.animate-on-scroll {
        opacity: 0 !important;
        transform: translateY(20px) !important;
        transition: transform 0.8s ease, opacity 0.8s ease;
    }
    
    .rundown-item.animate-on-scroll.aos-animate {
        opacity: 1 !important;
        transform: translateY(0) !important;
    }
    
    .rundown-content {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        background: rgba(255, 255, 255, 0.98) !important;
        border: 2px solid #d4af37 !important;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
    }
    
    .marker-circle {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        background: linear-gradient(135deg, rgba(212, 175, 55, 0.95) 0%, rgba(247, 215, 148, 0.9) 50%, rgba(212, 175, 55, 0.95) 100%) !important;
        border: 2px solid #d4af37 !important;
    }
}

/* Safari mobile specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 768px) {
    /* iOS Safari viewport fix */
    :root {
        --vh: 1vh;
    }
    
    .full-height {
        height: calc(var(--vh, 1vh) * 100);
    }
    
    /* Prevent zoom on input focus */
    input[type="text"],
    input[type="email"],
    textarea,
    select {
        font-size: 16px !important;
    }
    
    /* Simplify complex animations on mobile Safari */
    .rundown-item,
    .marker-circle,
    .rundown-content {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform, opacity;
    }
    
    /* Reduce animation complexity for better performance */
    [data-aos] {
        transition-duration: 0.6s !important;
    }
    
    .rundown-item.animate-on-scroll {
        transition-duration: 0.6s !important;
    }
}
