/* Board — horizontal columns layout, centered on screen, columns anchored to bottom */
.board {
    /* Dynamic cell-size: shrink cells so board + 1 queue box fits viewport */
    --queue-count: 1;
    --all-boxes: calc(var(--max-boxes) + var(--queue-count));
    --all-rows: calc(var(--all-boxes) * var(--box-rows));
    --overhead: calc(
        var(--all-boxes) * var(--box-extra)
        + var(--max-boxes) * var(--column-gap)
        + 120px
    );
    --cell-size: min(48px, calc((100dvh - var(--overhead)) / var(--all-rows)));

    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: flex-end;
    padding: 8px;
    max-width: 100vw;
    position: relative;
    height: calc(
        var(--all-boxes) * (var(--cell-size) * var(--box-rows) + var(--box-extra))
        + var(--max-boxes) * var(--column-gap)
        + 32px
    );
    margin: 0;
    overflow: visible;
}

/* Full-width separator between board and queue */
.board::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(
        12px
        + var(--max-boxes) * (var(--cell-size) * var(--box-rows) + var(--box-extra))
        + (var(--max-boxes) - 1) * var(--column-gap)
    );
    border-top: 6px solid rgba(184, 149, 106, 0.8);
    margin-left: -40px;
    margin-right: -40px;
}

/* Column — two sections stacked: queue on top, board on bottom */
.column {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 16px;
    min-width: calc(var(--cell-size) * var(--box-cols) + 17px);
}

/* Board section — fixed height, anchored to bottom */
.column-board {
    display: flex;
    flex-direction: column-reverse;
    gap: var(--column-gap);
    align-items: center;
    height: calc(
        var(--max-boxes) * (var(--cell-size) * var(--box-rows) + var(--box-extra))
        + (var(--max-boxes) - 1) * var(--column-gap)
    );
    justify-content: flex-start;
}

/* Queue section — same size boxes, with transparency */
.column-queue {
    display: flex;
    flex-direction: column-reverse;
    gap: var(--column-gap);
    align-items: center;
    opacity: 0.7;
}

.queue-more {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

/* Box — NxM CSS grid */
.box {
    display: inline-grid;
    gap: 0;
    padding: 6px;
    background: var(--bg-secondary);
    border: 2.5px solid var(--border-box);
    border-radius: var(--radius-box);
    box-shadow: var(--shadow-box);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.box:hover {
    border-color: #a07850;
}

/* Cell — single grid unit */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 0;
    transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
    position: relative;
}

.cell-empty {
    background: rgba(255, 255, 255, 0.25);
    border: 1px dashed rgba(184, 149, 106, 0.3);
}

.cell-void {
    visibility: hidden;
}

.cell-occupied {
    cursor: grab;
}

.block-hover {
    transform: scale(1.03);
    filter: brightness(1.1);
}

.cell-occupied:active {
    cursor: grabbing;
}

/* Block color classes */
.block-red {
    background: linear-gradient(135deg, var(--color-red), var(--color-red-dark));
}

.block-blue {
    background: linear-gradient(135deg, var(--color-blue), var(--color-blue-dark));
}

.block-green {
    background: linear-gradient(135deg, var(--color-green), var(--color-green-dark));
}

.block-yellow {
    background: linear-gradient(135deg, var(--color-yellow), var(--color-yellow-dark));
}

.block-purple {
    background: linear-gradient(135deg, var(--color-purple), var(--color-purple-dark));
}

.block-orange {
    background: linear-gradient(135deg, var(--color-orange), var(--color-orange-dark));
}

/* Picked block — ghost in original position */
.cell-picked {
    opacity: 0.3;
    transform: scale(0.9);
    cursor: default;
}

/* Candidate position — drop target highlight */
.cell-candidate {
    background: rgba(46, 204, 113, 0.25) !important;
    border: 2px dashed var(--color-green) !important;
    animation: candidate-pulse 1s ease-in-out infinite;
}

@keyframes candidate-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Placement preview — transparent block color */
.cell-preview {
    opacity: 0.35;
    border: none !important;
    animation: none;
}

/* Blast animation */
.cell-blast {
    animation: blast 0.4s ease-out forwards;
}

@keyframes blast {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.8; }
    100% { transform: scale(0); opacity: 0; }
}

/* Box features */
.box-closed {
    position: relative;
    border-color: #555 !important;
    background: repeating-linear-gradient(
        45deg, #8a7a6a, #8a7a6a 4px,
        #7a6a5a 4px, #7a6a5a 8px
    ) !important;
}
.box-closed .cell {
    visibility: hidden;
}
.box-closed::after {
    content: attr(data-box-countdown);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    z-index: 2;
    pointer-events: none;
}

.box-colored {
    border-width: 4px;
}
.box-colored-red { border-color: var(--color-red) !important; background: linear-gradient(135deg, rgba(231,76,60,0.4), rgba(231,76,60,0.15)) !important; }
.box-colored-blue { border-color: var(--color-blue) !important; background: linear-gradient(135deg, rgba(52,152,219,0.4), rgba(52,152,219,0.15)) !important; }
.box-colored-green { border-color: var(--color-green) !important; background: linear-gradient(135deg, rgba(46,204,113,0.4), rgba(46,204,113,0.15)) !important; }
.box-colored-yellow { border-color: var(--color-yellow) !important; background: linear-gradient(135deg, rgba(241,196,15,0.4), rgba(241,196,15,0.15)) !important; }
.box-colored-purple { border-color: var(--color-purple) !important; background: linear-gradient(135deg, rgba(155,89,182,0.4), rgba(155,89,182,0.15)) !important; }
.box-colored-orange { border-color: var(--color-orange) !important; background: linear-gradient(135deg, rgba(230,126,34,0.4), rgba(230,126,34,0.15)) !important; }

/* Block features */

/* Frozen — opaque ice in runtime, snowflake + countdown */
.cell-frozen { position: relative; }
.cell-frozen::before {
    content: "\2744";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    background: rgba(180, 220, 240, 0.85);
    border-radius: inherit;
    z-index: 1;
    pointer-events: none;
}
.cell-frozen[data-feature-label]:not([data-feature-label=""])::after {
    content: attr(data-feature-label);
    position: absolute;
    top: -2px;
    left: -2px;
    font-size: 0.55rem;
    color: white;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.7);
    padding: 1px 3px;
    border-radius: 3px;
    z-index: 3;
    pointer-events: none;
}

/* Fixed — 4 concentric double-ring screws per cell (2x size) */
.cell-fixed { position: relative; }
.cell-fixed::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 22% 22%, rgba(80,80,80,0.7) 4px, rgba(160,160,160,0.4) 4px, rgba(160,160,160,0.4) 7px, transparent 7px),
        radial-gradient(circle at 78% 22%, rgba(80,80,80,0.7) 4px, rgba(160,160,160,0.4) 4px, rgba(160,160,160,0.4) 7px, transparent 7px),
        radial-gradient(circle at 22% 78%, rgba(80,80,80,0.7) 4px, rgba(160,160,160,0.4) 4px, rgba(160,160,160,0.4) 7px, transparent 7px),
        radial-gradient(circle at 78% 78%, rgba(80,80,80,0.7) 4px, rgba(160,160,160,0.4) 4px, rgba(160,160,160,0.4) 7px, transparent 7px);
    z-index: 1;
    pointer-events: none;
}

/* Key — colored key icon */
.cell-key {
    position: relative;
    box-shadow: inset 0 0 0 2px var(--pair-color, rgba(241, 196, 15, 0.6)) !important;
}
.cell-key::before {
    content: "\1F511";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    background: color-mix(in srgb, var(--pair-color, rgba(241, 196, 15)) 15%, transparent);
    border-radius: inherit;
    z-index: 1;
    pointer-events: none;
}

/* Lock — colored lock icon */
.cell-locked {
    position: relative;
    box-shadow: inset 0 0 0 2px var(--pair-color, rgba(150, 150, 150, 0.6)) !important;
}
.cell-locked::before {
    content: "\1F512";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    background: color-mix(in srgb, var(--pair-color, rgba(150, 150, 150)) 15%, transparent);
    border-radius: inherit;
    z-index: 1;
    pointer-events: none;
}

/* Nested — inner color square */
.cell-nested { position: relative; }
.cell-nested::before {
    content: "";
    position: absolute;
    inset: 25%;
    background: var(--inner-color, rgba(255,255,255,0.3));
    border-radius: 2px;
    border: 1px solid rgba(0,0,0,0.3);
    z-index: 1;
    pointer-events: none;
}

/* Queue */
.queue-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-box);
    border: 1px solid var(--border-light);
}

.queue-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}


/* Timer */
.timer-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-box);
    border: 1px solid var(--border-light);
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.timer-warning {
    color: var(--color-red);
    animation: timer-pulse 0.5s ease-in-out infinite;
}

@keyframes timer-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Game Over Overlay */
.game-over-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    animation: fade-in 0.3s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.game-over-card {
    background: var(--bg-primary);
    padding: 40px 60px;
    border-radius: 20px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
    text-align: center;
    animation: slide-up 0.3s ease;
}

@keyframes slide-up {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.game-over-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 12px;
}

.game-over-win { color: var(--color-green); }
.game-over-fail { color: var(--color-red); }

.game-over-button {
    display: inline-block;
    margin-top: 20px;
    padding: 12px 40px;
    background: linear-gradient(135deg, var(--color-blue), var(--color-blue-dark));
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-button);
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
    transition: transform 0.15s ease;
}

.game-over-button:hover {
    transform: translateY(-2px);
}

.game-over-secondary {
    background: transparent;
    border: 2px solid var(--text-secondary);
    color: var(--text-secondary);
    box-shadow: none;
    margin-top: 10px;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 480px) {
    .board { gap: 8px; padding: 8px; }
    .box { padding: 4px; border-width: 2px; }
    .queue-container { gap: 8px; padding: 8px 12px; }
    .queue-label { font-size: 0.75rem; }
    .timer-container { font-size: 1.2rem; padding: 6px 14px; }
}

@media (max-width: 380px) {
    .board { gap: 6px; padding: 4px; }
    .box { padding: 3px; }
}
