/* ========================================
   Speech Control Panel Styles
======================================== */

/* Main Panel */
.speech-control-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transform: translateY(calc(100% + 40px));
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid var(--border-color);
}

.speech-control-panel.active {
    transform: translateY(0);
}

/* Panel Header */
.speech-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 2px solid var(--border-color);
    background: var(--background);
    border-radius: 12px 12px 0 0;
}

.speech-panel-header h3 {
    margin: 0;
    font-size: 1.125rem;
    color: var(--text-primary);
    font-weight: 600;
}

.speech-panel-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-secondary);
    transition: all 0.2s;
    border-radius: 4px;
}

.speech-panel-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* Panel Body */
.speech-panel-body {
    padding: 1.25rem;
    max-height: 60vh;
    overflow-y: auto;
}

/* Main Controls */
.speech-main-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.speech-control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 100px;
}

.speech-control-btn:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

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

.speech-control-btn svg {
    width: 32px;
    height: 32px;
}

.speech-control-btn .control-label {
    font-size: 0.875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.speech-play-pause.playing .play-icon {
    display: none;
}

.speech-play-pause.playing .pause-icon {
    display: block !important;
}

.speech-play-pause.playing .control-label::after {
    content: "一時停止";
}

.speech-play-pause.playing .control-label {
    font-size: 0;
}

.speech-stop {
    background: var(--text-secondary);
}

.speech-stop:hover {
    background: var(--danger-color);
}

/* Speed Control Section */
.speech-speed-section {
    background: var(--background);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.speed-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.speed-display {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 1rem;
}

.speed-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.speed-btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.speed-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.speed-btn svg {
    width: 18px;
    height: 18px;
}

#speechRateSlider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

#speechRateSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
}

#speechRateSlider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--secondary-color);
}

#speechRateSlider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

/* Speed Presets */
.speed-presets {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.preset-btn {
    flex: 1;
    padding: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.preset-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.preset-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Progress Section */
.speech-progress {
    margin-bottom: 1rem;
}

.progress-label {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.progress-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.speech-progress-bar {
    flex: 1;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.speech-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    width: 0%;
    transition: width 0.3s ease;
    position: relative;
}

.speech-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3));
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-20px); }
    100% { transform: translateX(20px); }
}

.progress-percentage {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-color);
    min-width: 40px;
}

/* Current Reading Section */
.current-reading {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.reading-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.reading-text {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    max-height: 100px;
    overflow-y: auto;
    padding: 0.5rem;
    background: white;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.reading-text.active {
    border-color: var(--secondary-color);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { border-color: var(--secondary-color); }
    50% { border-color: var(--accent-color); }
}

/* Shortcuts Info */
.shortcuts-info {
    background: var(--background);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.875rem;
}

.shortcuts-info h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.shortcuts-info dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1rem;
    margin: 0;
}

.shortcuts-info dt {
    text-align: right;
}

.shortcuts-info dd {
    margin: 0;
    color: var(--text-secondary);
}

.shortcuts-info kbd {
    background: white;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 0.85em;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

/* Enhanced Header Button */
.speech-toggle.with-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    transition: all 0.2s;
}

.speech-toggle.with-label:hover {
    background: rgba(255, 255, 255, 0.2);
}

.speech-toggle.with-label.active {
    background: var(--accent-color);
    color: white;
}

.button-label {
    font-size: 0.875rem;
    font-weight: 500;
    display: none;
}

@media (min-width: 768px) {
    .button-label {
        display: inline;
    }
}

/* Floating Button (Mobile) */
.speech-floating-btn {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 999;
    transition: all 0.3s;
}

.speech-floating-btn:hover {
    transform: scale(1.1);
    background: var(--secondary-color);
}

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

.speech-floating-btn.active::after {
    content: '';
    position: absolute;
    top: -5px;
    right: -5px;
    bottom: -5px;
    left: -5px;
    border: 2px solid var(--accent-color);
    border-radius: 50%;
    animation: ripple 1.5s infinite;
}

@keyframes ripple {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(1.3);
        opacity: 0;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .speech-control-panel {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 10px;
        border-radius: 12px 12px 0 0;
    }
    
    .speech-floating-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .speech-main-controls {
        flex-direction: column;
    }
    
    .speech-control-btn {
        width: 100%;
    }
    
    .speed-presets {
        flex-wrap: wrap;
    }
}

/* Dark Theme Support */
[data-theme="dark"] .speech-control-panel {
    background: #2c2c2c;
    border-color: #444;
    color: #e0e0e0;
}

[data-theme="dark"] .speech-panel-header {
    background: #1a1a1a;
    border-color: #444;
}

[data-theme="dark"] .speech-control-btn {
    background: #4a4a4a;
}

[data-theme="dark"] .speech-control-btn:hover {
    background: #5a5a5a;
}

[data-theme="dark"] .current-reading,
[data-theme="dark"] .shortcuts-info,
[data-theme="dark"] .speech-speed-section {
    background: #1a1a1a;
}

[data-theme="dark"] .reading-text,
[data-theme="dark"] .preset-btn,
[data-theme="dark"] .speed-btn {
    background: #2c2c2c;
    border-color: #444;
    color: #e0e0e0;
}

/* Highlight for reading text */
.chapter-body .sentence-reading {
    background: linear-gradient(90deg, rgba(231, 76, 60, 0.2), rgba(243, 156, 18, 0.2));
    border-left: 3px solid var(--secondary-color);
    padding-left: 0.5rem;
    margin-left: -0.5rem;
    transition: all 0.3s;
    animation: reading-pulse 2s infinite;
}

@keyframes reading-pulse {
    0%, 100% { background: rgba(231, 76, 60, 0.2); }
    50% { background: rgba(243, 156, 18, 0.3); }
}

/* First-time guide overlay */
.speech-guide-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.speech-guide-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.speech-guide {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
}

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

.speech-guide h2 {
    margin: 0 0 1rem 0;
    color: var(--primary-color);
}

.speech-guide-features {
    list-style: none;
    padding: 0;
    margin: 1.5rem 0;
}

.speech-guide-features li {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.speech-guide-features li::before {
    content: "✓";
    color: var(--accent-color);
    font-weight: bold;
    font-size: 1.2rem;
}

.speech-guide-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.guide-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.guide-btn-primary {
    background: var(--primary-color);
    color: white;
}

.guide-btn-primary:hover {
    background: var(--secondary-color);
}

.guide-btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.guide-btn-secondary:hover {
    background: var(--background);
}