:root {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-hover: #1e2a4a;
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --accent-gold: #f0c040;
    --accent-purple: #7c6bc4;
    --accent-blue: #4a90d9;
    --accent-teal: #3dcfcf;
    --accent-pink: #e06088;
    --danger: #e05555;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.3s ease;
    --gradient-night: linear-gradient(170deg, #0f0f23 0%, #141430 40%, #18153a 100%);
    --shadow-card: 0 2px 12px rgba(0,0,0,0.3);
    --shadow-glow-gold: 0 0 18px rgba(240,192,64,0.25);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    overscroll-behavior: none;
}
body.no-scroll {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

html {
    background: #14122e;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gradient-night);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

body::-webkit-scrollbar { width: 6px; }
body::-webkit-scrollbar-track { background: transparent; }
body::-webkit-scrollbar-thumb { background: rgba(124,107,196,0.3); border-radius: 3px; }

/* ==================== SCREENS ==================== */
.screen {
    min-height: 100vh;
    animation: screenSlideIn 0.4s ease;
}

@keyframes screenSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==================== STARFIELD ==================== */
.starfield {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.star {
    position: absolute;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background: #fff;
    animation: twinkle-star var(--dur) ease-in-out infinite;
    opacity: 0;
}

@keyframes twinkle-star {
    0%, 100% { opacity: 0.15; }
    50% { opacity: var(--peak, 0.8); }
}

/* ==================== HEADER ==================== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    position: sticky;
    top: 0;
    z-index: 10;
}
.app-header:not(.home-header) > :first-child,
.app-header:not(.home-header) > :last-child {
    width: 40px;
    flex-shrink: 0;
}
.app-header:not(.home-header) > .header-title {
    flex: 1;
    text-align: center;
}

.app-header.home-header {
    background: linear-gradient(135deg, #1a1a2e 0%, #1e1840 100%);
    border-bottom: 1px solid rgba(240,192,64,0.15);
}

.moon-glow {
    filter: drop-shadow(0 0 6px rgba(240,192,64,0.6));
    animation: moon-pulse 4s ease-in-out infinite;
}

@keyframes moon-pulse {
    0%, 100% { filter: drop-shadow(0 0 6px rgba(240,192,64,0.6)); }
    50% { filter: drop-shadow(0 0 12px rgba(240,192,64,0.9)); }
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-gold);
}

.logo-icon-small {
    font-size: 24px;
    color: var(--accent-gold);
}

/* ==================== CONTENT ==================== */
.content {
    padding: 24px 20px;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.section {
    margin-bottom: 28px;
}

.section h2 {
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    padding-left: 12px;
    border-left: 3px solid var(--accent-purple);
}

/* ==================== AUTH ==================== */
.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 40px 20px;
    position: relative;
    background: radial-gradient(ellipse at 50% 30%, rgba(124,107,196,0.1) 0%, transparent 60%);
}

.logo {
    text-align: center;
    margin-bottom: 40px;
}

.logo-icon {
    font-size: 64px;
    color: var(--accent-gold);
    display: block;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 12px rgba(240,192,64,0.5));
    animation: moon-pulse 4s ease-in-out infinite;
}

.logo h1 {
    font-family: 'Fredoka', sans-serif;
    font-size: 28px;
    color: var(--accent-gold);
    font-weight: 700;
}

.tagline {
    color: var(--text-secondary);
    margin-top: 8px;
    font-size: 14px;
}

.auth-form {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-form input {
    padding: 14px 16px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    background: rgba(22,33,62,0.6);
    color: var(--text-primary);
    font-family: 'Nunito', sans-serif;
    font-size: 16px;
    outline: none;
    transition: all var(--transition);
}

.auth-form input:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 12px rgba(124,107,196,0.2);
    background: rgba(22,33,62,0.8);
}

.auth-switch {
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-switch a {
    color: var(--accent-blue);
    text-decoration: none;
}

/* ==================== BUTTONS ==================== */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Nunito', sans-serif;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #6b5bb4 0%, #8b6fd4 100%);
    color: white;
    box-shadow: 0 2px 10px rgba(124,107,196,0.3);
}
.btn-primary:hover {
    background: linear-gradient(135deg, #7b6bc4 0%, #9b7fe4 100%);
    box-shadow: 0 4px 16px rgba(124,107,196,0.45);
    transform: translateY(-1px);
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-outline {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-primary);
}
.btn-outline:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.2);
}

.btn-danger {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
}
.btn-danger:hover { background: rgba(224,85,85,0.1); }
.btn-disabled { opacity: 0.35; pointer-events: none; }

.btn-full { width: 100%; }
.btn-large { padding: 16px 32px; font-size: 18px; }
.btn-small { padding: 8px 16px; font-size: 14px; }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.btn-icon:hover { background: rgba(255,255,255,0.08); }

.btn-dim { color: var(--text-secondary); }

.btn-playback {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6b5bb4 0%, #8b6fd4 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(124,107,196,0.4);
}
.btn-playback i {
    font-size: 24px;
}
.btn-playback .fa-play {
    margin-left: 3px;
}
.btn-playback:hover {
    background: linear-gradient(135deg, #7b6bc4 0%, #9b7fe4 100%);
    box-shadow: 0 6px 28px rgba(124,107,196,0.55);
    transform: scale(1.05);
}

/* ==================== GREETING ==================== */
.greeting {
    padding: 20px 0 8px;
    text-align: center;
    position: relative;
}

.greeting::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 200px;
    background: radial-gradient(ellipse, rgba(240,192,64,0.08) 0%, transparent 70%);
    pointer-events: none;
    z-index: -1;
}

.greeting-stars {
    font-size: 14px;
    letter-spacing: 6px;
    color: var(--accent-gold);
    opacity: 0.7;
    margin-bottom: 6px;
}

.greeting-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 26px;
    font-weight: 700;
    color: var(--accent-gold);
    text-shadow: 0 0 20px rgba(240,192,64,0.3);
}

.greeting-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 4px;
}

/* ==================== PROFILES ==================== */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.profile-card {
    background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-hover) 100%);
    border: 2px solid transparent;
    border-radius: var(--radius);
    padding: 20px 12px 16px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-card);
}
.profile-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--card-accent, var(--accent-purple));
}
.profile-card:hover {
    border-color: var(--accent-purple);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.profile-card.selected {
    border-color: var(--accent-gold);
    background: var(--bg-hover);
    box-shadow: var(--shadow-glow-gold);
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--card-accent, var(--accent-purple));
    border: 2px solid rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
    font-size: 22px;
    font-weight: bold;
    transition: transform var(--transition);
}
.profile-card:hover .profile-avatar { transform: scale(1.08); }

.profile-card-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.profile-card-age {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Add-child card inside grid */
.profile-card-add {
    background: transparent;
    border: 2px dashed rgba(255,255,255,0.15);
    border-radius: var(--radius);
    padding: 20px 12px 16px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 110px;
    box-shadow: none;
}
.profile-card-add::before { display: none; }
.profile-card-add:hover {
    border-color: var(--accent-purple);
    background: rgba(124,107,196,0.08);
}
.profile-card-add .add-icon {
    font-size: 28px;
    color: var(--text-secondary);
    line-height: 1;
}
.profile-card-add .add-label {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ==================== THEMES ==================== */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.theme-card {
    background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-hover) 100%);
    border: 2px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 20px 12px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: var(--shadow-card);
}
.theme-card:hover {
    border-color: var(--accent-purple);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.theme-card.selected {
    border-color: var(--accent-gold);
    background: var(--bg-hover);
    box-shadow: var(--shadow-glow-gold);
}
.theme-card.locked { opacity: 0.4; cursor: not-allowed; }
.theme-card.locked:hover { border-color: rgba(255,255,255,0.06); transform: none; box-shadow: var(--shadow-card); }

.theme-icon { font-size: 32px; transition: transform var(--transition); }
.theme-card:hover .theme-icon { transform: scale(1.15); }
.theme-label { font-family: 'Fredoka', sans-serif; font-size: 14px; font-weight: 600; }
.theme-lock { font-size: 10px; color: var(--text-secondary); }

/* ==================== VOICE SELECTOR ==================== */
.voice-grid {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.voice-card {
    background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-hover) 100%);
    border: 2px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 12px 20px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    box-shadow: var(--shadow-card);
}
.voice-card:hover {
    border-color: var(--accent-purple);
    transform: translateY(-1px);
}
.voice-card.selected {
    border-color: var(--accent-gold);
    background: var(--bg-hover);
    box-shadow: var(--shadow-glow-gold);
}
.voice-card.locked { opacity: 0.4; cursor: not-allowed; }
.voice-card.locked:hover { border-color: rgba(255,255,255,0.06); transform: none; }
.voice-name { font-family: 'Fredoka', sans-serif; font-size: 14px; font-weight: 600; }
.voice-lock { font-size: 10px; color: var(--text-secondary); }

/* ==================== CUSTOM PROMPT ==================== */
.custom-prompt-box {
    width: 100%;
    padding: 14px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    background: rgba(22,33,62,0.6);
    color: var(--text-primary);
    font-size: 15px;
    font-family: 'Nunito', sans-serif;
    outline: none;
    resize: vertical;
    transition: all var(--transition);
}
.custom-prompt-box::placeholder { color: var(--text-secondary); }
.custom-prompt-box:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 12px rgba(124,107,196,0.15);
    background: rgba(22,33,62,0.8);
}

/* ==================== STORY LOADING ==================== */
#storyLoadingScreen {
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
    background: radial-gradient(ellipse at 50% 40%, rgba(240,192,64,0.05) 0%, transparent 60%);
}

.loading-container h2 {
    font-family: 'Fredoka', sans-serif;
}

.loading-icon {
    font-size: 72px;
    color: var(--accent-gold);
    animation: float 3s ease-in-out infinite;
    margin-bottom: 20px;
    transition: all 0.6s ease;
    filter: drop-shadow(0 0 12px rgba(240,192,64,0.4));
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.loading-subtitle {
    color: var(--text-secondary);
    margin-top: 4px;
    font-style: italic;
    min-height: 1.4em;
    transition: opacity 0.4s ease;
}

.loading-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 32px;
    width: 100%;
    max-width: 320px;
}

.loading-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(22,33,62,0.6);
    border: 1px solid transparent;
    opacity: 0.35;
    transition: all 0.5s ease;
}

.loading-step.active {
    opacity: 1;
    border-color: var(--accent-gold);
    background: rgba(240, 192, 64, 0.08);
    box-shadow: 0 0 12px rgba(240,192,64,0.1);
}

.loading-step.done {
    opacity: 0.6;
    border-color: transparent;
}

.loading-step .step-icon {
    font-size: 22px;
    width: 32px;
    text-align: center;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.loading-step.active .step-icon {
    animation: pulse-icon 1.5s ease-in-out infinite;
}

.loading-step.done::after {
    content: "\2713";
    color: #5cb85c;
    font-size: 16px;
    margin-left: auto;
    flex-shrink: 0;
}

.loading-step .step-label {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: left;
    flex: 1;
}

.loading-step.active .step-label {
    color: var(--text-primary);
}

@keyframes pulse-icon {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.loading-progress-bar {
    width: 100%;
    max-width: 320px;
    height: 8px;
    background: var(--bg-card);
    border-radius: 4px;
    margin-top: 20px;
    overflow: hidden;
}

.loading-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-purple), var(--accent-gold));
    border-radius: 4px;
    transition: width 0.6s ease;
}

.loading-dots {
    margin-top: 20px;
    font-size: 32px;
    color: var(--accent-gold);
}
.loading-dots span {
    animation: blink 1.4s infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 20% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* ==================== PLAYBACK ==================== */
#storyPlaybackScreen {
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
.playback-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    max-width: 600px;
    margin: 0 auto;
}

.playback-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.playback-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    color: var(--accent-gold);
    text-align: center;
    flex: 1;
    padding-top: 4px;
}

.playback-text {
    flex: 1;
    font-size: 18px;
    line-height: 1.9;
    color: rgba(232,232,240,0.92);
    padding: 20px 0;
    overflow-y: auto;
    min-height: 0;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Karaoke word highlighting */
.karaoke-word {
    display: inline;
    transition: color 0.15s ease, text-shadow 0.15s ease;
    padding: 0 1px;
    cursor: pointer;
}
.karaoke-word.upcoming {
    color: rgba(232, 232, 240, 0.35);
}
.karaoke-word.active {
    color: #b48ae8;
    text-shadow: 0 0 8px rgba(139, 111, 212, 0.7),
                 0 0 20px rgba(139, 111, 212, 0.35);
    font-weight: 600;
}
.karaoke-word.spoken {
    color: rgba(232, 232, 240, 0.65);
}

.playback-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px 0;
    flex-shrink: 0;
}

.playback-buttons {
    display: flex;
    align-items: center;
    gap: 24px;
}

.btn-skip {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.btn-skip i {
    font-size: 22px;
}
.btn-skip:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.08);
}

.audio-progress {
    width: 100%;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-card);
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
}

.progress-fill {
    height: 100%;
    background: var(--accent-gold);
    width: 0%;
    transition: width 0.1s linear;
    border-radius: 3px;
}

/* ==================== CHOICE BUTTONS ==================== */
.choice-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px 0;
    animation: choicesAppear 0.5s ease;
}

@keyframes choicesAppear {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.choice-btn {
    padding: 20px 24px;
    min-height: 64px;
    border: 2px solid rgba(124,107,196,0.5);
    border-radius: var(--radius);
    background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-hover) 100%);
    color: var(--text-primary);
    font-family: 'Nunito', sans-serif;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.choice-btn:focus {
    outline: none;
}
@media (hover: hover) {
    .choice-btn:hover {
        background: linear-gradient(135deg, #5b4bb8 0%, #7c6bc4 100%);
        border-color: var(--accent-purple);
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(124,107,196,0.35);
    }
}
.choice-btn:active {
    background: linear-gradient(135deg, #5b4bb8 0%, #7c6bc4 100%);
    border-color: var(--accent-purple);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(124,107,196,0.35);
}

/* ==================== STORY COMPLETE ==================== */
#storyCompleteScreen {
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
.complete-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
    background: radial-gradient(ellipse at 50% 40%, rgba(240,192,64,0.06) 0%, transparent 55%);
}

.complete-stars {
    font-size: 40px;
    color: var(--accent-gold);
    margin-bottom: 20px;
    animation: twinkle 2s ease-in-out infinite;
    filter: drop-shadow(0 0 8px rgba(240,192,64,0.4));
}

@keyframes twinkle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.complete-container h1 {
    font-family: 'Fredoka', sans-serif;
    font-size: 36px;
    color: var(--accent-gold);
    margin-bottom: 8px;
    text-shadow: 0 0 24px rgba(240,192,64,0.3);
}

.complete-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 16px;
    font-style: italic;
}

.complete-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}

/* ==================== NEW STORY CTA ==================== */
.cta-new-story {
    display: flex;
    align-items: center;
    gap: 16px;
    background: linear-gradient(135deg, #5b4bb8 0%, #7c6bc4 50%, #9b7ed8 100%);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(240,192,64,0.2);
    width: 100%;
    text-align: left;
    color: white;
    box-shadow: 0 4px 16px rgba(124,107,196,0.3), 0 0 30px rgba(139,92,246,0.15);
    animation: cta-glow-pulse 3s ease-in-out infinite;
}
@keyframes cta-glow-pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(124,107,196,0.3), 0 0 30px rgba(139,92,246,0.15); }
    50% { box-shadow: 0 4px 20px rgba(124,107,196,0.4), 0 0 40px rgba(139,92,246,0.25); }
}
.cta-new-story:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(124,107,196,0.45), 0 0 50px rgba(139,92,246,0.3);
    animation: none;
}
.cta-new-story::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -75%;
    width: 50%;
    height: 200%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
    transform: skewX(-20deg);
    animation: shimmer 4s ease-in-out infinite;
}
@keyframes shimmer {
    0% { left: -75%; }
    100% { left: 125%; }
}
.cta-sparkle {
    font-size: 28px;
    flex-shrink: 0;
    filter: drop-shadow(0 0 4px rgba(240,192,64,0.5));
    animation: sparkle-spin 3s ease-in-out infinite;
}
@keyframes sparkle-spin {
    0%, 100% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(8deg) scale(1.1); }
}
.cta-body { flex: 1; }
.cta-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 2px;
}
.cta-subtitle {
    font-size: 13px;
    opacity: 0.85;
}
.cta-arrow {
    font-size: 20px;
    flex-shrink: 0;
    transition: transform var(--transition);
}
.cta-new-story:hover .cta-arrow { transform: translateX(4px); }

.btn-library {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ==================== SECTION HEADER ROW ==================== */
.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.section-header-row h2 {
    margin-bottom: 0;
}
.section-header-row .view-all {
    font-size: 13px;
    color: var(--accent-blue);
    text-decoration: none;
    cursor: pointer;
    transition: color var(--transition);
}
.section-header-row .view-all:hover { color: var(--accent-gold); }

/* ==================== STORY LIST ==================== */
.story-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.story-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    padding-left: 20px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 3px solid var(--story-theme-color, var(--bg-card));
}
.story-card:hover {
    background: var(--bg-hover);
    transform: translateX(3px);
    box-shadow: var(--shadow-card);
}

.story-card-info {
    flex: 1;
}

.story-card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.story-card-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.story-card-status {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
}
.status-ready { background: rgba(80,200,120,0.2); color: #50c878; }
.status-generating { background: rgba(240,192,64,0.2); color: var(--accent-gold); }
.status-failed { background: rgba(224,85,85,0.2); color: var(--danger); }

.story-card-actions {
    display: flex;
    gap: 4px;
}

/* Horizontal scroll variant for home recent stories */
.story-list-horizontal {
    flex-direction: row;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.story-list-horizontal::-webkit-scrollbar { display: none; }

.story-list-horizontal .story-card {
    min-width: 260px;
    max-width: 300px;
    flex-shrink: 0;
    scroll-snap-align: start;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}
.story-list-horizontal .story-card:hover {
    transform: translateY(-2px);
}
.story-list-horizontal .story-card-actions {
    align-self: flex-end;
}

/* ==================== FILTER BAR ==================== */
.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.filter-bar select {
    flex: 1;
    padding: 10px 12px;
    background: rgba(22,33,62,0.7);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    outline: none;
    transition: all var(--transition);
}
.filter-bar select:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 8px rgba(124,107,196,0.15);
}

/* ==================== PROFILES LIST ==================== */
.profiles-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.profile-list-item {
    background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-hover) 100%);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-card);
    transition: all var(--transition);
}
.profile-list-item:hover {
    border-color: rgba(255,255,255,0.1);
}

.profile-list-info h3 { font-family: 'Fredoka', sans-serif; font-size: 16px; margin-bottom: 2px; }
.profile-list-info p { font-size: 12px; color: var(--text-secondary); }

.profile-list-actions {
    display: flex;
    gap: 8px;
}

/* ==================== SETTINGS ==================== */
.settings-section {
    background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-hover) 100%);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-card);
}

.settings-section h3 {
    font-family: 'Fredoka', sans-serif;
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.settings-item {
    padding: 8px 0;
    font-size: 15px;
}

.premium-features ul {
    list-style: none;
    margin-bottom: 16px;
}

.premium-features li {
    padding: 6px 0;
    padding-left: 20px;
    position: relative;
    color: var(--text-secondary);
}

.premium-features li::before {
    content: "\2713";
    position: absolute;
    left: 0;
    color: var(--accent-gold);
}

.premium-price {
    font-family: 'Fredoka', sans-serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-gold);
    margin-bottom: 16px;
    text-shadow: 0 0 12px rgba(240,192,64,0.2);
}

/* ==================== MODAL ==================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: linear-gradient(180deg, #1e1e3a 0%, var(--bg-secondary) 100%);
    border: 1px solid rgba(255,255,255,0.08);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    box-shadow: 0 -4px 30px rgba(0,0,0,0.4);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 { font-family: 'Fredoka', sans-serif; font-size: 20px; }

.modal-content label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    margin-top: 14px;
}

.modal-content input,
.modal-content select,
.modal-content textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    background: rgba(15,15,35,0.6);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    font-family: 'Nunito', sans-serif;
    transition: all var(--transition);
}

.modal-content input:focus,
.modal-content select:focus,
.modal-content textarea:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 10px rgba(124,107,196,0.15);
    background: rgba(15,15,35,0.8);
}

/* ==================== CONFIRM MODAL ==================== */
.confirm-modal {
    align-items: center;
    justify-content: center;
}
.confirm-content {
    max-width: 360px;
    border-radius: var(--radius) !important;
    border: 1px solid rgba(255,255,255,0.08) !important;
    padding: 28px 24px 24px;
    text-align: center;
    animation: confirmSlideIn 0.25s ease;
}
@keyframes confirmSlideIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}
.confirm-message {
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    margin-bottom: 24px;
}
.confirm-input-wrap {
    margin-bottom: 20px;
}
.confirm-input-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.confirm-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    background: rgba(15,15,35,0.6);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    text-align: center;
}
.confirm-input:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 10px rgba(124,107,196,0.15);
}
.confirm-actions {
    display: flex;
    gap: 12px;
}
.confirm-actions .btn {
    flex: 1;
}

/* ==================== CHIPS ==================== */
.chip-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    padding: 8px 14px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 20px;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
    background: rgba(255,255,255,0.03);
}
.chip:hover {
    border-color: var(--accent-purple);
    background: rgba(124,107,196,0.08);
}
.chip.selected {
    background: linear-gradient(135deg, #6b5bb4 0%, #8b6fd4 100%);
    border-color: transparent;
    color: white;
    box-shadow: 0 2px 8px rgba(124,107,196,0.3);
}

/* ==================== QUOTA ==================== */
.quota-info {
    text-align: center;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text-secondary);
    background: rgba(22,33,62,0.6);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
}

/* ==================== TOAST ==================== */
#toastContainer {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    font-weight: 600;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
    max-width: 320px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.toast.info { background: rgba(74,144,217,0.9); color: white; }
.toast.success { background: rgba(80,200,120,0.9); color: white; }
.toast.error { background: rgba(224,85,85,0.9); color: white; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
    font-style: italic;
}

/* ==================== FOOTER ==================== */
.app-footer {
    text-align: center;
    padding: 32px 0 16px;
    font-size: 12px;
    color: rgba(136,136,170,0.5);
}
.app-footer a {
    color: rgba(136,136,170,0.6);
    text-decoration: none;
    transition: color var(--transition);
}
.app-footer a:hover { color: var(--accent-gold); }

/* ==================== RESPONSIVE ==================== */
@media (min-width: 768px) {
    .modal {
        align-items: center;
    }
    .modal-content {
        border-radius: var(--radius);
        border: 1px solid rgba(255,255,255,0.08);
        max-height: 80vh;
    }
}

@media (max-width: 600px) {
    .filter-bar {
        flex-direction: column;
        gap: 8px;
    }
    .story-list-horizontal .story-card {
        min-width: 230px;
    }
}
