body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f2f5;
    display: flex;
    height: 100vh;
    margin: 0;
    overflow: hidden; /* Prevent body scroll, handle internally */
}

/* SIDEBAR CONTROLS */
.sidebar {
    width: 320px;
    background: white;
    padding: 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 20;
    overflow-y: auto; /* Scrollable controls if too tall */
    flex-shrink: 0;
}

h2, h3 { margin-top: 0; margin-bottom: 5px; color: #333; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 10px; }

.control-group { display: flex; flex-direction: column; margin-bottom: 5px;}

label { font-size: 0.8rem; font-weight: bold; color: #666; margin-bottom: 5px; }

input, select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

button {
    padding: 12px;
    background-color: #ff4081;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 5px;
    touch-action: manipulation; /* Improves touch response */
}
button:hover { background-color: #e91e63; }
button.secondary { background-color: #666; }

hr { width: 100%; border: 0; border-top: 1px solid #ccc; margin: 10px 0; }

/* OVERLAY STATE */
#controls-overlay {
    opacity: 0.5;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: opacity 0.2s;
}

/* MAIN CANVAS AREA */
.canvas-area {
    flex-grow: 1;
    background-image: radial-gradient(#ccc 1px, transparent 1px);
    background-size: 20px 20px;
    background-color: #fafafa;
    position: relative;
    overflow: hidden;
    touch-action: none; /* CRITICAL: Prevents browser scrolling while dragging items */
}

/* DRAGGABLE ITEMS */
.text-item, .stick-item {
    position: absolute;
    cursor: grab;
    user-select: none;
    touch-action: none; /* Stops browser zooming/scrolling on the item */
}

.text-item {
    white-space: nowrap;
    color: #333;
    line-height: 1;
    padding-top: 5px;
    border: 2px dashed transparent;
    z-index: 10;
}

.stick-item {
    background-color: #000;
    width: 15px;
    height: 150px;
    z-index: 1;
}

.selected {
    border-color: #ff4081; /* Text border */
    outline: 2px dashed #ff4081; /* Stick outline */
    z-index: 100;
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    body {
        flex-direction: column; /* Stack vertically */
    }

    .canvas-area {
        order: 1; /* Canvas on top */
        height: 55vh; /* Take up top half of screen */
        width: 100%;
        border-bottom: 1px solid #ccc;
    }

    .sidebar {
        order: 2; /* Controls on bottom */
        width: 100%; /* Full width */
        height: 45vh; /* Bottom half */
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        padding: 15px;
        box-sizing: border-box; /* Include padding in width */
    }

    /* Make inputs larger for fingers */
    input[type="range"] { margin: 10px 0; }
    select, input[type="text"] { font-size: 16px; /* Prevents iOS zoom */ }
}