<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome - Education Department | District Kotli, AJ&K</title>
    <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700;800&family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <style>
        :root {
            --primary-dark: #0f172a; --primary-blue: #1e3c72; --primary-light: #2a5298;
            --gold: #d4af37; --gold-light: #e6c06b; --text-dark: #1e293b;
            --text-muted: #64748b; --text-light: #94a3b8; --white: #ffffff;
            --glass-bg: rgba(255, 255, 255, 0.92); --glass-border: rgba(212, 175, 55, 0.3);
            --shadow-lg: 0 25px 80px rgba(0, 0, 0, 0.45); --shadow-glow: 0 0 40px rgba(212, 175, 55, 0.25);
            --transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: 'Inter', sans-serif; color: var(--text-dark); min-height: 100vh; overflow-x: hidden; }
        body.no-scroll { overflow: hidden; }

        /* ========= SPLASH OVERLAY ========= */
        .splash-overlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999;
            display: flex; justify-content: center; align-items: center;
            background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-blue) 40%, var(--primary-light) 100%);
            transition: opacity 0.5s ease; will-change: opacity;
        }
        .splash-overlay.closing { opacity: 0; pointer-events: none; }

        /* ========= GLITTER & PARTICLES ========= */
        .glitter-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; background: repeating-radial-gradient(circle at 20% 30%, rgba(255,215,0,0.08) 0px, rgba(255,215,0,0.08) 2px, transparent 2px, transparent 8px); animation: glitterMove 12s linear infinite; }
        @keyframes glitterMove { 0% { background-position: 0 0; } 100% { background-position: 200px 200px; } }
        .sparkle { position: absolute; width: 3px; height: 3px; background: var(--gold); border-radius: 50%; box-shadow: 0 0 12px var(--gold); opacity: 0; animation: sparkleAnim 3s ease-in-out infinite; pointer-events: none; z-index: 6; }
        @keyframes sparkleAnim { 0%, 100% { opacity: 0; transform: scale(0); } 50% { opacity: 0.8; transform: scale(1); } }
        .splash-overlay::before, .splash-overlay::after { content: ''; position: absolute; width: 600px; height: 500px; border-radius: 50%; background: radial-gradient(circle, rgba(212, 175, 55, 0.15) 0%, transparent 70%); animation: float 20s infinite ease-in-out; z-index: 0; pointer-events: none; }
        .splash-overlay::before { top: -200px; left: -200px; }
        .splash-overlay::after { bottom: -200px; right: -200px; animation-delay: -10s; background: radial-gradient(circle, rgba(42, 82, 152, 0.2) 0%, transparent 70%); }
        @keyframes float { 0%, 100% { transform: translate(0,0) scale(1); } 25% { transform: translate(30px,30px) scale(1.05); } 50% { transform: translate(0,60px) scale(0.95); } 75% { transform: translate(-30px,30px) scale(1.02); } }
        .particles { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
        .particle { position: absolute; width: 4px; height: 4px; background: var(--gold); border-radius: 50%; opacity: 0.6; animation: rise 15s infinite ease-in-out; box-shadow: 0 0 10px var(--gold); }
        @keyframes rise { 0% { transform: translateY(100vh) scale(0); opacity: 0; } 10%, 90% { opacity: 0.8; } 100% { transform: translateY(-100px) scale(1); opacity: 0; } }

        /* ========= SPLASH CONTAINER (Compact Flex) ========= */
        .splash-container {
            background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
            border-radius: 22px; box-shadow: var(--shadow-lg), var(--shadow-glow);
            padding: 35px 35px; max-width: 650px; width: 92%;
            animation: fadeInUp 1s ease-out; border: 1px solid var(--glass-border);
            position: relative; z-index: 10; overflow: hidden;
            display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
        }
        .splash-container::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, transparent, var(--gold), var(--gold-light), var(--gold), transparent); animation: shimmer 2.5s infinite linear; }
        @keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
        @keyframes fadeInUp { from { opacity: 0; transform: translateY(30px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

        /* Close Button */
        .close-btn { position: absolute; top: 15px; right: 15px; width: 36px; height: 36px; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: var(--transition); z-index: 20; border: 1px solid var(--gold); color: var(--gold); font-size: 18px; font-weight: bold; }
        .close-btn:hover { background: var(--gold); color: var(--primary-dark); transform: scale(1.1) rotate(90deg); }

        /* Ornaments */
        .ornament { position: absolute; width: 45px; height: 45px; opacity: 0.6; z-index: 1; }
        .ornament.top-left { top: 15px; left: 15px; border-top: 2px solid var(--gold); border-left: 2px solid var(--gold); border-radius: 6px 0 0 0; }
        .ornament.top-right { top: 15px; right: 15px; border-top: 2px solid var(--gold); border-right: 2px solid var(--gold); border-radius: 0 6px 0 0; }
        .ornament.bottom-left { bottom: 15px; left: 15px; border-bottom: 2px solid var(--gold); border-left: 2px solid var(--gold); border-radius: 0 0 0 6px; }
        .ornament.bottom-right { bottom: 15px; right: 15px; border-bottom: 2px solid var(--gold); border-right: 2px solid var(--gold); border-radius: 0 0 6px 0; }

        /* ✨ CENTERED WELCOME TEXT ✨ */
        .welcome-text {
            font-family: 'Playfair Display', serif; font-size: 44px; font-weight: 800;
            background: linear-gradient(135deg, var(--gold) 0%, #fff4c2 40%, var(--gold-light) 100%);
            -webkit-background-clip: text; background-clip: text; color: transparent;
            text-shadow: 0 0 12px rgba(212, 175, 55, 0.5); letter-spacing: 1px;
            position: relative; display: inline-block; margin: 0 auto;
            animation: gentleGlow 2.5s ease-in-out infinite alternate;
            overflow: hidden; white-space: nowrap; border-right: 3px solid var(--gold);
            max-width: 0; animation: typingCenter 3s steps(28, end) forwards, blink 0.75s step-end infinite;
        }
        .welcome-text.typed { max-width: 100%; border-right: none; }
        @keyframes typingCenter { from { max-width: 0; } to { max-width: 100%; } }
        @keyframes blink { 50% { border-color: transparent; } }
        @keyframes gentleGlow { from { text-shadow: 0 0 4px rgba(212, 175, 55, 0.3); } to { text-shadow: 0 0 18px rgba(212, 175, 55, 0.8); } }

        /* 🔍 CLICKABLE EMBLEM WITH POPUP ========= */
        .emblem {
            width: 90px; height: 90px; background: linear-gradient(135deg, var(--primary-blue), var(--primary-light));
            border-radius: 50%; display: flex; align-items: center; justify-content: center;
            color: white; font-size: 36px; box-shadow: 0 10px 30px rgba(30, 60, 114, 0.5), 0 0 0 4px rgba(212, 175, 55, 0.4);
            animation: pulse 2.5s infinite ease-in-out; position: relative; overflow: hidden;
            transition: var(--transition); flex-shrink: 0; cursor: pointer; border: 3px solid rgba(255,255,255,0.9);
            -webkit-tap-highlight-color: transparent; user-select: none;
        }
        .emblem:hover { transform: scale(1.08) rotate(2deg); box-shadow: 0 15px 40px rgba(30, 60, 114, 0.7), 0 0 0 5px rgba(212, 175, 55, 0.6); }
        .emblem::after { content: '🔍'; position: absolute; bottom: -2px; right: 6px; background: var(--gold); width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--primary-dark); box-shadow: 0 2px 8px rgba(0,0,0,0.3); opacity: 0; transition: var(--transition); }
        .emblem:hover::after { opacity: 1; bottom: 0; }
        @keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
        .emblem-image { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; object-position: center; border: 2px solid rgba(255, 255, 255, 0.9); transition: var(--transition); pointer-events: none; }
        .emblem:hover .emblem-image { transform: scale(1.06); }

        .text-content { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
        .honoree-name {
            font-family: 'Playfair Display', serif; font-size: 30px; font-weight: 800; color: var(--text-dark);
            background: linear-gradient(135deg, var(--primary-blue), var(--primary-light), var(--gold-light));
            -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
            text-shadow: 0 2px 8px rgba(0,0,0,0.08); line-height: 1.2; text-align: center;
            overflow: hidden; border-right: 3px solid var(--gold-light); white-space: nowrap;
            animation: typingName 3.5s steps(30, end) forwards, blink 0.75s step-end infinite;
        }
        .honoree-name.typed { width: 100%; border-right: none; animation: textGlow 3s ease-in-out infinite alternate; }
        @keyframes typingName { from { width: 0; } to { width: 100%; } }
        @keyframes textGlow { from { text-shadow: 0 2px 8px rgba(0,0,0,0.08); } to { text-shadow: 0 4px 16px rgba(212, 175, 55, 0.3); } }

        .designation {
            color: var(--primary-light); font-size: 16px; font-weight: 600; line-height: 1.4;
            position: relative; padding-bottom: 4px; text-align: center;
            overflow: hidden; border-right: 2px solid var(--gold); white-space: nowrap;
            animation: typingDesignation 2.8s steps(35, end) forwards, blink 0.75s step-end infinite; min-width: 0;
        }
        .designation.typed { width: 100%; border-right: none; }
        .designation::after { content: ''; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 80px; height: 2px; background: linear-gradient(90deg, transparent, var(--gold), transparent); border-radius: 2px; }
        @keyframes typingDesignation { from { width: 0; } to { width: 100%; } }

        /* Visit Info */
        .visit-info {
            color: var(--text-dark); font-size: 14px; font-weight: 500; line-height: 1.5; padding: 14px 18px;
            background: linear-gradient(135deg, rgba(212, 175, 55, 0.1), rgba(30, 60, 114, 0.06));
            border-radius: 14px; border-left: 3px solid var(--gold); border-right: 3px solid var(--gold);
            box-shadow: inset 0 1px 3px rgba(0,0,0,0.04); transition: var(--transition);
            position: relative; overflow: hidden; width: 100%; max-width: 420px;
            display: flex; flex-direction: column; align-items: center; justify-content: center;
            text-align: center; gap: 4px;
        }
        .visit-info::before { content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent); transition: left 0.6s ease; }
        .visit-info:hover::before { left: 100%; }
        .visit-info:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.1); }
        .visit-info-icon { color: var(--gold); font-size: 16px; animation: bounce 2s infinite; margin-bottom: 2px; }
        @keyframes bounce { 0%, 20%, 50%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-4px); } 60% { transform: translateY(-2px); } }
        .visit-info-text { overflow: hidden; border-right: 2px solid var(--gold); white-space: nowrap; animation: typingVisit 3s steps(38, end) forwards, blink 0.75s step-end infinite; min-width: 0; }
        .visit-info-text.typed { border-right: none; }
        @keyframes typingVisit { from { width: 0; } to { width: 100%; } }
        .visit-subtext { font-size: 12px; color: var(--text-muted); font-weight: 400; overflow: hidden; border-right: 2px solid var(--gold); white-space: nowrap; animation: typingSub 2.5s steps(30, end) forwards, blink 0.75s step-end infinite; min-width: 0; margin-top: 2px; }
        .visit-subtext.typed { border-right: none; }
        @keyframes typingSub { from { width: 0; } to { width: 100%; } }

        .divider { width: 60px; height: 2px; background: linear-gradient(90deg, transparent, var(--gold), var(--gold-light), var(--gold), transparent); border-radius: 3px; position: relative; overflow: hidden; flex-shrink: 0; margin: 12px 0; }
        .divider::after { content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent); animation: dividerShine 2s infinite; }
        @keyframes dividerShine { 100% { left: 100%; } }

        .footer-text { color: var(--text-light); font-size: 11px; font-weight: 400; opacity: 0.9; transition: opacity 0.3s; text-align: center; margin-top: auto; padding-top: 10px; flex-shrink: 0; overflow: hidden; border-right: 2px solid var(--text-light); white-space: nowrap; animation: typingFooter 2.2s steps(35, end) forwards, blink 0.75s step-end infinite; min-width: 0; }
        .footer-text.typed { border-right: none; }
        @keyframes typingFooter { from { width: 0; } to { width: 100%; } }

        /* 🖼️ MODAL POPUP ========= */
        .modal { display: none; position: fixed; z-index: 10000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(15, 23, 42, 0.95); backdrop-filter: blur(14px); justify-content: center; align-items: center; animation: modalFadeIn 0.3s ease-out; touch-action: none; }
        .modal.active { display: flex; }
        @keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
        .modal-content { position: relative; max-width: 90%; max-height: 90%; animation: modalZoom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); transition: transform 0.2s ease; }
        @keyframes modalZoom { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
        .modal-image { max-width: 100%; max-height: 85vh; border-radius: 20px; box-shadow: 0 25px 80px rgba(0,0,0,0.7), 0 0 60px rgba(212, 175, 55, 0.4); border: 4px solid var(--gold); cursor: zoom-out; transition: var(--transition); }
        .modal-image:hover { transform: scale(1.02); }
        .modal-close { position: absolute; top: -50px; right: 0; color: var(--white); font-size: 36px; cursor: pointer; transition: var(--transition); background: linear-gradient(135deg, var(--primary-blue), var(--primary-light)); width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 3px solid var(--gold); box-shadow: 0 5px 20px rgba(0,0,0,0.4), 0 0 25px rgba(212, 175, 55, 0.3); }
        .modal-close:hover { color: var(--gold-light); background: var(--gold); transform: rotate(90deg) scale(1.15); box-shadow: 0 8px 30px rgba(0,0,0,0.5), 0 0 40px rgba(212, 175, 55, 0.6); }
        .modal-caption { text-align: center; color: var(--gold-light); font-family: 'Playfair Display', serif; font-size: 16px; margin-top: 15px; font-style: italic; overflow: hidden; border-right: 2px solid var(--gold-light); white-space: nowrap; animation: typingCaption 2.5s steps(35, end) forwards, blink 0.75s step-end infinite; min-width: 0; }
        .modal-caption.typed { border-right: none; }
        @keyframes typingCaption { from { width: 0; } to { width: 100%; } }

        /* Responsive & Accessibility */
        @media (max-width: 768px) {
            .splash-container { padding: 30px 25px; gap: 8px; }
            .welcome-text { font-size: 26px; }
            .honoree-name { font-size: 26px; }
            .designation { font-size: 14px; }
            .emblem { width: 80px; height: 80px; font-size: 32px; }
            .visit-info { padding: 12px 16px; font-size: 13px; }
            .modal-close { top: -45px; font-size: 32px; width: 44px; height: 44px; }
        }
        @media (max-width: 480px) {
            .splash-container { padding: 25px 20px; gap: 6px; border-radius: 18px; }
            .welcome-text { font-size: 22px; }
            .honoree-name { font-size: 22px; }
            .emblem { width: 70px; height: 70px; font-size: 28px; }
            .close-btn { width: 32px; height: 32px; font-size: 16px; top: 10px; right: 10px; }
            .modal-close { top: -40px; font-size: 28px; width: 40px; height: 40px; }
        }
        @media (prefers-reduced-motion: reduce) {
            *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
            .welcome-text, .honoree-name, .designation, .visit-info-text, .visit-subtext, .footer-text, .modal-caption { animation: none !important; max-width: 100% !important; width: 100% !important; border-right: none !important; }
        }
    </style>
</head>
<body class="no-scroll">

    <!-- ================= SPLASH OVERLAY ================= -->
    <div id="splashOverlay" class="splash-overlay">
        <div class="glitter-overlay"></div>
        <div class="particles" id="particles"></div>
        
        <div class="splash-container" id="splashContainer">
            <div class="close-btn" id="closeBtn" title="Close">✕</div>
            <div class="ornament top-left"></div><div class="ornament top-right"></div>
            <div class="ornament bottom-left"></div><div class="ornament bottom-right"></div>
            
            <!-- ✨ Centered Welcome Text ✨ -->
            <p class="welcome-text" id="welcomeText">✨ We Warmly Welcome ✨</p>

            <!-- 🔍 Clickable Emblem -->
            <div class="emblem" id="emblemTrigger" title="Click to view full emblem">
                <img src="images/dpi.jpeg" alt="DPI Emblem" class="emblem-image" onerror="this.parentElement.innerHTML='<i class=\'fas fa-graduation-cap\'></i>'">
            </div> 
            
            <div class="text-content">
                <h1 class="honoree-name" id="honoreeName">Mr. Muhammad Shafique Khan</h1>
                <div class="designation" id="designation">Director Public Instructions (E&S Education, AJ&K)</div>
            </div>
            
            <div class="visit-info">
                <i class="fas fa-map-marker-alt visit-info-icon"></i>
                <span class="visit-info-text" id="visitText">On his visit to District Kotli, AJ&K</span>
                <span class="visit-subtext" id="visitSubtext">Following his appointment as DPI</span>
            </div>
            
            <div class="divider"></div>
            <p class="footer-text" id="footerText">© 2026 E&S Education Department, District Kotli, AJ&K</p>
        </div>
    </div>

    <!-- 🖼️ EMBLEM POPUP MODAL -->
    <div id="emblemModal" class="modal">
        <div class="modal-content" id="modalContent">
            <span class="modal-close" id="modalClose" title="Close">&times;</span>
            <img class="modal-image" id="modalImage" src="images/dpi.jpeg" alt="DPI Emblem - Full View">
            <div class="modal-caption" id="modalCaption">Director Public Instructions • E&S Education, AJ&K</div>
        </div>
    </div>

    <script>
        // ===== TYPING ENGINE =====
        class Typewriter {
            constructor(element, options = {}) {
                this.el = element; this.text = element.textContent || '';
                this.speed = options.speed || 50; this.delay = options.delay || 0;
                this.cursor = options.cursor !== false; this.index = 0; this.element = null;
            }
            init() {
                this.el.dataset.original = this.text; this.el.textContent = '';
                this.element = document.createElement('span'); this.el.appendChild(this.element);
                if (this.cursor && !this.el.classList.contains('welcome-text')) {
                    this.cursorEl = document.createElement('span');
                    this.cursorEl.style.borderRight = '2px solid var(--gold)';
                    this.cursorEl.style.animation = 'blink 0.75s step-end infinite';
                    this.el.appendChild(this.cursorEl);
                }
                setTimeout(() => this.type(), this.delay); return this;
            }
            type() {
                if (this.index < this.text.length) {
                    this.element.textContent += this.text.charAt(this.index); this.index++;
                    setTimeout(() => this.type(), this.speed);
                } else {
                    if (this.cursorEl) this.cursorEl.remove(); this.el.classList.add('typed');
                }
            }
        }

        // ===== PARTICLES =====
        function createParticles() {
            const c = document.getElementById('particles');
            for (let i = 0; i < 25; i++) {
                const p = document.createElement('div'); p.className = 'particle';
                const s = Math.random() * 4 + 2;
                p.style.cssText = `width:${s}px;height:${s}px;left:${Math.random()*100}%;animation-delay:${Math.random()*15}s;animation-duration:${Math.random()*12+8}s;opacity:${Math.random()*0.5+0.3};`;
                c.appendChild(p);
            }
        }
        function createSparkles() {
            const b = document.body;
            for (let i = 0; i < 40; i++) {
                const s = document.createElement('div'); s.className = 'sparkle';
                const sz = Math.random() * 3 + 1;
                s.style.cssText = `width:${sz}px;height:${sz}px;left:${Math.random()*100}%;top:${Math.random()*100}%;animation-delay:${Math.random()*5}s;animation-duration:${Math.random()*3+2}s;`;
                b.appendChild(s);
            }
        }

        // ===== CLOSE SPLASH (Simply hides it) =====
        document.getElementById('closeBtn').addEventListener('click', function() {
            const overlay = document.getElementById('splashOverlay');
            overlay.classList.add('closing');
            setTimeout(() => {
                overlay.style.display = 'none';
                document.body.classList.remove('no-scroll');
            }, 500);
        });

        // ===== MODAL POPUP LOGIC =====
        const emblemTrigger = document.getElementById('emblemTrigger');
        const modal = document.getElementById('emblemModal');
        const modalClose = document.getElementById('modalClose');
        const modalImage = document.getElementById('modalImage');
        const modalContent = document.getElementById('modalContent');
        const modalCaption = document.getElementById('modalCaption');

        function openModal(src) {
            modalImage.src = src || 'images/dpi.jpeg';
            modal.classList.add('active');
            document.body.style.overflow = 'hidden';
            // Reset & retrigger caption typing
            modalCaption.classList.remove('typed');
            modalCaption.textContent = modalCaption.dataset.original || modalCaption.textContent;
            setTimeout(() => new Typewriter(modalCaption, { speed: 35 }).init(), 400);
        }
        function closeModal() {
            modal.classList.remove('active');
            document.body.style.overflow = '';
            modalContent.style.transform = 'translateY(0)';
        }

        emblemTrigger?.addEventListener('click', (e) => {
            e.stopPropagation();
            const img = emblemTrigger.querySelector('.emblem-image');
            let src = img ? img.src : null;
            if (!src || src.includes('fa-graduation-cap')) {
                src = 'image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><rect fill="%231e3c72" width="200" height="200"/><text x="100" y="120" font-family="Arial" font-size="80" fill="%23d4af37" text-anchor="middle" dominant-baseline="middle">🎓</text></svg>';
            }
            openModal(src);
        });

        modalClose?.addEventListener('click', (e) => { e.stopPropagation(); closeModal(); });
        modal?.addEventListener('click', (e) => { if (e.target === modal) closeModal(); });
        
        // Touch swipe to close modal
        let touchStartY = 0;
        modal?.addEventListener('touchstart', (e) => { touchStartY = e.touches[0].clientY; modalContent.style.transition = 'none'; }, { passive: true });
        modal?.addEventListener('touchmove', (e) => { const dy = e.touches[0].clientY - touchStartY; if (dy > 0) modalContent.style.transform = `translateY(${dy * 0.4}px)`; }, { passive: true });
        modal?.addEventListener('touchend', (e) => { const dy = e.changedTouches[0].clientY - touchStartY; modalContent.style.transition = 'transform 0.3s ease'; if (dy > 80) closeModal(); else modalContent.style.transform = 'translateY(0)'; }, { passive: true });

        // ===== INIT =====
        document.addEventListener('DOMContentLoaded', () => {
            const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
            if (!reduced) {
                createParticles(); createSparkles();
                const seq = [
                    { el: document.getElementById('welcomeText'), speed: 55, delay: 600 },
                    { el: document.getElementById('honoreeName'), speed: 45, delay: 2400 },
                    { el: document.getElementById('designation'), speed: 40, delay: 4000 },
                    { el: document.getElementById('visitText'), speed: 35, delay: 5500 },
                    { el: document.getElementById('visitSubtext'), speed: 30, delay: 6800, cursor: false },
                    { el: document.getElementById('footerText'), speed: 35, delay: 8200, cursor: false }
                ];
                seq.forEach(({ el, speed, delay, cursor = true }) => {
                    if (el) setTimeout(() => new Typewriter(el, { speed, delay: 0, cursor }).init(), delay);
                });
            } else {
                document.querySelectorAll('.welcome-text, .honoree-name, .designation, .visit-info-text, .visit-subtext, .footer-text, .modal-caption').forEach(el => el.classList.add('typed'));
            }

            // Escape key closes modal or splash
            document.addEventListener('keydown', e => {
                if (e.key === 'Escape') {
                    if (modal.classList.contains('active')) closeModal();
                    else if (document.getElementById('splashOverlay').style.display !== 'none') {
                        document.getElementById('closeBtn').click();
                    }
                }
            });
        });

        // Fallback images
        document.querySelector('.emblem-image')?.addEventListener('error', function() { this.parentElement.innerHTML = '<i class="fas fa-graduation-cap" style="font-size: 40px; color: white;"></i>'; });
        modalImage?.addEventListener('error', function() { this.src = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><rect fill="%231e3c72" width="200" height="200"/><text x="100" y="120" font-family="Arial" font-size="80" fill="%23d4af37" text-anchor="middle" dominant-baseline="middle">🎓</text></svg>'; });
    </script>
</body>
</html>