/* Expanded Card View */
.card-view {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1002;
    padding: 100px 20px;
}

.card-view.active {
    display: flex;
}

.expanded-card {
    width: 90vw;
    max-width: 500px;
    aspect-ratio: 2.5 / 3.5;
    background: var(--card-bg);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    transform: scale(0.8);
    opacity: 0;
    transition: all 0.4s ease;
}

.card-view.active .expanded-card {
    transform: scale(1);
    opacity: 1;
}

/* Reference Content Structure */
.reference-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.reference-header {
    flex-shrink: 0;
    padding: 1.5rem;
    background: var(--theater-burgundy);
    color: white;
}

.reference-title {
    font-family: var(--card-deck-font-display);
    font-size: 1.4rem;
    font-weight: 600;
    margin: 0;
    color: white;
    line-height: 1.3;
}

.reference-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--card-bg);
    scrollbar-width: thin;
    scrollbar-color: var(--neutral-400) transparent;
}

.reference-section {
    margin-bottom: 1.5rem;
}

.reference-section h3 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--theater-burgundy);
    margin: 0 0 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.reference-section p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
}

/* Markdown content styling within reference sections */
.reference-section h1,
.reference-section h2,
.reference-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--theater-burgundy, #8B1538);
    margin: 1.25rem 0 0.5rem 0;
    line-height: 1.3;
}

.reference-section h1:first-child,
.reference-section h2:first-child,
.reference-section h3:first-child {
    margin-top: 0;
}

.reference-section h2 {
    font-size: 0.95rem;
    color: var(--text-primary, #27272A);
    border-bottom: 1px solid var(--quote-border, rgba(139, 21, 56, 0.15));
    padding-bottom: 0.25rem;
}

.reference-section h3 {
    font-size: 0.875rem;
}

.reference-section ul,
.reference-section ol {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
    color: var(--text-secondary);
}

.reference-section li {
    margin-bottom: 0.25rem;
    line-height: 1.5;
}

.reference-section strong {
    font-weight: 600;
    color: var(--text-primary, #27272A);
}

.reference-section em {
    font-style: italic;
}

.reference-section hr {
    border: none;
    border-top: 1px solid var(--quote-border, rgba(139, 21, 56, 0.15));
    margin: 1rem 0;
}

.reference-footer {
    flex-shrink: 0;
    padding: 1.5rem;
    background: var(--theater-burgundy);
    color: white;
}

.reference-footer h3 {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    margin: 0 0 0.75rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: nowrap; /* Prevent wrapping to keep single line */
    overflow-x: auto; /* Enable horizontal scrolling */
    overflow-y: hidden;
    margin: 0;
    padding-bottom: 2px; /* Small padding for scroll bar */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}

.tag {
    background: var(--tag-bg, rgba(255, 255, 255, 0.2));
    color: var(--tag-text, white);
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-weight: 500;
    border: 1px solid var(--tag-border, rgba(255, 255, 255, 0.3));
    transition: all 0.2s ease;
    flex-shrink: 0; /* Prevent tags from shrinking when scrolling */
    white-space: nowrap; /* Ensure tag text doesn't wrap */
}

.tag:hover {
    background: var(--tag-bg, rgba(255, 255, 255, 0.3));
    filter: brightness(1.1);
}

/* Active tag highlighting in card footer for search results */
.tag.tag-active {
    background: var(--primary-color, #3b82f6) !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
    font-weight: 600;
    border: 1px solid var(--primary-color, #3b82f6);
}

/* Tags scrollbar styling */
.tags::-webkit-scrollbar {
    height: 4px;
}

.tags::-webkit-scrollbar-track {
    background: transparent;
}

.tags::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.tags::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

/* Loading States */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--text-secondary);
    font-family: var(--card-deck-font-body);
    font-size: 1.2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--neutral-300);
    border-top: 3px solid var(--theater-burgundy);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error States */
.error {
    text-align: center;
    color: var(--theater-burgundy);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--card-border-radius);
    padding: 2rem;
    margin: 2rem;
    font-family: var(--card-deck-font-body);
}

/* Responsive Design - FIX 2: Maintain Viewport Optimization */

/* Default desktop layout (above 768px) - larger footer */
@media (min-width: 769px) and (orientation: landscape) {
    .reference-carousel .reference-list .reference-item {
        position: fixed !important;
        top: 76px !important; /* Header bottom (72px) + 4px margin */
        bottom: 76px !important; /* Footer height (72px) + 4px margin above 769px */
        left: 50% !important;
        transform: translateX(-50%); /* Only center horizontally */
        width: min(var(--reference-card-width), 95vw) !important;
        height: calc(100vh - 76px - 76px); /* VH fallback for older browsers */
        height: calc(100dvh - 76px - 76px); /* DVH calculation: 100dvh - top - bottom */
        aspect-ratio: unset !important; /* Remove aspect ratio to ensure 4px margin priority */
        max-width: 95vw !important;
    }
}

@media (min-width: 769px) and (orientation: portrait) {
    .reference-carousel .reference-list .reference-item {
        position: fixed !important;
        top: 76px !important; /* Header bottom (72px) + 4px margin */
        bottom: 76px !important; /* Footer height (72px) + 4px margin above 769px */
        left: 50% !important;
        transform: translateX(-50%); /* Only center horizontally */
        width: min(var(--reference-card-width), 95vw) !important;
        height: calc(100vh - 76px - 76px); /* VH fallback for older browsers */
        height: calc(100dvh - 76px - 76px); /* DVH calculation: 100dvh - top - bottom */
        aspect-ratio: unset !important; /* Remove aspect ratio for portrait to allow stretching */
        max-width: 95vw !important;
    }
}

@media (min-width: 769px) and (orientation: landscape) {
    .reference-carousel .reference-list .reference-item:nth-child(1),
    .reference-carousel .reference-list .reference-item:nth-child(2),
    .reference-carousel .reference-list .reference-item:nth-child(3) {
        position: fixed !important;
        top: 76px !important; /* Header bottom (72px) + 4px margin */
        bottom: 76px !important; /* Footer height (72px) + 4px margin above 769px */
        left: 50% !important;
        transform: translateX(-50%); /* Only center horizontally */
        width: min(var(--reference-card-width), 95vw) !important;
        height: calc(100vh - 76px - 76px); /* VH fallback for older browsers */
        height: calc(100dvh - 76px - 76px); /* DVH calculation: 100dvh - top - bottom */
        aspect-ratio: unset !important; /* Remove aspect ratio to ensure 4px margin priority */
        max-width: 95vw !important;
    }
}

@media (min-width: 769px) and (orientation: portrait) {
    .reference-carousel .reference-list .reference-item:nth-child(1),
    .reference-carousel .reference-list .reference-item:nth-child(2),
    .reference-carousel .reference-list .reference-item:nth-child(3) {
        position: fixed !important;
        top: 76px !important; /* Header bottom (72px) + 4px margin */
        bottom: 76px !important; /* Footer height (72px) + 4px margin above 769px */
        left: 50% !important;
        transform: translateX(-50%); /* Only center horizontally */
        width: min(var(--reference-card-width), 95vw) !important;
        height: calc(100vh - 76px - 76px); /* VH fallback for older browsers */
        height: calc(100dvh - 76px - 76px); /* DVH calculation: 100dvh - top - bottom */
        aspect-ratio: unset !important; /* Remove aspect ratio for portrait to allow stretching */
        max-width: 95vw !important;
    }
}

@media (max-width: 768px) {
    :root {
        /* Maintain viewport-optimized sizing on mobile with adjusted margins */
        --available-height: calc(100vh - 50px - 70px - 30px); /* Smaller header/footer on mobile */
        --available-width: calc(100vw - 30px); /* Smaller margins on mobile */
    }
    
    /* Tablet card sizing using working template from sub-480px */
    .reference-carousel .reference-list .reference-item {
        position: fixed !important;
        top: 68px !important; /* Header bottom (64px) + 4px margin */
        bottom: 64px !important; /* Footer height (60px) + 4px margin at 768px */
        left: 50% !important;
        transform: translateX(-50%); /* Only center horizontally */
        width: min(var(--reference-card-width), 95vw) !important;
        height: calc(100vh - 68px - 64px); /* VH fallback for older browsers */
        height: calc(100dvh - 68px - 64px); /* DVH calculation: 100dvh - top - bottom */
        aspect-ratio: unset !important; /* Remove aspect ratio constraint like working template */
        max-width: 95vw !important;
    }
    
    /* Fix CSS specificity issue: Add tablet constraints to ALL nth-child selectors using working template */
    .reference-carousel .reference-list .reference-item:nth-child(1),
    .reference-carousel .reference-list .reference-item:nth-child(2),
    .reference-carousel .reference-list .reference-item:nth-child(3) {
        position: fixed !important;
        top: 68px !important; /* Header bottom (64px) + 4px margin */
        bottom: 64px !important; /* Footer height (60px) + 4px margin at 768px */
        left: 50% !important;
        transform: translateX(-50%); /* Only center horizontally */
        width: min(var(--reference-card-width), 95vw) !important;
        height: calc(100vh - 68px - 64px); /* VH fallback for older browsers */
        height: calc(100dvh - 68px - 64px); /* DVH calculation: 100dvh - top - bottom */
        aspect-ratio: unset !important; /* Remove aspect ratio constraint like working template */
        max-width: 95vw !important;
    }
    
    .reference-navigation {
        padding: 0.75rem 1rem;
        gap: 1.5rem;
    }
    
    .nav-btn {
        min-width: 100px;
        height: 36px;
        font-size: 0.8rem;
        padding: 0 0.75rem;
    }
    
    .reference-counter {
        font-size: 0.9rem;
        min-width: 70px;
    }
    
    .top-nav, .bottom-nav {
        padding: 0.75rem 1rem;
    }
    
    .bottom-nav-container {
        gap: 1.5rem;
        padding: 0.5rem 1rem;
    }
    
    .nav-button {
        min-width: 100px;
        height: 36px;
        font-size: 0.8rem;
        padding: 0 0.75rem;
    }
}

@media (max-width: 480px) {
    :root {
        /* Allow more vertical space at mobile sizes for better content visibility */
        --available-height: calc(100vh - 45px - 65px - 20px); /* Even smaller header/footer */
        --available-width: calc(100vw - 20px); /* Minimal margins */
    }
    
    /* iPhone-sized screens: Active positioning with DVH calculations */
    .reference-carousel .reference-list .reference-item {
        position: fixed !important;
        top: 68px !important;
        bottom: 52px !important;
        left: 50% !important;
        transform: translateX(-50%);
        width: min(var(--reference-card-width), 95vw) !important;
        height: calc(100vh - 68px - 52px);
        height: calc(100dvh - 68px - 52px);
        aspect-ratio: unset !important;
        max-width: 95vw !important;
    }
    
    /* Fix CSS specificity issue: Active positioning with DVH calculations */
    .reference-carousel .reference-list .reference-item:nth-child(1),
    .reference-carousel .reference-list .reference-item:nth-child(2),
    .reference-carousel .reference-list .reference-item:nth-child(3) {
        position: fixed !important;
        top: 68px !important;
        bottom: 52px !important;
        left: 50% !important;
        transform: translateX(-50%);
        width: min(var(--reference-card-width), 95vw) !important;
        height: calc(100vh - 68px - 52px);
        height: calc(100dvh - 68px - 52px);
        aspect-ratio: unset !important;
        max-width: 95vw !important;
    }
    
    .reference-header {
        padding: 1rem 1rem 0.75rem;
    }
    
    .reference-body {
        padding: 0.75rem 1rem;
    }
    
    .reference-footer {
        padding: 0.75rem 1rem 1rem;
    }
    
    .reference-navigation {
        gap: 1rem;
        padding: 0.5rem 0.75rem;
    }
    
    .nav-btn {
        min-width: 90px;
        height: 32px;
        font-size: 0.75rem;
    }
    
    .reference-counter {
        font-size: 0.8rem;
        min-width: 60px;
    }
}

/* Enhanced Card Features Styling */

/* Image Thumbnails */
.reference-images {
    margin-top: 0.75rem;
}

.image-thumbnail {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid var(--neutral-200);
    transition: all 0.2s ease;
    display: inline-block;
    margin-right: 0.5rem;
}

.image-thumbnail:hover {
    border-color: var(--theater-burgundy);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 21, 56, 0.15);
}

.image-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.image-thumbnail:hover .thumbnail-overlay {
    opacity: 1;
}

.expand-icon {
    color: white;
    font-size: 1.5rem;
}

/* Image Modal */
.image-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
    animation: fadeIn 0.3s ease;
}

.image-modal-content {
    position: relative;
    margin: auto;
    padding: 20px;
    width: 90%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    justify-content: center;
}

.image-modal-img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.image-modal-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
}

.image-modal-close:hover,
.image-modal-close:focus {
    color: #bbb;
    text-decoration: none;
}

.image-modal-caption {
    color: #f1f1f1;
    text-align: center;
    margin-top: 15px;
    font-size: 0.9rem;
}

/* Show Context Quote - Style 4: Card Coordinated */
.show-quote {
    background: linear-gradient(135deg, var(--quote-bg-start) 0%, var(--quote-bg-end) 100%);
    border: 1px solid var(--quote-border);
    border-left: 4px solid var(--quote-accent);
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin: 0.75rem 0;
    position: relative;
    font-style: italic;
    color: var(--quote-text);
    line-height: 1.5;
}

.show-quote:before {
    content: '"';
    color: var(--theater-burgundy);
    font-size: 2em;
    font-weight: bold;
    position: absolute;
    left: 8px;
    top: 2px;
}

.show-quote:after {
    content: '"';
    color: var(--theater-burgundy);
    font-size: 2em;
    font-weight: bold;
    position: absolute;
    right: 8px;
    bottom: -8px;
}

/* Tags Styling */
.reference-tags {
    margin-bottom: 1rem;
}

.reference-tags h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.tag {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--tag-bg, #f5f5f5);
    color: var(--tag-text, #6b7280);
    border: 1px solid var(--tag-border, #e9ecef);
}

/* Tag category colors */
/* Removed colored tag categories - using original card-deck-v3 styling */

.tag:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    filter: brightness(0.95);
}

/* Citations Styling */
.reference-citations {
    margin-top: 1rem;
}

.reference-citations h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.citations-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.citation-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.citation-badge {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    font-size: 0.625rem;
    font-weight: 600;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

/* Brass plate variations for different citation types */
.citation-badge.badge-primary {
    background: linear-gradient(145deg, rgba(34, 197, 94, 0.7) 0%, rgba(22, 163, 74, 0.8) 100%);
    color: #14532D;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.citation-badge.badge-scholarly {
    background: linear-gradient(145deg, rgba(59, 130, 246, 0.7) 0%, rgba(37, 99, 235, 0.8) 100%);
    color: #1E3A8A;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.citation-badge.badge-news {
    background: linear-gradient(145deg, rgba(245, 158, 11, 0.7) 0%, rgba(217, 119, 6, 0.8) 100%);
    color: #92400E;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.citation-badge.badge-reference {
    background: linear-gradient(145deg, rgba(168, 85, 247, 0.7) 0%, rgba(147, 51, 234, 0.8) 100%);
    color: #581C87;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.citation-badge.badge-other {
    background: linear-gradient(145deg, rgba(212, 175, 55, 0.7) 0%, rgba(184, 148, 31, 0.8) 100%);
    color: #2D1810;
    border: 1px solid rgba(180, 132, 31, 0.3);
}

.citation-item a {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-weight: 400;
    transition: color 0.2s ease;
    flex: 1;
}

.citation-item a:hover {
    color: white;
    text-decoration: underline;
}

/* Mobile responsive adjustments */
@media (max-width: 480px) {
    .image-thumbnail {
        width: 80px;
        height: 80px;
    }
    
    .tags {
        gap: 0.125rem;
    }
    
    .tag {
        padding: 0.125rem 0.375rem;
        font-size: 0.625rem;
    }
    
    .citation-item {
        font-size: 0.75rem;
    }
    
    .citation-badge {
        font-size: 0.5rem;
        padding: 0.125rem 0.25rem;
    }
    
    .image-modal-content {
        padding: 10px;
    }
    
    .image-modal-close {
        top: 10px;
        right: 20px;
        font-size: 30px;
    }
}

/* Popover citations styling */
.reference-citations {
    position: relative;
    margin-top: 1.5rem;
}

.citations-triggers {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.citation-trigger {
    background: var(--theater-burgundy);
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 0.25rem 0.5rem;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    line-height: 1;
}

.citation-trigger:hover {
    background: #A91B47;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(139, 21, 56, 0.3);
}

/* Inline Citation Superscripts - simplified */
.citation-inline {
    color: var(--theater-burgundy);
    font-size: 0.75em;
    font-weight: bold;
    text-decoration: none;
    position: relative;
    top: -0.3em;
    margin: 0 0.1rem;
    background: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    cursor: pointer;
}

.citation-inline:hover {
    color: #A91B47;
    text-decoration: underline;
}

/* Tags inline layout */
.tags-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap; /* Always maintain single row */
    min-width: 0; /* Allow shrinking */
}

.tags-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

/* Citation Mini-Card Popover - Theater-Inspired Design */
.citation-popover {
    position: fixed;
    z-index: 10001;
    max-width: 65%; /* Never wider than 65% of the card */
    min-width: 280px; /* Minimum width for readability */

    /* Mini-card structure with quote box gradient background on opaque white base */
    background-color: white;
    background-image: linear-gradient(135deg, var(--quote-bg-start) 0%, var(--quote-bg-end) 100%);
    border: 1px solid var(--quote-border);
    border-radius: 12px;
    position: relative;

    /* More pronounced shadow for better definition */
    box-shadow:
        0 20px 40px var(--quote-border),
        0 10px 25px rgba(0, 0, 0, 0.15),
        0 4px 10px rgba(0, 0, 0, 0.1),
        0 2px 4px var(--quote-border);
}

/* Combined Badge Header with Close Button */
.popover-badge-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.75rem;
    border-radius: 8px; /* Match URL area border-radius */
    margin: 1rem 1rem 0.25rem 1rem; /* Further reduced bottom margin for tighter spacing */
    /* transition: all 0.2s ease; */ /* Removed for static appearance */
    border: 1px solid transparent;
}

.citation-badge-text {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.popover-badge-header .popover-close {
    position: relative;
    margin: 0;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 24px;
    height: 24px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    cursor: pointer;
    pointer-events: auto;
    z-index: 999;
    flex-shrink: 0;
    border-radius: 2px;
}

/* Only apply hover effects on devices that support hover */
@media (hover: hover) and (pointer: fine) {
    .popover-badge-header .popover-close:hover {
        background: rgba(0, 0, 0, 0.2);
        color: white;
    }
}

/* Badge header metallic "brass plate" variations for different citation types */
.popover-badge-header.badge-primary {
    background: linear-gradient(145deg, #86EFAC 0%, #4ADE80 100%);
    color: #14532D;
    border: 1px solid rgba(34, 197, 94, 0.2);
    /* Metallic brass plate effect */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.popover-badge-header.badge-scholarly {
    background: linear-gradient(145deg, #93C5FD 0%, #60A5FA 100%);
    color: #1E3A8A;
    border: 1px solid rgba(59, 130, 246, 0.2);
    /* Metallic brass plate effect */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.popover-badge-header.badge-news {
    background: linear-gradient(145deg, #FCD34D 0%, #F59E0B 100%);
    color: #92400E;
    border: 1px solid rgba(245, 158, 11, 0.2);
    /* Metallic brass plate effect */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.popover-badge-header.badge-reference {
    background: linear-gradient(145deg, #C4B5FD 0%, #A78BFA 100%);
    color: #581C87;
    border: 1px solid rgba(168, 85, 247, 0.2);
    /* Metallic brass plate effect */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.popover-badge-header.badge-other {
    background: linear-gradient(145deg, #FDE68A 0%, #D4AF37 100%);
    color: #2D1810;
    border: 1px solid rgba(180, 132, 31, 0.2);
    /* Metallic brass plate effect */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

/* Adjust badge header text and close button colors for different badge types */
.popover-badge-header.badge-primary .citation-badge-text,
.popover-badge-header.badge-scholarly .citation-badge-text,
.popover-badge-header.badge-news .citation-badge-text,
.popover-badge-header.badge-reference .citation-badge-text,
.popover-badge-header.badge-other .citation-badge-text {
    color: inherit;
    font-weight: 700;
    letter-spacing: 1px;
    /* Embossed text effect for metallic brass plate */
    text-shadow: 
        0 1px 0 rgba(255, 255, 255, 0.4),
        0 -1px 0 rgba(0, 0, 0, 0.2);
}

.popover-badge-header.badge-primary .popover-close,
.popover-badge-header.badge-scholarly .popover-close,
.popover-badge-header.badge-news .popover-close,
.popover-badge-header.badge-reference .popover-close,
.popover-badge-header.badge-other .popover-close {
    color: inherit;
    background: rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(0, 0, 0, 0.2);
    font-weight: 700;
    /* Match badge text styling */
    text-shadow: 
        0 1px 0 rgba(255, 255, 255, 0.4),
        0 -1px 0 rgba(0, 0, 0, 0.2);
}

@media (hover: hover) and (pointer: fine) {
    .popover-badge-header.badge-primary .popover-close:hover,
    .popover-badge-header.badge-scholarly .popover-close:hover,
    .popover-badge-header.badge-news .popover-close:hover,
    .popover-badge-header.badge-reference .popover-close:hover,
    .popover-badge-header.badge-other .popover-close:hover {
        background: rgba(0, 0, 0, 0.2);
    }
}

/* Badge headers have no hover effect - they are informational, not interactive */

.popover-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    /* transition: all 0.2s ease; */ /* Removed for static appearance */
    opacity: 1;
    margin-left: 0.5rem;
}

@media (hover: hover) and (pointer: fine) {
    .popover-close:hover {
        opacity: 1;
        background: rgba(0, 0, 0, 0.1);
        transform: scale(1.1);
        
        /* Enhanced card-like shadows */
        box-shadow: 
            0 8px 25px rgba(139, 21, 56, 0.12),
            0 4px 10px rgba(0, 0, 0, 0.08),
            0 2px 4px rgba(0, 0, 0, 0.05),
            inset 0 1px 0 rgba(255, 255, 255, 0.8);
    }
}

/* Mobile-specific touch enhancements for close button */
@media (pointer: coarse) {
    .popover-badge-header .popover-close {
        min-width: 32px;
        min-height: 32px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
}

.citation-popover {
    padding: 0;
    max-width: 280px;
    min-width: 220px;

    /* Animation states */
    opacity: 0;
    visibility: hidden;
    display: none;
    /* transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); */ /* Removed for static appearance */
    transform: scale(0.95);
    pointer-events: none;

    /* Typography coordination with cards */
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--quote-text, #27272A);
}

.citation-popover.show {
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
    pointer-events: auto !important;
    transform: scale(1) !important;
}

.popover-header {
    background-color: white;
    background-image: linear-gradient(135deg, var(--quote-bg-start) 0%, var(--quote-bg-end) 100%);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--quote-border);
    border-radius: 8px 8px 0 0;
    color: var(--quote-text, #27272A);
}

/* Mini-card content area */
.popover-content {
    padding: 1rem;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: transparent; /* Let the outer quote gradient show through */
    border-radius: 9px; /* Inner radius smaller than outer */
    position: relative;
    color: var(--quote-text, #27272A);
}

/* Link styling with emoji indicator - permanent styling */
.popover-content a {
    color: var(--quote-text, #27272A);
    text-decoration: none;
    font-size: 0.875rem;
    line-height: 1.4;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 8px;
    /* transition: all 0.2s ease; */ /* Removed for static appearance */
    border: 1px solid var(--quote-border);
    background: #ffffff; /* White background for link area */
}

/* Link emoji indicator */
.popover-content a::before {
    content: '🔗';
    font-size: 0.75rem;
    flex-shrink: 0;
    opacity: 1;
    margin-top: 0.1rem;
}

.popover-content a:hover {
    background: var(--quote-bg-start);
    border-color: var(--quote-accent);
    /* transform: translateY(-1px); */ /* Removed motion effect */
    box-shadow: 0 3px 12px var(--quote-border);
}

.popover-content a:hover::before {
    opacity: 1;
}

.popover-arrow {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid white;
}

.popover-arrow::before {
    content: '';
    position: absolute;
    top: -7px;
    left: -6px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid rgba(139, 21, 56, 0.2);
}

/* Enhanced Citation Popover - Title, Description, Domain Layout */
.popover-body {
    padding: 0.75rem;
}

.popover-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--quote-text, #27272A);
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.popover-description {
    font-size: 0.85rem;
    color: var(--text-secondary, #52525B);
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

/* Full-width clickable footer link */
.popover-footer-link {
    display: block;
    padding: 0.6rem 0.75rem;
    background: rgba(0, 0, 0, 0.03);
    border-top: 1px solid var(--quote-border, rgba(139, 21, 56, 0.2));
    border-radius: 0 0 12px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--theater-burgundy, #8B1538);
    text-decoration: none;
    text-align: center;
    font-family: 'Inter', system-ui, sans-serif;
}

.popover-footer-link:hover {
    background: var(--quote-bg-start, rgba(139, 21, 56, 0.1));
    text-decoration: none;
}

/* Full-width Badge Header Design */
.citation-badge {
    font-family: 'Bricolage Grotesque', 'Inter', system-ui, sans-serif;
    font-size: 0.625rem;
    padding: 0;
    border-radius: 0;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    flex: 1;
    position: relative;
    
    /* Base metallic effect styles */
    box-shadow: 
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    
    /* Embossed text effect */
    text-shadow: 
        0 1px 0 rgba(255, 255, 255, 0.4),
        0 -1px 0 rgba(0, 0, 0, 0.2);
    
    /* Subtle animation */
    /* transition: all 0.2s ease; */ /* Removed for static appearance */
}

/* Citation badge has no hover effect - informational only */

/* Desktop - remove problematic side-note positioning */
@media (min-width: 768px) {
    .reference-card-content {
        padding-right: 0; /* Remove forced padding */
    }
}

/* Compact footer styling - card-deck-v3 optimized */
.reference-footer {
    padding: 0.75rem 1.5rem !important; /* Remove bottom padding to fix margin imbalance */
    margin: 0 !important; /* Ensure no extra margins */
}

.reference-footer h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    margin: 0 0 0.5rem 0; /* Reduced bottom margin */
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Tags inline layout with separate scrolling area */
.tags-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap; /* Always maintain single row */
    min-width: 0; /* Allow shrinking */
}

.tags-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0; /* Prevent label from shrinking */
}

/* Horizontal scrolling ONLY for the tags container */
.tags-inline .tags {
    display: flex;
    flex-wrap: nowrap !important; /* Force single line */
    gap: 0.5rem;
    overflow-x: auto !important; /* Enable horizontal scrolling */
    overflow-y: hidden;
    margin: 0;
    padding-bottom: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
    max-width: 100%; /* Ensure container doesn't expand */
}

/* Fallback for regular tags */
.tags {
    display: flex;
    flex-wrap: nowrap !important;
    gap: 0.5rem;
    overflow-x: auto !important;
    overflow-y: hidden;
    margin: 0;
    padding-bottom: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}

.tags::-webkit-scrollbar {
    height: 4px;
}

.tags::-webkit-scrollbar-track {
    background: transparent;
}

.tags::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.tags::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

/* Mobile footer optimization */
@media (max-width: 768px) {
    .reference-footer {
        padding: 0.5rem 1rem !important; /* Remove bottom padding for mobile too */
    }
    
    .reference-footer h4 {
        margin-bottom: 0.375rem;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .reference-carousel .reference-list .reference-item,
    .show-card,
    .nav-button,
    .arrows button,
    .top-nav,
    .bottom-nav {
        transition: none !important;
    }
    
    .spinner {
        animation: none;
    }
    
    /* Temporarily commented out to test animation fix
    .reference-carousel.next .reference-item,
    .reference-carousel.prev .reference-item,
    .reference-carousel .reference-list .reference-item.sliding-in-left,
    .reference-carousel .reference-list .reference-item.sliding-in-right,
    .reference-carousel .reference-list .reference-item.sliding-out-left,
    .reference-carousel .reference-list .reference-item.sliding-out-right {
        animation: none !important;
        transition: none !important;
    }
    */
}