:root {
    --bg-base: #0f172a;
    --bg-surface: #1e293b;
    --bg-overlay: rgba(30, 41, 59, 0.7);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 100%;
    max-width: 800px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
    overflow: hidden;
    position: relative;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(to right, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--text-primary);
}

/* Video Section */
.camera-section {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    position: relative;
    overflow: hidden;
}

.video-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

video {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror effect */
}

canvas {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 5;
    transform: scaleX(-1); /* Keep canvas mirrored to match video */
}

/* Overlays */
.loading-overlay, .error-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    backdrop-filter: blur(4px);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* Controls */
.controls-section {
    background: var(--bg-overlay);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 1.5rem;
    z-index: 10;
    position: relative;
}

.controls-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.glasses-carousel {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) rgba(255, 255, 255, 0.05);
}

.glasses-carousel::-webkit-scrollbar {
    height: 8px;
    display: block;
}

.glasses-carousel::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.glasses-carousel::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

.glass-item {
    min-width: 80px;
    width: 80px;
    max-width: 80px;
    height: 80px;
    background: var(--bg-surface);
    border: 2px solid transparent;
    border-radius: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    overflow: hidden;
}

.glass-item img {
    width: 80%;
    height: auto;
    object-fit: contain;
    transition: transform 0.3s;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.glass-item:hover {
    transform: translateY(-5px);
    background: rgba(59, 130, 246, 0.1);
}

.glass-item.active {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.15);
}

.glass-item.active img {
    transform: scale(1.1);
}

.glass-item.skeleton {
    animation: pulse 1.5s infinite;
}

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

.actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--text-primary);
    color: var(--bg-base);
}

.btn-primary:not(:disabled):hover {
    transform: scale(1.05);
    background: #e2e8f0;
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:not(:disabled):hover {
    background: rgba(255,255,255,0.1);
}

@media (min-width: 800px) {
    .app-container {
        height: 90vh;
        border-radius: 1.5rem;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    }
}


/* Navigation Arrows */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(15, 23, 42, 0.6);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    cursor: pointer;
    z-index: 20;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}
.nav-arrow:hover {
    background: var(--accent);
    border-color: var(--accent);
    transform: translateY(-50%) scale(1.1);
}
.nav-arrow.left { left: 1rem; }
.nav-arrow.right { right: 1rem; }

/* Fit Controls */
.fit-controls {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.slider-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.slider-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.slider-group input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

.slider-group input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.slider-group input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

