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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #16a34a;
    --danger-color: #dc2626;
    --warning-color: #d97706;
    --background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

body {
    font-family: 'Poppins', sans-serif;
    background: var(--background);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
.header {
    text-align: center;
    margin-bottom: 2rem;
    color: white;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo i {
    font-size: 2.5rem;
    color: #fbbf24;
}

.logo h1 {
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Main Content */
.main-content {
    flex: 1;
}

/* TTS Card */
.tts-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
    margin-bottom: 2rem;
}

/* Input Section */
.input-section {
    margin-bottom: 2rem;
}

.input-section label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.input-section label i {
    color: var(--primary-color);
}

#text-input {
    width: 100%;
    min-height: 150px;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    transition: all 0.3s ease;
    background: white;
}

#text-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.char-counter {
    text-align: right;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}


/* Controls Section */
.controls-section {
    margin-bottom: 2rem;
}

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

.control-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.control-group label i {
    color: var(--secondary-color);
    font-size: 0.9rem;
}

.control-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

select, input[type="range"] {
    width: 100%;
}

select {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s ease;
    line-height: 1.5;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Voice option styling */
select option:disabled {
    font-weight: 600 !important;
    color: #2563eb !important;
    background: #f0f9ff !important;
    font-size: 0.9rem !important;
    padding: 8px 0 2px 0 !important;
    border-bottom: 1px solid #e5e7eb !important;
}

select option:not(:disabled) {
    padding: 4px 8px !important;
    margin: 2px 0 !important;
}

/* Quality badges */
.quality-badge {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 12px;
    font-weight: 500;
    margin-left: 8px;
}

.quality-badge.premium {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
}

.quality-badge.standard {
    background: #e5e7eb;
    color: #6b7280;
}

.quality-badge.custom {
    background: linear-gradient(135deg, #dc2626, #ef4444);
    color: white;
    animation: pulse-gratis 2s infinite;
}

@keyframes pulse-gratis {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Voice info display */
.voice-info {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    display: none;
}

.voice-details {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.voice-name {
    font-weight: 600;
    color: var(--text-primary);
}

.voice-lang {
    background: var(--primary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.voice-gender {
    background: var(--secondary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.voice-gender.male {
    background: #3b82f6;
}

.voice-gender.female {
    background: #ec4899;
}

.voice-gender.neutral {
    background: var(--secondary-color);
}

input[type="range"] {
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: background 0.3s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: background 0.3s ease;
}


/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 120px;
    justify-content: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: white;
    border: 2px solid rgba(22, 163, 74, 0.2);
    position: relative;
    overflow: hidden;
}

.btn-success::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;
}

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

.btn-success:hover {
    background: linear-gradient(135deg, #15803d, #166534);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(22, 163, 74, 0.3);
    border-color: rgba(22, 163, 74, 0.4);
}

.btn-success:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Audio Player */
.audio-player {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--background);
    border-radius: 12px;
    display: none;
}

.audio-element {
    width: 100%;
}

/* Progress Section */
.progress-section {
    margin-bottom: 1.5rem;
    display: none;
}

/* Hidden buttons by default - TEMPORARILY ENABLE DOWNLOAD FOR TESTING */
#pause-btn,
#stop-btn {
    display: none;
}

#download-btn {
    display: flex; /* Always show download button for testing */
    opacity: 0.6;
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

#download-btn:hover {
    opacity: 1;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), #8b5cf6);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Features Section */
.features-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.feature-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease;
}

.feature-card:hover {
    transform: translateY(-5px);
}

.feature-card i {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.feature-card h3 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.feature-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Footer */
.footer {
    text-align: center;
    color: white;
    opacity: 0.9;
    margin-top: auto;
    padding-top: 2rem;
}

.footer i {
    color: #ef4444;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--success-color);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateX(0);
}

/* Error Toast Styles */
.toast.error-toast {
    background: var(--danger-color);
    max-width: 400px;
}

.toast.error-toast .toast-content {
    align-items: flex-start;
    gap: 1rem;
}

.toast.error-toast i {
    font-size: 1.5rem;
    color: white;
    flex-shrink: 0;
}

.toast.error-toast div {
    flex: 1;
    line-height: 1.4;
}

/* Fallback for browsers without flexbox */
@supports not (display: flex) {
    .toast-content {
        display: block;
    }

    .toast-content i {
        margin-right: 0.5rem;
        display: inline-block;
        vertical-align: middle;
    }
}

/* Loading state improvements */
.loading {
    pointer-events: none;
    opacity: 0.6;
    position: relative;
}

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

.toast-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    .logo {
        flex-direction: column;
        gap: 0.5rem;
    }

    .logo h1 {
        font-size: 2rem;
    }

    .tts-card {
        padding: 1.5rem;
    }

    .control-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        min-width: auto;
    }

    .features-section {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .toast {
        right: 20px;
        left: 20px;
        transform: translateY(100px);
    }

    .toast.show {
        transform: translateY(0);
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .logo h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .tts-card {
        padding: 1rem;
    }

    .bgm-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .toggle-switch {
        align-self: flex-end;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tts-card,
.features-section {
    animation: fadeIn 0.6s ease-out;
}

.feature-card {
    animation: fadeIn 0.8s ease-out;
    animation-fill-mode: both;
}

.feature-card:nth-child(1) {
    animation-delay: 0.2s;
}

.feature-card:nth-child(2) {
    animation-delay: 0.4s;
}

.feature-card:nth-child(3) {
    animation-delay: 0.6s;
}

/* Loading State */
.loading {
    pointer-events: none;
    opacity: 0.6;
}

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

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