/* Page layout: main editor + side gallery */
.editor-layout {
    display: flex;
    gap: var(--spacing-base);
    align-items: stretch;
    width: 100%;
    max-width: 1200px;
    height: 100%;
    min-height: 0; /* Important for flex children to shrink */
}

.editor-main {
    flex: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-base);
    min-height: 0;
    width: 100%;
}

.editor-side {
    display: flex;
    flex-direction: column;
    min-width: 200px;
    max-width: 300px;
    min-height: 0;
    border-left: 1px solid var(--border-color);
    padding: 20px;
    gap: 5px;
    flex-shrink: 0;
}

.editor-side > *, .comments-section > * {
    margin: 0;
}

.comments-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70vh;
    background-color: var(--secondary-bg);
    z-index: 1002;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /*border-top: 2px solid var(--accent-color);*/
    padding: 20px;
    box-shadow: 0 -5px 25px rgba(0,0,0,0.7);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.editor-side h2, .comments-section h2 {
    font-size: 1.2em;
    flex-shrink: 0;
}


.editor-side.open, .comments-section.open {
    transform: translateY(0);
}


.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(clamp(60px, 8vw, 100px), 1fr));
    grid-auto-rows: max-content;
    align-content: start;
    gap: 10px;
    overflow-y: auto;
    flex-grow: 1;
}

.gallery-item {
    cursor: pointer;
    aspect-ratio: 1;
    display: block;
    text-decoration: none;
}

.gallery-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
}

.capture-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-base);
    width: 100%;
    min-height: 0;
}

.webcam-frame {
    width: 100%;
    max-width: min(50vh, 500px);
    aspect-ratio: 1 / 1;
    position: relative;
    overflow: hidden;
    background-color: #000;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.carousel {
    width: 100%;
    max-width: min(80vh, 500px);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.carousel-track {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scroll-behavior: smooth;
    flex-grow: 1;
    padding-bottom: 5px;
}

.superposable-thumb {
    flex: 0 0 clamp(50px, 10vh, 80px);
    height: clamp(50px, 10vh, 80px);
    cursor: pointer;
    border: 2px solid transparent;
    box-sizing: border-box;
    object-fit: contain;
}

.editor-controls {
    display: flex;
    gap: var(--spacing-base);
    flex-shrink: 0;
}

.capture-format-switch, .editor-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 5px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.capture-view .btn-icon-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(35px, 6vh, 45px);
    height: clamp(35px, 6vh, 45px);
    min-width: clamp(35px, 6vh, 45px);
    min-height: clamp(35px, 6vh, 45px);
    aspect-ratio: 1 / 1;
    padding: 0;
    flex-shrink: 0;
    border-radius: 10px;
}

.btn-icon-nav:hover {
    background-color: #fff3;
    color: var(--accent-color);
}

.btn-icon-nav:hover .btn-icon {
    stroke: var(--accent-color);
}

.btn-icon-nav:active, .btn.active {
    background-color: white;
    color: var(--primary-bg);
}

.btn-icon-nav:active .btn-icon, .btn.active .btn-icon {
    stroke: var(--primary-bg);
}

.btn-icon {
    width: 1.5em;
    height: 1.5em;
    stroke: white;
}

.comments-section {
    min-height: 0;
}

.comments-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background-color: var(--secondary-bg);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 0.9em;
}

.comment {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

.comment:last-child {
    border-bottom: none;
}

#comment-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
    width: 100%;
    max-width: none;
    padding: 0;
    background: none;
    border: none;
    flex-shrink: 0;
}

#comment-form textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--accent-color);
    border-radius: 10px;
    background: none;
    color: var(--text-color);
    font-family: inherit;
    resize: none;
    height: 60px;
    margin-bottom: 5px;
}

#comment-form textarea.error {
    border-color: #cc333b;
}

#comment-form textarea:focus {
    outline: none;
    background-color: #fff3;
}

.capture-format-switch, .editor-actions, .editor-controls, .carousel {
    flex-shrink: 0;
}


.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    display: none;
}

.sidebar-overlay.open {
    display: block;
}

#sidebar-toggle {
    display: none;
}

@media (max-width: 800px), (max-height: 600px) {
    .editor-layout {
        flex-direction: column;
        overflow: hidden;
    }

    #sidebar-toggle {
        display: flex;
    }

    .webcam-frame {
        max-width: min(45vh, 400px);
    }

    .editor-side {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 70vh;
        background-color: var(--secondary-bg);
        z-index: 1002;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-left: none;
        /*border-top: 2px solid var(--accent-color);*/
        padding: 20px;
        gap: 5px;
        max-width: none;
        box-shadow: 0 -5px 25px rgba(0,0,0,0.7);
        border-radius: 20px 20px 0 0;
    }

    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        align-content: start;
    }
}

/* No display:block here — position:absolute already makes them block-level,
   and omitting display lets the browser's [hidden] attribute (display:none) work. */
.webcam-frame img,
.webcam-frame video,
.webcam-frame canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#upload-display {
    position: absolute;
    cursor: grab;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: none;
    object-fit: contain; /* Uploaded image should probably keep ratio inside its draggable box */
}

#upload-display:active {
    cursor: grabbing;
}

/* Overlay sits on top of the source; ignores pointer events so dragging the
   uploaded image underneath still works. */
#overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /*z-index: 1;*/
}

#camera-error {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #000c;
    color: white;
    text-align: center;
    padding: 20px;
    z-index: 10;
}

#camera-error[hidden] {
    display: none;
}

#canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    z-index: 1;
}

.superposable-thumb.selected {
    border-width: 2px;
    border-color: white;
    border-radius: 10px;
    background-color: #fff3;
}

