/* Copyright (c) 2026 Reavra. All rights reserved. */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #000; overflow: hidden; font-family: 'Segoe UI', Arial, sans-serif; color: #fff; -webkit-user-select: none; user-select: none; }
canvas { display: block; cursor: crosshair; touch-action: none; -webkit-user-select: none; user-select: none; }
#glCanvas { display: block; cursor: crosshair; touch-action: none; -webkit-user-select: none; user-select: none; }

/* ===== Desktop UI Panel ===== */
#ui {
    position: absolute; top: 10px; left: 10px;
    background: rgba(0,0,0,0.80); padding: 14px 18px; border-radius: 10px;
    font-size: 13px; line-height: 1.7; min-width: 240px;
    border: 1px solid rgba(255,255,255,0.12);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    max-height: calc(100vh - 20px); overflow-y: auto;
    z-index: 10;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}
.header-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
#ui h2 { font-size: 17px; margin: 0; color: #FDB813; letter-spacing: 0.5px; }
#btnAbout {
    background: none; border: 1px solid rgba(255,255,255,0.2); color: #888;
    font-size: 14px; font-style: italic; font-weight: 700; font-family: Georgia, 'Times New Roman', serif;
    width: 24px; height: 24px; border-radius: 50%;
    cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center;
    transition: color 0.15s, border-color 0.15s; flex-shrink: 0;
}
#btnAbout:hover { color: #4DA6FF; border-color: #4DA6FF; }
#ui .info { color: #aaa; }
#ui .controls { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
#ui button {
    background: #222; color: #fff; border: 1px solid #444; padding: 5px 14px;
    border-radius: 5px; cursor: pointer; font-size: 12px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
#ui button:hover { background: #444; }
#ui button.active { background: #4DA6FF; border-color: #4DA6FF; color: #000; font-weight: 600; }
#zoomLabel { margin-top: 8px; display: block; color: #aaa; font-size: 12px; }
input[type=range] { width: 190px; margin-top: 4px; accent-color: #4DA6FF; }
#legend { margin-top: 10px; font-size: 11px; line-height: 1.8; }
#legendSearch {
    width: 100%; padding: 5px 10px 5px 28px; margin-bottom: 6px;
    background: #1a1a1a url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%23888'%3E%3Ccircle cx='6' cy='6' r='4.5' stroke='%23888' stroke-width='1.5' fill='none'/%3E%3Cline x1='9.5' y1='9.5' x2='13' y2='13' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E") 8px center no-repeat;
    color: #fff; border: 1px solid #444; border-radius: 5px;
    font-size: 12px; font-family: inherit; outline: none;
    transition: border-color 0.2s;
}
#legendSearch:focus { border-color: #4DA6FF; }
#legendSearch::placeholder { color: #666; }
.legend-category {
    margin-top: 6px;
}
.legend-category:first-child { margin-top: 0; }
.legend-cat-header {
    display: flex; align-items: center; gap: 5px; cursor: pointer;
    padding: 3px 4px; border-radius: 4px; font-size: 11px;
    color: #999; font-weight: 600; letter-spacing: 0.3px;
    text-transform: uppercase; user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: color 0.15s;
}
.legend-cat-header:hover { color: #ccc; }
.legend-cat-arrow {
    display: inline-block; font-size: 9px; transition: transform 0.2s;
    width: 12px; text-align: center; flex-shrink: 0;
}
.legend-cat-arrow.collapsed { transform: rotate(-90deg); }
.legend-cat-count {        color: #555; font-size: 10px; font-weight: 400;
}
.legend-cat-items {
    overflow: hidden; transition: max-height 0.25s ease;
    padding-left: 4px;
}
.legend-cat-items.collapsed {
    max-height: 0 !important;
}
.legend-item { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 1px 4px; border-radius: 4px; transition: background 0.15s; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.legend-item:hover { background: rgba(255,255,255,0.08); }
.legend-item.tracking { background: rgba(77,166,255,0.2); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.legend-no-results { color: #555; font-style: italic; padding: 4px; font-size: 11px; }
#trackInfo {
    margin-top: 8px; padding: 8px 10px; background: rgba(77,166,255,0.1);
    border-radius: 6px; font-size: 12px; display: none;
    border: 1px solid rgba(77,166,255,0.25); white-space: pre-line;
}
#trackInfo .track-name { color: #4DA6FF; font-weight: 600; font-size: 13px; }
#trackInfo .track-data { color: #aaa; margin-top: 2px; }
#dateInput { margin-top: 6px; }
#dateInput input {
    background: #1a1a1a; color: #fff; border: 1px solid #444; padding: 4px 8px;
    border-radius: 4px; font-size: 12px; font-family: inherit; width: 140px;
}
#dateInput button {
    padding: 4px 10px; font-size: 11px; margin-left: 4px; vertical-align: middle;
}
#errorBox {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: rgba(200,0,0,0.9); color: #fff; padding: 20px 30px;
    border-radius: 10px; font-size: 14px; display: none; z-index: 9999;
    max-width: 80vw; word-break: break-all; white-space: pre-wrap;
}
/* ===== Mobile toggle button (always visible on mobile) ===== */
#mobileToggle {
    display: none;
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: calc(10px + env(safe-area-inset-left, 0px));
    background: rgba(0,0,0,0.75); border: 1px solid rgba(255,255,255,0.2);
    color: #FDB813; font-size: 22px; width: 44px; height: 44px;
    border-radius: 10px; cursor: pointer; z-index: 20;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    align-items: center; justify-content: center;
    line-height: 44px; text-align: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
#mobileToggle:active { background: rgba(77,166,255,0.3); }

/* ===== Mobile bottom HUD (date + speed) ===== */
#mobileHud {
    display: none;
    position: absolute; bottom: 0; left: 0; right: 0;
    z-index: 15;
}
#mobileHudBar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 12px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid rgba(255,255,255,0.1);
    gap: 4px; flex-wrap: wrap;
}
#mobileHudBar .mhud-info {
    color: #aaa; font-size: 11px; white-space: nowrap;
}
#mobileHudBar .mhud-controls {
    display: flex; gap: 4px; align-items: center;
}
#mobileHudBar button {
    background: #222; color: #fff; border: 1px solid #444;
    padding: 8px 12px; border-radius: 6px; font-size: 14px;
    cursor: pointer; min-width: 40px; text-align: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
#mobileHudBar button:active { background: #555; }
#mobileHudBar button.active { background: #4DA6FF; border-color: #4DA6FF; color: #000; font-weight: 600; }
/* ===== Mobile track info toast ===== */
#mobileTrackInfo {
    display: none;
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    left: calc(60px + env(safe-area-inset-left, 0px));
    background: rgba(0,0,0,0.80); border: 1px solid rgba(77,166,255,0.3);
    border-radius: 10px; padding: 10px 12px; font-size: 12px;
    z-index: 15; white-space: pre-line;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#mobileTrackInfo .track-name { color: #4DA6FF; font-weight: 600; font-size: 13px; }
#mobileTrackInfo .track-data { color: #aaa; margin-top: 2px; }
#mobileTrackInfo .mtrack-close {
    position: absolute; top: 6px; right: 10px; color: #888; font-size: 18px;
    cursor: pointer; line-height: 1;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Close button inside panel — hidden by default, shown on mobile */
#mobilePanelClose { display: none; }

/* ===== Mobile responsive overrides ===== */
@media (max-width: 768px), (pointer: coarse) {
    #mobileToggle { display: flex; }
    #mobileHud { display: block; }
    #ui {
        position: absolute; top: 0; left: 0; right: 0;
        bottom: calc(60px + env(safe-area-inset-bottom, 0px));
        min-width: unset; max-height: none; width: 100%;
        border-radius: 0; padding: 16px 16px 20px;
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    #ui.mobile-open {
        transform: translateX(0);
    }
    #ui h2 { font-size: 18px; padding-right: 40px; }
    #ui button { padding: 10px 16px; font-size: 14px; min-height: 44px; }
    #ui .controls { gap: 6px; }
    #zoomLabel { font-size: 13px; }
    input[type=range] { width: 100%; height: 30px; }
    #legend { font-size: 13px; line-height: 2.2; }
    #legendSearch { font-size: 14px; padding: 10px 10px 10px 32px; }
    .legend-cat-header { padding: 6px 8px; font-size: 13px; min-height: 36px; }
    .legend-item { padding: 6px 8px; min-height: 40px; }
    .legend-dot { width: 12px; height: 12px; }
    #dateInput input { font-size: 14px; padding: 8px 10px; width: 160px; }
    #dateInput button { padding: 8px 14px; font-size: 13px; }
    #trackInfo { font-size: 13px; padding: 10px 12px; }
    /* Close button inside panel on mobile */
    #mobilePanelClose {
        display: block;
        position: absolute; top: 14px; right: 14px;
        color: #888; font-size: 24px; cursor: pointer;
        line-height: 1; z-index: 5;
    }
}
@media (min-width: 769px) and (pointer: fine) {
    #mobilePanelClose { display: none !important; }
    #mobileTrackInfo { display: none !important; }
}

/* ===== 3D Control Bar ===== */
#bar3D {
    display: none;
    position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.82); border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px; padding: 8px 14px; z-index: 15;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    font-size: 12px; color: #aaa;
    align-items: center; gap: 10px;
    white-space: nowrap;
}
#bar3D.active { display: flex; }
#bar3D button {
    background: #222; color: #fff; border: 1px solid #555; padding: 5px 12px;
    border-radius: 5px; cursor: pointer; font-size: 12px;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}
#bar3D button:hover { background: #444; border-color: #888; }
#bar3D button:disabled { opacity: 0.35; cursor: default; }
#bar3D .bar3d-sep { width: 1px; height: 20px; background: rgba(255,255,255,0.15); }
#bar3D .bar3d-hint { color: #666; font-size: 11px; }

/* Category visibility checkbox */
.legend-cat-vis {
    width: 14px; height: 14px; accent-color: #4DA6FF;
    cursor: pointer; margin-left: auto; flex-shrink: 0;
}

/* ===== About Modal ===== */
#aboutOverlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.75); z-index: 1000;
    justify-content: center; align-items: center;
}
#aboutOverlay.visible { display: flex; }
#aboutModal {
    background: #1a1a2e; color: #ddd; border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px; padding: 28px 32px; max-width: 520px; width: 90%;
    max-height: 80vh; overflow-y: auto; position: relative;
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    font-size: 14px; line-height: 1.7;
}
#aboutModal h2 { color: #FDB813; font-size: 20px; margin-bottom: 12px; }
#aboutModal h3 { color: #4DA6FF; font-size: 14px; margin-top: 16px; margin-bottom: 4px; }
#aboutModal p { margin-bottom: 8px; }
#aboutModal ul { margin: 4px 0 8px 20px; }
#aboutModal li { margin-bottom: 2px; }
#aboutModal a { color: #4DA6FF; text-decoration: none; }
#aboutModal a:hover { text-decoration: underline; }
#aboutClose {
    position: absolute; top: 12px; right: 16px; font-size: 24px;
    color: #888; cursor: pointer; line-height: 1;
}
#aboutClose:hover { color: #fff; }
.about-footer { margin-top: 20px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.1); }
.about-footer p { color: #666; font-size: 12px; margin: 0; }

@media (max-width: 768px), (pointer: coarse) {
    #bar3D { bottom: calc(60px + env(safe-area-inset-bottom, 0px) + 8px); padding: 8px 10px; gap: 6px; }
    #bar3D button { padding: 8px 14px; font-size: 13px; min-height: 36px; }
    #aboutModal { padding: 20px 18px; max-width: 95%; }
}
