/* --- CORE LAYOUT --- */
body { margin: 0; overflow: hidden; background-color: #0f172a; user-select: none; }

#glCanvas, #canvas2d { 
    position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; 
}
#canvas2d { pointer-events: none; z-index: 10; display: none; } 
#glCanvas { z-index: 0; }

.custom-scroll::-webkit-scrollbar { width: 6px; }
.custom-scroll::-webkit-scrollbar-track { background: #1e293b; }
.custom-scroll::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
.custom-scroll::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* --- TOP BAR UI --- */
.top-bar {
    position: absolute; top: 0; left: 0; width: 100%; height: 50px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    z-index: 40;
    box-sizing: border-box;
}

.bar-group { display: flex; align-items: center; gap: 8px; }

/* --- BUTTON STYLES --- */
.btn-bar {
    pointer-events: auto;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: #e2e8f0;
    padding: 0 16px;
    height: 32px;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1; 
    white-space: nowrap;
}

.btn-bar:hover { transform: translateY(-1px); }
.btn-bar:active { transform: translateY(0px); }

.btn-red { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn-red:hover { background: rgba(239, 68, 68, 0.8); color: white; border-color: #ef4444; }

.btn-green { background: rgba(16, 185, 129, 0.15); border-color: rgba(16, 185, 129, 0.4); color: #6ee7b7; }
.btn-green:hover { background: rgba(16, 185, 129, 0.8); color: white; border-color: #10b981; }

.btn-blue { background: rgba(59, 130, 246, 0.8); border-color: #2563eb; color: white; box-shadow: 0 2px 10px rgba(37, 99, 235, 0.3); }
.btn-blue:hover { background: #1d4ed8; }

.btn-slate { background: rgba(51, 65, 85, 0.5); border-color: rgba(148, 163, 184, 0.3); color: #cbd5e1; }
.btn-slate:hover { background: rgba(71, 85, 105, 0.8); color: white; }

.btn-amber { background: rgba(245, 158, 11, 0.15); border-color: rgba(245, 158, 11, 0.4); color: #fcd34d; }
.btn-amber:hover { background: rgba(245, 158, 11, 0.8); color: white; border-color: #f59e0b; }

.btn-purple { background: rgba(139, 92, 246, 0.15); border-color: rgba(139, 92, 246, 0.4); color: #c4b5fd; }
.btn-purple:hover { background: rgba(139, 92, 246, 0.8); color: white; border-color: #8b5cf6; }

/* --- DROPDOWNS --- */
.dropdown-wrapper { position: relative; }

.dropdown-menu {
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    padding: 8px;
    min-width: 220px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    gap: 4px;
    position: absolute;
    top: 100%; left: 0; 
    margin-top: 8px;
    max-height: 80vh;
    overflow-y: auto;
}

.dropdown-menu.show { display: flex; animation: fadeIn 0.2s ease-out; }

.physics-dropdown {
    width: min(560px, calc(100vw - 24px));
    min-width: min(560px, calc(100vw - 24px));
    overflow-x: hidden;
}

.algorithm-picker { position: relative; }

.algorithm-native-select {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.algorithm-picker-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 7px;
    border: 1px solid rgba(100, 116, 139, 0.75);
    background: rgba(30, 41, 59, 0.9);
    color: #e2e8f0;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.algorithm-picker-button:hover,
.algorithm-picker-button[aria-expanded="true"] {
    border-color: rgba(96, 165, 250, 0.8);
    background: rgba(30, 58, 90, 0.85);
}

.algorithm-picker-copy { display: flex; min-width: 0; flex-direction: column; gap: 1px; }
.algorithm-picker-overline {
    color: #64748b;
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}
#physicsAlgorithmCurrent { overflow: hidden; font-size: 0.76rem; text-overflow: ellipsis; white-space: nowrap; }
.algorithm-picker-current-row {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 6px;
}
.physics-backend-badge {
    flex: 0 0 auto;
    border: 1px solid rgba(96, 165, 250, 0.55);
    border-radius: 999px;
    padding: 1px 5px;
    background: rgba(30, 64, 175, 0.25);
    color: #bfdbfe;
    font-size: 0.52rem;
    font-weight: 800;
    letter-spacing: 0.06em;
}
.physics-backend-badge.is-gpu {
    border-color: rgba(52, 211, 153, 0.65);
    background: rgba(6, 78, 59, 0.35);
    color: #a7f3d0;
}
.physics-backend-badge.is-pending {
    border-color: rgba(251, 191, 36, 0.65);
    background: rgba(120, 53, 15, 0.34);
    color: #fde68a;
}
.algorithm-picker-chevron { color: #93c5fd; transition: transform 0.15s ease; }
.algorithm-picker-button[aria-expanded="true"] .algorithm-picker-chevron { transform: rotate(90deg); }

.physics-backend-control {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(71, 85, 105, 0.58);
}
.physics-backend-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
    color: #94a3b8;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
#physicsBackendStatus {
    max-width: 190px;
    overflow: hidden;
    color: #64748b;
    font-size: 0.54rem;
    font-weight: 600;
    letter-spacing: normal;
    text-align: right;
    text-overflow: ellipsis;
    text-transform: none;
    white-space: nowrap;
}
.physics-backend-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 3px;
    border: 1px solid rgba(71, 85, 105, 0.75);
    border-radius: 8px;
    background: rgba(2, 6, 23, 0.58);
}
.physics-backend-option {
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 5px 8px;
    background: transparent;
    color: #94a3b8;
    font-size: 0.66rem;
    font-weight: 800;
    cursor: pointer;
}
.physics-backend-option:hover:not(:disabled) {
    border-color: rgba(96, 165, 250, 0.45);
    color: #e2e8f0;
}
.physics-backend-option.is-active {
    border-color: rgba(96, 165, 250, 0.78);
    background: rgba(30, 64, 175, 0.42);
    color: #dbeafe;
}
#physicsBackendGpu.is-active {
    border-color: rgba(52, 211, 153, 0.7);
    background: rgba(6, 95, 70, 0.42);
    color: #d1fae5;
}
.physics-backend-option:disabled {
    cursor: not-allowed;
    opacity: 0.42;
}

.algorithm-tree-panel {
    margin-top: 6px;
    width: 100%;
    max-height: min(68vh, 620px);
    overflow-x: hidden;
    overflow-y: auto;
    box-sizing: border-box;
    border: 1px solid rgba(71, 85, 105, 0.75);
    border-radius: 8px;
    background: rgba(2, 6, 23, 0.66);
    padding: 6px;
    overscroll-behavior: contain;
}

.algorithm-tree-graph {
    position: relative;
    min-width: 100%;
    margin: 0 auto;
}

.algorithm-tree-edges {
    position: absolute;
    inset: 0;
    overflow: visible;
    pointer-events: none;
}

.algorithm-tree-edge {
    fill: none;
    stroke: rgba(100, 116, 139, 0.72);
    stroke-width: 1.35;
    vector-effect: non-scaling-stroke;
}

.algorithm-tree-edge.is-active {
    stroke: rgba(96, 165, 250, 0.95);
    stroke-width: 2;
}

.algorithm-tree-arrow-head {
    fill: rgba(100, 116, 139, 0.86);
}

.algorithm-tree-arrow-head-active {
    fill: rgba(96, 165, 250, 1);
}

.algorithm-tree-root-node {
    position: absolute;
    z-index: 2;
    width: 66px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -50%);
    border: 1px solid rgba(96, 165, 250, 0.82);
    border-radius: 999px;
    background: rgba(30, 58, 90, 0.96);
    color: #dbeafe;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.algorithm-tree-choice {
    position: absolute;
    z-index: 3;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 5px 7px;
    box-sizing: border-box;
    overflow: hidden;
    border: 1px solid rgba(71, 85, 105, 0.9);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.96);
    color: #cbd5e1;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(2, 6, 23, 0.42);
    transition:
        border-color 0.15s ease,
        background 0.15s ease,
        color 0.15s ease,
        transform 0.15s ease;
}

.algorithm-tree-choice:hover {
    transform: translate(-50%, -50%) translateY(-1px);
    border-color: rgba(147, 197, 253, 0.72);
    background: rgba(30, 41, 59, 0.98);
    color: white;
}

.algorithm-tree-choice.is-path {
    border-color: rgba(96, 165, 250, 0.52);
    background: rgba(30, 58, 90, 0.72);
}

.algorithm-tree-choice[aria-selected="true"] {
    border-color: rgba(147, 197, 253, 1);
    background: rgba(37, 99, 235, 0.88);
    color: white;
    box-shadow:
        0 0 0 2px rgba(37, 99, 235, 0.26),
        0 4px 14px rgba(30, 64, 175, 0.45);
}

.algorithm-tree-label {
    display: -webkit-box;
    overflow: hidden;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.08;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.algorithm-tree-change {
    display: -webkit-box;
    overflow: hidden;
    color: #64748b;
    font-size: 0.55rem;
    line-height: 1.08;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.algorithm-tree-choice.is-path .algorithm-tree-change {
    color: #94a3b8;
}

.algorithm-tree-choice[aria-selected="true"] .algorithm-tree-change {
    color: #dbeafe;
}

.algorithm-tree-graph.is-compact .algorithm-tree-change {
    display: none;
}

.algorithm-tree-graph.is-compact .algorithm-tree-label {
    -webkit-line-clamp: 3;
}

@media (max-width: 760px) {
    .physics-dropdown {
        position: fixed;
        top: 50px;
        left: 12px;
        right: 12px;
        width: auto;
        min-width: 0;
        max-height: calc(100vh - 64px);
        margin-top: 8px;
    }
}

/* --- MENU CONNECTOR LINE (CONTAINER) --- */
#menuConnector {
    position: fixed;
    height: 2px;
    background-color: transparent; /* Container is invisible */
    transform-origin: 0 50%; /* Grow from left */
    z-index: 45; /* Below menu, above canvas */
    pointer-events: none;
    display: none;
    /* No transitions here! We snap this to the atom position every frame. */
}

/* --- MENU CONNECTOR LINE (VISUAL) --- */
#menuConnector::after {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    background-color: rgba(30, 41, 59, 0.95);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
    transform-origin: 0 50%;
    transform: scaleX(0); /* Start hidden */
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Trigger class for animation */
#menuConnector.visible::after {
    transform: scaleX(1);
}

/* --- CONTEXT MENU (Right Click) --- */
.context-menu {
    position: absolute;
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 12px;
    padding: 12px;
    min-width: 260px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    color: #e2e8f0;
    font-family: 'Inter', sans-serif;
    z-index: 50;
    
    /* Animation Hooks */
    transform-origin: 0 0;
    transition: 
        opacity 0.2s ease,
        transform 0.2s cubic-bezier(0.2, 1.1, 0.2, 1);
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    display: none;
}

.context-menu.active {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.menu-header {
    font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: #94a3b8; margin-bottom: 8px; padding-bottom: 8px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1); font-weight: 600;
}

.menu-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 8px; border-radius: 6px; cursor: default;
    transition: background 0.2s; font-size: 0.9rem;
    background: transparent; border: none; color: #e2e8f0; text-align: left;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.05); }

/* --- HELP MODAL --- */
.help-overlay {
    display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 90; backdrop-filter: blur(2px);
}
.help-modal {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.98); border: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5); padding: 24px; border-radius: 12px;
    width: 450px; z-index: 100; color: #e2e8f0; font-family: 'Inter', sans-serif;
}
.help-modal h2 { margin-top: 0; color: #60a5fa; font-size: 1.2rem; margin-bottom: 16px; border-bottom: 1px solid #334155; padding-bottom: 8px;}
.help-row { margin-bottom: 10px; font-size: 0.9rem; display: flex; justify-content: space-between; }
.help-key { font-weight: bold; color: #94a3b8; }
.close-help { position: absolute; top: 16px; right: 16px; background: none; border: none; color: #64748b; cursor: pointer; font-size: 1.2rem; }
.close-help:hover { color: white; }

/* --- NODE LABELS --- */
.node-labels-container {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; overflow: hidden; z-index: 20;
}
.node-label {
    position: absolute;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 4px; padding: 4px 6px;
    font-family: monospace; font-size: 10px; color: #e2e8f0;
    white-space: pre; transform: translate(-50%, -50%);
    pointer-events: none; z-index: 10;
    text-shadow: 0 1px 2px black; box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* --- DIAGRAM PANEL --- */
.diagram-panel {
    position: absolute; top: 60px; right: 20px;
    width: 400px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px; padding: 16px;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
    display: none; animation: slideIn 0.3s ease-out;
    color: #e2e8f0; font-family: 'Inter', sans-serif; z-index: 30;
}

/* --- Small Panel Buttons --- */
.btn-xs {
    background: rgba(51, 65, 85, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: #cbd5e1;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-xs:hover { background: rgba(71, 85, 105, 0.8); color: white; }
.btn-xs.active { background: #2563eb; border-color: #2563eb; color: white; }

/* --- ANIMATIONS --- */
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* --- FORM ELEMENTS --- */
input[type=range] {
    width: 100%; height: 4px; background: #475569;
    border-radius: 2px; appearance: none; outline: none; margin: 8px 0;
}
input[type=range]::-webkit-slider-thumb {
    appearance: none; width: 16px; height: 16px;
    background: #3b82f6; border-radius: 50%; cursor: pointer;
}

/* --- EDITOR STYLES --- */
#editorOverlay.hidden { display: none; }
#editorOverlay { animation: fadeIn 0.2s ease-out; }
.type-btn.active { background-color: #2563eb; color: white; }
.type-btn:not(.active):hover { background-color: #334155; color: #e2e8f0; }
#editorContainer { touch-action: none; }
#editorContainer canvas {
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
}

.editor-mode-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 72px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid rgba(96, 165, 250, 0.62);
    border-radius: 8px;
    background: rgba(30, 41, 59, 0.94);
    color: #bfdbfe;
    font-size: 0.75rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease,
        color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.editor-mode-toggle:hover {
    border-color: #60a5fa;
    background: rgba(37, 99, 235, 0.22);
    color: white;
    transform: translateY(-1px);
}

.editor-mode-toggle.is-3d {
    border-color: rgba(167, 139, 250, 0.82);
    background: rgba(109, 40, 217, 0.28);
    color: #ede9fe;
    box-shadow: 0 3px 12px rgba(109, 40, 217, 0.22);
}

.editor-mode-toggle.is-transitioning .editor-mode-glyph {
    animation: editorModeSpin 0.52s ease-in-out;
}

.editor-mode-glyph { font-size: 1rem; line-height: 1; }

@keyframes editorModeSpin {
    from { transform: rotateY(0deg); }
    to { transform: rotateY(180deg); }
}

.editor-tool-unavailable {
    opacity: 0.28 !important;
    cursor: not-allowed !important;
}

.editor-view-btn {
    height: 25px;
    padding: 0 9px;
    border: 1px solid rgba(71, 85, 105, 0.8);
    border-radius: 6px;
    background: rgba(30, 41, 59, 0.92);
    color: #cbd5e1;
    font-size: 0.68rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.editor-view-btn:hover {
    border-color: rgba(96, 165, 250, 0.75);
    background: rgba(51, 65, 85, 0.98);
    color: white;
}

.editor-history-controls {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 22;
    display: flex;
    align-items: stretch;
    gap: 5px;
}

.editor-history-action,
.editor-history-toggle {
    height: 44px;
    border: 1px solid rgba(71, 85, 105, 0.9);
    border-radius: 7px;
    background: rgba(15, 23, 42, 0.9);
    color: #e2e8f0;
    box-shadow: 0 5px 15px rgba(2, 6, 23, 0.3);
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: border-color 0.15s ease, background 0.15s ease,
        color 0.15s ease, opacity 0.15s ease;
}

.editor-history-action {
    width: 104px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 2px;
    padding: 4px 8px;
    text-align: left;
}

.editor-history-action:not(:disabled):hover,
.editor-history-toggle:hover,
.editor-history-toggle.is-open {
    border-color: rgba(96, 165, 250, 0.82);
    background: rgba(30, 41, 59, 0.97);
    color: white;
}

.editor-history-action.is-disabled {
    opacity: 0.48;
    cursor: not-allowed;
}

.editor-history-action-title {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
}

.editor-history-action-title > span {
    color: #93c5fd;
    font-size: 0.92rem;
}

.editor-history-action-hint {
    display: block;
    width: 100%;
    overflow: hidden;
    color: #94a3b8;
    font-size: 0.58rem;
    font-weight: 650;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-history-action-hint[data-kind="add"] { color: #6ee7b7; }
.editor-history-action-hint[data-kind="delete"] { color: #fca5a5; }
.editor-history-action-hint[data-kind="move"],
.editor-history-action-hint[data-kind="bond"] { color: #93c5fd; }
.editor-history-action-hint[data-kind="stereo"] { color: #c4b5fd; }

.editor-history-menu-wrap { position: static; }

.editor-history-toggle {
    width: 92px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-content: center;
    align-items: center;
    column-gap: 5px;
    padding: 4px 8px;
    text-align: left;
    font-size: 0.68rem;
    font-weight: 800;
}

.editor-history-count {
    grid-column: 1;
    grid-row: 2;
    color: #94a3b8;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.57rem;
    font-weight: 600;
}

.editor-history-chevron {
    grid-column: 2;
    grid-row: 1 / 3;
    color: #94a3b8;
    transition: transform 0.15s ease;
}

.editor-history-toggle.is-open .editor-history-chevron { transform: rotate(180deg); }

.editor-history-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: min(374px, calc(100vw - 48px));
    overflow: hidden;
    border: 1px solid rgba(71, 85, 105, 0.95);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.98);
    box-shadow: 0 18px 44px rgba(2, 6, 23, 0.72);
    backdrop-filter: blur(14px);
    animation: fadeIn 0.14s ease-out;
}

.editor-history-menu[hidden] { display: none; }

.editor-history-menu-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 11px 8px;
    border-bottom: 1px solid rgba(51, 65, 85, 0.72);
    color: #e2e8f0;
    font-size: 0.72rem;
    font-weight: 800;
}

.editor-history-menu-header > span:last-child {
    color: #64748b;
    font-size: 0.57rem;
    font-weight: 600;
}

.editor-history-list {
    max-height: 398px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 6px;
    overscroll-behavior: contain;
    scrollbar-color: #475569 transparent;
    scrollbar-width: thin;
}

.editor-history-entry {
    position: relative;
    width: 100%;
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 9px;
    min-height: 72px;
    padding: 5px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: #cbd5e1;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.14s ease, background 0.14s ease,
        opacity 0.14s ease;
}

.editor-history-entry + .editor-history-entry { margin-top: 4px; }
.editor-history-entry:hover,
.editor-history-entry:focus-visible {
    border-color: rgba(96, 165, 250, 0.5);
    background: rgba(51, 65, 85, 0.58);
    outline: none;
}

.editor-history-entry.is-current {
    border-color: rgba(96, 165, 250, 0.8);
    background: rgba(37, 99, 235, 0.14);
}

.editor-history-entry.is-future { opacity: 0.67; }
.editor-history-entry.is-future:hover,
.editor-history-entry.is-future:focus-visible { opacity: 1; }

.editor-history-preview {
    width: 112px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid rgba(71, 85, 105, 0.72);
    border-radius: 6px;
    background: #0f172a;
}

.editor-history-preview img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.editor-history-preview-placeholder {
    color: #64748b;
    font-size: 0.62rem;
    font-weight: 700;
}

.editor-history-entry-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.editor-history-entry-label {
    overflow: hidden;
    color: #e2e8f0;
    font-size: 0.7rem;
    font-weight: 750;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-history-entry[data-kind="add"] .editor-history-entry-label { color: #a7f3d0; }
.editor-history-entry[data-kind="delete"] .editor-history-entry-label { color: #fecaca; }
.editor-history-entry[data-kind="stereo"] .editor-history-entry-label { color: #ddd6fe; }

.editor-history-entry-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #64748b;
    font-size: 0.57rem;
    font-weight: 650;
}

.editor-history-mode {
    padding: 1px 5px;
    border: 1px solid rgba(96, 165, 250, 0.38);
    border-radius: 999px;
    color: #93c5fd;
    font-size: 0.52rem;
    letter-spacing: 0.04em;
}

.editor-history-mode.is-3d {
    border-color: rgba(167, 139, 250, 0.46);
    color: #c4b5fd;
}

.editor-history-entry-state {
    color: #60a5fa;
    font-size: 0.54rem;
    font-weight: 800;
    text-align: right;
    text-transform: uppercase;
}

.editor-history-entry.is-future .editor-history-entry-state { color: #a78bfa; }

#editorStatus { top: 62px; }

.editor-gesture-counter {
    position: absolute;
    z-index: 45;
    max-width: 260px;
    padding: 6px 9px;
    border: 1px solid rgba(103, 232, 249, 0.58);
    border-radius: 999px;
    background: rgba(2, 6, 23, 0.9);
    box-shadow: 0 8px 24px rgba(2, 6, 23, 0.42);
    color: #cffafe;
    font: 750 0.68rem/1.2 ui-monospace, SFMono-Regular, Menlo, Monaco,
        Consolas, monospace;
    letter-spacing: 0.01em;
    pointer-events: none;
    white-space: nowrap;
    backdrop-filter: blur(8px);
}

.editor-gesture-counter.is-invalid {
    border-color: rgba(248, 113, 113, 0.7);
    color: #fecaca;
}

.editor-tools-disabled {
    opacity: 0.34;
    filter: saturate(0.35);
    pointer-events: none;
}

#editorToolbars { transition: opacity 0.18s ease, filter 0.18s ease; }
#editorOverlay h2 { flex-shrink: 0; white-space: nowrap; }
.editor-3d #editorHelp { color: #64748b; }

@media (max-width: 900px) {
    #editorOverlay > div {
        max-height: calc(100vh - 1rem);
        overflow-y: auto;
    }

    #editorOverlay > div > div:first-child {
        align-items: flex-start;
        gap: 12px;
        flex-direction: column;
    }

    #editorToolbars {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }

    #editorContainer { height: min(540px, 58vh); }
}

@media (max-width: 620px) {
    .editor-history-action { width: 86px; padding-inline: 7px; }
    .editor-history-toggle { width: 82px; }
    .editor-history-entry {
        grid-template-columns: 96px minmax(0, 1fr) 40px;
        gap: 7px;
    }
    .editor-history-preview { width: 96px; height: 58px; }
}

#loading {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #94a3b8; font-family: sans-serif;
    pointer-events: none; transition: opacity 0.5s; z-index: 100;
}
