/* Base Styles */
:root {
    --primary-color: #8B0000;
    --secondary-color: #2D2D2D;
    --adjust-size: 0px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
    scroll-behavior: smooth;
}

body {
    position: relative;
    color: #222;
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    background-color: #fff;
}

/* RTL Styles */
body[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

body[dir="rtl"] .ri-arrow-right-s-line:before {
    content: "\ea64"; /* ri-arrow-left-s-line */
}

body[dir="rtl"] .ri-arrow-right-line:before {
    content: "\ea64"; /* ri-arrow-left-line */
}

/* Header Styles */
header {
    transition: all 0.3s ease;
}

header.scrolled {
    background-color: rgba(45, 45, 45, 0.9) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

/* Language Toggle Styles */
#language-toggle {
    position: relative;
    z-index: 10;
}

#language-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 120px;
    z-index: 1000;
}

#language-dropdown.show {
    display: block;
}

.language-option {
    display: block;
    padding: 8px 12px;
    text-decoration: none;
    color: var(--secondary-color);
    transition: background-color 0.3s;
}

.language-option:hover {
    background-color: #f5f5f5;
}

/* Smooth Section Transitions */
section {
    opacity: 0;
    transition: opacity 0.6s ease-out;
}

section.visible {
    opacity: 1;
}

[class*="section-delay-"] {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.section-delay-1 { transition-delay: 0.1s; }
.section-delay-2 { transition-delay: 0.2s; }
.section-delay-3 { transition-delay: 0.3s; }
.section-delay-4 { transition-delay: 0.4s; }
.section-delay-5 { transition-delay: 0.5s; }
.section-delay-6 { transition-delay: 0.6s; }

/* Hero Section doesn't need transition */
#home {
    opacity: 1;
    transform: none;
}

/* Navigation Active Link */
nav a.active {
    color: var(--primary-color) !important;
    font-weight: 600;
    position: relative;
}

nav a.active::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--primary-color);
    animation: underlineGrow 0.3s ease-out;
}

@keyframes underlineGrow {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}

/* Gallery Styles */
#gallery {
    position: relative;
    left: calc(-1 * var(--adjust-size));
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    max-width: 100%;
    padding: 1.5rem;
    perspective: 0;
    z-index: 1;
}

#gallery figure {
    position: relative;
    margin: var(--adjust-size);
    padding: 0.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    background-color: white;
    overflow: hidden;
    transform-origin: center 0.22rem;
}

#gallery figure img {
    aspect-ratio: 1 / 1;
    width: 100%;
    height: auto;
    object-fit: cover;
    display: block;
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
}

#gallery figure figcaption {
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    color: var(--secondary-color);
}

/* Animation Styles */
#gallery figure {
    animation-duration: var(--duration);
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-direction: alternate;
    animation-name: swing;
}

@keyframes swing {
    0% { transform: rotate3d(0, 0, 1, calc(-1 * var(--angle))); }
    50% { transform: rotate3d(0, 0, 1, var(--angle)); }
    100% { transform: rotate3d(0, 0, 1, calc(-1 * var(--angle))); }
}

/* Color and Animation Variations */
#gallery figure:nth-child(7n) { --duration: 3s; --pin-color: crimson; }
#gallery figure:nth-child(7n + 1) { --duration: 3.5s; --pin-color: hotpink; }
#gallery figure:nth-child(7n + 2) { --duration: 2.8s; --pin-color: magenta; }
#gallery figure:nth-child(7n + 3) { --duration: 3.2s; --pin-color: orangered; }
#gallery figure:nth-child(7n + 4) { --duration: 2.5s; --pin-color: darkorchid; }
#gallery figure:nth-child(7n + 5) { --duration: 3.7s; --pin-color: deeppink; }
#gallery figure:nth-child(7n + 6) { --duration: 2.9s; --pin-color: mediumvioletred; }

#gallery figure:nth-child(3n) { --angle: 3deg; }
#gallery figure:nth-child(3n + 1) { --angle: -3.3deg; }
#gallery figure:nth-child(3n + 2) { --angle: 2.4deg; }

/* Pin Effect */
#gallery figure:after {
    position: absolute;
    top: 0.22rem;
    left: 50%;
    width: 0.7rem;
    height: 0.7rem;
    content: "";
    background: var(--pin-color);
    border-radius: 50%;
    box-shadow: -0.1rem -0.1rem 0.3rem 0.02rem rgba(0, 0, 0, 0.5) inset;
    filter: drop-shadow(0.3rem 0.15rem 0.2rem rgba(0, 0, 0, 0.5));
    transform: translateZ(0);
    z-index: 2;
}

/* Form Styles */
#contact-form input,
#contact-form textarea,
#contact-form select {
    transition: all 0.3s ease;
    border: 1px solid #e2e8f0;
}

#contact-form input:focus,
#contact-form textarea:focus,
#contact-form select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(139, 0, 0, 0.1);
}

/* Button Styles */
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    background-color: rgba(139, 0, 0, 0.9);
}

/* Back to Top Button */
#back-to-top {
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Real Estate Section Styles */
.KHAYALLA-section {
    background: white;
    min-height: 300px;
    position: relative;
}

.stage {
    height: 180px;
    width: 300px;
    margin: auto;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    perspective: 9999px;
    transform-style: preserve-3d;
    cursor: pointer;
}

.layer {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
    animation: float 5s infinite alternate ease-in-out -7.5s;
    animation-fill-mode: forwards;
    transform: rotateY(40deg) rotateX(33deg) translateZ(0);
}

.layer:after {
    font: 80px/0.8 "Inter", sans-serif;
    content: "KHAYALLA";
    text-align: center;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 30px;
    color: #8B0000;
    letter-spacing: -1px;
    font-weight: 400;
    transition: all 0.3s ease;
}

.layer:nth-child(1):after { transform: translateZ(0px); opacity: 0.2; }
.layer:nth-child(2):after { transform: translateZ(-2px); opacity: 0.3; }
.layer:nth-child(3):after { transform: translateZ(-4px); opacity: 0.5; }
.layer:nth-child(4):after { transform: translateZ(-6px); opacity: 0.7; }
.layer:nth-child(5):after { transform: translateZ(-8px); opacity: 1; }

.stage:hover .layer:after {
    color: #2D2D2D;
}

@keyframes float {
    100% {
        transform: rotateY(-30deg) rotateX(-30deg);
    }
}

/* Footer Styles */
footer {
    background-color: var(--secondary-color);
    color: white;
}

footer a {
    color: #d1d5db;
    transition: color 0.3s ease;
}

footer a:hover {
    color: white;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #gallery {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
    
    /* Adjust section delays for mobile */
    [class*="section-delay-"] {
        transition-delay: 0s !important;
    }
    
    /* Adjust language toggle for mobile */
    #language-toggle {
        padding: 0.25rem 0.5rem;
        font-size: 0.875rem;
    }

    /* Adjust hero text for mobile */
    #home h1 {
        font-size: 2.5rem;
    }
}

@media (max-width: 480px) {
    #gallery {
        grid-template-columns: 1fr;
    }
    
    /* Adjust header for mobile */
    header {
        padding: 1rem;
    }
    
    /* Center language toggle on mobile */
    #language-toggle {
        margin-left: auto;
        margin-right: auto;
    }
}

/* Utility Classes */
.section-padding {
    padding: 5rem 0;
}

.max-width {
    max-width: 1200px;
    margin: 0 auto;
}

/* Language dropdown RTL adjustments */
#language-dropdown {
    right: auto;
    left: 0;
}

[dir="ltr"] #language-dropdown {
    left: auto;
    right: 0;
}

.language-option {
    text-align: right;
}

[dir="ltr"] .language-option {
    text-align: left;
}