:root {
    --bg-gradient: linear-gradient(135deg, #e3eeff 0%, #f6eeff 50%, #dafcfb 100%);
    --card-bg: rgba(255, 255, 255, 0.45);
    --card-border: rgba(255, 255, 255, 0.6);
    --primary-gradient: linear-gradient(90deg, #8b5cf6 0%, #3b82f6 100%);
    --text-main: #334155;
    --text-muted: #94a3b8;
    --font-family: 'Outfit', sans-serif;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.04);
}

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

body {
    font-family: var(--font-family);
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    padding: 24px 40px;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.logo-title {
    font-size: 28px;
    font-weight: 700;
    color: #4f46e5;
    letter-spacing: -0.5px;
}

.logo-subtitle {
    font-size: 14px;
    color: #64748b;
    font-weight: 400;
}

.user-profile {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

/* Main Layout */
.main-content {
    display: flex;
    gap: 30px;
    flex: 1;
}

/* Left Sidebar Controls */
.controls-panel {
    width: 400px;
    /* Fixed width for form fields */
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 10px;
    /* Removed fixed height and overflow so it scrolls with the main page naturally */
}

/* Webkit Scrollbar */
.controls-panel::-webkit-scrollbar {
    width: 6px;
}

.controls-panel::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

/* Control Cards */
.control-card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-soft);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.card-header h2 {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #64748b;
    text-transform: uppercase;
}

.card-header.space-between {
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-small {
    font-size: 16px;
    color: #8b5cf6;
}

.icon-large {
    font-size: 32px;
    color: #94a3b8;
    margin-bottom: 8px;
}

.icon-tiny {
    font-size: 14px;
}

/* Upload Area */
.upload-area {
    border: 2px dashed rgba(148, 163, 184, 0.4);
    border-radius: var(--radius-md);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.3);
}

.upload-area:hover {
    background: rgba(255, 255, 255, 0.5);
    border-color: #8b5cf6;
}

.upload-area p {
    font-size: 14px;
    color: #64748b;
}

/* Buttons */
.btn-suggest {
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
    border: none;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-suggest:hover {
    background: rgba(139, 92, 246, 0.2);
}

.btn-generate {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 16px;
    border-radius: var(--radius-lg);
    font-size: 16px;
    font-weight: 600;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
    margin-top: 10px;
}

.btn-generate:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

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

.btn-clear {
    color: #ff6b6b;
    background: none;
    border: none;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 1px;
}

/* Forms */
textarea,
.text-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid white;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-family: var(--font-family);
    font-size: 14px;
    color: var(--text-main);
    resize: none;
    transition: all 0.2s;
}

textarea:focus,
.text-input:focus {
    outline: none;
    border-color: #8b5cf6;
    background: white;
}

.textarea-wrapper {
    position: relative;
}

.inputs-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.row-2-cols {
    display: flex;
    gap: 16px;
}

.row-2-cols>* {
    flex: 1;
}

/* Selects */
.select-wrapper {
    background: rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.select-wrapper.no-border {
    background: rgba(255, 255, 255, 0.4);
}

select {
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    font-family: var(--font-family);
    font-size: 14px;
    color: var(--text-main);
    appearance: none;
    cursor: pointer;
}

select:focus {
    outline: none;
}

/* Layout Specific Adjustments for Dropdowns */
.settings-card {
    padding: 12px 16px;
}

.settings-card .card-header {
    margin-bottom: 8px;
}

/* Blur Slider */
.blur-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    background: white;
    padding: 4px 12px;
    border-radius: 20px;
}

.blur-slider input[type=range] {
    width: 60px;
    accent-color: #8b5cf6;
}

#blur-value {
    color: #8b5cf6;
    width: 25px;
}

/* Pro Toggle Map */
.pro-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
}

.pro-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pro-icon {
    background: #ffb020;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pro-icon span {
    font-size: 20px;
}

.pro-text h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
}

.pro-text p {
    font-size: 11px;
    color: #64748b;
}

/* Toggle Switch css */
.toggle-switch input {
    display: none;
}

.toggle-switch label {
    display: block;
    width: 44px;
    height: 24px;
    background-color: #cbd5e1;
    border-radius: 24px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.3s;
}

.toggle-switch label::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}

.toggle-switch input:checked+label {
    background-color: #8b5cf6;
}

.toggle-switch input:checked+label::after {
    transform: translateX(20px);
}


/* Right Panel / Preview */
.preview-panel {
    flex: 0 1 40%;
    max-width: 40%;
    aspect-ratio: 9 / 16;
    height: auto;
    max-height: calc(100vh - 140px);
    transition: aspect-ratio 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    align-self: flex-start;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    margin: 0;
}

.preview-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    min-width: 0;
}

.empty-state {
    text-align: center;
    color: #94a3b8;
}

.empty-state span {
    font-size: 48px;
    opacity: 0.5;
    margin-bottom: 16px;
}

.loading-state {
    text-align: center;
    color: #8b5cf6;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(139, 92, 246, 0.2);
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

.result-state {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-height: 0;
    min-width: 0;
}

canvas#poster-canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    object-fit: contain;
    flex-shrink: 1;
    min-height: 0;
    min-width: 0;
}

/* Footer / History */
.history-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.4);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.history-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.history-grid {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 10px;
}

.history-grid::-webkit-scrollbar {
    height: 6px;
}

.history-grid::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.history-item {
    width: 160px;
    height: 240px;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s, box-shadow 0.2s;
    background: white;
    position: relative;
}

.history-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-actions {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    opacity: 0;
    transition: opacity 0.2s;
}

.history-item:hover .history-actions {
    opacity: 1;
}

.btn-history-action {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-family: var(--font-family);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn-history-action:hover {
    background: rgba(255, 255, 255, 0.4);
}

.btn-history-action.delete:hover {
    background: rgba(255, 107, 107, 0.8);
    border-color: #ff6b6b;
}

/* --- Preview Hover Actions --- */
.preview-actions {
    position: absolute;
    bottom: 20px;
    display: flex;
    gap: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

#preview-result:hover .preview-actions {
    opacity: 1;
}

.btn-preview-action {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    background: rgba(30, 41, 59, 0.8);
    color: white;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.2s, background 0.2s;
    backdrop-filter: blur(10px);
}

.btn-preview-action:hover {
    transform: translateY(-2px);
    background: rgba(0, 0, 0, 0.9);
}

/* --- Modal Dialog --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    /* This activates flexbox layout */
    align-items: center;
    /* This centers the modal vertically */
    justify-content: center;
    /* This centers the modal horizontally */
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 500px;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    padding: 24px;
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    0% {
        transform: scale(0.9);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- Responsive & Mobile Layout --- */
@media (max-width: 900px) {
    body {
        padding: 16px 20px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .user-profile {
        width: 100%;
        justify-content: flex-start;
    }

    .main-content {
        flex-direction: column;
        gap: 24px;
    }

    .controls-panel {
        width: 100%;
        padding-right: 0;
    }

    .preview-panel {
        max-width: 100%;
        width: 100%;
        min-height: auto;
        max-height: 60vh;
    }

    .result-state {
        padding-bottom: 74px;
        /* Space for buttons */
    }

    .preview-actions {
        opacity: 1;
        bottom: 16px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .row-2-cols {
        flex-direction: column;
        gap: 16px;
    }
}