:root {
    /* Base Material Design 3 Color Palette (Dark Theme Default) */
    --primary-color: #9ECFFD;
    --on-primary-color: #00325A;
    --primary-container-color: #00497D;
    --on-primary-container-color: #D6E3FF;
    --secondary-color: #BCC7DB;
    --on-secondary-color: #283141;
    --secondary-container-color: #3F4759;
    --on-secondary-container-color: #D8E3F8;
    --tertiary-color: #DCC0E5;
    --on-tertiary-color: #402847;
    --tertiary-container-color: #583F5F;
    --on-tertiary-container-color: #F8D8FF;
    --error-color: #FFB4AB;
    --on-error-color: #690005;
    --error-container-color: #93000A;
    --on-error-container-color: #FFDAD6;
    --background-color: #1A1C1E;
    --on-background-color: #E2E2E6;
    --surface-color: #1A1C1E;
    --on-surface-color: #E2E2E6;
    --surface-variant-color: #43474E;
    --on-surface-variant-color: #C3C7CF;
    --outline-color: #8D9199;
    --shadow-color: rgba(0, 0, 0, 0.4); /* Dark theme shadow */
    --input-bg-color: #2D3035;
    --input-border-color: var(--outline-color);
    --input-text-color: #E2E2E6; /* High contrast text for dark mode inputs */
    --accent-color: var(--primary-color); /* Kept for legacy */

    /* Hover States for Dark Theme */
    --primary-hover-color: #B2D9FF; 
    --secondary-hover-color: #CFDAEC; 
    --tertiary-hover-color: #E9D2ED;
    --error-hover-color: #FFCACA;
    --surface-hover-color: #2A2C2F; /* Slightly lighter surface on hover */
}

[data-theme="light"] {
    /* Light Material Design 3 Color Palette */
    --primary-color: #0061A4;
    --on-primary-color: #FFFFFF;
    --primary-container-color: #D6E3FF;
    --on-primary-container-color: #001D36;
    --secondary-color: #555F71;
    --on-secondary-color: #FFFFFF;
    --secondary-container-color: #D8E3F8;
    --on-secondary-container-color: #121C2B;
    --tertiary-color: #715578;
    --on-tertiary-color: #FFFFFF;
    --tertiary-container-color: #F8D8FF;
    --on-tertiary-container-color: #291332;
    --error-color: #BA1A1A;
    --on-error-color: #FFFFFF;
    --error-container-color: #FFDAD6;
    --on-error-container-color: #410002;
    --background-color: #FDFCFF;
    --on-background-color: #1A1C1E;
    --surface-color: #FDFCFF;
    --on-surface-color: #1A1C1E;
    --surface-variant-color: #E0E2EC;
    --on-surface-variant-color: #43474E; /* Darker grey for light theme text/icons */
    --outline-color: #73777F;
    --shadow-color: rgba(0, 0, 0, 0.15); /* Light theme shadow */
    --input-bg-color: #F0F2F7;
    --input-border-color: var(--outline-color);
    --input-text-color: #1A1C1E; /* High contrast text for light mode inputs */
    --accent-color: var(--primary-color); /* Kept for legacy */

    /* Hover States for Light Theme */
    --primary-hover-color: #004B8C;
    --secondary-hover-color: #4A5565;
    --tertiary-hover-color: #654D6C;
    --error-hover-color: #CC0000;
    --surface-hover-color: #EBF0F5; /* Slightly darker surface on hover */
}

body {
    font-family: 'Roboto', sans-serif; /* Changed to Roboto */
    background-color: var(--background-color);
    color: var(--on-background-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: background-color 0.3s, color 0.3s;
    width: 100%;
    position: absolute;
}

/* Layout */
.container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    background-color: var(--surface-color); /* Use surface color for container */
}

/* Top Controls */
.top-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 100;
    display: flex;
    gap: 12px; /* Smaller gap */
}

.icon-btn {
    background: var(--surface-variant-color); /* Changed to surface-variant */
    border: none; /* No border for M3 */
    color: var(--on-surface-variant-color);
    width: 44px; /* M3 touch target size */
    height: 44px; /* M3 touch target size */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 3px var(--shadow-color), 0 1px 2px var(--shadow-color); /* Subtle M3 shadow */
    font-size: 1.1rem; /* Slightly smaller */
    transition: all 0.2s ease;
}
.icon-btn:hover {
    background-color: var(--surface-hover-color); /* Use hover color */
    transform: translateY(-2px);
    box-shadow: 0 4px 6px var(--shadow-color), 0 1px 3px var(--shadow-color);
}
.icon-btn:active {
    background-color: var(--surface-variant-color); /* Revert to base */
    transform: translateY(0);
    box-shadow: 0 1px 3px var(--shadow-color), 0 1px 2px var(--shadow-color);
}


/* FAB for Clear Button */
#clearBtn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 110;
    background-color: var(--tertiary-container-color);
    color: var(--on-tertiary-container-color);
    border: none;
    width: 56px;
    height: 56px;
    border-radius: 16px; /* M3 Standard for FAB */
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px var(--shadow-color);
    font-size: 1.5rem;
    transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
#clearBtn:hover {
    background-color: var(--tertiary-hover-color);
    transform: scale(1.05);
    box-shadow: 0 6px 12px var(--shadow-color);
}
#clearBtn:active {
    background-color: var(--tertiary-container-color); /* Revert to base */
    transform: scale(1);
    box-shadow: 0 4px 8px var(--shadow-color);
}

@media (max-width: 900px) {
    .container { 
        flex-direction: column; /* Controls will be bottom sheet */
        justify-content: center; /* Push content to bottom */
    }
    .preview { 
        flex: 1; 
        height: auto; 
        min-height: 40%; /* Ensure preview has space */
        padding: 16px; /* Adjusted padding */
        order: -1; /* Place preview on top */
    }
    .top-controls { top: 10px; right: 10px; gap: 8px; }
    .icon-btn { width: 38px; height: 38px; font-size: 1rem; }
    #clearBtn { bottom: 16px; right: 16px; width: 48px; height: 48px; font-size: 1.2rem; border-radius: 12px; }

    /* Bottom Sheet on Mobile */
    .bottom-sheet {
        position: relative; /* Take up space in flex column */
        width: 100%;
        height: auto; /* Allow auto height */
        max-height: 60%; /* Increase max height */
        background-color: var(--surface-color);
        box-shadow: 0 -4px 10px var(--shadow-color);
        border-top-left-radius: 28px; /* M3 rounded corners */
        border-top-right-radius: 28px;
        transform: translateY(0); /* Start visible */
        transition: transform 0.3s ease-out, max-height 0.3s ease-out;
        display: flex;
        flex-direction: column;
        z-index: 50; /* Ensure above canvas */
    }
    .bottom-sheet.collapsed {
        max-height: auto; /* Let content dictate collapsed height */
        /* transform: translateY(calc(100% - 80px)); */ /* Move mostly off screen */
    }
    .sheet-handle {
        width: 32px;
        height: 4px;
        background-color: var(--outline-color);
        border-radius: 2px;
        margin: 12px auto; /* More margin */
        cursor: grab;
        flex-shrink: 0; /* Prevent shrinking */
    }
    .sheet-content {
        flex: 1;
        overflow-y: auto;
        padding: 0 24px 30px 24px; /* More bottom padding for safe area */
    }
    .controls-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 20px; /* Spacing below header */
    }
    .controls-header h2 { margin: 0; font-size: 1.3rem; }
    .controls-header .icon-btn {
        background: none;
        box-shadow: none;
        color: var(--on-surface-variant-color);
    }
    .controls-header .icon-btn:hover { transform: none; }
    
    /* Mobile Form Adjustments */
    .form-row { 
        flex-direction: column; /* Stack row inputs vertically on mobile */
        gap: 16px; 
    }
    .form-group { gap: 8px; margin-bottom: 16px; } /* Increase spacing between groups */
    
    /* Hide the controls panel specific styles for mobile if it's a bottom sheet */
    .controls {
        width: auto; /* Allow full width */
        border-right: none;
        padding: 0; /* No padding on the outer controls container */
        gap: 0;
    }
}

/* Controls Panel (Desktop Sidebar) */
@media (min-width: 901px) {
    .bottom-sheet {
        position: relative; /* Not fixed bottom */
        width: 360px; /* Wider sidebar */
        background-color: var(--surface-color);
        border-right: 1px solid var(--outline-color);
        box-shadow: none;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    .sheet-handle { display: none; } /* No handle on desktop */
    .sheet-content {
        flex: 1;
        overflow-y: auto;
        padding: 30px; /* More padding */
    }
    .controls-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 25px;
    }
    .controls-header h2 { margin: 0; }
    .controls-header .icon-btn {
        background: none;
        box-shadow: none;
        color: var(--on-surface-variant-color);
    }
    .controls-header .icon-btn:hover { transform: none; }
    /* Keep row layout on desktop */
    .form-row { flex-direction: row; gap: 16px; }
    .form-group { margin-bottom: 20px; }

    /* For desktop, progressive unfold still applies to #step2Controls */
    #step2Controls.collapsed { padding-top: 0; }
    #step2Controls.expanded { padding-top: 18px; }
}


h2 { 
    margin: 0; 
    font-size: 1.2rem; /* Slightly larger heading */
    font-weight: 700; /* Bolder heading */
    color: var(--on-surface-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand-accent { color: var(--primary-color); } /* Use primary color for accent */

.form-group { display: flex; flex-direction: column; gap: 8px; } /* Slightly more gap */
.form-row { display: flex; gap: 16px; } /* Slightly more gap */

label { 
    font-size: 0.8rem; /* Slightly larger label */
    font-weight: 500; /* Medium weight */
    color: var(--on-surface-variant-color); 
    opacity: 0.9;
    text-transform: uppercase; 
    letter-spacing: 0.8px; 
}

/* M3 Input Styles */
input, select, textarea {
    background: var(--surface-variant-color); /* Filled input style */
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--input-text-color); /* Use specific input text color */
    padding: 16px;
    border-radius: 12px 12px 0 0; /* Top corners rounded only for filled variant look */
    font-size: 1rem;
    font-family: 'Roboto', sans-serif;
    transition: background-color 0.2s, border-bottom-color 0.2s, color 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    background-color: var(--surface-hover-color); /* Lighter background on focus */
    color: var(--input-text-color);
    border-bottom-color: var(--primary-color);
    box-shadow: none; /* Remove ring, use bottom border */
}
input::placeholder, textarea::placeholder {
    color: var(--on-surface-variant-color); /* Explicit placeholder color */
    opacity: 0.7; /* Slightly higher opacity for visibility */
}

/* M3 Pill Buttons */
.pill-btn {
    border-radius: 100px !important; /* Full Pill Shape */
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 500;
    letter-spacing: 0.5px;
}
.primary-btn {
    background-color: var(--primary-color);
    color: var(--on-primary-color);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.primary-btn:hover {
    background-color: var(--primary-hover-color);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
    transform: translateY(-1px);
}
.primary-btn:active {
    background-color: var(--primary-color); /* Revert to base */
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Base button styles applied to general 'button' tag */
button {
    background-color: var(--primary-color);
    color: var(--on-primary-color);
    border: none;
    padding: 16px; /* Larger padding for M3 touch targets */
    border-radius: 12px; /* M3 rounded corners */
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem; /* Slightly larger font */
    text-transform: uppercase;
    letter-spacing: 0.8px;
    transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 1px 3px var(--shadow-color), 0 1px 2px var(--shadow-color);
}
button:hover {
    background-color: var(--primary-hover-color);
    box-shadow: 0 2px 4px var(--shadow-color), 0 1px 2px var(--shadow-color);
}
button:active {
    background-color: var(--primary-color); /* Revert to base */
    transform: translateY(1px);
    box-shadow: 0 1px 2px var(--shadow-color);
}

button.secondary { 
    background-color: var(--secondary-container-color); 
    color: var(--on-secondary-container-color);
    border: none;
    padding: 12px;
    font-size: 0.9rem;
    box-shadow: none;
}
button.secondary:hover {
    background-color: var(--secondary-hover-color); /* Use hover color */
    color: var(--on-secondary-color); /* Keep this as it's typically on-color */
}
button.secondary:active {
    background-color: var(--secondary-container-color); /* Revert */
    transform: translateY(1px);
}

/* Icon Buttons */
.icon-btn {
    background: var(--surface-variant-color);
    border: none;
    color: var(--on-surface-variant-color);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 3px var(--shadow-color), 0 1px 2px var(--shadow-color);
    font-size: 1.1rem;
    transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.icon-btn:hover {
    background-color: var(--surface-hover-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px var(--shadow-color), 0 1px 3px var(--shadow-color);
}
.icon-btn:active {
    background-color: var(--surface-variant-color);
    transform: translateY(0);
    box-shadow: 0 1px 3px var(--shadow-color), 0 1px 2px var(--shadow-color);
}

/* Action Cards (Camera/Gallery buttons) */
.action-card {
    background-color: var(--secondary-container-color);
    color: var(--on-secondary-container-color);
    border: none;
    border-radius: 24px;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}
.action-card:hover {
    background-color: var(--secondary-hover-color); /* Use hover color */
    color: var(--on-secondary-color); /* Keep this as it's typically on-color */
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
}
.action-card:active {
    background-color: var(--secondary-container-color);
    transform: translateY(0);
    box-shadow: 0 2px 6px var(--shadow-color);
}

/* Preview Area */
.preview {
    flex: 1;
    background-color: var(--background-color); /* Match background */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px; /* Slightly reduced padding */
    position: relative;
    overflow: hidden;
}

canvas {
    max-width: 100%;
    max-height: 100%;
    display: block; /* Ensure block-level behavior for centering */
    box-shadow: 0 8px 20px var(--shadow-color);
    border-radius: 16px;
    object-fit: contain;
    margin-top: 20px;
}

.empty-msg { 
    position: absolute; 
    color: var(--on-surface-variant-color); /* Changed color */
    pointer-events: none; 
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px; /* More gap */
    align-items: center;
}
.empty-icon { font-size: 3.5rem; opacity: 0.6; } /* Larger icon */

/* Custom Upload UI */
.upload-section { margin-bottom: 20px; }
input[type="file"] { display: none; }

.upload-trigger {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-container-color); /* M3 primary container */
    border: none; /* No border for M3 */
    border-radius: 20px; /* More rounded */
    padding: 40px; /* Larger padding */
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--on-primary-container-color);
    gap: 10px;
    text-align: center;
    box-shadow: 0 2px 4px var(--shadow-color);
}

.upload-trigger:hover {
    background-color: var(--primary-color);
    color: var(--on-primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-color);
}
.upload-trigger:active { transform: translateY(0); box-shadow: 0 1px 3px var(--shadow-color); }

.icon-camera { font-size: 3rem; } /* Larger icon */
.upload-label-text { font-weight: 700; font-size: 1.1rem; text-transform: uppercase; letter-spacing: 1.2px; } /* Bolder, larger */

/* Search Box */
.search-row {
    display: flex;
    gap: 10px;
    align-items: center;
}
.search-row input {
    flex: 1;
    border-radius: 12px; /* Match other inputs */
}
.search-trigger {
    background-color: var(--secondary-container-color);
    color: var(--on-secondary-container-color);
    width: 52px;
    height: 52px;
    border-radius: 12px;
    flex-shrink: 0;
}
.search-trigger:hover {
    background-color: var(--primary-container-color);
    color: var(--on-primary-container-color);
}

/* Feature Details List */
.feature-details {
    margin-top: 30px; /* More spacing */
    color: var(--on-surface-variant-color);
    opacity: 0.9;
    font-size: 0.95rem; /* Slightly larger */
    line-height: 1.5;
}
.feature-details h3 { 
    font-size: 1.1rem; 
    color: var(--primary-color); 
    margin-bottom: 20px; 
    font-weight: 600;
}
.feature-details ul { list-style: none; padding: 0; }
.feature-details li { margin-bottom: 15px; display: flex; align-items: center; gap: 12px; } /* More spacing */
.feature-details li::before { 
    /* content: 'check'; */ /* Removed generic check */
    font-family: inherit; 
    color: var(--primary-color); 
    font-weight: normal; 
    font-size: 1.2em;
}
/* FontAwesome icons within list */
.feature-details li i { color: var(--primary-color); width: 24px; text-align: center; }


/* Section Divider */
.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 25px 0 20px 0; /* More spacing */
    color: var(--outline-color);
    opacity: 0.7;
    font-size: 0.75rem; /* Slightly larger */
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 500;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--outline-color);
}
.divider span { padding: 0 12px; } /* More padding */

/* About Section */
.about-card {
    background-color: var(--surface-color);
    padding: 0;
    box-shadow: none;
}
.about-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}
.author-avatar {
    width: 48px;
    height: 48px;
    background-color: var(--primary-container-color);
    color: var(--on-primary-container-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
}
.social-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}
.social-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background-color: var(--surface-variant-color);
    border-radius: 12px;
    text-decoration: none;
    color: var(--on-surface-variant-color);
    font-weight: 500;
    transition: background-color 0.2s;
}
.social-item:hover {
    background-color: var(--secondary-container-color);
    color: var(--on-secondary-container-color);
}
.social-item i { font-size: 1.4rem; width: 24px; text-align: center; }
.contact-info {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--outline-color);
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Header Actions */
.header-actions { display: flex; gap: 8px; }

/* Camera Overlay */
#cameraOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    z-index: 200; /* Above everything */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
#cameraFeed {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.camera-controls {
    position: absolute;
    bottom: 40px;
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 20px;
}
.shutter-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background-color: white;
    border: 4px solid rgba(255,255,255,0.5);
    cursor: pointer;
    transition: transform 0.1s;
}
.shutter-btn:active { transform: scale(0.9); }

#cameraOverlay .icon-btn {
    background-color: rgba(0,0,0,0.5);
    color: white;
    width: 48px;
    height: 48px;
}

/* Visibility Helpers */
.d-none { display: none !important; }

/* Progressive Unfold Animation */
#step2Controls {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding-top: 0;
    transition: max-height 0.7s ease-out, opacity 0.5s ease-out, padding-top 0.7s ease-out;
    pointer-events: none;
}
#step2Controls.expanded {
    max-height: 1000px;
    opacity: 1;
    padding-top: 18px; 
    pointer-events: all;
}
.upload-actions{
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
}