header a:focus-visible {
    /* Add a focus ring for accessibility */
    outline: 2px solid #ef4444; /* Red */
    border-radius: 4px;
    outline-offset: 2px;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: #111827; /* Dark Gray */
}
.profile-card {
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.profile-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
/* Modal styles */
.modal {
    transition: opacity 0.25s ease;
}
.modal-content {
    transition: transform 0.25s ease;
}
.modal.hidden {
    pointer-events: none;
}
/* Spinner for loading state */
.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #ef4444; /* Red */
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Skeleton loader animation */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
}

.skeleton-card {
    background-color: #1f2937;
    border-radius: 0.5rem;
    overflow: hidden;
}

.skeleton-image {
    height: 12rem;
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-text {
    height: 1rem;
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 0.25rem;
}

.skeleton-text-sm {
    height: 0.75rem;
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 0.25rem;
}

/* Toast animations */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast {
    animation: slideIn 0.3s ease-out forwards;
}

.toast-exit {
    animation: fadeOut 0.3s ease-in forwards;
}

/* Vote button animations */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

@keyframes voteBounce {
    0% { transform: scale(1); }
    30% { transform: scale(1.3); }
    50% { transform: scale(0.9); }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.vote-success {
    animation: voteBounce 0.5s ease-out;
}

.vote-loading {
    animation: pulse 1s ease-in-out infinite;
    opacity: 0.6;
}

/* Touch/active states for buttons */
.vote-btn:active:not(:disabled) {
    transform: scale(0.9);
}

.top5-card:active {
    transform: scale(0.98);
}

button:active:not(:disabled) {
    transform: scale(0.97);
}

/* Ensure minimum touch target size */
.vote-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Focus-visible styles for keyboard accessibility */
.vote-btn:focus-visible {
    outline: 2px solid #ef4444;
    outline-offset: 2px;
    border-radius: 4px;
}

.top5-card:focus-visible {
    outline: 2px solid #ef4444;
    outline-offset: 2px;
}

.profile-card:focus-visible {
    outline: 2px solid #ef4444;
    outline-offset: 2px;
}

/* Screen reader only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Search clear button */
.search-container {
    position: relative;
}

.search-clear-btn {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

/* Only apply display:flex when not hidden - prevents override of Tailwind's .hidden */
.search-clear-btn:not(.hidden) {
    display: flex;
}

.search-clear-btn:hover {
    color: #fff;
}

/* Preserve vertical centering when button is active (higher specificity than button:active:not(:disabled)) */
.search-clear-btn:active:not(:disabled) {
    transform: translateY(-50%);
}

/* Modal loading state */
.modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    gap: 1rem;
}

/* Small loader for vote buttons */
.loader-small {
    border: 2px solid #f3f3f3;
    border-top: 2px solid #ef4444;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 0.8s linear infinite;
}

/* View toggle buttons */
.view-toggle-btn {
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    border: 1px solid #374151;
    background-color: #1f2937;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s;
}

.view-toggle-btn:hover {
    background-color: #374151;
    color: #fff;
}

.view-toggle-btn.active {
    background-color: #ef4444;
    border-color: #ef4444;
    color: #fff;
}

/* Profile card images — show a grey placeholder while loading, then fade in */
.profile-card img,
.top5-card img {
    background-color: #374151;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.profile-card img.loaded,
.top5-card img.loaded {
    opacity: 1;
}

/* Party group sections */
.party-group {
    margin-bottom: 1rem;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid #374151;
    background-color: #1f2937;
}

.party-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.party-header:hover {
    filter: brightness(1.1);
}

.party-header .chevron {
    transition: transform 0.3s ease;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.7);
}

.party-header .chevron.open {
    transform: rotate(90deg);
}

.party-header .party-logo {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.party-header .party-name {
    font-weight: 700;
    font-size: 1.125rem;
    color: #fff;
    flex-grow: 1;
}

.party-header .party-count {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(0, 0, 0, 0.3);
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
}

.party-header .party-votes {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.3);
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
}

.party-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.party-body.open {
    /* ~2 full card rows (2×378px cards + 32px gap + 36px inner padding).
       Cap at 85vh so the section never exceeds the viewport on small screens. */
    max-height: min(824px, 85vh);
    overflow-y: auto;
}

.party-body-inner {
    padding: 1rem 1.25rem 1.25rem;
}

/* Official party logo images — white pill background for visibility */
.party-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Party logo in accordion headers */
.party-header .party-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: #fff;
    border-radius: 6px;
    padding: 3px;
    flex-shrink: 0;
}

.party-header .party-logo img,
.party-header .party-logo svg {
    width: 22px;
    height: 22px;
    object-fit: contain;
}

/* Party colour dot in leaderboard cards */
.party-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
}

/* Party logo in modal header */
.modal-party-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: #fff;
    border-radius: 0.75rem;
    padding: 8px;
    flex-shrink: 0;
}

.modal-party-logo svg {
    width: 48px;
    height: 48px;
}

.modal-party-logo img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

/* Responsive modal header — shrink party logo on small screens */
@media (max-width: 480px) {
    .modal-party-logo {
        width: 40px;
        height: 40px;
        padding: 5px;
        border-radius: 0.5rem;
    }
    .modal-party-logo svg,
    .modal-party-logo img {
        width: 30px;
        height: 30px;
    }
}

/* Close modal button — ensure 44px touch target */
.close-modal-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.close-modal-btn:focus-visible {
    outline: 2px solid #ef4444;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Party header focus style for keyboard navigation */
.party-header:focus-visible {
    outline: 2px solid #ef4444;
    outline-offset: -2px;
}

/* Card body focus style */
.card-body:focus-visible {
    outline: 2px solid #ef4444;
    outline-offset: -2px;
}

/* Ad container */
.ad-container {
    max-width: 728px;
    margin: 0 auto 2rem;
    padding: 0.75rem;
    background-color: #1f2937;
    border: 1px solid #374151;
    border-radius: 0.5rem;
    text-align: center;
}

.ad-label {
    display: block;
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    margin-bottom: 0.5rem;
}