html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #000;
    overflow: hidden;
}
#map {
    height: 100vh;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
}

/* Error + loading overlays */
.error {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: #dc3545;
    color: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    z-index: 2000;
    display: none;
}
.error.active {
    display: block;
}
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.75);
    color: #fff;
    padding: 14px 20px;
    border-radius: 10px;
    text-align: center;
    z-index: 2000;
    display: none;
}
.loading.active {
    display: block;
}
.loading .spinner {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    margin: 0 auto 8px;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Control panel (route + direction + GO) */
.control-panel {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1500;
    background: rgba(0, 27, 92, 0.9);
    border-radius: 10px;
    padding: 10px 12px;
    color: #ffdd00;
    max-width: 220px;
    width: 220px;
    box-sizing: border-box;
}

/* Hide route input and direction buttons when route is active */
.control-panel.route-active label[for="routeNumber"],
.control-panel.route-active #routeNumber,
.control-panel.route-active .dir-button {
    display: none !important;
}

/* Hide the entire control panel when route is active (END button is moved to body) */
.control-panel.route-active {
    display: none !important;
}

/* END button positioned at bottom left when route is active */
.go-button.end-mode.route-active-position {
    position: fixed;
    bottom: 10px;
    left: 10px;
    z-index: 1500;
    width: auto;
    min-width: 100px;
    padding: 10px 20px;
    margin-top: 0;
    border-radius: 6px;
    border: 2px solid #003366;
    background: #f44336;
    color: #fff;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
}

/* Route start/terminus banner above END button */
.route-start-terminus-banner {
    position: fixed;
    bottom: 60px;
    left: 10px;
    z-index: 1501;
    background: #001f3f; /* Navy blue */
    color: #ffffff; /* White text */
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: normal; /* Allow wrapping on small screens */
    word-wrap: break-word;
    max-width: calc(100vw - 80px); /* Prevent overflow on small screens */
    display: none;
}
.control-panel label {
    font-size: 0.8rem;
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}
.control-panel input[type="text"] {
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    border: 2px solid #003366;
    font-size: 1rem;
    text-align: center;
    font-weight: bold;
    background: #fff;
    color: #002b5c;
    margin-bottom: 8px;
}
.direction-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.dir-button {
    width: 100%;
    padding: 8px;
    font-size: 0.95rem;
    font-weight: bold;
    border-radius: 6px;
    border: 2px solid #003366;
    cursor: pointer;
    background: #FFF7A8; /* light yellow default */
    color: #003366;
}
.dir-button.selected {
    background: #A9F5A9; /* light green when selected */
    color: #003366;
}
/* disabled look for dir buttons when route number required */
.dir-button.disabled-dir {
    background: #FFF7A8;
    opacity: 0.7;
    cursor: not-allowed;
}
.go-button {
    width: 100%;
    margin-top: 4px;
    padding: 10px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 6px;
    border: 2px solid #003366;
    cursor: pointer;
    background: #4CAF50; /* green */
    color: #fff;
}
.go-button:hover {
    filter: brightness(1.05);
}
/* GO button when in END mode */
.go-button.end-mode {
    background: #f44336; /* red */
    color: #fff;
}

/* BIG bottom keyboard that fills lower screen (portrait baseline) */
.soft-keyboard {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1600;

    /* Take up a chunk of the screen but leave room for GO in portrait */
    height: 28vh;
    max-height: 220px;
    min-height: 160px;

    background: rgba(0, 0, 0, 0.85);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));

    display: none;             /* JS toggles to flex */
    flex-direction: column;
    gap: 4px;
}

/* Rows fill space equally */
.soft-keyboard-row {
    flex: 1;
    display: flex;
    gap: 4px;
}

/* Individual keys – all rows same size now */
.soft-key {
    flex: 1;

    width: auto;
    max-width: none;
    min-width: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 8px;
    border: 1px solid #555;
    background: #222;
    color: #fff;
    font-size: 1.4rem;
    font-weight: 600;
    padding: 6px 0;

    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Slightly wider keys for BACK / DEL */
.soft-key.wide {
    flex: 1.5;
}

/* Visual feedback on press */
.soft-key:active {
    background: #444;
}

/* Landscape: shrink keyboard so GO stays above it */
@media (orientation: landscape) {
    .soft-keyboard {
        height: 22vh;
        max-height: 180px;
    }
    .soft-key {
        font-size: 1.1rem;
        padding: 4px 0;
    }
}

/* On very small phones, make keys a bit bigger, but keep height reasonable */
@media (max-height: 650px) {
    .soft-keyboard {
        height: 32vh;
        max-height: none;
    }

    .soft-key {
        font-size: 1.5rem;
    }
}

/* Next stop banner */
.next-stop-banner {
    position: fixed;
    top: 15px;
    right: 15px;
    left: auto;
    transform: none;

    background: rgba(0, 51, 102, 0.85);
    color: #ffdd00;

    padding: 12px 16px;
    border-radius: 8px;

    font-size: 1.0em;
    font-weight: bold;
    z-index: 1999;

    display: inline-block;

    /* NEW: don’t stretch right across the route box */
    max-width: 65vw;
    white-space: normal;
    word-wrap: break-word;
    text-align: right;
}

/* Route info overlay */
.route-info-overlay.active {
    display: none !important;
}
.route-info-overlay h2 {
    margin: 0 0 6px;
    font-size: 0.9rem;
    color: #002b5c;
}
.route-info-grid {
    display: grid;
    grid-template-columns: 1fr;
    row-gap: 3px;
}
.route-info-item label {
    display: inline-block;
    min-width: 90px;
    font-weight: 600;
}
.route-info-item span {
    font-weight: 500;
}

/* Map controls (speed + follow / recenter) */
.map-controls-overlay {
    position: fixed;
    bottom: 70px;
    right: 10px;
    z-index: 1400;
    background: rgba(0,0,0,0.65);
    color: #fff;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 0.8rem;
    display: flex;
    gap: 8px;
    align-items: center;
}
.map-controls-overlay select,
.map-controls-overlay button {
    font-size: 0.8rem;
    border-radius: 6px;
    border: 1px solid #ccc;
    padding: 4px 6px;
}

/* Simple bus marker styling */
.bus-marker-icon .bus-marker-inner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #FF0000 !important; /* RED bus icon */
    border: 2px solid white;
}

/* Fullscreen exit button (X) */
.fs-exit-btn {
    position: fixed;
    top: 6px;
    left: 6px;
    z-index: 2100;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
    display: none;
    user-select: none;
}

/* Log Out button in control panel */
.control-panel .logout-btn {
    display: block;
    width: 100%;
    text-align: center;
    background: rgba(220, 53, 69, 0.9);
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;              /* match dir/go buttons */
    font-size: 0.7rem;
    text-decoration: none;
    border: 2px solid #003366;       /* match ROUTE / INBOUND / OUTBOUND / GO */
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.control-panel .logout-btn:hover {
    background: rgba(220, 53, 69, 1);
    text-decoration: none;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Blue route-long banner – positioned just below RE-CENTRE button */
.route-long-banner {
    position: fixed;
    bottom: 110px; /* Just below RE-CENTRE button (which is at bottom: 70px) */
    right: 10px;
    background: #002B80;
    color: #FFFFFF;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 18px;
    font-weight: bold;
    display: none;
    z-index: 9999;
    max-width: calc(100vw - 20px);
    white-space: normal;
    word-wrap: break-word;
    text-align: center;
}

/* When route is active, keep banner below RE-CENTRE button */
.route-long-banner.route-active-banner {
    bottom: 110px;
    right: 10px;
    left: auto;
    transform: none;
    max-width: calc(100vw - 20px);
}

/* In landscape, route banner sits above shorter keyboard */
@media (orientation: landscape) {
    .route-long-banner {
        bottom: calc(22vh + 10px);
        font-size: 16px;
    }
    
    .route-long-banner.route-active-banner {
        bottom: 10px;
    }
}

/* ============================================================
   RESPONSIVE: Mobile phones (max-width: 480px)
   ============================================================ */
@media (max-width: 480px) {
    /* Next stop banner - smaller font and padding on phones */
    .next-stop-banner {
        font-size: 0.85rem;
        padding: 8px 12px;
        max-width: calc(100vw - 80px); /* Leave space for controls */
        top: 10px;
        right: 10px;
    }

    /* Route start/terminus banner - smaller and allow wrapping */
    .route-start-terminus-banner {
        font-size: 0.75rem;
        padding: 5px 10px;
        max-width: calc(100vw - 80px);
        bottom: 60px;
        left: 10px;
        white-space: normal;
        word-wrap: break-word;
    }

    /* Route long banner - smaller font and better width constraint */
    .route-long-banner {
        font-size: 0.75rem;
        padding: 6px 10px;
        max-width: calc(100vw - 80px); /* Reduced for smaller screens */
        bottom: 110px;
        right: 10px;
        line-height: 1.2;
    }

    .route-long-banner.route-active-banner {
        max-width: calc(100vw - 80px);
    }

    /* Next turn banner - smaller on phones */
    #nextTurnBanner {
        max-width: 60vw !important;
        padding: 4px 8px !important;
        bottom: 130px !important; /* Higher up to avoid other banners */
    }

    #nextTurnDir,
    #nextTurnStreet,
    #nextTurnDist {
        font-size: 12px !important;
        line-height: 16px !important;
    }
}

/* Bottom banner - BUS ROUTE NAVIGATOR */
.bottom-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background: #000000; /* Blue background */
    color: #FFFFFF; /* White text */
    text-align: center;
    padding: 6px 10px;
    font-size: 0.75rem; /* Small font */
    font-weight: normal;
    z-index: 1000;
    box-sizing: border-box;
}

/* Make all controls inside the panel line up exactly */
.control-panel * {
    box-sizing: border-box;
}

/* (Explicit) ensure all buttons/inputs fill the panel */
.control-panel .logout-btn,
.control-panel input[type="text"],
.control-panel .dir-button,
.control-panel .go-button {
    display: block;
    width: 100%;
}
/* Current route banner - above BUS ROUTE NAVIGATOR */
.current-route-banner {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 30px; /* Above the bottom banner */
    background: #FFFACD; /* Light yellow background */
    color: #FF0000; /* Red text */
    font-weight: bold;
    padding: 6px 14px;
    border-radius: 4px;
    border: 1px solid #000000; /* Thin black border */
    white-space: nowrap;
    z-index: 1001;
    width: fit-content;
    display: inline-block;
}

/* Bottom banner: BUS ROUTE NAVIGATOR */
.bottom-banner{
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;

  width: fit-content;        /* key bit */
  display: inline-block;     /* prevents full-width block stretch */
  padding: 6px 14px;         /* whatever looks right */
  white-space: nowrap;       /* keep the 3 words on one line */
}

/* =========================================================
   NEXT TURN BANNER – DRIVER MODE (COMPACT, BOTTOM-RIGHT)
   ========================================================= */

/* =========================================================
   NEXT TURN BANNER – SMALL, BOTTOM-RIGHT (FONT 14)
   ========================================================= */

/* =========================================================
   NEXT TURN BANNER – SMALL, YELLOW ON BLACK, ABOVE RE-CENTRE
   ========================================================= */

/* NEXT TURN BANNER - positioned above RE-CENTRE button */
/* =========================================================
   NEXT TURN BANNER – MOBILE SAFE
   ========================================================= */

#nextTurnBanner{
  position: fixed !important;
  right: 12px !important;
  bottom: 150px !important;   /* above RE-CENTRE */
  left: auto !important;
  top: auto !important;

  z-index: 9999 !important;

  /* ✅ avoid iOS flex+fit-content repaint bugs */
  display: none;              /* JS/NextTurnAssist will show it */
  width: auto !important;
  max-width: 70vw !important;

  padding: 6px 10px !important;
  box-sizing: border-box !important;

  background: #000 !important;
  border-radius: 10px !important;
  transform: none !important;
}

#nextTurnDir,
#nextTurnStreet,
#nextTurnDist{
  display: block !important;
  margin: 0 !important;
  padding: 0 !important;

  font-size: 14px !important;
  line-height: 18px !important;
  text-align: right !important;

  color: #FFD700 !important;
  -webkit-text-fill-color: #FFD700 !important; /* ✅ iOS fix */
  opacity: 1 !important;
  visibility: visible !important;

  white-space: nowrap !important;
}

/* Bold the main direction line */
#nextTurnDir{
  font-weight: 800 !important;
}

/* Slightly softer for street/dist */
#nextTurnStreet,
#nextTurnDist{
  font-weight: 600 !important;
  margin-top: 2px !important;
}

/* Hide empty rows cleanly */
#nextTurnStreet:empty,
#nextTurnDist:empty{
  display: none !important;
}

/* Hide banner when keyboard is visible */
#nextTurnBanner.keyboard-visible-hide{
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Emphasis glow */
#nextTurnBanner.next-turn-emphasis{
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.6) !important;
}



