body {
    margin: 0;
    overflow: hidden;
    background: #000000;
    color: #e2e4e9;
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    color-scheme: dark;
}

html,
body.dashboard-page {
    width: 100%;
    height: 100%;
}

#loading,
#viewer-title,
#stats,
#colorbar,
#slice-panel {
    position: absolute;
    z-index: 10;
    transition: opacity 0.2s ease;
}

#loading {
    top: 50%;
    width: 100%;
    text-align: center;
    font-size: 14px;
    letter-spacing: 0.05em;
    color: #888;
}

#viewer-title {
    top: 24px;
    left: 24px;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.03em;
}

#stats {
    bottom: 20px;
    right: 24px;
    color: #666;
    font-size: 11px;
    pointer-events: none;
    letter-spacing: 0.02em;
}

#colorbar {
    display: none;
    color: #a0a0a0;
    font-size: 10px;
    pointer-events: none;
}

#colorbar .legend-title {
    margin-bottom: 6px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

#colorbar .legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#colorbar .bar {
    flex: 1 1 auto;
    min-width: 120px;
    height: 6px;
    border-radius: 2px;
    background: linear-gradient(to right,
            rgb(20, 41, 82) 0%,
            rgb(77, 188, 230) 42%,
            rgb(230, 230, 46) 72%,
            rgb(255, 255, 230) 100%);
}

.lil-gui #colorbar {
    position: static;
    z-index: auto;
    width: auto;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid #222;
    display: none;
    text-align: left;
    pointer-events: none;
}

#slice-panel {
    left: 24px;
    bottom: 24px;
    width: 256px;
    padding: 16px;
    border: 1px solid #222;
    border-radius: 6px;
    background: #0a0a0a;
    display: none;
    pointer-events: none;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.8);
}

#slice-panel .title {
    margin-bottom: 12px;
    color: #e2e4e9;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

#slice-canvas {
    display: block;
    width: 256px;
    height: 256px;
    margin: 0 auto;
    border-radius: 4px;
    background: #000;
    image-rendering: pixelated;
}

#slice-caption {
    margin-top: 12px;
    color: #666;
    font-size: 10px;
    text-align: center;
}

/* Minimal lil-gui Overrides */
.lil-gui {
    --background-color: #0a0a0a;
    --title-background-color: #111;
    --widget-color: #1a1a1a;
    --hover-color: #252525;
    --focus-color: #333;
    --text-color: #e2e4e9;
    --number-color: #fff;
    --font-family: inherit;
    border: 1px solid #222;
    border-radius: 6px;
    right: 24px !important;
    top: 24px !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.8);
}

.lil-gui select,
.lil-gui option {
    background: #111;
    color: #e2e4e9;
}

#viewer-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #000;
}

#control-panel {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 20;
    width: 220px;
    /* Slightly narrower */
    display: flex;
    flex-direction: column;
    padding: 12px 14px;
    /* Tighter padding to match lil-gui */
    border-radius: 6px;
    border: 1px solid #222;
    background: #0a0a0a;
    color: #e2e4e9;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.8);
    transition: opacity 0.2s ease;
}

#control-panel h1 {
    margin: 0 0 8px;
    /* Tighter margin */
    font-size: 13px;
    /* Matched to lil-gui title scale */
    font-weight: 600;
    letter-spacing: 0.02em;
}

#control-panel p {
    margin: 0 0 12px;
    font-size: 11px;
    line-height: 1.4;
    color: #888;
}

#control-panel label {
    display: block;
    margin-bottom: 8px;
    /* Tighter spacing */
    font-size: 11px;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#control-panel select,
#control-panel button {
    width: 100%;
    margin-top: 4px;
    padding: 6px 8px;
    /* Slimmer inputs */
    border-radius: 4px;
    border: 1px solid #333;
    background: #111;
    color: #e2e4e9;
    font: inherit;
    font-size: 11px;
    /* Smaller text inside inputs */
    transition: border-color 0.2s ease, background 0.2s ease;
}

#control-panel select:hover,
#control-panel button:hover {
    border-color: #555;
    background: #1a1a1a;
}

#control-panel button {
    cursor: pointer;
    margin-top: 10px;
    font-weight: 500;
}

#panel-status {
    margin-top: 10px;
    font-size: 10px;
    color: #555;
    min-height: 2.8em;
}

#panel-footer {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid #1c1c1c;
    font-size: 10px;
    color: #666;
    line-height: 1.5;
}

#panel-footer a {
    color: #9fb7ff;
    text-decoration: none;
}

#panel-footer a:hover {
    color: #c8d6ff;
    text-decoration: underline;
}

#panel-footer span {
    display: block;
}

/* -----------------------------------
   UI Hiding Logic 
----------------------------------- */
body.ui-hidden #control-panel,
body.ui-hidden #viewer-title,
body.ui-hidden #stats,
body.ui-hidden #slice-panel,
body.ui-hidden #colorbar,
body.ui-hidden .lil-gui,
body.ui-hidden .viewer-hint {
    display: none !important;
}

#restore-ui-button {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 9999;
    padding: 8px 14px;
    background: #0a0a0a;
    border: 1px solid #333;
    color: #888;
    border-radius: 4px;
    cursor: pointer;
    display: none;
    font-size: 11px;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color 0.2s ease, border-color 0.2s ease;
}

#restore-ui-button:hover {
    color: #fff;
    border-color: #666;
}

body.ui-hidden>#restore-ui-button {
    display: block;
}

.viewer-hint {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: min(520px, calc(100vw - 32px));
    padding: 11px 14px;
    border: 1px solid #2b2b2b;
    border-radius: 999px;
    background: rgba(10, 10, 10, 0.9);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    transform: translateX(-50%);
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.viewer-hint.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 12px);
}

.viewer-hint-icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    background: #151515;
    color: #9fb7ff;
}

.viewer-hint-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.viewer-hint-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.viewer-hint-copy strong {
    font-size: 12px;
    line-height: 1.2;
    color: #f3f5fa;
}

.viewer-hint-copy span {
    font-size: 11px;
    line-height: 1.3;
    color: #9aa0ab;
}

@media (max-width: 980px) {
    .lil-gui {
        top: auto !important;
        right: 12px !important;
        bottom: 12px !important;
        left: 12px !important;
        width: auto !important;
        max-width: none !important;
        max-height: 42vh;
    }

    #restore-ui-button {
        top: auto;
        left: auto;
        right: 12px;
        bottom: 12px;
    }

    #slice-panel {
        left: 12px;
        bottom: calc(42vh + 24px);
        width: min(256px, calc(100vw - 24px));
        padding: 12px;
    }

    #slice-canvas {
        width: 100%;
        height: auto;
    }
}

@media (max-width: 720px) {
    .viewer-hint {
        bottom: 16px;
        border-radius: 16px;
        padding: 10px 12px;
    }
}
