/* ✅ UPDATED CSS - Fixed to work with new IDs */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

body {
    font-family: 'Nunito', sans-serif;
}

.hero-gradient {
    background: linear-gradient(135deg, #FF5E62 0%, #FF9966 100%);
}

.card-hover:hover {
    transform: translateY(-8px) rotate(1deg);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
}

.custom-shadow {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.wavy-border {
    position: relative;
}

.wavy-border::after {
    content: "";
    position: absolute;
    bottom: -20px;
    left: 0;
    width: 100%;
    height: 20px;
    background-image: url("data:image/svg+xml,%3Csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,10 C30,28 70,-8 100,10 L100,0 L0,0 Z' fill='%23FEF2F2'/%3E%3C/svg%3E");
    background-size: 100px 20px;
    background-repeat: repeat-x;
}

.rainbow-text {
    background-image: linear-gradient(to right, #F59E0B, #10B981, #3B82F6, #8B5CF6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: rainbow 6s ease infinite;
    background-size: 400% 100%;
}

@keyframes rainbow {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

.bounce {
    animation: bounce 2s infinite;
}

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

.float {
    animation: float 3s ease-in-out infinite;
}

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

.wiggle:hover {
    animation: wiggle 0.5s ease-in-out;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

.loading-spinner {
    display: inline-block;
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 94, 98, 0.2);
    border-radius: 50%;
    border-top-color: #FF5E62;
    animation: spin 1s ease-in-out infinite;
}

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

.story-text p {
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
    line-height: 1.8;
}

.story-container {
    background-color: white;
    background-image: 
    radial-gradient(#FF9966 2px, transparent 2px),
    radial-gradient(#FF5E62 2px, transparent 2px);
    background-size: 40px 40px;
    background-position: 0 0, 20px 20px;
    background-repeat: repeat;
    background-attachment: fixed;
}

.membership-option {
    transition: all 0.3s ease;
}
    
.membership-option:hover {
    transform: translateY(-5px);
}

.tab-button {
    position: relative;
    transition: all 0.3s ease;
    border-bottom: none;
    margin-bottom: -1px;
    z-index: 10;

    /* Mobile-first sizing */
    padding: 8px 12px;
    font-size: 0.875rem; /* 14px */
    font-weight: 600;    
}

.tab-button.active {
    background-color: #FFFFFF;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
    color: #DB2777; /* pink-600 */
}

.tab-button:not(.active) {
    background-color: #F9A8D4; /* pink-300 */
    color: #FFFFFF;
}

.tab-content {
    display: none;
    position: relative;
    z-index: 5;
}

.tab-content.active {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.content-container {
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.tab-container {
    display: flex;
}

.action-button {
    transition: all 0.3s ease;
}

/* Saved state button */
.button-saved {
    background: linear-gradient(to right, #10b981, #059669);
    cursor: default;
    transform: none !important;
}

/* Button disabled state */
button:disabled {
    opacity: 0.7;
}

/* Save button spinner animation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.fa-spin {
    animation: spin 1s linear infinite;
}

/* Notification animation */
.notification {
    transition: opacity 0.5s ease;
}

.notification.hide {
    opacity: 0;
}

.story-image-container {
    margin: 20px 0;
    text-align: center;
}

.story-image-container img {
    max-width: 100%;
    height: auto;
    max-height: 600px;
    object-fit: contain;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border: 4px solid #e879f9;
    transition: transform 0.3s ease;
}

.story-image-container img:hover {
    transform: scale(1.05);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .story-image-container img {
        max-height: 200px;
    }
}

@media (max-width: 480px) {
    .story-image-container img {
        max-height: 150px;
    }
}

.character-card {
    background: linear-gradient(135deg, #fff7ed 0%, #fef3c7 100%);
    border: 2px solid #fed7aa;
    border-radius: 15px;
    padding: 20px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.character-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border-color: #fb923c;
}

.character-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #ea580c, #dc2626);
}

.character-avatar {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #fb923c, #ea580c);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px;
    box-shadow: 0 4px 15px rgba(234, 88, 12, 0.3);
    border: 3px solid white;
}
.character-name {
    color: #ea580c;
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 0;
    text-align: left;
}

.character-description {
    color: #6b7280;
    font-size: 0.9rem;
    line-height: 1.4;
    margin-bottom: 0;
    text-align: left;
    max-height: 40px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.character-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
}

.character-button {
    padding: 6px 12px;
    border: none;
    border-radius: 15px;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
}

.character-edit-btn {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
}

.character-edit-btn:hover {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.character-delete-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.character-delete-btn:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

#characterForm {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

#character-submit-btn {
    min-width: 180px;
    font-size: 1.1rem;
}

#character-submit-btn:hover {
    box-shadow: 0 6px 20px rgba(234, 88, 12, 0.4);
}

/* ✅ FIXED: Updated to target the story form dropdown specifically */
#story-characters-select {
    background-image: none; /* Remove default dropdown arrow for multi-select */
    padding: 12px;
    border: 2px solid #f9a8d4;
    border-radius: 12px;
    font-size: 14px;
}

/* ✅ FIXED: Updated Characters Tab specific styles */
#characters-tab-container {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

#story-characters-select:focus {
    border-color: #ec4899 !important; 
}

/* ✅ FIXED: Updated tab content active state */
#characters-tab.tab-content.active {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 1 !important;
    height: auto !important;
    overflow: visible !important;
}

/* ✅ FIXED: Ensure characters container is visible when parent is active */
#characters-tab.active #characters-tab-container {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
}

#story-characters-select:not(.tab-content) {
    /* This targets the dropdown select, not the tab content */
    background-image: none;
    padding: 12px;
    border: 2px solid #f9a8d4;
    border-radius: 12px;
    z-index: auto;
    position: relative;
    font-size: 14px;
    display: block;
}


/* Form validation styling */
.form-error {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.error-message {
    color: #ef4444;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    font-weight: 500;
}

/* Loading animation for character operations */
@keyframes spin {
    to { transform: rotate(360deg); }
}


@media (max-width: 640px) {
    .tab-container {
        display: flex;
        flex-wrap: wrap; /* Allow wrapping on very small screens */
        gap: 2px;
        margin-left: 5px; /* Reduce left margin */
    }
    
    .tab-button {
        padding: 6px 8px;
        font-size: 0.75rem; /* 12px */
        font-weight: 600;
        border-radius: 8px 8px 0 0; /* Smaller border radius */
        min-width: auto;
        flex: 1; /* Equal width distribution */
        text-align: center;
    }
    
    /* Stack tabs in 2 rows if needed on very small screens */
    .tab-button:nth-child(n+4) {
        margin-top: 4px;
    }
}

/* Small tablets (641px to 768px) - Medium tabs */
@media (min-width: 641px) and (max-width: 768px) {
    .tab-container {
        margin-left: 8px;
    }
    
    .tab-button {
        padding: 10px 16px;
        font-size: 0.875rem; /* 14px */
        font-weight: 700;
        border-radius: 12px 12px 0 0;
    }
}

/* Large tablets and small desktops (769px to 1024px) - Default size */
@media (min-width: 769px) and (max-width: 1024px) {
    .tab-container {
        margin-left: 10px;
    }
    
    .tab-button {
        padding: 12px 20px;
        font-size: 1rem; /* 16px */
        font-weight: 700;
        border-radius: 16px 16px 0 0;
    }
}

/* Large desktops (1025px and up) - Full size */
@media (min-width: 1025px) {
    .tab-container {
        margin-left: 10px;
    }
    
    .tab-button {
        padding: 12px 24px;
        font-size: 1.125rem; /* 18px */
        font-weight: 800;
        border-radius: 16px 16px 0 0;
    }
}

/* Responsive adjustments for character cards */
@media (max-width: 768px) {
    .character-card .character-content {
        text-align: center;
    }
    
    .character-card .character-actions {
        justify-content: center;
        width: 100%;
    }
   .character-card {
        padding: 15px;
    }
    
    .character-avatar {
        width: 60px;
        height: 60px;
    }
    
    .character-name {
        font-size: 1.25rem;
    }
    
    .character-actions {
        flex-direction: column;
        align-items: center;
    }
    
    .character-button {
        width: 100%;
        max-width: 150px;
    }
    
    #characters-tab {
        min-height: 80px; /* Smaller on mobile */
    }
}

@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Success state for form */
.form-success {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
}

/* Character list grid improvements */
.characters-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

@media (min-width: 1024px) {
    .characters-grid {
        grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    }
}


/* ✅ CRITICAL: Force display for characters tab container */
#characters-tab-container.space-y-4 {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    min-height: 50px;
}