/* --- THE BRICK LAYER --- */
#brick-layer {
    position: fixed;
    bottom: 0;
    left: 2px;
    right: 2px;
    height: 300px;
    display: flex;
    flex-wrap: wrap-reverse;
    align-items: flex-start; 
    align-content: flex-start;
    gap: 2px; 
    pointer-events: none;
    z-index: 50; 
    padding-bottom: 2px;
}

.brick-spacer {
    flex-grow: 1;
    pointer-events: none;
    min-width: 10px;
}

/* The Bricks themselves */
.brick {
    pointer-events: auto;
    height: 36px;
    min-width: 40px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    
    background-color: var(--ui-face);
    background-image: linear-gradient(45deg, rgba(255,255,255,0.1) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.1) 75%, transparent 75%, transparent);
    background-size: 4px 4px;
    color: var(--ui-text);
    
    border-top: 2px solid var(--ui-light);
    border-left: 2px solid var(--ui-light);
    border-right: 2px solid var(--ui-dark);
    border-bottom: 2px solid var(--ui-dark);
    box-shadow: 2px 2px 0px rgba(0,0,0,0.5);
    
    font-weight: bold;
    cursor: grab;
    user-select: none;
    
    /* MOBILE FIX: Prevents dragging the whole screen */
    touch-action: none; 
    
    position: relative;
    flex-shrink: 0;
    
    animation: fallIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* STATE: Landed */
.brick.landed {
    opacity: 1 !important; 
    transform: none;       
    animation: landShake 0.3s ease-out; 
}

/* STATE: Dragging */
.brick.dragging { 
    opacity: 0.9 !important;
    cursor: grabbing;
    z-index: 6000;
    transform-origin: center;
    animation: wobble 0.2s infinite ease-in-out;
    position: absolute; 
    box-shadow: 6px 6px 10px rgba(0,0,0,0.6);
}

/* STATE: Free */
.brick.free {
    position: absolute;
    margin: 0;
    opacity: 1 !important;
}

/* STATE: Impact Shake (Neighbors) */
.brick.impact-shake {
    animation: impactShake 0.4s ease-in-out;
}

/* --- ANIMATIONS --- */
@keyframes fallIn {
    0% { transform: translateY(-300px); opacity: 0; }
    60% { opacity: 1; }
    70% { transform: translateY(0); }
    85% { transform: translateY(-15px); }
    100% { transform: translateY(0); opacity: 1; }
}

@keyframes landShake {
    0% { transform: scale(1, 1); }
    30% { transform: scale(1.2, 0.8); }
    60% { transform: scale(0.9, 1.1); }
    100% { transform: scale(1, 1); }
}

@keyframes impactShake {
    0% { transform: translateY(0); }
    25% { transform: translateY(2px); }
    50% { transform: translateY(-2px); }
    75% { transform: translateY(1px); }
    100% { transform: translateY(0); }
}

@keyframes wobble {
    0% { transform: rotate(0deg) scale(1.1); }
    25% { transform: rotate(-5deg) scale(1.1); }
    75% { transform: rotate(5deg) scale(1.1); }
    100% { transform: rotate(0deg) scale(1.1); }
}

/* --- WINDOWS --- */
.window {
    position: absolute;
    display: flex;
    flex-direction: column;
    box-shadow: 6px 6px 0px rgba(0,0,0,0.4);
    padding: 3px;
    background: var(--ui-face);
    color: var(--ui-text);
    border-top: 2px solid var(--ui-light);
    border-left: 2px solid var(--ui-light);
    border-right: 2px solid var(--ui-dark);
    border-bottom: 2px solid var(--ui-dark);
    z-index: 100;
    
    /* MOBILE FIXES: Ensures windows squish to fit phone screens */
    max-width: 95vw; 
    max-height: calc(100vh - 44px); /* Leaves space for taskbricks */
}

.title-bar {
    background: linear-gradient(90deg, var(--title-grad-1), var(--title-grad-2));
    color: var(--title-text);
    padding: 2px 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    cursor: default;
    height: 22px;
    margin-bottom: 2px;
    
    /* CRITICAL MOBILE FIX: Prevents scroll intercepting window drag */
    touch-action: none; 
}

.title-bar.active { filter: brightness(1.2); }

.win-controls { display: flex; gap: 2px; }
.win-controls button {
    width: 14px; height: 14px;
    font-size: 8px; line-height: 8px;
    border: 1px solid white;
    background: silver;
    color: black;
    cursor: pointer;
    box-shadow: 1px 1px 0 black;
    padding: 0;
}

.window-content {
    flex-grow: 1;
    overflow-y: auto; /* ALLOW SCROLLING IF TALLER THAN SCREEN */
    overflow-x: hidden;
    position: relative;
    background: var(--win-bg);
    color: var(--win-text);
    border: 2px inset var(--ui-dark);
}

.resizer { 
    position: absolute; 
    /* CRITICAL MOBILE FIX: Prevents scroll intercepting window resize */
    touch-action: none; 
}

.resizer.bottom-right { width: 10px; height: 10px; right: 0; bottom: 0; cursor: se-resize; z-index: 10; }
.resizer.right { width: 5px; top: 0; right: 0; bottom: 10px; cursor: e-resize; }
.resizer.bottom { height: 5px; left: 0; bottom: 0; right: 10px; cursor: n-resize; }
.resizer.bottom-right::after {
    content: ''; position: absolute; right: 2px; bottom: 2px;
    width: 6px; height: 6px;
    border-right: 2px solid var(--ui-dark);
    border-bottom: 2px solid var(--ui-dark);
}