/* =================================================
   1. BASIC RESET & PAGE
================================================= */

/* CARD page: override parent header spacing */
.header {
    padding: 0;
}

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

html,
body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* =================================================
   2. TOP CARD MENU
================================================= */

#menuBar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;

    background: #fff;
    padding: 10px 12px;
}

/* CARD menu title */
#menuBar > h1 {
    font-size: 1.2rem;
    margin-bottom: 4px;
}


/* =================================================
   3. HORIZONTAL MENU SCROLLING
================================================= */

/*
   The wrapper is the ONLY horizontal scrolling area.
   This prevents competing scroll containers.
*/

.horizontal-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    touch-action: pan-x;
    padding-bottom: 4px;
}

.horizontal-wrapper::-webkit-scrollbar {
    height: 6px;
}

.horizontal-wrapper::-webkit-scrollbar-track {
    background: transparent;
}

.horizontal-wrapper::-webkit-scrollbar-thumb {
    background: #bbb;
    border-radius: 10px;
}


/* =================================================
   4. CARD GROUPS
================================================= */

.CARD-groups {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    width: max-content;
}


/* Individual group */
.CARD-group {
    flex: 0 0 auto;
    min-width: 200px;
    padding: 0;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}


/* =================================================
   5. GROUP HEADER & COLLAPSE BUTTON
================================================= */

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #eaeaea;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    user-select: none;
}

.group-header h2 {
    font-size: 0.95rem;
}


/*
   The aria-expanded attribute belongs to the button,
   so the rotation selector must target .toggle-btn.
*/

.toggle-btn {
    background: transparent;
    border: none;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    transition: transform 0.2s ease;
}

/* Expanded state */
.toggle-btn[aria-expanded="true"] {
    transform: rotate(90deg);
}


/* =================================================
   6. THUMBNAILS
================================================= */

.thumbnails {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.5rem;
    background: #fafafa;
}


/*
   When collapsed, ALL thumbnails are hidden.
   JavaScript will remove/add this class.
*/

.thumbnails.collapsed {
    display: none;
}


/* Individual thumbnails */
.thumbnails img {
    width: 80px;
    height: 110px;
    object-fit: cover;

    cursor: pointer;

    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.thumbnails img:hover {
    border-color: #0077ff;
}


/* =================================================
   7. SMALL-SCREEN MENU
================================================= */

@media (max-width: 480px) {

    #menuBar {
        padding-left: 8px;
        padding-right: 8px;
    }

    .CARD-group {
        min-width: 180px;
    }
}


/* =================================================
   8. MAIN AREA
================================================= */

#mainArea {
    flex: 1;
    position: relative;
}

#canvas {
    display: block;

    margin: auto;

    background: #fff;
    border: 1px solid #ccc;

    cursor: grab;
    user-select: none;
}

#canvas:active {
    cursor: grabbing;
}


/* =================================================
   9. MAIN ZOOM CONTROLS
================================================= */

#zoomControls {
    position: absolute;
    top: 10px;
    right: 10px;

    display: flex;
    flex-direction: column;
    gap: 2px;

    background: rgba(0, 0, 0, 0.4);
    border-radius: 4px;
}

#zoomControls button {
    width: 34px;
    height: 34px;

    background: transparent;
    border: none;
    border-radius: 3px;

    color: #fff;
    font-size: 1.3rem;

    cursor: pointer;
}

#zoomControls button:hover {
    background: rgba(255, 255, 255, 0.2);
}

#btnClearAll {
    font-size: 1.1rem;
    color: #ff6b6b;
}


/* =================================================
   10. STATUS BAR
================================================= */

#statusBar {
    position: absolute;
    bottom: 10px;
    left: 10px;

    background: rgba(0, 0, 0, 0.6);
    color: #fff;

    padding: 6px 14px;
    border-radius: 4px;

    font-size: 0.85rem;
}


/* =================================================
   11. MODAL OVERLAY
================================================= */

#modalOverlay {
    position: fixed;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background: rgba(0, 0, 0, 0.6);

    z-index: 999;
}

#modalOverlay.hidden {
    display: none;
}


/* =================================================
   12. MODAL
================================================= */

#modal {
    display: flex;
    flex-direction: column;
    gap: 15px;

    max-width: 90vw;
    max-height: 90vh;

    padding: 20px;

    background: #fff;
    border-radius: 6px;

    text-align: center;
}


/* =================================================
   13. MODAL IMAGE PREVIEW
================================================= */

#modalPreview {
    width: 70vw;
    height: 70vh;

    max-width: 900px;
    max-height: 700px;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: auto;

    background: #f5f5f5;
    border-radius: 4px;
}

#modalPreview img {
    width: 100%;
    height: 100%;

    object-fit: contain;

    transform-origin: center center;
    transition: transform 0.15s ease;

    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    user-drag: none;
}


/* =================================================
   14. MODAL ZOOM CONTROLS
================================================= */

.modalZoomControls {
    display: flex;
    align-items: center;
    justify-content: center;

    gap: 12px;
}

.modalZoomControls button {
    width: 36px;
    height: 36px;

    border: none;
    border-radius: 4px;

    background: #34495e;
    color: #fff;

    font-size: 1.3rem;

    cursor: pointer;
}

.modalZoomControls button:hover {
    background: #2c3e50;
}

#modalZoomLevel {
    min-width: 55px;

    text-align: center;

    font-size: 0.9rem;
    color: #555;
}


/* =================================================
   15. MODAL ACTION BUTTONS
================================================= */

.modalButtons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;

    gap: 10px;
}

.modalButtons button {
    padding: 8px 16px;

    border: none;
    border-radius: 4px;

    font-size: 1rem;
    cursor: pointer;

    transition: background 0.2s;
}

#btnFlip {
    background: #3498db;
    color: #fff;
}

#btnUse {
    background: #27ae60;
    color: #fff;
}

#btnCancel {
    background: #c0392b;
    color: #fff;
}