/* Scanlines & Noise */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9000;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.1) 50%, rgba(0, 0, 0, 0.1));
    background-size: 100% 4px;
    opacity: 0.05;
}

.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 8999;
    opacity: 0.03;
    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.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* Glitch Effect Utility */
@keyframes glitch-anim {
    0% {
        transform: translate(0);
    }

    20% {
        transform: translate(-2px, 2px);
    }

    40% {
        transform: translate(-2px, -2px);
    }

    60% {
        transform: translate(2px, 2px);
    }

    80% {
        transform: translate(2px, -2px);
    }

    100% {
        transform: translate(0);
    }
}

.glitch-hover:hover {
    animation: glitch-anim 0.3s cubic-bezier(.25, .46, .45, .94) both infinite;
    color: var(--accent);
    /* Glitch text shadow optimized for light theme */
    text-shadow: 2px 2px #ff0055, -2px -2px #00ccff;
}

:root {
    /* Default Dark Theme (Cyberpunk) */
    --bg: #050505;
    --fg: #e2e8f0;
    --accent: #00f3ff;
    --accent-glow: rgba(0, 243, 255, 0.4);
    --muted: #94a3b8;
    --glass: rgba(255, 255, 255, 0.05);
    --glassBorder: rgba(255, 255, 255, 0.1);
    --card-bg: rgba(0, 0, 0, 0.4);
    --nav-bg: rgba(0, 0, 0, 0.8);
    --timeline-line: linear-gradient(to bottom, #00f3ff, transparent);

    /* Text Shadow Variables for Gradients */
    --text-shadow-glow: 0 0 30px rgba(0, 243, 255, 0.3);
}

[data-theme="light"] {
    /* Light Theme (Tech Lab) */
    --bg: #f8fafc;
    --fg: #1e293b;
    --accent: #2563eb;
    --accent-glow: rgba(37, 99, 235, 0.4);
    --muted: #475569;
    --glass: rgba(255, 255, 255, 0.7);
    --glassBorder: rgba(0, 0, 0, 0.05);
    --card-bg: rgba(255, 255, 255, 0.6);
    --nav-bg: rgba(255, 255, 255, 0.85);
    --timeline-line: linear-gradient(to bottom, #2563eb, transparent);

    /* Text Shadow Override */
    --text-shadow-glow: none;
}

html {
    scroll-behavior: smooth;
    cursor: default;
    /* fluid base font-size for scalable/accessible typography */
    font-size: clamp(14px, 1.2vw + 10px, 18px);
}

body {
    background-color: var(--bg);
    color: var(--fg);
    font-family: 'Rajdhani', sans-serif;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.5s ease, color 0.5s ease;
}

/* Global Transition for Theme Switching */
*,
*::before,
*::after {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

/* Layout helpers */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.section {
    padding: clamp(1rem, 2vw, 3rem) 0;
}


/* Utility: Text Gradient */
.text-gradient {
    /* Adaptive gradient based on theme */
    background: linear-gradient(135deg, var(--fg) 0%, var(--accent) 50%, #06b6d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: var(--text-shadow-glow);
}

.muted-text {
    color: var(--muted);
}

.theme-card {
    background: var(--card-bg);
    border: 1px solid var(--glassBorder);
}

.theme-section {
    background: var(--glass);
    /* Or a slightly different transparent layer if desired */
}

/* 3D Container - touch-action none prevents scroll interference on mobile canvas */
#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    touch-action: none;
}


/* Glassmorphism */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glassBorder);
    border-radius: 12px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 1rem;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.glass-card:hover {
    border-color: var(--accent);
    box-shadow: 0 10px 30px -10px var(--accent-glow), inset 0 0 20px var(--glass);
    transform: translateY(-5px);
}

/* Buttons & Tags / UI Elements */
.tech-tag {
    font-size: 0.85rem;
    padding: 4px 12px;
    border-radius: 4px;
    background: rgba(var(--accent), 0.1);
    /* Needs reliable rgb values, falling back to simple opacity */
    background: var(--glass);
    color: var(--accent);
    border: 1px solid var(--accent);
    font-family: 'Orbitron', sans-serif;
}

.project-link {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: transform 120ms ease, background 120ms ease;
}

.btn-primary {
    background-color: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    transition: all 0.3s ease;
    box-shadow: 0 0 10px var(--accent-glow);
}

.btn-primary:hover {
    background-color: var(--accent);
    color: var(--bg);
    /* Invert text color on hover */
    box-shadow: 0 0 25px var(--accent);
    transform: translateY(-2px);
}

.btn-secondary {
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #ccc;
}

.btn-secondary:hover {
    border-color: #00f3ff;
    color: #00f3ff;
}

/* Timeline */
.timeline-line {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, var(--accent) 0%, rgba(0, 0, 0, 0) 100%);
}

/* Virtual Cursor */
/* Virtual Cursor (hidden on touch devices) */
/* Virtual Cursor */
#virtual-cursor {
    position: fixed;
    width: 20px;
    height: 20px;
    background-color: var(--accent);
    /* Use theme accent */
    border: 2px solid var(--fg);
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
    display: none;
    /* Hidden by default */
    box-shadow: 0 0 15px var(--accent);
    transition: background-color 0.2s, transform 0.12s;
}

/* Force visibility when active, even on mobile */
#virtual-cursor.active-cursor {
    display: block !important;
}

#virtual-cursor.clicking {
    background-color: #ff0055;
    transform: translate(-50%, -50%) scale(0.8);
}

/* OptiKey-style Dwell Indicator */
#dwell-indicator {
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: #00ff00;
    /* Green for go */
    display: none;
    animation: spin 1s linear forwards;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Hide virtual cursor for touch/poor-hover devices */
/* Virtual Cursor visibility managed by JS for gesture control */
/* Removed hover:none check to allow gesture cursor on mobile */

/* Instructions / Gesture modal */
#gesture-instructions {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid var(--accent);
    padding: 2rem;
    border-radius: 12px;
    z-index: 10000;
    display: none;
    text-align: center;
    width: min(92%, 720px);
}

.gesture-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
}

/* Make gesture modal less intrusive on small screens */
@media (max-width: 520px) {
    #gesture-instructions {
        padding: 1rem;
        width: min(96%, 360px);
    }

    .gesture-icon {
        font-size: 1.6rem;
    }
}

/* Debug Overlay */
#debug-overlay {
    position: fixed;
    left: 12px;
    bottom: 12px;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.7);
    color: var(--fg);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    max-width: 320px;
    display: none;
    /* Hidden by default, toggled via JS */
}

#debug-overlay b {
    color: var(--accent);
}

/* Hand Preview & Mirroring */
#hand-preview video,
#hand-preview canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Mirror video so it feels natural (like a mirror) */
#input_video {
    transform: scaleX(-1);
    -webkit-transform: scaleX(-1);
}

/* Mirror canvas so drawings match the mirrored video */
#hand-canvas {
    transform: scaleX(-1);
    -webkit-transform: scaleX(-1);
}

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

::-webkit-scrollbar-track {
    background: #050505;
}

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

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

/* Responsiveness */
/* Breakpoints */
@media (max-width: 1024px) {
    .container {
        padding: 0 1rem;
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: clamp(1.6rem, 6.5vw, 2.8rem);
    }

    #virtual-cursor {
        width: 16px;
        height: 16px;
    }

    .glass-card {
        border-radius: 10px;
        padding: 1rem;
        /* Slightly more padding for touch targets */
        margin-bottom: 1rem;
    }

    nav {
        padding: 0.75rem;
        background: var(--nav-bg);
        /* Ensure nav background is solid enough */
    }

    .project-link {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 520px) {
    h1 {
        font-size: clamp(1.4rem, 7.5vw, 2.2rem);
    }

    .tech-tag {
        font-size: 0.8rem;
        padding: 3px 8px;
    }

    .project-link {
        gap: 0.4rem;
        padding: 0.4rem 0.75rem;
    }

    #hand-scroll-ui {
        flex-direction: column;
        bottom: 1rem;
        right: 1rem;
        align-items: flex-end;
    }

    #hand-scroll-ui button {
        backdrop-filter: blur(8px);
        background: rgba(0, 0, 0, 0.6);
        /* Higher contrast for buttons on mobile */
    }

    /* Ensure no horizontal scroll */
    .container,
    section {
        overflow-x: hidden;
    }
}

@media (max-width: 420px) {

    /* #canvas-container { display: none; } - Enabled for mobile */
    .gesture-icon {
        font-size: 1.4rem;
    }

    .timeline-line {
        left: 8px;
    }
}

#mobile-menu {
    display: none;
}

#mobile-menu.open {
    display: block;
}

/* Accessibility: reduce motion */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}