:root {
    --primary-color: #312e81; /* Deep Indigo */
    --primary-hover: #1e1b4b;
    --accent-color: #8b5cf6; /* Electric Violet */
    --bg-color: #0f172a; /* Slate 950 */
    --card-bg: #1e293b; /* Slate 800 */
    --text-main: #f1f5f9; /* Slate 100 */
    --text-muted: #94a3b8; /* Slate 400 */
    --border-color: #334155; /* Slate 700 */
    --radius: 16px;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at top center, #1e1b4b 0%, #0f172a 100%);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.main-wrapper {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: auto 0;
}

.hero-section {
    text-align: center;
    margin-bottom: 0px;
}

.hero-section h1 {
    font-size: 2.8rem;
    background: linear-gradient(to right, #a78bfa, #8b5cf6, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
    letter-spacing: -2px;
}

.hero-subtitle {
    color: var(--text-muted);
    font-size: 1.15rem;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.4;
}

.yt-container, .tts-container {
    background: var(--card-bg);
    width: 100%;
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    height: fit-content;
    transition: transform 0.2s ease;
}

.yt-container h2, .tts-container h2 {
    font-size: 1.2rem;
    color: #a78bfa;
    margin-bottom: 4px;
    font-weight: 700;
    text-align: center;
}

.yt-input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.field-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-left: 4px;
}

.mode-selection {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 8px;
}

.mode-option {
    cursor: pointer;
}

.mode-option input {
    display: none;
}

.mode-card {
    background: rgba(15, 23, 42, 0.5);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    padding: 10px;
    text-align: center;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mode-option input:checked + .mode-card {
    border-color: var(--accent-color);
    background: rgba(139, 92, 246, 0.1);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.2);
}

.mode-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-main);
}

.mode-desc {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.yt-input-group input {
    width: 100%;
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 2px solid var(--border-color);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.yt-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.yt-input-group input:focus {
    border-color: var(--primary-color);
}

#fetchYoutubeBtn, #fetchAndDownloadBtn {
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s, transform 0.1s;
}

#fetchYoutubeBtn {
    background: var(--text-muted);
}

#fetchYoutubeBtn:hover {
    background: #444;
}

#fetchAndDownloadBtn {
    background: var(--accent-color);
}

#fetchAndDownloadBtn:hover {
    background: var(--primary-color);
}

#fetchYoutubeBtn:disabled, #fetchAndDownloadBtn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

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

#fetchAndDownloadBtn.loading .spinner, #fetchYoutubeBtn.loading .spinner {
    display: block;
}

.yt-status {
    margin-top: 10px;
    font-size: 0.85rem;
    text-align: center;
    min-height: 18px;
    color: var(--text-muted);
}

.feature-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    text-align: center;
    margin-top: 4px;
    opacity: 0.8;
}

header {
    margin-bottom: 12px;
    text-align: left;
}

h1 {
    font-size: 1.6rem;
    color: var(--primary-color);
    margin-bottom: 4px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.3;
}

.input-group {
    margin-bottom: 12px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

textarea {
    width: 100%;
    min-height: 150px;
    padding: 16px;
    border-radius: var(--radius);
    border: 2px solid var(--border-color);
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    background: #0f172a;
    color: #f1f5f9;
}

textarea:focus {
    border-color: var(--accent-color);
    background: #1e293b;
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.2);
}

.controls {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 15px;
    align-items: flex-end;
}

.voice-speed-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.speed-control {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.speed-control label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.speed-control input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    accent-color: var(--accent-color);
    cursor: pointer;
}

select {
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background-color: #0f172a;
    font-size: 0.95rem;
    color: var(--text-main);
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2394a3b8%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 50%;
    background-size: 10px auto;
}

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

.btn-generate {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

.btn-generate:hover {
    background: var(--primary-hover);
}

.btn-generate:active {
    transform: scale(0.98);
}

.btn-generate:disabled {
    background: #a0a0a0;
    cursor: not-allowed;
    transform: none;
}

.result-area {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    display: none;
    flex-direction: column;
    gap: 15px;
    animation: fadeIn 0.4s ease-out;
}

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

#audioPlayer {
    width: 100%;
    height: 40px;
}

.btn-download {
    background: #2e7d32;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-download:hover {
    background: #1b5e20;
}

.btn-download:active {
    transform: scale(0.98);
}

#status {
    margin-top: 15px;
    font-size: 0.9rem;
    text-align: center;
    min-height: 20px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.progress-container {
    width: 100%;
    height: 24px;
    background-color: #0f172a;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    display: none;
    margin-top: 10px;
    position: relative;
    isolation: isolate;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    transition: width 0.3s ease-out;
}

.progress-percent {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    mix-blend-mode: difference;
    pointer-events: none;
    z-index: 2;
}

.status-error {
    color: #d32f2f !important;
}

.status-success {
    color: #2e7d32 !important;
}

/* Spinner for loading state */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    display: none;
}

.btn-generate.loading .spinner {
    display: block;
}

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

/* Mobile responsiveness */
@media (max-width: 480px) {
    .controls {
        grid-template-columns: 1fr;
    }

    .yt-actions {
        grid-template-columns: 1fr;
    }
    
    .yt-container, .tts-container {
        padding: 20px;
        margin: 0;
        max-width: 100%;
        height: auto;
        min-height: 0;
    }

    textarea {
        min-height: 150px;
    }
}