@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Inter:wght@300;400;600;800&display=swap');

:root {
    --bg-dark: #0f0f13;
    --bg-panel: #1a1a20;
    --accent-primary: #8a2be2; /* Deep Purple */
    --accent-secondary: #b265f6;
    --text-main: #ffffff;
    --text-muted: #8f90a6;
    --border-color: #2d2d3a;
    --success: #00ff9d;
    --error: #ff4757;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: transparent;
    color: var(--text-main);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: scroll; /* Force scrollbar to prevent layout shift */
}

html {
    scrollbar-gutter: stable; /* Modern fix for layout shift */
}

#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-color: var(--bg-dark);
}

.app-container {
    max-width: 95vw;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.logo {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -1px;
}

nav span {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: 20px;
}

/* Hero Section */
.hero-section {
    text-align: center;
    margin-bottom: 20px;
    width: 100%;
}

h1 {
    font-size: 4rem;
    line-height: 0.9;
    margin: 0;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: -2px;
}

.highlight {
    color: var(--accent-primary);
}

.subtitle {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    margin-top: 10px;
    letter-spacing: 4px;
    font-size: 0.9rem;
}

/* Interface Layout */
.interface-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

/* Workspace (Video/Canvas) */
.workspace-frame {
    background: var(--bg-panel);
    padding: 10px;
    border: 1px solid var(--border-color);
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.workspace-frame::before {
    content: '';
    position: absolute;
    top: -1px; left: -1px;
    width: 20px; height: 20px;
    border-top: 2px solid var(--accent-primary);
    border-left: 2px solid var(--accent-primary);
    z-index: 10;
}

.workspace-frame::after {
    content: '';
    position: absolute;
    bottom: -1px; right: -1px;
    width: 20px; height: 20px;
    border-bottom: 2px solid var(--accent-primary);
    border-right: 2px solid var(--accent-primary);
    z-index: 10;
}

.workspace {
    position: relative;
    width: 100%;
    height: 50vh;
    background-color: #050505;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#canvas {
    position: relative;
    height: 100%;
    width: auto;
    aspect-ratio: 4/3;
    max-width: 100%;
    object-fit: contain;
    cursor: grab;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    touch-action: none; /* Critical for custom touch handling */
}

#canvas:active {
    cursor: grabbing;
}

/* Scan Line Animation - Removed */

/* Controls */
.control-panel {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: stretch;
    gap: 40px;
    width: 100%;
    flex-wrap: wrap;
}

.tech-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 15px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    width: 100%;
    text-align: center;
    display: block;
    box-sizing: border-box;
}

.tech-btn:hover:not(:disabled) {
    border-color: var(--accent-primary);
    background: rgba(138, 43, 226, 0.1);
    color: var(--accent-primary);
}

.tech-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.action-btn {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    font-weight: 700;
}

.action-btn:hover:not(:disabled) {
    background: var(--accent-secondary);
    color: white;
}

.primary-controls, .controls, .actions {
    flex: 1;
    min-width: 300px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.controls {
    background: var(--bg-panel);
    padding: 20px;
    border: 1px solid var(--border-color);
    justify-content: center;
}

.control-group {
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 15px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group .label {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0;
    min-width: 80px;
}

.btn-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

.icon-btn {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    flex: 1;
    height: 50px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.icon-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Analysis Layout */
.analysis-layout {
    display: flex;
    flex-direction: row;
    gap: 30px;
    align-items: flex-start;
    width: 100%;
    justify-content: center;
}

.left-column {
    flex: 1;
    min-width: 0; /* Prevent flex item from overflowing */
    max-width: 1000px;
    transition: all 0.3s ease;
    /* margin: 0 auto; Removed to prevent gap when right column is active */
}

.right-column {
    flex: 0 0 550px;
    width: 550px;
    min-width: 400px;
    display: none;
}

.right-column.active {
    display: block;
}

.metric-header {
    white-space: nowrap;
}

/* Results */
#result {
    margin-top: 0;
    background: linear-gradient(to right, var(--accent-primary) 4px, transparent 4px) no-repeat, var(--bg-panel);
    border: 1px solid var(--border-color);
    padding: 30px;
    position: relative;
    overflow-y: auto;
    max-height: 80vh;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--accent-primary);
    padding: 30px;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 0 50px rgba(138, 43, 226, 0.2);
    position: relative;
}

.modal-content h3 {
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-primary);
    margin-top: 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    font-size: 1.5rem;
}

.modal-content > p {
    font-family: 'JetBrains Mono', monospace;
    color: var(--error);
    font-weight: bold;
    margin-bottom: 20px;
}

.modal-body {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

.requirements {
    flex: 1;
}

.requirements ul {
    list-style: none;
    padding: 0;
}

.requirements li {
    margin-bottom: 10px;
    padding-left: 20px;
    position: relative;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.requirements li::before {
    content: '>';
    position: absolute;
    left: 0;
    color: var(--accent-primary);
}

.requirements strong {
    color: var(--text-main);
}

.reference-visual {
    flex: 0 0 150px;
    border: 1px solid var(--border-color);
    position: relative;
    background: #000;
}

.reference-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.8;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

@media (max-width: 600px) {
    .modal-body {
        flex-direction: column-reverse;
    }
    
    .reference-visual {
        height: 150px;
        flex: none;
    }
}

/* Responsive Layout */
@media (max-width: 1100px) {
    .analysis-layout {
        flex-direction: column;
    }
    
    .right-column {
        width: 100%;
        flex: none;
    }

    .left-column {
        width: 100%;
        max-width: 100%;
    }
}

/* Mobile Optimization */
@media (max-width: 768px) {
    .app-container {
        padding: 10px;
        max-width: 100vw;
        overflow-x: hidden; /* Prevent horizontal scroll */
    }

    .interface-container {
        width: 100%;
        align-items: center;
    }

    .workspace-frame {
        width: 100%;
        box-sizing: border-box;
    }

    h1 {
        font-size: 2.2rem;
        letter-spacing: -1px;
    }

    .subtitle {
        font-size: 0.7rem;
        letter-spacing: 2px;
    }

    /* Workspace adjustments */
    .workspace {
        height: 40vh;
        background-color: #000;
    }

    /* Controls flow */
    .control-panel {
        flex-direction: column;
        gap: 15px;
    }

    .primary-controls, .controls, .actions {
        min-width: 100%;
        max-width: 100%;
    }

    .tech-btn {
        padding: 12px;
        font-size: 0.85rem;
    }

    /* Guide Panel Mobile - Bottom Sheet Style */
    .guide-panel {
        width: auto;
        left: 10px;
        right: 10px;
        top: auto;
        bottom: 10px;
        padding: 15px;
        background: rgba(15, 15, 19, 0.98);
    }
    
    .guide-visual {
        aspect-ratio: 3/1; /* Shorter map to save vertical space */
    }

    /* Result Panel */
    #result {
        padding: 15px;
        max-height: none; /* Allow full scroll on mobile */
    }

    .result-header {
        flex-direction: row;
        align-items: center;
        margin-bottom: 20px;
    }

    #score {
        font-size: 2.5rem;
    }
    
    /* Hide background canvas on mobile to improve performance */
    #bg-canvas {
        display: none;
    }
    
    body {
        background-color: var(--bg-dark);
    }
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
}

h2 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.2rem;
    margin: 0;
    color: var(--success);
}

.score-display {
    text-align: right;
}

.score-display .label {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
}

#score {
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1;
}

.analysis-text .label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--accent-primary);
    display: block;
    margin-bottom: 10px;
}

.demographic-block {
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    padding: 12px 14px;
    margin-bottom: 18px;
}

.demographic-block .label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--accent-primary);
    display: block;
    margin-bottom: 6px;
}

.demographic-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    color: var(--text-main);
    font-weight: 700;
}

.demographic-breakdown {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Hide race readout visually while keeping markup and logic intact */
#raceBlock {
    display: none !important;
}

#comment {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    line-height: 1.6;
    margin: 0;
    color: var(--text-main);
}

.hidden {
    display: none;
}

/* Guide Panel */
.guide-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 280px;
    background: rgba(15, 15, 19, 0.95);
    border: 1px solid var(--accent-primary);
    padding: 20px;
    z-index: 100;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    pointer-events: none; /* Allow clicking through to canvas */
    transition: opacity 0.2s;
}

.guide-panel.hidden {
    opacity: 0;
    pointer-events: none;
}

.guide-panel h3 {
    margin: 0 0 10px 0;
    color: var(--accent-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

.guide-panel p {
    font-size: 0.85rem;
    color: var(--text-main);
    margin: 0 0 15px 0;
    line-height: 1.4;
}

.guide-visual {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.guide-map {
    width: 100%;
    height: 100%;
    background-image: url('../img/face.png');
    background-repeat: no-repeat;
    transition: background-position 0.2s ease-out, background-size 0.2s ease-out;
}

.guide-target {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background-color: var(--accent-primary);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-primary);
    z-index: 10;
}

/* Loading Dots Animation */
.loading-dots {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.loading-dots span {
    animation: dot-pulse 1.4s infinite ease-in-out both;
    font-size: 3rem; /* Match parent font size */
    line-height: 1;
    margin: 0 2px;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes dot-pulse {
    0%, 100% { 
        transform: scale(0.8);
        opacity: 0.5;
    }
    50% { 
        transform: scale(1.2);
        opacity: 1;
    }
}

.main-disclaimer {
    max-width: 900px;
    margin: 30px auto 10px;
    padding-top: 14px;
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.4;
    text-align: center;
    border-top: 1px solid var(--border-color);
}

/* Race Selection Modal Styles */
.race-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;
    height: 100%;
}

.race-option {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    background: transparent;
}

.race-option:hover {
    border-color: var(--accent-primary);
    background: rgba(138, 43, 226, 0.1);
}

.race-option input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    margin-right: 12px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    flex-shrink: 0;
}

.race-option input[type="radio"]:checked {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
}

.race-option input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
}

.race-option:has(input:checked) {
    border-color: var(--accent-primary);
    background: rgba(138, 43, 226, 0.15);
}

.race-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-main);
    letter-spacing: 0.5px;
    line-height: 1.3;
}

/* Responsive: stack on small screens */
@media (max-width: 500px) {
    .race-options {
        grid-template-columns: 1fr;
    }
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 20px;
    margin-top: 30px;
}

.feedback-link {
    color: var(--text-muted);
    text-decoration: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    transition: color 0.2s ease;
}

.feedback-link:hover {
    color: var(--accent-primary);
}

.kofi-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    transition: color 0.2s ease;
}

.kofi-link:hover {
    color: var(--accent-secondary);
}

.footer-divider {
    color: var(--text-muted);
    margin: 0 10px;
    font-size: 0.75rem;
}

/* Support prompt after results */
.support-prompt {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
}

.support-prompt span {
    color: var(--text-muted);
    margin-right: 8px;
}

.support-link {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.support-link:hover {
    color: var(--accent-secondary);
}
