:root {
    --primary-color: #302B63;
    --on-primary: #ffffff;
    --surface: #302B63;
    --on-surface: #ffffff;
    --surface-variant: rgba(255, 255, 255, 0.1);
    --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --elevation-2: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);

    /* Paleta kolorów - Primary (Purple Accent #302B63) */
    --primary-50: #ecebf5;
    --primary-100: #c5c0d8;
    --primary-200: #a39cc0;
    --primary-300: #8178a9;
    --primary-400: #665c97;
    --primary-500: #4d4186;
    --primary-600: #423a7d;
    --primary-700: #393373;
    --primary-800: #302B63;
    --primary-900: #201b4b;

    /* Light theme (default) */
    --md-sys-color-background: #f5f5f5;
    --md-sys-color-surface: #f8f8f8;
    --md-sys-color-primary: #302B63;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-on-surface: #1F1F1F;
    --md-sys-color-outline: #79747E;
    --md-sys-color-surface-variant: #e9e9e9;

    /* Error colors */
    /* Error colors (CERT Card) */
    --md-sys-color-error: #BA1A1A;
    --md-sys-color-error-container: #FFDAD6;
    --md-sys-color-on-error: #FFFFFF;
    --md-sys-color-on-error-container: #410002;

    /* Flags visibility */
    --show-pl-flag: block;
    --show-en-flag: none;
}

[data-theme="dark"] {
    /* Dark theme */
    --md-sys-color-background: #1F1F1F;
    --md-sys-color-surface: #121212;
    --md-sys-color-primary: #90CAF9;
    --md-sys-color-on-primary: #003258;
    --md-sys-color-on-surface: #E3E3E3;
    --md-sys-color-outline: #938F99;
    --md-sys-color-surface-variant: #4c4c4c;

    /* Error colors dark */
    /* Error colors dark (CERT Card) */
    --md-sys-color-error: #FFB4AB;
    --md-sys-color-error-container: #93000A;
    --md-sys-color-on-error: #690005;
    --md-sys-color-on-error-container: #FFDAD6;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Roboto', sans-serif;
    color: var(--md-sys-color-on-surface);
    background: var(--md-sys-color-background);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

/* --- APP BAR / NAVIGATION --- */
.app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    transform: translateY(0);
    transition: transform 0.3s ease-in-out, background-color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

/* Style dla belki po przewinięciu */
.app-bar.visible {
    background-color: var(--primary-color);
    box-shadow: var(--elevation-1);
}

/* Style dla trybu ciemnego po przewinięciu */
[data-theme="dark"] .app-bar.visible {
    background-color: var(--md-sys-color-surface);
}

/* Przezroczysta belka w hero section (dla obu trybów) */
.app-bar:not(.visible) {
    background-color: transparent;
    box-shadow: none;
}

/* Kolory tekstu i ikon w hero section (dla obu trybów) */
.app-bar:not(.visible) .nav-button,
.app-bar:not(.visible) .theme-toggle,
.app-bar:not(.visible) .app-title {
    color: var(--on-primary);
}


[data-theme="dark"] .app-bar:not(.visible) .nav-button,
[data-theme="dark"] .app-bar:not(.visible) .theme-toggle,
[data-theme="dark"] .app-bar:not(.visible) .app-title {
    color: var(--on-primary);
}

/* Kolory tekstu i ikon po przewinięciu w trybie jasnym */
.app-bar.visible .nav-button,
.app-bar.visible .theme-toggle,
.app-bar.visible .app-title {
    color: var(--on-primary);
}

/* Kolory tekstu i ikon po przewinięciu w trybie ciemnym */
[data-theme="dark"] .app-bar.visible .nav-button,
[data-theme="dark"] .app-bar.visible .theme-toggle,
[data-theme="dark"] .app-bar.visible .app-title {
    color: var(--md-sys-color-on-surface);
}

@media (max-width: 768px) {

    /* Hide excess plus icons on mobile to reduce clutter */
    .plus:nth-child(n+15) {
        display: none;
    }
}

.app-bar-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: opacity 0.2s ease-in-out;
    text-decoration: none;
    color: inherit;
}

.app-bar-left:hover {
    opacity: 0.8;
}

.app-logo {
    height: 40px;
    width: auto;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 500;
    margin: 0;
    color: var(--on-surface);
    font-family: 'Roboto Mono', monospace;
}

.app-bar-nav {
    display: flex;
    gap: 4px;
    align-items: center;
}

.nav-button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: none;
    border: none;
    color: var(--on-primary);
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    transition: background-color 0.2s;
    border-radius: 24px;
}

.nav-button.active {
    position: relative;
    font-weight: 500;
}

.nav-button.active::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 2px;
    background-color: var(--on-primary);
    border-radius: 1px;
}

.nav-divider {
    width: 2px;
    height: 24px;
    background-color: var(--on-primary);
    border-radius: 1px;
    margin: 0 4px 0 0;
}

/* Kolor dividera w trybie ciemnym po przewinięciu */
[data-theme="dark"] .app-bar.visible .nav-divider {
    background-color: var(--md-sys-color-on-surface);
}

.theme-toggle,
.language-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    transition: background-color 0.2s;
}

/* Unified hover effect */
.nav-button:hover,
.language-toggle:hover,
.theme-toggle:hover {
    background-color: var(--surface-variant);
    opacity: 1;
    transform: none;
}

/* Language Flags */
.language-flag {
    display: flex;
    align-items: center;
    justify-content: center;
}

.language-flag[data-lang="pl"] {
    display: var(--show-pl-flag, block);
}

.language-flag[data-lang="en"] {
    display: var(--show-en-flag, none);
}

[lang="en"] .language-flag[data-lang="pl"] {
    display: var(--show-pl-flag, none);
}

[lang="en"] .language-flag[data-lang="en"] {
    display: var(--show-en-flag, block);
}

.flag-icon {
    width: 24px;
    height: 16px;
    display: block;
    border-radius: 2px;
}

/* --- FOOTER --- */
.footer {
    background-color: var(--md-sys-color-surface);
    padding: 24px 0;
    margin-top: auto;
    border-top: 1px solid rgba(121, 116, 126, 0.08);
}

[data-theme="dark"] .footer {
    border-top-color: rgba(255, 255, 255, 0.08);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
    text-align: center;
    color: var(--md-sys-color-on-surface);
    opacity: 0.6;
    font-size: 0.875rem;
    line-height: 1.4;
    letter-spacing: 0.15px;
}

/* --- UTILITIES --- */
.hidden {
    display: none !important;
}

/* --- POPUPS / MODALS --- */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.popup-overlay.show {
    display: flex;
    opacity: 1;
}

.popup-content {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    padding: 24px;
    border-radius: 24px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transform: scale(1);
    transition: transform 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.popup-overlay.show .popup-content {
    transform: scale(1);
}

.popup-content h3 {
    font-family: 'Roboto Mono', monospace;
    font-size: 1.5rem;
    margin-top: 0;
    margin-bottom: 24px;
    color: var(--md-sys-color-primary);
    padding-right: 40px;
}

.join-popup-text p {
    margin-bottom: 16px;
    line-height: 1.6;
}

.join-popup-text p:last-child {
    margin-bottom: 0;
}

.popup-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--md-sys-color-on-surface);
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-close:hover {
    background-color: var(--md-sys-color-surface-variant);
}

/* Blur effects for body/background when popup is open */
body.map-open .app-bar,
body.map-open .main-content,
body.map-open .hero-section,
body.map-open .content-container,
body.map-open .materials-grid,
body.join-open .app-bar,
body.join-open .main-content,
body.join-open .hero-section,
body.join-open .content-container,
body.join-open .materials-grid,
body.modal-open .app-bar,
body.modal-open .main-content,
body.modal-open .content-container,
body.modal-open .materials-grid {
    filter: blur(8px);
    transition: filter 0.1s ease-in-out;
}

/* --- BUTTONS --- */
.join-button,
.download-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    border-radius: 24px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.join-button:hover,
.download-button:hover {
    opacity: 0.9;
    background-color: var(--primary-800);
    transform: translateY(-2px);
}

.join-button .material-icons,
.download-button .material-icons {
    font-size: 20px;
}

/* Link utilities */
.link-highlight {
    color: var(--md-sys-color-primary);
    text-decoration: none;
    font-weight: 500;
}

.link-highlight:hover {
    text-decoration: underline;
}

.highlight-name {
    font-weight: 700;
    color: inherit;
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    .nav-button span:not(.material-icons) {
        display: none;
    }

    .nav-button {
        padding: 8px;
    }

    .app-title {
        display: none;
    }

}

/* Hero Background Animation (Plus signs) - Shared for all pages */
.plus-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    -webkit-mask-image: radial-gradient(circle at center, transparent 0%, transparent 15%, black 50%);
    mask-image: radial-gradient(circle at center, transparent 0%, transparent 15%, black 50%);
    z-index: 0;
}

.plus {
    --rotation: 0deg;
    --size: 24px;
    position: absolute;
    font-size: var(--size);
    transform: rotate(var(--rotation));
    opacity: 0.5;
    color: white;
    user-select: none;
    animation: twinkle 4s infinite ease-in-out;
    /* filter: blur(2.5px); REMOVED for performance */
}

@keyframes twinkle {

    0%,
    100% {
        opacity: 0.2;
    }

    50% {
        opacity: 0.8;
    }
}

/* Randomize twinkle delays */
.plus:nth-child(odd) {
    animation-duration: 3s;
}

.plus:nth-child(2n) {
    animation-delay: 0.5s;
}

.plus:nth-child(3n) {
    animation-delay: 1s;
}

.plus:nth-child(5n) {
    animation-delay: 1.5s;
    animation-duration: 5s;
}

.plus:nth-child(7n) {
    animation-delay: 2s;
}

/* Pozycje plusów */
.plus:nth-child(1) {
    --rotation: 15deg;
    --size: 24px;
    top: 10%;
    left: 15%;
}

.plus:nth-child(2) {
    --rotation: -10deg;
    --size: 28px;
    top: 20%;
    left: 80%;
}

.plus:nth-child(3) {
    --rotation: 25deg;
    --size: 24px;
    top: 45%;
    left: 15%;
}

.plus:nth-child(4) {
    --rotation: -20deg;
    --size: 28px;
    top: 65%;
    left: 90%;
}

.plus:nth-child(5) {
    --rotation: 5deg;
    --size: 22px;
    top: 75%;
    left: 25%;
}

.plus:nth-child(6) {
    --rotation: -15deg;
    --size: 30px;
    top: 35%;
    left: 95%;
}

.plus:nth-child(7) {
    --rotation: 30deg;
    --size: 20px;
    top: 85%;
    left: 75%;
}

.plus:nth-child(8) {
    --rotation: -25deg;
    --size: 26px;
    top: 5%;
    left: 45%;
}

.plus:nth-child(9) {
    --rotation: 20deg;
    --size: 34px;
    top: 55%;
    left: 5%;
}

.plus:nth-child(10) {
    --rotation: -5deg;
    --size: 16px;
    top: 95%;
    left: 35%;
}

.plus:nth-child(11) {
    --rotation: 10deg;
    --size: 28px;
    top: 20%;
    left: 65%;
}

.plus:nth-child(12) {
    --rotation: -30deg;
    --size: 22px;
    top: 40%;
    left: 30%;
}

.plus:nth-child(13) {
    --rotation: 35deg;
    --size: 32px;
    top: 60%;
    left: 55%;
}

.plus:nth-child(14) {
    --rotation: -15deg;
    --size: 24px;
    top: 80%;
    left: 85%;
}

.plus:nth-child(15) {
    --rotation: 25deg;
    --size: 20px;
    top: 10%;
    left: 25%;
}

.plus:nth-child(16) {
    --rotation: -20deg;
    --size: 36px;
    top: 30%;
    left: 75%;
}

.plus:nth-child(17) {
    --rotation: 15deg;
    --size: 26px;
    top: 50%;
    left: 40%;
}

.plus:nth-child(18) {
    --rotation: -25deg;
    --size: 18px;
    top: 70%;
    left: 20%;
}

.plus:nth-child(19) {
    --rotation: 30deg;
    --size: 32px;
    top: 90%;
    left: 60%;
}

.plus:nth-child(20) {
    --rotation: -10deg;
    --size: 24px;
    top: 15%;
    left: 50%;
}

.plus:nth-child(21) {
    --rotation: 20deg;
    --size: 28px;
    top: 82%;
    left: 12%;
}

.plus:nth-child(22) {
    --rotation: -15deg;
    --size: 22px;
    top: 38%;
    left: 88%;
}

.plus:nth-child(23) {
    --rotation: 25deg;
    --size: 34px;
    top: 68%;
    left: 45%;
}

.plus:nth-child(24) {
    --rotation: -20deg;
    --size: 20px;
    top: 8%;
    left: 78%;
}

.plus:nth-child(25) {
    --rotation: 15deg;
    --size: 26px;
    top: 92%;
    left: 32%;
}

.plus:nth-child(26) {
    --rotation: -30deg;
    --size: 30px;
    top: 42%;
    left: 8%;
}

.plus:nth-child(27) {
    --rotation: 10deg;
    --size: 24px;
    top: 72%;
    left: 92%;
}

.plus:nth-child(28) {
    --rotation: -25deg;
    --size: 18px;
    top: 22%;
    left: 68%;
}

.plus:nth-child(29) {
    --rotation: 35deg;
    --size: 32px;
    top: 48%;
    left: 28%;
}

.plus:nth-child(30) {
    --rotation: -5deg;
    --size: 26px;
    top: 78%;
    left: 52%;
}

.plus:nth-child(31) {
    --rotation: 20deg;
    --size: 22px;
    top: 18%;
    left: 95%;
}

.plus:nth-child(32) {
    --rotation: -15deg;
    --size: 36px;
    top: 58%;
    left: 15%;
}

.plus:nth-child(33) {
    --rotation: 30deg;
    --size: 20px;
    top: 88%;
    left: 82%;
}

.plus:nth-child(34) {
    --rotation: -25deg;
    --size: 28px;
    top: 28%;
    left: 42%;
}

.plus:nth-child(35) {
    --rotation: 15deg;
    --size: 24px;
    top: 62%;
    left: 72%;
}

.plus:nth-child(36) {
    --rotation: -20deg;
    --size: 32px;
    top: 12%;
    left: 22%;
}

.plus:nth-child(37) {
    --rotation: 25deg;
    --size: 26px;
    top: 52%;
    left: 92%;
}

.plus:nth-child(38) {
    --rotation: -10deg;
    --size: 20px;
    top: 82%;
    left: 38%;
}

.plus:nth-child(39) {
    --rotation: 30deg;
    --size: 34px;
    top: 32%;
    left: 58%;
}

.plus:nth-child(40) {
    --rotation: -15deg;
    --size: 28px;
    top: 98%;
    left: 88%;
}

/* Fireworks */
.firework-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    animation: explode 1s ease-out forwards;
    z-index: 2;
    /* filter: blur(1.5px); REMOVED for performance */
}

@keyframes explode {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    20% {
        opacity: 0.8;
    }

    40% {
        opacity: 1;
    }

    60% {
        opacity: 0.6;
    }

    80% {
        opacity: 0.8;
    }

    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

.firework-sparkle {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
    /* Maintain the final position of the main particle */
    transform: translate(var(--tx), var(--ty));
    animation: sparkle-decay 1.5s ease-out forwards;
    box-shadow: 0 0 4px 1px rgba(255, 255, 255, 0.8);
    /* filter: blur(1px); REMOVED for performance */
}

@keyframes sparkle-decay {
    0% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0.1);
    }

    35% {
        opacity: 1;
        transform: translate(var(--tx), var(--ty)) scale(1);
    }

    25% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    75% {
        opacity: 0.2;
    }

    100% {
        opacity: 0;
        /* Move by drift vector */
        transform: translate(calc(var(--tx) + var(--dx)), calc(var(--ty) + var(--dy))) scale(0);
    }
}

/* Background Effects Container (Optimized Blur) */
.hero-bg-effects {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    filter: blur(3px);
    /* Apply blur once here */
}

/* Ensure content is above effects */
.hero-content {
    z-index: 1;
    position: relative;
}