/* TTS Controls Sidebar Styles */
#tts-sidebar {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #2c2416 0%, #4a3f2f 100%);
    color: #f5f5f5;
    padding: 20px;
    border-radius: 10px 0 0 10px;
    box-shadow: -5px 0 20px rgba(0,0,0,0.3);
    transition: right 0.3s ease;
    z-index: 1000;
    width: 300px;
    font-family: 'Georgia', serif;
}

#tts-sidebar.collapsed {
    right: -340px;
}

#tts-toggle {
    position: absolute;
    left: -40px;
    top: 50%;
    transform: translateY(-50%);
    background: #2c2416;
    color: #d4af37;
    border: none;
    padding: 15px 10px;
    cursor: pointer;
    border-radius: 10px 0 0 10px;
    font-size: 20px;
    box-shadow: -3px 0 10px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
    /* Ensure adequate touch target size */
    min-width: 44px;
    min-height: 44px;
    /* Prevent text selection */
    -webkit-user-select: none;
    user-select: none;
    /* Improve touch response */
    -webkit-tap-highlight-color: rgba(212, 175, 55, 0.3);
    touch-action: manipulation;
    /* Ensure it's clickable */
    z-index: 1001;
}

#tts-toggle:hover,
#tts-toggle:active {
    background: #4a3f2f;
    left: -43px;
}

.tts-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 15px;
    text-align: center;
    color: #d4af37;
    border-bottom: 2px solid #d4af37;
    padding-bottom: 10px;
    width: 100%;
    letter-spacing: 2px;
    font-family: 'Cinzel', 'Georgia', serif;
}

.tts-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    justify-content: center;
}

.tts-btn {
    background: #d4af37;
    color: #2c2416;
    border: none;
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 5px;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.2s ease;
}

.tts-btn:hover {
    background: #f0d577;
    transform: translateY(-2px);
    box-shadow: 0 3px 8px rgba(212, 175, 55, 0.4);
}

.tts-btn:disabled {
    background: #666;
    cursor: not-allowed;
    transform: none;
}

.tts-setting {
    margin-bottom: 15px;
}

.tts-label {
    display: block;
    margin-bottom: 5px;
    font-size: 12px;
    color: #d4af37;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tts-select, .tts-range {
    width: 100%;
    padding: 8px;
    background: #1a1410;
    color: #f5f5f5;
    border: 1px solid #4a3f2f;
    border-radius: 5px;
    font-size: 13px;
}

.tts-range {
    padding: 5px;
}

.tts-status {
    margin-top: 15px;
    padding: 10px;
    background: #1a1410;
    border-radius: 5px;
    font-size: 12px;
    text-align: center;
    min-height: 40px;
    color: #b8b8b8;
}

.tts-status.reading {
    color: #d4af37;
    font-weight: bold;
}

/* Background Music Controls */
.music-control {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #4a3f2f;
}

.music-btn {
    width: 100%;
    background: linear-gradient(135deg, #6b5b4f 0%, #8b7b6b 100%);
    color: #f5f5f5;
    border: 1px solid #d4af37;
    padding: 12px 15px;
    cursor: pointer;
    border-radius: 5px;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.3s ease;
    font-family: 'Georgia', serif;
}

.music-btn:hover {
    background: linear-gradient(135deg, #8b7b6b 0%, #a89b8b 100%);
    box-shadow: 0 3px 10px rgba(212, 175, 55, 0.3);
}

.music-btn.playing {
    background: linear-gradient(135deg, #2e5a3a 0%, #4a8b5a 100%);
    border-color: #7cfc00;
    animation: musicPulse 2s ease-in-out infinite;
}

@keyframes musicPulse {
    0%, 100% { box-shadow: 0 0 5px rgba(124, 252, 0, 0.3); }
    50% { box-shadow: 0 0 15px rgba(124, 252, 0, 0.6); }
}

.music-volume {
    margin-top: 10px;
}

.music-info {
    margin-top: 8px;
    font-size: 11px;
    color: #b8b8b8;
    text-align: center;
    font-style: italic;
    min-height: 16px;
}

@media (max-width: 768px) {
    #tts-sidebar {
        width: 250px;
        padding: 15px;
    }

    /* Only hide the panel, not the toggle button */
    #tts-sidebar.collapsed {
        right: -250px;
    }

    #tts-toggle {
        /* Position toggle button to always be visible at screen edge */
        position: fixed;
        right: 0;
        left: auto;
        top: 50%;
        transform: translateY(-50%);
        padding: 15px 12px;
        font-size: 22px;
        /* Increase touch target */
        min-width: 50px;
        min-height: 50px;
        /* Ensure it's above other content */
        z-index: 1001;
        /* Prevent text selection on touch */
        -webkit-user-select: none;
        user-select: none;
        /* Improve touch response */
        -webkit-tap-highlight-color: rgba(212, 175, 55, 0.3);
        touch-action: manipulation;
        /* Add border for visibility */
        border: 2px solid #d4af37;
        border-right: none;
        border-radius: 10px 0 0 10px;
    }

    /* When sidebar is open, attach toggle to sidebar */
    #tts-sidebar:not(.collapsed) #tts-toggle {
        position: absolute;
        right: auto;
        left: -50px;
    }

    .tts-btn {
        padding: 8px 12px;
        font-size: 12px;
        /* Increase touch target */
        min-width: 44px;
        min-height: 44px;
        /* Improve touch response */
        -webkit-tap-highlight-color: rgba(212, 175, 55, 0.3);
        touch-action: manipulation;
    }

    .tts-select, .tts-range {
        /* Improve touch response */
        touch-action: manipulation;
    }

    .music-btn {
        /* Increase touch target for music button */
        min-height: 48px;
        font-size: 15px;
    }
}

/* Extra small screens - floating action button style */
@media (max-width: 480px) {
    #tts-sidebar {
        width: 90vw;
        max-width: 300px;
        top: auto;
        bottom: 0;
        right: 5vw;
        transform: none;
        border-radius: 10px 10px 0 0;
        max-height: 75vh;
        overflow-y: auto;
    }

    #tts-sidebar.collapsed {
        bottom: -100%;
        right: 5vw;
    }

    /* Toggle button - always visible as floating button */
    #tts-toggle {
        position: fixed;
        bottom: 15px;
        right: 15px;
        left: auto;
        top: auto;
        transform: none;
        border-radius: 50%;
        width: 60px;
        height: 60px;
        border: 2px solid #d4af37;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 15px rgba(0,0,0,0.5);
        font-size: 24px;
        padding: 0;
    }

    /* When sidebar is open, move toggle to top of sidebar */
    #tts-sidebar:not(.collapsed) #tts-toggle {
        position: absolute;
        top: -50px;
        bottom: auto;
        right: auto;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 10px 10px 0 0;
        width: auto;
        height: auto;
        padding: 10px 20px;
        border-bottom: none;
    }
}
