/* Modern CSS Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* CSS Variables - Modern Color Palette */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    
    /* Glass morphism colors */
    --glass-bg: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.18);
    --glass-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
    
    /* Backgrounds */
    --background-primary: linear-gradient(135deg, #fed7e2 0%, #fbb6ce 15%, #c084fc 30%, #a78bfa 45%, #60a5fa 60%, #fb923c 80%, #fef3c7 100%);
    --background-secondary: #f8fafc;
    --background-card: rgba(252, 248, 243, 0.95);
    
    /* Text colors */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    
    /* Border and spacing */
    --border-radius: 16px;
    --border-radius-lg: 24px;
    --border-radius-sm: 12px;
    --spacing: 1rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Base Styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--background-primary);
    min-height: 100vh;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Header with glass effect */
header {
    width: 100%;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--glass-bg) !important;
    border-bottom: 1px solid var(--glass-border) !important;
    box-shadow: var(--shadow-sm) !important;
    position: sticky !important;
    top: 0;
    z-index: 100;
}

header nav {
    padding: 1rem var(--spacing-lg) !important;
}

/* Header navigation links */
header nav a {
    transition: all 0.3s ease;
    border-radius: var(--border-radius-sm);
    padding: 0.5rem 1rem;
    color: var(--text-primary) !important;
    text-decoration: none !important;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

header nav a:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Auth links styling */
#auth-links a {
    color: var(--text-primary) !important;
    text-decoration: none !important;
    font-weight: 500;
    padding: 0.4rem 0.8rem;
    border-radius: var(--border-radius-sm);
    transition: all 0.3s ease;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

#auth-links a:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

/* Main container with glass card effect */
.container {
    max-width: 900px;
    margin: 2rem auto;
    padding: 0 2rem;
    background: var(--background-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.125);
    position: relative;
    overflow: hidden;
}

.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
}

h1, h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
    letter-spacing: -0.025em;
}

h1 {
    font-size: 2.5rem;
}

h2 {
    font-size: 1.875rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
    letter-spacing: 0.025em;
}

.form-control {
    width: 100%;
    padding: 1rem 1.25rem;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    color: var(--text-primary);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06), inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06), inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 0 0 4px rgba(99, 102, 241, 0.1);
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.95);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236366f1' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1.25rem center;
    padding-right: 3rem;
    cursor: pointer;
}

/* Prevent dropdown arrow from animating */
select.form-control:focus {
    transform: none !important;
}

textarea.form-control {
    resize: vertical;
    min-height: 120px;
    font-family: inherit;
    line-height: 1.6;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.025em;
    min-height: 52px;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    filter: brightness(1.05);
}

.btn-secondary {
    background: rgba(100, 116, 139, 0.9);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: rgba(100, 116, 139, 1);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: var(--shadow-sm) !important;
}

/* Button container */
.button-status-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.25rem;
    flex-wrap: wrap;
}

/* Input Section */
.input-section {
    margin-bottom: 0.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

/* Audio Section */
.audio-section {
    margin-top: 0.25rem;
    padding-top: 0.25rem;
}

audio {
    width: 100%;
    margin-bottom: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    background: rgba(255, 255, 255, 0.5);
}

/* Progress Bar */
.progress-container {
    margin: 0.25rem 0 0.5rem 0;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), #34d399);
    border-radius: 6px;
    transition: width 0.3s ease;
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-text {
    text-align: center;
    margin-top: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Status Messages */
.status-message {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-weight: 500;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: fadeInUp 0.3s ease;
    font-size: 0.875rem;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.status-message.error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error-color);
    border-color: rgba(239, 68, 68, 0.3);
}

.status-message.success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success-color);
    border-color: rgba(16, 185, 129, 0.3);
}

/* Hide empty status messages */
.status-message:empty {
    display: none !important;
}

/* Download Button - Mobile Only */
#download-button {
    display: none !important;
}

/* Glass Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box;
    overflow: hidden;
}

/* Ensure specific modals always take full viewport */
#paywall-modal,
#purchase-success-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal[style*="display: flex"] {
    display: flex !important;
}

.modal-content {
    background: var(--glass-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    padding: var(--spacing-xl);
    border-radius: var(--border-radius-lg);
    max-width: 480px;
    width: 90%;
    margin: 0;
    position: relative;
    box-shadow: var(--glass-shadow);
    border: 1px solid var(--glass-border);
    animation: slideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Close button styling */
.modal-content > span {
    position: absolute !important;
    top: 20px !important;
    right: 24px !important;
    font-size: 1.75rem !important;
    cursor: pointer !important;
    color: var(--text-secondary) !important;
    transition: all 0.3s ease !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
}

.modal-content > span:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    transform: scale(1.1) !important;
    color: var(--text-primary) !important;
}

/* Usage display styling */
#usage-display {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.025em;
    margin-left: 1rem;
    transition: all 0.3s ease;
    cursor: default;
    text-shadow: none;
}

#usage-display.can-generate {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success-color);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

#usage-display.upgrade-needed {
    background: #f97316;
    color: white;
    border: 1px solid #ea580c;
    cursor: pointer;
}

#usage-display.upgrade-needed:hover {
    background: #ea580c;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.4);
}

#usage-display.first-free {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-color);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

/* Mobile usage display - moves below header */
@media (max-width: 768px) {
    #usage-display {
        position: fixed;
        top: 70px; /* Below header */
        right: 1rem;
        z-index: 99;
        margin-left: 0;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
}

/* Account dropdown improvements */
#account-dropdown, #account-modal {
    max-height: 300px !important;
    overflow-y: auto;
    min-height: auto !important;
    height: auto !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        margin: 1rem;
        padding: 1.5rem;
        border-radius: var(--border-radius);
    }
    
    body > div:not(.container):not(.modal),
    footer {
        margin: 1rem;
        padding: 1rem;
    }
    
    header nav {
        padding: 1rem !important;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    .btn {
        width: 100%;
        margin-bottom: 0.75rem;
    }
    
    .button-status-container {
        flex-direction: column;
        align-items: stretch;
    }
    
    /* Show download button only on mobile when audio is available */
    #download-button.show-mobile {
        display: block !important;
        margin-top: 0.75rem;
    }
    
    .modal-content {
        margin: 0;
        padding: 1.5rem;
        max-width: calc(100vw - 2rem);
        width: calc(100% - 2rem);
    }
}

@media (max-width: 480px) {
    :root {
        --border-radius-lg: 20px;
    }
    
    body {
        font-size: 14px;
    }
    
    .container {
        margin: 0.5rem;
        padding: 1rem;
    }
    
    body > div:not(.container):not(.modal),
    footer {
        margin: 0.5rem;
        padding: 0.75rem;
    }
    
    .modal-content {
        margin: 0;
        width: calc(100% - 1rem);
        max-width: calc(100vw - 1rem);
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Focus styles */
.btn:focus,
.form-control:focus,
button:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Loading states */
.btn.loading {
    color: transparent;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin-left: -10px;
    margin-top: -10px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Footer and external content styling */
hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1), transparent);
    margin: 2rem 0 1.5rem 0;
}

/* Description text below main container */
body > div:not(.container):not(.modal) {
    max-width: 800px;
    margin: 0 auto 2rem auto;
    padding: 1.5rem 2rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Footer styling */
footer {
    max-width: 800px;
    margin: 1.5rem auto;
    padding: 1rem 2rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
}

footer a:hover {
    background: rgba(99, 102, 241, 0.1);
    transform: translateY(-1px);
}