/* --- 1. THEME ENGINE --- */
@property --light-r { syntax: '<number>'; inherits: true; initial-value: 220; }
@property --light-g { syntax: '<number>'; inherits: true; initial-value: 230; }
@property --light-b { syntax: '<number>'; inherits: true; initial-value: 255; }

:root {
    /* DARK MODE (Default) */
    --bg-body: #050505;
    --bg-panel: #0a0a0a;
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.4);
    --border-dim: rgba(255, 255, 255, 0.1);
    --border-highlight: rgba(255, 255, 255, 0.3);
    /* Updated to Yellow-400 (#FACC15) */
    --accent-gold: #FACC15; 
    --particle-color: rgba(255, 255, 255, 0.6);
    
    /* Cold Light (Base) */
    --light-base-r: 220; --light-base-g: 230; --light-base-b: 255;
    /* Active (animated) light values - refer to base by default */
    --light-r: var(--light-base-r); --light-g: var(--light-base-g); --light-b: var(--light-base-b);
    /* Warm Light (Hover) */
    --warm-r: 250; --warm-g: 204; --warm-b: 21; /* Yellow-400 */
    
    --beam-blend: screen;
    --beam-opacity: 0.9;
    --map-filter: none; /* Full Color */
}

[data-theme="light"] {
    /* LIGHT MODE */
    --bg-body: #F5F5F0;
    --bg-panel: #EBEBE6;
    --text-main: #1a1a1a;
    --text-muted: rgba(26, 26, 26, 0.5);
    --border-dim: rgba(0, 0, 0, 0.08);
    --border-highlight: rgba(0, 0, 0, 0.2);
    --accent-gold: #ffc341; /* Darker Gold for visibility on light bg */
    --particle-color: rgba(0, 0, 0, 0.2);

    --light-base-r: 50; --light-base-g: 50; --light-base-b: 50; 
    --light-r: var(--light-base-r); --light-g: var(--light-base-g); --light-b: var(--light-base-b);
    --warm-r: 234; --warm-g: 179; --warm-b: 8;

    --beam-blend: multiply; 
    --beam-opacity: 0.15; 
    --map-filter: none; /* Full Color */
}

/* Smooth Transitions */
body, section, nav, .nav-btn, .project-card, .material-card, .hero-title, p, h2, h3, span, div, iframe, svg {
    transition: background-color 0.6s cubic-bezier(0.25, 1, 0.5, 1), 
                color 0.6s cubic-bezier(0.25, 1, 0.5, 1),
                border-color 0.6s cubic-bezier(0.25, 1, 0.5, 1),
                filter 0.6s ease;
}


/* --- 2. LAMP LOADER --- */
#loader {
    position: fixed; inset: 0; z-index: 100;
    background-color: #050505; 
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    transition: opacity 0.8s ease-out, visibility 0.8s;
    overflow: hidden;
}

.lamp-assembly {
    position: absolute; top: 0; left: 50%; /* Fixed to top */
    transform-origin: top center;
    animation: pendulumSwing 2.5s infinite ease-in-out alternate;
    height: 40vh; /* String length area */
    width: 2px;
}

.lamp-cord {
    width: 2px; height: 100%;
    background: #333;
    margin: 0 auto;
}

.lamp-shade {
    position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
    width: 60px; height: 40px;
    background: #222;
    border-radius: 40px 40px 0 0;
    border-bottom: 2px solid #444;
    z-index: 2;
}

.lamp-bulb {
    position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%);
    width: 24px; height: 24px;
    background: #444;
    border-radius: 50%;
    z-index: 1;
    transition: background 0.2s, box-shadow 0.2s;
    animation: bulbFlicker 3s linear forwards;
}

.lamp-beam {
    position: absolute; top: 35px; left: 50%; transform: translateX(-50%);
    width: 0; height: 0;
    border-left: 100px solid transparent;
    border-right: 100px solid transparent;
    border-bottom: 400px solid rgba(255, 255, 255, 0.0);
    pointer-events: none;
    z-index: 0;
    animation: beamIntensity 3s linear forwards;
    filter: blur(10px);
}

.loader-text {
    position: fixed; bottom: 10%; width: 100%; text-align: center;
    font-family: 'Cinzel', serif; color: #fff; letter-spacing: 0.5em;
    font-size: 0.8rem; opacity: 0;
    animation: textFadeIn 1s ease-out 1.5s forwards;
}

@keyframes pendulumSwing {
    from { transform: rotate(10deg); }
    to { transform: rotate(-10deg); }
}

@keyframes bulbFlicker {
    0% { background: #444; box-shadow: 0 0 0 transparent; }
    10% { background: #555; box-shadow: 0 0 0 transparent; }
    12% { background: #fff; box-shadow: 0 0 20px rgba(255,255,255,0.8); }
    15% { background: #444; box-shadow: 0 0 0 transparent; }
    20% { background: #fff; box-shadow: 0 0 20px rgba(255,255,255,0.8); }
    40% { background: #fff; box-shadow: 0 0 40px rgba(255,255,255,0.6); }
    100% { background: #fff; box-shadow: 0 0 80px rgba(255,255,255,0.8); }
}

@keyframes beamIntensity {
    0%, 15% { border-bottom-color: rgba(255, 255, 255, 0); }
    20% { border-bottom-color: rgba(255, 255, 255, 0.1); }
    40% { border-bottom-color: rgba(255, 255, 255, 0.05); }
    100% { border-bottom-color: rgba(255, 255, 255, 0.2); }
}

@keyframes textFadeIn { to { opacity: 0.5; } }
/* --- 3. LIGHTING CONTROLLER --- */
.lighting-controller {
    transition: --light-r 0.8s ease, --light-g 0.8s ease, --light-b 0.8s ease;
}

@media (min-width: 769px) {
    body:hover {
        --light-r: var(--warm-r);
        --light-g: var(--warm-g);
        --light-b: var(--warm-b);
    }
}

@media (max-width: 768px) {
    .lighting-controller {
        animation: mobileLightBreath 6s infinite ease-in-out;
    }
    /* LTR Beam Move */
    html[dir="ltr"] .light-cone {
        animation: beamFloatLTR 8s infinite ease-in-out;
    }
    /* RTL Beam Move */
    html[dir="rtl"] .light-cone {
        animation: beamFloatRTL 8s infinite ease-in-out;
    }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    .lighting-controller { animation: none !important; }
    html[dir="ltr"] .light-cone,
    html[dir="rtl"] .light-cone { animation: none !important; }
}

@keyframes mobileLightBreath {
    0%, 100% { --light-r: var(--light-base-r); --light-g: var(--light-base-g); --light-b: var(--light-base-b); }
    50% { --light-r: var(--warm-r); --light-g: var(--warm-g); --light-b: var(--warm-b); }
}

/* FIXED: ANGLE OSCILLATION (Static Center, Moving Angle) */
@keyframes beamFloatLTR {
    0% { transform: translateY(-50%) perspective(200px) rotateY(3deg) rotateZ(-10deg); opacity: 0.8; }
    50% { transform: translateY(-50%) perspective(200px) rotateY(3deg) rotateZ(10deg); opacity: 1; }
    100% { transform: translateY(-50%) perspective(200px) rotateY(3deg) rotateZ(-10deg); opacity: 0.8; }
}

@keyframes beamFloatRTL {
    0% { transform: translateY(-50%) perspective(200px) rotateY(-3deg) rotateZ(10deg); opacity: 0.8; }
    50% { transform: translateY(-50%) perspective(200px) rotateY(-3deg) rotateZ(-10deg); opacity: 1; }
    100% { transform: translateY(-50%) perspective(200px) rotateY(-3deg) rotateZ(10deg); opacity: 0.8; }
}

.spotlight-wrapper {
    position: absolute; top: 0; left: 0; width: 100%; height: 100vh;
    pointer-events: none; z-index: 10; 
    mix-blend-mode: var(--beam-blend); 
}

.light-cone {
    position: absolute; top: 50%; width: 140vw; height: 400px;
    /* LTR Default */
    inset-inline-start: -10%; transform-origin: center left;
    
    background: linear-gradient(90deg, 
        rgba(var(--light-r), var(--light-g), var(--light-b), var(--beam-opacity)) 0%, 
        rgba(var(--light-r), var(--light-g), var(--light-b), 0.1) 60%, 
        transparent 100%);
    
    mask-image: linear-gradient(to right, black 0%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 0%, transparent 100%);
    filter: blur(60px);
    
    transform: translateY(-50%) perspective(200px) rotateY(3deg);
}

/* RTL Logic */
html[dir="rtl"] .light-cone {
    inset-inline-start: auto; inset-inline-end: -10%;
    transform-origin: center right;
    
    background: linear-gradient(-90deg, 
        rgba(var(--light-r), var(--light-g), var(--light-b), var(--beam-opacity)) 0%, 
        rgba(var(--light-r), var(--light-g), var(--light-b), 0.1) 60%, 
        transparent 100%);
        
    mask-image: linear-gradient(to left, black 0%, transparent 100%);
    -webkit-mask-image: linear-gradient(to left, black 0%, transparent 100%);
    
    transform: translateY(-50%) perspective(200px) rotateY(-3deg);
}

/* Particles */
.particle {
    position: absolute; background: var(--particle-color);
    border-radius: 50%; opacity: 0; pointer-events: none;
    animation: drift 15s infinite linear;
    box-shadow: 0 0 4px var(--particle-color);
}
@keyframes drift {
    0% { transform: translate(0,0); opacity: 0; }
    20% { opacity: 0.8; }
    80% { opacity: 0.8; }
    100% { transform: translate(100px, -50px); opacity: 0; }
}

/* --- 4. TYPOGRAPHY & LAYOUT --- */
* { font-style: normal !important; }

body {
    background-color: var(--bg-body);
    color: var(--text-main);
}

.hero-title {
    position: relative; z-index: 11;
    font-size: clamp(3rem, 10vw, 7rem); 
    letter-spacing: 0.05em; line-height: 1;
    text-transform: uppercase;
    color: var(--text-main);
    text-shadow: 0 10px 40px rgba(var(--light-r), var(--light-g), var(--light-b), 0.4);
}

html[lang="ar"] .hero-title { line-height: 1.3; letter-spacing: 0; }
html[lang="ar"] .intro-text { line-height: 2 !important; }

html[lang="en"] .brand-font { font-family: 'Cinzel', serif; }
html[lang="en"] body { font-family: 'Inter', sans-serif; }

html[lang="ar"] { font-size: 120%; }
html[lang="ar"] .brand-font { font-family: 'IBM Plex Sans Arabic', serif; font-weight: 700; }
html[lang="ar"] body { font-family: 'IBM Plex Sans Arabic', serif; font-weight: 400; font-size: 1em; }

/* Force 0 tracking for some Arabic tracking utility classes */
html[lang="ar"] .tracking-widest,
html[lang="ar"] .tracking-wider { letter-spacing: 0 !important; }

/* --- UI COMPONENTS --- */
.noise-overlay {
    position: fixed; inset: 0; z-index: 50;
    opacity: 0.04; pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* Arabic typography tweaks: reduce letter-spacing for specific label elements */
html[lang="ar"] .hero-subtitle,
html[lang="ar"] .signature-subtitle,
html[lang="ar"] .signature-text,
html[lang="ar"] [data-key="mat_label"],
html[lang="ar"] [data-key="hero_subtitle"],
html[lang="ar"] [data-key="signature_sub"],
html[lang="ar"] [data-key^="step_"],
html[lang="ar"] [data-key^="proj_"] ,
html[lang="ar"] [data-key="phil_cta"] {
    letter-spacing: 0.02em !important;
}

/* Payment card labels: more gap below icon on mobile */
@media (max-width: 768px) {
    .material-card span[data-key^="mat_"] {
        top: 74% !important; /* push label down for more spacing under icons */
    }
}

.nav-group {
    display: flex; align-items: center;
    border: 1px solid var(--border-dim);
    padding: 4px; gap: 2px;
    background: rgba(125,125,125,0.05);
    backdrop-filter: blur(5px);
    border-radius: 4px;
}

.nav-btn {
    cursor: pointer; font-size: 0.7rem; letter-spacing: 0.1em;
    color: var(--text-main); padding: 8px 12px;
    transition: all 0.3s ease; background: transparent; border: none;
    display: flex; align-items: center; justify-content: center;
    opacity: 0.8;
}
.nav-btn:hover { opacity: 1; background: var(--border-dim); }
.nav-divider { width: 1px; height: 16px; background: var(--border-dim); }

.menu-overlay {
    background-color: var(--bg-body);
    clip-path: polygon(0 0, 100% 0, 100% 0, 0 0);
    transition: clip-path 0.6s cubic-bezier(0.8, 0, 0.2, 1);
}
body.menu-active .menu-overlay { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }

.reveal-up { opacity: 0; transform: translateY(40px); transition: all 1s ease; }
.reveal-up.active { opacity: 1; transform: translateY(0); }

.project-card, .material-card { border-color: var(--border-dim); }
.project-card .project-img { transition: transform 0.7s ease; }
.project-card:hover .project-img { transform: scale(1.05); }
.project-overlay { background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); }
[data-theme="light"] .project-overlay { background: linear-gradient(to top, rgba(0,0,0,0.5), transparent); }

.signature-text {
    background: linear-gradient(to right, var(--accent-gold) 20%, var(--text-main) 50%, var(--accent-gold) 80%);
    background-size: 200% auto;
    background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    animation: shine 6s linear infinite;
}
@keyframes shine { 0% { background-position: 200% center; } 100% { background-position: -200% center; } }

/* Legacy Year Style */
.legacy-year {
    font-family: 'Cinzel', serif;
    color: var(--accent-gold);
    font-weight: 700;
    font-size: 1.1em;
}
