html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background: #111111;
    overflow: hidden;
    font: 13px sans-serif;
    color: #eeeeee;
}

html * {
    font-family: "Space Mono", monospace;
    font-weight: 400;
    font-style: normal;
}

#scene { 
    width: 100%;
    height: 100vh;
}

#controls {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 900;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    background: rgba(27, 27, 27, 0.85);
    border-radius: 8px;
    padding: 8px 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    max-width: calc(100vw - 24px);
}
#modes { 
    display: flex;
    border: 1px solid #444;
    border-radius: 6px;
    overflow: hidden;
}
button {
    background: #222;
    border: 1px solid #444;
    color: #eee;
    cursor: pointer;
    font: inherit;
}
#modes button {
    padding: 6px 14px;
}
button:hover:not(:disabled) { 
    background: #2e2e2e;
}

button:disabled { 
    color: #777;
    cursor: not-allowed;
}
#modes button + button { 
    border-left: 1px solid #444;
}
#modes button.active { 
    background: #00fefc;
    color: #2e2e2e;
}

.option { 
    display: none;
    align-items: center;
    gap: 6px;
    color: #cfcfcf;
}
.option.visible { 
    display: flex;
}
.option input[type=number] {
    width: 56px;
    background: #222;
    color: #eee;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 3px 5px;
}
#count { 
    color: #9a9a9a;
}

#message {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    line-height: 1.5;
    background: #111;
}
#message.visible { 
    display: flex;
}
#message code { 
    background: #222;
    padding: 1px 5px;
    border-radius: 3px;
}

#info-button {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    z-index: 950;
    border: 1px solid #555;
    border-radius: 6px;
    padding: 7px 18px;
    background: rgba(27, 27, 27, 0.92);
}
#info-button:hover {
    border-color: #00fefc;
}
#info-dialog {
    width: min(560px, calc(100vw - 32px));
    max-height: min(70vh, 640px);
    padding: 20px;
    border: 1px solid #444;
    border-radius: 8px;
    background: #1b1b1b;
    color: #eee;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
    box-sizing: border-box;
    overflow-y: auto;
}
#info-dialog::backdrop {
    background: rgba(0, 0, 0, 0.7);
}
.info-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}
.info-dialog-header h2 {
    margin: 0;
    font-size: 18px;
}
#info-close {
    background: none;
    border: 0;
    color: #eee;
    font-size: 24px;
    line-height: 1;
    padding: 0 4px;
}
#info-close:hover {
    color: #00fefc;
}
#info-content {
    color: #cfcfcf;
    line-height: 1.6;
    white-space: normal;
}
#info-content p {
    margin: 0 0 10px;
}
#info-content h3 {
    margin: 16px 0 6px;
    color: #eee;
}
#info-content ul,
#info-content ol {
    margin: 0 0 12px;
    padding-left: 22px;
}
#info-content li + li {
    margin-top: 5px;
}

.panel {
    position: fixed;
    z-index: 1000;
    background: #1b1b1b;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    width: 480px;
    max-width: calc(100vw - 32px);
    box-sizing: border-box;
}
.bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 6px 12px;
}

#research-panel {
    left: 0;
    top: 70px;
    bottom: 16px;
    width: 33px;
    min-width: 33px;
    max-width: calc(100vw - 16px);
    transition: width 180ms ease;
    border-radius: 0 8px 8px 0;
}
#research-panel.is-open {
    width: 480px;
}
#player-panel {
    display: none;
    right: 16px;
    bottom: 16px;
    border-radius: 8px;
}

#research-window {
    display: none;
    flex-direction: column;
    gap: 6px;
    background: #1b1b1b;
    position: absolute;
    top: 0;
    left: 0;
    right: 25px;
    bottom: 0;
    overflow-y: auto;
    padding: 12px;
    box-sizing: border-box;
}

* {
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: #666 #1b1b1b; /* thumb, track */
}

*::-webkit-scrollbar {
    width: 8px; /* Chrome, Edge, Safari */
}

*::-webkit-scrollbar-track {
    background: #1b1b1b;
}

*::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb:hover {
    background: #00fefc;
}

#search-results { 
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
#search-results .hint { 
    color: #9a9a9a;
    padding: 4px 2px;
}
.result {
    text-align: left;
    background: #222;
    color: #eee;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 6px 8px;
    cursor: pointer;
    font: inherit;
}
.result:hover { 
    background: #2e2e2e;
    border-color: #00fefc;
}

#song-card { 
    margin: 12px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}
#song-card:empty { 
    display: none;
}
#song-card h3 { 
    margin: 0 0 8px;
    font-size: 15px;
}
button.search-panel-button {
    border-radius: 4px;
    padding: 5px 8px;
    margin-bottom: 8px;
    margin-right: 6px;
}
button.search-panel-button:hover {
    border-color: #00fefc;
}
.card-row { 
    display: flex;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid #262626;
}
.card-key { 
    flex: 0 0 120px;
    color: #9a9a9a;
}
.card-val { 
    flex: 1;
    word-break: break-word;
}
.value-btn {
    background: none;
    border: 0;
    border-bottom: 1px dotted #00fefc;
    color: #eee;
    padding: 0;
    margin-right: 8px;
    font: inherit;
    cursor: pointer;
    text-align: left;
}
.value-btn:hover { 
    color: #00fefc;
}

a { 
    color: white;
    word-break: break-all;
}
a:hover { 
    color: #00fefc;
}

#research-form { 
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#search-btn-box { 
    display: flex;
    gap: 6px;
}
input, select { 
    font: inherit;
    max-width: 80%;
    box-sizing: border-box;
    background: #222;
    color: #eee;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px 6px;
}
input:not([id="robust"]), select {
    width: 210px;
}
#research-window input:-webkit-autofill,
#research-window input:-webkit-autofill:hover,
#research-window input:-webkit-autofill:focus,
#research-window input:autofill {
    background-color: #222 !important;
    color: #eee !important;
    -webkit-box-shadow: 0 0 0 1000px #222 inset !important;
    box-shadow: 0 0 0 1000px #222 inset !important;
    -webkit-text-fill-color: #eee !important;
    caret-color: #eee !important;
    transition: background-color 9999s ease-out 0s;
}

#random-song-button {
    width: fit-content;
}

#toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: #222;
    color: #eee;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 8px 14px;
    z-index: 1200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms ease;
}
#toast.visible { 
    opacity: 1;
}

.neighbors { 
    margin: 8px 0 12px;
}
.neighbors h4 { 
    margin: 10px 0 4px;
    font-size: 13px;
    color: #9a9a9a;
}
.nb-row { 
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 3px 0;
    border-bottom: 1px solid #262626;
}
.nb-row .value-btn { 
    min-width: 0;
    margin-right: 0;
}
.nb-score { 
    margin-left: auto;
    color: #9a9a9a;
    font-variant-numeric: tabular-nums;
}

#research-panel.is-open #research-window { 
    display: flex;
}
#research-bar {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 25px;
    justify-content: center;
    padding: 6px 4px;
}
#research-toggle, #player-close {
    background: none;
    border: 0;
    color: #eeeeee;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
#research-toggle:hover, #player-close:hover { 
    color: #00fefc;
}
#player-frame { 
    display: block;
    width: 100%;
    height: 270px;
    border: 0;
}

#mobile-legend[hidden] {
    display: none;
}

#mobile-legend {
    position: fixed;
    z-index: 850;
    right: 12px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    width: min(240px, 30vw);
    max-height: min(48dvh, 520px);
    overflow: hidden;
    border: 1px solid #444;
    border-radius: 8px;
    background: rgba(27, 27, 27, 0.94);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

#mobile-legend.is-collapsed {
    width: max-content;
    max-width: calc(100vw - 16px);
    max-height: none;
}

#mobile-legend-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 5px 10px;
    border: 0;
    background: transparent;
    text-align: left;
}

#mobile-legend-count {
    color: #9a9a9a;
    font-size: 11px;
}

#mobile-legend-chevron {
    margin-left: auto;
    font-size: 18px;
}

#mobile-legend-items {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2px 5px 5px;
}

#mobile-legend.is-collapsed #mobile-legend-items {
    display: none;
}

button.mobile-legend-item {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 34px;
    padding: 4px 6px;
    overflow: hidden;
    border: 0;
    border-radius: 4px;
    background: transparent;
    text-align: left;
}

button.mobile-legend-item:hover {
    background: #2e2e2e;
}

button.mobile-legend-item.is-hidden {
    opacity: 0.45;
}

.mobile-legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.mobile-legend-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 1024px) {
    #controls {
        top: max(10px, env(safe-area-inset-top));
        left: 12px;
        right: 12px;
        max-width: none;
        box-sizing: border-box;
    }

    #research-panel.is-open {
        width: min(420px, calc(100vw - 32px));
    }

    #player-panel {
        right: 12px;
        width: min(420px, calc(100vw - 24px));
    }

    #mobile-legend {
        right: 12px;
        width: min(240px, 32vw);
        max-height: min(45dvh, 500px);
    }
}

@media (max-width: 700px) {
    #scene {
        height: 100vh;
        height: 100dvh;
    }

    .js-plotly-plot .plotly .modebar {
        top: 15px !important;
    }

    #controls {
        top: max(8px, env(safe-area-inset-top));
        left: max(8px, env(safe-area-inset-left));
        right: max(8px, env(safe-area-inset-right));
        gap: 5px 8px;
        padding: 6px;
        border-radius: 6px;
    }

    #modes {
        flex: 1 0 100%;
    }

    #modes button {
        flex: 1 1 0;
        min-height: 40px;
        padding: 7px 4px;
    }

    #count,
    .option {
        font-size: 11px;
    }

    .option input[type="checkbox"] {
        min-width: 18px;
        min-height: 18px;
        margin: 0;
    }

    #info-button {
        bottom: max(8px, env(safe-area-inset-bottom));
        min-height: 40px;
        padding: 7px 16px;
    }

    #info-dialog {
        width: calc(100vw - 24px);
        max-height: calc(100dvh - 24px);
        padding: 16px;
    }

    #research-panel {
        top: auto;
        right: auto;
        bottom: calc(56px + env(safe-area-inset-bottom));
        width: 30px;
        min-width: 0;
        max-width: calc(100vw - 16px);
        height: 40px;
        transition: height 180ms ease;
    }

    #research-panel.is-open {
        top: calc(100px + env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
        bottom: max(8px, env(safe-area-inset-bottom));
        width: auto;
        height: auto;
    }

    #research-window {
        right: 0;
        bottom: 34px;
        padding: 10px;
    }

    #research-toggle {
        min-width: 44px;
        min-height: 34px;
    }

    #player-panel {
        top: auto;
        right: max(8px, env(safe-area-inset-right));
        bottom: max(8px, env(safe-area-inset-bottom));
        left: auto;
        width: min(300px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
    }

    #player-bar {
        min-height: 34px;
        justify-content: flex-end;
    }

    #player-close {
        min-width: 40px;
        min-height: 40px;
    }

    #player-frame {
        height: auto;
        aspect-ratio: 16 / 9;
        max-height: min(24dvh, 170px);
    }

    #toast {
        bottom: calc(56px + env(safe-area-inset-bottom));
        max-width: calc(100vw - 32px);
        box-sizing: border-box;
        text-align: center;
    }

    #mobile-legend {
        right: max(8px, env(safe-area-inset-right));
        top: 140px;
        bottom: auto;
        width: min(220px, 58vw);
        max-height: min(45dvh, 360px);
    }

    #scene .modebar-container {
        top: 92px !important;
        right: 8px !important;
    }

}