* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-image: url('stadium.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    /* Allow the main content (especially the map) to use more horizontal space */
    max-width: 1800px;
    width: 95%;
    margin: 0 auto;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
    padding: 20px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
}

.stats-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

/* Smaller stats when used in the sidebar on the right of the map */
.stats-sidebar {
    margin-bottom: 0;
    /* Stack team cards one above the other */
    grid-template-columns: 1fr;
}

.stats-sidebar .team-stats {
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    /* Arrange boxes side by side under the heading */
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: 8px;
    row-gap: 8px;
}

.stats-sidebar .team-stats h2 {
    grid-column: 1 / -1;
    margin-bottom: 4px;
    font-size: 1rem;
}

.stats-sidebar .stat-box {
    margin: 0;
    padding: 8px 10px;
    min-width: 0;
}

.stats-sidebar .stat-value {
    font-size: 1.4rem;
}

.stats-sidebar .stat-label {
    font-size: 0.75rem;
}

/* Team legend icons in headers */
.team-icon {
    width: 20px;
    height: 20px;
    margin-right: 6px;
    vertical-align: middle;
}

.team-stats {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: center;
}

.team-adults h2 {
    /* Gold to match adults bike icon and leg winner colour */
    color: #FFD700;
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.team-children h2 {
    /* Blue to match children bike icon and leg winner colour */
    color: #0066FF;
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.team-header {
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s ease;
}

.team-header:hover {
    opacity: 0.8;
}

.stat-box {
    display: inline-block;
    margin: 10px;
    padding: 15px 25px;
    background: #f8f9fa;
    border-radius: 10px;
    min-width: 120px;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 0.9rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Wrapper for map layout and progress bar */
.map-and-progress-wrapper {
    display: grid;
    /* Use the same grid structure as map-layout */
    grid-template-columns: minmax(0, 2.8fr) minmax(260px, 0.8fr);
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 30px;
}

/* Layout: map on the left, sidebar on the right */
.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 2.8fr) minmax(260px, 0.8fr);
    gap: 20px;
    align-items: flex-start;
    grid-column: 1 / -1;
}

.map-container {
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.sidebar-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Scoreboard styling - matches the image design */
.scoreboard-container {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
}

.scoreboard {
    display: flex;
    align-items: center;
    background: #1e3a8a; /* Dark blue background */
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.scoreboard-team {
    flex: 1;
    padding: 20px 15px;
    text-align: center;
    background: #1e3a8a; /* Dark blue */
}

.scoreboard-left {
    border-top-left-radius: 12px;
    border-bottom-left-radius: 12px;
}

.scoreboard-right {
    border-top-right-radius: 12px;
    border-bottom-right-radius: 12px;
}

.scoreboard-team-name {
    font-size: 0.85rem;
    font-weight: bold;
    color: white;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.scoreboard-score {
    font-size: 2.5rem;
    font-weight: bold;
    color: white;
    line-height: 1;
}

.scoreboard-vs {
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 12px;
    font-size: 0.9rem;
    font-weight: bold;
    color: #1e3a8a;
    text-transform: uppercase;
    letter-spacing: 2px;
    min-width: 50px;
    text-align: center;
}

/* Donation section: QR code + JustGiving in a card like the scoreboard */
.donation-container {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.donation-container .sidebar-qr {
    width: 200px;
    height: 200px;
    object-fit: contain;
    display: block;
}

.donation-container .sidebar-justgiving {
    height: 96px;
    width: auto;
    max-width: 440px;
    object-fit: contain;
    display: block;
}

/* Overall Progress Bar - positioned under the map */
.progress-bar-container {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    /* Align with the map container (first column) */
    grid-column: 1;
    width: 100%;
}

.progress-bar-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #333;
}

.progress-start {
    color: #666;
}

.progress-end {
    color: #666;
}

.progress-bar-track {
    position: relative;
    width: 100%;
    height: 30px;
    background: #e5e7eb;
    border-radius: 15px;
    overflow: visible;
}

.progress-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 15px;
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 5px;
}

#adults-progress-bar {
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.3), rgba(255, 215, 0, 0.6));
    z-index: 2;
}

#children-progress-bar {
    background: linear-gradient(90deg, rgba(0, 102, 255, 0.3), rgba(0, 102, 255, 0.6));
    z-index: 1;
}

.progress-bike-icon {
    width: 35px;
    height: 35px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
    transform: translateX(50%);
}

.map-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    background: #f0f0f0;
    border-radius: 10px;
    overflow: hidden;
}

.base-map {
    width: 100%;
    height: auto;
    display: block;
}

/* Overlay container - positioned absolutely over the map */
.overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* SVG for team paths */
.paths-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Keep paths behind markers and labels */
    z-index: 0;
}

/* Individual overlay elements */
.overlay {
    position: absolute;
    pointer-events: auto;
    transition: all 0.3s ease;
}

/* Team position markers */
.team-marker {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -50%);
    background: transparent;
    z-index: 10;
    position: relative;
}

.bike-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* Fine-tune children's bike visual alignment (image has different internal padding) */
.marker-children .bike-icon {
    /* Move the blue bike further up inside its marker to match the gold bike */
    transform: translateY(-40px);
}

/* Leg location markers */
.leg-marker {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    background: #28a745;
    transform: translate(-50%, -50%);
    /* Above path lines */
    z-index: 5;
}

.leg-marker.completed {
    background: #ffc107;
}

.leg-marker.current {
    background: #17a2b8;
    animation: pulse 2s infinite;
}

/* Leg winner colours */
.leg-marker.winner-adults {
    /* Gold for adults */
    background: #FFD700;
    border-color: #FFD700;
}

.leg-marker.winner-children {
    /* Blue for children */
    background: #0066FF;
    border-color: #0066FF;
}

/* Start marker - visually distinct */
.start-marker {
    background: #6c757d;
    width: 35px;
    height: 35px;
    border: 3px solid white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

.start-marker.current {
    background: #28a745;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 0.8;
    }
}

/* Location labels */
.location-label {
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    border: 1px solid rgba(0,0,0,0.1);
    pointer-events: none;
    transform: translate(-50%, -100%);
    margin-top: -8px;
    /* Above path lines */
    z-index: 6;
}

.location-label::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid rgba(255, 255, 255, 0.95);
}

.start-label {
    background: rgba(108, 117, 125, 0.95);
    color: white;
}

.start-label::after {
    border-top-color: rgba(108, 117, 125, 0.95);
}

/* Progress path/line */
.progress-path {
    position: absolute;
    height: 4px;
    background: linear-gradient(90deg, transparent, currentColor, transparent);
    transform-origin: left center;
    pointer-events: none;
    opacity: 0.6;
}

.path-adults {
    color: #667eea;
}

.path-children {
    color: #f093fb;
}

.legs-info {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    margin-bottom: 0;
    max-height: 420px;
    overflow-y: auto;
    /* Align with the map container (first column) */
    grid-column: 1;
    width: 100%;
}

.legs-info h3 {
    margin-bottom: 12px;
    color: #333;
    font-size: 1.2rem;
}

.legs-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

.leg-item {
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #ddd;
    transition: all 0.3s ease;
}

.leg-item.completed {
    border-left-color: #ffc107;
    background: #fff9e6;
}

.leg-item.current {
    border-left-color: #17a2b8;
    background: #e6f7ff;
    font-weight: bold;
}

/* Winner colouring for leg cards */
.leg-item.winner-adults {
    border-left-color: #FFD700;
    background: #fff9d1;
}

.leg-item.winner-children {
    border-left-color: #0066FF;
    background: #e3f0ff;
}

.btn-reset-leg {
    margin-top: 8px;
    padding: 6px 10px;
    font-size: 0.7rem;
    border-radius: 6px;
    border: 1px solid #ccc;
    background: #ffffff;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

.btn-reset-leg:hover {
    background: #f1f3f5;
    transform: translateY(-1px);
}

/* Start item styling */
.start-item {
    border-left-color: #6c757d;
    background: #f1f3f5;
}

.start-item.current {
    border-left-color: #28a745;
    background: #e8f5e9;
    font-weight: bold;
}

.leg-item h4 {
    margin-bottom: 5px;
    color: #333;
}

.leg-item p {
    font-size: 0.9rem;
    color: #666;
}

.admin-section {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.admin-section h3 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.5rem;
}

.update-form {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.form-group {
    flex: 1;
    min-width: 200px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: #666;
    font-weight: 500;
}

.form-group select,
.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.btn-primary {
    padding: 12px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Easter egg: video overlay inside map container */
.map-video-overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.map-video-overlay .map-video-player {
    flex: 1;
    width: 100%;
    min-height: 0;
    height: 100%;
    object-fit: cover;
}

.map-video-controls {
    flex-shrink: 0;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.8);
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.map-video-controls .btn-back-to-map {
    padding: 10px 24px;
    background: #1e3a8a;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.map-video-controls .btn-back-to-map:hover {
    background: #2d4a9e;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

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

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    position: relative;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    right: 20px;
    top: 20px;
    cursor: pointer;
    transition: color 0.2s ease;
}

.close-modal:hover,
.close-modal:focus {
    color: #000;
}

.modal-content h2 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.8rem;
}

.modal-form {
    margin-top: 20px;
}

.modal-form .form-group {
    margin-bottom: 20px;
}

.modal-form .btn-primary {
    width: 100%;
    margin-top: 10px;
}

/* Responsive design for mobile devices */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        width: 100%;
        max-width: 100%;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    /* Stack map and sidebar vertically on mobile */
    .map-and-progress-wrapper {
        grid-template-columns: 1fr;
        gap: 15px;
    }

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

    .progress-bar-container {
        grid-column: 1;
    }

    .map-container {
        padding: 10px;
    }

    /* Make sidebar full width on mobile */
    .sidebar-panel {
        width: 100%;
    }

    /* Stack team stats vertically on mobile */
    .stats-container {
        grid-template-columns: 1fr;
    }

    .stats-sidebar {
        grid-template-columns: 1fr;
    }

    .stats-sidebar .team-stats {
        padding: 12px;
    }

    .stats-sidebar .stat-box {
        margin: 4px;
        padding: 8px 10px;
    }

    .stats-sidebar .stat-value {
        font-size: 1.2rem;
    }

    .stats-sidebar .stat-label {
        font-size: 0.7rem;
    }

    /* Adjust scoreboard for mobile */
    .scoreboard {
        flex-direction: column;
    }

    .scoreboard-team {
        width: 100%;
        padding: 15px;
    }

    .scoreboard-left,
    .scoreboard-right {
        border-radius: 0;
    }

    .scoreboard-left {
        border-top-left-radius: 12px;
        border-top-right-radius: 12px;
    }

    .scoreboard-right {
        border-bottom-left-radius: 12px;
        border-bottom-right-radius: 12px;
    }

    .scoreboard-vs {
        padding: 10px;
        min-width: auto;
    }

    /* Adjust progress bar for mobile */
    .progress-bar-container {
        padding: 12px;
    }

    .progress-bar-track {
        height: 25px;
    }

    .progress-bike-icon {
        width: 28px;
        height: 28px;
    }

    /* Adjust legs list for mobile - single column */
    .legs-list {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .leg-item {
        padding: 12px;
    }

    /* Adjust legs info section */
    .legs-info {
        padding: 12px;
        max-height: none;
    }

    .legs-info h3 {
        font-size: 1rem;
    }

    .update-form {
        flex-direction: column;
    }

    .form-group {
        width: 100%;
    }

    .modal-content {
        margin: 10% auto;
        padding: 20px;
        width: 90%;
        max-width: 90%;
    }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .map-and-progress-wrapper {
        grid-template-columns: 1.5fr 1fr;
    }

    .map-layout {
        grid-template-columns: 1.5fr 1fr;
    }

    .legs-list {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

