/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

:root {
    --user-nav-offset: 70px;
    --menu-bar-height: 52px;
    --toolbar-height: 52px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1e1e1e;
    color: #e0e0e0;
    /* overflow: hidden; */ /* Let the body scroll if needed */
    font-size: 16px;
}



/* App Container */
#app-container {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--user-nav-offset));
    height: calc(100vh - var(--user-nav-offset));
    width: 100vw;
    padding-top: var(--user-nav-offset); /* Account for fixed user-info navbar height */
}

/* Menu Bar */
#menu-bar {
    background: #2d2d30;
    padding: 0.5rem;
    border-bottom: 1px solid #3e3e42;
    display: flex;
    gap: 0.5rem;
    height: var(--menu-bar-height);
    align-items: center;
}

.menu-group {
    display: flex;
    gap: 0.25rem;
}

.menu-btn {
    background: transparent;
    border: none;
    color: #e0e0e0;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    font-size: 16px;
    border-radius: 3px;
    transition: background 0.2s;
}

.menu-btn:hover {
    background: #3e3e42;
}

.menu-btn.active {
    background: #094771;
}

/* Dropdown Menus */
.dropdown-menu {
    display: none;
    position: absolute;
    background: #2d2d30;
    border: 1px solid #3e3e42;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    min-width: 200px;
    z-index: 1000;
    border-radius: 3px;
}

.dropdown-menu.show {
    display: block;
}

.menu-item {
    padding: 0.7rem 1.1rem;
    cursor: pointer;
    font-size: 15px;
    transition: background 0.15s;
}

.menu-item:hover {
    background: #094771;
}

.menu-separator {
    height: 1px;
    background: #3e3e42;
    margin: 0.25rem 0;
}

/* Toolbar */
#toolbar {
    background: #2d2d30;
    padding: 0.5rem;
    border-bottom: 1px solid #3e3e42;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    height: var(--toolbar-height);
}

.tool-btn {
    background: #3e3e42;
    border: none;
    color: #e0e0e0;
    padding: 0.6rem 1.1rem;
    cursor: pointer;
    font-size: 20px;
    border-radius: 3px;
    transition: background 0.2s;
}

.tool-btn:hover {
    background: #094771;
}

.tool-btn:active {
    background: #063b5c;
}

.separator {
    width: 1px;
    height: 24px;
    background: #3e3e42;
}

/* Content Container */
#content-container {
    display: flex;
    flex: 1;
    overflow: hidden; /* Prevent spillover outside app bounds */
    min-height: 0; /* Allow flex item to shrink below content size */
    height: calc(100vh - var(--user-nav-offset) - var(--menu-bar-height) - var(--toolbar-height));
    max-height: calc(100vh - var(--user-nav-offset) - var(--menu-bar-height) - var(--toolbar-height));
}

/* Viewport */
#viewport-container {
    flex: 1;
    position: relative;
    background: #000;
    min-width: 400px; /* Prevent viewport from shrinking too much and squeezing sidebar */
    min-height: 100%;
    overflow: hidden; /* Ensure canvas doesn't overflow container */
    /* Padding handled by canvas positioning logic instead */
}

#three-canvas {
    /* Width and height are set dynamically by JavaScript to maintain aspect ratio */
    /* Position is set to absolute by JavaScript for centering with letterboxing */
    display: block;
    z-index: 1;
}

#viewport-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.6);
    padding: 0.5rem;
    border-radius: 3px;
    font-size: 12px;
    line-height: 1.3;
    max-width: 320px;
    pointer-events: none;
    z-index: 10;
}

/* Pose mode layout adjustments */
body.pose-mode .menu-btn[data-menu="edit"],
body.pose-mode .menu-btn[data-menu="geometry"],
body.pose-mode .menu-btn[data-menu="settings"] {
    display: none;
}

body.pose-mode #side-panel {
    padding: 0; /* Remove padding - let sections handle their own spacing */
    display: flex;
    flex-direction: column;
    gap: 0; /* Remove gap - sections handle spacing */
    overflow-y: auto;
    overflow-x: hidden;
    align-self: stretch; /* Take full height of parent flex container */
    min-height: 0; /* CRITICAL: Allow overflow calculation */
    height: 100%;
    max-height: 100%;
    scrollbar-gutter: stable both-edges;
    overscroll-behavior: contain;
}

body.pose-mode .pose-sidebar-section {
    background: #1e1e1e;
    border: 1px solid #2c2c2c;
    border-radius: 0; /* Remove border radius for seamless edge-to-edge */
    border-left: none; /* Remove left border */
    border-right: none; /* Remove right border */
    border-top: none; /* Remove top border for first item */
    padding: 1.25rem; /* Consistent internal padding */
    padding-bottom: 2rem; /* Extra bottom padding for last item */
    transition: all 0.2s ease;
    /* NO flex-shrink: 0 - allow natural overflow for scroll activation */
}

body.pose-mode .pose-sidebar-section.drag-over {
    background: #2a3a2a;
    border: 2px dashed #4caf50;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.3);
}

#ai-gen-dialog.drag-over {
    background: #2a3a2a;
    border: 2px dashed #4caf50;
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.5);
}

body.pose-mode .pose-sidebar-section h3 {
    margin-top: 0;
    margin-bottom: 0.75rem;
    font-size: 1.3rem;
    color: #f0f0f0;
}

body.pose-mode .section-intro {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    color: #ccc;
}

body.pose-mode .shortcut-list {
    list-style: none;
    padding: 0;
    margin: 0 0 0.75rem 0;
    font-size: 0.95rem;
    color: #ddd;
}

body.pose-mode .shortcut-list li {
    margin-bottom: 0.45rem;
    line-height: 1.4;
}

body.pose-mode .shortcut-key {
    display: inline-block;
    background: #333;
    color: #ffa500;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    margin-right: 0.4rem;
}

body.pose-mode .hint-text {
    font-size: 0.95rem;
    color: #999;
    margin: 0;
}

body.pose-mode #ai-panel textarea {
    width: 100%;
    resize: vertical;
    min-height: 120px;
    background: #1a1a1a;
    border: 1px solid #333;
    color: #f5f5f5;
    border-radius: 4px;
    padding: 0.6rem;
    font-size: 0.95rem;
}

body.pose-mode .button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

body.pose-mode .primary-btn,
body.pose-mode .secondary-btn {
    padding: 0.6rem 1rem;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 1.05rem;
    background: #2a2a2a;
    color: #f5f5f5;
}

body.pose-mode .primary-btn {
    background: #4caf50;
    border-color: #4caf50;
    color: #fff;
}

body.pose-mode .primary-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

body.pose-mode .secondary-btn {
    background: #1f1f1f;
    border-color: #3a3a3a;
}

body.pose-mode .checkbox-inline {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: #ccc;
}

body.pose-mode .status-block {
    margin-top: 0.85rem;
    padding: 0.6rem;
    background: #1b1b1b;
    border: 1px solid #2d2d2d;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #e0e0e0;
    min-height: 2.4rem;
}

body.pose-mode #ai-inline-result {
    display: none;
    margin-top: 0.85rem;
    max-width: 100%;
    border-radius: 4px;
    border: 1px solid #2d2d2d;
}

body.pose-mode #ai-inline-download {
    display: none;
    margin-top: 0.75rem;
    padding: 0.5rem 0.85rem;
    background: #1976d2;
    color: #fff;
    text-decoration: none;
    text-align: center;
    border-radius: 4px;
}

body.pose-mode #ai-inline-download:hover {
    background: #1e88e5;
}

#frame-counter,
#fps-counter {
    margin: 0.25rem 0;
}

/* Left Panel */
#left-panel {
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    scrollbar-gutter: stable both-edges;
    overscroll-behavior: contain;
}

/* Side Panel */
#side-panel {
    width: 320px;
    background: #252526;
    border-left: 1px solid #3e3e42;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0; /* Don't allow sidebar to shrink, maintaining AI panel layout */
    align-self: stretch; /* Take full height of parent flex container */
    min-height: 0; /* CRITICAL: Allow overflow calculation */
    height: 100%;
    max-height: 100%;
    scrollbar-gutter: stable both-edges;
    overscroll-behavior: contain;
}

/* Tab Navigation */
#tab-nav {
    display: flex;
    background: #2d2d30;
    border-bottom: 1px solid #3e3e42;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: #e0e0e0;
    padding: 0.75rem;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: #2a2a2d;
}

.tab-btn.active {
    background: #252526;
    border-bottom-color: #0e639c;
}

/* Tab Content */
#tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.tab-pane h3 {
    margin-bottom: 1rem;
    font-size: 16px;
    color: #4ec9b0;
}

/* Control Groups */
.control-group {
    margin-bottom: 1.5rem;
}

.control-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 15px;
    color: #9cdcfe;
}

.control-group input[type="range"] {
    width: 100%;
    margin: 0.5rem 0;
}

.control-group input[type="number"],
.control-group input[type="text"],
.control-group select {
    width: 100%;
    background: #3e3e42;
    border: 1px solid #555;
    color: #e0e0e0;
    padding: 0.6rem;
    border-radius: 3px;
    font-size: 15px;
}

.control-group input[type="checkbox"] {
    margin-right: 0.5rem;
}

.control-group button {
    background: #0e639c;
    border: none;
    color: #fff;
    padding: 0.7rem 1.1rem;
    cursor: pointer;
    border-radius: 3px;
    font-size: 15px;
    width: 100%;
    transition: background 0.2s;
}

.control-group button:hover {
    background: #1177bb;
}

.control-group button:active {
    background: #0d5a8f;
}

.button-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.button-row button {
    flex: 1;
    min-width: 80px;
}

.input-row {
    display: flex;
    gap: 0.5rem;
}

.input-row > div {
    flex: 1;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.radio-group label {
    display: flex;
    align-items: center;
    margin: 0;
}

/* Lists */
#object-list,
#pose-list,
#geo-object-list {
    max-height: 200px;
    overflow-y: auto;
    background: #1e1e1e;
    border: 1px solid #3e3e42;
    border-radius: 3px;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
}

.object-item,
.pose-item,
.geo-item {
    padding: 0.5rem;
    margin: 0.25rem 0;
    background: #2d2d30;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 13px;
}

.object-item:hover,
.pose-item:hover,
.geo-item:hover {
    background: #3e3e42;
}

.object-item.selected,
.pose-item.selected,
.geo-item.selected {
    background: #094771;
}

.object-item input[type="checkbox"] {
    margin: 0;
}

.object-item label {
    margin: 0;
    cursor: pointer;
    flex: 1;
}

/* Status Bar */
#status-bar {
    background: #007acc;
    color: #fff;
    padding: 0.4rem 1rem;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    border-top: 1px solid #0e639c;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #1e1e1e;
}

::-webkit-scrollbar-thumb {
    background: #3e3e42;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Range Input Styling */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: #3e3e42;
    outline: none;
    border-radius: 3px;
    height: 6px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #0e639c;
    cursor: pointer;
    border-radius: 50%;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #0e639c;
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #1177bb;
}

/* Tooltips */
[title] {
    position: relative;
}



/* Responsive Design */
@media (max-width: 1024px) {
    #side-panel {
        width: 280px;
    }
}

@media (max-width: 768px) {
    #side-panel {
        position: absolute;
        right: -320px;
        height: calc(100vh - 100px);
        transition: right 0.3s;
        z-index: 100;
    }

    #side-panel.open {
        right: 0;
    }
}

/* Loading Indicator */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    border: 4px solid #3e3e42;
    border-top: 4px solid #0e639c;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error Messages */
.error-message {
    background: #f44336;
    color: #fff;
    padding: 1rem;
    border-radius: 3px;
    margin: 1rem 0;
    font-size: 14px;
}

.success-message {
    background: #4caf50;
    color: #fff;
    padding: 1rem;
    border-radius: 3px;
    margin: 1rem 0;
    font-size: 14px;
}

.warning-message {
    background: #ff9800;
    color: #fff;
    padding: 1rem;
    border-radius: 3px;
    margin: 1rem 0;
    font-size: 14px;
}

/* AI Studio Improvements */
#ai-video-studio-content,
#ai-image-studio-content {
    /* NO max-height - let content determine height naturally */
    /* NO overflow-y - parent #side-panel handles scrolling */
    overflow-x: hidden;
    padding-right: 8px;
}

/* Constrain video reference preview image */
#ai-video-ref-preview img {
    max-height: 120px;
    object-fit: contain;
    width: 100%;
}

/* Generation History Panel */
#generation-history-panel {
    background: #1e1e1e;
    border: 1px solid #2c2c2c;
    border-radius: 6px;
    margin-top: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
}

#generation-history-panel.collapsed #history-content {
    display: none;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #252525;
    border-bottom: 1px solid #2c2c2c;
    cursor: pointer;
    user-select: none;
}

.history-header h4 {
    margin: 0;
    font-size: 0.9em;
    color: #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.history-toggle {
    font-size: 0.8em;
    color: #888;
    transition: transform 0.3s ease;
}

#generation-history-panel.collapsed .history-toggle {
    transform: rotate(-90deg);
}

.history-controls {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: #1a1a1a;
    border-bottom: 1px solid #2c2c2c;
}

.history-controls button {
    flex: 1;
    padding: 6px;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    transition: background 0.2s;
}

.history-controls button:hover {
    background: #333;
}

#history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    padding: 12px;
    /* NO max-height - let content determine height naturally */
    /* NO overflow-y - parent #side-panel handles scrolling */
}

/* Mobile responsive grid */
@media (max-width: 600px) {
    #history-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        gap: 6px;
    }
}

.history-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    background: #2a2a2a;
}

.history-item:hover,
.history-item:focus {
    border-color: #4CAF50;
    transform: scale(1.05);
    outline: none;
}

/* Expiration warning states */
.history-item.expiring-warning {
    border-color: rgba(255, 165, 0, 0.4);
}

.history-item.expiring-soon {
    border-color: rgba(255, 107, 107, 0.6);
}

.history-item.expiring-warning:hover,
.history-item.expiring-warning:focus {
    border-color: #ffa500;
}

.history-item.expiring-soon:hover,
.history-item.expiring-soon:focus {
    border-color: #ff6b6b;
}

.history-item img,
.history-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-item-type {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.7em;
    pointer-events: none;
}

/* Timestamp badge */
.history-item-timestamp {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: #ccc;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.65em;
    pointer-events: none;
}

/* Expiration warning badge */
.history-item-expiration {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 107, 107, 0.95);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7em;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Storage indicator */
#history-storage-indicator {
    font-size: 0.75em;
    color: #888;
    padding: 6px 12px;
    text-align: center;
    background: #1a1a1a;
    border-top: 1px solid #2c2c2c;
}

.history-item-instruction {
    position: absolute;
    left: 50%;
    bottom: 8px;
    transform: translateX(-50%) translateY(10px);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    max-width: 90%;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

.history-item:hover .history-item-instruction,
.history-item:focus .history-item-instruction {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.history-instruction-arrow {
    font-size: 1.5em;
    line-height: 1;
}

.history-instruction-text {
    font-weight: 600;
    letter-spacing: 0.05em;
}

#history-empty {
    text-align: center;
    padding: 24px 12px;
    color: #666;
    font-size: 0.85em;
}

/* Smooth scrollbar styling */
#ai-video-studio-content::-webkit-scrollbar,
#ai-image-studio-content::-webkit-scrollbar,
#history-grid::-webkit-scrollbar {
    width: 8px;
}

#ai-video-studio-content::-webkit-scrollbar-track,
#ai-image-studio-content::-webkit-scrollbar-track,
#history-grid::-webkit-scrollbar-track {
    background: #1a1a1a;
    border-radius: 4px;
}

#ai-video-studio-content::-webkit-scrollbar-thumb,
#ai-image-studio-content::-webkit-scrollbar-thumb,
#history-grid::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

#ai-video-studio-content::-webkit-scrollbar-thumb:hover,
#ai-image-studio-content::-webkit-scrollbar-thumb:hover,
#history-grid::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Viewport Button Styling */
.viewport-btn {
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 1.1em;
    border-radius: 6px;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.viewport-btn:hover {
    background: rgba(30, 30, 30, 0.85);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.viewport-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Hide frame and FPS counters */
#frame-counter,
#fps-counter {
    display: none;
}

/* History Drawer Floating Panel */
.history-drawer {
    position: fixed;
    top: 0;
    right: -500px;
    width: 500px;
    height: 100vh;
    background: rgba(20, 20, 20, 0.98);
    backdrop-filter: blur(10px);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.history-drawer.open {
    right: 0;
}

.history-drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(30, 30, 30, 0.9);
}

.history-drawer-header h3 {
    color: #fff;
}

.history-drawer-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s ease;
}

.history-drawer-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.history-drawer-close {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.history-drawer-close:hover {
    background: rgba(244, 67, 54, 0.2);
    border-color: #f44336;
}

.history-drawer-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
}

.history-drawer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.history-drawer-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: #888;
}

.history-drawer-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(30, 30, 30, 0.9);
}

/* History drawer items with drag support */
.history-drawer-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: grab;
    border: 2px solid transparent;
    transition: all 0.2s;
    background: #2a2a2a;
}

.history-drawer-item:hover {
    border-color: #4CAF50;
    transform: scale(1.05);
    overflow: visible;
}

.history-drawer-item:active {
    cursor: grabbing;
}

.history-drawer-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.history-drawer-item img,
.history-drawer-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.history-drawer-item-type {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 600;
    pointer-events: none;
}

.history-drawer-item-instruction {
    bottom: auto;
    top: 100%;
    margin-top: 10px;
    transform: translate(-50%, 10px);
    background: rgba(0, 0, 0, 0.85);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}

.history-drawer-item:hover .history-drawer-item-instruction,
.history-drawer-item:focus .history-drawer-item-instruction {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Drag drop zones highlight */
#ai-image-thumbnails.drag-over,
#ai-video-ref-preview.drag-over {
    background: rgba(76, 175, 80, 0.2) !important;
    border-color: #4CAF50 !important;
    border-style: solid !important;
}

/* History Thumbnail Strip */
#history-strip {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Scrollbar for grid */
#history-strip-grid::-webkit-scrollbar {
    width: 6px;
}

#history-strip-grid::-webkit-scrollbar-track {
    background: transparent;
}

#history-strip-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}


#viewport-button-primary,
#viewport-button-secondary,
#viewport-button-tertiary {
    position: absolute;
    display: none;
    --viewport-shadow-base: 0, 0, 0;
    align-items: center;
    gap: 6px;
    padding: 0.45rem 1rem;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    z-index: 120;
    pointer-events: auto;
    transform: translate(-50%, -50%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
    backdrop-filter: blur(6px);
    border: 2px solid rgba(255, 255, 255, 0.35);
}

#viewport-button-primary .icon,
#viewport-button-secondary .icon,
#viewport-button-tertiary .icon {
    font-size: 18px;
    line-height: 1;
}

#viewport-button-primary .label,
#viewport-button-secondary .label,
#viewport-button-tertiary .label {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

@keyframes viewportGradientShift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

@keyframes viewportButtonGlow {
    0% {
        filter: saturate(1) brightness(1);
        box-shadow: 0 10px 28px rgba(var(--viewport-shadow-base, 0, 0, 0), 0.42);
    }
    50% {
        filter: saturate(1.25) brightness(1.08);
        box-shadow: 0 14px 34px rgba(var(--viewport-shadow-base, 0, 0, 0), 0.72);
    }
    100% {
        filter: saturate(1.08) brightness(1.02);
        box-shadow: 0 11px 30px rgba(var(--viewport-shadow-base, 0, 0, 0), 0.48);
    }
}

#viewport-button-primary.active,
#viewport-button-secondary.active,
#viewport-button-tertiary.active {
    background-size: 185% 185%;
    background-position: 50% 50%;
    animation: viewportGradientShift 6s ease-in-out infinite, viewportButtonGlow 1.6s ease-in-out infinite alternate;
}

#viewport-button-primary {
    background-image: none;
    background-color: rgba(0, 0, 0, 0.78);
    border-color: rgba(255, 255, 255, 0.42);
    color: #ffffff;
    text-shadow: none;
}

#viewport-button-primary.active {
    background-image: linear-gradient(135deg, rgba(255, 205, 90, 1), rgba(255, 140, 30, 1));
    border-color: rgba(255, 235, 200, 1);
    box-shadow: 0 10px 28px rgba(255, 140, 30, 0.52);
    --viewport-shadow-base: 255, 140, 30;
}

#viewport-button-secondary {
    background-image: none;
    background-color: rgba(0, 0, 0, 0.78);
    border-color: rgba(255, 255, 255, 0.42);
    color: #ffffff;
}

#viewport-button-secondary.active {
    background-image: linear-gradient(135deg, rgba(80, 205, 255, 1), rgba(35, 150, 230, 1));
    border-color: rgba(195, 240, 255, 1);
    box-shadow: 0 10px 28px rgba(35, 150, 230, 0.52);
    --viewport-shadow-base: 35, 150, 230;
}

#viewport-button-tertiary {
    background-image: none;
    background-color: rgba(0, 0, 0, 0.78);
    border-color: rgba(255, 255, 255, 0.42);
    color: #ffffff;
}

#viewport-button-tertiary.active {
    background-image: linear-gradient(135deg, rgba(215, 205, 255, 1), rgba(160, 150, 255, 1));
    border-color: rgba(238, 232, 255, 1);
    box-shadow: 0 10px 28px rgba(120, 110, 245, 0.5);
    --viewport-shadow-base: 120, 110, 245;
}

#viewport-button-primary:hover,
#viewport-button-secondary:hover,
#viewport-button-tertiary:hover {
    transform: translate(-50%, -50%) scale(1.07);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48);
}

#viewport-button-primary:active,
#viewport-button-secondary:active,
#viewport-button-tertiary:active {
    transform: translate(-50%, -50%) scale(0.98);
}

#history-strip-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Make scrollbar overlay instead of taking up space */
#history-strip-grid {
    scrollbar-gutter: stable;
}

/* History Strip Thumbnails */
.history-strip-item {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 6px;
    overflow: hidden;
    cursor: grab;
    border: 2px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    background: #2a2a2a;
    flex-shrink: 0;
    pointer-events: auto; /* Re-enable pointer events for interactive thumbnails */
}

.history-strip-item:hover {
    transform: scale(2.5) translateX(-15px);
    border-color: #4CAF50;
    z-index: 9999;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    overflow: visible;
    position: relative;
}

.history-strip-item:active {
    cursor: grabbing;
}

.history-strip-item.dragging {
    opacity: 0.5;
}

.history-strip-item img,
.history-strip-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    border-radius: 4px;
}

.history-strip-item-type {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.6em;
    font-weight: 600;
    pointer-events: none;
}

/* Show instruction callout on hover for enlarged items */
.history-strip-item-instruction {
    bottom: auto;
    top: 100%;
    margin-top: 12px;
    transform: translate(-50%, 12px);
    background: rgba(0, 0, 0, 0.9);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
    padding: 8px 12px;
}

.history-strip-item:hover .history-strip-item-instruction,
.history-strip-item:focus .history-strip-item-instruction {
    opacity: 1;
    transform: translate(-50%, 0);
}


/* Admin overlay */
.admin-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.78);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    backdrop-filter: blur(4px);
}

.admin-modal {
    width: min(520px, 90vw);
    background: #181818;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.admin-modal-header,
.admin-modal-footer {
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.admin-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #f3f3f3;
}

.admin-close {
    background: transparent;
    color: #ddd;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    width: 34px;
    height: 34px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.admin-close:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.admin-modal-body {
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.admin-help {
    margin: 0;
    font-size: 0.95rem;
    color: #d0d0d0;
    line-height: 1.5;
}

.admin-primary-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #35b3ff, #1a7be6);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 6px 18px rgba(26, 123, 230, 0.35);
}

.admin-primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 9px 24px rgba(26, 123, 230, 0.48);
}

.admin-status {
    min-height: 1.2rem;
    font-size: 0.9rem;
    color: #bbb;
}

.admin-status.success {
    color: #4caf50;
}

.admin-status.error {
    color: #f44336;
}

.admin-status.info {
    color: #64b5f6;
}

.admin-hint {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
}

/* Bone Scaling Slider Styling */
#bone-length-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #FF9800;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.5);
    border: 2px solid #fff;
}

#bone-length-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #FF9800;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.5);
    border: 2px solid #fff;
}

#bone-length-slider:hover::-webkit-slider-thumb {
    transform: scale(1.1);
    box-shadow: 0 3px 12px rgba(255, 152, 0, 0.7);
}

#bone-length-slider:hover::-moz-range-thumb {
    transform: scale(1.1);
    box-shadow: 0 3px 12px rgba(255, 152, 0, 0.7);
}

#bone-reset-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

#bone-close-btn:hover {
    background: #45a049;
}
