:root {
    --bg-color: #121214;
    --panel-bg: rgba(32, 32, 36, 0.85);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-primary: #EDEDED;
    --text-secondary: #A1A1AA;
    --accent-color: #646cff;
    --accent-hover: #535bf2;
    --danger-color: #ff4d4d;
    --font-family: 'Inter', sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Toolbar */
.toolbar {
    height: 60px;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
    backdrop-filter: blur(10px);
    z-index: 100;
}

.brand {
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
}

.tools {
    display: flex;
    gap: 10px;
}

.separator {
    width: 1px;
    background-color: var(--panel-border);
    height: 24px;
    margin: 0 5px;
}

/* Buttons */
.btn {
    background-color: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn.primary {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.btn.primary:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

.btn.danger {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.btn.danger:hover:not(:disabled) {
    background-color: rgba(255, 77, 77, 0.1);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Workspace */
.workspace {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#canvas-container {
    width: 100%;
    height: 100%;
    background-color: #0d0d0d;
    /* Slightly darker than bg for contrast */
    background-image:
        radial-gradient(circle at 10% 20%, rgba(20, 20, 20, 1) 0%, rgba(5, 5, 5, 0) 50%);
    cursor: grab;
}

#canvas-container:active {
    cursor: grabbing;
}

#drag-hint {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.5);
    color: rgba(255, 255, 255, 0.7);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    pointer-events: auto;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.3s;
    z-index: 50;
}

#drag-hint:hover {
    color: rgba(255, 255, 255, 1);
    background-color: rgba(0, 0, 0, 0.7);
}

/* Sidebar Properties */
.sidebar {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 300px;
    background-color: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-height: calc(100% - 40px);
    display: flex;
    flex-direction: column;
}

/* Panel Sections handled as flex items of Sidebar */
.panel-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Crucial for nested flex scrolling */
}

#view-settings-panel {
    flex: 0 0 auto;
    /* Auto height based on content, don't grow */
    max-height: 50%;
    /* Cap it just in case */
    border-bottom: 1px solid var(--panel-border);
}

#property-panel {
    flex: 1 1 auto;
    /* Take remaining space */
}

.panel-header {
    padding: 16px;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
    /* Header shouldn't shrink */
}

.panel-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.placeholder-text {
    color: var(--text-secondary);
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
}

/* Form Elements in Panel */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    background-color: #222;
    border: 1px solid var(--panel-border);
    color: var(--text-primary);
    padding: 8px;
    border-radius: 4px;
    font-family: inherit;
}

.form-group input[type="color"] {
    width: 100%;
    height: 36px;
    background: none;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    cursor: pointer;
}

/* Graph Controls (Bottom Right) */
.graph-controls {
    position: absolute;
    bottom: 20px;
    right: 340px;
    /* To left of sidebar */
    display: flex;
    gap: 10px;
    transition: bottom 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Force dark style for graph controls to be visible on light canvas */
.graph-controls .btn {
    background-color: #333 !important;
    color: #ccc !important;
    border: 1px solid #555 !important;
}

.graph-controls .btn:hover:not(:disabled) {
    background-color: #444 !important;
    color: #fff !important;
    border-color: #666 !important;
}

.graph-controls .btn:disabled {
    opacity: 0.5;
    background-color: #222 !important;
    border-color: #444 !important;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal {
    background-color: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 24px;
    width: 320px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    color: var(--text-primary);
}

.modal h3 {
    margin-bottom: 20px;
    font-size: 1.1rem;
    text-align: center;
}

.modal-actions {
    gap: 10px;
    margin-top: 20px;
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    background-color: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--panel-border);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 10px 4px;
    font-size: 0.8rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    background-color: rgba(100, 108, 255, 0.1);
}

.tab-pane {
    display: none;
    flex: 1;
    overflow: hidden;
    /* Ensure inner scroll works */
    flex-direction: column;
}

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

/* Adjust panel content to fit tab pane */
.tab-pane .panel-section {
    height: 100%;
    border-bottom: none;
    /* Remove border if nested */
}

/* Specific override for View Settings Panel in Tab */
.tab-pane #view-settings-panel {
    max-height: none;
    flex: 1;
}

/* --- Export Preview & Crop UI --- */
.preview-container {
    position: relative;
    width: 100%;
    height: 180px;
    background-color: #000;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    overflow: hidden;
}

#minimap-canvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    /* Though we draw to size */
}

#crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    /* z-index: 10; inside container */
}

#crop-box {
    position: absolute;
    border: 1px solid #fff;
    /* Simulate dimming outside: massive shadow */
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    cursor: move;
    display: none;
    /* Hidden until initialized/drawn */
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: var(--accent-color);
    border: 1px solid #fff;
    border-radius: 50%;
}

.resize-handle.nw {
    top: -4px;
    left: -4px;
    cursor: nw-resize;
}

.resize-handle.ne {
    top: -4px;
    right: -4px;
    cursor: ne-resize;
}

.resize-handle.sw {
    bottom: -4px;
    left: -4px;
    cursor: sw-resize;
}

.resize-handle.se {
    bottom: -4px;
    right: -4px;
    cursor: se-resize;
}

.ratio-input {
    flex: 1;
    text-align: center;
}

/* Help Icon */
.help-icon {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 20px;
    min-width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border: 1px solid var(--panel-border);
    font-size: 0.8rem;
    margin-left: 8px;
    cursor: pointer;
    transition: all 0.2s;
    vertical-align: middle;
    padding: 0;
}

.help-icon:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.help-modal-content {
    width: 400px;
    line-height: 1.6;
}

.help-text p {
    margin-bottom: 0.5em;
    font-size: 0.95rem;
    color: var(--text-primary);
}

/* --- Mobile Responsiveness --- */
/* Hamburger Menu Button */
#mobile-menu-btn {
    font-size: 1.2rem;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    display: none;
    /* Hidden on desktop */
}

/* Mobile Sidebar Toggle Button (Floating) */
#mobile-sidebar-toggle {
    display: none;
    /* Hidden on desktop */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    background-color: var(--accent-color);
    border: none;
    color: white;
    border-radius: 50%;
    /* Circle */
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 1.4rem;
    line-height: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 200;
}

@media (max-width: 768px) {
    /* Hide dragged hint on mobile usually, or keep it? Keep for now. */

    .toolbar {
        padding: 0 10px;
        position: relative;
        /* Ensure dropdown is positioned relative to toolbar or body? */
    }

    /* Show Hamburger */
    #mobile-menu-btn {
        display: block;
    }

    /* Hide Toolbar Items by default */
    #toolbar-items {
        display: none;
        position: absolute;
        top: 60px;
        /* Below toolbar */
        right: 0;
        width: 200px;
        flex-direction: column;
        background-color: var(--panel-bg);
        border: 1px solid var(--panel-border);
        padding: 10px;
        gap: 10px;
        border-radius: 0 0 0 8px;
        backdrop-filter: blur(10px);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }

    #toolbar-items.show {
        display: flex;
    }

    #toolbar-items .separator {
        width: 100%;
        height: 1px;
        margin: 5px 0;
    }

    /* Adjust Graph Controls (Bottom Right Buttons) */
    .graph-controls {
        right: 20px;
        /* Move closer to edge since sidebar is gone */
        bottom: 80px;
        /* Move up to avoid sidebar toggle if needed */
        flex-direction: column;
        /* Stack vertically for thumb access */
    }

    /* Sidebar - Collapsible Sheet */
    .sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        /* Full width */
        width: 100%;
        height: 60vh;
        /* Takes up 60% of screen height */
        max-height: 60vh;
        border-radius: 12px 12px 0 0;
        transform: translateY(100%);
        /* Hidden by default */
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 150;
        /* Above canvas, below modals */
    }

    .sidebar.open {
        transform: translateY(0);
    }

    /* Shift graph controls up when sidebar is open */
    body.sidebar-open .graph-controls {
        bottom: calc(60vh + 20px);
    }

    /* Show Mobile Toggle */
    #mobile-sidebar-toggle {
        display: block !important;
    }

    /* Help Modal */
    .help-modal-content {
        width: 90%;
        max-width: 400px;
    }
}