:root {
    /* Diameter of the printed image inside each 2in circle slot. The remaining
       space is the transparent ring where a physical scratch sticker is placed.
       This single value drives the on-screen preview AND the PDF/print output so
       they always match — tweak it here only. */
    --circle-img-size: 1.9in;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 250px;
    background: white;
    border-right: 1px solid #ddd;
    padding: 20px;
    overflow-y: auto;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
}

.sidebar h1 {
    font-size: 24px;
    margin-bottom: 20px;
    color: #333;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 30px;
}

.save-status {
    font-size: 12px;
    color: #666;
    text-align: center;
    padding: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    margin-top: 10px;
}

.save-status.saved {
    color: #4caf50;
    background: #e8f5e9;
}

.save-status.error {
    color: #d32f2f;
    background: #ffebee;
}

.btn {
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-primary {
    background: #007bff;
    color: white;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.upload-controls-sidebar {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
}

.image-gallery-sidebar {
    background: #f9f9f9;
    padding: 12px;
    border-radius: 4px;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.image-gallery-sidebar h3 {
    font-size: 12px;
    margin: 0 0 8px 0;
    color: #555;
}

.help-text {
    font-size: 10px;
    color: #777;
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.gallery-drop-zone {
    border: 2px dashed #ddd;
    border-radius: 4px;
    padding: 12px;
    text-align: center;
    margin-bottom: 8px;
    background: #fafafa;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-drop-zone.drag-over {
    border-color: #ff1493;
    background: rgba(255, 20, 147, 0.1);
    box-shadow: inset 0 0 0 2px #ff1493;
}

.drop-hint {
    font-size: 11px;
    color: #999;
    margin: 0;
    pointer-events: none;
}

.gallery-container-sidebar {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    overflow-y: auto;
    flex: 1;
}

.main-content {
    flex: 1;
    padding: 30px;
    overflow: auto;
    background: #f5f5f5;
}

.preview-container {
    max-width: 900px;
    margin: 0 auto;
}

#imageInput {
    display: none;
}

.file-label {
    display: inline-block;
    padding: 12px 20px;
    background: #007bff;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.file-label:hover {
    background: #0056b3;
}

.gallery-image {
    width: 80px;
    height: 80px;
    border: 2px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    cursor: grab;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.gallery-image:hover {
    border-color: #007bff;
    box-shadow: 0 0 8px rgba(0, 123, 255, 0.3);
    transform: scale(1.05);
}

.gallery-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pdf-preview {
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 0;
}

.page {
    width: 100%;
    aspect-ratio: 8.5 / 11;
    display: flex;
    flex-direction: column;
    background: white;
}

.match3-page {
    flex: 1;
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    justify-content: center;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    position: relative;
    transition: box-shadow 0.2s ease;
}

.match3-page.drag-over-bg {
    box-shadow: inset 0 0 0 3px #ff1493;
}

.match3-top {
    border-bottom: 1px solid #eee;
}

.match3-page h2 {
    font-size: 60pt;
    color: #ff1493;
    text-align: center;
    margin: 0;
    font-family: 'Brush Script MT', 'Lucida Handwriting', cursive;
    font-weight: bold;
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.3);
    letter-spacing: 2px;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    background: rgba(255, 255, 255, 0.85);
    padding: 8px 24px;
    border-radius: 8px;
    backdrop-filter: blur(4px);
}

.editable-title {
    outline: none;
    padding: 5px 10px;
    border-radius: 4px;
    transition: all 0.2s ease;
    cursor: text;
}

.editable-title:hover {
    background: rgba(255, 255, 255, 0.1);
}

.editable-title:focus {
    background: rgba(255, 255, 255, 0.2);
    outline: 2px solid #ff6b9d;
}

.circles-grid {
    display: grid;
    grid-template-columns: repeat(3, 2in);
    gap: 15px;
    width: 100%;
    justify-content: center;
    align-items: center;
}

.circle-slot {
    width: 2in;
    height: 2in;
    margin: 0 auto;
    border-radius: 50%;
    border: none;
    overflow: hidden;
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.circle-slot:hover {
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.3);
}

.circle-slot[style*="opacity: 0.7"] {
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.6);
    transform: scale(1.05);
}

.circle-slot img {
    width: var(--circle-img-size);
    height: var(--circle-img-size);
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.circle-slot.empty {
    background: #f9f9f9;
    border: 2px dashed #ddd;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: #fefefe;
    margin: 50px auto;
    padding: 30px;
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-height: 85vh;
    overflow-y: auto;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
}

.close:hover {
    color: #000;
}

.modal h2 {
    margin-bottom: 20px;
    color: #333;
    font-size: 20px;
}

.modal-body {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.preview-section {
    display: flex;
    gap: 30px;
    margin-bottom: 20px;
}

.preview-preview {
    flex: 1;
    text-align: center;
}

.preview-preview h3 {
    margin-bottom: 15px;
    font-size: 14px;
    color: #555;
}

#previewCanvas {
    width: 200px;
    height: 200px;
    border: none;
    border-radius: 50%;
    background: white;
    display: block;
    margin: 0 auto;
    cursor: grab;
    overflow: hidden;
}

.preview-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-size: 12px;
    color: #555;
    font-weight: 500;
}

.control-group input[type="range"] {
    width: 100%;
}

.control-group span {
    font-size: 12px;
    color: #999;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-actions .btn {
    flex: 1;
    max-width: 150px;
}

/* Export mode tweaks so html2pdf captures tight layout (print media isn't used there) */
body.exporting .page {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    width: 8.5in !important;
    height: 11in !important;
    aspect-ratio: auto !important;
}

body.exporting .match3-page {
    padding: 0 !important;
    margin: 0 !important;
    gap: 2px !important;
    justify-content: flex-start !important;
    align-items: center !important;
    flex: 1 !important;
    height: 50% !important;
}

@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #ddd;
        max-height: 150px;
    }

    .circles-grid {
        gap: 20px;
    }

    .match3-page {
        padding: 20px;
        gap: 20px;
    }

    .preview-section {
        flex-direction: column;
    }

    .circle-slot {
        max-width: 120px;
    }
}

@media print {
    @page {
        margin: 0;
    }

    body {
        background: white;
        margin: 0;
        padding: 0;
    }

    .pdf-preview {
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
    }

    .page {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 0 !important;
        width: 8.5in !important;
        height: 11in !important;
        aspect-ratio: auto !important;
    }

    .sidebar, .main-content {
        display: none;
    }

    .pdf-preview {
        box-shadow: none;
    }

    .match3-page {
        padding: 0 !important;
        gap: 0 !important;
        align-items: center !important;
        margin: 0 !important;
        flex: 1 !important;
    }
    
    .match3-page h2 {
        color: #ff1493 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        font-weight: bold !important;
        margin: 0 !important;
        padding: 0 !important;
        flex: 1 !important;
        min-height: 50% !important;
        display: block !important;
        background: transparent !important;
        border-radius: 0 !important;
        align-self: center !important;
        text-align: center !important;
    }
    
    .circles-grid {
        gap: 10px !important;
    }
    
    .circle-slot {
        border-radius: 50% !important;
        border: none !important;
        width: 2in !important;
        height: 2in !important;
        flex-shrink: 0 !important;
        overflow: hidden !important;
        background: transparent !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .circle-slot img {
        border-radius: 50% !important;
        width: var(--circle-img-size) !important;
        height: var(--circle-img-size) !important;
        object-fit: cover !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}
