/* ==========================================================================
   1. ROOT & THEME VARIABLES
   ========================================================================== */
:root {
    --font-primary: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-monospace: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;

    /* Border Radius Scale */
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 24px;

    /* Light Theme */
    --bg-color: #f0f2f5;
    --surface-color: #ffffff;
    --text-primary: #000;
    --text-secondary: #6e6e73;
    --text-tertiary: #8a8a8e;
    --border-color: #e1e4e8;
    --modal-bg: #ffffff;
    --icon-color: #555555;
    --accent-color: #003875;
    --alexa-color: #4361ee;
    --danger-bg: #d3271e;
    --danger-confirm-bg: #aa0000;
    --danger-text: #ffffff;
    --success-bg: #237c28;
    --success-text: #ffffff;
    --warn-bg: #ff9500;
    --warn-text: #ffffff;
    --settings-btn-bg: rgba(210, 210, 215, 0.65);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-strong: 0 15px 50px rgba(0, 0, 0, 0.15);
}

body.dark-mode {
    --bg-color: #000000;
    --surface-color: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a5;
    --text-tertiary: #5a5a5f;
    --border-color: #2c2c2e;
    --modal-bg: #121212;
    --icon-color: #e5e5e5;
    --accent-color: #0A84FF;
    --alexa-color: #5a7aff;
    --danger-bg: #d3271e;
    --danger-confirm-bg: #aa0000;
    --danger-text: #ffffff;
    --success-bg: #237c28;
    --success-text: #ffffff;
    --warn-bg: #ff9f0a;
    --warn-text: #ffffff;
    --settings-btn-bg: rgba(80, 80, 85, 0.65);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.1);
    --shadow-strong: 0 15px 50px rgba(0, 0, 0, 0.3);
}


/* ==========================================================================
   2. GLOBAL RESETS & BASE STYLES
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overscroll-behavior: none;
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    line-height: 1.5;
}


/* ==========================================================================
   3. LAYOUT & CORE COMPONENTS
   ========================================================================== */
main {
    flex-grow: 1;
    display: flex;
}

textarea#textInput {
    flex-grow: 1;
    width: 100%;
    border: none;
    resize: none;
    outline: none;
    background-color: transparent;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: clamp(1.7rem, 5.5vw, 2.5rem);
    line-height: 1.45;
    padding: max(20px, env(safe-area-inset-top)) 80px 280px 25px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

footer {
    position: fixed;
    inset: auto 0 0 0;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
    /*background-color: var(--surface-color);*/
    /*box-shadow: var(--shadow);*/
    z-index: 100;
    transition: background-color 0.3s ease;
    overflow: visible;
}


/* ==========================================================================
   4. BUTTONS & INTERACTIVE ELEMENTS
   ========================================================================== */
button,
[role="button"] {
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    outline: none;
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease, opacity 0.2s ease;
}

button:active {
    transform: scale(0.96);
}

.icon {
    width: 1.35em;
    height: 1.35em;
    fill: currentColor;
}

#playBtn, #pauseBtn {
    width: 100%;
    padding: 24px;
    border-radius: var(--radius-md);
    font-size: 1.4rem;
    background-color: var(--accent-color);
    color: var(--surface-color);
    font-weight: 700;
    gap: 12px;
    min-height: 77px;
    text-transform: uppercase;
    transition: opacity 0.2s ease;
}

#pauseBtn {
    position: absolute;
    inset: 12px 16px auto;
    background-color: var(--warn-bg);
}

#playBtn.speaking {
    background-color: var(--warn-bg);
    color: var(--warn-text);
    box-shadow: 0 4px 15px -2px #c87500;
}

#playBtn.waiting {
    opacity: 0.7;
    cursor: wait;
}

#clearBtn, #templatesBtn, #alexaBtn {
    position: fixed;
    z-index: 101;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    padding: 22px 32px;
    border-radius: var(--radius-md);
    font-size: 1.3rem;
    font-weight: 700;
    gap: 10px;
    min-height: 80px;
    transition: opacity 0.3s ease;
    min-width: 215px;
    text-transform: uppercase;
    justify-content: flex-start;
}

#clearBtn {
    inset: auto 16px calc(112px + env(safe-area-inset-bottom)) auto;
    background-color: var(--danger-bg);
    color: var(--danger-text);
}

#templatesBtn {
    inset: auto 16px calc(199px + env(safe-area-inset-bottom)) auto;
    background-color: var(--success-bg);
    color: var(--success-text);
}

#alexaBtn {
    inset: auto 16px calc(286px + env(safe-area-inset-bottom)) auto;
    background-color: var(--alexa-color);
    color: #ffffff;
}

#settingsBtn {
    position: fixed;
    inset: max(12px, env(safe-area-inset-top)) 12px auto auto;
    z-index: 1000;
    background: var(--settings-btn-bg);
    padding: 15px;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    min-width: 56px;
    min-height: 56px;
    transition: opacity 0.3s ease;
}

#settingsBtn svg {
    fill: var(--icon-color);
    width: 26px;
    height: 26px;
}

#restartBtn,
#forceUpdateBtn {
    padding: 8px;
    background: var(--accent-color);
    border-radius: var(--radius-sm);
    color: var(--surface-color);
}

#restartBtn .icon {
    width: 20px;
    height: 20px;
}

#forceUpdateBtn .icon {
    width: 20px;
    height: 20px;
}

.install-btn {
    width: 100%;
    padding: 16px;
    background-color: var(--accent-color);
    color: #ffffff;
    border-radius: var(--radius-md);
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.install-btn .icon {
    width: 22px;
    height: 22px;
    fill: #ffffff;
}


/* ==========================================================================
   5. MODAL & SETTINGS
   ========================================================================== */
.modal-overlay, .tmpl-modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.65);
    display: flex;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
}

.modal-overlay {
    z-index: 2000;
    align-items: center;
    transition: opacity 0.25s ease;
}

.tmpl-modal-overlay {
    z-index: 3000;
    align-items: flex-start;
    padding-top: 10vh;
    transition: opacity 0.2s ease;
}

.modal-overlay.active, .tmpl-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: var(--modal-bg);
    color: var(--text-primary);
    width: clamp(300px, 95vw, 600px);
    max-height: 90dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-strong);
    transform: scale(0.95) translateY(10px);
    transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1), background-color 0.3s ease;
    border: 1px solid var(--border-color);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

.version-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

#versionDisplay {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
    font-family: var(--font-monospace);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.setting-item.full-width {
    grid-column: 1 / -1;
}

.setting-item {
    background-color: var(--surface-color);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.setting-label {
    font-weight: 600;
    font-size: 0.95rem;
}

.toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
}

.tab-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 700;
    background-color: var(--bg-color);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.tab-btn.active {
    background-color: var(--accent-color);
    color: var(--surface-color);
    border-color: var(--accent-color);
}

.tab-content {
    display: none;
    overflow-y: auto;
    min-height: 0;
}

.tab-content.active {
    display: block;
}

.backup-stats {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 4px 14px;
}

.submenu-content .backup-info {
    margin-bottom: 0;
}

.submenu-content .toggle-container {
    padding: 0;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-value {
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-monospace);
}

/* Dictionary & Templates - Shared */
.dict-search-wrap {
    position: relative;
    margin-bottom: 8px;
}

.dict-search {
    width: 100%;
    padding: 12px 40px 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    font-family: inherit;
}

.dict-search:focus {
    border-color: var(--accent-color);
}

.dict-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border-radius: var(--radius-xs);
    background-color: var(--text-tertiary);
    color: var(--surface-color);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
}

.dict-info-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.dict-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: var(--font-monospace);
}

#tab-dictionary, #tab-templates, #tab-alexa {
    display: none;
    flex-direction: column;
}

#tab-dictionary.active, #tab-templates.active, #tab-alexa.active {
    display: flex;
    flex: 1;
}

.dict-list, .tmpl-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-color);
}

.dict-row, .tmpl-row {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
}

.dict-row { justify-content: space-between; }
.tmpl-row { gap: 8px; }

.dict-row:last-child, .tmpl-row:last-child {
    border-bottom: none;
}

.dict-word, .tmpl-text {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tmpl-text {
    flex: 1;
    cursor: pointer;
    padding: 4px 0;
}

.tmpl-text:hover {
    color: var(--accent-color);
}

.dict-row-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.dict-word-count {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    font-family: var(--font-monospace);
}

.dict-delete-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-xs);
    background-color: var(--danger-bg);
    color: var(--danger-text);
    font-size: 1.1rem;
    font-weight: 700;
    flex-shrink: 0;
}

.dict-empty, .tmpl-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.dict-clear-section {
    margin-top: 12px;
}

.dict-clear-btn {
    width: 100%;
    padding: 8px;
    border-radius: var(--radius-sm);
    background-color: var(--danger-bg);
    color: var(--danger-text);
    font-size: 0.85rem;
    font-weight: 600;
}

/* Template Management */
.tmpl-open-add-btn {
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-sm);
    background-color: var(--accent-color);
    color: var(--surface-color);
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.tmpl-modal {
    background-color: var(--modal-bg);
    border-radius: 16px;
    padding: 20px;
    width: clamp(280px, 90vw, 500px);
    box-shadow: var(--shadow-strong);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tmpl-modal .dict-search {
    font-size: 1.1rem;
    padding: 14px 16px;
}

.tmpl-modal-buttons {
    display: flex;
    gap: 10px;
}

.tmpl-modal-btn, .backup-btn {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 700;
    color: var(--surface-color);
}

.tmpl-cancel-btn {
    background-color: var(--text-tertiary);
}

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

.tmpl-edit-input {
    flex: 1;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    border: 2px solid var(--accent-color);
    background-color: var(--surface-color);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    outline: none;
    min-width: 0;
}

.tmpl-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.tmpl-move-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-xs);
    background-color: var(--accent-color);
    color: var(--surface-color);
    font-size: 1.1rem;
    font-weight: 700;
    flex-shrink: 0;
}

.tmpl-move-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.tmpl-delete-btn {
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    background-color: var(--danger-bg);
    color: var(--danger-text);
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-left: 10px;
    white-space: nowrap;
}

.tmpl-delete-btn.confirm {
    background-color: var(--danger-confirm-bg);
}

.backup-info {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    line-height: 1.5;
}

.backup-buttons {
    display: flex;
    gap: 10px;
}

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

.close-btn {
    width: 100%;
    padding: 16px;
    background-color: var(--success-bg);
    color: var(--success-text);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    margin-top: 20px;
    font-size: 1rem;
    font-weight: 700;
}


/* ==========================================================================
   6. FORM ELEMENTS & CUSTOM CONTROLS
   ========================================================================== */
select#voiceSelect {
    -webkit-appearance: none;
    appearance: none;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 0.9rem;
    color: var(--text-primary);
    width: 100%;
    outline: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23888'%3e%3cpath d='M8 11.25a.625.625 0 0 1-.442-.183l-3.5-3.5a.625.625 0 1 1 .884-.884L8 9.932l3.058-3.057a.625.625 0 0 1 .884.884l-3.5 3.5a.625.625 0 0 1-.442.183Z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    cursor: pointer;
}

/* Accordion/Submenu */
details.submenu {
    background-color: transparent;
}


summary.setting-label {
    cursor: pointer;
    padding: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    list-style: none;
}
summary.setting-label::-webkit-details-marker { display: none; }

.arrow-icon {
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
    fill: var(--text-tertiary);
}

details[open] > summary .arrow-icon {
    transform: rotate(180deg);
}

.submenu-content {
    padding: 14px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.submenu-section {
    background-color: var(--bg-color);
    border-radius: var(--radius-sm);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.submenu-section-title {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.submenu-section select#voiceSelect {
    background-color: var(--surface-color) !important;
}

.submenu-section input[type=range]::-webkit-slider-runnable-track {
    background-color: var(--surface-color);
}

/* Range Sliders */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.slider-group .setting-label {
    display: flex;
    justify-content: space-between;
}

.range-value {
    font-weight: 600;
    color: var(--accent-color);
    font-size: 0.9em;
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    margin: 6px 0;
    cursor: pointer;
    pointer-events: none;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: var(--bg-color);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 24px;
    width: 24px;
    border-radius: 50%;
    background: var(--accent-color);
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    margin-top: -10px;
    pointer-events: auto;
}

/* Toggle Switch */
.switch {
    position: relative;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.switch input { display: none; }

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    transition: background-color .3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 2px;
    top: 2px;
    background-color: var(--surface-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    transition: transform .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--success-bg);
    border-color: var(--success-bg);
}

input:checked + .slider:before {
    transform: translateX(20px);
}


/* ==========================================================================
   7. WORD SUGGESTIONS
   ========================================================================== */
#suggestions {
    display: none;
    position: absolute;
    bottom: 100%;
    right: 0;
    z-index: 101;
    grid-template-columns: auto auto;
    direction: rtl;
    gap: 8px;
    padding: 0 12px 8px 0;
}

#suggestions button {
    padding: 6px 14px;
    min-height: 50px;
    border-radius: var(--radius-md);
    background-color: var(--success-bg);
    color: var(--success-text);
    border: none;
    font-size: 1.75rem;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}


/* ==========================================================================
   8. TABLET LANDSCAPE OPTIMIZATIONS
   ========================================================================== */
@media (orientation: landscape) and (min-width: 768px) {
    textarea#textInput {
        font-size: clamp(1.75rem, 4vw, 2.5rem);
        padding: 25px 30px 300px 30px;
    }

    #playBtn {
        min-height: 86px;
        font-size: 1.35rem;
    }

    #clearBtn {
        font-size: 1.3rem;
        padding: 24px 36px;
    }

    #settingsBtn {
        padding: 12px;
    }

    #settingsBtn svg {
        width: 30px;
        height: 30px;
    }

    .modal-content {
        max-width: 700px;
        max-height: 85vh;
    }
}


.popup-backdrop {
    position: fixed;
    inset: 0;
    z-index: 149;
    background-color: rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   9. TEMPLATE POPUP & QUICK BUTTONS
   ========================================================================== */
.tmpl-quick-btn {
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 8px;
    background: var(--accent-color);
    color: var(--surface-color);
    border-radius: 10px;
    font-size: 1.6rem;
    font-weight: 700;
    text-align: left;
    min-height: 52px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.tmpl-popup {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 50%;
    background: var(--surface-color);
    border-radius: 0;
    padding: 16px;
    box-shadow: var(--shadow-strong);
    z-index: 150;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.tmpl-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.tmpl-popup-header h3 {
    font-size: 1.1rem;
    margin: 0;
}

#templateList, #alexaList {
    overflow-y: auto;
    flex-shrink: 1;
    min-height: 0;
}

.tmpl-popup-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
    flex-shrink: 0;
}

.tmpl-close-btn {
    padding: 16px 34px;
    background: var(--danger-bg);
    border-radius: var(--radius-md);
    color: var(--danger-text);
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    min-height: 70px;
}

.alexa-popup {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 50%;
    background: var(--surface-color);
    border-radius: 0;
    padding: 16px;
    box-shadow: var(--shadow-strong);
    z-index: 150;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}


/* ==========================================================================
   10a. TTS ERROR OVERLAY
   ========================================================================== */
#ttsErrorOverlay {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.7);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#ttsErrorOverlay.active {
    opacity: 1;
    pointer-events: auto;
}

#ttsErrorRestartBtn {
    padding: 24px 48px;
    background: var(--accent-color);
    color: var(--surface-color);
    border-radius: var(--radius-sm);
    font-size: inherit;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
}

#ttsErrorRestartBtn .icon {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* ==========================================================================
   10b. DEBUG OVERLAY (Floating Window)
   ========================================================================== */
#debugOverlay {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    width: min(672px, calc(100vw - 80px));
    max-height: 62vh;
    z-index: 10000;
    background-color: rgba(0, 0, 0, 0.92);
    color: #f0f0f0;
    font-family: var(--font-monospace);
    font-size: 0.75rem;
    line-height: 1.4;
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    flex-direction: column;
}

#debugOverlay.active {
    display: flex;
}

#debugOverlay .debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background-color: rgba(0, 0, 0, 0.95);
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#debugOverlay .debug-header:active {
    cursor: grabbing;
}

#debugOverlay .debug-header span {
    font-weight: 700;
    font-size: 0.8rem;
    pointer-events: none;
}

#debugOverlay .debug-close-btn {
    padding: 4px 12px;
    background-color: var(--danger-bg);
    color: #fff;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    min-height: 28px;
}

#debugOverlay .debug-filters {
    display: flex;
    gap: 4px;
    padding: 5px 10px;
    background-color: rgba(0, 0, 0, 0.9);
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    flex-wrap: wrap;
}

#debugOverlay .debug-filter-btn {
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-monospace);
    min-height: 26px;
    border: 1px solid #555;
    color: #888;
    background: transparent;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

#debugOverlay .debug-filter-btn.active {
    color: #fff;
    border-color: transparent;
}

#debugOverlay .debug-filter-btn.active[data-level="log"] { background-color: #555; }
#debugOverlay .debug-filter-btn.active[data-level="warn"] { background-color: #8a6d00; }
#debugOverlay .debug-filter-btn.active[data-level="error"] { background-color: #8b1a15; }
#debugOverlay .debug-filter-btn.active[data-level="dbg"] { background-color: #1a5c8b; }

#debugOverlay .debug-filter-clear {
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-monospace);
    min-height: 26px;
    margin-left: auto;
    color: #aaa;
    background: transparent;
    border: 1px solid #444;
}

#debugOverlay .debug-log {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

#debugOverlay .debug-entry {
    padding: 4px 10px;
    border-bottom: 1px solid #222;
    word-break: break-word;
}

#debugOverlay .debug-entry.log { color: #f0f0f0; }
#debugOverlay .debug-entry.warn { color: #ffd60a; }
#debugOverlay .debug-entry.error { color: #ff453a; }

#debugOverlay .debug-dbg-tag {
    color: #4da6ff;
}

#debugOverlay .debug-time {
    color: #888;
    margin-right: 6px;
}
