:root { --blue: #007aff; --red: #ff3b30; --bg: #0a0a0a; --yellow: #FFD60A; }

/* 1. BASE SETUP */
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); overflow-x: hidden; }

/* 2. WRAPPER - UPDATED FOR "TIGHT FIT" */
.s4a-wrapper { 
    display: flex; 
    flex-direction: column;
    align-items: center;    
    width: 100%; 
    height: auto;       /* Removes the forced huge vertical space */
    padding: 40px 20px; /* Clean spacing below the header */
    box-sizing: border-box; 
}

/* 3. APP BOX */
.s4a-app {
    position: relative; 
    width: 100%; 
    max-width: 1280px; 
    background: var(--bg); 
    border-radius: 24px; 
    overflow: hidden;
    border: 1px solid #222; 
    box-shadow: 0 40px 80px rgba(0,0,0,0.8);
    margin: 0 auto;
    
    /* DESKTOP DEFAULT: 16:9 Widescreen */
    aspect-ratio: 16/9; 
}

/* STAGE & BACKGROUND */
.s4a-stage { width: 100%; height: 100%; position: relative; background: var(--bg); }

.s4a-stage::before {
    content: ''; position: absolute; inset: 0;
    background-image: url('https://images.unsplash.com/photo-1600607687939-ce8a6c25118c?q=80&w=1200&auto=format&fit=crop');
    background-size: cover; background-position: center; 
    opacity: 0.6; transition: opacity 0.8s ease; z-index: 1;
}

.s4a-app.camera-active .s4a-stage::before { opacity: 0; }

#camRaw { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* 4. CANVAS SCALING */
#mainCanvas { 
    width: 100%; 
    height: 100%; 
    object-fit: contain; 
    display: block; 
    position: relative; 
    z-index: 5; 
}

/* OVERLAY */
.s4a-overlay { 
    position: absolute; inset: 0; background: rgba(0,0,0,0.6); 
    display: flex; justify-content: center; align-items: center; z-index: 100; 
    transition: opacity 0.5s ease, visibility 0.5s;
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
}
.s4a-app.camera-active .s4a-overlay { opacity: 0; visibility: hidden; pointer-events: none; }

/* BRANDING CARD */
.glass-card { 
    background: #0a0a0a; border: 1px solid #222; 
    padding: 40px 30px; border-radius: 28px; text-align: center; 
    width: 90%; max-width: 380px; box-shadow: 0 30px 60px rgba(0,0,0,0.9);
    box-sizing: border-box;
    display: flex; flex-direction: column; align-items: center;
}

/* LOGO FIX */
.s4a-logo {
    width: 100%;       
    max-width: 260px;   
    height: auto; 
    display: block; 
    margin-bottom: 15px;
}

.glass-card p { margin: 0 0 25px 0; color: var(--yellow); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.9; }

/* UI LAYERS */
.ui-layer { 
    position: absolute; inset: 0; pointer-events: none; 
    display: flex; flex-direction: column; justify-content: space-between; 
    padding: max(20px, env(safe-area-inset-top)) 20px max(30px, env(safe-area-inset-bottom)) 20px;
    opacity: 0; transition: opacity 0.5s ease 0.5s; z-index: 50;
}
.s4a-app.camera-active .ui-layer { opacity: 1; }

.ui-top { display: flex; justify-content: space-between; pointer-events: auto; }
.ui-bottom { display: flex; justify-content: center; pointer-events: auto; }

/* BUTTONS */
.btn-primary { 
    background: var(--blue); color: white; border: none; 
    padding: 16px 32px; border-radius: 99px; font-weight: 600; cursor: pointer; 
    font-size: 16px; transition: transform 0.1s; box-shadow: 0 5px 15px rgba(0,122,255,0.4);
    max-width: 100%;
}
.btn-primary:active { transform: scale(0.98); }
.full-width { width: 100%; margin-top: 10px; border-radius: 12px; }

.btn-glass { background: rgba(30,30,30,0.8); color: white; border: 1px solid rgba(255,255,255,0.15); padding: 8px 16px; border-radius: 20px; cursor: pointer; backdrop-filter: blur(10px); font-weight: 600; font-size: 13px; transition: background 0.2s; }
.btn-glass:hover { background: rgba(50,50,50,0.9); }
.btn-text { background: none; border: none; cursor: pointer; font-weight: bold; font-size: 16px; }
.text-red { color: var(--red); }

/* RECORD BUTTON */
.record-btn { width: 72px; height: 72px; border-radius: 50%; border: 4px solid white; background: transparent; display: flex; justify-content: center; align-items: center; cursor: pointer; }
.record-inner { width: 60px; height: 60px; background: var(--red); border-radius: 50%; transition: 0.3s cubic-bezier(0.25, 1, 0.5, 1); }
.record-btn.recording .record-inner { width: 30px; height: 30px; border-radius: 6px; }
.record-btn.recording { border-color: rgba(255,255,255,0.5); }

/* INDICATORS */
.rec-pill { background: rgba(255,0,0,0.2); border: 1px solid red; color: red; padding: 6px 12px; border-radius: 20px; font-weight: bold; display: none; align-items: center; gap: 6px; font-size: 12px; }
.red-dot { width: 8px; height: 8px; background: red; border-radius: 50%; animation: pulse 1s infinite; }
.audio-viz { position: absolute; bottom: 110px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; align-items: flex-end; height: 20px; }
.viz-bar { width: 6px; height: 100%; background: #34c759; border-radius: 3px; opacity: 0.3; transition: height 0.1s; }

/* MODALS */
.s4a-modal { 
    position: absolute; inset: 0; background: rgba(10,10,10,0.8); 
    z-index: 200; display: flex; justify-content: center; align-items: center; 
    backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px);
}
.modal-card { 
    background: #0a0a0a; padding: 30px; border-radius: 24px; width: 90%; max-width: 500px; 
    text-align: center; color: white; border: 1px solid #222; box-shadow: 0 40px 80px rgba(0,0,0,0.8);
}
.small-card { max-width: 320px; }
.modal-card h3 { margin: 0 0 20px 0; color: #fff; font-size: 20px; font-weight: 700; }
.modal-card label { display: block; text-align: left; font-size: 12px; color: #888; font-weight: 700; margin-bottom: 5px; text-transform: uppercase; }

/* INPUTS */
.s4a-input, .s4a-select { 
    width: 100%; padding: 14px; margin-bottom: 15px; background: #1a1a1a; 
    border: 1px solid #333; color: white; border-radius: 12px; box-sizing: border-box; font-size: 16px; 
}
.s4a-input:focus, .s4a-select:focus { border-color: var(--blue); outline: none; }
.video-wrap { width: 100%; background: transparent; border-radius: 12px; overflow: hidden; margin-bottom: 20px; }
.video-wrap video { width: 100%; max-height: 50vh; display: block; object-fit: contain; }
.btn-row { display: flex; justify-content: center; gap: 15px; }

@keyframes pulse { 50% { opacity: 0.5; } }

/* 5. MOBILE OVERRIDES */
@media (max-width: 768px) { 
    .s4a-wrapper { padding: 10px; }
    
    .s4a-app { 
        /* Vertical Portrait on phones */
        aspect-ratio: 9/16; 
        
        /* Minimum height so it never collapses */
        min-height: 550px; 
        
        /* Keep it within screen */
        max-height: 85vh; 
        border-radius: 20px;
    }

    .s4a-logo { max-width: 200px; }
    .glass-card { width: 85%; padding: 30px 20px; }
    .ui-layer { padding: 20px; }
}