/* CSS Reset and Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --cosmic-purple: #1a0a2e;
    --cosmic-deep: #0d0518;
    --nebula-pink: #ff6b9d;
    --nebula-cyan: #4ecdc4;
    --nebula-blue: #7b68ee;
    --star-white: #f0f0ff;
}

html, body {
    width: 100%;
    min-height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--cosmic-deep);
    color: var(--star-white);
}

body.in-demo {
    overflow: hidden;
}

/* ============================================
   MENU SCREEN
   ============================================ */

#menu-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 500;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 40px 0;
}

.menu-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, var(--cosmic-purple) 0%, var(--cosmic-deep) 100%);
    z-index: -1;
}

.menu-background::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,0.3), transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.2), transparent),
        radial-gradient(1px 1px at 90px 40px, rgba(255,255,255,0.4), transparent),
        radial-gradient(2px 2px at 130px 80px, rgba(255,255,255,0.2), transparent),
        radial-gradient(1px 1px at 160px 120px, rgba(255,255,255,0.3), transparent);
    background-repeat: repeat;
    background-size: 200px 150px;
    animation: twinkle 4s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.menu-content {
    text-align: center;
    padding: 40px;
    max-width: 800px;
}

.menu-title {
    font-size: 3.5rem;
    font-weight: 200;
    letter-spacing: 8px;
    text-transform: uppercase;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--nebula-cyan), var(--nebula-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 60px rgba(78, 205, 196, 0.3);
}

.menu-subtitle {
    font-size: 1rem;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: rgba(240, 240, 255, 0.5);
    margin-bottom: 15px;
}

.github-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: rgba(240, 240, 255, 0.5);
    text-decoration: none;
    font-size: 0.85rem;
    margin-bottom: 40px;
    transition: color 0.2s ease;
}

.github-link:hover {
    color: var(--nebula-cyan);
}

.github-link svg {
    opacity: 0.7;
}

.demo-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 30px;
    margin-bottom: 40px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.demo-card {
    flex: 0 1 280px;
    max-width: 320px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(78, 205, 196, 0.2);
    border-radius: 20px;
    padding: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.demo-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, transparent 0%, rgba(78, 205, 196, 0.1) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.demo-card:hover {
    transform: translateY(-5px);
    border-color: var(--nebula-cyan);
    box-shadow: 0 20px 40px rgba(78, 205, 196, 0.2),
                0 0 60px rgba(78, 205, 196, 0.1);
}

.demo-card:hover::before {
    opacity: 1;
}

.demo-card.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.demo-card.disabled .demo-card-controls {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(240, 240, 255, 0.5);
}

.demo-card-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    color: var(--nebula-cyan);
    transition: all 0.3s ease;
}

.demo-card:hover .demo-card-icon {
    color: var(--nebula-pink);
    transform: scale(1.1);
}

.demo-card-icon svg {
    width: 100%;
    height: 100%;
}

.prism-icon {
    animation: rotate-slow 20s linear infinite;
}

.airplane-icon {
    animation: float 3s ease-in-out infinite;
}

@keyframes rotate-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

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

.demo-card-title {
    font-size: 1.4rem;
    font-weight: 400;
    margin-bottom: 10px;
    color: var(--star-white);
}

.demo-card-desc {
    font-size: 0.9rem;
    color: rgba(240, 240, 255, 0.6);
    margin-bottom: 15px;
    line-height: 1.5;
}

.demo-card-controls {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--nebula-cyan);
    padding: 8px 16px;
    background: rgba(78, 205, 196, 0.1);
    border-radius: 20px;
    display: inline-block;
}

.menu-hint {
    font-size: 0.85rem;
    color: rgba(240, 240, 255, 0.4);
    letter-spacing: 2px;
}

/* ============================================
   DEMO CONTAINER
   ============================================ */

#demo-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#canvas-container {
    width: 100%;
    height: 100%;
}

#canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ============================================
   BACK BUTTON
   ============================================ */

#back-button {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 30px;
    color: var(--nebula-cyan);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

#back-button:hover {
    background: rgba(78, 205, 196, 0.2);
    border-color: var(--nebula-cyan);
    transform: translateX(-3px);
}

#back-button svg {
    transition: transform 0.3s ease;
}

#back-button:hover svg {
    transform: translateX(-3px);
}

/* ============================================
   WEBCAM & UI ELEMENTS
   ============================================ */

#webcam {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
}

#webcam-preview {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 160px;
    aspect-ratio: 4/3;
    border-radius: 12px;
    overflow: hidden;
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(78, 205, 196, 0.4);
    box-shadow: 0 0 20px rgba(78, 205, 196, 0.2),
                inset 0 0 20px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

#webcam-preview #preview-canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scaleX(-1);
}

#webcam-preview .preview-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--nebula-cyan);
    text-align: center;
}

#camera-toggle {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 6px;
    color: var(--nebula-cyan);
    cursor: pointer;
    transition: all 0.2s ease;
}

#camera-toggle:hover {
    background: rgba(78, 205, 196, 0.2);
    border-color: var(--nebula-cyan);
}

#camera-toggle.active {
    background: rgba(78, 205, 196, 0.3);
    color: var(--star-white);
}

/* Openness Indicator */
#openness-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.indicator-bar {
    width: 8px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.indicator-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0%;
    background: linear-gradient(to top, var(--nebula-cyan), var(--nebula-pink));
    border-radius: 4px;
    transition: height 0.1s ease-out;
    box-shadow: 0 0 10px var(--nebula-cyan);
}

.indicator-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(240, 240, 255, 0.5);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
}

/* Instructions */
#instructions {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 100;
    pointer-events: none;
    opacity: 0.8;
    transition: opacity 0.3s;
}

#instructions p,
#instructions-text {
    font-size: 16px;
    font-weight: 300;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--star-white);
    text-shadow: 0 0 20px rgba(78, 205, 196, 0.5);
}

#instructions p.sub,
#instructions-sub {
    font-size: 12px;
    margin-top: 8px;
    color: rgba(240, 240, 255, 0.5);
    letter-spacing: 2px;
}

/* ============================================
   LOADING OVERLAY
   ============================================ */

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, var(--cosmic-purple) 0%, var(--cosmic-deep) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader {
    text-align: center;
}

.loader-ring {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    border: 3px solid transparent;
    border-top-color: var(--nebula-cyan);
    border-right-color: var(--nebula-pink);
    border-radius: 50%;
    animation: spin 1.5s linear infinite;
    box-shadow: 0 0 30px rgba(78, 205, 196, 0.3),
                inset 0 0 30px rgba(255, 107, 157, 0.1);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader p {
    font-size: 14px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(240, 240, 255, 0.7);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.hidden {
    display: none !important;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .menu-title {
        font-size: 2rem;
        letter-spacing: 4px;
    }

    .menu-subtitle {
        font-size: 0.8rem;
        letter-spacing: 2px;
    }

    .demo-grid {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }

    .demo-card {
        flex: 0 1 auto;
        width: 100%;
        max-width: 320px;
        padding: 20px;
    }

    .demo-card-icon {
        width: 60px;
        height: 60px;
    }

    #webcam-preview {
        width: 120px;
        aspect-ratio: 4/3;
        bottom: 10px;
        left: 10px;
    }

    #openness-indicator {
        bottom: 10px;
        right: 10px;
    }

    .indicator-bar {
        height: 80px;
    }

    #instructions {
        top: 70px;
    }

    #instructions p,
    #instructions-text {
        font-size: 12px;
        letter-spacing: 2px;
    }

    #instructions p.sub,
    #instructions-sub {
        font-size: 10px;
    }

    #back-button {
        top: 15px;
        left: 15px;
        padding: 10px 16px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    #menu-screen {
        padding: 20px 0;
    }

    .menu-content {
        padding: 15px;
    }

    .menu-title {
        font-size: 1.5rem;
        letter-spacing: 2px;
    }

    #webcam-preview {
        width: 100px;
        aspect-ratio: 4/3;
    }

    .indicator-bar {
        height: 60px;
        width: 6px;
    }
}

/* ============================================
   CHESS DEMO UI
   ============================================ */

#chess-difficulty-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(26, 10, 46, 0.95) 0%, rgba(13, 5, 24, 0.98) 100%);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 20px;
    padding: 40px 50px;
    text-align: center;
    z-index: 1000;
    box-shadow: 
        0 0 40px rgba(78, 205, 196, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

#chess-difficulty-panel h2 {
    font-size: 2rem;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--nebula-cyan), var(--nebula-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#chess-difficulty-panel p {
    color: rgba(240, 240, 255, 0.7);
    margin-bottom: 30px;
    font-size: 0.95rem;
}

.difficulty-selector {
    margin-bottom: 30px;
}

.difficulty-selector label {
    display: block;
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: var(--star-white);
}

.difficulty-selector label span {
    color: var(--nebula-cyan);
    font-weight: bold;
    font-size: 1.3rem;
}

#difficulty-slider {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, var(--nebula-cyan), var(--nebula-pink));
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

#difficulty-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--star-white);
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 0 10px rgba(78, 205, 196, 0.5);
    transition: transform 0.2s;
}

#difficulty-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

#difficulty-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--star-white);
    border-radius: 50%;
    cursor: grab;
    border: none;
    box-shadow: 0 0 10px rgba(78, 205, 196, 0.5);
}

#start-chess-btn {
    padding: 14px 40px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--cosmic-deep);
    background: linear-gradient(135deg, var(--nebula-cyan), var(--nebula-blue));
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#start-chess-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(78, 205, 196, 0.5);
}

#chess-status {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(13, 5, 24, 0.9);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 25px;
    padding: 12px 30px;
    font-size: 1rem;
    color: var(--star-white);
    z-index: 100;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

#chess-status.game-over {
    background: linear-gradient(135deg, rgba(78, 205, 196, 0.3), rgba(255, 107, 157, 0.3));
    border-color: var(--nebula-pink);
    font-size: 1.2rem;
    font-weight: bold;
}

/* Mobile adjustments for chess */
@media (max-width: 768px) {
    #chess-difficulty-panel {
        padding: 30px;
        width: 90%;
        max-width: 350px;
    }

    #chess-difficulty-panel h2 {
        font-size: 1.5rem;
    }

    #chess-status {
        font-size: 0.9rem;
        padding: 10px 20px;
    }
}
