:root {
    --primary: #25476D;
    --bg-color: #e1eefc;
    --panel-bg: #ffffffec;
    --text-main: #333333;
}

/**
 * Global Body Styling
 * Includes a repeating SVG wave pattern encoded directly into the CSS.
 * The background is fixed to the viewport, allowing JavaScript to control the horizontal drift.
 */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #0c2849;

    /* URL-encoded SVG wave pattern */
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='60' viewBox='0 0 120 60'%3E%3Cg fill='none' stroke='%23ffffff' stroke-width='4' stroke-linecap='round' opacity='0.15'%3E%3Cpath d='M0 25 C20 25, 25 5, 40 5 C35 15, 45 25, 60 25 C80 25, 85 5, 100 5 C95 15, 105 25, 120 25' /%3E%3Cpath d='M-30 55 C-10 55, -5 35, 10 35 C5 45, 15 55, 30 55 C50 55, 55 35, 70 35 C65 45, 75 55, 90 55 C110 55, 115 35, 130 35 C125 45, 135 55, 150 55' /%3E%3C/g%3E%3C/svg%3E");
    background-attachment: fixed; /* Locks the waves in place vertically */
    background-size: 120px 60px;

    color: var(--text-main);
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    text-align: center;
    padding: 2rem 1rem;
    background-color: #ffffff;
    border-bottom: 1px solid #ddd;
}

/* Styles the main banner logo to be responsive and centered */
.banner-logo {
    max-width: 100%;
    width: 800px;
    height: auto;
    display: block;
    margin: 0 auto 1rem auto; /* Centers the image and adds a little space below it */
}

/**
 * Layout: Navigation Menu
 * Structures fixed top-left positioning with a light glassmorphism effect.
 * Adjusts the palette to match Navy/Orange.
 */
.nav-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 2000;
}

.menu-toggle {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: inline-block;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.85);
    padding: 8px 8px 3px 8px; /* Expands the clickable hit-box around the SVG */
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border: 1px solid rgba(0,0,0,0.05);
}

.menu-toggle:hover {
    /* Simulats a physical lift toward the user */
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.nav-links {
    list-style: none;
    margin-top: 10px;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(37, 71, 109, 0.15); /* Subtle Navy border */
    border-radius: 8px;
    display: none; 
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.nav-links.active {
    display: flex;
}

.nav-links a {
    color: #25476D;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    display: block;
    padding: 8px 12px;
    border-radius: 4px;
    transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.nav-links a:hover {
    background: rgba(37, 71, 109, 0.08);
    color: #F08118;
    /* Nudges the text slightly to indicate selection */
    transform: translateX(5px);
}

main {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.panel {
    background-color: var(--panel-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
}

.hidden {
    display: none !important;
}

.upload-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

button {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

button:hover { background-color: #1C3754; }

/* Container to align the primary action buttons and the divider horizontally */
.action-buttons {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

/* Styling for the text divider between the action buttons */
.or-divider {
    color: #888888;
    font-size: 0.95rem;
}

/* Styles the demo button to match the primary button dimensions but in orange */
.demo-btn {
    background-color: #F08118; /* Vibrant orange */
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

/* Hover state for the demo button */
.demo-btn:hover {
    background-color: #D27014; /* Darker orange */
}

/* Container holding the map and enabling the bottom-right resize handle */
#map-container, #map-container-c {
    position: relative; /* anchors resize emblem.to the box */
    height: 40vh; /* Dynamically sizes to 40% of the active browser window height */
    min-height: 100px; /* Prevents the user from crushing the map out of existence */
    width: 100%;
    resize: both; /* Adds the drag handle to allow vertical and horizontal resizing */
    overflow: hidden; /* CSS requires overflow: hidden (or auto/scroll) for 'resize' to function */
    margin-bottom: -1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2); /* Subtle shadow to define the draggable edge */
}

/* * Customises the physical clickable resize box in WebKit browsers (Chrome, Edge, Safari).
 * Increases the hit target area and applies the SVG directly to the draggable space.
 */
#map-container::-webkit-resizer {
    background-color: transparent;
    width: 24px;  /* Expands the horizontal clickable area */
    height: 24px; /* Expands the vertical clickable area */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg' stroke='%23666666' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='2' y1='14' x2='14' y2='2' /%3E%3Cline x1='8' y1='14' x2='14' y2='8' /%3E%3Cline x1='14' y1='14' x2='14.01' y2='14' /%3E%3C/svg%3E"); 
    background-size: 16px 16px;
    background-repeat: no-repeat;
    background-position: bottom 2px right 2px; /* Snugs the icon right into the corner */
}

/**
 * Chart Master Wrapper Fullscreen Mode
 * Expands the wrapper to fill the screen. Flexbox ensures the canvas 
 * grows to take up the top portion, pinning the trim sliders to the bottom.
 */
#fullscreen-wrapper-a:fullscreen,
#compare-map-container:fullscreen,
#fullscreen-wrapper-c:fullscreen {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 20px; 
    border-radius: 0;
    background-color: white;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Adds a scrollbar just in case the monitor is extremely short */
}

/* * Fallback for Firefox. 
 * Firefox ignores WebKit resizer properties and uses a fixed hit target, 
 * so we just snap the visual icon flush into the corner.
 */
@supports not selector(::-webkit-resizer) {
    #map-container::after {
        content: '';
        position: absolute;
        bottom: 0; /* Snaps flush to the bottom */
        right: 0;  /* Snaps flush to the right */
        width: 16px; 
        height: 16px;
        background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg' stroke='%23666666' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='2' y1='14' x2='14' y2='2' /%3E%3Cline x1='8' y1='14' x2='14' y2='8' /%3E%3Cline x1='14' y1='14' x2='14.01' y2='14' /%3E%3C/svg%3E"); 
        background-size: contain;
        background-repeat: no-repeat;
        pointer-events: none; 
        z-index: 1000; 
        opacity: 0.6; 
    }
}

/* Forces the Leaflet map to stretch exactly to whatever size the user drags the container to */
#map {
    height: 100%;
    width: 100%;
    z-index: 1;
}

/**
 * Component: Boat Marker
 * Renders a red dot using standard DOM elements instead of SVG.
 * Enables strict z-index control to float above the trim markers.
 */
.boat-marker-icon {
    background-color: red;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

/* * Container for the playback and timeline controls. 
 */
.controls {
    margin: 1.3rem 0;
    display: flex;
    flex-direction: column;
    gap: 1.0rem;
}

#time-slider { width: 100%; }

/**
 * Metrics Dashboard Banner
 * Displays real-time rowing statistics.
 */
.dashboard {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap; 
    background-color: #f8f9fa; 
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 10px 10px; /* Tight padding to condense the layout */
    
    margin-top: -1.7rem; /* how close to the audio controls */
    margin-bottom: 1rem; 
    
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    position: relative;
    z-index: 10; 
    width: 100%;
    box-sizing: border-box; 
}

/*
 * Individual statistic containers within the dashboard.
 */
.stat-box { 
    font-weight: bold; 
    font-size: 1.1rem; 
    text-align: center;
    flex: 1;
    min-width: 100px;
}
.stat-box span { 
    color: var(--primary); 
    font-weight: normal; 
}

.chart-container {
    height: 30vh;  /* Dynamically sizes to 30% of the active browser window height */
    min-height: 220px;
    width: 100%;
    margin-top: -0.5rem;
}

/**
 * Chart Fullscreen Button Styling
 * Positions the control neatly in the top-left corner of the chart areas.
 */
.chart-fullscreen-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 10;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    
    /* Drops the button to 30% visibility */
    opacity: 0.3; 
    /* Ensures both the background colour and the fade effect animate smoothly */
    transition: background-color 0.2s, opacity 0.2s; 
}

.chart-fullscreen-btn:hover {
    background-color: #f4f4f4;
    /* Pops to full solid visibility when the mouse enters */
    opacity: 1; 
}

/**
 * Chart Fullscreen Mode
 * Ensures the chart fills the screen, maintains a solid background, 
 * and adds padding so the axes do not touch the monitor edges.
 */
.chart-container:fullscreen,
#chart-wrap-c:fullscreen {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 20px; 
    border-radius: 0;
    background-color: white;
    display: flex;
    flex-direction: column;
}

/**
 * Component: Dual Range Slider
 * Structured two native HTML range inputs absolutely positioned over each other.
 * Removes default styling and enabled pointer events only on the thumb handles 
 * to allow independent dragging.
 */
.dual-slider-wrapper {
    position: relative;
    width: 100%;
    height: 32px;
}

.dual-slider-track {
    position: absolute;
    width: 100%;
    height: 6px;
    top: 13px;
    background: #e0e0e0;
    border-radius: 3px;
    z-index: 1;
}

.dual-slider-wrapper input[type="range"] {
    position: absolute;
    width: 100%;
    height: 32px;
    top: 0;
    margin: 0;
    appearance: none;
    background: transparent;
    pointer-events: none;
    z-index: 2;
}

.dual-slider-wrapper input[type="range"]::-webkit-slider-thumb {
    pointer-events: all;
    width: 8px;
    height: 32px;
    appearance: none;
    background: #F08118; /* CoxOrb Orange */
    border: 2px solid #25476D; /* CoxOrb Navy */
    border-radius: 4px;
    cursor: ew-resize;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/**
 * Component: Map Boundary Markers
 * Renders vertical bars to clearly indicate the chopped start and end points.
 * Centering is handled natively by Leaflet's iconAnchor.
 */
.custom-trim-wrapper {
    background: transparent;
    border: none;
}

.trim-marker-bar {
    background-color: #F08118;
    border: 2px solid #25476D;
    width: 8px;
    height: 30px;
    border-radius: 4px;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    transform-origin: center center; /* Ensures the rotation pivots around the middle */
}


/* Container for the secondary comparison map, styled to match the primary map */
#compare-map-container {
    position: relative;
    height: 500px; 
    min-height: 100px; 
    width: 100%;
    resize: both; 
    overflow: hidden; 
    margin-top: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2); 
}

/* Duplicates the WebKit resize handle injection for the secondary map */
#compare-map-container::-webkit-resizer {
    background-color: transparent;
    width: 24px;  
    height: 24px; 
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg' stroke='%23666666' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='2' y1='14' x2='14' y2='2' /%3E%3Cline x1='8' y1='14' x2='14' y2='8' /%3E%3Cline x1='14' y1='14' x2='14.01' y2='14' /%3E%3C/svg%3E"); 
    background-size: 16px 16px;
    background-repeat: no-repeat;
    background-position: bottom 2px right 2px;
}

#compare-map {
    height: 100%;
    width: 100%;
    z-index: 1;
}

/* Styling for the comparison map legend */
.map-legend {
    background: white;
    padding: 10px 12px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    font-size: 0.9rem;
    color: var(--text-main);
}

/* Flexbox container to align the color swatches with the text */
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

/* Removes the bottom margin from the last item so the box padding stays even */
.legend-item:last-child {
    margin-bottom: 0;
}

/* The physical colored square drawn next to the text */
.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    display: inline-block;
}

/* Layout for each individual comparison route row */
.compare-row {
    display: flex;
    align-items: center;
    gap: 15px;
    background: #f8f9fa;
    padding: 10px 15px;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.route-label {
    font-weight: bold;
    width: 65px;
}

/* CSS implementation of an iOS-style toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    margin-left: auto; /* Pushes the toggle to the far right of the row */
}

/* Hides the default HTML checkbox */
.toggle-switch input { 
    opacity: 0; 
    width: 0; 
    height: 0; 
}

/* The visual track of the slider */
.slider {
    position: absolute; 
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; 
    transition: .4s; 
    border-radius: 24px;
}

/* The moving circular nub inside the slider */
.slider:before {
    position: absolute; 
    content: "";
    height: 16px; 
    width: 16px; 
    left: 4px; 
    bottom: 4px;
    background-color: white; 
    transition: .4s; 
    border-radius: 50%;
}

/* Changes track color and slides the nub when checked */
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

/* Styling for the clear/reset buttons */
.clear-btn {
    background-color: transparent;
    color: #C0392B; /* Red text */
    border: 1px solid #C0392B;
}

/* Hover state for the clear buttons */
.clear-btn:hover {
    background-color: #FADBD8; /* Soft red background */
    color: #A93226;
}


/* --- Audio Player & Timeline Theme --- */

/* Styling the container with the CoxOrb look */
#audio-container {
    background-color: var(--panel-bg);
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 8px 8px;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: row;
    flex-wrap: wrap; 
    align-items: center;
    justify-content: center;
    gap: 15px;
}

/* Styling the label with html h3 tag */
#audio-container h3 {
    margin-top: 0;
    margin-bottom: -30px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary); /* CoxOrb Navy */
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* label without h3 tag (fallback) */
#audio-container:not(:has(h3))::before {
    content: 'Coxswain Audio Recording';
    width: 100%;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: -30px;
    text-align: center;
}

/* Base styling for the native player element */
audio, #audio-player {
    width: 100%;
    height: 40px;
    outline: none;
}

/**
 * Custom Play/Pause Button
 * Circular, high-contrast button to control the hidden audio element.
 */
.play-btn {
    background-color: var(--primary); /* CoxOrb Navy */
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: background-color 0.2s;
}

.play-btn:hover {
    background-color: #1C3754;
}

/**
 * Skip Buttons
 * Compact buttons for skipping backward and forward through the timeline.
 */
.skip-btn {
    background-color: #F08118; /* CoxOrb Orange */
    color: white;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.skip-btn:hover {
    background-color: #D27014; /* Darker orange */
    color: white;
}

/* -------------------Audio Styling END -------------------*/

/**
 * Secondary Utility Button (speed-colouring reset)
 * A compact, less prominent button for resetting background variables 
 * without distracting from primary dashboard actions.
 */
.secondary-btn {
    background-color: #e9ecef; /* Neutral grey background */
    color: var(--primary); /* CoxOrb Navy text */
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    background-color: #dee2e6;
    color: #1C3754;
}

/**
 * GitHub Button
 * Styled button for linking to the GitHub repository.
 */
.GitHub-btn {
    background-color: var(--primary); /* CoxOrb blue */
    color: white;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.GitHub-btn:hover {
    background-color: #1C3754; /* Darker blue */
    color: white;
}

/**
 * Print Formatting Rules
 * Strips all interactive UI elements, margins, and flexible heights
 * to ensure the analytical report fits onto a single PDF page without blank overflows.
 * Enforced maximum widths to prevent the canvas and map from bleeding off the paper.
 */
@media print {
    /* Defines physical paper margins and resets page geometry */
    @page {
        size: landscape;
        margin: 1cm;
    }

    html, body {
        background-color: white !important;
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important; 
        overflow: visible !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Erases the interactive UI components */
    .upload-grid, 
    .action-buttons, 
    #compare-inputs,
    .controls, 
    #speed-toggle-container,
    #fairway-toggle-container,
    #buoys-toggle-container,
    #export-section,
    #support-section, 
    #feedback-section,
    hr {
        display: none !important;
    }

    .nav-container { 
        display: none !important; 
    }
    
    /* Strips structural padding and forces strict width containment */
    .panel {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Forces the remaining analytical elements to stay together and fit the page */
    #replay-section {
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
    }

    /* Tells the Comparison tool to always start on a new printed page */
    #compare-section {
        break-before: page !important;
        page-break-before: always !important; /* Fallback for older browser rendering engines */
    }

    .chart-container, 
    #map-container,
    .dashboard {
        page-break-inside: avoid !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Tells the canvas to shrink to the physical paper width */
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }

    /**
     * Renders the attribution text at the very bottom of the generated PDF.
     */
    .print-only {
        display: block !important;
        text-align: center;
        margin-top: 40px;
        padding-top: 15px;
        border-top: 1px solid #cccccc;
        font-size: 0.85rem;
        color: #666666;
        width: 100%;
    }
    
    .print-only a {
        color: #25476D; /* CoxOrb Navy */
        text-decoration: none;
    }
    
}

/**
 * Navigational Buoy Tooltip
 * Applies the CoxOrb colour palette (Navy  & Orange) to the Leaflet tooltip.
 * Stripps the default Leaflet formatting.
 */
.coxorb-tooltip {
    background-color: #25476D;
    color: #ffffff;
    border: 2px solid #F08118;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.8rem;
    padding: 5px 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Removed the default triangle pointer styling to maintain a clean rectangular badge */
.leaflet-tooltip.coxorb-tooltip::before {
    display: none;
}


/**
 * Layout: Print Footer
 * Hides the attribution text during standard interactive screen viewing.
 */
.print-only {
    display: none;
}

/* Section C: Comparison Boat Markers */
.boat-marker-orange {
    background-color: #F08118;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.boat-marker-blue {
    background-color: #25476D;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

/*
 * Section C Dashboard Spacing
 * Overrides the general tight dashboard margin to ensure it clears the comparison action buttons safely.
 */
#dashboard-c {
    margin-top: 1.0rem;
}