:root {
    /* Light Mode Tokens */
    --bg-color: #f3f4f6;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --panel-bg: rgba(255, 255, 255, 0.7);
    --panel-border: rgba(255, 255, 255, 0.4);
    --input-bg: rgba(255, 255, 255, 0.9);
    --input-border: #d1d5db;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --blob-1: rgba(99, 102, 241, 0.4);
    --blob-2: rgba(168, 85, 247, 0.4);
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
}

[data-theme="dark"] {
    /* Dark Mode Tokens */
    --bg-color: #0d1117;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(15, 23, 42, 0.8);
    --input-border: #334155;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --blob-1: rgba(99, 102, 241, 0.2);
    --blob-2: rgba(168, 85, 247, 0.2);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Cairo', 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
    transition: background-color 0.5s ease, color 0.5s ease;
}

/* Background Blobs (Dynamic Aesthetic) */
.blob {
    position: absolute;
    filter: blur(80px);
    z-index: -1;
    border-radius: 50%;
    animation: float 10s infinite ease-in-out alternate;
}
.blob-1 {
    top: -10%;
    right: -10%;
    width: 400px;
    height: 400px;
    background: var(--blob-1);
    animation-delay: 0s;
}
.blob-2 {
    bottom: -10%;
    left: -10%;
    width: 350px;
    height: 350px;
    background: var(--blob-2);
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(30px) scale(1.1); }
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    padding: 40px;
    width: 100%;
    max-width: 600px;
    box-shadow: var(--shadow);
    z-index: 10;
}

header {
    margin-bottom: 30px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.5;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.icon-btn:hover {
    background-color: var(--input-bg);
}

.hidden {
    display: none !important;
}

/* Form Elements */
.input-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
    gap: 8px;
}

.input-row {
    display: flex;
    gap: 20px;
}
.input-row .input-group {
    flex: 1;
}

label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

textarea, select, input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 16px;
    padding: 14px;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
}

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

textarea:focus, select:focus, input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Primary Button */
.primary-btn {
    width: 100%;
    background: var(--accent);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.primary-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

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

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

/* Spinner */
.spinner {
    border: 3px solid rgba(255,255,255,0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

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

/* Results & Audio */
#result-container {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    gap: 15px;
    animation: slideUp 0.5s ease;
}

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

audio {
    width: 100%;
    height: 40px;
    outline: none;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

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

.error-toast {
    margin-top: 20px;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid #ef4444;
    color: #ef4444;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}

/* Responsive */
@media (max-width: 640px) {
    .glass-panel {
        margin: 20px;
        padding: 24px;
        border-radius: 20px;
    }
    
    .input-row {
        flex-direction: column;
        gap: 0;
    }
}

/* Voice Selector Custom UI */
.relative-group {
    position: relative;
}

.custom-select-btn {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    text-align: right;
    transition: all 0.3s ease;
    min-height: 58px;
}

.custom-select-btn:hover {
    border-color: var(--accent);
}

.voice-btn-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 15px;
    flex-shrink: 0;
}

.voice-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.voice-name {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 14.5px;
}

.voice-gender {
    font-size: 12px;
    color: var(--text-secondary);
}

.dropdown-icon {
    color: var(--text-secondary);
}

/* Modal Overlay Dropdown */
.voice-selector-modal {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    margin-top: 8px;
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    z-index: 100;
    overflow: hidden;
    animation: fadeIn 0.2s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--panel-border);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    background: rgba(0,0,0,0.02);
}

.close-btn {
    padding: 4px;
    color: var(--text-secondary);
}

.voice-list {
    max-height: 280px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Scrollbar tweaks for modal */
.voice-list::-webkit-scrollbar {
    width: 6px;
}
.voice-list::-webkit-scrollbar-track {
    background: transparent;
}
.voice-list::-webkit-scrollbar-thumb {
    background: var(--panel-border);
    border-radius: 10px;
}

.voice-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--panel-border);
    transition: background-color 0.2s;
}

.voice-item:last-child {
    border-bottom: none;
}

.voice-item:hover, .voice-item.active {
    background: rgba(99, 102, 241, 0.08);
}

.voice-item-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.checkmark {
    color: var(--text-secondary);
    display: none;
}

.voice-item.active .checkmark {
    display: block;
    color: var(--accent);
}

/* Audio Preview Animation */
.preview-audio-anim {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 15px;
    margin-right: 15px;
}

.preview-audio-anim span {
    display: block;
    width: 3px;
    height: 3px;
    background: var(--accent);
    border-radius: 3px;
    animation: eq 0.8s infinite alternate;
}

.preview-audio-anim span:nth-child(1) { animation-delay: 0.1s; }
.preview-audio-anim span:nth-child(2) { animation-delay: 0.3s; }
.preview-audio-anim span:nth-child(3) { animation-delay: 0.5s; }

@keyframes eq {
    0% { height: 3px; }
    100% { height: 14px; }
}

/* Voice item right-side (preview + checkmark) */
.voice-item-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Preview play button inside modal */
.preview-btn {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--accent);
    transition: background 0.2s, transform 0.15s;
    padding: 0;
}

.preview-btn:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.1);
}

/* Open state: rotate dropdown chevron */
.custom-select-btn.open .dropdown-icon {
    transform: rotate(180deg);
    transition: transform 0.25s ease;
}

.dropdown-icon {
    transition: transform 0.25s ease;
    flex-shrink: 0;
}
