/* Glossary Tooltip Styles */

/* Glossary term highlighting */
.glossary-term {
    color: var(--cosmic-highlight, #64ffda);
    border-bottom: 1px dotted currentColor;
    cursor: help;
    text-decoration: none;
    position: relative;
    transition: all 0.2s ease;
}

.glossary-term:hover,
.glossary-term:focus {
    color: var(--starlight, #ffffff);
    border-bottom-color: var(--cosmic-highlight, #64ffda);
    background: rgba(100, 255, 218, 0.1);
    border-radius: 2px;
    outline: none;
}

.glossary-term:focus {
    outline: 2px solid var(--cosmic-highlight, #64ffda);
    outline-offset: 1px;
}

/* Tooltip container */
.glossary-tooltip {
    position: absolute;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    max-width: 320px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.glossary-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* Tooltip content */
.tooltip-content {
    background: rgba(18, 29, 51, 0.98);
    border: 1px solid rgba(100, 255, 218, 0.3);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    position: relative;
}

.tooltip-term {
    font-weight: 600;
    color: var(--cosmic-highlight, #64ffda);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.tooltip-definition {
    color: var(--distant-stars, #a0b3c8);
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

.tooltip-link {
    color: var(--cosmic-highlight, #64ffda);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: color 0.2s ease;
}

.tooltip-link:hover,
.tooltip-link:focus {
    color: var(--starlight, #ffffff);
    text-decoration: underline;
}

/* Tooltip arrow */
.tooltip-arrow {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: rgba(18, 29, 51, 0.98);
    border: 1px solid rgba(100, 255, 218, 0.3);
    border-top: none;
    border-left: none;
    transform: translateX(-50%) rotate(45deg);
}

/* Arrow for top position */
.glossary-tooltip.tooltip-top .tooltip-arrow {
    bottom: auto;
    top: -6px;
    border: 1px solid rgba(100, 255, 218, 0.3);
    border-bottom: none;
    border-right: none;
    transform: translateX(-50%) rotate(-135deg);
}

/* Light theme support */
@media (prefers-color-scheme: light) {
    .tooltip-content {
        background: rgba(255, 255, 255, 0.98);
        border-color: rgba(18, 29, 51, 0.2);
        color: #2d3748;
    }
    
    .tooltip-term {
        color: #2b6cb0;
    }
    
    .tooltip-definition {
        color: #4a5568;
    }
    
    .tooltip-link {
        color: #2b6cb0;
    }
    
    .tooltip-arrow {
        background: rgba(255, 255, 255, 0.98);
        border-color: rgba(18, 29, 51, 0.2);
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .glossary-term {
        border-bottom-width: 2px;
        border-bottom-style: solid;
    }
    
    .tooltip-content {
        border-width: 2px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.8);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .glossary-term,
    .glossary-tooltip,
    .tooltip-link {
        transition: none;
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .glossary-tooltip {
        max-width: calc(100vw - 2rem);
        font-size: 0.85rem;
    }
    
    .tooltip-content {
        padding: 0.875rem;
    }
    
    .tooltip-term {
        font-size: 0.95rem;
    }
    
    /* Larger touch targets */
    .glossary-term {
        padding: 0.125rem 0.25rem;
        margin: -0.125rem -0.25rem;
        border-radius: 3px;
    }
}

/* Print styles */
@media print {
    .glossary-term {
        color: inherit;
        border-bottom: none;
        background: none;
    }
    
    .glossary-tooltip {
        display: none;
    }
}

/* Tooltip toggle styles */
.tooltip-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(125, 140, 196, 0.1);
    border: 1px solid rgba(125, 140, 196, 0.3);
    border-radius: 6px;
    color: var(--distant-stars, #a0b3c8);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tooltip-toggle:hover {
    background: rgba(125, 140, 196, 0.2);
    border-color: rgba(125, 140, 196, 0.5);
}

.tooltip-toggle input[type="checkbox"] {
    margin: 0;
    accent-color: var(--cosmic-highlight, #64ffda);
}

/* Animation for new terms */
@keyframes term-highlight {
    0% { background: rgba(100, 255, 218, 0.3); }
    100% { background: rgba(100, 255, 218, 0.1); }
}

.glossary-term.newly-added {
    animation: term-highlight 1s ease-out;
}

/* Focus management */
.glossary-term:focus-visible {
    outline: 2px solid var(--cosmic-highlight, #64ffda);
    outline-offset: 2px;
    border-radius: 3px;
}

/* Tooltip positioning helpers */
.glossary-tooltip.tooltip-left .tooltip-arrow {
    left: 20px;
}

.glossary-tooltip.tooltip-right .tooltip-arrow {
    left: auto;
    right: 20px;
    transform: translateX(50%) rotate(45deg);
}

.glossary-tooltip.tooltip-top.tooltip-right .tooltip-arrow {
    transform: translateX(50%) rotate(-135deg);
}

/* Loading state */
.glossary-loading .glossary-term {
    opacity: 0.7;
    pointer-events: none;
}

/* Glossary page styles */
.glossary-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
}

.glossary-page .term-entry {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: rgba(18, 29, 51, 0.6);
    border-radius: 8px;
    border-left: 4px solid var(--cosmic-highlight, #64ffda);
}

.glossary-page .term-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--cosmic-highlight, #64ffda);
    margin-bottom: 0.5rem;
}

.glossary-page .term-definition {
    color: var(--distant-stars, #a0b3c8);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.glossary-page .term-link {
    color: var(--cosmic-highlight, #64ffda);
    text-decoration: none;
    font-size: 0.9rem;
}

.glossary-page .term-link:hover {
    text-decoration: underline;
}