:root {
    --bg-dark: #0a0a0c;
    --bg-card: rgba(20, 20, 25, 0.7);
    --primary: #f1c40f;
    --primary-glow: rgba(241, 196, 15, 0.4);
    --accent: #8e44ad;
    --text-main: #ffffff;
    --text-muted: #a0a0b0;
    --error: #e74c3c;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

/* Login Overlay Styles */
.login-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}
.login-box {
    text-align: center;
}
.user-info {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(0,0,0,0.7);
    padding: 10px 20px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.1);
    z-index: 1000;
    backdrop-filter: blur(10px);
    max-width: calc(100vw - 40px);
}
#user-welcome {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}
.small-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    margin: 0;
    white-space: nowrap;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background Animations */
.blob {
    position: absolute;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.5;
    animation: float 10s ease-in-out infinite;
}

.blob-1 {
    width: 300px;
    height: 300px;
    background: var(--primary);
    top: 10%;
    left: 10%;
    border-radius: 50%;
}

.blob-2 {
    width: 400px;
    height: 400px;
    background: var(--accent);
    bottom: -10%;
    right: 5%;
    border-radius: 50%;
    animation-delay: -5s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, -50px) scale(1.1); }
}

/* Landing Section */
.hero-section {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px;
}

.glass-container {
    background: rgba(25, 25, 27, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 3rem;
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    width: 100%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.glow-text {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    margin-bottom: 1rem;
    background: linear-gradient(to right, #fff, #ccc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    font-size: 1.1rem;
}

.search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 1rem;
}

input {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    color: white;
    font-size: 1.2rem;
    outline: none;
    transition: all 0.3s ease;
}

input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
}

button {
    background: var(--primary);
    color: black;
    border: none;
    border-radius: 12px;
    padding: 0 2rem;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px var(--primary-glow);
}

.bib-hint {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-top: 0.2rem;
    margin-bottom: 0.8rem;
    text-align: center;
    line-height: 1.45;
    opacity: 0.9;
}

.bib-zero-link {
    color: var(--primary, #f1c40f);
    font-weight: 700;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.2s, text-shadow 0.2s;
}

.bib-zero-link:hover {
    color: #fff;
    text-shadow: 0 0 8px var(--primary-glow);
}

.error {
    color: var(--error);
    margin-top: 1rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.hidden {
    display: none !important;
}

.primary-btn {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    background: #f1c40f;
    color: #000;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    margin-top: 15px;
}

.primary-btn:hover {
    background: #d4ac0d;
    transform: translateY(-2px);
}

.secondary-btn {
    padding: 0.8rem 1.5rem;
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: rgba(255,255,255,0.2);
}

.tertiary-btn {
    background: transparent;
    color: #a0a0b0;
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
    margin-bottom: 20px;
    transition: color 0.2s;
    align-self: flex-start;
}

.tertiary-btn:hover {
    color: white;
}

/* Layer 1: Races Grid */
.races-section {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    z-index: 10;
}

.races-glass {
    max-width: 1000px !important;
    width: 100%;
}

.races-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 30px;
    width: 100%;
}

.race-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.race-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-5px);
    border-color: rgba(241, 196, 15, 0.3);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.race-card h3 {
    margin: 0 0 10px 0;
    font-size: 1.4rem;
    color: white;
}

.race-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: #a0a0b0;
    font-size: 0.95rem;
}

.loading-text {
    text-align: center;
    color: #a0a0b0;
    grid-column: 1 / -1;
}

/* Layer 2: Gallery */
.gallery-section {
    padding: 2rem;
    min-height: 100vh;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.gallery-nav-group {
    display: flex;
    align-items: center;
    gap: 20px;
}

.highlight {
    color: var(--primary);
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

/* Masonry Grid */
.masonry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    grid-gap: 20px;
    grid-auto-rows: 20px; /* Helper for masonry layout if done via JS, otherwise pure CSS below */
}

/* Fallback for simple CSS grid */
@supports (grid-template-rows: masonry) {
    .masonry-grid {
        grid-template-rows: masonry;
    }
}

.photo-card {
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    background: var(--bg-card);
    transition: transform 0.3s ease;
    break-inside: avoid;
    margin-bottom: 20px; /* For column layout fallback */
}

/* Column layout fallback */
.masonry-grid {
    column-count: 3;
    column-gap: 20px;
    display: block;
}

@media (max-width: 900px) {
    .masonry-grid { column-count: 2; }
    .glass-container { padding: 2rem; }
    .search-box { flex-direction: column; }
    button { padding: 1rem; }
}

@media (max-width: 600px) {
    .masonry-grid { column-count: 1; }
    .gallery-header { flex-direction: column; gap: 1rem; text-align: center; }
}

.photo-card:hover {
    transform: scale(1.02);
    z-index: 2;
}

.photo-card img {
    width: 100%;
    display: block;
    border-radius: 16px;
}

.photo-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.photo-card:hover .photo-overlay {
    opacity: 1;
}

.download-btn {
    padding: 0.8rem 1.5rem;
    background: rgba(255,255,255,0.9);
    color: #000;
    text-decoration: none;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: transform 0.2s, background 0.2s;
}

.download-btn:hover {
    transform: scale(1.05);
    background: #fff;
}

/* HD Download Button */
.hd-download-btn {
    display: block;
    width: 100%;
    max-width: 500px;
    margin: 20px auto 0;
    padding: 18px 20px;
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    color: #000;
    text-align: center;
    border-radius: 12px;
    font-weight: 800;
    font-size: 1.1rem;
    text-decoration: none;
    box-shadow: 0 10px 20px rgba(241, 196, 15, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

.hd-download-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 25px rgba(241, 196, 15, 0.4);
}

/* Reproductor de Vídeo Recuerdo */
.runner-video-box {
    max-width: 760px;
    margin: 0 auto 35px auto;
    width: 100%;
}

.video-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(241, 196, 15, 0.3);
    border-radius: 16px;
    padding: 18px;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.video-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.video-tag {
    background: #f1c40f;
    color: #000;
    font-weight: 800;
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 6px;
    letter-spacing: 0.5px;
}

.download-vid-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 6px 14px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.2s;
}

.download-vid-btn:hover {
    background: #f1c40f;
    color: #000;
    border-color: #f1c40f;
}

.main-video-player {
    width: 100%;
    max-height: 480px;
    border-radius: 12px;
    background: #000;
    outline: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   Responsive Móvil (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
    /* Barra de usuario compacta en la esquina superior */
    .user-info {
        top: 10px;
        right: 10px;
        padding: 6px 12px;
        gap: 8px;
        border-radius: 14px;
        max-width: calc(100vw - 20px);
    }

    #user-welcome {
        max-width: 130px;
        font-size: 0.8rem;
    }

    .small-btn {
        padding: 0.35rem 0.65rem;
        font-size: 0.75rem;
    }

    /* Compensar altura superior para que ningún botón ni título quede tapado */
    .gallery-section {
        padding: 85px 1rem 2rem 1rem;
    }

    .gallery-header {
        margin-bottom: 1.5rem;
        padding-bottom: 0.8rem;
    }

    .gallery-nav-group {
        gap: 12px;
        flex-wrap: wrap;
        width: 100%;
    }

    .gallery-header h2 {
        font-size: 1.35rem;
        margin: 0;
    }

    #back-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    /* Secciones de carreras y hero */
    .races-section {
        padding: 75px 15px 30px 15px;
    }

    .hero-section {
        padding: 75px 15px 30px 15px;
    }

    .glass-container {
        padding: 2rem 1.2rem;
        border-radius: 18px;
    }

    .glow-text {
        font-size: 1.8rem;
        text-align: center;
    }

    .subtitle {
        font-size: 0.95rem;
        margin-bottom: 1.5rem;
        text-align: center;
    }

    .races-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        margin-top: 20px;
    }

    .masonry-grid {
        grid-template-columns: 1fr;
        grid-gap: 15px;
    }
}

