/* Mobile-friendly improvements */
#progress-container {
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

#progress-bar {
    flex: 1;
    height: 4px !important;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

#progress {
    height: 100%;
    background: #2962FF;
    transition: width 0.3s ease;
}

#current-waypoint {
    color: white;
    font-size: 14px;
    font-weight: bold;
    min-width: 30px;
    text-align: center;
}

#tour-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    padding: 0 10px;
}

/* Desktop: only as wide as needed */
@media (min-width: 769px) {
    #tour-controls {
        width: fit-content;
        padding: 0;
    }
}

#tour-controls button {
    background: #2962FF;
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    min-width: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

#tour-controls button:hover {
    background: #1976D2;
}

#tour-controls button:active {
    background: #0D47A1;
}

#tour-controls button:disabled {
    background: #666;
    color: #999;
    cursor: not-allowed;
}

#tour-controls button:disabled:hover {
    background: #666;
}

#waypoint-info {
    max-width: 90vw;
    transition: all 0.3s ease;
    position: relative;
}

/* Override any default positioning for mobile only */
@media (max-width: 768px) {
    #waypoint-info {
        position: relative !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        bottom: auto !important;
        width: fit-content !important;
        max-width: calc(100vw - 20px) !important;
        margin: 10px auto !important;
    }
}

/* Desktop: static positioning on top-right */
@media (min-width: 769px) {
    #waypoint-info {
        position: absolute !important;
        width: auto !important;
        max-width: 400px !important;
        margin: 0 !important;
        left: auto !important;
        right: 20px !important;
        top: 20px !important;
        bottom: auto !important;
        transform: none !important;
        min-width: auto !important;
        max-height: none !important;
        /* Override any flex or grid positioning that might interfere */
        flex: none !important;
        align-self: auto !important;
        justify-self: auto !important;
    }
}

#waypoint-header {
    display: flex;
    align-items: center;
    gap: 10px;
    width: fit-content;
    z-index: 10;
}

#waypoint-title {
    font-size: 24px;
    margin: 0;
    flex: 0 1 auto;
    line-height: 1.2;
    z-index: 10;
}

#expand-btn {
    background: transparent;
    color: white;
    border: none;
    padding: 0;
    cursor: pointer;
    font-size: 14px;
    font-weight: normal;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
    opacity: 0.7;
}

#expand-btn:hover {
    opacity: 1;
}

#waypoint-content {
    margin-top: 10px;
}

/* Minimize button placed in the top-right of the info panel */
#minimize-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.142);
    background: inherit; /* match panel background (rgba) */
    color: #ffffff4c; /* white on black */
    cursor: pointer;
    font-size: 12px;
    line-height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
    z-index: 1; /* below text by default */
    pointer-events: none; /* do not intercept clicks until hovered */
    opacity: 0.75;
}

#minimize-btn:hover {
    border-color: rgba(255, 255, 255, 0.9);
}

/* When hovering the panel, bring the button to front and make it clickable */
#waypoint-info:hover #minimize-btn {
    z-index: 999;
    pointer-events: auto;
    opacity: 1;
}

/* On touch devices (no hover), keep the button interactive */
@media (hover: none) {
    #minimize-btn {
        z-index: 999;
        pointer-events: auto;
        opacity: 1;
    }
}

/* Collapsed state hides content on all screen sizes when triggered via minimize */
#waypoint-info.collapsed #waypoint-content {
    display: none;
}

#waypoint-description {
    font-size: 16px;
    line-height: 1.4;
    margin: 0;
    z-index: 10;
}

/* Mobile specific adjustments */
@media (max-width: 768px) {
    #tour-controls {
        gap: 6px;
        padding: 0 5px;
    }

    #tour-controls button {
        padding: 12px 14px;
        font-size: 18px;
        min-width: 46px;
        min-height: 46px;
        flex: 0 1 auto;
    }

    #waypoint-dropdown {
        width: 32px !important;
        padding: 12px 4px !important;
        font-size: 14px !important;
    }

    #speed-dropdown {
        width: 38px !important;
        padding: 12px 4px !important;
        font-size: 14px !important;
    }

    #waypoint-info {
        padding: 20px 15px;
        margin: 10px auto !important;
        max-width: calc(100vw - 20px);
        position: relative !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        bottom: auto !important;
        width: fit-content !important;
    }

    #waypoint-info.collapsed #waypoint-content {
        display: none;
    }

    #waypoint-info.expanded {
        position: fixed !important;
        top: 10px !important;
        left: 10px !important;
        right: 10px !important;
        bottom: auto !important;
        max-height: 70vh;
        overflow-y: auto;
        z-index: 1000;
        background: rgba(0, 0, 0, 0.9);
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
        width: auto !important;
        margin: 0 !important;
    }

    #waypoint-title {
        font-size: 28px;
        font-weight: bold;
        z-index: 10;
    }

    #waypoint-description {
        font-size: 16px;
    }

    #expand-btn {
        font-size: 16px;
    }
}

/* Very narrow screens (iPhone SE, etc.) */
@media (max-width: 400px) {
    #tour-controls {
        gap: 4px;
        padding: 0 3px;
    }

    #tour-controls button {
        padding: 10px 12px;
        font-size: 16px;
        min-width: 40px;
        min-height: 40px;
        flex: 1 1 auto;
        max-width: 60px;
    }

    #waypoint-dropdown {
        width: 28px !important;
        padding: 10px 2px !important;
        font-size: 12px !important;
        flex: 0 0 28px;
    }

    #speed-dropdown {
        width: 32px !important;
        padding: 10px 2px !important;
        font-size: 12px !important;
        flex: 0 0 32px;
    }

    #progress-container {
        margin: 0 3px 8px 3px;
        padding: 6px 10px;
    }

    #waypoint-info {
        margin: 10px auto !important;
        padding: 18px 12px;
        max-width: calc(100vw - 15px);
        position: relative !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        bottom: auto !important;
        width: fit-content !important;
    }

    #waypoint-info.expanded {
        top: 5px !important;
        left: 5px !important;
        right: 5px !important;
        max-height: 75vh;
        padding: 15px;
        margin: 0 !important;
    }

    #waypoint-title {
        font-size: 24px;
        font-weight: bold;
        z-index: 10;
    }

    #waypoint-description {
        font-size: 15px;
    }

    #expand-btn {
        font-size: 14px;
    }
}

/* Countdown Timer */
#countdown-timer {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#countdown-value {
    color: #2962FF;
    font-size: 16px;
}

@media (max-width: 768px) {
    #countdown-timer {
        bottom: 10px;
        right: 10px;
        font-size: 12px;
        padding: 6px 10px;
    }

    #countdown-value {
        font-size: 14px;
    }
}