/* ========================================
   WISDEMY - Solid of Revolution Visualizer
   Style: Dark Premium (Refined Inputs)
   ======================================== */

/* --- CSS Variables --- */
:root {
    /* Brand Colors - Keep original */
    --primary-color: #bb2649;
    /* Deep Pink/Red */
    --secondary-color: #ffb3c1;
    /* Light Pink */

    /* Backgrounds: Warm Dark Theme (Educational) */
    --bg-primary: #1e2433;
    /* Warm dark blue - main background */
    --bg-secondary: #252d3d;
    /* Slightly lighter - panel BG */
    --bg-glass: rgba(37, 45, 61, 0.95);
    --bg-input: rgba(0, 0, 0, 0.3);

    /* Accents */
    --accent-glow: rgba(187, 38, 73, 0.4);

    /* Text - Warmer tones */
    --text-primary: #f0f0f0;
    /* Soft white (less harsh) */
    --text-secondary: #d0d5dd;
    /* Warm gray */
    --text-muted: #a0aec0;
    /* Warm blue-gray */

    /* Borders */
    --border-color: rgba(255, 255, 255, 0.1);

    /* Layout */
    --panel-width: 380px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Quicksand', 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* --- App Container --- */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* --- Control Panel Wrapper --- */
.panel-wrapper {
    width: var(--panel-width);
    min-width: var(--panel-width);
    height: 100%;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
    transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

/* --- Control Panel Internal (Scrollable) --- */
.control-panel {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.control-panel::-webkit-scrollbar {
    width: 6px;
}

.control-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* --- Panel Header --- */
.panel-header {
    padding: 24px 20px;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.logo-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.owl-logo {
    width: 44px;
    height: 44px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.panel-header h1 {
    font-family: 'Segoe UI', sans-serif;
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--primary-color);
}

.panel-header .subtitle {
    font-family: 'Quicksand', sans-serif;
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    opacity: 0.8;
}

/* --- Control Sections --- */
.control-section {
    padding: 20px;
    /* Removed border-bottom as we merged sections */
}

/* Unified Section Spacing */
.func-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    margin-bottom: 12px;
}

/* First header shouldn't have top margin */
.control-section>.func-group-header:first-child {
    margin-top: 0;
}

/* --- Inputs --- */
.control-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0;
}

.input-group {
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

/* ... */

.slider-group label {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 10px;
}

.input-group input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

/* ... */

.func-item input[type="text"] {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
    font-weight: 500;
}

/* ... */

.input-bound input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
    font-weight: 500;
    outline: none;
    transition: border-color 0.2s;
}

/* ... */

.range-row input {
    width: 60px;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-align: center;
    font-family: 'Consolas', monospace;
    font-size: 0.85rem;
    /* Slightly smaller for tight spaces */
    font-weight: 500;
}

.input-group input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Horizontal Group (Label Left, Input Right) */
.horizontal-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.horizontal-group label {
    margin-bottom: 0;
    white-space: nowrap;
    margin-right: 12px;
}

.horizontal-group select {
    width: 180px;
    /* Fixed width for consistency */
}

/* Modern Select Dropdowns */
/* Modern Select Dropdowns */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: 'Quicksand', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    /* Custom Arrow Icon (Chevron Down) */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d0d5dd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 18px;
    transition: all 0.2s ease;
}

/* ... existing hover/focus styles ... */

.color-controls select {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    min-width: 110px;
}

/* ... */

.color-inputs-container select {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
}

select:hover {
    border-color: rgba(255, 255, 255, 0.3);
    background-color: rgba(255, 255, 255, 0.05);
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

select option {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    padding: 12px;
}

/* Inline Color Picker Label */
.label-with-color {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
}

.label-with-color input[type="color"] {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.label-with-color input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

/* --- Bounds Section (NEW) --- */
.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-label {
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
}

.bounds-row {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.input-bound {
    flex: 1;
}

.input-bound label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.input-bound input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Consolas', monospace;
    font-size: 1rem;
    font-weight: 600;
}

.input-bound input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(0, 0, 0, 0.6);
}

/* --- Gradient Pickers --- */
.gradient-group label {
    display: block;
    margin-bottom: 10px;
}

.gradient-pickers {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gradient-picker-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.gradient-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.gradient-picker-item input[type="color"] {
    width: 40px;
    height: 32px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.2s;
}

.gradient-picker-item input[type="color"]:hover {
    border-color: var(--primary-color);
}

.gradient-arrow {
    color: var(--text-muted);
    font-size: 1.2rem;
    margin: 0 4px;
}

/* --- Utility Classes --- */
.hidden {
    display: none !important;
}

/* --- Compact Color Row --- */
.color-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.color-row>label {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
}

.color-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.color-controls select {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-width: 110px;
}

.color-controls select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* --- Color Settings Row (New) --- */
.color-settings-row {
    margin-bottom: 16px;
}

.color-settings-row label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.color-inputs-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-inputs-container select {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

.color-inputs-container select:focus {
    border-color: var(--primary-color);
    outline: none;
}

.color-pickers {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Modern Circular Color Picker - Global */
input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 2px solid #ffffff;
    /* Solid white border */
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    vertical-align: middle;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
    padding: 0;
}

input[type="color"]:hover {
    transform: scale(1.1);
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* --- Single Color Picker --- */
/* --- Compact Toggle Row --- */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.toggle-row>label:first-child {
    font-size: 0.9rem;
    font-weight: 600;
}

.switch {
    position: relative;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 28px;
    transition: all 0.3s;
}

.switch-slider::before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted);
    border-radius: 50%;
    transition: all 0.3s;
}

.switch input:checked+.switch-slider {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.switch input:checked+.switch-slider::before {
    transform: translateX(22px);
    background-color: white;
}

/* =========================================
   UI POLISH (Card Glow & Icons)
   ========================================= */

/* Card Interactions */
.func-item {
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
    /* Ensure border exists for transition */
}

.func-item:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 15px rgba(255, 78, 80, 0.15);
    /* Soft red glow */
    transform: translateY(-2px);
}

/* SVG Button Polishing */
.btn-icon,
.btn-remove,
.icon-btn-small {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-icon svg,
.btn-remove svg {
    pointer-events: none;
    /* Let button handle clicks */
}

.btn-icon:hover,
.btn-remove:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--primary-color);
    transform: scale(1.1);
}

/* Adjust remove button specific positioning if needed */
.btn-remove {
    padding: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.btn-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    padding: 6px;
}

/* --- Sliders --- */
.slider-group {
    margin-bottom: 20px;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.slider-value {
    color: var(--secondary-color);
    font-weight: 700;
    font-family: 'Times New Roman', serif;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-glow);
}

/* --- Color Groups --- */
.color-group {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.color-group input[type="color"] {
    width: 60px;
    height: 30px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    padding: 0;
}

.color-group input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

/* --- Result View (Decorated) --- */
.decorated-panel {
    background: rgba(0, 0, 0, 0.2);
    padding: 0;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

.result-item:last-child {
    border-bottom: none;
}

.result-label {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.result-number {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 1.4rem;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.result-item.highlight {
    background: linear-gradient(90deg, rgba(187, 38, 73, 0.15) 0%, rgba(187, 38, 73, 0.05) 100%);
    border-left: 4px solid var(--primary-color);
}

.result-item.highlight .result-label {
    color: var(--primary-color);
}

.result-item.highlight .result-number {
    color: var(--secondary-color);
}

/* --- Latex Preview --- */
.latex-preview {
    min-height: 40px;
    margin-top: 10px;
    padding: 8px 12px;
    background: rgba(0, 212, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: center;
}

.latex-preview .katex {
    font-size: 1.2rem;
    color: #fff;
    font-family: 'KaTeX_Main', 'Times New Roman', serif;
}

/* --- Dynamic Function List --- */
.func-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

/* Inherit global section-label style, remove overrides */
.func-group-header .section-label {
    /* Previously 0.95rem/600, now inheriting 0.8rem/700/Uppercase from global .section-label */
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    /* Ensure color consistency */
}

.btn-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: var(--primary-color);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--primary-color);
    color: white;
}

.func-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.func-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
}

.func-item-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.func-item input[type="text"] {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
}

.btn-remove {
    width: 24px;
    height: 24px;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.btn-remove:hover {
    color: #ff6b6b;
}

/* Added to match bound inputs with function inputs */
.input-bound input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Consolas', monospace;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-bound input:focus {
    border-color: var(--primary-color);
}

.range-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 36px;
    /* Align with input text */
    font-size: 0.85rem;
    color: var(--text-muted);
}

.range-row input {
    width: 60px;
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-align: center;
}

.range-value {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    color: #fff;
    min-width: 3rem;
    text-align: right;
}

/* --- Header Controls --- */
.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

#btn-share {
    margin-right: 4px;
}

#btn-share svg {
    width: 16px;
    height: 16px;
}

/* --- Toast Notification --- */
.toast {
    visibility: hidden;
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.show {
    visibility: visible;
    opacity: 1;
    bottom: 40px;
}

.mt-4 {
    margin-top: 16px;
}

.panel-footer {
    margin-top: auto;
    padding: 16px 20px;
    text-align: center;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-save {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    margin-bottom: 4px;
}

.btn-save:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-muted);
}

.footer-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* --- Canvas --- */
.canvas-container {
    flex: 1;
    background: #0f0f1a;
    overflow: hidden;
    position: relative;
}

#three-canvas {
    width: 100%;
    height: 100%;
}

/* Force canvas to fill container, overriding Three.js inline styles */
#three-canvas canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    outline: none;
}

/* --- Error Overlay --- */
.error-overlay {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 40, 0.95);
    border-left: 4px solid #ff4466;
    padding: 12px 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 600;
    z-index: 100;
}

.error-overlay.hidden {
    display: none;
}

/* Responsive */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
    }

    .control-panel {
        width: 100%;
        max-height: 50vh;
        border-right: none;
    }
}

.input-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    /* Ensure it takes full width of flex item */
    min-width: 0;
    /* Fix flex overflow */
}

.func-item-row.top-row {
    align-items: flex-start;
    /* Align color picker to top */
    gap: 10px;
}

.func-item-row.top-row .color-pickers {
    margin-top: 4px;
    /* Slight adjust to align with input text */
}

/* --- Inline Latex Preview --- */
.latex-mini {
    min-height: 24px;
    font-size: 1.1rem;
    color: #ffffff;
    /* Default white text */
    background: transparent;
    border: none;
    padding: 0;
    margin-top: 4px;
    margin-bottom: 0;
    margin-left: 0;
    /* Reset manual offset */
    text-align: left;
    overflow-x: auto;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.latex-mini:empty {
    display: none;
}

.latex-mini .katex {
    font-size: 1.1em;
    font-family: 'KaTeX_Main', 'Times New Roman', serif;
}

/* --- Sidebar Toggle Button --- */
.control-panel {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    /* Ensure button positions relative to this */
}

.sidebar-toggle {
    position: absolute;
    top: 50%;
    right: -20px;
    /* Stick out */
    width: 20px;
    height: 60px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-left: none;
    /* Connect to panel */
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transform: translateY(-50%);
    z-index: 100;
    transition: all 0.3s;
    padding: 0;
    backdrop-filter: blur(10px);
}

.sidebar-toggle:hover {
    background: var(--bg-secondary);
    color: var(--primary-color);
    width: 24px;
    /* Slight expand on hover */
}

.sidebar-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.3s;
}

/* Collapsed State (Desktop) */
.panel-wrapper.collapsed {
    margin-left: -380px;
    /* Pull off-screen to left */
}

/* Icon Rotation Logic */
.panel-wrapper.collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* Responsive Logic (Mobile) */
@media (max-width: 900px) {
    .sidebar-toggle {
        top: auto;
        bottom: -20px;
        /* Stick to bottom */
        right: auto;
        left: 50%;
        transform: translateX(-50%);
        width: 60px;
        height: 20px;
        border-right: 1px solid var(--border-color);
        border-left: 1px solid var(--border-color);
        border-top: none;
        border-radius: 0 0 8px 8px;
    }

    .sidebar-toggle:hover {
        width: 60px;
        height: 24px;
        transform: translateX(-50%);
    }

    .sidebar-toggle svg {
        transform: rotate(90deg);
        /* Point down by default */
    }

    .panel-wrapper.collapsed {
        margin-left: 0;
        /* Reset desktop margin */
        margin-top: -50vh;
        /* Pull off-screen upwards */
    }

    .panel-wrapper.collapsed .sidebar-toggle svg {
        transform: rotate(-90deg);
        /* Point up (or flip) */
    }
}

.slider-value {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1rem;
    min-width: 3.5rem;
    text-align: right;
}

/* Force Border on Bounds Color */
#color-bounds {
    border: 2px solid #ffffff !important;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}