:root {
    /* Color Variables */
    --ui-blue: #2b4158;           /* Blue for section headers, sliders, pills, and other UI elements */
    --ui-blue-hover: #1e293b;      /* Slightly lighter blue for hover states */
    --ui-bg-pane: #f2f5f7;         /* Background for control panel/pane */
    --ui-bg-titlebar: #FAFBFC;     /* Background for app header/titlebar */
    
    /* Layout Variables */
    --header-height-desktop: 60px;
    --header-height-mobile: 56px;
    --panel-width: 250px;
    --toggle-button-size: 56px;
    --content-padding: 20px;
    --content-padding-mobile: 16px;
    
    /* Z-Index Hierarchy (from lowest to highest) */
    --z-toggle: 997;        /* Controls toggle button */
    --z-overlay: 998;       /* Panel overlay backdrop */
    --z-panel: 999;         /* Control panel */
    --z-header: 1000;       /* App header */
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #fafafa;
    overflow: hidden;
}

/* Canvas Container */
#canvas-container {
    position: fixed;
    left: 0;
    top: var(--header-height-desktop);
    right: var(--panel-width);
    height: calc(100vh - var(--header-height-desktop));
    background: #d0d0d0;
}

#canvas-container canvas {
    display: block;
}

/* App Header with Mode Buttons */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-header);
    background: var(--ui-bg-titlebar);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding: 12px var(--content-padding);
    display: flex;
    justify-content: center;
    align-items: center;
    height: var(--header-height-desktop);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Loading Indicator */
#loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease-out, visibility 0.3s ease-out;
}

#loading-indicator.hidden {
    display: none;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(15, 23, 42, 0.2);
    border-top-color: var(--ui-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--ui-blue);
    font-size: 13px;
    font-weight: 500;
}

/* Mode Button Pills */
.mode-buttons {
    display: inline-flex;
    gap: 6px;
    background: #f3f4f6;
    padding: 4px;
    border-radius: 10px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.mode-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    white-space: nowrap;
}

.mode-btn:hover:not(.active) {
    color: #374151;
    background: rgba(255, 255, 255, 0.6);
}

.mode-btn.active {
    background: var(--ui-bg-pane);
    color: var(--ui-blue);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    font-weight: 600;
}

/* Controls Toggle Button (Mobile) */
.controls-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: var(--toggle-button-size);
    height: var(--toggle-button-size);
    border-radius: 50%;
    background: var(--ui-blue);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.4);
    z-index: var(--z-toggle);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.controls-toggle:hover {
    background: var(--ui-blue-hover);
    transform: scale(1.05);
}

.controls-toggle:active {
    transform: scale(0.95);
}

/* Panel Overlay (Mobile) */
.panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
}

.panel-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Control Panel */
.control-panel {
    position: fixed;
    right: 0;
    top: var(--header-height-desktop);
    width: var(--panel-width);
    max-width: 90vw;
    height: calc(100vh - var(--header-height-desktop));
    background: var(--ui-bg-pane);
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: var(--z-panel);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px var(--content-padding);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: var(--ui-bg-pane);
}

.controls-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

.scrollable-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.scrollable-content {
    padding: var(--content-padding);
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    box-sizing: border-box;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.scrollable-content::-webkit-scrollbar {
    width: 8px;
}

.scrollable-content::-webkit-scrollbar-track {
    background: transparent;
}

.scrollable-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.scrollable-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Panel Title - uses negative margin to extend to edges of scrollable-content */
.panel-title {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    background-color: var(--ui-blue);
    /* Negative margins compensate for parent padding to extend to edges */
    margin: 0 calc(-1 * var(--content-padding)) 15px calc(-1 * var(--content-padding));
    padding: 12px var(--content-padding);
    border-radius: 0;
}

.scrollable-content > .panel-title:first-child {
    margin-top: calc(-1 * var(--content-padding));
    border-radius: 0;
}

.control-group {
    margin-bottom: 16px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
}

.control-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: background 0.2s;
}

.control-group input[type="range"]:hover {
    background: #d1d5db;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ui-blue);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--ui-blue-hover);
    transform: scale(1.1);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ui-blue);
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group input[type="range"]::-moz-range-thumb:hover {
    background: var(--ui-blue-hover);
    transform: scale(1.1);
}

/* Disabled control group styling */
.control-group.disabled label {
    color: #6c757d;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    position: relative;
}

.control-group.disabled input[type="range"] {
    cursor: not-allowed;
    background: #dee2e6;
    opacity: 0.6;
}

.control-group.disabled input[type="range"]:hover {
    background: #dee2e6;
}

.control-group.disabled input[type="range"]::-webkit-slider-thumb {
    background: #adb5bd;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    border: 1px solid #868e96;
}

.control-group.disabled input[type="range"]::-webkit-slider-thumb:hover {
    background: #adb5bd;
    transform: none;
}

.control-group.disabled input[type="range"]::-moz-range-thumb {
    background: #adb5bd;
    cursor: not-allowed;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    border: 1px solid #868e96;
}

.control-group.disabled input[type="range"]::-moz-range-thumb:hover {
    background: #adb5bd;
    transform: none;
}

.control-group.disabled #mu-value {
    color: #6c757d;
}

.mode-note {
    display: inline-flex;
    align-items: center;
    background: #d97706;
    color: #ffffff;
    font-size: 10px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(217, 119, 6, 0.3);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    position: absolute;
    left: 0;
    top: 0;
    white-space: nowrap;
}

#mu-value,
#sigma-value,
#eta-value,
#lambda-value,
#alpha-value,
#gamma-value,
#beta-value,
#var0-value,
#kappa-value {
    color: var(--ui-blue);
    font-weight: 600;
}

/* Mobile Styles - Consolidated into single media query */
@media (max-width: 768px) {
    .app-header {
        padding: 10px var(--content-padding-mobile);
        height: var(--header-height-mobile);
        box-sizing: border-box;
    }
    
    #canvas-container {
        top: var(--header-height-mobile);
        right: 0;
        height: calc(100vh - var(--header-height-mobile));
        /* Removed conflicting margin-top - top positioning handles it */
    }
    
    .control-panel {
        top: var(--header-height-mobile);
        width: var(--panel-width);
        max-width: 85vw;
        height: calc(100vh - var(--header-height-mobile));
        transform: translateX(100%);
    }
    
    .control-panel.open {
        transform: translateX(0);
    }
    
    .mode-buttons {
        gap: 4px;
        padding: 3px;
    }
    
    .mode-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .controls-toggle {
        display: flex;
    }
    
    .close-btn {
        display: flex;
    }
    
    .controls-header {
        padding: 14px var(--content-padding-mobile);
    }
    
    .scrollable-content {
        padding: var(--content-padding-mobile);
    }
    
    /* Update panel-title negative margins for mobile padding */
    .panel-title {
        margin: 0 calc(-1 * var(--content-padding-mobile)) 15px calc(-1 * var(--content-padding-mobile));
        padding: 12px var(--content-padding-mobile);
    }
    
    .scrollable-content > .panel-title:first-child {
        margin-top: calc(-1 * var(--content-padding-mobile));
    }
}

/* Tablet Styles */
@media (min-width: 769px) and (max-width: 1024px) {
    .control-panel {
        width: var(--panel-width);
    }
}

/* Desktop: Hide toggle button and overlay */
@media (min-width: 769px) {
    .controls-toggle {
        display: none;
    }
    
    .panel-overlay {
        display: none;
    }
}

/* Legacy styles cleanup - can be removed if not needed */
#left-panels-container {
    display: none;
}

#mode-panel {
    display: none;
}

#stationarity-warning {
    background: rgba(255, 230, 230, 0.95);
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Debug Panel Styles */
#debug-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 40vh;
    background: rgba(0, 0, 0, 0.95);
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    z-index: 10000;
    display: none;
    flex-direction: column;
    border-top: 2px solid #4a9eff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

#debug-panel.visible {
    display: flex;
}

#debug-panel-header {
    background: #1a1a1a;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

#debug-panel-title {
    font-weight: bold;
    color: #4a9eff;
    font-size: 12px;
}

#debug-panel-controls {
    display: flex;
    gap: 8px;
}

#debug-panel-clear,
#debug-panel-toggle {
    background: #333;
    border: 1px solid #555;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-family: 'Courier New', monospace;
}

#debug-panel-clear:hover,
#debug-panel-toggle:hover {
    background: #444;
}

#debug-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    line-height: 1.4;
}

#debug-panel-content::-webkit-scrollbar {
    width: 8px;
}

#debug-panel-content::-webkit-scrollbar-track {
    background: #1a1a1a;
}

#debug-panel-content::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

#debug-panel-content::-webkit-scrollbar-thumb:hover {
    background: #666;
}

.debug-log-entry {
    margin-bottom: 4px;
    padding: 2px 0;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.debug-log-entry.log {
    color: #e0e0e0;
}

.debug-log-entry.info {
    color: #4a9eff;
}

.debug-log-entry.warn {
    color: #ffaa00;
}

.debug-log-entry.error {
    color: #ff4444;
    font-weight: bold;
}

.debug-log-timestamp {
    color: #888;
    margin-right: 8px;
}

.debug-log-level {
    margin-right: 8px;
    font-weight: bold;
}

@media (max-width: 768px) {
    #debug-panel {
        max-height: 50vh;
        font-size: 10px;
    }
    
    #debug-panel-header {
        padding: 6px 10px;
    }
    
    #debug-panel-title {
        font-size: 11px;
    }
}
