/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-align: center;
    padding: 2rem 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Main Content */
main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Races Container */
#races-container {
    display: grid;
    gap: 2rem;
}

.loading {
    text-align: center;
    padding: 3rem;
    color: #666;
    font-size: 1.1rem;
}

.no-races {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.no-races h2 {
    margin-bottom: 1rem;
    color: #999;
}

/* Race Card */
.race-card {
    display: block;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    text-decoration: none;
    color: inherit;
}

a.race-card {
    cursor: pointer;
}

.race-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.race-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
}

.race-header h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.race-info {
    font-size: 0.9rem;
    opacity: 0.9;
}

.strava-link {
    display: inline-block;
    margin-top: 0.5rem;
    margin-right: 0.5rem;
    color: #ffffff;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    background: #fc4c02;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
}

.strava-link:hover {
    background: #e04400;
}

/* Sources */
.sources-container {
    padding: 1.5rem;
}

.source-section {
    margin-bottom: 2rem;
}

.source-section:last-child {
    margin-bottom: 0;
}

.source-header {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #667eea;
}

.source-header h3 {
    color: #667eea;
    font-size: 1.3rem;
}

.photo-count {
    margin-left: auto;
    background: #667eea;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.9rem;
}

/* Photo Grid */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.photo-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 4px;
    background: #f0f0f0;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.photo-item:hover {
    transform: scale(1.05);
}

.photo-item img,
.photo-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.photo-item.video-item::after {
    content: '▶';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    transition: opacity 0.2s;
}

.photo-item.video-item:hover::after {
    opacity: 0;
}

.photo-item .photo-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #999;
    font-size: 3rem;
}

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    max-width: 90%;
    max-height: 90%;
    position: relative;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 90vh;
    display: block;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 40px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
}

.lightbox-close:hover {
    color: #ccc;
}

/* Back Link */
.back-link {
    display: inline-block;
    margin-bottom: 1rem;
    color: #667eea;
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 500;
}

.back-link:hover {
    text-decoration: underline;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 2rem;
    background: white;
    border-radius: 8px;
    padding: 1.5rem 2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 70px;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: #667eea;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.85rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.links-bar {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.links-bar a {
    color: #667eea;
    text-decoration: none;
    font-size: 0.95rem;
    padding: 0.4rem 1rem;
    border: 1px solid #667eea;
    border-radius: 20px;
    transition: background 0.2s, color 0.2s;
}

.links-bar a:hover {
    background: #667eea;
    color: white;
}

/* Map */
.race-map {
    width: 100%;
    height: 400px;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1;
}

.photo-cluster-icon {
    background: none;
    border: none;
}

.cluster-count {
    width: 36px;
    height: 36px;
    background: #667eea;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 2px solid white;
}
}

/* GPX Chart */
.gpx-chart-container {
    width: 100%;
    height: 250px;
    padding: 1rem 1.5rem;
}

/* Map legend */
.map-legend {
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    font-size: 12px;
    line-height: 1.6;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
}

.legend-icon.km-marker {
    background: #667eea;
    border: 1px solid white;
}

.legend-icon.photo-marker {
    background: #e74c3c;
    border: 2px solid white;
}

/* Km distance markers */
.km-marker-icon {
    background: none;
    border: none;
}

.km-marker {
    width: 20px;
    height: 20px;
    background: #667eea;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    opacity: 0.7;
    border: 1px solid white;
}

/* Map photo marker */
.photo-marker-icon {
    background: none;
    border: none;
}

.photo-marker {
    width: 28px;
    height: 28px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 2px solid white;
}

/* Map photo popup */
.map-photo-popup {
    max-width: 280px;
}

.map-photo-scroll {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    max-width: 280px;
    padding-bottom: 4px;
}

.map-photo-scroll img {
    width: 100px;
    height: 75px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.map-photo-time {
    font-size: 0.8rem;
    color: #666;
    margin-top: 4px;
    text-align: center;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 1rem;
    color: #666;
    margin-top: 3rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem;
    }

    .race-header h2 {
        font-size: 1.5rem;
    }

    .lightbox-close {
        top: 10px;
        right: 20px;
        font-size: 30px;
    }
}

@media (max-width: 480px) {
    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 0.5rem;
    }
}
