body { 
    margin: 0; 
    padding: 0; 
    display: flex; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    height: 100vh;
    overflow: hidden;
}

/* Left Sidebar Control Pane */
/* Left Sidebar Control Pane */
#control-pane {
    width: 320px;
    min-width: 320px; /* Prevents it from squishing */
    height: 100vh;
    background-color: #f8fafc;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 2001;
    padding: 24px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
    
    /* NEW: Desktop sliding animation */
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 0;
}

/* Slides it off-screen, causing the map to flex-grow instantly */
#control-pane.collapsed {
    margin-left: -320px; 
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 12px;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.4rem;
    color: #0f172a;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

label {
    font-weight: 600;
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Connected Button Group UI */
.button-group {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #cbd5e0;
    background-color: #ffffff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.button-group button {
    flex: 1;
    padding: 10px 8px;
    border: none;
    border-right: 1px solid #cbd5e0;
    background: transparent;
    color: #475569;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.button-group button:last-child {
    border-right: none;
}

.button-group button:hover {
    background-color: #f1f5f9;
}

/* Active State */
.button-group button.active {
    background-color: #2563eb;
    color: #ffffff;
    font-weight: 600;
}

/* Horizontally Scrollable Group for Times */
.scrollable-group {
    overflow-x: auto;
    /* Hide scrollbar for a cleaner look but keep functionality */
    scrollbar-width: none; 
    -ms-overflow-style: none;
}
.scrollable-group::-webkit-scrollbar {
    display: none;
}

.scrollable-group button {
    flex: 0 0 auto; /* Prevent shrinking */
    min-width: 90px; /* Ensure time buttons are readable */
}

.time-date {
    display: block;
    font-size: 0.65rem;
    opacity: 0.8;
    margin-bottom: 2px;
}

.time-hour {
    display: block;
    font-size: 0.85rem;
}

/* Map Container */
/* Map area — transparent wrapper so the timer card can float over the map */
#map-area {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
}

/* ==========================================
   Race Timer — floating card
   ========================================== */
#race-timer-bar {
    position: fixed;
    top: 62px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.93);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(51, 65, 85, 0.9);
    border-radius: 14px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    z-index: 1200;
    max-width: calc(100vw - 32px);
}
#race-timer-bar::-webkit-scrollbar { display: none; }
#race-timer-bar.rtb-hidden { display: none; }

#rtb-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    min-width: max-content;
}

/* Mode toggle */
#rtb-mode {
    display: flex;
    border: 1px solid #334155;
    border-radius: 5px;
    overflow: hidden;
    flex-shrink: 0;
}
.rtb-mode-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 4px 9px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1;
}
.rtb-mode-btn.active {
    background: #1e40af;
    color: #fff;
}

/* Countdown / pursuit entry rows */
#rtb-countdown-entry,
#rtb-pursuit-entry {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.rtb-entry-label {
    font-size: 0.65rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
#rtb-countdown-time,
#rtb-pursuit-time {
    background: #1e293b;
    border: 1px solid #334155;
    color: #e2e8f0;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    border-radius: 4px;
    padding: 3px 5px;
    outline: none;
    width: 96px;
}
#rtb-countdown-time:focus,
#rtb-pursuit-time:focus { border-color: #3b82f6; }
#rtb-countdown-time:disabled { opacity: 0.4; cursor: default; }

/* Timer display */
#rtb-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 74px;
    flex-shrink: 0;
}
#rtb-timer-digits {
    font-size: 1.65rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    color: #f1f5f9;
    letter-spacing: 0.02em;
    line-height: 1;
}
#rtb-timer-digits.rtb-warning { color: #fbbf24; }
#rtb-timer-digits.rtb-elapsed { color: #4ade80; }
#rtb-timer-label {
    font-size: 0.55rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-top: 2px;
}

/* Control buttons */
#rtb-controls {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.rtb-btn {
    background: #1e293b;
    border: 1px solid #334155;
    color: #cbd5e1;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 5px 9px;
    border-radius: 4px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.rtb-btn:hover:not(:disabled) {
    background: #334155;
    color: #f1f5f9;
}
.rtb-btn:disabled { opacity: 0.35; cursor: default; }
#rtb-start:not(:disabled) { border-color: #2563eb; color: #93c5fd; }
#rtb-reset { border-color: #475569; }

/* Burn readout in bar */
#rtb-ttl {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 8px;
    border-left: 1px solid #1e293b;
    flex-shrink: 0;
}
.rtb-ttl-label {
    font-size: 0.55rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
#rtb-ttl-value {
    font-size: 1.05rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    line-height: 1;
}
#rtb-ttl.burn-ahead  #rtb-ttl-value { color: #4ade80; }
#rtb-ttl.burn-behind #rtb-ttl-value { color: #f87171; }
#rtb-ttl-word {
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    line-height: 1;
    margin-top: 2px;
}
#rtb-ttl.burn-ahead  #rtb-ttl-word { color: #4ade80; }
#rtb-ttl.burn-behind #rtb-ttl-word { color: #f87171; }

/* Burn map pin label */
.rtb-ttl-pin {
    display: inline-block;
    background: rgba(15, 23, 42, 0.92);
    font-family: 'Courier New', monospace;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid;
    white-space: nowrap;
    pointer-events: none;
    transform: translate(-50%, -50%);
    line-height: 1.4;
}
.rtb-ttl-pin.burn-ahead  { color: #4ade80; border-color: #4ade80; }
.rtb-ttl-pin.burn-behind { color: #f87171; border-color: #f87171; }
.rtb-ttl-pin .pin-time {
    font-size: 0.82rem;
    font-weight: 700;
}
.rtb-ttl-pin .pin-word {
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.08em;
}

/* ==========================================
   Race Marker Styles
   ========================================== */
.custom-race-mark {
    background: none !important;
    border: none !important;
}

.mark-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
    color: #ffffff;
    font-weight: 700;
    font-size: 11px;
    /* Dimensions are controlled via inline styles in JS to allow dynamic sizing if needed later */
}

.mark-label {
    position: absolute;
    left: 28px; /* Pushes the label slightly to the right of the circle */
    top: 2px;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    color: #0f172a;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    white-space: nowrap; /* Prevents text wrapping on long names */
    border: 1px solid #cbd5e0;
}

/* ==========================================
   Inline Leg Pill Styles
   ========================================== */
.custom-course-label {
    background: none !important;
    border: none !important;
}

.leg-pill-wrap {
    position: absolute;
    width: max-content;
    white-space: nowrap;
    pointer-events: none;
    transform-origin: center center;
}

.leg-course-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(91, 104, 124, 0.94);
    border: 1px solid rgba(203, 213, 225, 0.48);
    color: #f8fafc;
    box-shadow: 0 2px 5px rgba(0,0,0,0.35);
    font-size: 0.68rem;
    font-weight: 750;
    line-height: 1;
    text-shadow: 0 1px 1px rgba(0,0,0,0.35);
    box-sizing: border-box;
    overflow: hidden;
    white-space: nowrap;
}

.leg-course-pill span {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
}

.leg-pill-course {
    flex-shrink: 0 !important;
    color: #ffffff;
    font-size: 0.78rem;
    font-weight: 900;
}

.leg-pill-plan {
    color: #f8fafc;
    font-weight: 850;
}

.leg-pill-distance {
    flex-shrink: 0 !important;
    color: #e2e8f0;
    font-weight: 850;
}

.leg-pill-muted {
    color: #dbe4ef;
    font-weight: 700;
}

.leg-course-pill.compact {
    gap: 5px;
    padding: 3px 7px;
    font-size: 0.62rem;
}

.leg-course-pill.compact .leg-pill-course {
    font-size: 0.72rem;
}

.leg-course-pill.mini {
    gap: 4px;
    padding: 3px 6px;
    font-size: 0.58rem;
}

.leg-course-pill.mini .leg-pill-course {
    font-size: 0.68rem;
}

.waypoint-action-popup {
    min-width: 190px;
}

.waypoint-action-title {
    margin-bottom: 8px;
    color: #0f172a;
    font-size: 0.82rem;
    font-weight: 800;
}

.waypoint-action-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
    color: #475569;
    font-size: 0.68rem;
    letter-spacing: 0;
    text-transform: none;
}

.waypoint-action-row select {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    padding: 6px;
    background: #ffffff;
    color: #0f172a;
    font-size: 0.78rem;
}

.waypoint-menu-btn,
.waypoint-delete-btn {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    padding: 7px 8px;
    background: #ffffff;
    color: #1e293b;
    font-size: 0.76rem;
    font-weight: 850;
    cursor: pointer;
}

.waypoint-delete-btn {
    background: #fee2e2;
    border-color: #fecaca;
    color: #991b1b;
}

.app-fullscreen-control button {
    width: 30px;
    height: 30px;
    border: 0;
    background: #ffffff;
    color: #0f172a;
    font-size: 1rem;
    font-weight: 900;
    cursor: pointer;
}

.gps-boat-marker {
    background: none !important;
    border: none !important;
    pointer-events: none;
}

.gps-boat-icon {
    transform-origin: 50% 50%;
    filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.5));
}

/* ==========================================
   Text-Driven Route Plotter
   ========================================== */
#route-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #cbd5e0;
    border-radius: 6px;
    background-color: #fff;
    font-size: 1rem;
    font-family: monospace; /* Gives that technical ForeFlight feel */
    font-weight: 600;
    color: #1e293b;
    box-sizing: border-box;
    transition: all 0.2s;
    text-transform: uppercase;
}

#route-input:focus {
    border-color: #3182ce;
    outline: none;
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.2);
}

.route-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 24px;
}

.route-waypoint {
    background-color: #e2e8f0;
    color: #1a202c;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}


/* ==========================================
   Rounding Arrow Styles
   ========================================== */
.custom-rounding-arrow {
    background: none !important;
    border: none !important;
}

.rounding-icon svg {
    /* Slight animation to make them "pop" when plotted */
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    0% { transform: scale(0.5) rotate(-20deg); opacity: 0; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ==========================================
   ForeFlight-Style Route Plotter
   ========================================== */
.fpl-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    background-color: #fff;
    box-sizing: border-box;
    cursor: text;
    transition: all 0.2s;
    min-height: 42px;
}

.fpl-container:focus-within {
    border-color: #3182ce;
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.2);
}

.fpl-container.error {
    border-color: #e53e3e;
    background-color: #fff5f5;
}

#fpl-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

#route-input {
    flex: 1;
    min-width: 60px;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.95rem;
    color: #2d3748;
    padding: 2px 0;
}

/* Inside-the-box Route Pill */
.route-waypoint {
    background-color: #e2e8f0;
    color: #1a202c;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* ==========================================
   Rounding Arrow Styles
   ========================================== */
.custom-rounding-arrow {
    background: none !important;
    border: none !important;
}

.rounding-icon svg {
    /* Slight animation to make them "pop" when plotted */
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    0% { transform: scale(0.5) rotate(-20deg); opacity: 0; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ==========================================
   Ship Specifications Styles
   ========================================== */
.ship-specs-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.spec-input {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.spec-input label {
    font-size: 0.65rem;
    color: #718096;
    letter-spacing: 0;
}

.spec-input input {
    width: 100%;
    padding: 6px 4px;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #1e293b;
    text-align: center;
    box-sizing: border-box;
}

.spec-input input:focus {
    border-color: #3182ce;
    outline: none;
}

/* ==========================================
   Tactics Styles
   ========================================== */
.tactics-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.tactic-card {
    background: #ffffff;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    padding: 8px;
    font-size: 0.8rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.tactic-card-header {
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}

.tactic-maneuver {
    font-weight: bold;
    color: #e53e3e; /* Red for emphasis on maneuvers */
}

/* Map Labels */
.custom-maneuver-label { background: none !important; border: none !important; }
.maneuver-bubble {
    background-color: #ef4444;
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #b91c1c;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    white-space: nowrap;
}
#route-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #cbd5e0;
    border-radius: 6px;
    background-color: #fff;
    font-size: 1rem;
    font-family: monospace; 
    font-weight: 600;
    color: #1e293b;
    box-sizing: border-box;
    transition: border-color 0.2s;
    text-transform: uppercase;
    resize: none; /* Disables manual drag, JS will handle height */
    overflow: hidden;
    min-height: 48px;
}

/* ==========================================
   Route Summary Styles
   ========================================== */
.summary-box {
    background-color: #0f172a; /* Deep Slate Navy */
    color: #f8fafc;
    border-radius: 6px;
    padding: 14px;
    font-size: 0.85rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid #334155;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.summary-label {
    font-size: 0.62rem;
    color: #94a3b8;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.summary-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: #38bdf8; /* Sky Blue highlight */
}

.summary-total-row {
    grid-column: span 2;
    border-top: 1px solid #334155;
    padding-top: 8px;
    margin-top: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ==========================================
   Tactical Colors & Maneuvers
   ========================================== */
.bg-port { 
    background-color: #ef4444 !important; /* Red */
    border-color: #b91c1c !important; 
    color: white; 
}
.bg-stbd { 
    background-color: #10b981 !important; /* Green */
    border-color: #047857 !important; 
    color: white; 
}
.text-port { color: #ef4444; font-weight: 800; }
.text-stbd { color: #10b981; font-weight: 800; }

.maneuver-bubble {
    font-size: 0.65rem;
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid #cbd5e0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    white-space: nowrap;
}

.waypoint-label-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
}

.crew-action-bubble {
    width: max-content;
    max-width: 160px;
    padding: 3px 7px;
    border-radius: 4px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(203, 213, 225, 0.42);
    color: #facc15;
    font-size: 0.62rem;
    font-weight: 850;
    line-height: 1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.28);
    white-space: nowrap;
}
.crew-pass-label {
    font-weight: 400;
    font-size: 0.58rem;
    opacity: 0.6;
    letter-spacing: 0.03em;
}

/* ==========================================
   Course Line Arrows
   ========================================== */
.custom-route-arrow {
    background: none !important;
    border: none !important;
}

.route-arrow-svg {
    filter: drop-shadow(0px 1px 2px rgba(0,0,0,0.6));
    display: block;
    /* Rotation will be applied inline by JS to match the course heading */
}

/* ==========================================
   Dynamic Bubble Wrappers
   ========================================== */
.dynamic-bubble {
    position: absolute;
    width: max-content;
    /* Prevents the text from wrapping to a second line */
    white-space: nowrap; 
}

/* Pushes the maneuver bubble to the top-right of the buoy */
.dynamic-bubble.maneuver-offset {
    transform: translate(14px, -24px); 
}

/* ==========================================
   Responsive Top Route Header
   ========================================== */
.mobile-only {
    display: none;
}

#mobile-header {
    display: flex; /* Always visible — the cheater bar */
    position: absolute;
    top: 0;
    left: 320px; /* Sits beside the sidebar on desktop */
    right: 0;
    height: 52px;
    background: rgba(255,255,255,0.97);
    z-index: 1999; /* Below sidebar (2001) */
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    padding: 0 10px;
    align-items: center;
    gap: 10px;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(4px);
}

/* When sidebar collapses, bar expands full-width */
body.sidebar-closed #mobile-header {
    left: 0;
}

/* Push Leaflet zoom controls down so the cheater bar doesn't cover them */
.leaflet-top {
    margin-top: 52px !important;
    transition: margin-top 0.3s ease;
}

.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #0f172a;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#mobile-route-pills {
    flex: 1;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    align-items: center;
    margin-top: 0;
    padding-top: 6px;    /* room for active-waypoint ring shadow above pills */
    padding-bottom: 6px;
    padding-left: 5px;   /* prevent first pill shadow from being clipped */
    scroll-padding-left: 5px;
}

/* Floating Action Buttons (GPS & Lock) */
#floating-actions {
    position: absolute;
    bottom: 78px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

/* ==========================================
   NMEA Instrument Panels
   ========================================== */
#nmea-bottom-bar {
    position: absolute;
    left: 340px;
    right: 24px;
    bottom: 14px;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1200;
    display: grid;
    grid-template-columns: repeat(5, minmax(70px, 1fr));
    gap: 6px;
    padding: 7px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.38);
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    backdrop-filter: blur(8px);
}

body.sidebar-closed #nmea-bottom-bar {
    left: 16px;
}

#course-status-bar {
    position: absolute;
    left: 340px;
    right: 24px;
    bottom: 72px;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1200;
    display: grid;
    grid-template-columns: 34px minmax(92px, 1fr) minmax(72px, 0.8fr) minmax(92px, 1fr) 34px;
    gap: 6px;
    padding: 6px;
    border-radius: 8px;
    background: rgba(248, 250, 252, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.45);
    box-shadow: 0 5px 14px rgba(15,23,42,0.22);
    backdrop-filter: blur(8px);
}

body.sidebar-closed #course-status-bar {
    left: 16px;
}

#course-status-bar div {
    min-width: 0;
    padding: 4px 6px;
    border-radius: 5px;
    background: rgba(226, 232, 240, 0.8);
    text-align: center;
}

#course-status-bar span {
    display: block;
    color: #64748b;
    font-size: 0.52rem;
    font-weight: 900;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#course-status-bar strong {
    display: block;
    margin-top: 3px;
    color: #0f172a;
    font-size: 0.78rem;
    font-weight: 950;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tracker-step-btn {
    width: 100%;
    height: 100%;
    min-height: 34px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    background: #ffffff;
    color: #1e293b;
    font-size: 1.2rem;
    font-weight: 900;
    cursor: pointer;
}

#nmea-bottom-bar div {
    min-width: 0;
    padding: 4px 6px;
    border-radius: 5px;
    background: rgba(51, 65, 85, 0.7);
    text-align: center;
}

#nmea-bottom-bar span,
.nmea-data-grid span {
    display: block;
    color: #94a3b8;
    font-size: 0.58rem;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#nmea-bottom-bar strong,
.nmea-data-grid strong {
    display: block;
    margin-top: 3px;
    color: #f8fafc;
    font-size: 0.92rem;
    font-weight: 900;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#nmea-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    max-width: calc(100vw - 24px);
    height: 100vh;
    z-index: 2200;
    box-sizing: border-box;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
    border-left: 1px solid #cbd5e1;
    box-shadow: -8px 0 22px rgba(0,0,0,0.22);
    transition: transform 0.24s ease;
}

#nmea-panel.collapsed {
    transform: translateX(100%);
}

.nmea-panel-header,
.nmea-log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.nmea-panel-header {
    padding-bottom: 10px;
    border-bottom: 2px solid #e2e8f0;
}

.nmea-panel-header h2 {
    margin: 0;
    color: #0f172a;
    font-size: 1.2rem;
}

.nmea-connect-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
}

#nmea-url,
#nmea-manual-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    background: #ffffff;
    color: #0f172a;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.76rem;
}

#nmea-url {
    padding: 7px;
}

#nmea-manual-input {
    padding: 8px;
    resize: vertical;
    min-height: 64px;
}

#nmea-connect,
#nmea-scan,
#nmea-parse-manual,
#nmea-clear-log {
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    background: #ffffff;
    color: #1e293b;
    font-weight: 800;
    cursor: pointer;
}

#nmea-connect,
#nmea-scan,
#nmea-parse-manual {
    padding: 7px 10px;
}

#nmea-clear-log {
    padding: 4px 8px;
    font-size: 0.7rem;
}

.nmea-status {
    padding: 7px 9px;
    border-radius: 5px;
    font-size: 0.78rem;
    font-weight: 800;
}

.nmea-status.offline {
    background: #fee2e2;
    color: #991b1b;
}

.nmea-status.connecting {
    background: #fef3c7;
    color: #92400e;
}

.nmea-status.online {
    background: #dcfce7;
    color: #166534;
}

.nmea-data-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}

.nmea-data-grid div {
    min-width: 0;
    padding: 8px;
    border-radius: 6px;
    background: #0f172a;
}

.nmea-data-grid div:first-child {
    grid-column: span 2;
}

#nmea-log {
    flex: 1;
    min-height: 120px;
    margin: 0;
    padding: 9px;
    overflow: auto;
    border-radius: 6px;
    background: #020617;
    color: #a7f3d0;
    font-size: 0.68rem;
    line-height: 1.35;
    white-space: pre-wrap;
}

.nmea-toggle {
    position: absolute;
    top: 74px;
    right: 16px;
    z-index: 1300;
    padding: 8px 10px;
    border: 1px solid rgba(203, 213, 225, 0.8);
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.9);
    color: #f8fafc;
    font-size: 0.75rem;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}

.fab-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background-color: #ffffff;
    color: #334155;
    border: 1px solid #cbd5e1;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fab-btn:hover { background-color: #f8fafc; transform: scale(1.05); }

.fab-btn.locked {
    background-color: #ef4444; 
    color: #ffffff;
    border-color: #dc2626;
}

.race-mode-text {
    display: none;
    font-size: 0.56rem;
    font-weight: 900;
    letter-spacing: 0.03em;
}

.fab-btn.locked .race-mode-text {
    display: block;
}

.fab-btn.locked svg {
    display: none !important;
}

/* Tablet & Phone Breakpoints (1024px) */
@media (max-width: 1024px) {
    body { flex-direction: column; }
    
    /* 2. Show the header ALL the time on mobile */
    #mobile-header { display: flex !important; }
    .mobile-only { display: flex; }

    body.sidebar-closed .leaflet-top { margin-top: 0; } /* Reset control offset */

    #map {
        position: absolute;
        top: 60px;
        width: 100%;
        height: calc(100vh - 60px);
    }

    #control-pane {
        position: absolute;
        top: 60px;
        left: -100%; 
        margin-left: 0 !important; 
        width: 100%;
        max-width: 380px;
        height: calc(100vh - 60px);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2001;
    }

    #control-pane.open {
        left: 0;
        box-shadow: 10px 0 25px rgba(0,0,0,0.3);
    }
}

/* Floating Action Buttons (GPS & Lock) */
#floating-actions {
    position: absolute;
    bottom: 78px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.fab-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background-color: #ffffff;
    color: #334155;
    border: 1px solid #cbd5e1;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fab-btn:hover { background-color: #f8fafc; transform: scale(1.05); }

.fab-btn.locked {
    background-color: #ef4444; /* Bright Red */
    color: #ffffff;
    border-color: #dc2626;
}

/* 1024px captures both Phones AND iPads */
@media (max-width: 1024px) {
    body { flex-direction: column; }
    #mobile-header { display: flex; }
    .mobile-only { display: flex; }

    #map {
        position: absolute;
        top: 60px;
        width: 100%;
        height: calc(100vh - 60px);
    }

    /* Convert Sidebar into a Sliding Drawer */
    #control-pane {
        position: absolute;
        top: 60px;
        left: -100%; 
        width: 100%;
        max-width: 380px;
        height: calc(100vh - 60px);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2001;
    }

    #control-pane.open {
        left: 0;
        box-shadow: 10px 0 25px rgba(0,0,0,0.3);
    }
}

/* High-Density Forecast Grid Control */
.time-grid-container {
    display: grid;
    grid-template-columns: repeat(6, 1fr); /* 6 columns = 4 tight rows for 24 hours */
    gap: 4px;
    padding: 2px 0;
    max-height: none; /* No scrollbar needed now! */
    overflow: hidden;
}

.time-grid-container button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 1px !important; /* Ultra-tight touch target padding */
    height: 34px; /* Fixed mechanical micro-height */
    border-radius: 4px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #334155;
    cursor: pointer;
    transition: all 0.1s ease;
}

.time-grid-container button:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.time-grid-container button.active {
    background: #2563eb !important;
    border-color: #1d4ed8 !important;
    color: #ffffff !important;
    font-weight: 700;
}

/* Micro-Typography scaling */
.time-grid-container .mini-date {
    font-size: 0.5rem !important; /* Shrunk down for absolute layout fit */
    line-height: 1 !important;
    opacity: 0.8;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.time-grid-container .mini-hour {
    font-weight: 700;
    font-size: 0.65rem !important;
    line-height: 1 !important;
}

/* Desktop-Specific Map Menu Button */
.desktop-only { display: flex; }

#desktop-menu-btn {
    position: absolute;
    top: 84px; /* Sits perfectly below Leaflet's +/- zoom buttons */
    left: 12px;
    z-index: 1000;
}

/* Tablet & Phone Breakpoints (1024px captures both Phones AND iPads) */
@media (max-width: 1024px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: flex; }
    
    body { flex-direction: column; }
    #mobile-header { display: flex; }

    #map {
        position: absolute;
        top: 60px;
        width: 100%;
        height: calc(100vh - 60px);
    }

    #control-pane {
        position: absolute;
        top: 60px;
        left: -100%; 
        margin-left: 0 !important; /* Protects mobile from the desktop margin animation */
        width: 100%;
        max-width: 380px;
        height: calc(100vh - 60px);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2001;
    }

    #control-pane.open {
        left: 0;
        box-shadow: 10px 0 25px rgba(0,0,0,0.3);
    }

    #nmea-bottom-bar {
        left: 8px;
        right: 8px;
        bottom: 8px;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 4px;
        padding: 5px;
    }

    #nmea-bottom-bar strong {
        font-size: 0.78rem;
    }

    #floating-actions {
        bottom: 68px;
        right: 12px;
    }

    .nmea-toggle {
        top: 72px;
        right: 10px;
    }
}

/* ==========================================
   Final App-Shell & Mobile Responsiveness
   ========================================== */
:root {
    --mobile-header-height: 60px;
    --bottom-instrument-height: 58px;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
}

.hidden {
    display: none !important;
}

.route-waypoint.active-waypoint {
    box-shadow: 0 0 0 3px #d946ef, 0 0 0 5px rgba(217, 70, 239, 0.25);
    font-weight: 900;
}

.waypoint-directto-btn {
    width: 100%;
    border: 1px solid #0369a1;
    border-radius: 5px;
    padding: 7px 8px;
    background: #e0f2fe;
    color: #0369a1;
    font-size: 0.76rem;
    font-weight: 850;
    cursor: pointer;
}

.waypoint-directto-btn:disabled {
    opacity: 0.45;
    cursor: default;
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #94a3b8;
}

.leaflet-container {
    background: #e8eef3;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

#map,
#control-pane,
#nmea-panel {
    height: 100dvh;
}

#control-pane,
#nmea-panel {
    min-height: 0;
}

.custom-user-mark {
    z-index: 900 !important;
}

.custom-mark-circle {
    width: 26px;
    height: 26px;
    font-size: 0.58rem;
    letter-spacing: 0;
}

.custom-mark-circle.start-mark {
    background: #0ea5e9;
    border-color: #0369a1;
}

.custom-mark-circle.manual-mark {
    background: #7c3aed;
    border-color: #5b21b6;
}

.custom-mark-label {
    top: 3px;
    background: rgba(15, 23, 42, 0.88);
    color: #f8fafc;
    border-color: rgba(203, 213, 225, 0.35);
}

.fab-btn.active {
    background-color: #2563eb;
    color: #ffffff;
    border-color: #1d4ed8;
}

.fab-btn.active.unlocked {
    background-color: #ffffff;
    color: #2563eb;
    border-color: #2563eb;
}

.fab-btn:disabled {
    opacity: 0.45;
    pointer-events: none;
}

#btn-ping-start {
    background-color: #0ea5e9;
    color: #ffffff;
    border-color: #0369a1;
}

#floating-actions {
    bottom: 132px;
}

@media (max-width: 1024px) {
    body {
        position: fixed;
        inset: 0;
        flex-direction: column;
    }

    #mobile-header {
        left: 0; /* sidebar is a drawer overlay on mobile, header always full-width */
        height: calc(var(--mobile-header-height) + env(safe-area-inset-top));
        padding-top: env(safe-area-inset-top);
        box-sizing: border-box;
    }

    #map {
        position: absolute;
        top: calc(var(--mobile-header-height) + env(safe-area-inset-top));
        width: 100%;
        height: calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top));
    }

    #control-pane {
        position: absolute;
        top: calc(var(--mobile-header-height) + env(safe-area-inset-top));
        width: min(100vw, 380px);
        height: calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top));
        padding: 18px;
        padding-bottom: calc(var(--bottom-instrument-height) + env(safe-area-inset-bottom) + 18px);
    }

    #nmea-panel {
        height: 100dvh;
        padding-bottom: calc(env(safe-area-inset-bottom) + 18px);
    }

    #nmea-bottom-bar {
        bottom: calc(8px + env(safe-area-inset-bottom));
        left: 8px;
        right: 8px;
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    #course-status-bar {
        left: 8px;
        right: 8px;
        bottom: calc(var(--bottom-instrument-height) + env(safe-area-inset-bottom) + 14px);
        grid-template-columns: 30px minmax(72px, 1fr) minmax(58px, 0.8fr) minmax(72px, 1fr) 30px;
        gap: 4px;
        padding: 5px;
    }

    #floating-actions {
        right: calc(12px + env(safe-area-inset-right));
        bottom: calc(var(--bottom-instrument-height) + env(safe-area-inset-bottom) + 68px);
    }
}

@media (max-width: 480px) {
    #mobile-header {
        padding-left: 10px;
        padding-right: 10px;
        gap: 10px;
    }

    .fab-btn {
        width: 42px;
        height: 42px;
    }

    #floating-actions {
        gap: 9px;
    }

    #nmea-bottom-bar {
        gap: 3px;
        padding: 4px;
    }

    #nmea-bottom-bar div {
        padding: 4px 3px;
    }

    #nmea-bottom-bar span {
        font-size: 0.48rem;
        letter-spacing: 0.02em;
    }

    #nmea-bottom-bar strong {
        font-size: 0.68rem;
    }

    #course-status-bar strong {
        font-size: 0.64rem;
    }

    .leg-course-pill {
        gap: 5px;
        padding: 3px 7px;
        font-size: 0.6rem;
    }
}

/* ==========================================
   Cheater Bar Bearing Separators
   ========================================== */
.route-brg-sep {
    font-size: 0.6rem;
    color: #94a3b8;
    align-self: center;
    white-space: nowrap;
    padding: 0 2px;
    letter-spacing: -0.02em;
}

/* ==========================================
   Track-Up Orientation Button
   ========================================== */
#btn-orient.track-up {
    background-color: #0ea5e9;
    color: #ffffff;
    border-color: #0284c7;
}

/* Map rotation transition */
#map {
    transition: transform 0.25s ease;
    transform-origin: center center;
}

/* ==========================================
   TWD Override Controls
   ========================================== */
.twd-override-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
}

.twd-override-row input[type="number"] {
    width: 50px;
    padding: 4px 4px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 0.78rem;
    text-align: center;
    background: #f8fafc;
    color: #1e293b;
}

.twd-override-row input[type="number"].active-override {
    border-color: #f59e0b;
    background: #fef9c3;
    color: #92400e;
    font-weight: 700;
}

.twd-clear-btn {
    padding: 3px 7px;
    border-radius: 5px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #64748b;
    cursor: pointer;
    font-size: 0.75rem;
    flex-shrink: 0;
}
.twd-clear-btn:hover { background: #fee2e2; color: #ef4444; border-color: #fca5a5; }

/* ==========================================
   Responsive: Landscape Short-Screen Phones
   (e.g. iPhone SE landscape: 568×320)
   ========================================== */
@media (max-height: 480px) and (orientation: landscape) {
    :root {
        --bottom-instrument-height: 44px;
    }

    #floating-actions {
        gap: 7px;
        bottom: calc(var(--bottom-instrument-height) + env(safe-area-inset-bottom) + 52px);
        right: calc(10px + env(safe-area-inset-right));
    }

    .fab-btn {
        width: 38px;
        height: 38px;
    }

    .fab-btn svg {
        width: 17px !important;
        height: 17px !important;
    }

    #nmea-bottom-bar {
        padding: 3px 4px;
        gap: 3px;
    }

    #nmea-bottom-bar div {
        padding: 3px 2px;
    }

    #nmea-bottom-bar span {
        font-size: 0.44rem;
        letter-spacing: 0.01em;
    }

    #nmea-bottom-bar strong {
        font-size: 0.6rem;
        margin-top: 1px;
    }

    #course-status-bar {
        padding: 3px 4px;
        gap: 3px;
        bottom: calc(var(--bottom-instrument-height) + env(safe-area-inset-bottom) + 10px);
    }

    #course-status-bar span {
        font-size: 0.44rem;
    }

    #course-status-bar strong {
        font-size: 0.62rem;
        margin-top: 1px;
    }

    .tracker-step-btn {
        min-height: 26px;
        font-size: 1rem;
    }
}

/* ==========================================
   Responsive: Extra Small Phones (< 360px wide)
   ========================================== */
@media (max-width: 360px) {
    #nmea-bottom-bar span {
        font-size: 0.43rem;
        letter-spacing: 0;
    }

    #nmea-bottom-bar strong {
        font-size: 0.6rem;
    }

    #nmea-bottom-bar div {
        padding: 4px 2px;
    }

    #course-status-bar strong {
        font-size: 0.58rem;
    }

    #course-status-bar span {
        font-size: 0.46rem;
    }

    .route-waypoint {
        font-size: 0.72rem;
        padding: 2px 5px;
    }

    .route-brg-sep {
        font-size: 0.5rem;
        padding: 0 1px;
    }

    .fab-btn {
        width: 40px;
        height: 40px;
    }

    #floating-actions {
        gap: 8px;
    }
}

/* ==========================================
   Responsive: TWD override row on narrow panes
   ========================================== */
@media (max-width: 340px) {
    .twd-override-row {
        flex-wrap: wrap;
    }

    .twd-override-row input[type="number"] {
        flex: 1 0 auto;
    }
}

/* ==========================================
   Responsive: Tablet portrait (768px)
   ========================================== */
@media (max-width: 768px) and (min-width: 481px) {
    #course-status-bar {
        gap: 5px;
        padding: 5px;
    }

    #nmea-bottom-bar {
        gap: 4px;
    }
}

/* ==========================================
   Desktop: Ensure sidebar-open NMEA bar gap
   ========================================== */
@media (min-width: 1025px) {
    #nmea-bottom-bar {
        left: 340px;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #course-status-bar {
        left: 340px;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    body.sidebar-closed #nmea-bottom-bar {
        left: 16px;
    }

    body.sidebar-closed #course-status-bar {
        left: 16px;
    }

    #floating-actions {
        bottom: 132px;
        right: 24px;
    }
}

/* ==========================================
   Help Modal
   ========================================== */
#help-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

#help-modal.open {
    opacity: 1;
    pointer-events: auto;
}

#help-modal-inner {
    background: #f8fafc;
    border-radius: 12px;
    width: min(700px, calc(100vw - 24px));
    max-height: min(88vh, 840px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

#help-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 2px solid #e2e8f0;
    flex-shrink: 0;
    background: #fff;
}

#help-modal-header h2 {
    margin: 0;
    font-size: 1rem;
    color: #0f172a;
    font-weight: 800;
    letter-spacing: -0.01em;
}

#help-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #64748b;
    font-size: 1.6rem;
    line-height: 1;
    padding: 0 6px;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

#help-modal-close:hover {
    background: #e2e8f0;
    color: #0f172a;
}

#help-modal-body {
    overflow-y: auto;
    padding: 14px 18px 20px;
    flex: 1;
}

#help-modal-footer {
    flex-shrink: 0;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    padding: 10px 20px;
    text-align: center;
}

#help-modal-footer p {
    margin: 0;
    font-size: 0.78rem;
    color: #64748b;
}

.help-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
}

.help-section {
    margin-bottom: 16px;
}

.help-section h3 {
    font-size: 0.66rem;
    color: #2563eb;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 800;
    margin: 0 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #e2e8f0;
}

.help-section ul {
    margin: 0;
    padding-left: 14px;
    list-style: disc;
}

.help-section li {
    font-size: 0.78rem;
    color: #334155;
    line-height: 1.65;
    margin-bottom: 2px;
}

.help-section li strong {
    color: #0f172a;
    font-weight: 700;
}

.help-section li code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.73rem;
    background: #e2e8f0;
    padding: 1px 4px;
    border-radius: 3px;
    color: #1e293b;
}

@media (max-width: 560px) {
    .help-cols {
        grid-template-columns: 1fr;
        gap: 0;
    }

    #help-modal {
        align-items: flex-end;
    }

    #help-modal-inner {
        border-radius: 14px 14px 0 0;
        max-height: 86vh;
        width: 100%;
    }
}

/* ==========================================
   Custom Popup Dialog (popup.js)
   ========================================== */
.pup-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.16s ease;
    padding: 16px;
}

.pup-overlay.pup-open {
    opacity: 1;
}

.pup-card {
    background: #ffffff;
    border-radius: 10px;
    padding: 20px 22px 16px;
    width: min(340px, 100%);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
    transform: translateY(8px) scale(0.97);
    transition: transform 0.16s ease;
}

.pup-overlay.pup-open .pup-card {
    transform: translateY(0) scale(1);
}

.pup-title {
    font-size: 0.88rem;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 7px;
    letter-spacing: -0.01em;
}

.pup-message {
    font-size: 0.8rem;
    color: #475569;
    line-height: 1.55;
    margin-bottom: 18px;
}

.pup-btn-row {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.pup-btn {
    font-size: 0.78rem;
    font-weight: 700;
    padding: 7px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: filter 0.1s;
    letter-spacing: 0.01em;
}

.pup-btn:hover  { filter: brightness(0.9); }
.pup-btn:active { filter: brightness(0.78); }

.pup-btn-primary { background: #2563eb; color: #fff; }
.pup-btn-danger  { background: #dc2626; color: #fff; }
.pup-btn-warning { background: #d97706; color: #fff; }
.pup-btn-ghost   { background: #e2e8f0; color: #334155; }

/* ==========================================
   Race Course Selector
   ========================================== */
.course-select {
    width: 100%;
    padding: 7px 10px;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #0f172a;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    appearance: auto;
    transition: border-color 0.15s;
}

.course-select:focus {
    outline: none;
    border-color: #2563eb;
}

/* ==========================================
   Vessel Performance Section
   ========================================== */
.vessel-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.vessel-row select {
    flex: 1;
    padding: 7px 10px;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #0f172a;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    appearance: auto;
}

.vessel-row select:focus { outline: none; border-color: #2563eb; }

.vessel-icon-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}

.vessel-icon-btn:hover { background: #e2e8f0; border-color: #94a3b8; }

.vessel-status {
    font-size: 0.7rem;
    color: #64748b;
    margin-top: 4px;
    min-height: 14px;
    line-height: 1.4;
}

/* ==========================================
   Polar leg data in tactics cards
   ========================================== */
.polar-leg-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    flex-wrap: wrap;
}

.polar-bsp {
    font-size: 0.82rem;
    font-weight: 800;
    color: #2563eb;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    padding: 1px 7px;
}

.polar-ete {
    font-size: 0.78rem;
    font-weight: 700;
    color: #64748b;
}

.sail-badge {
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 4px;
    padding: 1px 7px;
    letter-spacing: 0.02em;
}

.sail-reef {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    color: #92400e;
}

/* ==========================================
   Performance Charts Modal
   ========================================== */
#perf-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

#perf-modal-inner {
    background: #0f172a;
    border: 1px solid #1e3a5f;
    border-radius: 12px;
    width: min(96vw, 900px);
    height: min(88vh, 660px);
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#perf-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #1e3a5f;
}

#perf-modal-header h2 { color: #e2e8f0; font-size: 1rem; margin: 0; }

#perf-modal-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
}

#perf-modal-close:hover { color: #e2e8f0; }

.perf-tab-bar {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid #1e3a5f;
    background: #0f172a;
}

.perf-tab-btn {
    padding: 5px 18px;
    border: 1.5px solid #334155;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.perf-tab-btn.active, .perf-tab-btn:hover {
    background: #1e3a5f;
    border-color: #3b82f6;
    color: #60a5fa;
}

.perf-tab-pane {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#polar-canvas,
#crossover-canvas {
    flex: 1;
    width: 100%;
    min-height: 0;
    display: block;
}

/* ==========================================
   Add Vessel Modal
   ========================================== */
#add-vessel-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3100;
}

.av-modal-inner {
    background: #fff;
    border-radius: 12px;
    width: min(92vw, 440px);
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.av-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #1e293b;
    color: #e2e8f0;
}

.av-modal-header h2 { font-size: 1rem; margin: 0; }

.av-modal-header button {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
}

.av-modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.av-field { display: flex; flex-direction: column; gap: 4px; }

.av-field label { font-size: 0.8rem; font-weight: 700; color: #1e293b; }

.av-hint { font-weight: 400; color: #64748b; }

.av-field input[type="text"] {
    padding: 7px 10px;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.88rem;
    color: #0f172a;
}

.av-field input[type="text"]:focus { outline: none; border-color: #2563eb; }

.av-field input[type="file"] {
    font-size: 0.82rem;
    color: #334155;
}

.av-status {
    font-size: 0.8rem;
    color: #64748b;
    min-height: 18px;
    font-weight: 500;
}

.av-btn-row { display: flex; gap: 8px; justify-content: flex-end; }

.av-btn-primary {
    padding: 8px 20px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
}

.av-btn-secondary {
    padding: 8px 16px;
    background: #f1f5f9;
    color: #334155;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.av-btn-primary:hover { background: #1d4ed8; }
.av-btn-secondary:hover { background: #e2e8f0; }

/* ==========================================
   Sail toggle buttons (vessel sail selector)
   ========================================== */
.vessel-sail-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
    min-height: 0;
}

.sail-toggle-btn {
    padding: 3px 10px;
    border-radius: 4px;
    border: 2px solid var(--sail-color, #64748b);
    background: transparent;
    color: var(--sail-color, #64748b);
    font-size: 0.75rem;
    font-weight: 800;
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: opacity 0.15s, filter 0.15s;
}

.sail-toggle-btn:hover {
    filter: brightness(0.85);
    background: #f1f5f9;
}

.sail-toggle-btn.excluded {
    opacity: 0.3;
    text-decoration: line-through;
}

/* ==========================================
   Ship Specifications — vessel-override dim
   ========================================== */
#ship-specs-group.vessel-override .ship-specs-grid {
    opacity: 0.45;
    pointer-events: none;
    user-select: none;
}

.ship-specs-note {
    font-size: 0.68rem;
    font-weight: 500;
    color: #2563eb;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 3px;
    padding: 1px 5px;
    margin-left: 4px;
    vertical-align: middle;
}

/* ==========================================
   Sail plan summary (top of tactical breakdown)
   ========================================== */
.sail-plan-summary {
    background: #f8faff;
    border: 1.5px solid #bfdbfe;
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
}

.sail-summary-title {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #2563eb;
    margin-bottom: 5px;
}

.sail-summary-pills {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sail-summary-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
}

.sail-summary-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sail-summary-legs {
    color: #64748b;
    font-size: 0.72rem;
}

/* ==========================================
   Collapsible sidebar sections
   ========================================== */
.section-toggle-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    gap: 6px;
    /* Extend tap target slightly */
    margin: -4px -6px;
    padding: 4px 6px;
    border-radius: 5px;
    transition: background 0.12s;
}

.section-toggle-header:hover {
    background: rgba(0, 0, 0, 0.04);
}

/* The label inside the header keeps its existing styles */
.section-toggle-header > label {
    cursor: pointer;
    margin: 0;
    flex: 1;
}

.section-chevron {
    flex-shrink: 0;
    color: #94a3b8;
    transition: transform 0.2s ease;
    display: block;
}

.section-collapsed .section-chevron {
    transform: rotate(-90deg);
}

.section-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Smooth collapse animation */
    overflow: hidden;
    transition: opacity 0.18s ease;
}

.section-collapsed .section-body {
    display: none;
}

/* ==========================================
   Pill settings panel (gear button dropdown)
   ========================================== */
#pill-settings-panel {
    position: absolute;
    top: 58px;
    right: 48px;
    z-index: 3000;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 10px 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.18);
    min-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pill-settings-title {
    font-size: 0.7rem;
    font-weight: 800;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 2px;
}

.pill-settings-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    font-weight: 500;
    color: #1e293b;
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0;
}

.pill-settings-row input[type=checkbox] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #2563eb;
}

.pill-settings-row input:disabled {
    opacity: 0.45;
    cursor: default;
}

.pill-settings-note {
    color: #94a3b8;
    font-size: 0.68rem;
    font-style: italic;
}

/* ==========================================
   Sail change arrows inside route waypoint pills
   ========================================== */
.wp-sail-arrow {
    font-size: 1rem;
    font-weight: 900;
    line-height: 1;
    color: #0f172a;
}


/* ==========================================
   Sail plan — leg-by-leg list
   ========================================== */
.sail-summary-leglist {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}

.sail-summary-leg-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 5px;
    background: #f1f5f9;
    font-size: 0.76rem;
}

.ssl-leg {
    font-weight: 700;
    color: #475569;
    white-space: nowrap;
    flex-shrink: 0;
}

.ssl-sail {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.76rem;
    font-weight: 600;
}

/* Leg pill sail field */
.leg-pill-sail {
    font-weight: 900;
    font-size: 0.72rem;
}

/* Custom waypoint name input in placement popup */
.waypoint-name-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    padding: 6px 8px;
    font-size: 0.82rem;
    color: #0f172a;
    background: #f8fafc;
    margin-top: 6px;
    margin-bottom: 2px;
    outline: none;
}
.waypoint-name-input:focus {
    border-color: #2563eb;
    background: #fff;
}
.waypoint-name-error {
    font-size: 0.72rem;
    color: #dc2626;
    min-height: 14px;
    margin-bottom: 2px;
}

/* ==========================================
   Start Line Panel
   ========================================== */
#start-line-panel {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 4500;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.22), 0 1px 6px rgba(0, 0, 0, 0.1);
    padding: 12px 13px 10px;
    width: min(310px, calc(100vw - 24px));
    transform: translateY(-112%) scale(0.97);
    opacity: 0;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    pointer-events: none;
}

#start-line-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

#slp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

#slp-title {
    font-size: 0.78rem;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.01em;
    text-transform: uppercase;
}

#slp-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0 2px;
    border-radius: 4px;
    transition: color 0.15s;
}
#slp-close:hover { color: #0f172a; }

#slp-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin-bottom: 8px;
}

.slp-opt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 9px 5px 8px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    text-align: center;
}
.slp-opt:hover {
    border-color: #94a3b8;
    background: #f1f5f9;
}
.slp-opt:active {
    background: #e2e8f0;
}
.slp-opt.sl-placed {
    border-color: #22c55e;
    background: #f0fdf4;
}
.slp-opt.sl-placed:hover {
    border-color: #16a34a;
    background: #dcfce7;
}

.slp-opt-icon {
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
}
.slp-opt.sl-placed .slp-opt-icon { color: #16a34a; }

.slp-opt-name {
    font-size: 0.7rem;
    font-weight: 700;
    color: #0f172a;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.2;
}

.slp-opt-status {
    font-size: 0.66rem;
    color: #64748b;
    line-height: 1.2;
}
.slp-opt.sl-placed .slp-opt-status {
    color: #16a34a;
    font-weight: 600;
}

#slp-line-status {
    font-size: 0.7rem;
    color: #0369a1;
    font-weight: 600;
    min-height: 14px;
    text-align: center;
    padding: 2px 0;
}

#slp-hint {
    font-size: 0.65rem;
    color: #94a3b8;
    text-align: center;
    margin-top: 5px;
    line-height: 1.4;
}
#slp-hint em { font-style: normal; font-weight: 600; color: #64748b; }

@media (max-width: 1024px) {
    #start-line-panel {
        top: calc(var(--mobile-header-height) + env(safe-area-inset-top) + 8px);
        right: 8px;
    }
}

/* Timer card: shift below mobile header on small screens */
@media (max-width: 1024px) {
    #race-timer-bar {
        top: 72px; /* 60px header + 12px gap */
    }
}
