/* Coloring editor */
.coloring-editor-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(17, 24, 39, 0.92);
    display: none;
    flex-direction: column;
    color: #fff;
}

.coloring-editor-overlay.is-open {
    display: flex;
}

.coloring-editor-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #111827;
    border-bottom: 1px solid #374151;
}

.coloring-editor-header h2 {
    margin: 0;
    font-size: 1rem;
    flex: 1;
    min-width: 140px;
}

.coloring-editor-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.coloring-editor-tools button,
.coloring-editor-tools label.tool-btn {
    background: #1f2937;
    border: 1px solid #4b5563;
    color: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.coloring-editor-tools button:hover,
.coloring-editor-tools label.tool-btn:hover {
    background: #374151;
}

.coloring-editor-tools button.is-active {
    background: #2563eb;
    border-color: #2563eb;
}

.coloring-editor-tools input[type="color"] {
    width: 40px;
    height: 36px;
    padding: 2px;
    border: 1px solid #4b5563;
    border-radius: 8px;
    cursor: pointer;
    background: #1f2937;
}

.coloring-editor-body {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: center;
    overflow: hidden;
    padding: 16px;
    gap: 12px;
    min-height: 0;
}

.editor-stamps-panel {
    width: 148px;
    flex-shrink: 0;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s ease, opacity 0.2s ease, margin 0.2s ease;
}

.editor-stamps-panel.is-collapsed {
    width: 0;
    opacity: 0;
    margin-left: -12px;
    border: 0;
    pointer-events: none;
}

.editor-stamps-title {
    padding: 10px 12px 8px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #9ca3af;
    border-bottom: 1px solid #374151;
}

.editor-stamp-sizes {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    border-bottom: 1px solid #374151;
    flex-wrap: wrap;
}

.editor-stamps-label {
    font-size: 0.75rem;
    color: #9ca3af;
    width: 100%;
    margin-bottom: 2px;
}

.editor-stamp-sizes button {
    flex: 1;
    background: #1f2937;
    border: 1px solid #4b5563;
    color: #fff;
    border-radius: 6px;
    padding: 5px 0;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}

.editor-stamp-sizes button:hover {
    background: #374151;
}

.editor-stamp-sizes button.is-active {
    background: #2563eb;
    border-color: #2563eb;
}

.editor-stamps-grid {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    align-content: start;
}

.editor-stamp-btn {
    aspect-ratio: 1;
    background: #1f2937;
    border: 2px solid #4b5563;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    color: #e5e7eb;
    transition: border-color 0.12s ease, background 0.12s ease;
}

.editor-stamp-btn:hover {
    background: #374151;
    border-color: #6b7280;
}

.editor-stamp-btn.is-active {
    border-color: #60a5fa;
    background: #1e3a5f;
    box-shadow: 0 0 0 1px #2563eb;
}

.editor-stamp-btn canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.coloring-editor-body .coloring-editor-stage {
    margin: auto;
}

.coloring-editor-stage {
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    background: #fff;
    touch-action: none;
}

.coloring-editor-stage canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
}

.coloring-editor-stage canvas.paint-layer {
    z-index: 1;
    cursor: crosshair;
}

.coloring-editor-stage.tool-stamp canvas.paint-layer {
    cursor: copy;
}

.coloring-editor-stage canvas.line-layer {
    z-index: 2;
    pointer-events: none;
}

.coloring-editor-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #111827;
    border-top: 1px solid #374151;
    font-size: 0.9rem;
}

.coloring-editor-progress {
    flex: 1;
    min-width: 200px;
}

.coloring-editor-progress-bar {
    height: 8px;
    background: #374151;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 6px;
}

.coloring-editor-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #22c55e, #84cc16);
    width: 0%;
    transition: width 0.2s ease;
}

.coloring-editor-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.coloring-editor-actions .btn-close {
    background: #4b5563;
}

.coloring-editor-actions .btn-save {
    background: #16a34a;
}

.coloring-editor-actions .btn-save:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.coloring-editor-hint {
    font-size: 0.8rem;
    color: #9ca3af;
    width: 100%;
}

.gallery-section {
    margin-top: 40px;
}

.gallery-section h2 {
    margin: 0 0 16px;
    font-size: 1.35rem;
}

.gallery-grid {
    display: grid;
    gap: 20px;
}

.gallery-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.gallery-grid-3:has(.gallery-item:only-child) {
    grid-template-columns: minmax(0, 420px);
    justify-content: center;
}

@media (max-width: 900px) {
    .gallery-grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 520px) {
    .gallery-grid-3 {
        grid-template-columns: 1fr;
    }
}

.gallery-item {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
    margin: 0;
    padding: 0;
}

.gallery-item-open {
    cursor: zoom-in;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.gallery-item-open:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.1);
}

.gallery-item-open:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.gallery-item img {
    width: 100%;
    aspect-ratio: 210 / 297;
    object-fit: contain;
    background: #fff;
    display: block;
    padding: 8px;
}

.gallery-item figcaption {
    padding: 10px 12px;
    font-size: 0.85rem;
    color: var(--muted);
    text-align: center;
    border-top: 1px solid var(--line);
}

.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.gallery-lightbox.is-open {
    display: flex;
}

.gallery-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.88);
}

.gallery-lightbox-panel {
    position: relative;
    z-index: 1;
    background: #fff;
    border-radius: 14px;
    max-width: min(96vw, 900px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.gallery-lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.gallery-lightbox-header h3 {
    margin: 0;
    font-size: 1rem;
}

.gallery-lightbox-close {
    background: none;
    border: 0;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 4px 8px;
}

.gallery-lightbox-body {
    padding: 16px;
    overflow: auto;
    text-align: center;
    background: #f9fafb;
}

.gallery-lightbox-body img {
    max-width: 100%;
    max-height: calc(92vh - 140px);
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.gallery-lightbox-footer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
}

.btn-color-online {
    background: linear-gradient(135deg, #7c3aed, #2563eb);
}

.btn-color-online:hover {
    background: linear-gradient(135deg, #6d28d9, #1d4ed8);
}

@media (max-width: 640px) {
    .coloring-editor-header h2 {
        width: 100%;
    }

    .coloring-editor-body {
        flex-direction: column;
        overflow: auto;
    }

    .editor-stamps-panel {
        width: 100%;
        max-height: 140px;
        order: 2;
    }

    .editor-stamps-panel.is-collapsed {
        width: 100%;
        max-height: 0;
        opacity: 0;
        margin: 0;
        padding: 0;
    }

    .editor-stamps-grid {
        grid-template-columns: repeat(5, 1fr);
        overflow-x: auto;
        overflow-y: hidden;
        flex: none;
    }

    .coloring-editor-body .coloring-editor-stage {
        order: 1;
    }
}
