:root {
    --primary: #7c3aed;
    --primary-hover: #6d28d9;
    --primary-glow: rgba(124, 58, 237, 0.3);
    --bg: #0a0a0f;
    --surface: #16161f;
    --surface-hover: #1e1e2a;
    --border: #2a2a3a;
    --text: #f0f0f5;
    --text-muted: #8888a0;
    --success: #10b981;
    --error: #ef4444;
    --radius: 16px;
    --radius-sm: 10px;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* App Layout — two columns */
.app-layout {
    display: flex;
    gap: 1rem;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1rem;
    min-height: 100vh;
}

.app {
    flex: 1;
    max-width: 560px;
    padding: 1.5rem 0 3rem;
}

/* Header */
.app-header {
    text-align: center;
    padding: 2rem 0 1.5rem;
}

.app-header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #a78bfa, #7c3aed, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.app-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 300;
}

/* Selfie Upload */
.selfie-section {
    margin-bottom: 2rem;
}

.selfie-upload {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: var(--surface);
}

.selfie-upload:hover {
    border-color: var(--primary);
    box-shadow: 0 0 20px var(--primary-glow);
}

.selfie-upload input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.selfie-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1rem;
    gap: 0.5rem;
}

.selfie-icon {
    font-size: 2.5rem;
    margin-bottom: 0.25rem;
}

.selfie-text {
    font-size: 1.1rem;
    font-weight: 600;
}

.selfie-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.selfie-preview {
    position: relative;
}

.selfie-preview img {
    width: 100%;
    max-height: 280px;
    object-fit: cover;
    display: block;
}

.selfie-change {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    z-index: 3;
    transition: background 0.2s;
}

.selfie-change:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* Scenes Gallery */
.scenes-section {
    margin-bottom: 2rem;
}

.scenes-section h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.scenes-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.scene-card {
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.3s;
    background: var(--surface);
    border: 2px solid transparent;
}

.scene-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.scene-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 20px var(--primary-glow);
}

.scene-card-image {
    position: relative;
    aspect-ratio: 2 / 3;
    overflow: hidden;
}

.scene-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s;
}

.scene-card:hover .scene-card-image img {
    transform: scale(1.05);
}

.scene-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
    display: flex;
    justify-content: flex-end;
}

.scene-emoji {
    font-size: 1.3rem;
}

.scene-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
}

.scene-card-title {
    font-size: 0.8rem;
    font-weight: 500;
}

/* Generating State */
.generating-section {
    margin: 2rem 0;
}

.generating-content {
    text-align: center;
    padding: 3rem 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.generating-content h2 {
    margin-top: 1rem;
    font-size: 1.2rem;
    font-weight: 600;
}

.generating-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* Spinner */
.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

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

/* Custom Prompt */
.custom-prompt-box {
    margin-bottom: 1rem;
}

.custom-prompt-input-row {
    display: flex;
    gap: 0.5rem;
}

.custom-prompt-input-row input {
    flex: 1;
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
}

.custom-prompt-input-row input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.btn-accent {
    flex-shrink: 0;
    padding: 0.7rem 1.2rem;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.btn-accent:hover {
    opacity: 0.9;
}

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

.custom-loading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.spinner-small {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.custom-preview {
    margin-top: 0.75rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.custom-preview .scene-card {
    flex: 0 0 160px;
}

.btn-use-custom {
    flex: 1;
    align-self: stretch;
    font-size: 0.9rem;
}

/* Divider */
.divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.25rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Result */
.result-section {
    margin: 2rem 0;
}

.result-section h2 {
    text-align: center;
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.result-image-wrapper {
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    margin-bottom: 1.25rem;
}

.result-image-wrapper img {
    width: 100%;
    display: block;
}

.result-prompt-box {
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    text-align: left;
}

.result-prompt-box h4 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.result-prompt-box p {
    color: var(--text-muted);
    line-height: 1.4;
    font-family: monospace;
}

.result-actions {
    display: flex;
    gap: 0.75rem;
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex: 1;
    padding: 0.9rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: background 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
}

/* Error Toast */
.error-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--error);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
    z-index: 100;
    animation: slideUp 0.3s ease-out;
    max-width: 90%;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Utility */
.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 900px) {
    .app-layout {
        flex-direction: column;
    }

    .debug-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 200px;
        border-radius: 12px 12px 0 0;
        border-top: 1px solid var(--border);
    }

    .app {
        padding-bottom: 220px;
    }
}

@media (max-width: 400px) {
    .app {
        padding: 1rem 0.75rem 2rem;
    }

    .app-header h1 {
        font-size: 1.6rem;
    }

    .scenes-grid {
        gap: 0.5rem;
    }
}

/* Debug Panel */
.debug-panel {
    width: 360px;
    flex-shrink: 0;
    background: #0d0d14;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.debug-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.debug-clear {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}

.debug-clear:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.debug-log {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.72rem;
    line-height: 1.5;
}

.debug-entry {
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.25rem;
    word-break: break-word;
    white-space: pre-wrap;
}

.debug-entry .debug-time {
    color: #555;
    margin-right: 0.4rem;
}

.debug-entry.info {
    color: #8888a0;
}

.debug-entry.success {
    color: #10b981;
    background: rgba(16, 185, 129, 0.08);
}

.debug-entry.error {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border-left: 2px solid #ef4444;
}

.debug-entry.step {
    color: #7c3aed;
    background: rgba(124, 58, 237, 0.08);
}

/* Scene Categories */
.scene-category {
    margin-bottom: 1.75rem;
}

.category-header {
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.category-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.category-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Prompt Info Button */
.prompt-info-btn {
    background: none;
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.15rem 0.3rem;
    border-radius: 4px;
    opacity: 0.4;
    transition: opacity 0.2s;
    line-height: 1;
    flex-shrink: 0;
}

.prompt-info-btn:hover {
    opacity: 1;
}

/* Prompt Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: color 0.2s, background 0.2s;
}

.modal-close:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
}

.modal-body pre {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.75rem;
    line-height: 1.6;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-word;
}

/* New UI Elements */
.selfie-actions {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    display: flex;
    gap: 0.5rem;
    z-index: 3;
}

.selfie-actions .btn {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    color: white;
}

.selfie-actions .btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.selfie-traits-box {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.selfie-traits-box h4 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.selfie-traits-box p {
    color: var(--text-muted);
    line-height: 1.4;
}

/* Gallery Modal */
.modal-large {
    max-width: 800px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.gallery-item {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
}

.gallery-item:hover {
    transform: scale(1.05);
    border-color: var(--primary);
}