:root {
    --primary: #4361ee;
    --primary-hover: #3153e0;
    --success: #22c55e;
    --success-hover: #1db153;
    --background: #f0f4ff;
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-radius: 16px;
    --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Segoe UI', 'PingFang SC', system-ui, -apple-system, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 20px;
    background-image: radial-gradient(circle at 25% 30%, rgba(67, 97, 238, 0.07) 0%, transparent 80%);
}

/* GitHub Link in top-right corner */
.github-link {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001; /* Higher than modal backdrop */
    transition: transform 0.2s ease-in-out;
}

.github-link:hover {
    transform: scale(1.1);
}

.github-link svg {
    width: 32px;
    height: 32px;
    fill: var(--text-secondary);
    transition: fill 0.2s ease-in-out;
}

.github-link:hover svg {
    fill: var(--text-primary);
}

.page-switch-link {
    position: fixed;
    top: 20px;
    /* (GitHub icon right edge: 20px + GitHub icon width: 32px + spacing: 10px) = 62px from screen right for its own right edge */
    right: 62px;
    z-index: 1001;
    width: 36px; /* Define box width */
    height: 36px; /* Define box height */
    background: rgba(67, 97, 238, 0.08); /* Light background */
    border-radius: 8px; /* Rounded corners */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease-in-out, background-color 0.2s ease-in-out;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); /* Subtle shadow */
}

.page-switch-link:hover {
    transform: scale(1.1);
    background: rgba(67, 97, 238, 0.15); /* Darker on hover */
}

.page-switch-link svg {
    width: 20px; /* Adjust SVG size within the box */
    height: 20px;
    stroke: var(--primary); /* Use stroke for these icons, and primary color */
    fill: none; /* Ensure no fill if icons are purely stroke-based */
    transition: stroke 0.2s ease-in-out;
}

.page-switch-link:hover svg {
    stroke: var(--primary-hover); /* Darker stroke on hover */
}

.container {
    max-width: 680px;
    margin: 10px auto;
    padding: 0 10px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    animation: fadeIn 0.8s ease-out;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--primary) 0%, #7c4dff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    position: relative;
    display: inline-block;
}

h1::after {
    content: "";
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 4px;
    background: linear-gradient(90deg, var(--primary) 0%, #7c4dff 100%);
    border-radius: 8px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 32px;
    margin-bottom: 30px;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 22px;
    color: var(--text-primary);
}

/* Auth Section */
#authSection {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.verify-btn {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.25);
}

.verify-btn:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(245, 158, 11, 0.3);
}

.verify-btn.verified {
    background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
    box-shadow: 0 2px 6px rgba(34, 197, 94, 0.25);
}

.verify-btn.verified:hover {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    box-shadow: 0 3px 8px rgba(34, 197, 94, 0.3);
}

/* Icon Box */
.icon-box {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: rgba(67, 97, 238, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-box svg {
    width: 24px;
    height: 24px;
    stroke: var(--primary);
}

.icon-box.success {
    background: rgba(34, 197, 94, 0.1);
}
.icon-box.success svg {
     stroke: var(--success);
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Buttons */
.btn {
    background: linear-gradient(135deg, var(--primary) 0%, #6d5ef9 100%);
    color: white;
    border: none;
    padding: 14px 36px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.2);
}

.btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(67, 97, 238, 0.3);
}

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

/* Status Indicator */
#status {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
    font-size: 1.05rem;
    color: var(--text-primary);
    opacity: 0;
    height: 0;
    transition: all 0.3s;
}

#status.active {
    opacity: 1;
    height: auto;
    padding-top: 20px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(67, 97, 238, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* --- STT (index.html) Specific Styles --- */

/* Cache Notice (STT) */
.cache-notice {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border: 1px solid #86efac;
    border-radius: 12px;
    padding: 16px 20px;
    margin: 16px 0;
    display: none;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    color: #166534;
    animation: slideDown 0.3s ease-out;
}
.cache-notice.visible { display: flex; }
.cache-notice-icon {
    width: 20px; height: 20px; border-radius: 50%; background: #22c55e;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.cache-notice-icon svg { width: 12px; height: 12px; stroke: white; stroke-width: 2.5; }

/* Cache Button (STT) */
.cache-btn {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer;
    font-size: 0.85rem; font-weight: 500; transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(139, 92, 246, 0.25); margin-left: 8px;
}
.cache-btn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    transform: translateY(-1px); box-shadow: 0 3px 8px rgba(139, 92, 246, 0.3);
}

/* Modal (STT) */
.modal {
    display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px);
}
.modal.active { display: flex; align-items: center; justify-content: center; animation: fadeIn 0.2s ease-out; }
.modal-content {
    background: white; border-radius: 16px; padding: 24px; max-width: 90vw; max-height: 80vh;
    overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.3); animation: slideUp 0.3s ease-out; position: relative;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px;
    padding-bottom: 12px; border-bottom: 1px solid #e2e8f0;
}
.modal-header h3 { font-size: 1.25rem; font-weight: 600; color: var(--text-primary); }
.close-btn {
    background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary);
    padding: 4px; border-radius: 4px; transition: all 0.2s;
}
.close-btn:hover { background: #f1f5f9; color: var(--text-primary); }

/* Cache Table (STT) */
.cache-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.cache-table th, .cache-table td { padding: 12px; text-align: left; border-bottom: 1px solid #e2e8f0; }
.cache-table th { background: #f8fafc; font-weight: 600; color: var(--text-primary); font-size: 0.85rem; }
.cache-table td { font-size: 0.85rem; color: var(--text-secondary); }
.cache-table tr:hover { background: #f8fafc; }
.cache-actions { display: flex; gap: 8px; }
.action-btn { padding: 4px 8px; border: none; border-radius: 4px; font-size: 0.8rem; cursor: pointer; transition: all 0.2s; }
.restore-btn { background: #ddd6fe; color: #7c3aed; }
.restore-btn:hover { background: #c4b5fd; }
.delete-btn { background: #fecaca; color: #dc2626; }
.delete-btn:hover { background: #fca5a5; }
.text-preview { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; title: attr(data-full-text); }
.empty-cache { text-align: center; padding: 40px; color: var(--text-secondary); }
.clear-all-btn {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); color: white; border: none;
    padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; font-weight: 500;
    transition: all 0.2s; margin-top: 16px;
}
.clear-all-btn:hover { background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%); transform: translateY(-1px); }

/* Audio Extraction Notice (STT) */
.audio-extraction-notice {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%); border: 1px solid #f59e0b;
    border-radius: 12px; padding: 16px 20px; margin: 16px 0; display: none; align-items: center;
    gap: 12px; font-size: 0.9rem; color: #92400e; animation: slideDown 0.3s ease-out;
}
.audio-extraction-notice.visible { display: flex; }
.audio-extraction-notice .spinner { /* Specific styling for this spinner, inherits animation from .spinner */
    width: 20px; height: 20px; border: 2px solid rgba(245, 158, 11, 0.3); border-top-color: #f59e0b;
}

/* File Formats (STT) */
.file-formats { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 22px; }
.format-row { display: flex; gap: 0.5rem; }
.format-tag {
    background: rgba(67, 97, 238, 0.08); color: var(--primary); padding: 6px 12px;
    border-radius: 8px; font-size: 0.85rem; font-weight: 500;
}
.format-tag.audio { background-color: #e8f5e9; color: #2e7d32; }
.format-tag.convert.audio { background-color: #fff3e0; color: #e65100; }
.format-tag.convert.video { background-color: #e3f2fd; color: #0d47a1; }

/* File Upload Area (STT) */
.file-upload-area {
    border: 2px dashed #c7d2fe; border-radius: 12px; padding: 16px 20px; display: flex;
    align-items: center; justify-content: center; gap: 16px; transition: all 0.3s;
    background: rgba(247, 249, 254, 0.6); margin-bottom: 1px; position: relative;
}
.file-upload-area:hover { border-color: var(--primary); background: rgba(67, 97, 238, 0.03); }
.upload-icon {
    width: 40px; height: 40px; background: rgba(67, 97, 238, 0.1); border-radius: 10px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.upload-icon svg { width: 24px; height: 24px; stroke: var(--primary); }
.upload-text { color: var(--text-secondary); font-size: 0.95rem; white-space: nowrap; flex-shrink: 0; }
#fileInputLabel {
    display: inline-block; background: var(--primary); color: white; padding: 8px 20px;
    border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 0.9rem;
    transition: all 0.2s; box-shadow: 0 3px 8px rgba(67, 97, 238, 0.25); flex-shrink: 0;
}
#fileInputLabel:hover {
    background: var(--primary-hover); transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.3);
}
#fileName { margin-top: 8px; font-size: 0.85rem; color: var(--text-secondary); text-align: center; }

/* STT Result Area */
.result-container { /* Wrapper for STT result box */
    padding: 8px 0;
}
#result-box { overflow: hidden; max-height: 0; transition: max-height 0.5s ease; }
#result-box.active { max-height: 350px; }
#result {
    width: 100%; min-height: 220px; padding: 24px; border-radius: 16px; border: 2px solid transparent;
    background: linear-gradient(145deg, #ffffff 0%, #fafbff 100%); background-clip: padding-box;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.08), inset 0 0 0 1px rgba(67,97,238,0.12),
                0 4px 12px rgba(0,0,0,0.05), 0 1px 3px rgba(0,0,0,0.08);
    font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.95rem; line-height: 1.75; color: var(--text-primary); resize: vertical;
    transition: all 0.3s ease; position: relative; backdrop-filter: blur(4px);
}
#result:focus {
    outline: none; border-color: var(--primary);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.08), inset 0 0 0 1px var(--primary),
                0 0 0 4px rgba(67,97,238,0.15), 0 8px 25px rgba(67,97,238,0.15),
                0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}
#result::placeholder { color: #9ca3af; font-style: italic; opacity: 0.8; }
#result::-webkit-scrollbar { width: 8px; }
#result::-webkit-scrollbar-track { background: rgba(67, 97, 238, 0.05); border-radius: 8px; }
#result::-webkit-scrollbar-thumb { background: linear-gradient(135deg, var(--primary) 0%, #7c4dff 100%); border-radius: 8px; transition: all 0.2s; }
#result::-webkit-scrollbar-thumb:hover { background: linear-gradient(135deg, var(--primary-hover) 0%, #6b46c1 100%); }
#result::selection { background: rgba(67, 97, 238, 0.2); color: inherit; }

#copyBtn {
    background: linear-gradient(135deg, var(--success) 0%, #00b894 100%); padding: 10px 16px;
    border-radius: 8px; box-shadow: 0 4px 10px rgba(34, 197, 94, 0.25); display: inline-flex;
    align-items: center; gap: 6px; font-size: 0.9rem; color: white; border: none; cursor: pointer;
}
#copyBtn.hidden { opacity: 0; visibility: hidden; }
#timer { font-variant-numeric: tabular-nums; font-weight: 600; }


/* --- TTS (tts.html) Specific Styles --- */

/* Form Elements (TTS) */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 8px; color: var(--text-secondary); }
.form-group textarea, .form-group select {
    width: 100%; padding: 12px; border-radius: 8px; border: 1px solid #d1d5db;
    background: #f9fafb; font-size: 0.95rem; transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group textarea:focus, .form-group select:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}
.form-group textarea { min-height: 120px; resize: vertical; }
#charCount { font-size: 0.8rem; color: var(--text-secondary); text-align: right; margin-top: 4px; }

/* Parameter Controls Layout (TTS) */
.parameter-controls-row { display: flex; gap: 20px; margin-bottom: 20px; }
.parameter-controls-row .form-group { flex: 1; margin-bottom: 0; }

/* TTS Result Area (uses ID for specificity) */
#resultContainer { /* This is the div with id="resultContainer" and class="card" in tts.html */
    margin-top: 20px; opacity: 0; max-height: 0; overflow: hidden;
    transition: opacity 0.5s ease, max-height 0.5s ease;
}
#resultContainer.active { opacity: 1; max-height: 500px; }
#audioPlayer { width: 100%; margin-bottom: 15px; }
#downloadBtn {
    background: linear-gradient(135deg, var(--success) 0%, #00b894 100%); padding: 10px 16px;
    border-radius: 8px; box-shadow: 0 4px 10px rgba(34, 197, 94, 0.25); display: inline-flex;
    align-items: center; gap: 6px; font-size: 0.9rem; color: white; border: none;
    cursor: pointer; text-decoration: none; opacity: 0; visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
#downloadBtn.visible { opacity: 1; visibility: visible; }


/* --- Animations (Common) --- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }


/* --- Responsive Design (Combined) --- */
@media (max-width: 768px) {
    .github-link { top: 15px; right: 15px; }
    .github-link svg { width: 28px; height: 28px; }
    .page-switch-link {
        top: 15px; /* Align with GitHub link */
        /* (GitHub mobile right edge: 15px + GitHub mobile width: 28px + spacing: 8px) = 51px from screen right */
        right: 51px;
        width: 32px; /* Smaller box on mobile */
        height: 32px;
        border-radius: 6px;
    }
    .page-switch-link svg {
        width: 18px; /* Smaller SVG on mobile */
        height: 18px;
    }
    .card-header {
        flex-direction: column;
        align-items: center; 
        justify-content: flex-start; 
        gap: 16px;
        text-align: center; 
    }
    
    .container { margin: 20px auto; }
    .card { padding: 22px; }
    h1 { font-size: 2rem; }
    .btn { width: 100%; justify-content: center; padding: 14px; }
    .verify-btn { padding: 5px 12px; font-size: 0.8rem; }
    .icon-box { display: none; } /* Hides icon-box on mobile for both pages */

    /* STT Specific Responsive */
    .modal-content { margin: 20px; max-width: calc(100vw - 40px); }
    .cache-table { font-size: 0.8rem; }
    .cache-table th, .cache-table td { padding: 8px 6px; }
    .text-preview { max-width: 120px; }
    .file-upload-area { flex-direction: column; padding: 16px; gap: 8px; }
    .upload-text { white-space: normal; text-align: center; font-size: 0.9rem; }
    #result { min-height: 180px; padding: 20px; font-size: 0.9rem; }
    .cache-btn { padding: 5px 12px; font-size: 0.8rem; }
    .upload-icon { width: 36px; height: 36px; }
    #fileInputLabel { padding: 6px 16px; font-size: 0.85rem; }
    .file-formats { flex-direction: row; flex-wrap: wrap; gap: 0.5rem; }
    .format-row { display: contents; }

    /* TTS Specific Responsive */
    .parameter-controls-row { flex-direction: column; gap: 0; }
    .parameter-controls-row .form-group { margin-bottom: 20px; }
    .parameter-controls-row .form-group:last-child { margin-bottom: 0; }
}