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

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    user-select: none;
    cursor: default;
}

#container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0;
}

#canvas {
    background: transparent;
    cursor: grab;
    position: absolute;
    left: 280px;
    top: 0;
    width: calc(100vw - 280px);
    height: 100vh;
    z-index: 1;
    transition: left 0.3s ease, width 0.3s ease;
}

#canvas:active {
    cursor: grabbing;
}

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 10;
    padding: 16px;
    background: #FFFFFF;
    border-right: 1px solid #E0E0E0;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.08);
    overflow-y: auto;
    overflow-x: visible;
    transition: width 0.3s ease, padding 0.3s ease;
}

.sidebar-toggle-btn {
    position: fixed;
    top: 16px;
    left: 280px;
    width: 20px;
    height: 56px;
    border-radius: 0 10px 10px 0;
    border: none;
    background: linear-gradient(135deg, #832EC5 0%, #a855f7 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 8px rgba(131, 46, 197, 0.25);
    transition: all 0.25s ease, left 0.3s ease;
    z-index: 101;
    opacity: 0.7;
}

.sidebar-toggle-btn:hover {
    opacity: 1;
    width: 24px;
    box-shadow: 3px 3px 12px rgba(131, 46, 197, 0.35);
}

.sidebar-toggle-btn .toggle-icon {
    transition: transform 0.3s ease;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.sidebar-toggle-btn.collapsed .toggle-icon {
    transform: rotate(180deg);
}

.sidebar.collapsed {
    width: 0px;
    padding: 0;
    border-right: 0;
    box-shadow: none;
    overflow: visible;
}

.sidebar.collapsed > *:not(.sidebar-toggle-btn) {
    display: none;
}

#totalDisplay {
    transition: transform 0.3s ease;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-section-title {
    font-size: 0.66rem;
    font-weight: 600;
    color: #666666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.slider-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: #E8E8E8;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #B900FF 0%, #832EC5 100%);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(131, 46, 197, 0.4);
    transition: transform 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #B900FF 0%, #832EC5 100%);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(131, 46, 197, 0.4);
}

.slider-value {
    font-size: 0.75rem;
    color: #666666;
    font-weight: 600;
}

.source-marbles {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    justify-items: center;
}

.source-marble {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 
        inset -6px -6px 12px rgba(0, 0, 0, 0.2),
        inset 6px 6px 12px rgba(255, 255, 255, 0.5),
        2px 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
    border: 2px solid transparent;
}

.source-marble::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 25%;
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.8), transparent);
}

.source-marble:hover {
    transform: scale(1.05);
    border-color: #FFC700;
    box-shadow: 
        inset -6px -6px 12px rgba(0, 0, 0, 0.2),
        inset 6px 6px 12px rgba(255, 255, 255, 0.5),
        0 0 0 1px rgba(255, 199, 0, 0.2),
        2px 2px 8px rgba(0, 0, 0, 0.15);
}

.source-marble:active {
    cursor: default;
}

.control-panel {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

/* Reuse button/input styles defined in DESIGN_SYSTEM.md */
.control-btn {
    flex: 1;
    min-height: 50px; /* Reduced height to be closer to tool-btn */
    border: 2px solid #E0E0E0;
    border-radius: 12px;
    cursor: pointer;
    background: #F5F5F5;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 8px; /* Adjusted padding */
}

.control-btn:hover {
    background: #F5F5F5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
    color: #333333;
}

.control-btn:active {
    transform: translateY(-1px);
}

.control-btn.active {
    border-color: #832EC5;
    box-shadow: 0 0 0 2px rgba(131, 46, 197, 0.2);
    color: #333333;
}

.control-btn.active:hover {
     border: 2px solid #832EC5;
     box-shadow: 0 2px 8px rgba(131, 46, 197, 0.15);
}

.tool-icon {
    width: 20px;
    height: 20px;
    color: #666666;
}

.control-btn:hover .tool-icon {
    color: #333333;
}

.control-btn.active .tool-icon {
    color: #333333;
}

.control-btn span {
    font-size: 0.7rem;
    font-weight: 500;
    color: #666666;
}

.control-btn:hover span {
     color: #333333;
}

.control-btn.active span {
    color: #333333;
}


.empty-jar-btn {
    width: 100%;
    background: #FFFFFF;
    border: 2px solid #EF4444;
    color: #333333;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.empty-jar-btn:hover:not(:disabled) {
    background: #FEF2F2;
    transform: translateY(-1px);
}

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

.slider-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(90deg, #E0E0E0 0%, #E0E0E0 100%);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #832EC5 0%, #B900FF 100%);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(131, 46, 197, 0.4);
    transition: transform 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #832EC5 0%, #B900FF 100%);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(131, 46, 197, 0.4);
}

.slider-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: #832EC5;
    background: linear-gradient(135deg, #F3E8FF 0%, #EDE0FF 100%);
    padding: 4px 12px;
    border-radius: 8px;
    min-width: 50px;
    text-align: center;
}

.title-total-container {
    display: none;
}

.game-title-top {
    display: none;
}

#totalDisplay {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333333;
    background: linear-gradient(135deg, #FFF9E6 0%, #FFF3CC 100%);
    padding: 14px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #FFC700;
    min-height: 48px;
}

.total-section {
    display: none;
}

.total-section.visible {
    display: flex;
}

.dragged-marble-overlay {
    position: fixed;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 
        inset -10px -10px 20px rgba(0, 0, 0, 0.2),
        inset 10px 10px 20px rgba(255, 255, 255, 0.5),
        5px 5px 15px rgba(0, 0, 0, 0.3);
    display: none;
}

.dragged-marble-overlay::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 25%;
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.8), transparent);
}

/* Manual Controls Styles */
.stepper-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.stepper-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f9f9f9;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid #eee;
    gap: 6px;
    transition: all 0.2s ease;
}

.stepper-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border-color: #e0e0e0;
    background: #fff;
}

.stepper-item .number-stepper {
    width: 100%;
    max-width: 120px;
    justify-content: center;
}

.stepper-item .stepper-input {
    width: 38px;
}

/* Update Total Display Position */
#totalDisplay {
    position: absolute;
    top: 20px;
    left: 50%; /* Center based on screen */
    transform: translateX(calc(-50% + 140px)); /* Offset by sidebar width (280px/2) to center in remaining space */
    z-index: 100;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    display: none; /* Initially hidden */
}

#totalDisplay.visible {
    display: flex;
}

@media (max-width: 1024px) {
     #totalDisplay {
        transform: translateX(calc(-50% + 120px));
    }
}

@media (max-width: 768px) {
     #totalDisplay {
        transform: translateX(calc(-50% + 100px));
    }
}

@media (max-width: 480px) {
     #totalDisplay {
        transform: translateX(calc(-50% + 80px));
    }
}

/* Update Fill Button for Randomly Fill */
.fill-btn-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.fill-btn-subtitle {
    font-size: 0.7rem;
    color: #666666;
    font-weight: 500;
}

.control-btn:hover .fill-btn-subtitle {
    color: #333333;
}
@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
        padding: 14px;
    }
    
    .source-marbles {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .source-marble {
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 200px;
        padding: 12px;
        gap: 12px;
    }
    
    .sidebar-section-title {
        font-size: 0.6rem;
    }
    
    #totalDisplay {
        font-size: 0.9rem;
        padding: 10px 12px;
        min-height: 36px;
    }
    
    .source-marbles {
        grid-template-columns: repeat(5, 1fr);
        gap: 6px;
    }
    
    .source-marble {
        width: 28px;
        height: 28px;
    }
    
    .control-btn {
        width: 40px;
        height: 40px;
    }
    
    .control-btn img {
        width: 24px;
        height: 24px;
    }
    
    #canvas {
        max-height: 80vh;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 160px;
        padding: 10px;
        gap: 10px;
    }
    
    .source-marbles {
        grid-template-columns: repeat(5, 1fr);
        gap: 4px;
    }
    
    .source-marble {
        width: 24px;
        height: 24px;
    }
    
    .control-btn {
        width: 36px;
        height: 36px;
    }
    
    .control-btn img {
        width: 20px;
        height: 20px;
    }
    
    #totalDisplay {
        font-size: 0.75rem;
        padding: 8px 10px;
    }
    
    .slider-value {
        font-size: 0.7rem;
        padding: 2px 8px;
    }
}
