html, body {
    width: 100%;
    height: 100%;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
body { margin: 0; overflow: hidden; overscroll-behavior: none; background-color: #050505; color: white; font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

body *,
body *::before,
body *::after {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

canvas {
    touch-action: none;
}

img {
    -webkit-user-drag: none;
}

/* Icons */
.icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    background: #333;
    color: white;
    border: 1px solid #555;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-family: serif;
    pointer-events: auto;
    flex-shrink: 0; 
    z-index: 25;
    position: relative;
    overflow: hidden;
}
.icon-btn:hover { background: #555; }
.icon-btn.active { background: #555; border-color: #8b9be1; color: #fff; }
.icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: #222; border-color: #444; }

.btn-icon-img {
    width: 14px;
    height: 14px;
    object-fit: contain;
    display: block; /* Default to show if loaded */
}

.btn-text {
    display: none; /* Hidden by default, shown via onerror */
    width: 14px;
    height: 14px;
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1;
    text-align: center;
}

.transport-icon {
    width: 30px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.skip-btn .transport-icon {
    gap: 0;
}

.skip-btn .transport-triangle + .transport-triangle {
    margin-left: 1px;
}

#skipStartBtn .transport-bar {
    margin-right: 1px;
}

#skipEndBtn .transport-bar {
    margin-left: 1px;
}

.transport-bar,
.pause-bar {
    width: 4px;
    min-width: 4px;
    height: 14px;
    background: currentColor;
    flex: 0 0 4px;
}

.transport-triangle,
.playback-triangle {
    width: 12px;
    height: 14px;
    background: currentColor;
    flex: 0 0 12px;
}

.transport-triangle.backward {
    clip-path: polygon(100% 0, 0 50%, 100% 100%);
}

.transport-triangle.forward,
.playback-triangle {
    clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.playback-icon {
    width: 30px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.playback-icon .playback-triangle {
    display: none;
}

.playback-icon.show-play .playback-triangle {
    display: block;
}

.playback-icon.show-play .pause-bar {
    display: none;
}

/* Bottom Controls Wrapper */
#bottomWrapper {
    position: absolute;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: 20px;
    right: 20px;
    display: flex;
    flex-direction: row; 
    justify-content: flex-end; 
    align-items: center;
    pointer-events: none; 
    gap: 15px;
    z-index: 20;
    height: 40px; /* Explicit height for alignment */
}

/* Timeline Container - Fluid Width */
#timelineContainer {
    position: absolute;
    bottom: 0;
    left: 155px;
    right: 105px;
    height: 40px;
    
    background: rgba(0, 0, 0, 0.8);
    padding: 0 15px;
    border-radius: 30px;
    border: 1px solid #333;
    display: flex;
    align-items: center;
    gap: 15px;
    pointer-events: auto;
    
    /* Animation properties */
    transition: opacity 0.3s ease, transform 0.3s ease, left 0.2s ease;
    overflow: hidden;
    white-space: nowrap;
    z-index: 20;
    box-sizing: border-box;
}

/* Collapsed State */
#timelineContainer.collapsed {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* Hidden via Settings */
#timelineContainer.hidden-setting {
    display: none !important;
}

#bottomWrapper.is-playing .paused-only {
    display: none;
}

#bottomWrapper:not(.is-playing) .playing-only {
    display: none;
}

/* Timeline Labels Responsive Logic */
@media (max-width: 600px) {
    #timelineStart, #timelineEnd {
        display: none;
    }
}

/* Button Groups */
#transportGroup,
#buttonGroup {
    position: absolute;
    bottom: 0;
    display: flex;
    gap: 10px;
    pointer-events: auto;
    z-index: 25;
}

#transportGroup {
    left: 0;
}

#buttonGroup {
    right: 0;
}

@media (max-width: 700px) {
    #bottomWrapper {
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        left: 12px;
        right: 12px;
        height: 92px;
    }

    #timelineContainer,
    #bottomWrapper.is-playing #timelineContainer {
        top: 0;
        bottom: auto;
        left: 0;
        right: 0;
    }

}

@media (max-width: 380px) {
    #transportGroup,
    #buttonGroup {
        gap: 7px;
    }
}

/* Range Slider Styling */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%; 
    background: transparent; 
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #555;
    border-radius: 2px;
}
input[type=range]:focus { outline: none; }

#timelineSlider {
    touch-action: pan-x;
}

/* Panels (Info & Settings) */
.panel {
    position: absolute;
    bottom: 80px;
    right: 20px;
    background: rgba(0, 0, 0, 0.95);
    padding: 20px;
    border-radius: 8px;
    min-width: 260px;
    max-width: 320px;
    border: 1px solid #333;
    display: none; 
    z-index: 30;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    pointer-events: auto;
    max-height: 70vh;
    overflow-y: auto;
}
.panel.visible { display: block; }

/* Typography */
h1, h2 { margin: 0 0 15px 0; font-size: 1.2rem; color: #ff9999; }
h2 { color: #8b9be1; font-size: 1.1rem; border-bottom: 1px solid #333; padding-bottom: 10px; }
p { font-size: 0.9rem; color: #ccc; margin-bottom: 8px; }
a { color: #8b9be1; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Legend */
.legend {
    margin-top: 15px;
    width: 100%;
    height: 10px;
    border-radius: 2px;
    position: relative; /* For marker positioning */
}

#legendMarker {
    position: absolute;
    top: -4px;
    bottom: -4px;
    width: 2px;
    background-color: #fff;
    box-shadow: 0 0 4px rgba(0,0,0,0.8);
    left: 33.33%; /* Default center at 0 */
    transition: left 0.1s linear;
    pointer-events: none;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-top: 4px;
}
.legend-labels:empty { display: none; }
#legendCaption { margin-top: 6px; color: #aaa; font-size: 0.75rem; overflow-wrap: anywhere; }
#legendCaption:empty { display: none; }
#infoLocation { margin-bottom: 8px; color: #bbb; font-size: 0.8rem; overflow-wrap: anywhere; }
#infoLocation:empty { display: none; }

/* Close Button */
.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: #666;
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
}
.close-btn:hover { color: white; }

.info-details-toggle {
    display: none;
    position: absolute;
    top: 6px;
    left: 6px;
    width: 32px;
    height: 32px;
    padding: 0;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: #999;
    cursor: pointer;
}

.info-details-toggle:hover { color: #fff; }

.info-details-toggle .chevron {
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
}

#infoPanel.details-expanded .info-details-toggle .chevron {
    transform: translateY(2px) rotate(225deg);
}

/* Settings */
#settingsPanel {
    width: min(340px, calc(100vw - 24px));
    min-width: 0;
    max-width: 340px;
    padding: 0;
    box-sizing: border-box;
    overflow: hidden;
}
#settingsPanel.visible { display: flex; flex-direction: column; }
.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    padding: 8px 10px 8px 16px;
    border-bottom: 1px solid #333;
}
.settings-header h2 { margin: 0; padding: 0; border: 0; font-size: 1rem; }
.settings-header .close-btn { position: static; width: 32px; height: 32px; padding: 0; }
.settings-body {
    width: 100%;
    min-height: 0;
    padding: 0 16px 8px;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-padding-block: 12px;
    scrollbar-width: thin;
    scrollbar-color: #555 transparent;
}
.settings-body::-webkit-scrollbar { width: 8px; }
.settings-body::-webkit-scrollbar-track { background: transparent; }
.settings-body::-webkit-scrollbar-thumb {
    min-height: 32px;
    border: 2px solid transparent;
    border-radius: 8px;
    background: #555;
    background-clip: content-box;
}
.settings-body::-webkit-scrollbar-thumb:hover { background-color: #707070; }
.settings-dataset { display: grid; gap: 8px; padding: 16px 0; }
.settings-dataset label { color: #aaa; font-size: 0.8rem; }
.settings-layout { width: 100%; margin: 14px 0 0; box-sizing: border-box; }
.settings-layout label { flex: 1; text-align: center; }
.settings-layout span { padding-block: 8px; }
#settingsPanel input[type=range] { box-sizing: border-box; margin-inline: 0; }
#datasetSelect, #cameraViewSelect, #colorMode, #tubeSides, #curveSegments, #videoAdvanced select, #localTemperatureControls select {
    width: 100%;
    min-width: 0;
    height: 38px;
    padding: 0 10px;
    border: 1px solid #555;
    border-radius: 4px;
    background: #222;
    color: #fff;
    color-scheme: dark;
    font: inherit;
    font-size: 16px;
}
#cameraViewSelect { width: 140px; max-width: 55%; }
#colorMode { width: 190px; max-width: 65%; }
#tubeSides, #curveSegments { width: 90px; max-width: 55%; }
#singleColorRow[hidden] { display: none; }
#singleColor { width: 42px; height: 30px; padding: 3px; border: 1px solid #555; border-radius: 4px; background: #222; cursor: pointer; }
#settingsSourceLink { justify-self: start; color: #aaa; font-size: 0.75rem; }
#localTemperatureControls { display: grid; gap: 8px; min-width: 0; }
#localTemperatureControls[hidden] { display: none; }
#localSearchForm { display: flex; gap: 6px; }
.local-search-field { position: relative; flex: 1; min-width: 0; }
#localSearch {
    min-width: 0; width: 100%; height: 38px; box-sizing: border-box;
    padding: 0 38px 0 10px; border: 1px solid #555; border-radius: 4px;
    background: #222; color: white; color-scheme: dark; font: inherit; font-size: 16px;
    -webkit-user-select: text; user-select: text; -webkit-touch-callout: default;
}
#localLocateBtn {
    position: absolute; top: 1px; right: 1px; width: 36px; height: 36px;
    display: grid; place-items: center; padding: 0; border: 0; border-radius: 3px;
    background: transparent; color: #aaa; cursor: pointer; touch-action: manipulation;
}
#localLocateBtn span {
    width: 18px; height: 18px; background: currentColor;
    -webkit-mask: url('./icons/locate-fixed.svg') center / contain no-repeat;
    mask: url('./icons/locate-fixed.svg') center / contain no-repeat;
}
#localLocateBtn:hover { background: #333; color: #fff; }
#localLocateBtn:disabled { opacity: 0.45; cursor: wait; background: transparent; }
#localSearchForm .upload-label { flex-shrink: 0; }
#localResults { list-style: none; padding: 0; margin: 0; }
#localResults button {
    width: 100%; padding: 10px 8px; text-align: left; border: 0; border-bottom: 1px solid #333;
    background: transparent; color: #ddd; font: inherit; font-size: 0.85rem;
    overflow-wrap: anywhere; cursor: pointer;
}
#localResults button:hover { background: #333; }
#localSelected { color: #ddd; font-size: 0.8rem; overflow-wrap: anywhere; }
#localSelected:empty { display: none; }
.local-status-row { display: flex; align-items: center; gap: 8px; }
#localStatus { flex: 1; color: #aaa; font-size: 0.75rem; overflow-wrap: anywhere; }
#localAction { flex-shrink: 0; }
#localStationFields { display: grid; gap: 8px; min-width: 0; }
#localStationFields[hidden] { display: none; }
#localStationFields select { min-width: 0; max-width: 100%; }
#localStationSelect { text-overflow: ellipsis; }
#localStationDetails { margin: 0; color: #aaa; font-size: 0.75rem; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
#localStationDetails:empty { display: none; }
#localCountryDetails { margin: 0; color: #aaa; font-size: 0.75rem; line-height: 1.5; overflow-wrap: anywhere; }
.local-radius, .local-source { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.local-source[hidden] { display: none; }
.local-source label { flex-shrink: 0; }
#localTemperatureControls #localStationRadius { width: auto; }
.layout-modes { display: flex; border: 1px solid #555; border-radius: 6px; overflow: hidden; }
.layout-modes label { position: relative; cursor: pointer; }
.local-display label { flex: 1; text-align: center; }
.layout-modes input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.layout-modes span { display: block; padding: 7px 10px; font-size: 0.8rem; color: #aaa; }
.layout-modes input:checked + span { color: #fff; background: #454545; }
.layout-modes input:focus-visible + span { outline: 2px solid #8b9be1; outline-offset: -2px; }
.layout-modes input:disabled + span { opacity: 0.5; cursor: default; }
.settings-section { border-top: 1px solid #333; }
.settings-section > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    color: #eee;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}
.settings-section > summary::-webkit-details-marker { display: none; }
.settings-section > summary::after {
    content: '';
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    margin-right: 3px;
    border-right: 2px solid #999;
    border-bottom: 2px solid #999;
    transform: rotate(-45deg);
}
.settings-section[open] > summary::after { transform: translateY(-2px) rotate(45deg); }
.settings-section > summary:hover { color: #fff; }
.settings-section-content { padding: 4px 0 16px; }
.section-status { margin-left: auto; color: #8b9be1; font-size: 0.75rem; font-weight: 400; }
.section-status:empty { display: none; }
#settingsPanel :is(button, select, input, summary, a):focus-visible {
    outline: 2px solid #8b9be1;
    outline-offset: 2px;
}
#settingsPanel .switch:focus-within .slider-switch { outline: 2px solid #8b9be1; outline-offset: 2px; }
#settingsPanel input:not([type=checkbox]):disabled,
#settingsPanel select:disabled { opacity: 0.45; }
.switch input:disabled + .slider-switch { opacity: 0.45; cursor: default; }
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: #ddd;
    gap: 12px;
}
.setting-row:last-child { margin-bottom: 0; }
.setting-column { flex-direction: column; align-items: stretch; gap: 4px; }
.data-source-status { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; margin-bottom: 12px; }
#dataOrigin { color: #888; font-size: 0.75rem; }
.data-actions { display: flex; gap: 10px; }
.data-actions .upload-label { flex: 1; min-width: 0; }

/* Toggle Switch CSS */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    margin-left: 10px;
    flex-shrink: 0;
}
.switch input {
    position: absolute;
    inset: 0;
    z-index: 1;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.switch input:disabled { cursor: default; }
.slider-switch {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #444;
    transition: .3s;
    border-radius: 20px;
}
.slider-switch:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: #aaa;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider-switch { background-color: #2196F3; }
input:checked + .slider-switch:before { 
    transform: translateX(16px); 
    background-color: white;
}

/* Slider Labels */
.slider-label {
    display:flex; 
    justify-content:space-between; 
    width:100%; 
    margin-bottom:5px; 
    font-size:0.9rem;
}
.slider-val {
    color:#8b9be1; 
    font-size:0.8rem;
}

/* Upload Button */
.upload-label {
    background: #444;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    border: 1px solid #555;
    transition: background 0.2s;
    min-height: 32px;
}
.upload-label:hover { background: #555; }

.upload-label:disabled { opacity: 0.45; cursor: default; }

.video-export-row { gap: 12px; flex-wrap: wrap; }
.video-number {
    width: 70px;
    padding: 5px;
    box-sizing: border-box;
    border: 1px solid #555;
    border-radius: 4px;
    background: #222;
    color: #fff;
    font: inherit;
    font-size: 16px;
}
#videoAdvanced { margin-bottom: 15px; }
#videoAdvanced > summary { font-size: 0.8rem; font-weight: 400; }
#videoAdvanced > .settings-section-content { padding-bottom: 0; }
.video-dimensions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 15px; }
.video-dimensions label { display: grid; gap: 6px; font-size: 0.8rem; color: #ddd; min-width: 0; }
.video-dimensions .video-number { width: 100%; min-width: 0; }
.video-view-list { display: grid; gap: 6px; margin: -5px 0 10px; }
.video-view-step { display: grid; grid-template-columns: minmax(0, 1fr) repeat(3, 34px); gap: 4px; align-items: center; }
.video-view-step select { min-width: 0; }
.video-pause-duration { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: #bbb; font-size: 0.8rem; }
.video-pause-duration[hidden] { display: none; }
.video-pause-duration input { width: 74px; }
.video-path-label { display: block; margin: -4px 0 7px; color: #aaa; font-size: 0.8rem; }
.video-step-button {
    width: 34px; height: 36px; padding: 0; border: 1px solid #444; border-radius: 4px;
    background: #222; color: #ccc; cursor: pointer; font: inherit;
}
.video-step-button:hover:not(:disabled) { background: #383838; color: #fff; }
.video-step-button:disabled { opacity: 0.3; cursor: default; }
.video-add-view { background: transparent; color: #ccc; width: 100%; }
.video-path-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#videoPreviewBar { position: absolute; z-index: 30; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 8px 10px; border: 1px solid #555; border-radius: 6px; background: #111; white-space: nowrap; }
#videoPreviewBar[hidden] { display: none; }
#videoPreviewTime { min-width: 76px; text-align: center; font-variant-numeric: tabular-nums; font-size: 0.8rem; }
#videoCustomSize[hidden], #videoTransitionRow[hidden] { display: none; }
#videoExportProgress { width: 100%; accent-color: #8b9be1; }
#videoExportStatus, #svgExportStatus {
    margin: 8px 0;
    font-size: 0.8rem;
    color: #aaa;
    overflow-wrap: anywhere;
}
#videoExportStatus:empty, #svgExportStatus:empty { display: none; }

.loading-text {
    color: #f39c12;
    font-size: 0.8rem;
    display: none;
}

/* Drag Overlay */
#dragOverlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    color: white;
    display: none;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    z-index: 1000;
    pointer-events: none;
    border: 4px dashed #8b9be1;
}

@media (max-width: 700px) {
    .panel {
        position: fixed;
        left: 50%;
        right: auto;
        width: min(320px, calc(100vw - 24px));
        min-width: 0;
        max-width: 320px;
        padding: 16px;
        box-sizing: border-box;
    }

    #settingsPanel {
        top: 50%;
        bottom: auto;
        transform: translate(-50%, -50%);
        max-height: min(70vh, calc(100dvh - 32px));
    }

    #infoPanel {
        top: auto;
        bottom: calc(114px + env(safe-area-inset-bottom, 0px));
        transform: translateX(-50%);
        max-height: calc(100dvh - 158px - env(safe-area-inset-bottom, 0px));
        transition: bottom 0.2s ease;
    }

    body:not(.timeline-visible) #infoPanel {
        bottom: calc(62px + env(safe-area-inset-bottom, 0px));
    }

    .info-details-toggle {
        display: flex;
    }

    #infoPanel:not(.details-expanded) #infoDetails {
        display: none;
    }

    #infoPanel:not(.details-expanded) #currentDataDisplay {
        margin-top: 0 !important;
        padding-top: 18px !important;
        border-top: none !important;
    }

    #infoPanel:not(.details-expanded) {
        padding: 12px 14px;
    }

    #infoPanel:not(.details-expanded) .info-data-label {
        display: none;
    }

    #infoPanel:not(.details-expanded) .close-btn {
        top: 3px;
        right: 4px;
        width: 24px;
        height: 24px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
    }

    #infoPanel:not(.details-expanded) .info-details-toggle {
        top: 2px;
        left: 3px;
        width: 26px;
        height: 26px;
    }

    #infoPanel:not(.details-expanded) .info-details-toggle .chevron {
        width: 7px;
        height: 7px;
    }

    #infoPanel:not(.details-expanded) .legend {
        margin-top: 10px;
    }

    #infoPanel.details-expanded #infoDetails {
        padding-top: 24px;
    }
}
