/* =========================================================
   1. ZMIENNE I RESET (BRAK ZEWNĘTRZNYCH ZALEŻNOŚCI)
   ========================================================= */
:root {
    --pumas-navy: #002B5C;
    --pumas-navy-dark: #001836;
    --pumas-gold: #D4AF37;
    --pumas-gold-bright: #FACC15;
    --term-bg: #070D19;
    --term-card: #0C172B;
    --term-border: rgba(212, 175, 55, 0.35);
    --text-light: #F1F5F9;
    --text-muted: #94A3B8;
    --mex-green: #006847;
    --mex-white: #FFFFFF;
    --mex-red: #CE1126;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

html, body {
    width: 100%;
    min-height: 100dvh;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--term-bg);
    color: var(--text-light);
    overflow-x: hidden;
    transition: background 0.8s ease;
}

body.mode-terminal {
    background-color: var(--term-bg);
    background-image:
        radial-gradient(circle at 50% 0%, rgba(0, 43, 92, 0.65), transparent 65%),
        linear-gradient(rgba(212, 175, 55, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(212, 175, 55, 0.06) 1px, transparent 1px);
    background-size: 100% 100%, 28px 28px, 28px 28px;
}

body.mode-fiesta {
    background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 45%, #FFEDD5 100%);
    color: #1E293B;
}

.hidden {
    display: none !important;
}

.mono {
    font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

/* =========================================================
   2. GLOBALNE KONTROLKI (DŹWIĘK) I CANVAS KONFETTI
   ========================================================= */
#mute-btn {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1200;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(212, 175, 55, 0.5);
    background: rgba(0, 24, 54, 0.85);
    backdrop-filter: blur(8px);
    color: var(--pumas-gold-bright);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    transition: transform 0.15s ease;
}

#mute-btn:hover { transform: scale(1.07); }
#mute-btn:active { transform: scale(0.94); }

body.mode-fiesta #mute-btn {
    background: rgba(255, 255, 255, 0.92);
    color: #002B5C;
    border-color: var(--pumas-gold);
}

#confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

/* =========================================================
   3. FAZA 0: FAŁSZYWE LOGOWANIE (EDYCJA PUMAS UNAM)
   ========================================================= */
#stage-login {
    min-height: 100dvh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 64px 16px 24px;
    position: relative;
}

/* Dyskretny przycisk do wgrania zdjęcia do testu w rogu */
.upload-test-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px dashed rgba(212, 175, 55, 0.45);
    background: rgba(0, 24, 54, 0.82);
    color: #CBD5E1;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: border-color 0.2s, color 0.2s, transform 0.15s;
}

.upload-test-btn:hover {
    border-color: var(--pumas-gold-bright);
    color: #FFFFFF;
    transform: translateY(-1px);
}

.login-card {
    width: 100%;
    max-width: 470px;
    background: linear-gradient(180deg, #0D1B33 0%, #091224 100%);
    border: 1px solid var(--term-border);
    border-radius: 20px;
    padding: 24px 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(212, 175, 55, 0.12);
    position: relative;
    overflow: hidden;
}

.login-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--pumas-navy), var(--pumas-gold), var(--pumas-navy));
}

.terminal-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--pumas-gold-bright);
    background: rgba(212, 175, 55, 0.12);
    border: 1px solid rgba(212, 175, 55, 0.35);
    padding: 5px 11px;
    border-radius: 999px;
    margin-bottom: 14px;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22C55E;
    box-shadow: 0 0 8px #22C55E;
    animation: pulseDot 1.5s infinite;
}

@keyframes pulseDot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}

.login-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: #FFFFFF;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
}

.login-sub {
    font-size: 0.86rem;
    color: var(--text-muted);
    margin-bottom: 18px;
}

/* Ramka ze zdjęciem Dawida - ID Badge */
.id-dossier {
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(0, 43, 92, 0.35);
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 18px;
    position: relative;
}

.id-photo-wrap {
    width: 78px;
    height: 92px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid var(--pumas-gold);
    background: var(--pumas-navy-dark);
    position: relative;
    flex-shrink: 0;
}

.id-photo-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    filter: contrast(1.1) saturate(0.85);
    image-rendering: pixelated;
}

.id-scanline {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.18) 0px,
        rgba(0, 0, 0, 0.18) 2px,
        transparent 2px,
        transparent 4px
    );
    pointer-events: none;
}

.id-meta {
    flex: 1;
    min-width: 0;
}

.id-stamp {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: #070D19;
    background: var(--pumas-gold-bright);
    padding: 3px 7px;
    border-radius: 5px;
    margin-bottom: 6px;
}

.id-meta-line {
    font-size: 0.78rem;
    color: #CBD5E1;
    line-height: 1.45;
}

.id-meta-line strong {
    color: #FFFFFF;
}

.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--pumas-gold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: #060B14;
    color: #FFFFFF;
    font-size: 1rem;
    outline: none;
    user-select: text;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    border-color: var(--pumas-gold-bright);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2);
}

.captcha-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    background: rgba(6, 11, 20, 0.75);
    border: 1px solid rgba(212, 175, 55, 0.25);
    margin-bottom: 12px;
    cursor: pointer;
}

.captcha-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--pumas-gold);
    cursor: pointer;
    flex-shrink: 0;
}

.captcha-row span {
    font-size: 0.88rem;
    line-height: 1.35;
    color: #E2E8F0;
}

.login-error {
    min-height: 20px;
    font-size: 0.82rem;
    color: #FCA5A5;
    font-weight: 600;
    margin-bottom: 10px;
}

.btn-gold {
    width: 100%;
    padding: 15px 18px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #B48A1E, #FACC15);
    color: #071226;
    font-size: 0.98rem;
    font-weight: 900;
    letter-spacing: 0.03em;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(212, 175, 55, 0.32), 0 3px 0 #85610C;
    transition: transform 0.14s ease, filter 0.14s ease;
}

.btn-gold:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.btn-gold:active {
    transform: translateY(2px);
}

/* Animacja ładowania / hakowania */
#loading-screen {
    padding: 20px 6px;
    text-align: center;
}

.hack-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(212, 175, 55, 0.2);
    border-top-color: var(--pumas-gold-bright);
    border-radius: 50%;
    margin: 0 auto 18px;
    animation: spin 0.75s linear infinite;
}

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

.hack-log {
    background: #050912;
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 12px;
    padding: 14px;
    text-align: left;
    font-size: 0.82rem;
    line-height: 1.7;
    color: #CBD5E1;
}

.hack-log .ok { color: #4ADE80; font-weight: 700; }
.hack-log .gold { color: var(--pumas-gold-bright); font-weight: 700; }

/* =========================================================
   4. WSPÓLNY EKRAN ARCADE (FAZY 1, 2, 3)
   ========================================================= */
#stage-arcade {
    height: 100dvh;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 10px 12px;
    overflow: hidden;
    position: relative;
}

.arcade-hud {
    width: 100%;
    max-width: 780px;
    background: rgba(12, 23, 43, 0.92);
    border: 1px solid rgba(212, 175, 55, 0.38);
    border-radius: 16px;
    padding: 10px 14px;
    padding-right: 58px; /* miejsce na przycisk wyciszenia */
    margin-bottom: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    z-index: 20;
}

.hud-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 7px;
}

.hud-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.hud-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--pumas-gold-bright);
    object-fit: cover;
    object-position: center top;
    background: var(--pumas-navy);
    flex-shrink: 0;
}

.hud-stage-title {
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--pumas-gold-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hud-stats {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.88rem;
    font-weight: 700;
    flex-shrink: 0;
}

.hud-score-pill {
    background: rgba(0, 43, 92, 0.7);
    border: 1px solid rgba(212, 175, 55, 0.4);
    padding: 3px 10px;
    border-radius: 999px;
    color: #FFFFFF;
}

.hud-progress-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-bar-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
}

.hud-bar-track {
    flex: 1;
    height: 12px;
    background: #050912;
    border-radius: 999px;
    border: 1px solid rgba(212, 175, 55, 0.3);
    overflow: hidden;
}

.hud-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #006847, #22C55E, #FACC15);
    transition: width 0.2s ease;
}

.hud-bar-fill.boss-hp {
    background: linear-gradient(90deg, #DC2626, #F97316, #FACC15);
}

/* Kontener Canvasu Gry */
.canvas-stage-wrap {
    position: relative;
    width: 100%;
    max-width: 780px;
    flex: 1;
    min-height: 0;
    background: radial-gradient(circle at 50% 60%, #102342 0%, #060D1A 85%);
    border: 2px solid rgba(212, 175, 55, 0.42);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

#arcade-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}

/* Okienko komunikatora kokpitu (Faza 2: Space Invaders) */
#comms-box {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 240px;
    background: rgba(0, 24, 54, 0.88);
    border: 1px solid var(--pumas-gold);
    border-radius: 14px;
    padding: 7px 11px 7px 7px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

#comms-box img {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    object-fit: cover;
    object-position: center top;
    border: 2px solid var(--pumas-gold-bright);
    flex-shrink: 0;
}

.comms-name {
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--pumas-gold-bright);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

#comms-text {
    font-size: 0.84rem;
    font-weight: 700;
    color: #FFFFFF;
    line-height: 1.2;
}

/* Nakładka zapowiadająca nowy etap */
#stage-banner {
    position: absolute;
    inset: 0;
    z-index: 40;
    background: rgba(6, 13, 26, 0.9);
    backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    animation: fadeIn 0.3s ease;
}

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

.banner-tag {
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: #071226;
    background: var(--pumas-gold-bright);
    padding: 5px 14px;
    border-radius: 999px;
    margin-bottom: 12px;
}

.banner-title {
    font-size: clamp(1.5rem, 5vw, 2.3rem);
    font-weight: 900;
    color: #FFFFFF;
    margin-bottom: 10px;
    text-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.banner-desc {
    font-size: 0.98rem;
    color: #CBD5E1;
    max-width: 440px;
    line-height: 1.5;
    margin-bottom: 20px;
}

.banner-btn {
    padding: 13px 28px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #006847, #10B981);
    color: #FFFFFF;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 104, 71, 0.4), 0 3px 0 #064E3B;
    transition: transform 0.14s ease;
}

.banner-btn:hover { transform: translateY(-2px); }
.banner-btn:active { transform: translateY(1px); }

/* Dolny pasek podpowiedzi sterowania */
.arcade-controls-hint {
    margin-top: 6px;
    font-size: 0.76rem;
    color: var(--text-muted);
    text-align: center;
    max-width: 780px;
}

/* =========================================================
   5. FAZA 4: WIELKI FINAŁ – URODZINOWA FIESTA!
   ========================================================= */
#stage-finale {
    min-height: 100dvh;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 16px 48px;
    position: relative;
    animation: fiestaPop 0.75s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes fiestaPop {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}

/* Animowana girlanda Papel Picado */
.papel-picado {
    width: 100%;
    max-width: 1200px;
    height: 74px;
    overflow: hidden;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.papel-picado svg {
    width: 100%;
    height: 100%;
    display: block;
    filter: drop-shadow(0 5px 7px rgba(0, 0, 0, 0.14));
    animation: bannerSway 3.6s ease-in-out infinite alternate;
    transform-origin: top center;
}

@keyframes bannerSway {
    0% { transform: rotate(-0.6deg) translateY(0px); }
    100% { transform: rotate(0.6deg) translateY(3px); }
}

.finale-wrap {
    width: 100%;
    max-width: 650px;
    text-align: center;
    z-index: 10;
    margin: auto 0;
}

.mex-flag-pill {
    display: inline-flex;
    width: 128px;
    height: 9px;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

.mex-flag-pill span:nth-child(1) { flex: 1; background: var(--mex-green); }
.mex-flag-pill span:nth-child(2) { flex: 1; background: var(--mex-white); }
.mex-flag-pill span:nth-child(3) { flex: 1; background: var(--mex-red); }

.finale-title {
    font-size: clamp(1.8rem, 6vw, 2.85rem);
    font-weight: 900;
    line-height: 1.12;
    color: var(--mex-red);
    text-shadow: 0 3px 0 rgba(255, 255, 255, 0.95), 0 8px 20px rgba(206, 17, 38, 0.22);
    margin-bottom: 6px;
}

.finale-subtitle {
    font-size: clamp(1.1rem, 3.8vw, 1.48rem);
    font-weight: 800;
    color: var(--mex-green);
    letter-spacing: 0.04em;
    margin-bottom: 24px;
}

/* Złoty Polaroid ze zdjęciem Dawida i pływającym Sombrero */
.polaroid-stage {
    position: relative;
    display: inline-block;
    margin: 14px auto 26px;
}

.floating-sombrero {
    position: absolute;
    top: -42px;
    left: -26px;
    width: 112px;
    height: 70px;
    z-index: 20;
    pointer-events: none;
    filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.25));
    animation: sombreroFloat 2.6s ease-in-out infinite;
}

@keyframes sombreroFloat {
    0%, 100% { transform: rotate(-16deg) translateY(0px); }
    50% { transform: rotate(-10deg) translateY(-8px); }
}

.polaroid-card {
    background: #FFFFFF;
    border: 4px solid var(--pumas-gold);
    border-radius: 16px;
    padding: 12px 12px 18px;
    width: min(290px, 82vw);
    box-shadow: 0 22px 45px rgba(0, 43, 92, 0.22), 0 0 0 6px rgba(212, 175, 55, 0.2);
    transform: rotate(-2.5deg);
    transition: transform 0.3s ease;
}

.polaroid-card:hover {
    transform: rotate(0deg) scale(1.03);
}

.polaroid-photo-frame {
    width: 100%;
    aspect-ratio: 4 / 5;
    border-radius: 10px;
    overflow: hidden;
    background: var(--pumas-navy-dark);
    border: 2px solid rgba(0, 43, 92, 0.15);
    margin-bottom: 12px;
}

#finale-photo.finale-photo-reveal {
    animation: finalePhotoIn 0.65s ease;
}

@keyframes finalePhotoIn {
    from {
        opacity: 0;
        transform: scale(0.92) rotate(-2deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

.polaroid-photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    display: block;
}

.polaroid-caption {
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--pumas-navy);
    letter-spacing: 0.01em;
}

/* Karta z życzeniami */
.wishes-card {
    background: rgba(255, 255, 255, 0.94);
    border: 3px solid var(--pumas-gold);
    border-radius: 22px;
    padding: 24px 20px;
    box-shadow: 0 16px 36px rgba(217, 119, 6, 0.16), 0 0 0 5px rgba(212, 175, 55, 0.12);
    text-align: left;
    margin-bottom: 20px;
}

.wishes-card p {
    font-size: 1.05rem;
    line-height: 1.65;
    color: #1E293B;
    margin-bottom: 12px;
}

.wishes-card p:last-child {
    margin-bottom: 0;
    font-weight: 800;
    color: var(--mex-green);
    text-align: center;
    font-size: 1.15rem;
}

/* Podsumowanie punktów z 3 etapów */
.score-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.score-box {
    background: rgba(255, 255, 255, 0.88);
    border: 2px solid rgba(0, 43, 92, 0.15);
    border-radius: 14px;
    padding: 10px 8px;
}

.score-box-lbl {
    font-size: 0.72rem;
    font-weight: 700;
    color: #64748B;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.score-box-val {
    font-size: 1.2rem;
    font-weight: 900;
    color: var(--pumas-navy);
}

.total-score-banner {
    background: linear-gradient(135deg, var(--pumas-navy), #004080);
    color: var(--pumas-gold-bright);
    border: 2px solid var(--pumas-gold);
    border-radius: 14px;
    padding: 12px 16px;
    font-size: 1.1rem;
    font-weight: 900;
    margin-bottom: 22px;
    box-shadow: 0 8px 20px rgba(0, 43, 92, 0.25);
}

.finale-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.btn-fiesta {
    padding: 13px 20px;
    border: none;
    border-radius: 14px;
    font-size: 0.98rem;
    font-weight: 800;
    cursor: pointer;
    flex: 1 1 180px;
    max-width: 240px;
    transition: transform 0.14s ease;
}

.btn-fiesta:hover { transform: translateY(-2px); }
.btn-fiesta:active { transform: translateY(2px); }

.btn-green {
    background: linear-gradient(135deg, #006847, #10B981);
    color: #FFFFFF;
    box-shadow: 0 6px 16px rgba(0, 104, 71, 0.3), 0 3px 0 #064E3B;
}

.btn-orange {
    background: linear-gradient(135deg, #F59E0B, #EA580C);
    color: #FFFFFF;
    box-shadow: 0 6px 16px rgba(234, 88, 12, 0.3), 0 3px 0 #9A3412;
}

.btn-navy {
    background: linear-gradient(135deg, #002B5C, #1D4ED8);
    color: #FFFFFF;
    box-shadow: 0 6px 16px rgba(0, 43, 92, 0.3), 0 3px 0 #001836;
}

@media (max-width: 520px) {
    .hud-stage-title { font-size: 0.8rem; }
    .hud-stats { font-size: 0.8rem; gap: 6px; }
    .score-summary { grid-template-columns: 1fr; }
    #comms-box { max-width: 195px; padding: 5px 8px 5px 5px; }
    #comms-box img { width: 34px; height: 34px; }
    #comms-text { font-size: 0.76rem; }
}
