html, body {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    background: #0d0f12;
    color: #e8e8e8;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
                 "Malgun Gothic", sans-serif;
    overflow: hidden;
}

#viewer {
    display: block;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    outline: none;
}

.hidden { display: none !important; }

/* ───── Loading overlay ───── */
.loading {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(13, 15, 18, 0.92);
    z-index: 50;
}
.loading-card {
    width: 360px; padding: 24px 28px;
    background: #1a1d22; border: 1px solid #2a2f37; border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.loading-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.loading-status { font-size: 13px; opacity: 0.7; margin-bottom: 16px; }
.progress {
    width: 100%; height: 4px; border-radius: 2px;
    background: #2a2f37; overflow: hidden;
}
.progress-bar {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #4fc3f7, #29b6f6);
    transition: width 0.15s ease-out;
}

/* ───── Error overlay ───── */
.error {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(13, 15, 18, 0.92);
    z-index: 60;
}
.error-card {
    max-width: 480px; padding: 24px 28px;
    background: #2a1a1a; border: 1px solid #6e2a2a; border-radius: 8px;
}
.error-title { font-size: 16px; font-weight: 600; color: #ff8a80; margin-bottom: 8px; }
.error-msg { font-size: 13px; opacity: 0.85; line-height: 1.5; word-break: break-all; }

/* ───── HUD (control panel) ───── */
.hud {
    position: fixed;
    top: 16px; right: 16px;
    width: 260px;
    padding: 14px 16px;
    background: rgba(26, 29, 34, 0.92);
    border: 1px solid #2a2f37;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.35);
    backdrop-filter: blur(6px);
    z-index: 10;
    font-size: 12px;
}
.hud hr {
    margin: 12px -16px;
    border: none; border-top: 1px solid #2a2f37;
}
.hud-row {
    display: flex; align-items: center; gap: 6px;
    margin: 4px 0;
}
.hud-title { font-size: 13px; font-weight: 600; }
.dim { opacity: 0.65; }
.badge {
    font-size: 11px;
    background: #2a2f37; color: #b0bec5;
    padding: 2px 6px; border-radius: 3px;
}

.ctrl {
    display: grid;
    grid-template-columns: 64px 1fr 36px;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}
.ctrl > span:first-child { opacity: 0.75; }
.ctrl input[type=range] {
    width: 100%;
    accent-color: #29b6f6;
}
.ctrl-val { text-align: right; font-variant-numeric: tabular-nums; opacity: 0.85; }

.legend {
    display: flex; flex-direction: column; gap: 2px;
}
.legend-row {
    display: grid;
    grid-template-columns: 14px 1fr;
    gap: 8px;
    align-items: center;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.legend-swatch {
    width: 14px; height: 14px;
    border-radius: 2px;
    border: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.legend-header { margin-bottom: 4px; }

.legend-toggle {
    cursor: pointer;
    padding: 2px 4px;
    margin: 0 -4px;
    border-radius: 3px;
    user-select: none;
    transition: background 0.1s;
}
.legend-toggle:hover { background: rgba(255,255,255,0.06); }

.legend-hidden { opacity: 0.35; }
.legend-hidden .legend-swatch {
    background: transparent !important;
    border-style: dashed;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15);
}
.legend-hidden > div:last-child {
    text-decoration: line-through;
    text-decoration-color: rgba(255,255,255,0.5);
}

.legend-actions {
    display: flex !important;
    grid-template-columns: none !important;
    gap: 6px;
    margin-top: 6px;
}
.btn-mini {
    flex: 1;
    padding: 4px 6px;
    background: #2a2f37; color: #cfd8dc;
    border: 1px solid #3a4047; border-radius: 3px;
    font-size: 11px; cursor: pointer;
}
.btn-mini:hover { background: #343a44; }

.btn {
    width: 100%;
    margin: 4px 0;
    padding: 6px 10px;
    background: #2a2f37; color: #e8e8e8;
    border: 1px solid #3a4047; border-radius: 4px;
    font-size: 12px; cursor: pointer;
}
.btn:hover { background: #343a44; }
.btn:active { background: #1f242b; }
