/* /collage/style.css */
@page {
    size: A4 portrait;
    margin: 0;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 20px;
    font-family: sans-serif;
    background: #444;
}

.controls {
    position: relative;
    z-index: 999;
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.controls button {
    border: 0;
    font-size: 14px;
    padding: 9px 18px;
    background: #6495ed;
    color: white;
    border-radius: 2px;
    cursor: pointer;
    transition: background 0.2s;
}

.controls button:hover {
    background: #1976D2;
}

.controls button.reset {
    background: #FF9800;
}

.controls button.reset:hover {
    background: #F57C00;
}

.controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    background: white;
    padding: 9px 18px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 14px;
    user-select: none;
    transition: background 0.2s;
}

.controls label:hover {
    background: #f5f5f5;
}

.controls label.active {
    background: #E3F2FD;
}

.controls input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

#container {
    width: 210mm;
    margin: 0 auto;
    background: white;
    padding: 0;
}

.page {
    width: 210mm;
    height: 297mm;
    padding: 10mm;
    background: white;
    page-break-after: always;
    position: relative;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    isolation: isolate;
}

.page::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 0;
}

.page::after {
    content: '@Mariya_KidsPlay';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 80px;
    font-weight: 700;
    color: rgba(0, 0, 0, 0.03);
    z-index: 999;
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 10px;
    user-select: none;
}

.page:last-child {
    page-break-after: auto;
}

.grid {
    width: 190mm;
    height: 277mm;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 0px;
    position: relative;
    z-index: 1;
}

.cell {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: transparent;
    overflow: hidden;
    border: none;
    border-right: 1px dashed #ccc;
    border-bottom: 1px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Верхній ряд (перші дві комірки) */
.cell:nth-child(-n+2) {
    border-top: 1px dashed #ccc;
}

/* Лівий стовпець (1, 3, 5) */
.cell:nth-child(2n+1) {
    border-left: 1px dashed #ccc;
}

.cell.active {
    border: 2px solid #2196F3;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

.cell img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 2;
    user-select: none;
    will-change: transform;
    transform-origin: center center;
}

.cell img.movable {
    cursor: move;
    outline: 2px dashed #2196F3;
    outline-offset: -2px;
}

.zoom-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 4;
    display: none;
    gap: 5px;
}

.cell.has-image:hover .zoom-controls {
    display: flex;
}

.zoom-btn {
    width: 30px;
    height: 30px;
    background: rgba(33, 150, 243, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.zoom-btn:hover {
    background: rgba(25, 118, 210, 1);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.caption {
    position: absolute;
    top: 13px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    color: #1a375c;
    font-size: 24px;
    font-weight: 600;
    padding: 6px;
    border-radius: 2px;
    cursor: text;
    user-select: none;
    letter-spacing: 1px;
    white-space: pre-wrap;
    word-wrap: break-word;
    width: calc(100% - 20px);
    text-align: center;
    pointer-events: auto;
    will-change: transform;
}

.caption div {
    font-size: 22px;
    font-weight: 300;
    line-height: 1.3;
}

.caption.movable {
    cursor: move;
    outline: 2px dashed #2196F3;
    outline-offset: 2px;
}

.caption[contenteditable="true"]:focus {
    outline: 2px dashed #2196F3;
    user-select: text;
}

.author-signature {
    position: absolute;
    bottom: 6mm;
    right: 10mm;
    font-size: 14px;
    color: rgba(0, 0, 0, 0.55);
    z-index: 1001;
    pointer-events: none;
    user-select: none;
}

.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loader-overlay.active {
    display: flex;
}

.loader-content {
    background: white;
    padding: 30px 50px;
    border-radius: 8px;
    text-align: center;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #2196F3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-text {
    font-size: 18px;
    color: #333;
    font-weight: 500;
}

@media print {
    body {
        margin: 0;
        padding: 0;
        background: white;
    }

    .controls, .zoom-controls {
        display: none !important;
    }

    #container {
        width: 210mm;
        margin: 0;
    }

    .page {
        margin: 0;
        padding: 10mm;
        box-shadow: none;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .page::before {
        display: none;
    }

    .page::after {
        color: rgba(0, 0, 0, 0.03);
    }

    .grid {
        width: 190mm;
        height: 277mm;
    }

    .cell {
        width: 100%;
        height: 100%;
        border: 1px solid #ccc;
    }
}