/* ============================================================
   READ ALOUD — Study Article Player & TTS
   
   Two modes:
   1. Pre-generated audio → sticky player bar
   2. Browser TTS fallback → per-section buttons + word highlight
   ============================================================ */

/* ── Trigger Button (injected into .page-header) ────────── */
.study-read-aloud-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: rgba(26, 18, 11, 0.75);
    border: 1.5px solid var(--gold-primary);
    border-radius: 24px;
    color: var(--gold-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: 1.25rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(196, 148, 58, 0.15);
}
.study-read-aloud-trigger:hover {
    background: rgba(196, 148, 58, 0.25);
    border-color: var(--gold-light);
    box-shadow: 0 2px 16px rgba(196, 148, 58, 0.3), 0 0 0 1px rgba(196, 148, 58, 0.3);
    color: var(--gold-light);
}
.study-read-aloud-trigger:active {
    transform: scale(0.97);
}
.study-read-aloud-trigger svg {
    flex-shrink: 0;
}
.study-read-aloud-trigger.listening {
    background: rgba(196, 148, 58, 0.2);
    border-color: var(--gold-primary);
    animation: studyTriggerPulse 2.5s ease-in-out infinite;
}
@keyframes studyTriggerPulse {
    0%, 100% { box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(196, 148, 58, 0.15); }
    50% { box-shadow: 0 2px 16px rgba(196, 148, 58, 0.35), 0 0 0 3px rgba(196, 148, 58, 0.1); }
}

/* ── Sticky Audio Player Bar ────────────────────────────── */
.study-player-bar {
    position: fixed;
    top: 60px;  /* below site header */
    left: 0;
    right: 0;
    z-index: 1050;
    background: linear-gradient(180deg, rgba(26, 18, 11, 0.97), rgba(42, 29, 20, 0.97));
    border-bottom: 1px solid rgba(196, 148, 58, 0.2);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.35s ease, opacity 0.35s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.study-player-bar.visible {
    transform: translateY(0);
    opacity: 1;
}

/* Play / Pause Button */
.study-player-play {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(196, 148, 58, 0.4);
    background: rgba(196, 148, 58, 0.12);
    color: var(--gold-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.study-player-play:hover {
    background: rgba(196, 148, 58, 0.25);
    border-color: var(--gold-primary);
}
.study-player-play .icon-pause { display: none; }
.study-player-bar.playing .study-player-play .icon-play { display: none; }
.study-player-bar.playing .study-player-play .icon-pause { display: block; }

/* Progress Section */
.study-player-progress-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.study-player-title {
    font-family: var(--font-serif);
    font-size: 0.75rem;
    color: rgba(232, 220, 196, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.study-player-seek {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(196, 148, 58, 0.15);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.study-player-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gold-primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 4px rgba(196, 148, 58, 0.4);
}
.study-player-seek::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gold-primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 4px rgba(196, 148, 58, 0.4);
}
.study-player-seek::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
}
.study-player-seek::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: rgba(196, 148, 58, 0.15);
}

.study-player-time {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: rgba(232, 220, 196, 0.5);
    display: flex;
    justify-content: space-between;
    line-height: 1;
}

/* Speed Button */
.study-player-speed {
    flex-shrink: 0;
    padding: 0.3rem 0.55rem;
    border-radius: 14px;
    border: 1px solid rgba(196, 148, 58, 0.25);
    background: rgba(196, 148, 58, 0.08);
    color: var(--gold-primary);
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.study-player-speed:hover {
    background: rgba(196, 148, 58, 0.18);
    border-color: rgba(196, 148, 58, 0.45);
}

/* Close Button */
.study-player-close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(196, 148, 58, 0.08);
    color: rgba(232, 220, 196, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.study-player-close:hover {
    background: rgba(196, 148, 58, 0.2);
    color: var(--cream);
}

/* ── Per-Section TTS Button (browser fallback) ──────────── */
.study-tts-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    background: rgba(196, 148, 58, 0.1);
    border: 1px solid rgba(196, 148, 58, 0.25);
    border-radius: 20px;
    color: var(--gold-primary);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all var(--transition-fast);
    float: right;
    margin: 0 0 var(--space-sm) var(--space-sm);
}
.study-tts-btn:hover {
    background: rgba(196, 148, 58, 0.18);
    border-color: rgba(196, 148, 58, 0.45);
}
.study-tts-btn:active {
    transform: scale(0.97);
}

/* Icon toggling */
.study-tts-btn .icon-stop { display: none; }
.study-tts-btn.playing .icon-play { display: none; }
.study-tts-btn.playing .icon-stop { display: inline; }

/* Playing state */
.study-tts-btn.playing {
    background: rgba(196, 148, 58, 0.2);
    border-color: var(--gold-primary);
    animation: studyTtsPulse 2s ease-in-out infinite;
}
.study-tts-btn.playing .study-tts-label::after {
    content: 'Stop';
    font-size: 0.78rem;
}
.study-tts-btn.playing .study-tts-label {
    font-size: 0;
}

@keyframes studyTtsPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(196, 148, 58, 0.25); }
    50% { box-shadow: 0 0 0 4px rgba(196, 148, 58, 0); }
}

/* ── Word-Level Highlighting (TTS mode) ─────────────────── */
.study-tts-word {
    transition: background-color 0.15s ease, color 0.15s ease;
    border-radius: 2px;
    padding: 0 1px;
}
.study-tts-word.study-tts-highlight {
    background-color: rgba(196, 148, 58, 0.3);
    color: var(--cream-soft);
    box-shadow: 0 0 0 2px rgba(196, 148, 58, 0.15);
}

/* Active section indicator */
.content-section.study-tts-active {
    position: relative;
}
.content-section.study-tts-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--gold-primary);
    border-radius: 2px;
    opacity: 0.5;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .study-player-bar {
        top: 56px;
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }
    .study-player-title {
        display: none;
    }
    .study-player-play {
        width: 32px;
        height: 32px;
    }
    .study-tts-btn {
        padding: 0.35rem 0.65rem;
        font-size: 0.72rem;
    }
}

@media (max-width: 480px) {
    .study-player-bar {
        gap: 0.4rem;
    }
    .study-player-speed {
        font-size: 0.68rem;
        padding: 0.25rem 0.45rem;
    }
}
