/* =========================================================================
   Shared WordPopover Stylesheet
   Used by both Reader (.word-popover) and LoopLingua (.loop-word-popover)
   ========================================================================= */

/* 1. Base Container */
.word-popover,
.loop-word-popover {
    position: fixed;
    z-index: 9999;
    display: none;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
}

.word-popover.visible,
.loop-word-popover.visible {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* 2. Popover Content Box */
.word-popover-content,
.loop-word-popover-content {
    background: rgba(24, 24, 27, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    min-width: 280px;
    max-width: 340px;
    color: #f4f4f5;
    font-family: 'Inter', sans-serif;
}

/* Dark theme integration specifically for Reader */
[data-theme='light'] .word-popover-content {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: #18181b;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

/* 3. Headers & Word text */
.word-header,
.loop-word-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.word-text,
.loop-word-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.01em;
}
[data-theme='light'] .word-text {
    color: #18181b;
}

.word-close,
.loop-word-close {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: #a1a1aa;
    cursor: pointer;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1.2rem;
}
[data-theme='light'] .word-close {
    background: rgba(0, 0, 0, 0.05);
    color: #71717a;
}

.word-close:hover,
.loop-word-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}
[data-theme='light'] .word-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #18181b;
}

/* 4. Pronunciation & Phonetic */
.word-pronunciation,
.loop-word-pronunciation {
    font-size: 0.9rem;
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.1);
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-family: monospace;
    font-weight: 500;
}

/* 5. Translations & Definition */
.word-translation,
.loop-word-translation {
    font-size: 1.05rem;
    color: #e4e4e7;
    margin-bottom: 12px;
    line-height: 1.5;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border-left: 3px solid #10b981;
}
[data-theme='light'] .word-translation {
    color: #27272a;
    background: rgba(0, 0, 0, 0.02);
}

.word-definition,
.loop-word-definition {
    font-size: 0.85rem;
    color: #a1a1aa;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
    line-height: 1.4;
}
[data-theme='light'] .word-definition {
    color: #71717a;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.1);
}

/* AI insights note classes (LoopLingua specific) */
.loop-expert-note {
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.15);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.loop-expert-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #c084fc;
    font-weight: 600;
    margin-bottom: 4px;
}

.loop-expert-content {
    color: #e4e4e7;
}

.ll-pos-badge {
    background: rgba(139, 92, 246, 0.2);
    color: #d8b4fe;
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: monospace;
    font-weight: bold;
}

.loop-context-translation {
    font-size: 0.85rem;
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.15);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 12px;
    font-style: italic;
    line-height: 1.3;
}

/* 6. Action Elements & Buttons */
.word-actions,
.loop-word-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-icon,
.loop-btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e4e4e7;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
[data-theme='light'] .btn-icon {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.08);
    color: #27272a;
}

.btn-icon:hover,
.loop-btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}
[data-theme='light'] .btn-icon:hover {
    background: rgba(0, 0, 0, 0.08);
}

.loop-btn-primary,
.word-add-vocab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 10px;
    padding: 10px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.loop-btn-primary:hover,
.word-add-vocab:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.loop-btn-primary.saved,
.word-add-vocab.saved {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #10b981;
    cursor: default;
    transform: none;
    box-shadow: none;
}

/* 7. Position Arrow */
.word-popover-arrow,
.loop-word-popover-arrow {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
}

.word-popover.above .word-popover-arrow,
.loop-word-popover.above .loop-word-popover-arrow {
    border-top: 8px solid rgba(24, 24, 27, 0.95);
    border-bottom: none;
    top: 100%;
}
[data-theme='light'] .word-popover.above .word-popover-arrow {
    border-top: 8px solid rgba(255, 255, 255, 0.95);
}

.word-popover.below .word-popover-arrow,
.loop-word-popover.below .loop-word-popover-arrow {
    border-bottom: 8px solid rgba(24, 24, 27, 0.95);
    border-top: none;
    bottom: 100%;
}
[data-theme='light'] .word-popover.below .word-popover-arrow {
    border-bottom: 8px solid rgba(255, 255, 255, 0.95);
}

/* 8. Text selection hover highlight */
.ll-word {
    cursor: pointer;
    padding: 0 2px;
    border-radius: 4px;
    transition: all 0.2s;
}

.ll-word:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #38bdf8;
}

.ll-word.filled {
    color: #10b981;
    border-bottom: 1px dashed rgba(16, 185, 129, 0.4);
}

.ll-word.filled:hover {
    background: rgba(16, 185, 129, 0.15);
}

/* 9. Mobile adaptations (ported from Reader so it doesn't regress on small screens) */
@media (max-width: 640px) {
    .word-popover-content,
    .loop-word-popover-content {
        min-width: 260px;
        max-width: 300px;
        max-height: 80vh;
        overflow: auto;
    }

    .word-actions,
    .loop-word-actions {
        flex-direction: column;
        gap: 12px;
    }

    .word-actions .btn-secondary,
    .word-actions .btn-ghost,
    .word-add-vocab,
    .loop-btn-primary {
        width: 100%;
    }

    /* Reader-only context block (LoopLingua never emits these) */
    .word-context {
        margin-top: 8px;
        padding-top: 8px;
        max-height: 150px;
    }

    .context-source {
        font-size: 0.8rem;
        max-height: 60px;
    }

    .context-translation {
        font-size: 0.8rem;
    }
}

/* 10. Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .word-popover,
    .loop-word-popover {
        transition: none;
    }

    .word-popover.visible,
    .loop-word-popover.visible {
        transform: none;
    }
}
