:root,
[data-bs-theme="light"] {
    color-scheme: light;
    --app-bg: #f4f6f8;
    --app-surface: #ffffff;
    --app-surface-muted: #f8f9fb;
    --app-border: #e2e6ea;
    --app-navbar-bg: rgba(28, 31, 37, 0.96);
    --app-footer-bg: #ffffff;
    --app-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

[data-bs-theme="dark"] {
    color-scheme: dark;
    --app-bg: #0d1117;
    --app-surface: #161b22;
    --app-surface-muted: #1c2128;
    --app-border: #30363d;
    --app-navbar-bg: rgba(10, 13, 18, 0.94);
    --app-footer-bg: #11161d;
    --app-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    --bs-body-color: #e6edf3;
    --bs-secondary-color: #9da7b3;
    --bs-tertiary-bg: #21262d;
    --bs-border-color: #30363d;
}

body {
    min-height: 100vh;
    padding-top: 4.5rem;
    padding-bottom: 3rem;
    background-color: var(--app-bg);
    color: var(--bs-body-color);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.app-navbar {
    background: var(--app-navbar-bg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.14);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.navbar-brand {
    font-weight: 700;
    letter-spacing: -0.01em;
}

.navbar-controls {
    gap: 0.25rem;
}

.theme-toggle {
    width: 2.2rem;
    height: 2.2rem;
    display: inline-grid;
    place-items: center;
    padding: 0;
    color: rgba(255, 255, 255, 0.82);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.6rem;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
    font-size: 1rem;
    line-height: 1;
    overflow: hidden;
}

/* Force flag emoji to fit inside the toggle on all devices */
.theme-toggle span[aria-hidden] {
    font-size: 0.9rem;
    display: inline-block;
    transform: scale(0.85);
}

/* Vertically centre the toggle inside navbar-nav items on desktop */
.navbar-nav .nav-item .theme-toggle {
    margin-top: 0.45rem;
}

.theme-toggle:hover,
.theme-toggle:focus-visible,
.theme-toggle.show {
    color: #fff;
    background: rgba(255, 255, 255, 0.13);
    border-color: rgba(255, 255, 255, 0.2);
}

.theme-toggle:active {
    transform: translateY(1px);
}

.theme-menu {
    min-width: 11.5rem;
    padding: 0.45rem;
    border-color: var(--app-border);
    border-radius: 0.75rem;
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
}

.theme-menu .dropdown-header {
    padding: 0.35rem 0.65rem 0.45rem;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border-radius: 0.5rem;
    padding: 0.5rem 0.65rem;
}

.theme-option .theme-check {
    margin-left: auto;
    opacity: 0;
    font-size: 0.8rem;
}

.theme-option.is-active {
    color: var(--bs-primary);
    background: rgba(var(--bs-primary-rgb), 0.11);
    font-weight: 600;
}

.theme-option.is-active .theme-check {
    opacity: 1;
}

.footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 40px;
    line-height: 40px;
    background-color: var(--app-footer-bg);
    border-top: 1px solid var(--app-border);
    text-align: center;
    z-index: 10;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.card {
    margin-bottom: 20px;
    background-color: var(--app-surface);
    border-color: var(--app-border);
    box-shadow: var(--app-shadow);
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.dropdown-menu,
.modal-content,
.accordion-item,
.offcanvas {
    border-color: var(--app-border);
}

[data-bs-theme="dark"] .bootstrap-select > .dropdown-toggle {
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .bootstrap-select > .dropdown-toggle:focus,
[data-bs-theme="dark"] .bootstrap-select > .dropdown-toggle:hover {
    color: var(--bs-body-color);
    background-color: var(--bs-tertiary-bg);
    border-color: var(--bs-border-color);
}

.subtitle-card {
    transition: transform 0.2s, background-color 0.2s ease, border-color 0.2s ease;
}

.subtitle-card:hover {
    transform: translateY(-5px);
}

.active-subtitle {
    border: 2px solid #198754;
}

.vote-buttons .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.vote-count {
    font-weight: bold;
    min-width: 30px;
    display: inline-block;
    text-align: center;
}

.poster-img {
    max-height: 300px;
    object-fit: contain;
}

.toast-container {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050;
}

.poster-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.poster-image {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.poster-image.loaded {
    opacity: 1;
}

.poster-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background-color: var(--app-surface-muted);
    border: 1px solid var(--app-border);
    border-radius: 0.375rem;
    z-index: 1;
    opacity: 1;
    transition: opacity 0.3s ease-in-out, background-color 0.2s ease, border-color 0.2s ease;
}

.poster-fallback i {
    font-size: 2rem;
    color: var(--bs-secondary-color);
    animation: pulse 2s infinite;
}

.poster-fallback.hidden {
    opacity: 0;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.poster-wrapper-card {
    position: relative;
    width: 100%;
    height: 300px;
    min-height: 200px;
    overflow: hidden;
}

.poster-wrapper-card .poster-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    opacity: 0;
    transform: scale(1.05);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.poster-wrapper-card .poster-image.loaded {
    opacity: 1;
    transform: scale(1);
}

.poster-fallback-card {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--app-surface-muted) 0%, var(--app-surface) 100%);
    z-index: 1;
    opacity: 1;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.poster-fallback-card i {
    font-size: 4rem;
    color: var(--bs-secondary-color);
    animation: fadeInOut 2s ease-in-out infinite;
}

.poster-fallback-card.hidden {
    opacity: 0;
    transform: scale(0.95);
}

/* Bootstrap 5.3 keeps .bg-info and .bg-light light in both themes, but
   .list-group-item takes its colour from --bs-body-color, which the dark theme
   sets near-white. Override both background and text for dark mode. */
[data-bs-theme="dark"] .list-group-item.bg-info {
    background-color: rgba(13, 202, 240, 0.15) !important;
    color: #a8d8ea;
}

[data-bs-theme="dark"] .list-group-item.bg-light {
    background-color: rgba(255, 255, 255, 0.06) !important;
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .list-group-item.bg-info .text-muted,
[data-bs-theme="dark"] .list-group-item.bg-light .text-muted {
    color: rgba(255, 255, 255, 0.5) !important;
}

/* Card headers in dark mode: muted versions of the Bootstrap colours */
[data-bs-theme="dark"] .card-header.bg-primary {
    background-color: rgba(13, 110, 253, 0.2) !important;
    color: #8bb9fe;
    border-color: rgba(13, 110, 253, 0.15);
}

[data-bs-theme="dark"] .card-header.bg-success {
    background-color: rgba(25, 135, 84, 0.2) !important;
    color: #75d4a7;
    border-color: rgba(25, 135, 84, 0.15);
}

[data-bs-theme="dark"] .card-header.bg-info {
    background-color: rgba(13, 202, 240, 0.15) !important;
    color: #86e4f5;
    border-color: rgba(13, 202, 240, 0.1);
}

/* "Install Addon" button in dark mode */
[data-bs-theme="dark"] .card-body .btn-primary:not(.btn-outline-primary) {
    background-color: rgba(13, 110, 253, 0.25);
    border-color: rgba(13, 110, 253, 0.4);
    color: #8bb9fe;
}
[data-bs-theme="dark"] .card-body .btn-primary:not(.btn-outline-primary):hover {
    background-color: rgba(13, 110, 253, 0.4);
    color: #fff;
}

/* Stats buttons and badges in dark mode */
[data-bs-theme="dark"] .btn-outline-primary {
    color: #8bb9fe;
    border-color: rgba(13, 110, 253, 0.35);
}
[data-bs-theme="dark"] .btn-outline-primary:hover {
    background-color: rgba(13, 110, 253, 0.2);
    color: #fff;
}
[data-bs-theme="dark"] .btn-outline-primary .badge.bg-primary {
    background-color: rgba(13, 110, 253, 0.3) !important;
    color: #8bb9fe;
}

.list-group-item.bg-info {
    transition: filter 0.3s ease-in-out;
    filter: brightness(1);
}

.list-group-item.bg-info.highlighted {
    filter: brightness(0.9);
}

/* Coffee Banner */
.coffee-banner {
    display: none;
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1050;
    max-width: 350px;
    width: 90%;
}

@media (min-width: 768px) {
    .coffee-banner {
        left: auto;
        right: 20px;
        transform: none;
        width: auto;
    }
}

@media (min-width: 992px) {
    .navbar-collapse {
        order: 2;
    }

    .navbar-controls {
        order: 3;
        margin-left: 0.5rem;
    }
}

/* Mobile navbar adjustments */
@media (max-width: 991.98px) {
    .navbar-toggler {
        padding: 0.15rem 0.4rem;
        font-size: 1rem;
    }

    .navbar-toggler-icon {
        width: 1.2em;
        height: 1.2em;
    }

    #langDropdownMobile {
        padding: 0.25rem 0.25rem 0.25rem 0.5rem;
        font-size: 1.2rem;
    }

    #langDropdownMobile::after {
        display: none;
    }

    .navbar .container {
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .navbar-controls {
        margin-left: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    body,
    .card,
    .footer,
    .theme-toggle,
    .subtitle-card,
    .poster-fallback {
        transition: none;
    }
}
