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

:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --secondary: #764ba2;
    --success: #48bb78;
    --warning: #ed8936;
    --danger: #f56565;
    --bg-dark: #1a1a2e;
    --bg-darker: #16213e;
    --text-light: #ffffff;
    --text-muted: #a0aec0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-darker) 100%);
    color: var(--text-light);
    min-height: 100vh;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

/* Screens */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.screen.active {
    display: flex;
}

/* Connection Screen */
#connection-screen .logo {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: float 3s ease-in-out infinite;
}

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

#connection-screen h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

#connection-screen .subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

#qr-container {
    background: white;
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

#qr-code {
    display: block;
    width: 180px;
    height: 180px;
}

.room-code-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1rem;
}

.room-code-display .label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.room-code-display .code {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 0.5rem;
    font-family: 'Courier New', monospace;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.instruction {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50px;
}

.status-indicator .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 2s ease-in-out infinite;
}

.status-indicator.connected .dot {
    background: var(--success);
    animation: none;
}

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

/* Buttons */
.primary-btn {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 1rem;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    background: transparent;
    color: var(--text-light);
    border: 2px solid var(--text-muted);
    padding: 0.75rem 2rem;
    font-size: 1rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Permission Screen */
#permission-screen .icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
}

#permission-screen h2 {
    margin-bottom: 1rem;
}

#permission-screen p {
    color: var(--text-muted);
    text-align: center;
    max-width: 300px;
    margin-bottom: 0.5rem;
}

#permission-screen .note {
    font-size: 0.85rem;
    margin-bottom: 2rem;
}

.error {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(245, 101, 101, 0.2);
    border-radius: 8px;
    text-align: center;
}

.error p {
    color: var(--danger);
    margin-bottom: 1rem;
}

/* Capture Screen */
#capture-screen {
    padding: 0;
    position: relative;
}

.video-container {
    position: relative;
    width: 100vw;
    height: 100vh;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
}

/* HUD */
.hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.hud-top {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    padding: 1rem;
    padding-top: max(env(safe-area-inset-top), 1rem);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.stat .value {
    font-size: 1.25rem;
    font-weight: 700;
}

.stat .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.stat .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.stat .dot.green { background: var(--success); }
.stat .dot.yellow { background: var(--warning); }
.stat .dot.red { background: var(--danger); }

.hud-bottom {
    position: absolute;
    bottom: 120px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
}

.gesture-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.6);
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    backdrop-filter: blur(10px);
}

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

.gesture-name {
    font-weight: 600;
}

/* Controls */
.controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
    padding-bottom: max(env(safe-area-inset-bottom), 1.5rem);
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    transition: all 0.2s;
}

.control-btn.active {
    background: var(--primary);
}

.control-btn.danger {
    background: var(--danger);
}

.control-btn:hover {
    transform: scale(1.1);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-darker);
    padding: 2rem;
    border-radius: 16px;
    width: 100%;
    max-width: 350px;
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    text-align: center;
}

.setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting label {
    font-size: 0.95rem;
}

.setting input[type="checkbox"] {
    width: 24px;
    height: 24px;
}

.setting input[type="range"] {
    width: 100px;
}

.connection-info {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.connection-info p {
    margin-bottom: 0.5rem;
}

.connection-info span {
    color: var(--text-light);
    font-family: monospace;
}

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

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

/* Utility */
.hidden {
    display: none !important;
}

/* Responsive */
@media (max-height: 600px) {
    #connection-screen .logo {
        font-size: 3rem;
    }
    
    #qr-code {
        width: 140px;
        height: 140px;
    }
    
    .room-code-display .code {
        font-size: 2rem;
    }
}
