/* Layout & Views */

/* Sections */
.view-section {
    display: none;
}

.view-section.active {
    display: block;
}

/* Grids */
.poly-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 30px;
    animation: fadeInUp 0.8s ease-out 0.4s both;
}

@media (max-width: 768px) {
    .poly-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px;
    }
}

/* Generator View */
.generator-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .generator-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .generator-controls .btn-size {
        grid-column: span 2;
    }

    .generator-controls .input-group {
        justify-content: center;
    }
}

.interactive-grid {
    display: grid;
    position: relative;
    justify-content: center;
    gap: 4px;
    margin: 0 auto 40px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    width: fit-content;
}

.interactive-grid .cell {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.interactive-grid .cell.obstacle {
    background: #000;
    border: 3px solid #fff;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
}

@media (max-width: 768px) {
    .interactive-grid .cell {
        width: 35px;
        height: 35px;
    }
}

/* Playground Layout */
.playground-layout {
    display: flex;
    gap: 30px;
    margin: 20px 0;
    align-items: center;
}

.playground-main {
    flex: 1;
    min-width: 0;
}

.playground-sidebar {
    width: 350px;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 80vh;
    overflow-y: auto;
    backdrop-filter: blur(10px);
}

@media (max-width: 1000px) {
    .playground-layout {
        flex-direction: column;
    }

    .playground-sidebar {
        width: 100%;
        max-height: none;
    }
}

/* Playground Grid */
.stage-nav-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.nav-btn-side {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    z-index: 100;
}

.nav-btn-side:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-color);
    color: var(--accent-color);
    transform: scale(1.1);
}

.nav-btn-side:disabled {
    opacity: 0;
    pointer-events: none;
}

.playground-grid-container {
    padding: 20px 100px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    border: 2px dashed var(--glass-border);
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: visible;
}

@media (max-width: 768px) {
    .playground-sidebar {
        width: 320px;
        max-width: calc(100vw - 40px);
        max-height: 70vh;
        /* Collapsible on mobile */
        /* See .palette-mobile-container usage below */
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
        background: var(--glass-bg);
        margin-bottom: 10px;
    }

    .playground-sidebar.collapsed {
        display: none;
    }

    .playground-grid-container {
        padding: 20px;
        min-height: 400px;
    }

    #factory-view .palette-mobile-container {
        position: static;
        display: block;
        pointer-events: auto;
        margin-top: 20px;
        z-index: auto;
    }

    #factory-view .palette-toggle-btn {
        display: none !important;
    }

    #factory-view .playground-sidebar {
        display: flex !important;
        /* Always visible */
        width: 100%;
        max-width: none;
        max-height: none;
        margin-bottom: 20px;
        position: static;
        box-shadow: none;
        background: var(--card-bg);
        padding: 15px;
    }

    #factory-view .palette-container {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px;
    }
}

/* Mobile Palette Styling */
.palette-mobile-container {
    display: block;
    /* Desktop default - Visible */
}

@media (max-width: 768px) {
    .palette-mobile-container {
        display: flex;
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 1000;
        flex-direction: column;
        align-items: flex-end;
        pointer-events: none;
    }

    .palette-mobile-container>* {
        pointer-events: auto;
    }
}

.palette-toggle-btn {
    display: none;
    /* Desktop default */
}

@media (max-width: 768px) {
    .palette-toggle-btn {
        display: flex;
        width: 50px;
        height: 50px;
        background: var(--accent-gradient);
        color: white;
        border: none;
        border-radius: 50%;
        cursor: grab;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        box-shadow: 0 4px 15px rgba(0, 210, 255, 0.4);
        touch-action: none;
    }
}

/* Palette Items grid */
.palette-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    padding: 10px;
}

.palette-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 15px;
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 120px;
    position: relative;
    z-index: 1;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    touch-action: none;
}

.palette-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: var(--accent-color);
}

.palette-item.active {
    border-color: var(--accent-color);
    background: rgba(0, 210, 255, 0.12) !important;
    box-shadow: 0 0 25px rgba(0, 210, 255, 0.4), inset 0 0 15px rgba(0, 210, 255, 0.2);
    outline: 2px dashed rgba(255, 255, 255, 0.8);
    outline-offset: 4px;
    transform: translateY(-4px) scale(1.02);
    z-index: 100;
}

.palette-item.enabled {
    opacity: 1;
}

.palette-item.disabled {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
    cursor: default;
}

.palette-item.used {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
    position: relative;
}

.palette-item.used::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    color: var(--accent-color);
    font-weight: bold;
}

.palette-item .visual-grid {
    pointer-events: none;
    transform: scale(0.8);
    max-width: 100%;
    max-height: 100%;
}

/* Placed Pieces */
.placed-piece {
    position: absolute;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.placed-piece:active {
    cursor: grabbing;
}

.placed-piece .visual-grid {
    pointer-events: none;
}

.placed-piece.selected {
    z-index: 100;
    filter: drop-shadow(0 0 4px #fff) drop-shadow(0 0 2px var(--accent-color));
    outline: 2px dashed rgba(255, 255, 255, 0.8);
    outline-offset: 4px;
}

@media (max-width: 768px) {
    .palette-container {
        grid-template-columns: repeat(2, 1fr) !important;
        max-height: 295px;
        overflow-y: auto;
    }

    .palette-item {
        width: 100%;
        height: 120px;
        padding: 5px;
    }
}

/* Stage Mode */
.level-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding: 20px 0;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 15px;
    padding: 20px 0;
}

@media (max-width: 768px) {
    .level-list {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px;
        width: 100%;
        max-width: 400px;
        margin: 0 auto;
    }

    .level-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 8px;
        width: 100%;
        max-width: 400px;
        margin: 0 auto;
    }

    .level-btn {
        font-size: 1.1rem;
        border-radius: 8px;
    }

    .generator-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .generator-controls .btn-size {
        grid-column: span 2;
    }
}

.level-btn {
    aspect-ratio: 1;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
}

.level-btn.completed {
    background: rgba(0, 210, 255, 0.1);
    color: var(--accent-color);
    border-color: var(--accent-color);
}

.level-btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(0, 0, 0, 0.3);
}

.level-btn.locked::after {
    content: '🔒';
    font-size: 1rem;
    position: absolute;
}

/* Hidden Print Area */
#print-area {
    display: none;
}

#drag-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* Print Mode */
@media print {
    body.print-mode {
        background: white;
        color: black;
        overflow: visible;
    }

    body.print-mode header,
    body.print-mode .tabs,
    body.print-mode #app,
    body.print-mode footer,
    body.print-mode #drag-layer,
    body.print-mode .overlay {
        display: none !important;
    }

    body.print-mode #print-area {
        display: block !important;
        width: 100%;
    }

    /* Patterns Grid - 3 per row */
    .print-patterns-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        row-gap: 20px;
        width: 100%;
    }

    .poly-card.print-card {
        background: none;
        box-shadow: none;
        backdrop-filter: none;
        display: flex !important;
        justify-content: center;
        align-items: center;
        border: 1px dashed #aaa;
        border-radius: 8px;
        padding: 5px;
        margin: 0;
        break-inside: avoid;
        page-break-inside: avoid;
        transform: none !important;
    }

    .poly-card.print-card .poly-info {
        display: none;
    }

    .block {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        box-shadow: none !important;
    }

    .printable-board .block {
        background: white !important;
        border: 1px solid black;
    }

    .print-board-container {
        display: flex;
        justify-content: center;
        padding-top: 50px;
    }

    .print-board-section {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-top: 80px;
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* Outline Mode (Theming) */
body.print-outline .block.filled {
    background: white !important;
    border: 1px solid #000;
}

body.print-outline .block.empty {
    border: none;
}

/* Ensure board always has borders even in outline mode */
body.print-outline .printable-board .block {
    background: white !important;
    border: 1px solid black !important;
}

/* Print Tools Section */
.print-tools-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 50px;
    margin-top: 50px;
    break-inside: avoid;
    page-break-inside: avoid;
}

.print-obstacles-container {
    display: flex;
    gap: 10px;
}

/* Obstacle Style: Black with White Border & Black Stroke */
/* Note: We use box-shadow to simulate the outer stroke/double border effect if needed, 
   but user asked for "black and white border+black stroke".
   Let's try: Border white, Box-shadow black. */
.print-obstacle-card .block {
    background: black !important;
    border: 2px solid white !important;
    box-shadow: 0 0 0 1px black !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Wood Marker Style */
.wood-texture {
    background: #8B4513 !important;
    border: none !important;
    background-image: repeating-linear-gradient(45deg,
            rgba(255, 255, 255, 0.1) 0px,
            rgba(255, 255, 255, 0.1) 2px,
            transparent 2px,
            transparent 4px),
        repeating-linear-gradient(-45deg,
            rgba(0, 0, 0, 0.1) 0px,
            rgba(0, 0, 0, 0.1) 1px,
            transparent 1px,
            transparent 3px) !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}