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

:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-hover: #1a1a1a;
    --border: #2a2a2a;
    --text: #e5e5e5;
    --text-dim: #888;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --error: #ef4444;
    --success: #22c55e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-dim);
}

.generator {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 3rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

textarea,
input[type="number"] {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

textarea:focus,
input:focus {
    outline: none;
    border-color: var(--accent);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

button {
    cursor: pointer;
    font-family: inherit;
}

#generate-btn {
    width: 100%;
    padding: 1rem 2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.2s;
}

#generate-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

#generate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#progress-container {
    margin-top: 2rem;
}

.progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s ease-out;
}

.progress-text {
    text-align: center;
    margin-top: 0.5rem;
    color: var(--text-dim);
    font-size: 0.875rem;
}

#result-container {
    margin-top: 2rem;
}

.result-image {
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
}

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

.result-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.download-btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--surface-hover);
    color: var(--text);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: background 0.2s;
}

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

#error-container {
    margin-top: 2rem;
}

.error-message {
    padding: 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: 8px;
    color: var(--error);
}

.gallery {
    margin-top: 3rem;
}

.gallery h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

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

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}

.gallery-item:hover {
    transform: scale(1.02);
}

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

.gallery-item .overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    font-size: 0.75rem;
    color: var(--text);
    opacity: 0;
    transition: opacity 0.2s;
}

.gallery-item:hover .overlay {
    opacity: 1;
}

.load-more-btn {
    display: block;
    margin: 2rem auto 0;
    padding: 0.75rem 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    font-size: 0.875rem;
    transition: background 0.2s;
}

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

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.modal[hidden] {
    display: none;
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    background: var(--bg);
    border: none;
    border-radius: 50%;
    color: var(--text);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--border);
}

#modal-image {
    max-width: 100%;
    max-height: 70vh;
    display: block;
}

.modal-info {
    padding: 1.5rem;
}

.modal-prompt {
    margin-bottom: 0.5rem;
}

.modal-meta {
    color: var(--text-dim);
    font-size: 0.875rem;
}

footer {
    text-align: center;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.875rem;
}

@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .generator {
        padding: 1.5rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}
