:root {
    --bg-main: #0b0f19;
    --bg-card: rgba(20, 27, 45, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --accent-primary: #8b5cf6;
    --accent-secondary: #ec4899;
    --accent-cyan: #06b6d4;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --card-radius: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    background-image: 
        radial-gradient(circle at 15% 15%, rgba(139, 92, 246, 0.15), transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(236, 72, 153, 0.12), transparent 45%),
        radial-gradient(circle at 50% 50%, rgba(6, 182, 212, 0.08), transparent 50%);
    min-height: 100vh;
}

.app-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Header ── */
.header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    font-size: 2.2rem;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 12px;
    padding: 6px 12px;
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3);
}

h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.gradient-text {
    background: linear-gradient(135deg, #a78bfa, #f472b6, #38bdf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.pollinations-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 8px 16px;
    border-radius: 9999px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.85rem;
    transition: var(--transition);
    backdrop-filter: blur(8px);
}

.pollinations-badge:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #10b981;
    box-shadow: 0 0 10px #10b981;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.3); }
}

/* ── Main Layout ── */
.main-container {
    display: grid;
    grid-template-columns: 440px 1fr;
    gap: 24px;
    flex: 1;
}

@media (max-width: 1024px) {
    .main-container {
        grid-template-columns: 1fr;
    }
}

.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    padding: 24px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
}

/* ── Control Panel ── */
.panel-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.4rem;
    margin-bottom: 6px;
}

.panel-header p {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.story-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-group.half {
    flex: 1;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #cbd5e1;
    letter-spacing: 0.3px;
}

textarea, select {
    background: rgba(11, 15, 25, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.92rem;
    transition: var(--transition);
    outline: none;
}

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

textarea:focus, select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25);
}

.prompt-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.chip {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
    color: #cbd5e1;
}

.chip:hover {
    background: rgba(139, 92, 246, 0.2);
    border-color: var(--accent-primary);
    color: #fff;
}

.primary-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 14px 20px;
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.35);
    margin-top: 8px;
}

.primary-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(139, 92, 246, 0.5);
}

.primary-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ── Status Card ── */
.status-card {
    margin-top: 20px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    gap: 14px;
    align-items: center;
}

.status-icon {
    font-size: 1.8rem;
}

.status-info {
    flex: 1;
}

.status-info h4 {
    font-size: 0.92rem;
    font-weight: 600;
}

.status-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-top: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-cyan));
    width: 20%;
    transition: width 0.4s ease;
}

/* ── Story Display & Reader ── */
.story-display {
    display: flex;
    flex-direction: column;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
}

.empty-illustration {
    font-size: 4rem;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.empty-state h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-muted);
    max-width: 440px;
    font-size: 0.95rem;
    line-height: 1.5;
}

/* ── Active Story Reader ── */
.story-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.story-main-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
}

.story-genre-tag {
    font-size: 0.8rem;
    color: var(--accent-cyan);
    font-weight: 600;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.3);
}

/* ── Chapter Carousel Card ── */
.chapter-carousel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chapter-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: center;
    background: rgba(11, 15, 25, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 20px;
}

@media (max-width: 900px) {
    .chapter-card {
        grid-template-columns: 1fr;
    }
}

.chapter-image-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    overflow: hidden;
    background: #0f172a;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.chapter-artwork {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease;
}

.chapter-artwork:hover {
    transform: scale(1.02);
}

.image-overlay-loader {
    position: absolute;
    inset: 0;
    background: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

.chapter-text-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chapter-badge {
    align-self: flex-start;
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(139, 92, 246, 0.4);
    color: #c4b5fd;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chapter-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    color: #f1f5f9;
}

.chapter-paragraphs {
    font-size: 0.98rem;
    line-height: 1.7;
    color: #cbd5e1;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 8px;
}

.chapter-paragraphs p {
    margin-bottom: 12px;
}

/* ── Reader Navigation ── */
.reader-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.nav-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    border-radius: 10px;
    padding: 10px 18px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.nav-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-dots {
    display: flex;
    gap: 8px;
}

.nav-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: var(--transition);
}

.nav-dot.active {
    background: var(--accent-primary);
    transform: scale(1.3);
    box-shadow: 0 0 10px var(--accent-primary);
}

/* ── Footer ── */
.footer {
    margin-top: 32px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.footer a {
    color: var(--accent-cyan);
    text-decoration: none;
    font-weight: 600;
}

.footer a:hover {
    text-decoration: underline;
}

.api-links code {
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #e2e8f0;
}
