:root {
    /* Light Mode (Default) */
    --bg: #F7F8FA;
    --surface: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.7);
    --border: rgba(0, 0, 0, 0.06);
    --text: #1A202C;
    --text-muted: #718096;
    --primary: #6366f1;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --accent-glow: rgba(99, 102, 241, 0.3);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 30px -10px rgba(0,0,0,0.1);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
    
    /* Inputs */
    --input-bg: #F0F2F5;
    --input-glass: rgba(240, 242, 245, 0.6);
}

body.dark {
    --bg: #0F1115;
    --surface: #1A1D24;
    --surface-glass: rgba(26, 29, 36, 0.7);
    --border: rgba(255, 255, 255, 0.08);
    --text: #F7FAFC;
    --text-muted: #A0AEC0;
    --primary: #818cf8;
    --primary-gradient: linear-gradient(135deg, #818cf8 0%, #c084fc 100%);
    --accent-glow: rgba(129, 140, 248, 0.25);
    --shadow-sm: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 20px 50px -20px rgba(0,0,0,0.5);
    
    --input-bg: #15181E;
    --input-glass: rgba(21, 24, 30, 0.6);
}

* {
    box-sizing: border-box;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Manrope', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* Glassmorphism Utilities */
.glass {
    background: var(--surface-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
}

.glass-panel {
    background: var(--surface-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border);
    box-shadow: -10px 0 40px rgba(0,0,0,0.05);
}

/* 1️⃣ TOP BAR (Floating) */
.top-bar {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    max-width: 1200px;
    height: 64px;
    border-radius: 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 50;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
}
.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--primary-gradient);
    display: grid;
    place-items: center;
    color: white;
    box-shadow: 0 0 15px var(--accent-glow);
}

/* Mode Switcher Pills */
.mode-switch {
    background: var(--input-bg);
    padding: 4px;
    border-radius: 20px;
    display: flex;
    gap: 4px;
}
.mode-pill {
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.3s ease;
}
.mode-pill.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.mode-pill.v3-active {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 2px 10px var(--accent-glow);
}

.top-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: all 0.2s;
}
.icon-btn:hover {
    background: var(--input-bg);
    color: var(--text);
}

/* Tabs */
.tabs-container {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 100px auto 2rem auto; /* More breathing room from top bar */
    max-width: 400px;
    background: var(--surface);
    padding: 6px;
    border-radius: 20px;
    border: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    text-align: center;
    padding: 10px 20px;
    border-radius: 16px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.tab-btn.active {
    background: var(--bg);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* 2️⃣ HERO PROMPT AREA */
.hero-section {
    padding: 0 1rem 2rem 1rem; /* Removed top padding, tabs provide margin */
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.prompt-container {
    width: 100%;
    max-width: 800px;
    position: relative;
    transition: transform 0.3s ease;
}
.prompt-container:focus-within {
    transform: scale(1.02);
}

.prompt-box {
    width: 100%;
    background: var(--surface-glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.prompt-input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 1.1rem;
    font-family: inherit;
    color: var(--text);
    resize: none;
    min-height: 40px; /* Reduced min-height */
    max-height: 300px;
    line-height: 1.6;
    overflow-y: auto;
}
.prompt-input::placeholder { color: var(--text-muted); opacity: 0.6; }

.prompt-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.magic-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}
.magic-toggle input { display: none; }
.magic-icon {
    width: 20px;
    height: 20px;
    transition: all 0.3s;
}
.magic-toggle input:checked + .magic-icon {
    color: var(--primary);
    filter: drop-shadow(0 0 5px var(--accent-glow));
}

.btn-generate {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px var(--accent-glow);
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-generate:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--accent-glow);
}
.btn-generate:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

/* Chips */
.suggestions {
    display: flex;
    gap: 8px;
    margin-top: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}
.chip {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}
.chip:hover {
    background: var(--input-bg);
    color: var(--text);
    border-color: var(--text-muted);
}

/* 3️⃣ CONTEXTUAL SETTINGS PANEL */
.settings-toggle-btn {
    position: fixed;
    right: 2rem;
    bottom: 2rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 40;
    transition: all 0.3s;
    color: var(--text);
}
.settings-toggle-btn:hover {
    transform: scale(1.1);
}

.settings-drawer {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    z-index: 100;
    padding: 2rem;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}
.settings-drawer.open { right: 0; }

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.drawer-title { font-size: 1.5rem; font-weight: 700; margin: 0; }

.setting-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.setting-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Aspect Ratio Visuals */
.ar-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.ar-card {
    background: var(--input-bg);
    border: 2px solid transparent;
    border-radius: 12px;
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s;
}
.ar-card:hover { background: var(--surface); border-color: var(--border); }
.ar-card.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}
.ar-shape {
    border: 2px solid currentColor;
    border-radius: 4px;
    opacity: 0.7;
}

/* Style Presets */
.style-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.style-card {
    height: 60px;
    border-radius: 12px;
    background: var(--input-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    overflow: hidden;
    position: relative;
}
.style-card:hover { border-color: var(--text-muted); }
.style-card.active {
    border-color: var(--primary);
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 4px 12px var(--accent-glow);
}

/* Sliders */
input[type=range] {
    width: 100%;
    height: 6px;
    background: var(--input-bg);
    border-radius: 3px;
    -webkit-appearance: none;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--surface);
    border: 2px solid var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* 4️⃣ GALLERY MASONRY */
.gallery-wrapper {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem 4rem 2rem;
}

.gallery-masonry {
    column-count: 5;
    column-gap: 1.5rem;
}
@media (max-width: 1400px) { .gallery-masonry { column-count: 4; } }
@media (max-width: 1000px) { .gallery-masonry { column-count: 3; } }
@media (max-width: 700px) { .gallery-masonry { column-count: 2; } }
@media (max-width: 500px) { .gallery-masonry { column-count: 1; } }

.gallery-item {
    break-inside: avoid;
    margin-bottom: 1.5rem;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: zoom-in;
    group: item;
}

.gallery-item.selected-card {
    border: 2px solid var(--primary);
    transform: scale(0.98);
}

.selection-checkbox {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.8);
    cursor: pointer;
    z-index: 20;
    transition: all 0.2s ease;
}

.selection-checkbox:hover {
    background: rgba(0, 0, 0, 0.6);
    transform: scale(1.1);
}

.selection-checkbox.selected {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--accent-glow);
}

.selection-checkbox.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    z-index: 2;
}

.gallery-img {
    width: 100%;
    display: block;
    background: #000;
}

.item-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 40%);
    opacity: 0;
    transition: opacity 0.3s;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 1.2rem;
}
.gallery-item:hover .item-overlay { opacity: 1; }

.item-actions {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 8px;
}

.action-chip {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.action-chip:hover { background: var(--primary); border-color: transparent; }

.item-prompt {
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* Loading State */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}
.spinner-ring {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Helpers */
.hidden { display: none !important; }
.overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 90;
    backdrop-filter: blur(2px);
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-box {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* Metadata Modal */
.metadata-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.metadata-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.metadata-box {
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.metadata-overlay.active .metadata-box {
    transform: translateY(0);
}

.meta-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.meta-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.meta-table-container {
    overflow-y: auto;
    padding-right: 4px;
}

.meta-table {
    width: 100%;
    border-collapse: collapse;
}
.meta-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.meta-table tr:last-child td { border-bottom: none; }

.meta-key {
    width: 140px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.meta-value {
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    padding-right: 2rem; /* space for copy icon */
}
.meta-copy-btn {
    position: absolute;
    top: 1rem;
    right: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    opacity: 0.5;
    transition: all 0.2s;
}
.meta-copy-btn:hover {
    opacity: 1;
    color: var(--primary);
}

/* Tooltip for Copy */
.copy-tooltip {
    position: fixed;
    background: var(--text);
    color: var(--bg);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1100;
}
.copy-tooltip.visible { opacity: 1; }
