/* --- 1. GLOBAL PLATFORM VARIABLE CONFIGURATIONS & THEMES --- */
:root {
    --bg-primary: #121214;
    --bg-surface: #1a1a1e;
    --text-main: #e1e1e6;
    --accent: #6200ee;
    --accent-hover: #7f39fb;
    --border: #29292e;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-main);
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%; /* Prevents iOS font size adjustments on orientation changes */
}

#app-root {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 100;
}

.header-container, .footer-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem; /* Reduced from 2rem to prevent container pinching on smaller screens */
}

.app-logo {
    font-size: 1.35rem; /* Marginally scaled down for tight horizontal viewports */
    font-weight: 800;
    text-decoration: none;
    color: var(--text-main);
    white-space: nowrap;
}

.logo-accent { color: var(--accent); }

/* --- MOBILE FIRST RESPONSIVE NAVIGATION CONTROL --- */
.nav-toggle-btn {
    display: block;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.75rem; /* Enhanced touch target size */
    cursor: pointer;
    padding: 0.5rem; /* Larger hit target area for thumbs */
}

.main-nav-links {
    display: none; /* Collapsed under mobile burger menu constraints by default */
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.6);
}

.main-nav-links.open {
    display: flex;
}

.nav-item {
    color: var(--text-main);
    text-decoration: none;
    margin: 0.25rem 1rem;
    padding: 0.85rem 1rem; /* Slightly taller vertical touch targets */
    border-radius: 6px;
    transition: background 0.2s;
    text-align: center;
    font-size: 1.05rem;
}

.nav-item:hover { background-color: var(--border); }
.nav-item.active { background-color: var(--accent); }

.nav-btn-logout { 
    background: none; 
    border: none; 
    color: #ff5555; 
    cursor: pointer; 
    font-size: 1.05rem; 
    margin: 0.25rem 1rem;
    padding: 0.85rem 1rem;
    text-align: center;
}

.app-content-view {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 1rem; /* Scaled down slightly to maximize screen utility area */
    box-sizing: border-box;
}

.app-footer {
    text-align: center;
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    background-color: var(--bg-surface);
    padding: 1.25rem 1rem;
}

/* --- 2. TRANSIT SPINNER UTILITIES --- */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.app-loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- 3. STUDIO COMPOSITION LAYOUT RULES --- */
.studio-workspace {
    display: flex;
    flex-direction: column; 
    gap: 1.25rem;
}

.capture-panel, .sidebar-history { 
    background: var(--bg-surface); 
    padding: 1.25rem; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
    box-sizing: border-box;
    width: 100%;
}

.video-container { 
    position: relative; 
    width: 100%; 
    max-width: 640px; 
    aspect-ratio: 4/3; 
    background: #000; 
    border-radius: 6px; 
    overflow: hidden; 
    margin: 0 auto; 
}
#webcam-preview { width: 100%; height: 100%; object-fit: cover; }
#active-overlay-preview { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; object-fit: contain; z-index: 10; }
.hidden-preview { display: none; }

.controls-row { 
    display: flex; 
    flex-direction: column; /* Stack primary execution buttons vertically on mobile components */
    gap: 0.75rem; 
    margin-top: 1.25rem; 
    margin-bottom: 1.5rem; 
}

.sticker-options { 
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(65px, 1fr)); /* Auto-wrap grid to maintain aspect layouts */
    gap: 0.75rem; 
    margin-top: 0.5rem; 
}
.sticker-item { 
    width: 100%; /* Scale inside its grid footprint fluidly */
    aspect-ratio: 1 / 1;
    height: auto;
    border: 2px solid var(--border); 
    border-radius: 6px; 
    padding: 4px; 
    background: #fff; 
    cursor: pointer; 
    transition: 0.15s; 
    box-sizing: border-box;
}
.sticker-item:hover { border-color: var(--accent-hover); transform: scale(1.03); }
.sticker-item.selected { border-color: var(--accent); background: #f0e6ff; box-shadow: 0 0 12px rgba(98, 0, 238, 0.4); }

.action-btn-primary { 
    background: var(--accent); 
    color: #fff; 
    border: none; 
    padding: 0.85rem 1.5rem; /* Deeper padding targets */
    border-radius: 6px; 
    font-weight: 600; 
    cursor: pointer; 
    width: 100%;
    font-size: 1rem;
}
.action-btn-primary:disabled { background: #444; color: #888; cursor: not-allowed; }
.action-btn-secondary { 
    background: transparent; 
    color: var(--text-main); 
    border: 1px solid var(--border); 
    padding: 0.85rem 1.5rem; 
    border-radius: 6px; 
    cursor: pointer; 
    width: 100%;
    font-size: 1rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    transition: background-color 0.2s, border-color 0.2s;
}

.action-btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--text-main);
}
.file-input-hidden { display: none; }

/* --- 4. PUBLIC GALLERY MATRIX --- */
.gallery-layout-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); /* Adjusted minimum width to beautifully accommodate interaction fields */
    gap: 1.6rem; 
    margin-top: 1.25rem; 
}

/* 🖼️ THE FIX: Force standard layout dimensions on your post containers */
.gallery-post-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.gallery-post-card img {
    width: 100%;
    aspect-ratio: 4 / 3;    /* 🌟 Preserves the native aspect ratio of your composited creations */
    object-fit: cover;      /* 🌟 Prevents horizontal squishing or stretching */
    background-color: #000;
}

.gallery-post-card .post-meta {
    padding: 0.85rem;
    font-size: 0.9rem;
    border-top: 1px solid var(--border);
    color: #a1a1aa;
    display: flex;          /* 🌟 Aligns publisher tag and interactive items cleanly */
    justify-content: space-between;
    align-items: center;
}

/* ❤️ SOCIAL INTERACTION STYLING EXTENSIONS */
.like-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #a1a1aa;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: transform 0.1s ease, color 0.2s ease;
}

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

.like-btn.active-like { 
    color: #ff3366; 
    font-weight: bold; 
    transform: scale(1.05); 
}

.comments-section {
    padding: 0.85rem;
    background: rgba(0, 0, 0, 0.15);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.comments-list {
    max-height: 120px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding-right: 4px;
}

/* Custom mini scrollbar for clean comment tracks */
.comments-list::-webkit-scrollbar {
    width: 4px;
}
.comments-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.comment-item {
    font-size: 0.85rem;
    line-height: 1.3;
    color: #e4e4e7;
}

.comment-item strong {
    color: #ffffff;
    margin-right: 0.25rem;
}

.comment-input-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.4rem;
}

.comment-box {
    flex: 1;
    background: var(--bg-primary, #18181b);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
    color: #fff;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.comment-box:focus {
    border-color: var(--accent, #3b82f6);
}

.send-comment-btn {
    background: var(--accent, #3b82f6);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0 0.85rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.send-comment-btn:hover {
    opacity: 0.9;
}

/* --- 5. SECURE ACCOUNT INTERFACE AND ALERTS --- */
.auth-form-card { 
    max-width: 420px; 
    margin: 1rem auto; 
    background: var(--bg-surface); 
    padding: 1.5rem 1.25rem; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
    box-sizing: border-box;
    width: 100%;
    text-align: center;
}

.auth-form-heading {
    margin-bottom: 0.5rem;
    text-align: center;
    font-size: 1.6rem;
}

.auth-form-subtitle {
    color: #88898e;
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 1.25rem;
}

.form-group label {
    text-align: left; /* Align fields intuitively */
    font-size: 0.85rem;
    color: #a1a1aa;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.auth-form-card input { 
    width: 100%; 
    padding: 0.85rem 0.75rem; /* Enhanced mobile element tapping buffer */
    background: var(--bg-primary); 
    border: 1px solid var(--border); 
    border-radius: 6px; 
    color: #fff; 
    box-sizing: border-box;
    font-size: 1rem; /* Prevents auto-zooming behaviors inside iOS Safari browsers */
    transition: border-color 0.15s;
}

.auth-form-card input:focus {
    outline: none;
    border-color: var(--accent);
}

.toggle-link {
    display: block;
    text-align: center;
    margin-top: 1.25rem;
    color: var(--accent-hover);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 0.5rem; /* Touch targets protection */
}

.toggle-link:hover { text-decoration: underline; }

.error-banner { 
    background-color: #ff333322; 
    border: 1px solid #ff3333aa; 
    color: #ff6666; 
    padding: 0.75rem; 
    border-radius: 6px; 
    margin-bottom: 1.25rem; 
    font-size: 0.9rem; 
    text-align: center; 
}

/* --- 6. HISTORY ASSETS INTERACTIVE CARDS --- */
.mini-post-card { 
    position: relative; 
    display: inline-block; 
    margin: 6px; 
    max-width: calc(50% - 12px); /* Fits comfortably in mobile feed streams without wrapping breaks */
}
.mini-post-card img {
    width: 100%;
    height: auto;
    border-radius: 4px;
}
.delete-post-btn { 
    position: absolute; 
    top: 4px; 
    right: 4px; 
    background: rgba(255,0,0,0.9); 
    color: white; 
    border: none; 
    border-radius: 50%; 
    cursor: pointer; 
    width: 28px; /* Standardize click target frame width */
    height: 28px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- 7. TABLET AND WIDESCREEN ENHANCEMENT MATRIX (Breakpoints > 768px) --- */
@media (min-width: 768px) {
    .header-container, .footer-container {
        padding: 1rem 2rem;
    }

    .app-logo {
        font-size: 1.5rem;
    }

    .nav-toggle-btn {
        display: none; /* Drop burger navigation on wide desktop screens */
    }

    .main-nav-links {
        display: flex; /* Keep layout persistent layout horizontal stream inline */
        flex-direction: row;
        position: static;
        width: auto;
        padding: 0;
        background: none;
        border: none;
        box-shadow: none;
    }

    .nav-item {
        margin-left: 1.5rem;
        margin-top: 0;
        margin-bottom: 0;
        padding: 0.5rem 1rem;
        font-size: 1rem;
    }

    .nav-btn-logout {
        margin-left: 1.5rem;
        margin-top: 0;
        margin-bottom: 0;
        padding: 0.5rem 1rem;
        font-size: 1rem;
    }

    .studio-workspace {
        flex-direction: row; /* Switch camera setup back to double panel rows */
    }

    .controls-row {
        flex-direction: row; /* Sideways distribution on horizontal monitors */
    }

    .gallery-layout-grid { 
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); /* Larger tiles on desktop screens */
        gap: 1.5rem; 
    }
    
    .auth-form-card {
        margin: 4rem auto;
        padding: 2.5rem;
    }

    .mini-post-card {
        max-width: none;
    }
}

/* --- 8. SMALL BREAKPOINT OPTIMIZATIONS (Micro screen-size bounds) --- */
@media (max-width: 380px) {
    .app-content-view {
        padding: 0.75rem 0.5rem;
    }

    .auth-form-card {
        padding: 1rem 0.75rem;
        border: none;
        background: transparent;
    }

    .header-container {
        padding: 0.75rem;
    }

    .gallery-layout-grid { 
        grid-template-columns: 1fr; /* Full width items on ultra narrow screens */
    }
}
