/**
 * ═════════════════════════════════════════════════════════════════════════
 *  👵👴 ELDER ASSIST STYLESHEET (EdukalEDAD Gerontological Accessibility)
 * ═════════════════════════════════════════════════════════════════════════
 *  Provides reusable visual pointing guides, high-contrast spotlight rings,
 *  senior-accessible voice controls (>=60px tap targets), and quiz banners.
 * ═════════════════════════════════════════════════════════════════════════
 */

/* ── 1. SPOTLIGHT PULSE RING (HIGH CONTRAST DUAL-COLOR) ── */
@keyframes tourSpotlightPulse {
    0% {
        box-shadow: 0 0 0 4px #2563eb, 0 0 0 8px rgba(245, 158, 11, 0.5), 0 8px 24px rgba(37, 99, 235, 0.35);
        transform: translateY(-2px) scale(1.02);
    }
    100% {
        box-shadow: 0 0 0 6px #f59e0b, 0 0 0 12px rgba(37, 99, 235, 0.35), 0 14px 34px rgba(245, 158, 11, 0.55);
        transform: translateY(-4px) scale(1.035);
    }
}

.tour-spotlight,
.pointing-active {
    animation: tourSpotlightPulse 1s ease-in-out infinite alternate !important;
    position: relative !important;
    z-index: 45 !important;
    border-color: #f59e0b !important;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease !important;
}

/* ── 2. SENIOR-ACCESSIBLE VOICE LISTEN & STOP BUTTONS ── */
@keyframes speakingActivePulse {
    0% {
        box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.35), 0 4px 14px rgba(220, 38, 38, 0.4);
        transform: translateY(-1px);
    }
    100% {
        box-shadow: 0 0 0 7px rgba(220, 38, 38, 0.2), 0 8px 22px rgba(220, 38, 38, 0.6);
        transform: translateY(-2px);
    }
}

@keyframes offerAttentionPulse {
    0% {
        box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.4), 0 2px 8px rgba(22, 163, 74, 0.2);
    }
    100% {
        box-shadow: 0 0 0 6px rgba(22, 163, 74, 0.15), 0 6px 18px rgba(22, 163, 74, 0.45);
    }
}

/* Base Listen Button */
.btn-elder-listen {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: #ffffff !important;
    border: 2px solid rgba(187, 247, 208, 0.9);
    border-radius: 16px;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(22, 163, 74, 0.28);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    font-family: inherit;
    text-decoration: none;
}

.btn-elder-listen:hover:not(:disabled) {
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(22, 163, 74, 0.38);
}

.btn-elder-listen:active:not(:disabled) {
    transform: translateY(1px);
}

/* Active Speaking State (Crimson Stop Mode) */
.btn-elder-listen.speaking {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
    color: #ffffff !important;
    border-color: rgba(254, 202, 202, 0.95) !important;
    animation: speakingActivePulse 0.9s infinite alternate !important;
}

.btn-elder-listen.speaking:hover:not(:disabled) {
    background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%) !important;
}

/* Offer attention pulse for first visits */
.btn-elder-listen.help-offer-pulse {
    animation: offerAttentionPulse 1.4s infinite alternate;
}

/* Compact variant (Topbar Tulong button) */
.btn-elder-listen--compact {
    height: 38px;
    min-height: 38px;
    padding: 0 16px;
    font-size: 0.9rem;
    border-radius: 100px;
    gap: 7px;
}

/* Preparation Page Large CTA Listen Button */
.btn-prep-listen {
    width: 100%;
    height: clamp(3.15rem, 4.8vh, 3.75rem);
    min-height: clamp(3.15rem, 4.8vh, 3.75rem);
    font-size: clamp(1.05rem, 1.4vh, 1.22rem);
    padding: 0 24px;
    border-radius: clamp(14px, 1.8vh, 18px);
    margin-bottom: clamp(8px, 1.2vh, 14px);
    flex-shrink: 0;
}

.btn-prep-listen .listen-icon {
    font-size: 1.35rem;
    line-height: 1;
}

/* ── 3. QUIZ PERSISTENT INSTRUCTION BAR ── */
.quiz-instruction-bar {
    background: #eff6ff;
    border: 2px solid #93c5fd;
    border-radius: 14px;
    padding: 10px 20px;
    margin-bottom: clamp(14px, 2vh, 20px);
    font-size: clamp(16px, 1.4vw, 19px);
    font-weight: 800;
    color: #1e3a8a;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
    text-align: center;
    line-height: 1.35;
}

/* ── 4. QUIZ QUESTION HEADER & SPEAKER BUTTON ── */
.elder-q-head {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: clamp(18px, 2.8vh, 30px);
    width: 100%;
}

.elder-q-head .elder-q-title {
    margin-bottom: 0 !important;
    text-align: left;
    flex: 1;
}

.btn-question-speak {
    width: 54px;
    height: 54px;
    min-width: 54px;
    min-height: 54px;
    border-radius: 16px;
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: #ffffff;
    border: 2px solid rgba(187, 247, 208, 0.85);
    font-size: 24px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.28);
    transition: all 0.2s ease;
    flex-shrink: 0;
    user-select: none;
}

.btn-question-speak:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 18px rgba(22, 163, 74, 0.38);
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
}

.btn-question-speak:active {
    transform: translateY(1px);
}

.btn-question-speak.speaking {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
    border-color: rgba(254, 202, 202, 0.95) !important;
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.3), 0 6px 18px rgba(220, 38, 38, 0.45) !important;
    animation: speakingActivePulse 0.9s infinite alternate !important;
}

/* ═════════════════════════════════════════════════════════════════════════
   🎙️ 5. APO VOICE ASSISTANT: SPEAKING ANIMATION & 2-WAY COMPANION DOCK
═════════════════════════════════════════════════════════════════════════ */
@keyframes apoAuraRadiate {
    0% {
        transform: scale(0.95);
        opacity: 0.8;
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.6);
    }
    100% {
        transform: scale(1.22);
        opacity: 0;
        box-shadow: 0 0 0 16px rgba(245, 158, 11, 0);
    }
}

@keyframes apoAuraListening {
    0% {
        transform: scale(0.95);
        opacity: 0.85;
        box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.7);
    }
    100% {
        transform: scale(1.25);
        opacity: 0;
        box-shadow: 0 0 0 18px rgba(16, 185, 129, 0);
    }
}

@keyframes apoBobHead {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-3px) scale(1.06);
    }
}

@keyframes swBounceSpeaking {
    0% {
        height: 4px;
    }
    100% {
        height: 18px;
    }
}

@keyframes swBounceListening {
    0% {
        height: 4px;
    }
    100% {
        height: 18px;
    }
}

/* Main Floating Companion Dock (Compact & Educator-Friendly) */
.apo-companion-dock {
    position: fixed;
    bottom: 14px;
    right: 18px;
    z-index: 1000;
    max-width: 320px;
    width: calc(100vw - 32px);
    background: #ffffff;
    border: 2px solid #3b82f6;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(12, 31, 74, 0.14), 0 0 0 3px rgba(59, 130, 246, 0.1);
    padding: 8px 12px;
    transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
}

.apo-companion-dock.is-speaking {
    border-color: #2563eb;
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.2), 0 0 0 4px rgba(245, 158, 11, 0.2);
}

.apo-companion-dock.is-listening {
    border-color: #16a34a;
    box-shadow: 0 10px 28px rgba(22, 163, 74, 0.2), 0 0 0 4px rgba(34, 197, 94, 0.2);
}

.apo-companion-inner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

/* Avatar & Animated Sound Wave Stage */
.apo-avatar-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    position: relative;
    flex-shrink: 0;
}

.apo-glow-ring {
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
}

.is-speaking .apo-glow-ring {
    animation: apoAuraRadiate 1.2s ease-out infinite;
    opacity: 1;
}

.is-listening .apo-glow-ring {
    animation: apoAuraListening 1s ease-out infinite;
    opacity: 1;
}

.apo-avatar-circle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fef08a 0%, #facc15 100%);
    border: 2.5px solid #ffffff;
    box-shadow: 0 3px 10px rgba(202, 138, 4, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s;
}

.apo-avatar-circle:hover {
    transform: scale(1.06);
}

.is-speaking .apo-avatar-circle {
    animation: apoBobHead 0.7s ease-in-out infinite alternate;
}

.apo-avatar-emoji {
    font-size: 24px;
    line-height: 1;
}

/* Equalizer Sound Wave Bars */
.apo-soundwave-bars {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2.5px;
    height: 18px;
    padding: 0 1px;
}

.sw-bar {
    width: 3px;
    height: 4px;
    border-radius: 3px;
    background: #cbd5e1;
    transition: all 0.15s ease;
}

.is-speaking .sw-bar {
    background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
    animation: swBounceSpeaking 0.8s ease-in-out infinite alternate;
}

.is-speaking .sw-bar.bar-1 { animation-delay: 0.05s; height: 10px; }
.is-speaking .sw-bar.bar-2 { animation-delay: 0.22s; height: 18px; }
.is-speaking .sw-bar.bar-3 { animation-delay: 0.38s; height: 9px; }
.is-speaking .sw-bar.bar-4 { animation-delay: 0.12s; height: 15px; }
.is-speaking .sw-bar.bar-5 { animation-delay: 0.28s; height: 12px; }

.is-listening .sw-bar {
    background: linear-gradient(180deg, #10b981 0%, #059669 100%) !important;
    animation: swBounceListening 0.45s ease-in-out infinite alternate !important;
}

.is-listening .sw-bar.bar-1 { animation-delay: 0.04s; }
.is-listening .sw-bar.bar-2 { animation-delay: 0.18s; }
.is-listening .sw-bar.bar-3 { animation-delay: 0.3s; }
.is-listening .sw-bar.bar-4 { animation-delay: 0.1s; }
.is-listening .sw-bar.bar-5 { animation-delay: 0.24s; }

.is-thinking .sw-bar {
    background: linear-gradient(180deg, #8b5cf6 0%, #6366f1 100%) !important;
    animation: swBounceThinking 0.6s ease-in-out infinite alternate !important;
}

@keyframes swBounceThinking {
    0% { height: 4px; opacity: 0.6; }
    100% { height: 16px; opacity: 1; }
}

.is-thinking .sw-bar.bar-1 { animation-delay: 0.08s; }
.is-thinking .sw-bar.bar-2 { animation-delay: 0.20s; }
.is-thinking .sw-bar.bar-3 { animation-delay: 0.32s; }
.is-thinking .sw-bar.bar-4 { animation-delay: 0.14s; }
.is-thinking .sw-bar.bar-5 { animation-delay: 0.26s; }

/* Dialogue & Controls Stage */
.apo-content-stage {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.apo-header-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.apo-name-group {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.apo-live-badge {
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 1px 6px;
    border-radius: 100px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    white-space: nowrap;
}

.is-speaking .apo-live-badge {
    background: #fffbeb;
    color: #b45309;
    border-color: #fde68a;
}

.is-listening .apo-live-badge {
    background: #f0fdf4;
    color: #15803d;
    border-color: #bbf7d0;
}

.is-thinking .apo-live-badge {
    background: #f5f3ff;
    color: #6d28d9;
    border-color: #ddd6fe;
    animation: speakingActivePulse 0.9s infinite alternate;
}

.apo-name-text {
    font-size: 0.88rem;
    font-weight: 900;
    color: #0c1f4a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Language Switcher Pill Toggle */
.apo-lang-toggle {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    padding: 2px 7px;
    font-size: 0.65rem;
    font-weight: 800;
    color: #334155;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
    font-family: inherit;
    line-height: 1;
}

.apo-lang-toggle:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
    transform: scale(1.04);
}

.apo-lang-toggle:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

.apo-btn-action {
    border: none;
    border-radius: 100px;
    font-weight: 800;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.2s;
    white-space: nowrap;
}

/* Speech Caption Bubble */
.apo-speech-caption {
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    padding: 5px 8px;
    font-size: 0.80rem;
    line-height: 1.3;
    font-weight: 600;
    color: #1e293b;
    max-height: 50px;
    overflow-y: auto;
    word-break: break-word;
}

.is-speaking .apo-speech-caption {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e3a8a;
}

.is-listening .apo-speech-caption {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #14532d;
    font-weight: 700;
}

.is-thinking .apo-speech-caption {
    background: #faf5ff;
    border-color: #e9d5ff;
    color: #581c87;
    font-style: italic;
}

/* Two-Way Interaction Bar */
.apo-interaction-bar {
    display: flex;
    align-items: center;
    margin-top: 2px;
}

.apo-btn-talk {
    width: 100%;
    justify-content: center;
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: #ffffff;
    border: 1.5px solid rgba(187, 247, 208, 0.8);
    border-radius: 10px;
    padding: 5px 12px;
    font-size: 0.80rem;
    height: 30px;
    box-shadow: 0 2px 6px rgba(22, 163, 74, 0.22);
}

.apo-btn-talk:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 9px rgba(22, 163, 74, 0.3);
}

.is-listening .apo-btn-talk {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
    border-color: rgba(254, 202, 202, 0.8) !important;
    animation: speakingActivePulse 0.9s infinite alternate;
}

/* Responsive adjustment */
@media (max-width: 640px) {
    .apo-companion-dock {
        bottom: 8px;
        right: 8px;
        left: auto;
        width: auto;
        max-width: 290px;
        padding: 7px 10px;
        border-radius: 14px;
    }
    .apo-avatar-circle {
        width: 36px;
        height: 36px;
    }
    .apo-avatar-emoji {
        font-size: 20px;
    }
    .apo-speech-caption {
        font-size: 0.76rem;
        padding: 4px 7px;
        max-height: 42px;
    }
}
