/* ── CSS Custom Properties ── */
:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #252525;
    --bg-panel: #2a2a2a;
    --bg-input: #333;
    --bg-hover: #3a3a3a;
    --border: #444;
    --border-hover: #555;
    --text-primary: #e0e0e0;
    --text-secondary: #999;
    --text-muted: #666;
    --text-label: #aaa;
    --accent: #3498db;
    --accent-hover: #4aa8eb;
    --danger: #e74c3c;
    --success: #2ecc71;
    --warning: #e67e22;
    --purple: #8e44ad;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    --shadow-sm: 0 2px 6px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ── Toolbar ── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 8px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--bg-input);
    flex-shrink: 0;
}

.toolbar h1 {
    font-size: 16px;
    color: var(--accent);
    white-space: nowrap;
}

.tool-group {
    display: flex;
    gap: 5px;
    align-items: center;
}

.tool-btn, .action-btn, .view-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-md);
    font-size: 12px;
    transition: all var(--transition);
    white-space: nowrap;
}

.tool-btn:hover, .action-btn:hover, .view-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

.tool-btn:focus-visible, .action-btn:focus-visible, .view-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tool-btn.active, .view-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    box-shadow: 0 0 8px rgba(52,152,219,0.3);
}

.send-to-game-btn {
    background: linear-gradient(135deg, #667eea, #764ba2) !important;
    border-color: #667eea !important;
    color: white !important;
    font-weight: 600;
    animation: sendBtnPulse 2s ease infinite;
}
.send-to-game-btn:hover {
    background: linear-gradient(135deg, #7b8ff0, #8a5db8) !important;
    box-shadow: 0 0 12px rgba(102,126,234,0.5) !important;
}
@keyframes sendBtnPulse {
    0%, 100% { box-shadow: 0 0 4px rgba(102,126,234,0.3); }
    50% { box-shadow: 0 0 12px rgba(102,126,234,0.6); }
}

.action-btn {
    width: 100%;
    margin-top: 6px;
    font-size: 12px;
}

.action-btn.danger {
    background: rgba(231, 76, 60, 0.15);
    border-color: rgba(231, 76, 60, 0.4);
    color: var(--danger);
}

.action-btn.danger:hover {
    background: rgba(231, 76, 60, 0.3);
    border-color: rgba(231, 76, 60, 0.6);
}

/* ── Main Container ── */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebars ── */
.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    overflow-y: auto;
    padding: 10px;
    flex-shrink: 0;
}

.sidebar.left {
    border-right: 1px solid var(--bg-input);
}

.sidebar.right {
    border-left: 1px solid var(--bg-input);
}

/* ── Panels ── */
.panel {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    padding: 12px;
    margin-bottom: 8px;
}

.panel h3 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-label);
    margin-bottom: 10px;
    letter-spacing: 0.6px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    line-height: 1.4;
}

.panel h3::after {
    content: '\25B4';
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.25s ease;
}

.panel.collapsed h3 {
    margin-bottom: 0;
}

.panel.collapsed h3::after {
    transform: rotate(180deg);
}

.panel-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.25s ease;
    max-height: 1200px;
    opacity: 1;
}

.panel.collapsed .panel-content {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

/* ── Controls ── */
.control-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.control-row label {
    font-size: 12px;
    min-width: 65px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.control-row input[type="number"],
.control-row select {
    flex: 1;
    padding: 5px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 12px;
    transition: border-color var(--transition);
}

.control-row input[type="number"]:focus,
.control-row select:focus {
    border-color: var(--accent);
    outline: none;
}

.control-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}

.control-row input[type="color"] {
    width: 40px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
    padding: 1px;
}

.control-row input[type="checkbox"] {
    accent-color: var(--accent);
}

.control-row span {
    font-size: 11px;
    color: #888;
    min-width: 28px;
    text-align: right;
}

/* ── Sculpt Actions ── */
.sculpt-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.sculpt-actions .action-btn {
    flex: 1;
    min-width: 60px;
    margin-top: 0;
    padding: 5px 8px;
    font-size: 11px;
}

.action-btn.sculpt-ready {
    background: rgba(46, 204, 113, 0.15);
    border-color: rgba(46, 204, 113, 0.4);
    color: var(--success);
    font-weight: 600;
}
.action-btn.sculpt-ready:hover {
    background: rgba(46, 204, 113, 0.3);
}

.warning-text {
    font-size: 10px;
    color: var(--warning);
    font-style: italic;
}

.toolbar-label {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-right: 4px;
}

.shapes-group {
    flex-wrap: wrap;
}

/* ── Sculpt Status ── */
.sculpt-status {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    align-items: center;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    padding: 6px 16px;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(0, 255, 136, 0.15);
    font-size: 12px;
    color: #00ff88;
    pointer-events: none;
    z-index: 10;
}

.sculpt-status span:last-child {
    color: #888;
}

kbd {
    background: rgba(255,255,255,0.1);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: inherit;
    font-weight: 600;
    color: rgba(255,255,255,0.5);
    font-size: 10px;
}

.hint {
    font-size: 10px;
    color: var(--border-hover);
    margin-top: 4px;
    font-style: italic;
}

/* ── AI Sculpt ── */
.action-btn.ai-generate {
    background: linear-gradient(135deg, rgba(142, 68, 173, 0.25), rgba(41, 128, 185, 0.25));
    border: 1px solid rgba(142, 68, 173, 0.4);
    color: #bb88ee;
    font-weight: 600;
    font-size: 13px;
    padding: 10px;
    letter-spacing: 0.3px;
    transition: all 0.3s;
}

.action-btn.ai-generate:hover {
    background: linear-gradient(135deg, rgba(142, 68, 173, 0.45), rgba(41, 128, 185, 0.45));
    border-color: rgba(142, 68, 173, 0.7);
    color: #ddaaff;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(142, 68, 173, 0.2);
}

.ai-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 6px 8px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
}

.ai-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, rgba(142, 68, 173, 0.3), rgba(41, 128, 185, 0.3));
    border-radius: var(--radius-sm);
    transition: width 0.3s ease;
    width: 0%;
}

.ai-progress span {
    position: relative;
    z-index: 1;
    font-size: 11px;
    color: #bb88ee;
}

/* === BUILD LOADING OVERLAY === */
#build-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 15, 0.85);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.build-overlay-content {
    text-align: center;
    padding: 32px 48px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    min-width: 280px;
}
.build-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 16px;
    border: 3px solid rgba(142, 68, 173, 0.2);
    border-top-color: #bb88ee;
    border-radius: 50%;
    animation: build-spin 0.8s linear infinite;
}
@keyframes build-spin {
    to { transform: rotate(360deg); }
}
#build-overlay-label {
    font-size: 16px;
    font-weight: 600;
    color: #e0e0e0;
    margin-bottom: 16px;
}
.build-progress-track {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 10px;
}
.build-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #8e44ad, #2980b9);
    border-radius: 3px;
    transition: width 0.3s ease;
}
#build-phase-detail {
    font-size: 13px;
    color: #a0a0b0;
    margin-bottom: 12px;
    min-height: 18px;
    transition: opacity 0.3s;
}
#build-progress-text {
    font-size: 12px;
    color: #bb88ee;
}
#build-tip {
    font-size: 11px;
    color: #666680;
    margin-top: 10px;
    font-style: italic;
    min-height: 16px;
}

#ai-sculpt-form optgroup {
    color: #bb88ee;
    font-style: normal;
    font-weight: 600;
}

#ai-sculpt-form option {
    color: var(--text-primary);
    font-weight: 400;
}

/* ── Viewport ── */
.viewport {
    flex: 1;
    position: relative;
    background: var(--bg-primary);
    min-width: 0;
}

#canvas-container {
    width: 100%;
    height: 100%;
}

#canvas-container canvas {
    display: block;
}

.viewport-controls {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(10px);
    padding: 6px 10px;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255,255,255,0.06);
}

.view-btn {
    padding: 5px 12px;
    font-size: 11px;
}

/* ── Stats Bar ── */
.stats-bar {
    position: absolute;
    bottom: 12px;
    left: 12px;
    display: flex;
    gap: 14px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    padding: 5px 12px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255,255,255,0.06);
    font-size: 11px;
    color: var(--text-secondary);
    z-index: 5;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}

.stats-bar .stat-val {
    color: var(--accent);
    font-weight: 600;
}

.stats-bar .stat-fps {
    color: #00ff88;
    font-weight: 600;
}

/* ── Object List ── */
#object-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

#object-list li {
    padding: 6px 10px;
    background: var(--bg-input);
    margin-bottom: 3px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.15s;
    border: 1px solid transparent;
}

#object-list li:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

#object-list li.selected {
    background: rgba(52, 152, 219, 0.2);
    border-color: rgba(52, 152, 219, 0.4);
    color: #7ec8e3;
}

/* ── Visibility Toggle ── */
.vis-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
    opacity: 0.6;
    transition: opacity var(--transition);
    flex-shrink: 0;
}

.vis-btn:hover {
    opacity: 1;
}

.vis-btn.hidden-obj {
    opacity: 0.25;
}

#object-list li.obj-hidden {
    opacity: 0.4;
}

/* ── Group Hierarchy ── */
.object-group {
    font-weight: 700;
    color: #8899dd;
    cursor: pointer;
    padding: 5px 10px;
    background: #2a2a3a;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    border: 1px solid var(--border);
}
.object-group::before { content: '\1F4C1 '; }
.object-group:hover { background: #333355; border-color: #6677aa; }
.group-children {
    padding-left: 14px;
    margin-left: 6px;
    margin-bottom: 6px;
    border-left: 2px solid #445;
}
.group-children li {
    font-size: 11px;
    padding: 4px 8px;
    background: #2e2e2e;
}

/* ── Vertex Edit ── */
.vertex-info {
    margin-top: 8px;
    padding: 8px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
}

.vertex-info.hidden {
    display: none;
}

.vertex-info p {
    font-size: 11px;
    margin-bottom: 6px;
}

/* ── Info Panel ── */
.panel p {
    font-size: 12px;
    margin-bottom: 4px;
    color: #888;
}

.panel p span {
    color: var(--text-primary);
    float: right;
    font-weight: 600;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* ── Toast Notifications ── */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 100000;
    pointer-events: none;
}

.toast {
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    background: rgba(40,40,50,0.92);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease forwards;
    pointer-events: auto;
    max-width: 420px;
    text-align: center;
}

.toast.toast-out {
    animation: toast-out 0.25s ease forwards;
}

.toast.toast-success {
    border-color: rgba(46,204,113,0.3);
    color: #8fffb4;
}

.toast.toast-error {
    border-color: rgba(231,76,60,0.3);
    color: #ff9494;
}

.toast.toast-warning {
    border-color: rgba(230,126,34,0.3);
    color: #ffc078;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(16px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* ── AI Chat Panel ── */
.ai-chat {
    position: fixed !important;
    bottom: 10px !important;
    right: 270px !important;
    width: 400px;
    height: 520px;
    background: #1a1a2e;
    border: 2px solid #6677cc;
    border-radius: var(--radius-xl);
    display: flex !important;
    flex-direction: column;
    z-index: 99999 !important;
    box-shadow: 0 8px 32px rgba(100,120,200,0.5);
    transition: height 0.3s ease, width 0.3s ease;
    overflow: hidden;
    font-size: 13px;
}
.ai-chat.minimized {
    height: 46px;
    width: 260px;
    cursor: pointer;
    border: 2px solid #99aaff;
    box-shadow: 0 4px 24px rgba(100,140,255,0.6);
    background: linear-gradient(135deg, #1a1a3e, #2a2a5e);
}
.ai-chat.minimized .ai-chat-body,
.ai-chat.minimized .ai-chat-settings { display: none !important; }

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: linear-gradient(135deg, #3344aa, #5533aa);
    border-bottom: 1px solid #6655cc;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    cursor: pointer;
    user-select: none;
    min-height: 42px;
    box-sizing: border-box;
}
.ai-chat-title {
    font-weight: 700;
    color: #ffffff;
    font-size: 14px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.ai-chat-header-btns { display: flex; gap: 6px; }
.ai-chat-header-btns button {
    background: none;
    border: none;
    color: #888;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.ai-chat-header-btns button:hover { color: #fff; background: rgba(255,255,255,0.1); }

.ai-chat-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.ai { justify-content: flex-start; }
.chat-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: var(--radius-xl);
    line-height: 1.5;
    word-wrap: break-word;
}
.chat-msg.user .chat-bubble {
    background: #2a3a5c;
    color: #d4deff;
    border-bottom-right-radius: var(--radius-sm);
}
.chat-msg.ai .chat-bubble {
    background: #2a2a2e;
    color: #ccc;
    border-bottom-left-radius: var(--radius-sm);
}
.chat-msg.ai .chat-bubble em { color: #a8b4ff; font-style: normal; }
.chat-bubble .action-tag {
    display: inline-block;
    background: #3a4a3a;
    color: #8f8;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    margin: 2px 2px;
}
.chat-bubble .error-tag {
    color: #f88;
    background: #4a3a3a;
}
.chat-msg.ai .chat-bubble.thinking {
    color: #888;
    font-style: italic;
}
.chat-msg.ai .chat-bubble.thinking::after {
    content: '';
    animation: dots 1.5s infinite;
}
@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

.ai-chat-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--bg-input);
    background: #222;
}
.ai-chat-input-area textarea {
    flex: 1;
    background: #2a2a2e;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: #ddd;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    max-height: 80px;
    outline: none;
}
.ai-chat-input-area textarea:focus { border-color: #6677aa; }
.ai-chat-input-area button {
    background: linear-gradient(135deg, #4a5aaa, #6a4aaa);
    border: none;
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-lg);
    font-size: 16px;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}
.ai-chat-input-area button:hover { filter: brightness(1.2); }
.ai-chat-input-area button:disabled { opacity: 0.4; cursor: not-allowed; }

.ai-chat-settings {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xl);
    z-index: 10;
}
.settings-content {
    background: #2a2a2e;
    padding: 20px;
    border-radius: var(--radius-lg);
    width: 85%;
    border: 1px solid var(--border);
}
.settings-content h4 {
    margin: 0 0 12px;
    color: #a8b4ff;
    font-size: 14px;
}
.settings-content input,
.settings-content select {
    background: #1e1e1e;
    border: 1px solid var(--border);
    color: #ddd;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
}

/* ── Mobile Responsive ── */
@media (max-width: 900px) {
    .sidebar { width: 200px; padding: 8px; }
    .toolbar { padding: 6px 12px; gap: 10px; flex-wrap: wrap; }
}

@media (max-width: 700px) {
    .main-container { flex-direction: column; }
    .sidebar { width: 100%; max-height: 200px; border: none; border-bottom: 1px solid var(--bg-input); }
    .sidebar.left { display: flex; flex-wrap: wrap; gap: 8px; overflow-x: auto; }
    .sidebar.left .panel { min-width: 200px; flex: 1; margin-bottom: 0; }
    .sidebar.right { display: none; }
}

/* ── Map Picker Modal ── */
#map-picker-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(10, 10, 15, 0.92);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.map-picker-container {
    width: 88vw; height: 82vh;
    max-width: 1300px; max-height: 850px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: 0 12px 48px rgba(0,0,0,0.6);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.map-picker-header {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.map-picker-header h3 {
    font-size: 14px; color: var(--text-primary);
    white-space: nowrap; margin: 0;
}
.map-picker-search {
    flex: 1; display: flex; gap: 4px; max-width: 420px;
}
.map-picker-search input {
    flex: 1; padding: 6px 10px; font-size: 12px;
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    outline: none;
}
.map-picker-search input:focus { border-color: var(--accent); }
.map-picker-search button {
    padding: 4px 10px; background: var(--accent); border: none;
    color: #fff; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px;
}
.map-picker-search button:hover { background: var(--accent-hover); }
.map-picker-close-btn {
    margin-left: auto; background: none; border: none;
    color: var(--text-secondary); font-size: 22px;
    cursor: pointer; padding: 0 4px; line-height: 1;
}
.map-picker-close-btn:hover { color: var(--danger); }
.map-picker-map { flex: 1; min-height: 0; background: #111; }
.map-picker-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.map-picker-info { display: flex; flex-direction: column; gap: 2px; }
#map-picker-location-name {
    font-size: 13px; color: var(--text-primary); font-weight: 500;
}
.map-picker-coords-text {
    font-size: 11px; color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.map-picker-actions { display: flex; gap: 8px; }
.map-picker-actions .action-btn {
    width: auto; padding: 8px 18px; font-size: 13px; margin-top: 0;
}
.map-picker-actions .action-btn:disabled {
    opacity: 0.4; cursor: not-allowed;
}
/* Leaflet dark controls */
.map-picker-map .leaflet-control-zoom a {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}
.map-picker-map .leaflet-control-zoom a:hover {
    background: var(--bg-hover) !important;
}
.map-picker-map .leaflet-control-attribution {
    background: rgba(26,26,26,0.8) !important;
    color: var(--text-muted) !important; font-size: 9px;
}
.map-picker-map .leaflet-control-attribution a {
    color: var(--accent) !important;
}

/* ═══════════════════════════════════════════════════════════
   ██  DIRECTOR TIMELINE SYSTEM
   ═══════════════════════════════════════════════════════════ */

.director-timeline {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 190px;
    background: rgba(18, 18, 24, 0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid rgba(255,255,255,0.08);
    z-index: 60;
    display: flex;
    flex-direction: column;
    font-size: 11px;
    color: var(--text-primary);
    user-select: none;
}

.director-toolbar {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: rgba(28, 28, 36, 0.95);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
    height: 34px;
    overflow-x: auto;
}

.dir-btn {
    padding: 3px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 11px;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.dir-btn:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.dir-btn-play { font-size: 15px; padding: 3px 12px; min-width: 34px; text-align: center; }
.dir-btn-accent { background: rgba(52,152,219,0.15); border-color: rgba(52,152,219,0.35); color: #7ec8e3; }
.dir-btn-accent:hover { background: rgba(52,152,219,0.3); }
.dir-btn-render { background: rgba(46,204,113,0.15); border-color: rgba(46,204,113,0.35); color: #8fffb4; font-weight: 600; }
.dir-btn-render:hover { background: rgba(46,204,113,0.3); }
.dir-btn-danger { background: rgba(231,76,60,0.2); border-color: rgba(231,76,60,0.4); color: #ff9494; }
.dir-btn.active { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.25); }

.dir-time {
    font-family: 'Consolas', 'Courier New', monospace;
    color: #00ff88;
    font-size: 12px;
    min-width: 130px;
    letter-spacing: 0.5px;
}

.dir-label { color: var(--text-secondary); font-size: 10px; }
.dir-separator { width: 1px; height: 18px; background: var(--border); margin: 0 2px; flex-shrink: 0; }

.dir-input-sm {
    width: 42px; padding: 2px 4px;
    background: var(--bg-input); border: 1px solid var(--border);
    color: var(--text-primary); border-radius: var(--radius-sm);
    font-size: 11px; text-align: center;
}
.dir-select-sm {
    padding: 2px 4px;
    background: var(--bg-input); border: 1px solid var(--border);
    color: var(--text-primary); border-radius: var(--radius-sm);
    font-size: 11px;
}

/* Tracks area */
.director-tracks-area {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

.director-track-labels {
    width: 110px;
    flex-shrink: 0;
    overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,0.06);
    padding-top: 20px; /* align with ruler height */
}

.dir-track-label {
    height: 26px;
    line-height: 26px;
    padding: 0 8px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 10px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    color: var(--text-secondary);
    cursor: default;
}
.dir-track-label:hover { background: rgba(255,255,255,0.03); }
.dir-track-label-cam { color: #ff8844; font-weight: 600; }
.dir-track-label-env { color: #44aaff; }
.dir-track-label-actor { color: #44ff88; }
.dir-track-label-state { color: #ff44aa; font-size: 9px; }

.director-track-canvas {
    flex: 1;
    position: relative;
    overflow-x: auto;
    overflow-y: auto;
}

/* Ruler */
.dir-ruler {
    height: 20px;
    position: sticky;
    top: 0;
    background: rgba(22, 22, 28, 0.98);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    z-index: 3;
    min-width: 100%;
}

.dir-ruler-tick {
    position: absolute;
    top: 0;
    height: 100%;
    border-left: 1px solid rgba(255,255,255,0.12);
    padding-left: 3px;
    font-size: 9px;
    color: var(--text-muted);
    line-height: 20px;
}

/* Track rows */
.dir-track-row {
    height: 26px;
    position: relative;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    min-width: 100%;
}
.dir-track-row:nth-child(odd) { background: rgba(255,255,255,0.012); }

/* Keyframe diamonds */
.dir-keyframe {
    position: absolute;
    width: 10px; height: 10px;
    transform: rotate(45deg);
    top: 50%; margin-top: -5px; margin-left: -5px;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.3);
    z-index: 2;
    transition: transform 0.1s, box-shadow 0.1s;
}
.dir-keyframe:hover {
    transform: rotate(45deg) scale(1.35);
    border-color: #fff;
    box-shadow: 0 0 6px rgba(255,255,255,0.3);
}
.dir-keyframe.cam   { background: #ff8844; }
.dir-keyframe.env   { background: #44aaff; }
.dir-keyframe.actor { background: #44ff88; }
.dir-keyframe.state {
    background: #ff44aa;
    border-radius: 50%;
    transform: none;
    margin-top: -5px;
}
.dir-keyframe.state:hover {
    transform: scale(1.35);
}

/* Playhead */
.dir-playhead {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background: #ff3333;
    z-index: 4;
    pointer-events: none;
    left: 0;
}
.dir-playhead::before {
    content: '';
    position: absolute;
    top: 0; left: -5px;
    width: 0; height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 10px solid #ff3333;
}

/* Render overlay */
.dir-render-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dir-render-content {
    background: rgba(30,30,38,0.95);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 30px 40px;
    text-align: center;
    min-width: 320px;
}

.dir-render-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.dir-render-info {
    font-family: 'Consolas', monospace;
    color: #00ff88;
    margin-bottom: 16px;
    font-size: 13px;
}

.dir-render-progress-track {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 18px;
}

.dir-render-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #44ff88, #00cc66);
    border-radius: 4px;
    transition: width 0.15s;
}

/* ══════════════════════════════════════════════════════════════════════
   MODE-BASED UI — Menu Bar, Mode Tabs, Dropdowns, Panel Visibility
   ══════════════════════════════════════════════════════════════════════ */

/* ── Menu Bar Layout ── */
.menu-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.menu-bar .logo {
    font-size: 15px;
    color: var(--accent);
    white-space: nowrap;
    margin-right: 4px;
}

/* ── Mode Selector (Blender-style dropdown) ── */
.mode-selector {
    display: flex;
    align-items: center;
}

.mode-dropdown {
    padding: 6px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    min-width: 140px;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}

.mode-dropdown:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

.mode-dropdown option {
    background: var(--bg-panel);
    color: var(--text-primary);
    padding: 4px 8px;
}

/* ── Dropdown Menus ── */
.menu-dropdowns {
    display: flex;
    gap: 2px;
    margin-left: 8px;
}

.menu-dropdown {
    position: relative;
}

.menu-btn {
    padding: 5px 12px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 500;
    transition: all var(--transition);
}

.menu-btn:hover,
.menu-dropdown.open .menu-btn {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--border);
}

.dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 2px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 9000;
    min-width: 160px;
    padding: 4px;
}

.menu-dropdown.open .dropdown-content {
    display: block;
}

/* Primitives grid dropdown */
.dropdown-content.primitives-grid {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    min-width: 280px;
    padding: 6px;
}

.menu-dropdown.open .dropdown-content.primitives-grid {
    display: grid;
}

.primitives-grid .tool-btn {
    padding: 5px 4px;
    font-size: 10px;
    text-align: center;
    border-radius: var(--radius-sm);
}

/* Dropdown items */
.dropdown-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 11px;
    text-align: left;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.dropdown-item:hover {
    background: var(--accent);
    color: #fff;
}

/* ── Mode-Based Panel Visibility (5 Blender-style modes) ── */
body.mode-object .sidebar .panel[data-mode]:not([data-mode~="object"]) {
    display: none !important;
}

body.mode-editmode .sidebar .panel[data-mode]:not([data-mode~="editmode"]) {
    display: none !important;
}

body.mode-sculpt .sidebar .panel[data-mode]:not([data-mode~="sculpt"]) {
    display: none !important;
}

body.mode-texture .sidebar .panel[data-mode]:not([data-mode~="texture"]) {
    display: none !important;
}

body.mode-animation .sidebar .panel[data-mode]:not([data-mode~="animation"]) {
    display: none !important;
}

/* ── Header Right Section (Symmetry + Shading) ── */
.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sym-toggles, .shading-btns {
    display: flex;
    gap: 2px;
}

.sym-toggles::before {
    content: 'Sym';
    font-size: 9px;
    color: var(--text-muted);
    align-self: center;
    margin-right: 2px;
}

.sym-btn, .shade-btn {
    padding: 3px 7px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    transition: all 0.15s;
    line-height: 1;
}

.sym-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.shade-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.sym-btn:hover, .shade-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

/* ── Edit Mode: Selection Mode Bar ── */
.selection-mode-bar {
    display: flex;
    gap: 4px;
}

.sel-mode-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 4px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 9px;
    transition: all 0.15s;
}

.sel-mode-btn svg {
    width: 18px;
    height: 18px;
}

.sel-mode-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sel-mode-btn.active {
    background: rgba(255, 140, 0, 0.2);
    border-color: #ff8c00;
    color: #ff8c00;
}

/* ── Edit Tool Grid ── */
.edit-tool-grid {
    display: grid;
    gap: 4px;
    margin-bottom: 8px;
}

.edit-tool-btn {
    font-size: 10px !important;
    padding: 5px 4px !important;
    margin: 0 !important;
    text-align: center;
}

/* ── Dropdown separator ── */
.dropdown-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

/* ══════════════════════════════════════════════════════════════════════
   BRUSH PALETTE — ZBrush-style visual brush grid
   ══════════════════════════════════════════════════════════════════════ */

.brush-palette {
    max-height: 340px;
    overflow-y: auto;
    overflow-x: hidden;
    margin: 4px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-hover) transparent;
}

.brush-palette::-webkit-scrollbar { width: 4px; }
.brush-palette::-webkit-scrollbar-track { background: transparent; }
.brush-palette::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.brush-cat-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted, #666);
    padding: 6px 4px 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 3px;
}

.brush-cat-label:first-child {
    padding-top: 2px;
}

.brush-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    padding: 0 2px 4px;
}

.brush-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 4px 2px 3px;
    border: 1px solid transparent;
    background: var(--bg-input, #2a2a2a);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.12s ease;
    min-height: 44px;
}

.brush-tile svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.brush-tile span {
    font-size: 8px;
    color: var(--text-muted, #888);
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.brush-tile:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

.brush-tile:hover svg {
    color: var(--text-primary);
}

.brush-tile:hover span {
    color: var(--text-primary);
}

.brush-tile.active {
    background: color-mix(in srgb, var(--accent) 25%, var(--bg-input, #2a2a2a));
    border-color: var(--accent);
    box-shadow: 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent);
}

.brush-tile.active svg {
    color: var(--accent);
}

.brush-tile.active span {
    color: var(--accent);
    font-weight: 600;
}
