/* Custom CSS Variables */
:root {
    --primary-color: #0EA5E9;
    --secondary-color: #06B6D4;
    --accent-color: #10B981;
    --dark-color: #0F172A;
    --dark-lighter: #1E293B;
    --gray-custom: #64748B;
    --transition: all 0.3s ease;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--dark-color);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Smooth Scroll */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Body Styles */
body {
    overflow-x: hidden;
    line-height: 1.6;
}

/* Navigation Styles */
.nav-link {
    position: relative;
    transition: var(--transition);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s ease;
}

.nav-link:hover::after,
.nav-link.active::after {
    width: 100%;
}

/* Hero Section Background Effects */
.particles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.particles-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, var(--primary-color) 1px, transparent 1px);
    background-size: 50px 50px;
    animation: particleFloat 20s linear infinite;
    opacity: 0.1;
}

.gradient-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, 
        rgba(14, 165, 233, 0.1) 0%, 
        rgba(6, 182, 212, 0.1) 25%,
        rgba(16, 185, 129, 0.1) 50%,
        rgba(14, 165, 233, 0.1) 75%,
        rgba(6, 182, 212, 0.1) 100%);
    animation: gradientShift 8s ease-in-out infinite;
}

@keyframes particleFloat {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(-50px, -50px) rotate(360deg); }
}

@keyframes gradientShift {
    0%, 100% { opacity: 0.1; }
    50% { opacity: 0.2; }
}

/* Button Styles */
.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border: none;
    color: white;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.2), 
        transparent);
    transition: left 0.5s ease;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.btn-secondary::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
    z-index: -1;
}

.btn-secondary:hover::before {
    width: 100%;
}

.btn-secondary:hover {
    color: white;
}

/* Service Cards */
.service-card {
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.service-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(14, 165, 233, 0.1), 
        transparent);
    transition: left 0.5s ease;
}

.service-card:hover::before {
    left: 100%;
}

.service-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 20px 40px rgba(14, 165, 233, 0.2);
}

/* Portfolio Items */
.portfolio-item {
    transition: var(--transition);
    overflow: hidden;
}

.portfolio-item:hover {
    transform: translateY(-10px);
    box-shadow: 0 20px 40px rgba(14, 165, 233, 0.2);
}

.portfolio-item img {
    transition: transform 0.5s ease;
}

.portfolio-item:hover img {
    transform: scale(1.1);
}

/* Form Styles */
input, textarea {
    transition: var(--transition);
}

input:focus, textarea:focus {
    box-shadow: 0 0 20px rgba(14, 165, 233, 0.3);
    transform: translateY(-2px);
}

/* Loading Animation */
.loading {
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Scroll Reveal Animations */
.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.8s ease;
}

.reveal.active {
    opacity: 1;
    transform: translateY(0);
}

/* Typing Animation */
.typing-animation {
    overflow: hidden;
    border-right: 2px solid var(--primary-color);
    white-space: nowrap;
    animation: typing 3s steps(40, 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(--primary-color); }
}

/* Floating Elements */
.floating {
    animation: float 3s ease-in-out infinite;
}

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

/* Pulse Animation */
.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(14, 165, 233, 0); }
    100% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0); }
}

/* Glitch Effect */
.glitch {
    position: relative;
}

.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.glitch::before {
    animation: glitch-anim-1 0.3s infinite linear alternate-reverse;
    color: var(--primary-color);
    z-index: -1;
}

.glitch::after {
    animation: glitch-anim-2 0.3s infinite linear alternate-reverse;
    color: var(--secondary-color);
    z-index: -2;
}

@keyframes glitch-anim-1 {
    0% { clip-path: inset(40% 0 61% 0); }
    20% { clip-path: inset(92% 0 1% 0); }
    40% { clip-path: inset(43% 0 1% 0); }
    60% { clip-path: inset(25% 0 58% 0); }
    80% { clip-path: inset(54% 0 7% 0); }
    100% { clip-path: inset(58% 0 43% 0); }
}

@keyframes glitch-anim-2 {
    0% { clip-path: inset(25% 0 58% 0); }
    20% { clip-path: inset(54% 0 7% 0); }
    40% { clip-path: inset(58% 0 43% 0); }
    60% { clip-path: inset(40% 0 61% 0); }
    80% { clip-path: inset(92% 0 1% 0); }
    100% { clip-path: inset(43% 0 1% 0); }
}

/* Parallax Effect */
.parallax {
    transform: translateZ(0);
    will-change: transform;
}

/* Text Gradient Animation */
.gradient-text {
    background: linear-gradient(270deg, var(--primary-color), var(--secondary-color), var(--accent-color));
    background-size: 600% 600%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientText 3s ease infinite;
}

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

/* Mobile Optimizations */
@media (max-width: 768px) {
    .particles-container::before {
        background-size: 30px 30px;
    }
    
    .service-card:hover {
        transform: none;
    }
    
    .portfolio-item:hover {
        transform: none;
    }
}

/* Responsive Typography para iPhone */
@media (max-width: 390px) {
    h1 {
        font-size: 2.5rem !important; /* Reducir en pantallas muy pequeñas */
    }
    
    .text-xl {
        font-size: 1.125rem;
    }
    
    .text-5xl {
        font-size: 2.5rem;
    }
}

/* Para iPhone SE y similares */
@media (max-width: 375px) {
    h1 {
        font-size: 2.25rem !important;
    }
    
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #ffffff;
        --secondary-color: #ffffff;
        --accent-color: #ffffff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {
    .particles-container,
    .gradient-bg,
    nav,
    .floating,
    button {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
}

/* Dark mode specific adjustments */
@media (prefers-color-scheme: dark) {
    /* Additional dark mode specific styles if needed */
}

/* Custom focus states for accessibility */
button:focus,
input:focus,
textarea:focus,
a:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Improved text selection */
::selection {
    background: var(--primary-color);
    color: white;
}

::-moz-selection {
    background: var(--primary-color);
    color: white;
}

/* Mobile Menu Improvements */
#mobile-menu {
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(100, 116, 139, 0.2);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

#mobile-menu a {
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(100, 116, 139, 0.1);
}

#mobile-menu a:last-child {
    border-bottom: none;
}

/* Navbar shadow fix */
#navbar {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* iOS Safari Fixes */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Fix para inputs en iOS */
input, textarea, select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0.5rem;
}

/* Prevenir zoom en inputs en iOS */
input[type="text"],
input[type="email"],
input[type="tel"],
textarea {
    font-size: 16px; /* Mínimo 16px para evitar auto-zoom en iOS */
}

/* Fix para botones en Safari */
button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Safe area para iPhone con notch */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    #navbar {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }
}

/* Fix para hover en dispositivos táctiles */
@media (hover: none) {
    .service-card:hover,
    .portfolio-item:hover {
        transform: none;
    }
    
    .service-card:active,
    .portfolio-item:active {
        transform: translateY(-8px) scale(1.02);
    }
}

/* Mejoras para pantallas Retina (Mac) */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Fix para videos/imágenes en Safari */
img, video {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Safari specific fixes */
body.safari .gradient-bg {
    will-change: transform;
}

/* iOS specific fixes */
body.ios input[type="submit"],
body.ios button {
    border-radius: 0.5rem;
}