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

/* Defensive overrides to prevent flipped/mirrored POI markers in shared zoom modals */
.profile-modal .poi-marker {
    top: 18px !important;
    bottom: auto !important;
    transform: none !important;
}

.profile-modal-canvas {
    /* Allow POI markers to render fully even if early measurements are off */
    overflow: visible !important;
}

.profile-modal-canvas .stage-profile-container {
    position: relative !important;
    transform: none !important;
    overflow: visible !important;
}

.profile-modal-canvas .profile-wrapper {
    position: relative !important;
    transform: none !important;
}

/* Ensure only one profile container */
#profile-modal-profile {
    position: relative;
}

#profile-modal-profile > .stage-profile-container:not(:first-child) {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI', Roboto, sans-serif;
    background: #fef2f2;
    color: #0f172a;
    min-height: 100vh;
    font-feature-settings: 'cv11', 'ss01';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

.container {
    padding: 60px 24px;
    max-width: 1800px;
    margin: 0 auto;
    position: relative;
}

/* Home Icon */
.home-icon {
    position: absolute;
    top: 40px;
    left: 16px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    border: 1.5px solid rgba(220, 38, 38, 0.3);
    border-radius: 12px;
    color: #dc2626;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    z-index: 10003;
}

.home-icon:hover {
    background: rgba(220, 38, 38, 1);
    border-color: rgba(220, 38, 38, 1);
    color: #ffffff;
    transform: translateY(-2px) scale(1.05);
    box-shadow: 
        0 8px 25px rgba(220, 38, 38, 0.2),
        0 4px 10px rgba(0, 0, 0, 0.1);
}

.home-icon svg {
    width: 18px;
    height: 18px;
    transition: all 0.2s ease;
}

.home-icon:hover svg {
    transform: scale(1.1);
}

h1 {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
    font-size: 48px;
    font-weight: 700;
    margin-bottom: 40px;
    text-align: center;
    color: #0f172a;
    letter-spacing: -0.03em;
    line-height: 1.0;
    position: relative;
}

h1::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 4px;
    background: linear-gradient(90deg, #dc2626, #b91c1c);
    border-radius: 2px;
}

/* Sticky header (title + filters) */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 10002;
    background: #fef2f2;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    padding-bottom: 0;
    text-align: center;
}

/* Tighter spacing on desktop to pull toggle up slightly */
.sticky-header .stage-filters {
    margin: 12px auto 8px;
}

@media (max-width: 900px) {
    .sticky-header {
        box-shadow: 0 6px 12px rgba(220, 38, 38, 0.08);
        border-bottom: 1px solid #fecaca;
        padding-bottom: 6px; /* maintain comfortable spacing under title as it sticks */
    }
    .sticky-header h1 {
        margin-bottom: 12px;
    }
    .sticky-header .stage-filters {
        margin: 8px auto 8px;
    }
}

/* Stage Filters */
.stage-filters {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin: 32px auto 40px;
    flex-wrap: wrap;
    padding: 0 24px;
}

.filter-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #ffffff;
    border: 1.5px solid #fecaca;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    font-family: inherit;
}

.filter-btn:hover {
    background: #fef2f2;
    border-color: #f87171;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.15);
}

.filter-btn.active {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    border-color: #dc2626;
    color: #ffffff;
}

.filter-btn.active .filter-icon {
    transform: scale(1.1);
}

.filter-icon {
    font-size: 14px;
    display: inline-flex;
    transition: transform 0.2s;
}

.filter-label {
    font-size: 11px;
    letter-spacing: 0.01em;
}

@media (max-width: 768px) {
    .stage-filters {
        gap: 6px;
        margin: 20px auto 24px;
        padding: 0 16px;
    }
    
    .filter-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
    
    /* Slightly smaller preset buttons on mobile */
    .preset-btn {
        font-size: 12px;
    }
    
    .filter-icon {
        font-size: 14px;
    }
    
    .filter-label {
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .stage-filters {
        gap: 5px;
    }
    
    .filter-btn {
        padding: 5px 8px;
    }
    
    .filter-label {
        display: none;
    }
    
    .filter-icon {
        font-size: 16px;
    }
}

/* Timezone Selector */
.timezone-selector {
    position: relative;
    display: inline-block;
    margin-left: 8px;
    z-index: 1000;
}

.timezone-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
}

.timezone-toggle:hover {
    border-color: #dc2626;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.12);
}

.clock-icon {
    width: 12px;
    height: 12px;
    color: #6b7280;
}

.timezone-text {
    font-family: monospace;
    font-size: 11px;
}

.timezone-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #ffffff;
    border: 1px solid #fecaca;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(220, 38, 38, 0.12);
    min-width: 180px;
    overflow: hidden;
    z-index: 20005;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.timezone-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s;
    font-size: 14px;
}

.timezone-option:hover {
    background: #fef2f2;
}

.timezone-option.active {
    background: #fee2e2;
    color: #991b1b;
}

.tz-name {
    color: #374151;
    font-weight: 500;
}

.tz-code {
    color: #6b7280;
    font-family: monospace;
    font-size: 12px;
}

.timezone-option.active .tz-name {
    color: #991b1b;
}

.timezone-option.active .tz-code {
    color: #dc2626;
}

.timezone-indicator {
    font-size: inherit;
    color: inherit;
    font-weight: inherit;
}

/* Mobile responsive for timezone selector */
@media (max-width: 768px) {
    .timezone-selector {
        margin-left: 4px;
    }
    
    .timezone-toggle {
        padding: 3px 6px;
        font-size: 11px;
    }
    
    .clock-icon {
        width: 10px;
        height: 10px;
    }
    
    .timezone-text {
        font-size: 10px;
    }
    
    .timezone-dropdown {
        min-width: 160px;
        right: auto;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100vw - 32px);
        max-width: 420px;
        margin-top: 8px;
    }
}

/* Jersey Leaders */
.jersey-leaders {
    margin: 40px auto 40px;
    max-width: 800px;
}

.jersey-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.jersey-item {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid #fecaca;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.08);
}

.jersey-icon {
    font-size: 24px;
}

.jersey-icon.red { color: #dc2626; }
.jersey-icon.green { color: #059669; }
.jersey-icon.polka { color: #2563eb; }
.jersey-icon.white { color: #94a3b8; }

.leader-name {
    font-weight: 600;
    font-size: 14px;
    color: #1e293b;
}

/* Table Styles */
.stages-table {
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid #fecaca;
    box-shadow: 0 4px 24px -6px rgba(220, 38, 38, 0.08), 0 0 0 1px rgba(220, 38, 38, 0.02);
    overflow-x: visible;
    overflow-y: visible;
    width: 100%;
    margin: 8px auto 0;
    position: relative;
}

/* Dedicated horizontal scroller wrapping header + body */
.table-scroll {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    scrollbar-gutter: stable; /* reserve space for scrollbar so header and body align */
}

/* Desktop: pull table slightly closer to sticky header */
@media (min-width: 901px) {
    .stages-table {
        margin-top: -10px;
    }
}

.table-body {
    max-height: 80vh;
    overflow-y: auto;
    border-radius: 0 0 16px 16px;
    overflow-x: visible;
    width: max-content;
    display: inline-block;
}

#stages-container {
    position: relative;
}

.table-header {
    display: grid;
    grid-template-columns: 120px 100px 280px 300px 500px 120px 160px;
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    border-bottom: 1px solid #fecaca;
    color: #ffffff;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
    position: relative;
    z-index: 1;
    /* Ensure the gradient background spans full scrollable width */
    width: max-content;
    min-width: 100%;
    backface-visibility: hidden;
    transform: translateZ(0);
    padding-right: var(--body-scrollbar-width, 0px);
}

.table-header > div {
    padding: 12px 10px;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    line-height: 1.2;
}

.table-header > div:last-child {
    border-right: none;
}

/* Stage Rows */
.stage-row {
    display: grid;
    grid-template-columns: 120px 100px 280px 300px 500px 120px 160px;
    border-bottom: 1px solid #fee2e2;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    width: max-content;
}

.stage-row:hover {
    background: #fef2f2;
}

.stage-row.expanded {
    background: #fef2f2;
}

.stage-row.completed-stage {
    opacity: 0.6;
    background: #f9fafb;
}

.stage-row.next-stage {
    border: 2px solid #dc2626;
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.1);
    border-radius: 8px;
    margin: 4px 0;
}

/* Column specific styles */
.col-stage {
    padding: 30px 10px;
    border-right: 1px solid #fee2e2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
}

.stage-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.stage-winner {
    font-size: 11px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 4px;
    text-align: center;
    line-height: 1.2;
}

.desktop-only {
    display: block;
}

@media (max-width: 900px) {
    .desktop-only {
        display: none !important;
    }
}

.stage-number {
    font-size: 24px;
    font-weight: 700;
    color: #991b1b;
    line-height: 1;
}

.stage-date {
    font-size: 12px;
    color: #64748b;
    margin-top: 4px;
}

.col-winner {
    padding: 30px 10px;
    border-right: 1px solid #fee2e2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.winner-name {
    font-weight: 600;
    color: #991b1b;
    font-size: 14px;
}

.col-route {
    padding: 30px 10px;
    border-right: 1px solid #fee2e2;
}

.route-cities {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.arrow {
    color: #ef4444;
    font-size: 16px;
}

.route-features {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.route-feature-tag {
    font-size: 10px;
    background: #fee2e2;
    color: #991b1b;
    padding: 2px 6px;
    border-radius: 4px;
}

.col-type {
    padding: 30px 10px;
    border-right: 1px solid #fee2e2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.type-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.type-name {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}

.col-preview {
    padding: 30px 10px;
    border-right: 1px solid #fee2e2;
}

.col-stats {
    padding: 30px 8px;
    border-right: 1px solid #fee2e2;
    padding-bottom: 36px; /* extra breathing room beneath profile */
}

.quick-preview {
    font-size: 12px;
    line-height: 1.4;
    color: #475569;
}

.col-distance {
    padding: 30px 10px;
    border-right: 1px solid #fee2e2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.distance-km {
    font-weight: 600;
    font-size: 16px;
    color: #1e293b;
}

.elevation {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
}

.col-difficulty {
    padding: 30px 10px;
    border-right: 1px solid #fee2e2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.difficulty-score {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    padding: 8px 12px;
    border-radius: 8px;
    min-width: 48px;
    text-align: center;
}

.difficulty-score.easy {
    background: #dcfce7;
    color: #16a34a;
}

.difficulty-score.medium {
    background: #fef3c7;
    color: #d97706;
}

.difficulty-score.hard {
    background: #fee2e2;
    color: #dc2626;
}

.difficulty-rank {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
}

.col-timing {
    padding: 30px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.optimal-viewing {
    font-weight: 600;
    color: #991b1b;
    font-size: 13px;
    white-space: nowrap;
}

/* Special badges */
.special-badge {
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-top: 8px;
}

.special-badge.grand-depart {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
}

.special-badge.finale {
    background: linear-gradient(135deg, #991b1b, #7f1d1d);
    color: white;
}

.special-badge.hardest {
    background: #7f1d1d;
    color: white;
}

/* Rest day - match TdF styling */
.rest-day {
    background: #f8fafc;
    color: #64748b;
    text-align: center;
    padding: 12px;
    margin: 8px 0;
    border-top: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
}

.rest-content {
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.025em;
}

/* Completed stages toggle */
.completed-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #dc2626;
    color: #ffffff;
    border: none;
    width: 32px;
    height: 32px;
    padding: 0;
    margin: 6px auto 2px;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
    transition: all 0.2s;
    z-index: 10;
}

.completed-toggle:hover { background: #b91c1c; }

.completed-stages-wrapper {
    border-bottom: 2px solid #dc2626;
}

/* Credits */
.credits {
    margin-top: 24px;
    text-align: center;
    font-size: 14px;
    color: #64748b;
}

.credits a {
    color: #dc2626;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.credits a:hover {
    border-bottom-color: #dc2626;
}

/* Mobile Labels - Hidden on Desktop */
.mobile-label {
    display: none;
}

/* Mobile Center Wrapper - Show content on Desktop */
.mobile-center-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    text-align: center;
    height: auto;
}

.mobile-center-wrapper .mobile-label {
    display: none;
}

/* Hide mobile winner on desktop */
.mobile-winner {
    display: none;
}

/* Mobile styles */
@media (max-width: 900px) {
    .container {
        padding: 20px 16px;
    }
    
    .home-icon {
        top: 18px;
        left: 16px;
        width: 32px;
        height: 32px;
    }
    
    .home-icon svg {
        width: 15px;
        height: 15px;
    }
    
    h1 {
        font-size: 36px;
        margin-bottom: 24px;
    }
    
    .stages-table {
        border-radius: 12px;
        margin: 0;
    }
    
    .table-body {
        max-height: none;
        overflow-y: visible;
        width: 100% !important;
        display: block !important;
        overflow-x: hidden !important;
    }
    
    /* Position toggle button for mobile */
    .completed-toggle {
        width: 32px;
        height: 32px;
        margin: 6px auto 2px;
        border-radius: 50%;
    }
    
    /* Mobile Card Layout */
    .table-header {
        display: none;
    }
    
    .stage-row {
        display: block;
        background: #ffffff;
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 16px;
        box-shadow: 0 2px 8px rgba(220, 38, 38, 0.08);
        border: 1px solid #fecaca;
        width: 100% !important;
    }
    
    .stage-row:hover {
        transform: none;
        box-shadow: 0 2px 12px rgba(220, 38, 38, 0.12);
    }
    
    .stage-row > div {
        border-right: none;
        padding: 0;
        margin-bottom: 12px;
    }
    
    .stage-row > div:last-child {
        margin-bottom: 0;
    }
    
    /* Mobile checkbox */
    .col-checkbox {
        position: absolute;
        top: 16px;
        right: 16px;
        border: none;
        padding: 0;
        z-index: 10;
    }
    
    /* Mobile Stage Header */
    .col-stage {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
        padding: 12px 16px !important;
        margin: -16px -16px 16px -16px;
        border-radius: 12px 12px 0 0;
        border-bottom: 1px solid #fecaca;
        text-align: center;
        min-height: 50px;
    }
    
    .stage-number {
        font-size: 24px;
        font-weight: 800;
        color: #ffffff;
    }
    
    .stage-date {
        font-size: 12px;
        font-weight: 600;
        color: rgba(255, 255, 255, 0.8);
        margin: 0;
    }
    
    /* Hide desktop winner column on mobile */
    .col-winner {
        display: none !important;
    }
    
    /* Mobile winner in header */
    .mobile-winner {
        font-size: 13px;
        font-weight: 600;
        color: rgba(255, 255, 255, 0.9);
        margin-bottom: 4px;
        opacity: 0.9;
        display: block;
    }
    
    /* Mobile Route */
    .col-route {
        margin-bottom: 16px;
    }
    
    .route-cities {
        font-size: 16px;
        font-weight: 700;
        color: #1e293b;
        margin-bottom: 8px;
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
        display: block;
        text-align: center;
    }
    
    /* Mobile Route Features */
    .route-features {
        justify-content: center;
    }
    
    /* Mobile Stats Row */
    .mobile-stats {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #fef2f2;
        padding: 12px;
        border-radius: 8px;
        margin-bottom: 16px;
        gap: 12px;
    }
    
    .mobile-stat {
        text-align: center;
        flex: 1;
    }
    
    .mobile-stat-label {
        font-size: 10px;
        text-transform: uppercase;
        color: #64748b;
        font-weight: 600;
        margin-bottom: 4px;
    }
    
    .mobile-stat-value {
        font-size: 14px;
        font-weight: 700;
        color: #1e293b;
    }
    
    /* Hide desktop columns on mobile */
    .col-distance {
        display: none;
    }
    
    /* Mobile Difficulty and Timing */
    .col-difficulty, .col-timing {
        display: block !important;
        width: 100% !important;
        margin-bottom: 16px;
        text-align: center !important;
        justify-content: center !important;
        align-items: center !important;
        padding-top: 0 !important;
    }
    
    /* Mobile center wrapper - NUCLEAR OPTION */
    .mobile-center-wrapper {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        text-align: center !important;
    }
    
    .mobile-center-wrapper > * {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        width: auto !important;
        margin: 2px 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }
    
    /* Reset specific problematic elements */
    .mobile-center-wrapper .difficulty-score {
        padding: 6px 10px !important;
        margin: 2px auto !important;
    }
    
    .mobile-center-wrapper .optimal-viewing {
        padding: 0 !important;
        margin: 2px auto !important;
    }
    
    .mobile-label {
        display: block;
        font-size: 11px;
        text-transform: uppercase;
        color: #64748b;
        font-weight: 600;
        margin-bottom: 4px;
    }
    
    /* Center align all mobile content */
    .stage-row > div {
        text-align: center;
    }
    
    /* Specific mobile alignments */
    .difficulty-score {
        display: inline-block;
        text-align: center;
    }
    
    .difficulty-rank {
        display: block;
        text-align: center;
        margin-left: 0;
        margin-top: 4px;
    }
    
    .optimal-viewing {
        text-align: center;
    }
    
    /* Mobile Preview */
    .col-preview {
        margin: 0 auto 16px auto !important;
        padding: 0 !important;
        width: 85% !important;
        display: block !important;
    }
    
    .quick-preview {
        font-size: 14px;
        line-height: 1.5;
        color: #475569;
        text-align: left;
        width: 100%;
        display: block;
    }
    
    /* Mobile Stats/Profile */
    .col-stats {
        display: block !important;
        padding: 12px 0 !important;
        margin-bottom: 16px !important;
        position: relative !important;
        min-height: auto !important;
    }
    
    .stats-row {
        position: relative !important;
        top: auto !important; /* ensure desktop var/top doesn't affect mobile */
        bottom: auto !important;
        left: auto !important;
        transform: none !important;
        margin-top: 8px !important;
        justify-content: center !important;
    }
    
    .stage-profile-container {
        margin-bottom: 8px !important;
    }
    
    /* Rest Days Mobile */
    .rest-day {
        margin: 12px -8px;
        border-radius: 8px;
    }
    
    /* Credits Mobile */
    .credits {
        margin-top: 24px;
        padding: 16px 0;
    }
    
    .credits p {
        font-size: 11px;
        line-height: 1.4;
    }
    
    .jersey-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 12px 10px;
    }
    
    h1 {
        font-size: 28px;
    }
    
    /* Fit all filters on one line on small phones */
    .stage-filters {
        gap: 4px;
        flex-wrap: nowrap;
        padding: 0 8px;
    }
    .filter-btn {
        padding: 4px 7px;
        font-size: 10px;
    }
    .preset-btn {
        font-size: 10px;
        padding: 4px 8px;
        letter-spacing: -0.01em;
    }
    .filter-icon {
        font-size: 13px;
    }
    
    /* Slightly smaller again on small phones */
    .preset-btn {
        font-size: 11px;
    }
    
    .stage-row {
        padding: 12px;
        margin-bottom: 8px;
    }
    
    .col-stage {
        margin: -12px -12px 12px -12px;
        padding: 10px 12px;
    }
    
    .mobile-stats {
        padding: 10px;
        gap: 8px;
    }
    
    .quick-preview {
        font-size: 13px;
    }
}

@media (min-width: 901px) {
    .mobile-winner {
        display: none;
    }
    
    .mobile-label {
        display: none;
    }
}


.stage-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #dc2626;
}

/* Or divider */
.or-divider {
    text-align: center;
    margin: 16px auto 8px;
    font-size: 12px;
    color: #94a3b8;
    font-weight: 500;
    text-transform: lowercase;
}

/* Calendar controls */
.calendar-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin: 20px auto 32px;
    flex-wrap: wrap;
}

.calendar-controls.single-button {
    margin: 20px auto 16px;
}

.preset-btn, .calendar-btn {
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid;
    font-family: inherit;
}

.preset-btn {
    background: #ffffff;
    color: #dc2626;
    border: 1.5px solid #fecaca; /* match filter-btn border */
    border-radius: 16px; /* match filter-btn radius */
}

.preset-btn:hover {
    background: #fee2e2;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.15);
}

.preset-btn.active {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border-color: #dc2626;
}

/* Make preset buttons visually consistent with filter buttons */
.preset-btn,
.filter-btn {
    padding: 6px 10px;
}

.calendar-btn {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border-color: #dc2626;
}

.calendar-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(220, 38, 38, 0.3);
}

.calendar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Floating calendar button (mobile-first) */
.floating-calendar-btn {
    position: fixed;
    right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: #ffffff;
    /* icon handled via inline SVG */
    box-shadow: 0 10px 24px rgba(220, 38, 38, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.9);
}

/* SVG calendar icon inside FAB */
.floating-calendar-btn svg {
    width: 26px;
    height: 26px;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.floating-calendar-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
    filter: grayscale(0.3) brightness(0.95);
}

/* Attention pulse when there are selected stages */
.floating-calendar-btn.has-selected:not(:disabled) {
    animation: fabPulse 1.6s ease-in-out infinite;
}

@keyframes fabPulse {
    0% { box-shadow: 0 10px 24px rgba(220, 38, 38, 0.35); transform: translateZ(0) scale(1); }
    50% { box-shadow: 0 16px 36px rgba(220, 38, 38, 0.45); transform: translateZ(0) scale(1.04); }
    100% { box-shadow: 0 10px 24px rgba(220, 38, 38, 0.35); transform: translateZ(0) scale(1); }
}

/* Wiggle animation layered on top of pulse when filters change */
.floating-calendar-btn.wiggle:not(:disabled) {
    animation: fabWiggle 0.6s ease-in-out 1;
}

/* When also pulsing due to selected stages, run both animations */
.floating-calendar-btn.has-selected.wiggle:not(:disabled) {
    animation: fabPulse 1.6s ease-in-out infinite, fabWiggle 0.6s ease-in-out 1;
}

@keyframes fabWiggle {
    0% { rotate: 0deg; }
    15% { rotate: -12deg; }
    30% { rotate: 10deg; }
    45% { rotate: -8deg; }
    60% { rotate: 6deg; }
    75% { rotate: -4deg; }
    100% { rotate: 0deg; }
}

/* Show on desktop too per request */

/* Calendar Modal */
.calendar-modal {
    display: none;
    position: fixed;
    z-index: 20000; /* Above sticky header */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: white;
    margin: 12% auto 6%;
    padding: 32px;
    border-radius: 16px;
    max-width: 600px;
    width: 90%;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-height: 70vh;
    overflow-y: auto;
    padding-bottom: 24px;
}

.modal-close {
    color: #94a3b8;
    float: right;
    font-size: 32px;
    font-weight: 300;
    cursor: pointer;
    line-height: 20px;
    position: absolute;
    right: 24px;
    top: 24px;
}

.modal-close:hover {
    color: #dc2626;
}

.modal-content h3 {
    margin-bottom: 24px;
    font-size: 24px;
    color: #0f172a;
}

.modal-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 2px solid #fee2e2;
}

.tab-btn {
    padding: 12px 24px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #64748b;
    transition: all 0.2s;
    margin-bottom: -2px;
}

.tab-btn.active {
    color: #dc2626;
    border-bottom-color: #dc2626;
}

.tab-btn:hover:not(.active) {
    color: #0f172a;
}

.tab-content {
    padding: 16px 0;
}

.tab-content p {
    margin-bottom: 20px;
    color: #64748b;
}

/* Normalize list typography in modal content */
.tab-content ol {
    font-family: inherit;
    font-size: 14px;
    color: #64748b;
    line-height: 1.5;
    margin: 8px 0 12px 18px;
    padding-left: 0;
    list-style: decimal;
    list-style-position: outside;
}

.tab-content li {
    margin: 6px 0;
}

.tab-content ol a {
    color: #dc2626;
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.tab-content ol a:hover {
    border-bottom-color: #dc2626;
}

.download-ics-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.download-ics-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(220, 38, 38, 0.3);
}

.google-calendar-link {
    padding: 12px 0;
    border-bottom: 1px solid #fee2e2;
}

.google-calendar-link:last-child {
    border-bottom: none;
}

.gcal-link {
    color: #dc2626;
    text-decoration: none;
    font-weight: 500;
    display: block;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.gcal-link:hover {
    background: #fee2e2;
    padding-left: 20px;
}

/* Mobile responsiveness for calendar features */
@media (max-width: 768px) {
    .calendar-controls {
        padding: 0 16px;
    }
    
    .modal-content {
        margin: 24% auto 8%;
        padding: 24px;
        width: 95%;
        padding-bottom: 16px;
    }
    
    .col-checkbox {
        padding: 16px 4px;
    }
}

/* Stats Column */
.col-stats {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-width: 200px;
    padding: 12px;
    position: relative;
    padding-bottom: 42px; /* extra breathing room beneath profile */
}

.col-stats .stats-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0; /* Remove gap between distance and elevation */
}

.stats-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 11px;
    position: absolute;
    /* Use computed position from JS; fall back to aligning near bottom */
    top: var(--stats-top, calc(100% - 28px));
    left: 50%;
    transform: translateX(-50%);
}

.distance-km {
    font-weight: 500;
    color: #6b7280;
    font-size: 10px;
}

.elevation {
    color: #9ca3af;
    font-size: 10px;
}

.difficulty-score {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    min-width: 40px;
    text-align: center;
    display: inline-block;
}

.difficulty-score.easy {
    background: #dcfce7;
    color: #15803d;
}

.difficulty-score.medium {
    background: #fef3c7;
    color: #d97706;
}

.difficulty-score.hard {
    background: #fecaca;
    color: #dc2626;
}

.difficulty-rank {
    font-size: 11px;
    color: #6b7280;
    margin-top: 4px;
}

.stage-profile-container {
    width: 100%;
    height: 140px;
    position: relative;
    background: transparent;
    border-radius: 6px;
    padding: 0;
}

.stage-profile-container svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Zoom icon overlay for profile (desktop/tablet) */
.profile-zoom {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #dc2626; /* red */
    border: 1px solid #b91c1c;
    border-radius: 50%;
    text-decoration: none;
    line-height: 1;
    color: #ffffff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
    transform: translateX(-50%);
    z-index: 2;
}

.profile-zoom::before,
.profile-zoom::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
}

/* Horizontal bar */
.profile-zoom::before {
    /* Lens circle */
    width: 4px;
    height: 4px;
    border: 1px solid #ffffff;
    border-radius: 50%;
    background: transparent;
    transform: translate(-60%, -60%);
}

/* Vertical bar */
.profile-zoom::after {
    /* Handle */
    width: 3px;
    height: 1px;
    background: #ffffff;
    border-radius: 1px;
    transform: translate(1px, 1px) rotate(45deg);
}

.profile-zoom:hover {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    background: #b91c1c;
    border-color: #991b1b;
}

/* show on mobile too (override previous rule) */
@media (max-width: 900px) {
    .profile-zoom {
        width: 22.5px; /* 25% larger */
        height: 22.5px;
    }
}

/* Profile modal for zoomable profile */
.profile-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(2px);
    z-index: 20005;
    display: none;
}

.profile-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
    width: min(950px, 95vw);
    max-height: 80vh;
    display: none;
    z-index: 20006;
    overflow: hidden;
}

.profile-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 10px 14px;
    border-bottom: 1px solid #f1f5f9;
}

.profile-modal-title {
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
}

.profile-modal-close {
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 22px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
}

.profile-modal-close:hover {
    background: #f8fafc;
}

.profile-modal-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.profile-ctrl-btn {
    border: 1px solid #e5e7eb;
    background: #ffffff;
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
    color: #334155;
}

.profile-ctrl-btn:hover { background: #f8fafc; }

.profile-zoom-slider { accent-color: #dc2626; }

.profile-modal-body {
    padding: 14px 12px 6px;
}

/* Modal filter bar (top-right, under header) */
.profile-filter-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin: 0 4px 8px;
}

.profile-filter-pill {
    padding: 6px 10px;
    background: #ffffff;
    border: 1.5px solid #fecaca;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    transition: all 0.2s;
}
.profile-filter-pill:hover {
    background: #fef2f2;
    border-color: #f87171;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.15);
}
.profile-filter-pill.active {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    border-color: #dc2626;
    color: #ffffff;
}

@media (max-width: 900px) {
    .profile-filter-bar {
        margin: 0 2px 6px;
    }
    .profile-filter-pill {
        padding: 5px 9px;
        font-size: 11px;
    }
}

.profile-modal-canvas {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 420px;
    border-radius: 8px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    padding-top: 8px;
}

/* Hard bottom safe-area to ensure nothing renders below the logo zone */
.profile-modal-canvas::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 14px; /* Cut in half from 28px - minimal space for logo */
    background: #ffffff; /* match modal background */
    pointer-events: none;
    z-index: 19; /* just below the logo (which is 20) */
}

/* Stage Viewer logo inside modal */
.profile-modal-logo {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 21; /* above bottom safe-area mask and UI */
    font-family: 'Bungee', cursive;
    font-size: 18px;
    font-weight: 400;
    letter-spacing: -0.02em;
    color: #0f172a;
    text-shadow: none;
    pointer-events: none;
    user-select: none;
}

.profile-modal-logo .logo-vuelta-e {
    color: #dc2626;
}

.profile-modal-canvas .stage-profile-container {
    height: 340px;
    width: 100%;
    overflow: visible;
    position: relative;
    flex: 0 0 auto;
}

/* Share button in modal header */
.profile-share-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
    margin-right: 4px;
}

.profile-share-btn svg { width: 20px; height: 20px; }

.profile-share-btn:hover {
    background: #f8fafc;
    color: #1e293b;
}

.profile-share-btn:active {
    background: #f1f5f9;
}

/* Calendar button in modal header */
.profile-calendar-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.profile-calendar-btn:hover { background: #f8fafc; color: #1e293b; }
.profile-calendar-btn:active { background: #f1f5f9; }
.profile-calendar-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

@media (max-width: 900px) {
    .profile-share-btn {
        width: 36px;
        height: 36px;
    }
    .profile-share-btn svg { width: 22px; height: 22px; }
    .profile-calendar-btn { width: 36px; height: 36px; }
    .profile-calendar-btn svg { width: 22px; height: 22px; }

    /* Avoid overlap between logo and left-side gray time box on mobile */
    .profile-modal-logo {
        left: auto;
        right: 10px;
        bottom: 2px; /* Minimal gap from bottom */
        font-size: 13.5px; /* 75% of 18px */
    }
}

.profile-share-toast {
    position: absolute;
    right: 12px;
    top: 52px; /* Position below header instead of above button */
    background: rgba(255,255,255,0.98);
    border: 1px solid #e5e7eb;
    color: #0f172a;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    z-index: 23;
    transition: opacity 0.25s ease;
}

/* Share options popover */
.profile-share-menu {
    position: absolute;
    right: 52px; /* Position to left of share button */
    top: 48px; /* Align below header */
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(0,0,0,0.18);
    overflow: hidden;
    z-index: 24;
    min-width: 180px;
}

.share-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    font-size: 13px;
    color: #0f172a;
    background: #ffffff;
    border: none;
    cursor: pointer;
}

.share-menu-item:hover {
    background: #fef2f2;
    color: #b91c1c;
}

/* POI markers (KOM/Sprint/Climb categories) */
.poi-marker {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    pointer-events: auto;
    user-select: none;
    z-index: 20012; /* above modal overlays within canvas */
    cursor: pointer;
}

.poi-marker.kom { background: #2563eb; }
.poi-marker.sprint { background: #16a34a; }
.poi-marker.climb { background: #dc2626; }

.profile-modal-canvas .poi-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 20010;
}

/* Clip any bleed from SVG fill or markers at the bottom in the modal */
.profile-modal-canvas .stage-profile-container {
    overflow: hidden;
}
.profile-modal-canvas .stage-profile-container svg {
    overflow: hidden;
    display: block;
}

.poi-marker-label {
    position: absolute;
    top: -18px;
    transform: translateX(-50%);
    left: 50%;
    background: rgba(255,255,255,0.95);
    color: #0f172a;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    display: none;
    z-index: 12;
}

/* POI popover */
.poi-popover {
    position: absolute;
    min-width: 160px;
    max-width: 240px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.14);
    padding: 8px 10px;
    color: #0f172a;
    font-size: 12px;
    line-height: 1.4;
    z-index: 20;
}

.profile-modal-canvas .profile-wrapper {
    transform-origin: left center;
}

/* Profile interaction controls */
.profile-controls {
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: #f8fafc;
    flex: 0 0 auto;
    margin-top: auto;
}

.profile-time-display {
    position: absolute;
    left: 0;
    /* top will be set dynamically by JavaScript */
    display: flex;
    flex-direction: column;
    gap: 3px; /* 25% larger than 2px */
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700; /* Bold for better readability */
    color: #ffffff;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
    pointer-events: none;
    user-select: none;
    line-height: 1.2;
    z-index: 10;
    /* Modern lighter gray background */
    background: rgba(71, 85, 105, 0.92); /* slate-600 - lighter and more sophisticated */
    border-radius: 8px;
    padding: 6px 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); /* Subtle shadow */
    backdrop-filter: blur(8px); /* Glass effect */
    border: 1px solid rgba(255, 255, 255, 0.15); /* Subtle light border */
    /* Smooth transition for position changes */
    transition: top 0.2s ease-out;
}

.time-value, .distance-value {
    color: #ffffff; /* White text for contrast on gray bubble */
    font-variant-numeric: tabular-nums;
}

/* Make the kms-left line smaller than the time line inside the gray box */
.profile-time-display .distance-value {
    font-size: 80%;
}

/* Window time display (shown in center of window band) */
.window-time-display {
    display: flex;
    flex-direction: column;
    gap: 3px; /* 25% larger than 2px */
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700; /* Bold for better readability */
    color: #ffffff;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
    pointer-events: none;
    user-select: none;
    line-height: 1.2;
    /* Modern lighter gray background */
    background: rgba(71, 85, 105, 0.92); /* slate-600 - lighter and more sophisticated */
    border-radius: 8px;
    padding: 6px 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); /* Subtle shadow */
    backdrop-filter: blur(8px); /* Glass effect */
    border: 1px solid rgba(255, 255, 255, 0.15); /* Subtle light border */
}

.window-time-range, .window-km-range {
    color: #ffffff;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Reduce km range size inside the window band gray box */
.window-km-range {
    font-size: 80%;
}

.profile-vertical-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1.5px;
    background: #ef4444; /* lighter red */
    opacity: 0.5;
    display: none;
    z-index: 9;
    pointer-events: none;
    box-shadow: 0 0 4px rgba(220, 38, 38, 0.4);
}

.profile-window-band {
    position: absolute;
    top: 0;
    left: 0;
    height: 40px;
    width: 100px;
    background: rgba(220, 38, 38, 0.12);
    border: 1px dashed rgba(220, 38, 38, 0.35);
    border-radius: 3px;
    z-index: 8;
    pointer-events: none;
}

.window-time-start,
.window-time-end {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
}

.window-time-end {
    align-items: flex-end;
}

.window-km {
    font-size: 9px;
    color: #7f1d1d;
    font-weight: 500;
    display: block;
}

.profile-mode-toggle {
    display: flex;
    gap: 0;
    border-radius: 6px;
    background: #e2e8f0;
    padding: 2px;
    margin-right: 8px;
}

.mode-toggle-btn {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.mode-toggle-btn:hover {
    color: #475569;
}

.mode-toggle-btn.active {
    background: white;
    color: #dc2626;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.profile-window-handle {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #dc2626;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
    z-index: 11;
    cursor: ew-resize;
}

/* Increase touch target without changing visual size */
.profile-window-handle::after {
    content: '';
    position: absolute;
    left: -7px; right: -7px; top: -7px; bottom: -7px; /* expand hit area to ~32px */
}



/* Band info pill */
.profile-window-pill {
    position: absolute;
    top: -22px;
    left: 0;
    background: rgba(255,255,255,0.95);
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    padding: 2px 8px;
    font-size: 11px;
    color: #0f172a;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    pointer-events: none;
}





/* Draggable handle at the top of the vertical line */
.profile-drag-handle {
    position: absolute;
    top: 0;
    width: 20px;
    height: 20px;
    border-radius: 9999px;
    background: #dc2626;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    display: none;
    z-index: 10;
    cursor: grab;
}

.profile-drag-handle.dragging {
    cursor: grabbing;
}


/* Points of Interest Table */
.profile-poi-table {
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    max-height: 200px;
    overflow-y: auto;
}

.poi-header {
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    font-size: 14px;
    color: #374151;
}

.poi-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.poi-table th {
    background: #f8fafc;
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.poi-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
}

.poi-table tr:hover {
    background: #f8fafc;
}

.poi-table .location {
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.poi-table .distance {
    color: #6b7280;
    font-variant-numeric: tabular-nums;
}

.poi-table .time {
    font-weight: 500;
    color: #dc2626;
    font-variant-numeric: tabular-nums;
}

.no-poi {
    padding: 20px;
    text-align: center;
    color: #6b7280;
    font-style: italic;
}

@media (max-width: 900px) {
    .profile-controls {
        padding: 16px;
    }
    
    .profile-time-display {
        gap: 5px; /* 25% larger than 4px */
        /* Ensure gray box stays within modal bounds on mobile */
        max-width: calc(100% - 16px);
        /* Add bottom margin to prevent cutoff */
        margin-bottom: 8px;
    }
    
    .profile-modal {
        width: 94vw;
        max-height: 86vh;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        border-radius: 12px;
        /* Ensure modal stays within viewport bounds on mobile */
        max-width: calc(100vw - 12px);
        max-height: calc(100vh - 12px);
        /* Allow scrolling if content overflows */
        overflow-y: auto;
    }
    .profile-modal-body { 
        height: auto; 
        /* Further reduced padding to minimize white space */
        padding-bottom: 15px;
    }
    .profile-modal-canvas { 
        height: 320px; /* Reduced height for more compact layout in portrait */
        padding-top: 8px; /* Reduced padding */
        /* Ensure canvas content can be scrolled */
        position: relative;
        overflow: visible;
    }
    .profile-modal-canvas .stage-profile-container { 
        height: 260px;
        margin-bottom: 0; /* Remove any bottom margin */
    }
    .profile-drag-handle { width: 25px; height: 25px; }
}

/* Portrait orientation specific - make even more compact */
@media (max-width: 900px) and (orientation: portrait) {
    .profile-modal-canvas {
        height: 290px; /* Much more compact for portrait - just enough for profile + gray box */
        padding-top: 4px; /* Minimal padding */
    }
    
    .profile-modal-body {
        padding-bottom: 10px; /* Minimal bottom padding */
    }
    
    /* Reduce the white mask area even more in portrait */
    .profile-modal-canvas::after {
        height: 10px; /* Minimal space for logo in portrait */
    }
}

/* Prevent background scroll and jitter while modal is open */
body.modal-open {
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
}

.profile-modal,
.profile-modal-canvas {
    overscroll-behavior: contain;
}

/* Improve touch drag behavior */
.profile-modal-canvas,
.profile-drag-handle,
.profile-vertical-line {
    touch-action: none;
}

.profile-distance {
    font-size: 10px;
    color: #9ca3af;
    margin-top: 2px;
    text-align: right;
}

.profile-error {
    font-size: 11px;
    color: #9ca3af;
    text-align: center;
    padding: 8px;
    background: #f9fafb;
    border-radius: 4px;
}

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

/* Landscape orientation specific styles */
@media (max-width: 900px) and (orientation: landscape) {
    .profile-modal {
        max-height: 95vh; /* Use more vertical space in landscape */
        max-width: 90vw; /* Slightly narrower to give more breathing room */
        /* Ensure scrolling is available in landscape too */
        overflow-y: auto;
    }
    
    .profile-modal-header {
        padding: 6px 10px; /* Reduce header padding */
    }
    
    .profile-modal-body {
        padding: 8px 10px 4px; /* Reduce body padding */
        /* Further reduced padding in landscape too */
        padding-bottom: 12px;
    }
    
    .profile-modal-canvas {
        height: calc(100vh - 120px); /* Dynamic height based on viewport */
        max-height: 240px; /* Cap the height to prevent too tall profiles */
        padding-top: 8px;
        /* Allow content to extend beyond canvas bounds in landscape */
        overflow: visible;
    }
    
    .profile-modal-canvas .stage-profile-container {
        height: calc(100% - 40px); /* Adjust container to fit, leaving room for gray box */
        max-height: 180px;
    }
    
    /* Ensure controls don't take too much space */
    .profile-controls {
        padding: 10px;
    }

    /* Place logo bottom-left on mobile landscape as well */
    .profile-modal-logo {
        left: 10px;
        right: auto;
        bottom: 2px; /* Minimal gap consistent with portrait mode */
        font-size: 13.5px; /* 75% of 18px */
    }
    
    /* Additional constraints for gray box in landscape */
    .profile-time-display {
        /* Ensure it doesn't get too close to bottom edge in landscape */
        margin-bottom: 12px;
        /* Smaller font size in landscape to save space */
        font-size: 14px;
    }
}
