@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap');

:root {
    --bg: #faf0e6;
    --panel: rgba(255, 255, 255, .8);
    --shadow: 0 8px 32px rgba(0, 0, 0, .1);
    --btn: #ffe4e1;
    --btnText: #8b4513;
    --navH: 54px;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: 'Prompt', system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: #333;
}

img {
    user-select: none;
}

.topnav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navH);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    z-index: 20;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, .1);
}

.topnav .brand {
    color: #8b4513;
    text-decoration: none;
    font-weight: 700;
}

.topnav .links {
    display: flex;
    gap: 8px;
}

.topnav .links a {
    color: #333;
    text-decoration: none;
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .8);
    border: 1px solid rgba(0, 0, 0, .1);
}

.topnav .links a.active {
    background: #ffe4e1;
    color: #8b4513;
    border-color: transparent;
}

button {
    border: 0;
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--btn);
    color: var(--btnText);
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .1);
    transition: transform .08s ease, opacity .15s ease;
}

button:active {
    transform: scale(.98);
}

button.soft {
    background: rgba(255, 255, 255, .8);
    color: #333;
    border: 1px solid rgba(0, 0, 0, .1);
    box-shadow: none;
}

.productWrap {
    padding-top: calc(var(--navH) + 12px);
    padding-bottom: 18px;
    min-height: 100vh;
}

.productTop {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 12px 10px;
}

.productTitle h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
}

.productTitle p {
    margin: 6px 0 0;
    color: rgba(255, 255, 255, .75);
    font-size: 12.5px;
}

.productActions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.pill {
    color: #333;
    background: rgba(255, 255, 255, .8);
    padding: 8px 10px;
    border-radius: 999px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(0, 0, 0, .1);
}

.charmCount {
    opacity: .8;
    margin-left: 6px;
}

.board {
    position: relative;
    margin: 0 12px;
    height: min(52vh, 420px);
    background: rgba(255, 255, 255, .8);
    border: 1px solid rgba(0, 0, 0, .1);
    border-radius: 18px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .1);
    overflow: hidden;
}

.board.dragOver {
    outline: 2px dashed rgba(255, 255, 255, .55);
    outline-offset: -10px;
}

.boardHint {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    text-align: center;
    color: rgba(139, 69, 19, .8);
    padding: 18px;
    font-size: 14px;
}

.boardHint small {
    display: block;
    margin-top: 8px;
    color: rgba(255, 255, 255, .65);
    font-size: 12px;
}

.neckline {
    position: absolute;
    left: 6%;
    right: 6%;
    top: 52%;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(139, 69, 19, .3), transparent);
    opacity: .85;
}

.piece {
    position: absolute;
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.piece.active {
    cursor: grabbing;
    transform: scale(1.02);
}

.piece img {
    width: 46px;
    height: 46px;
    object-fit: contain;
    border-radius: 12px;
    pointer-events: none;
}

.tray {
    margin: 12px 12px 0;
    overflow: hidden;
}

.trayHead {
    padding: 10px 10px 0;
}

.trayList {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    position: relative;
}

.trayList::after {
    content: "";
    position: sticky;
    left: 0;
    right: 0;
    bottom: 0;
    height: 10px;
    margin-top: -10px;
    pointer-events: none;
    background: linear-gradient(to bottom,
            transparent,
            rgba(255, 255, 255, .14),
            transparent);
    opacity: .75;
}

.trayList::-webkit-scrollbar {
    height: 10px;
}

.trayList::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .22);
    border-radius: 999px;
}

.trayItem {
    position: relative;
    flex: 0 0 auto;
    scroll-snap-align: start;
    width: 88px;
    height: 88px;
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, .1);
    background: rgba(255, 255, 255, .8);
    box-shadow: 0 4px 16px rgba(0, 0, 0, .1);

    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.trayItem img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.trayMeta {
    display: none !important;
}

.tagPrice {
    position: static;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .45);
    border: 1px solid rgba(255, 255, 255, .16);
    line-height: 1;
    color: #fff;

    /* ซ่อนราคา */
    display: none !important;
}

/* ===== Price bar ===== */
.priceBar {
    padding: 8px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, .10);
    background: rgba(255, 255, 255, .05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.priceTitle {
    font-size: 11px;
    /* จาก 12px */
    opacity: .75;
}

.priceTotal {
    font-size: 18px;
    /* จาก 22px */
    font-weight: 700;
    line-height: 1.1;
}

.priceMeta {
    font-size: 11px;
    /* จาก 12px */
    opacity: .8;
}

img.charm {
    width: 64px;
    height: 64px;
    object-fit: contain;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    cursor: grab;
    flex: 0 0 auto;
}

img.charm:active {
    cursor: grabbing;
}

.baseBar {
    margin: 12px 12px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.baseList {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 6px 2px;
    flex: 1;
}

.baseList::-webkit-scrollbar {
    height: 8px;
}

.baseList::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .18);
    border-radius: 999px;
}

.baseItem {
    flex: 0 0 auto;
    width: 92px;
    height: 92px;
    border-radius: 16px;
    background: rgba(255, 255, 255, .8);
    border: 1px solid rgba(0, 0, 0, .1);
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 8px;
}

.baseItem img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.baseMeta {
    display: none !important;
}

.baseItem.active {
    background: #ffe4e1;
    border-color: transparent;
}

.baseItem.active img {
    filter: none;
}

.baseLayer {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    z-index: 1;
}

.piece {
    z-index: 3;
}

.basePiece {
    position: absolute;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.basePiece.active {
    cursor: grabbing;
}

.basePiece img {
    width: min(300px, 70%);
    height: auto;
    object-fit: contain;
    pointer-events: none;
}

#trayList,
.board,
.piece,
.basePiece,
img.charm {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.dragGhost {
    position: fixed;
    width: 52px;
    height: 52px;
    object-fit: contain;
    pointer-events: none;
    z-index: 9999;
    opacity: .95;
    transform: translateZ(0);
}

.transformUI {
    --transform-arrow-x: 50%;

    /*
     * ใช้ fixed เพราะ transformUI
     * อยู่นอก Board ใน product.php
     */
    position: fixed;
    z-index: 100500;

    display: flex;
    align-items: center;
    gap: 6px;

    width: max-content;
    max-width: calc(100vw - 16px);

    padding: 7px;

    background:
        rgba(255,
            253,
            251,
            .97);

    border:
        1px solid rgba(139,
            69,
            19,
            .13);

    border-radius: 15px;

    box-shadow:
        0 14px 32px rgba(92,
            52,
            34,
            .16),

        0 3px 10px rgba(92,
            52,
            34,
            .08);

    backdrop-filter:
        blur(14px);

    -webkit-backdrop-filter:
        blur(14px);
}

.transformUI.hidden {
    display: none;
}

.transformUI button {
    position: relative;

    width: 36px;
    height: 36px;

    display: grid;
    place-items: center;

    padding: 0;

    border:
        1px solid rgba(139,
            69,
            19,
            .11);

    border-radius: 50%;

    color: #8b4513;

    background:
        linear-gradient(180deg,
            #fff5f2,
            #ffe3de);

    font-size: 16px;
    font-weight: 900;
    line-height: 1;

    cursor: pointer;

    box-shadow:
        0 4px 10px rgba(139,
            69,
            19,
            .07);

    transition:
        transform .16s ease,
        box-shadow .16s ease,
        background .16s ease;
}

.transformUI button:hover {
    transform:
        translateY(-2px);

    background:
        linear-gradient(180deg,
            #fff9f7,
            #ffd9d2);

    box-shadow:
        0 8px 16px rgba(139,
            69,
            19,
            .12);
}

.transformUI button:active {
    transform: scale(.95);
}

.transformUI button[hidden] {
    display: none;
}

.transformUI .transformDelete {
    color: #b64141;

    background:
        linear-gradient(180deg,
            #fff4f4,
            #ffdddd);
}

.transformUI button::after {
    content: attr(data-tip);

    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    z-index: 4;

    width: max-content;
    max-width: 130px;

    padding: 5px 8px;

    color: #fff;

    background:
        rgba(58,
            39,
            30,
            .95);

    border-radius: 8px;

    font-size: 10px;
    font-weight: 700;
    line-height: 1.2;

    white-space: nowrap;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transform:
        translate(-50%,
            4px);

    transition:
        opacity .16s ease,
        transform .16s ease,
        visibility .16s ease;
}

.transformUI button:hover::after,
.transformUI button:focus-visible::after {
    opacity: 1;
    visibility: visible;

    transform:
        translate(-50%,
            0);
}

.transformUI.placeBelow button::after {
    top: calc(100% + 8px);
    bottom: auto;

    transform:
        translate(-50%,
            -4px);
}

.transformUI.placeBelow button:hover::after,
.transformUI.placeBelow button:focus-visible::after {
    transform:
        translate(-50%,
            0);
}

.transformArrow {
    position: absolute;

    left:
        var(--transform-arrow-x);

    bottom: -7px;

    width: 14px;
    height: 14px;

    background:
        rgba(255,
            253,
            251,
            .97);

    border-right:
        1px solid rgba(139,
            69,
            19,
            .13);

    border-bottom:
        1px solid rgba(139,
            69,
            19,
            .13);

    transform:
        translateX(-50%) rotate(45deg);
}

.transformUI.placeBelow .transformArrow {
    top: -7px;
    bottom: auto;

    border: 0;

    border-left:
        1px solid rgba(139,
            69,
            19,
            .13);

    border-top:
        1px solid rgba(139,
            69,
            19,
            .13);
}


.piece.isTransformSelected img,
.basePiece.isTransformSelected img {
    filter:
        drop-shadow(0 7px 12px rgba(139,
                69,
                19,
                .22));
}

.board,
.baseLayer,
.piece,
.basePiece {
    touch-action: none;
}

html.lockScroll,
body.lockScroll {
    height: 100%;
    overflow: hidden !important;
}

body {
    overscroll-behavior-y: none;
}

@media (hover: none) and (pointer: coarse) {

    html,
    body {
        height: 100%;
        overflow: hidden;
        overscroll-behavior: none;
    }

    .productWrap {
        min-height: 100dvh;
        height: 100dvh;
        padding-top: calc(var(--navH) + 8px);
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        display: flex;
        flex-direction: column;
        gap: 10px;
        overflow: hidden;
    }

    /* Make the picker panel scrollable on small screens so long lists of charms don't get cut off */
    .pickerPanel {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .productTop {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 12px 0;
    }

        .productActions {
            width: 100%;
    
            display: flex;
            align-items: center;
            justify-content: center;
    
            /*
         * ไม่อนุญาตให้ปุ่ม AI ตกลงแถวใหม่
         */
            flex-wrap: nowrap;
    
            gap: 5px;
        }
    
        .productActions button {
            /*
         * ให้ปุ่มย่อตามพื้นที่หน้าจอ
         * แต่ไม่ตัดข้อความและไม่ขึ้นบรรทัดใหม่
         */
            flex: 0 1 auto;
            min-width: 0;
    
            padding:
                8px clamp(5px, 1.8vw, 8px);
    
            font-size:
                clamp(9px, 2.55vw, 11px);
    
            line-height: 1.2;
            white-space: nowrap;
    
            border-radius: 10px;
        }
    
        #btnAiDesigner {
            /*
         * ปุ่ม AI มีข้อความยาวที่สุด
         * อนุญาตให้ย่อได้มากกว่าปุ่มอื่นเล็กน้อย
         */
            flex-shrink: 1;
        }

    button {
        padding: 9px 10px;
        font-size: 13px;
    }

    .board {
        margin: 0 12px;
        height: 230px;
        flex: 0 0 auto;
    }

    .tray,
    .baseBar {
        flex: 0 0 auto;
    }

    .trayList,
    .baseList {
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        overscroll-behavior-y: none;
        touch-action: pan-x;
        -webkit-overflow-scrolling: auto;
    }

    img.charm,
    .piece,
    .basePiece {
        touch-action: none;
    }

    img.charm {
        width: 56px;
        height: 56px;
    }

    .trayList {
        padding: 8px;
        gap: 8px;
    }

    .baseList {
        padding: 4px 2px;
        gap: 8px;
    }

    .baseItem {
        width: 84px;
        height: 84px;
    }

    .baseItem img {
        width: 74px;
        height: 74px;
    }

    .basePiece img {
        width: min(260px, 70%);
    }
}

@media print {
    body {
        background: #fff !important;
        color: #111 !important;
    }

    .topnav,
    .productTop,
    .tray {
        display: none !important;
    }

    .board {
        height: 80vh !important;
        margin: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
        background: #fff !important;
    }

    .neckline {
        opacity: .25 !important;
    }
}

:root {
    --bg: #faf0e6;
    --panel: rgba(255, 255, 255, .82);
    --panel-strong: rgba(255, 255, 255, .92);
    --line: rgba(139, 69, 19, .12);
    --text-main: #5c3822;
    --text-soft: rgba(92, 56, 34, .68);
    --accent: #f6d9d5;
    --accent-strong: #efc3bc;
    --white: #fffdfb;
    --shadow-soft: 0 10px 30px rgba(139, 69, 19, .08);
    --shadow-card: 0 6px 18px rgba(139, 69, 19, .08);
}

/* ===== Picker Panel ===== */
.pickerPanel {
    margin: 12px;
    padding: 12px;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .86), rgba(255, 250, 246, .92));
    border: 1px solid rgba(139, 69, 19, .08);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.pickerTabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 4px;
    border-radius: 18px;
    background: rgba(139, 69, 19, .05);
    margin-bottom: 14px;
}

.pickerTab {
    border: 0;
    border-radius: 14px;
    padding: 12px 14px;
    background: transparent;
    color: var(--text-soft);
    font-weight: 600;
    box-shadow: none;
}

.pickerTab.active {
    background: var(--panel-strong);
    color: var(--text-main);
    border: 1px solid rgba(139, 69, 19, .08);
    box-shadow: 0 4px 12px rgba(139, 69, 19, .08);
}

.countBadge {
    font-size: 12px;
    opacity: .7;
    margin-left: 4px;
}

.pickerSection {
    display: none;
}

.pickerSection.active {
    display: block;
}

.sectionHead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.sectionHead h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text-main);
}

.sectionHead p {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--text-soft);
}

/* ===== Base Grid ===== */
.baseGrid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    max-height: 320px;
    overflow-y: auto;
    padding: 2px;
}

.baseGrid::-webkit-scrollbar {
    width: 8px;
}

.baseGrid::-webkit-scrollbar-thumb {
    background: rgba(139, 69, 19, .16);
    border-radius: 999px;
}

.baseItem {
    width: 100%;
    height: 92px;
    padding: 8px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, .96), rgba(248, 241, 236, .95));
    border: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: var(--shadow-card);
}

.baseItem img {
    max-width: 84%;
    max-height: 84%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
    pointer-events: none;
}

.baseMeta {
    display: none !important;
}

.baseName {
    font-size: 11px;
    color: var(--text-main);
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    display: none !important;
}

.basePrice {
    font-size: 11px;
    color: var(--text-soft);
    display: none !important;
}

.baseItem.active {
    background: linear-gradient(180deg, #fff8f6, #ffe9e4);
    border-color: rgba(139, 69, 19, .18);
    box-shadow: 0 10px 24px rgba(239, 195, 188, .45);
    transform: translateY(-1px);
}

.baseItem.active::after {
    content: "✓";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #8b4513;
    color: white;
    font-size: 12px;
    display: grid;
    place-items: center;
}

.trayCategories {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 10px;
    margin-bottom: 4px;
    scrollbar-width: none;
}

.trayCategories::-webkit-scrollbar {
    display: none;
}

.catChip {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .72);
    color: var(--text-soft);
    border-radius: 999px;
    padding: 9px 14px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: none;
}

.catChip.active {
    background: #8b4513;
    color: #fff;
    border-color: transparent;
    box-shadow: 0 8px 16px rgba(139, 69, 19, .18);
}

.trayGrid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    max-height: 320px;
    overflow-y: auto;
    padding: 2px;
}

.trayGrid::-webkit-scrollbar {
    width: 8px;
}

.trayGrid::-webkit-scrollbar-thumb {
    background: rgba(139, 69, 19, .16);
    border-radius: 999px;
}

.trayItem {
    position: relative;
    width: 100%;
    height: 92px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(255, 255, 255, .96), rgba(248, 241, 236, .96));
    box-shadow: var(--shadow-card);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.trayItem:hover {
    transform: translateY(-1px);
}

.trayItem img {
    max-width: 84%;
    max-height: 84%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
    pointer-events: none;
}

.trayMeta {
    display: none !important;
}

.trayName {
    font-size: 10px;
    line-height: 1.15;
    text-align: center;
    color: var(--text-main);
    font-weight: 600;
    display: none !important;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tagPrice {
    display: none !important;
    position: static;
    font-size: 10px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    border: 0;
    line-height: 1.1;
    color: var(--text-soft);
    font-weight: 500;
}

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

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

@media (hover: none) and (pointer: coarse) {
    .pickerPanel {
        margin: 10px 12px 8px;
        padding: 10px;
        border-radius: 22px;
    }

    .trayGrid {
        max-height: 270px;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 8px;
    }

    .trayItem {
        width: 88px;
        height: 88px;
        border-radius: 16px;
    }

    .baseItem {
        width: 92px;
        height: 92px;
    }
}

/* ปรับกริดให้พอดีหน้าจอมือถือขนาดเล็ก */
@media (max-width: 420px) {
    /* ฐานนาฬิกาเลื่อนขึ้นลงได้เหมือนชาร์ม */
    .baseGrid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-height: 260px;
        overflow-y: auto;
        padding: 8px 6px;
        gap: 10px;
    }

    .baseItem {
        width: 100%;
        height: 84px;
    }

        /* ปรับกริดชาร์มให้สมส่วนบนมือถือ */
        .trayGrid {
            /*
         * ใช้ 4 ชิ้นต่อแถว
         * ลดขนาดการ์ดไม่ให้ใหญ่และห่างเกินไป
         */
            grid-template-columns:
                repeat(4,
                    minmax(0, 1fr));
    
            gap: 8px;
            padding: 4px;
    
            align-items: stretch;
        }
    
        /*
     * ให้การ์ดเป็นสี่เหลี่ยมจัตุรัส
     * และขยายตามขนาดคอลัมน์
     */
        .trayItem {
            width: 100%;
            height: auto;
    
            aspect-ratio: 1 / 1;
    
            margin: 0;
            padding: 6px;
    
            border-radius: 14px;
        }
    
        /*
     * ทำให้รูปชาร์มแต่ละลาย
     * แสดงอยู่ในพื้นที่ขนาดเดียวกัน
     */
        .trayItem img,
        .trayItem img.charm {
            width: 76%;
            height: 76%;
    
            max-width: none;
            max-height: none;
    
            object-fit: contain;
            object-position: center;
        }
}


/* ===== Tablet / iPad support ===== */
@media (min-width: 768px) and (max-width: 1180px) {
    :root {
        --navH: 62px;
    }

    .topnav {
        padding: 12px 18px;
    }

    .topnav .brand {
        font-size: 18px;
    }

    .topnav .links a {
        font-size: 14px;
        padding: 9px 14px;
    }

    .productWrap {
        padding-top: calc(var(--navH) + 18px);
        padding-bottom: 24px;
    }

    .productTop {
        padding: 12px 18px;
    }

    .productActions {
        gap: 10px;
    }

    .productActions button {
        font-size: 14px;
        padding: 11px 16px;
    }

    .board {
        margin: 0 18px;
        height: min(46vh, 500px);
        border-radius: 22px;
    }

    .boardHint {
        font-size: 15px;
    }

    .piece {
        width: 64px;
        height: 64px;
    }

    .piece img {
        width: 52px;
        height: 52px;
    }

    .basePiece img {
        width: min(360px, 72%);
    }

    .pickerPanel {
        margin: 14px 18px 18px;
        padding: 14px;
        border-radius: 26px;
    }

    .pickerTab {
        font-size: 14px;
        padding: 13px 16px;
    }

    .sectionHead h3 {
        font-size: 17px;
    }

    .trayCategories {
        gap: 10px;
        padding-bottom: 12px;
    }

    .catChip {
        font-size: 13px;
        padding: 10px 15px;
    }

    .baseGrid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        max-height: 360px;
        gap: 12px;
    }

    .trayGrid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        max-height: 380px;
        gap: 12px;
    }

    .baseItem,
    .trayItem {
        width: 100%;
        height: 100px;
        border-radius: 20px;
    }

        .transformUI {
            max-width:
                calc(100vw - 12px);
    
            padding: 7px;
            gap: 5px;
    
            border-radius: 14px;
        }
    
        .transformUI button {
            width: 38px;
            height: 38px;
    
            font-size: 17px;
        }
    
        .transformUI button::after {
            display: none;
        }
}

@media (min-width: 768px) and (max-width: 1180px) and (orientation: landscape) {
    .board {
        height: min(50vh, 520px);
    }

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

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


/* =========================================================
   AI DESIGN ASSISTANT POPUP
   ========================================================= */

body.aiDesignerOpen {
    overflow: hidden !important;
}

/* ตัวครอบ Popup ทั้งหน้าจอ */
.aiDesignerModal {
    position: fixed;
    inset: 0;
    z-index: 99999;

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

    padding: 18px;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition:
        opacity 0.25s ease,
        visibility 0.25s ease;
}

/* ตอน JavaScript เพิ่ม class show */
.aiDesignerModal.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* พื้นหลังดำโปร่งใส */
.aiDesignerBackdrop {
    position: absolute;
    inset: 0;

    background:
        radial-gradient(circle at 20% 20%,
            rgba(255, 192, 203, 0.18),
            transparent 38%),
        rgba(53, 34, 24, 0.55);

    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* กล่อง Popup */
.aiDesignerDialog {
    position: relative;
    z-index: 2;

    width: min(680px, 100%);
    max-height: calc(100dvh - 36px);
    overflow-y: auto;

    border-radius: 30px;
    padding: 28px;

    color: #3d291f;

    background:
        radial-gradient(circle at top right,
            rgba(255, 222, 218, 0.85),
            transparent 38%),
        linear-gradient(145deg,
            #fffdfa 0%,
            #fff5ef 50%,
            #fffaf7 100%);

    border: 1px solid rgba(139, 69, 19, 0.12);

    box-shadow:
        0 35px 100px rgba(62, 35, 21, 0.30),
        0 8px 30px rgba(139, 69, 19, 0.12);

    transform: translateY(30px) scale(0.94);
    opacity: 0;

    transition:
        transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.25s ease;
}

.aiDesignerModal.show .aiDesignerDialog {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* ปุ่มปิด */
.aiDesignerClose {
    position: absolute;
    top: 14px;
    right: 14px;

    width: 42px;
    height: 42px;

    display: grid;
    place-items: center;

    padding: 0;
    border: 0;
    border-radius: 50%;

    color: #8b4513;
    background: rgba(255, 225, 220, 0.90);

    font-size: 26px;
    line-height: 1;

    cursor: pointer;

    box-shadow: 0 6px 18px rgba(139, 69, 19, 0.12);

    transition:
        transform 0.2s ease,
        background 0.2s ease;
}

.aiDesignerClose:hover {
    transform: rotate(8deg) scale(1.06);
    background: #ffd9d3;
}

/* ส่วนหัว */
.aiDesignerHeader {
    display: grid;
    grid-template-columns: 58px 1fr;
    gap: 16px;
    align-items: start;

    padding-right: 38px;
    margin-bottom: 22px;
}

.aiDesignerHeaderIcon {
    width: 58px;
    height: 58px;

    display: grid;
    place-items: center;

    border-radius: 20px;

    color: #fff;
    font-size: 26px;

    background:
        linear-gradient(135deg,
            #d98e82,
            #b8665d);

    box-shadow:
        0 10px 24px rgba(184, 102, 93, 0.30);

    animation: aiStarFloat 2.4s ease-in-out infinite;
}

@keyframes aiStarFloat {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    50% {
        transform: translateY(-4px) rotate(8deg);
    }
}

.aiDesignerEyebrow {
    margin: 0 0 5px;

    color: #a76459;

    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
}

.aiDesignerHeader h2 {
    margin: 0;

    color: #30221b;

    font-size: clamp(23px, 4vw, 34px);
    line-height: 1.18;
}

.aiDesignerDescription {
    margin: 10px 0 0;

    color: rgba(61, 41, 31, 0.70);

    font-size: 14px;
    line-height: 1.65;
}

/* เนื้อหา */
.aiDesignerBody {
    display: grid;
    gap: 18px;
}

.aiDesignerLabel {
    color: #3d291f;
    font-size: 15px;
    font-weight: 800;
}

.aiDesignerTextareaWrap {
    position: relative;
}

.aiDesignerTextareaWrap textarea {
    width: 100%;
    min-height: 118px;

    resize: vertical;

    padding: 16px 16px 34px;

    color: #3d291f;
    background: rgba(255, 255, 255, 0.90);

    border: 1px solid rgba(139, 69, 19, 0.15);
    border-radius: 20px;

    font: inherit;
    font-size: 15px;
    line-height: 1.55;

    outline: none;

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        0 8px 24px rgba(139, 69, 19, 0.07);

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.aiDesignerTextareaWrap textarea:focus {
    border-color: rgba(190, 105, 93, 0.65);

    box-shadow:
        0 0 0 4px rgba(232, 167, 157, 0.16),
        0 12px 28px rgba(139, 69, 19, 0.10);
}

.aiDesignerCounter {
    position: absolute;
    right: 14px;
    bottom: 11px;

    color: rgba(61, 41, 31, 0.55);

    font-size: 12px;
    font-weight: 700;
}

/* ปุ่มไอเดีย */
.aiPromptSection {
    display: grid;
    gap: 10px;
}

.aiPromptSectionTitle {
    color: rgba(61, 41, 31, 0.72);
    font-size: 13px;
    font-weight: 800;
}

.aiPromptChips {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
}

.aiPromptChip {
    padding: 10px 14px;

    border: 1px solid rgba(171, 87, 75, 0.13);
    border-radius: 999px;

    color: #8b4513;
    background: linear-gradient(180deg,
            #ffe9e5,
            #ffded9);

    font-size: 13px;
    font-weight: 700;

    cursor: pointer;

    box-shadow: 0 5px 14px rgba(139, 69, 19, 0.08);

    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.aiPromptChip:hover {
    transform: translateY(-2px);

    box-shadow:
        0 9px 20px rgba(139, 69, 19, 0.13);
}

/* ตัวเลือก */
.aiDesignerOptions {
    display: grid;
    grid-template-columns: minmax(150px, 0.5fr) 1fr;
    gap: 12px;
}

.aiDesignerOption,
.aiDesignerCheckOption {
    min-height: 62px;

    display: flex;
    align-items: center;
    gap: 10px;

    padding: 12px 14px;

    border: 1px solid rgba(139, 69, 19, 0.10);
    border-radius: 18px;

    background: rgba(255, 255, 255, 0.72);
}

.aiDesignerOption {
    justify-content: space-between;
}

.aiDesignerOption span,
.aiDesignerCheckOption span {
    color: #4a3024;

    font-size: 13px;
    font-weight: 700;
}

.aiDesignerOption select {
    min-width: 82px;

    padding: 8px 10px;

    color: #5f3828;
    background: #fff;

    border: 1px solid rgba(139, 69, 19, 0.15);
    border-radius: 12px;

    font: inherit;
    font-size: 13px;
    font-weight: 700;

    outline: none;
}

.aiDesignerCheckOption input {
    width: 19px;
    height: 19px;

    flex: 0 0 auto;

    accent-color: #bd7468;
}

/* กล่องผลลัพธ์ */
.aiDesignerResult {
    display: grid;
    grid-template-columns: 42px 1fr;
    gap: 12px;
    align-items: start;

    padding: 14px;

    border: 1px solid rgba(139, 69, 19, 0.10);
    border-radius: 18px;

    background: rgba(255, 255, 255, 0.68);
}

.aiDesignerResult.success {
    border-color: rgba(93, 157, 120, 0.22);

    background:
        linear-gradient(135deg,
            rgba(239, 255, 245, 0.90),
            rgba(255, 250, 244, 0.90));
}

.aiDesignerResultIcon {
    width: 42px;
    height: 42px;

    display: grid;
    place-items: center;

    border-radius: 14px;

    color: #fff;
    background: linear-gradient(135deg,
            #cf8b7f,
            #a95d53);
}

.aiDesignerResult strong {
    display: block;

    margin-bottom: 4px;

    color: #3a281f;
}

.aiDesignerResult p {
    margin: 0;

    color: rgba(61, 41, 31, 0.68);

    font-size: 13px;
    line-height: 1.55;
}

.aiDesignerResultTags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;

    margin-top: 9px;
}

.aiDesignerResultTags span {
    padding: 5px 9px;

    border-radius: 999px;

    color: #875044;
    background: rgba(229, 165, 153, 0.18);

    font-size: 11px;
    font-weight: 700;
}

/* ส่วนปุ่มล่าง */
.aiDesignerFooter {
    display: flex;
    justify-content: flex-end;
    gap: 10px;

    margin-top: 22px;
}

.aiDesignerCancel,
.aiDesignerGenerate {
    min-height: 46px;

    padding: 11px 18px;

    border: 0;
    border-radius: 15px;

    font-weight: 800;
    cursor: pointer;

    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease,
        opacity 0.2s ease;
}

.aiDesignerCancel {
    color: #7c4a3a;
    background: #f7e6e1;
}

.aiDesignerGenerate {
    color: #fff;

    background:
        linear-gradient(135deg,
            #d48d81,
            #a95d53);

    box-shadow:
        0 10px 24px rgba(169, 93, 83, 0.26);
}

.aiDesignerGenerate:hover:not(:disabled) {
    transform: translateY(-2px);

    box-shadow:
        0 14px 30px rgba(169, 93, 83, 0.32);
}

.aiDesignerGenerate:disabled {
    cursor: wait;
    opacity: 0.75;
}

/* Spinner */
.aiGenerateSpinner {
    display: inline-block;

    width: 16px;
    height: 16px;

    margin-right: 7px;

    vertical-align: -3px;

    border: 2px solid rgba(255, 255, 255, 0.38);
    border-top-color: #fff;
    border-radius: 50%;

    animation: aiSpinner 0.75s linear infinite;
}

@keyframes aiSpinner {
    to {
        transform: rotate(360deg);
    }
}

/* Animation ชาร์มที่ระบบเลือก */
.aiPlacedPiece {
    animation: aiCharmDrop 0.65s cubic-bezier(0.2, 1.4, 0.35, 1);
}

@keyframes aiCharmDrop {
    0% {
        opacity: 0;
        transform: translateY(-40px) scale(0.3) rotate(-14deg);
    }

    68% {
        opacity: 1;
        transform: translateY(4px) scale(1.14) rotate(4deg);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1) rotate(0deg);
    }
}

.board.aiBoardReveal {
    animation: aiBoardReveal 0.95s ease;
}

@keyframes aiBoardReveal {

    0%,
    100% {
        box-shadow: var(--shadow-soft);
    }

    50% {
        box-shadow:
            0 0 0 5px rgba(232, 167, 157, 0.22),
            0 22px 55px rgba(139, 69, 19, 0.18);
    }
}

/* ปุ่ม AI บนหน้าเว็บ */
.aiDesignerButton {
    position: relative;
    overflow: hidden;

    color: #fff !important;

    background:
        linear-gradient(135deg,
            #d58f83,
            #a95d53) !important;

    border: 0 !important;

    box-shadow:
        0 8px 22px rgba(169, 93, 83, 0.24) !important;
}

.aiDesignerButton::after {
    content: "";

    position: absolute;
    top: -50%;
    left: -70%;

    width: 45%;
    height: 200%;

    background: rgba(255, 255, 255, 0.32);

    transform: rotate(22deg);

    animation: aiButtonShine 3.2s ease-in-out infinite;
}

@keyframes aiButtonShine {

    0%,
    55% {
        left: -70%;
    }

    80%,
    100% {
        left: 140%;
    }
}

/* Mobile */
@media (max-width: 600px) {
    .aiDesignerModal {
        align-items: flex-end;
        padding: 8px;
    }

    .aiDesignerDialog {
        width: 100%;
        max-height: calc(100dvh - 16px);

        padding: 22px 16px 18px;

        border-radius: 26px 26px 20px 20px;

        transform: translateY(100%);
    }

    .aiDesignerModal.show .aiDesignerDialog {
        transform: translateY(0);
    }

    .aiDesignerHeader {
        grid-template-columns: 46px 1fr;
        gap: 11px;

        padding-right: 30px;
        margin-bottom: 17px;
    }

    .aiDesignerHeaderIcon {
        width: 46px;
        height: 46px;

        border-radius: 15px;
        font-size: 21px;
    }

    .aiDesignerHeader h2 {
        font-size: 22px;
    }

    .aiDesignerDescription {
        font-size: 13px;
    }

    .aiDesignerOptions {
        grid-template-columns: 1fr;
    }

    .aiDesignerFooter {
        position: sticky;
        bottom: -18px;

        margin: 18px -16px -18px;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));

        background: rgba(255, 250, 247, 0.95);

        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);

        border-top: 1px solid rgba(139, 69, 19, 0.08);
    }

    .aiDesignerCancel,
    .aiDesignerGenerate {
        flex: 1;
    }
}

@media (prefers-reduced-motion: reduce) {

    .aiDesignerModal,
    .aiDesignerDialog,
    .aiDesignerHeaderIcon,
    .aiDesignerButton::after,
    .aiPlacedPiece,
    .board.aiBoardReveal {
        animation: none !important;
        transition: none !important;
    }
}

/* =========================================================
   AI INITIAL / NAME DESIGN
   ========================================================= */

.aiInitialSection {
    display: grid;
    gap: 11px;

    padding: 16px;

    border: 1px solid rgba(139, 69, 19, 0.1);
    border-radius: 20px;

    background:
        radial-gradient(circle at top right,
            rgba(255, 218, 211, 0.42),
            transparent 45%),
        rgba(255, 255, 255, 0.72);

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        0 8px 24px rgba(139, 69, 19, 0.06);
}

.aiInitialHeading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.aiInitialDescription {
    margin: 5px 0 0;

    color: rgba(61, 41, 31, 0.62);

    font-size: 12px;
    line-height: 1.45;
}

.aiInitialBadge {
    flex: 0 0 auto;

    padding: 6px 10px;

    border-radius: 999px;

    color: #9a5549;
    background: rgba(222, 145, 133, 0.15);

    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.08em;
}

.aiInitialInputWrap {
    position: relative;

    display: flex;
    align-items: center;
}

.aiInitialIcon {
    position: absolute;
    left: 15px;

    z-index: 1;

    color: #bd7468;

    font-size: 16px;

    pointer-events: none;
}

.aiInitialInputWrap input {
    width: 100%;
    height: 54px;

    padding: 0 48px 0 44px;

    color: #3d291f;
    background: rgba(255, 255, 255, 0.94);

    border: 1px solid rgba(139, 69, 19, 0.15);
    border-radius: 17px;

    font: inherit;
    font-size: 17px;
    font-weight: 900;
    letter-spacing: 0.15em;
    text-transform: uppercase;

    outline: none;

    box-shadow:
        0 7px 20px rgba(139, 69, 19, 0.07);

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

.aiInitialInputWrap input::placeholder {
    color: rgba(61, 41, 31, 0.38);

    font-size: 13px;
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
}

.aiInitialInputWrap input:focus {
    border-color: rgba(190, 105, 93, 0.62);

    box-shadow:
        0 0 0 4px rgba(232, 167, 157, 0.15),
        0 10px 25px rgba(139, 69, 19, 0.1);

    transform: translateY(-1px);
}

.aiInitialClear {
    position: absolute;
    right: 11px;

    width: 32px;
    height: 32px;

    display: grid;
    place-items: center;

    padding: 0;

    border: 0;
    border-radius: 50%;

    color: #935143;
    background: #f8dfda;

    font-size: 20px;
    line-height: 1;

    cursor: pointer;

    transition:
        transform 0.2s ease,
        background 0.2s ease;
}

.aiInitialClear:hover {
    transform: rotate(8deg) scale(1.06);
    background: #f2cec7;
}

.aiInitialClear[hidden] {
    display: none;
}

.aiInitialBottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.aiInitialPreview,
.aiInitialHint {
    color: rgba(61, 41, 31, 0.52);

    font-size: 11px;
    font-weight: 700;
}

.aiInitialPreview.hasInitials {
    color: #a55e52;
    font-weight: 900;
}

.aiInitialPiece {
    z-index: 6;

    filter:
        drop-shadow(0 8px 10px rgba(112, 61, 42, 0.2));

    animation:
        aiInitialReveal 0.72s cubic-bezier(0.2, 1.45, 0.35, 1);
}

@keyframes aiInitialReveal {
    0% {
        opacity: 0;
        transform:
            translateY(-45px) scale(0.25) rotate(-12deg);
    }

    65% {
        opacity: 1;
        transform:
            translateY(3px) scale(1.18) rotate(3deg);
    }

    100% {
        opacity: 1;
        transform:
            translateY(0) scale(1) rotate(0deg);
    }
}

@media (max-width: 600px) {
    .aiInitialSection {
        padding: 14px;
        border-radius: 18px;
    }

    .aiInitialInputWrap input {
        height: 50px;
        font-size: 16px;
    }

    .aiInitialBottom {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }
}

/* =========================================================
   PHOTO CHARM EDITOR
   ========================================================= */

body.photoCharmOpen {
    overflow: hidden !important;
}

.photoCharmModal {
    position: fixed;
    inset: 0;
    z-index: 100200;

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

    padding: 18px;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transition:
        opacity 0.25s ease,
        visibility 0.25s ease;
}

.photoCharmModal.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.photoCharmBackdrop {
    position: absolute;
    inset: 0;

    background:
        radial-gradient(circle at 20% 15%,
            rgba(255, 215, 207, 0.24),
            transparent 38%),
        rgba(45, 29, 22, 0.62);

    backdrop-filter: blur(13px);
    -webkit-backdrop-filter: blur(13px);
}

.photoCharmDialog {
    position: relative;
    z-index: 2;

    width: min(720px, 100%);
    max-height: calc(100dvh - 36px);
    overflow-y: auto;

    padding: 26px;

    border:
        1px solid rgba(139, 69, 19, 0.12);

    border-radius: 30px;

    color: #3d291f;

    background:
        radial-gradient(circle at top right,
            rgba(255, 222, 216, 0.88),
            transparent 38%),
        linear-gradient(145deg,
            #fffdfa 0%,
            #fff5ef 52%,
            #fffaf7 100%);

    box-shadow:
        0 36px 105px rgba(48, 29, 20, 0.34),

        0 10px 34px rgba(139, 69, 19, 0.12);

    opacity: 0;

    transform:
        translateY(28px) scale(0.95);

    transition:
        opacity 0.25s ease,

        transform 0.35s cubic-bezier(0.22,
            1,
            0.36,
            1);
}

.photoCharmModal.show .photoCharmDialog {
    opacity: 1;

    transform:
        translateY(0) scale(1);
}

.photoCharmClose {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 4;

    width: 42px;
    height: 42px;

    display: grid;
    place-items: center;

    padding: 0;
    border: 0;
    border-radius: 50%;

    color: #8b4513;
    background:
        rgba(255,
            225,
            220,
            0.95);

    font-size: 26px;
    line-height: 1;

    cursor: pointer;

    box-shadow:
        0 7px 18px rgba(139, 69, 19, 0.13);

    transition:
        transform 0.2s ease,
        background 0.2s ease;
}

.photoCharmClose:hover {
    transform:
        rotate(8deg) scale(1.06);

    background: #ffd8d1;
}

.photoCharmHeader {
    display: grid;

    grid-template-columns:
        58px 1fr;

    gap: 15px;
    align-items: start;

    padding-right: 44px;
    margin-bottom: 18px;
}

.photoCharmHeaderIcon {
    width: 58px;
    height: 58px;

    display: grid;
    place-items: center;

    border-radius: 19px;

    color: #fff;

    background:
        linear-gradient(135deg,
            #db9588,
            #aa6055);

    font-size: 25px;

    box-shadow:
        0 11px 26px rgba(169, 93, 83, 0.26);
}

.photoCharmEyebrow {
    margin: 0 0 5px;

    color: #a76459;

    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.14em;
}

.photoCharmHeader h2 {
    margin: 0;

    color: #30221b;

    font-size:
        clamp(23px,
            4vw,
            33px);

    line-height: 1.18;
}

.photoCharmDescription {
    margin: 9px 0 0;

    color:
        rgba(61,
            41,
            31,
            0.68);

    font-size: 13px;
    line-height: 1.55;
}

.photoCharmBody {
    display: grid;
    gap: 14px;
}

.photoCharmTypeBar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    padding: 10px 13px;

    border:
        1px solid rgba(139, 69, 19, 0.09);

    border-radius: 14px;

    background:
        rgba(255,
            255,
            255,
            0.72);
}

.photoCharmTypeBar span {
    color:
        rgba(61,
            41,
            31,
            0.6);

    font-size: 12px;
    font-weight: 700;
}

.photoCharmTypeBar strong {
    color: #9b564b;

    font-size: 13px;
}

.photoCharmStage {
    position: relative;

    width: min(500px, 100%);
    aspect-ratio: 1 / 1;

    justify-self: center;

    display: grid;
    place-items: center;

    overflow: hidden;

    border:
        1px solid rgba(139, 69, 19, 0.12);

    border-radius: 24px;

    background-color: #efe9e4;

    background-image:
        linear-gradient(45deg,
            rgba(255, 255, 255, 0.62) 25%,
            transparent 25%),

        linear-gradient(-45deg,
            rgba(255, 255, 255, 0.62) 25%,
            transparent 25%),

        linear-gradient(45deg,
            transparent 75%,
            rgba(255, 255, 255, 0.62) 75%),

        linear-gradient(-45deg,
            transparent 75%,
            rgba(255, 255, 255, 0.62) 75%);

    background-size:
        24px 24px;

    background-position:
        0 0,
        0 12px,
        12px -12px,
        -12px 0;

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.88),

        0 13px 32px rgba(139, 69, 19, 0.1);
}

.photoCharmStage canvas {
    width: 100%;
    height: 100%;

    object-fit: contain;

    cursor: grab;
    touch-action: none;
    user-select: none;
}

.photoCharmStage.dragging canvas {
    cursor: grabbing;
}

.photoCharmDragHint {
    position: absolute;
    left: 50%;
    bottom: 12px;

    display: flex;
    align-items: center;
    gap: 6px;

    padding: 7px 11px;

    border:
        1px solid rgba(255, 255, 255, 0.35);

    border-radius: 999px;

    color: #fff;

    background:
        rgba(57,
            36,
            27,
            0.62);

    font-size: 11px;
    font-weight: 800;

    pointer-events: none;

    transform:
        translateX(-50%);

    backdrop-filter: blur(7px);
    -webkit-backdrop-filter:
        blur(7px);
}

.photoCharmZoomRow {
    display: grid;

    grid-template-columns:
        44px 1fr 44px;

    gap: 10px;
    align-items: center;
}

.photoCharmIconButton {
    width: 44px;
    height: 44px;

    display: grid;
    place-items: center;

    padding: 0;

    border:
        1px solid rgba(139, 69, 19, 0.1);

    border-radius: 14px;

    color: #8b4513;
    background: #f9e5e0;

    font-size: 22px;
    font-weight: 800;

    cursor: pointer;
}

.photoCharmZoomControl {
    display: grid;
    gap: 7px;

    padding: 10px 13px;

    border:
        1px solid rgba(139, 69, 19, 0.09);

    border-radius: 15px;

    background:
        rgba(255,
            255,
            255,
            0.76);
}

.photoCharmZoomControl span {
    color: #583a2d;

    font-size: 12px;
    font-weight: 800;
}

.photoCharmZoomControl input {
    width: 100%;

    accent-color: #bd7468;
}

.photoCharmTools {
    display: grid;

    grid-template-columns:
        1fr 1fr;

    gap: 10px;
}

.photoCharmSoftButton {
    min-height: 43px;

    padding: 10px 14px;

    border:
        1px solid rgba(139, 69, 19, 0.1);

    border-radius: 14px;

    color: #805043;

    background:
        rgba(255,
            255,
            255,
            0.78);

    font-weight: 800;
    cursor: pointer;
}

.photoCharmPrivacy {
    margin: 0;

    color:
        rgba(61,
            41,
            31,
            0.52);

    font-size: 11px;
    line-height: 1.5;
    text-align: center;
}

.photoCharmFooter {
    display: flex;
    justify-content: flex-end;
    gap: 10px;

    margin-top: 18px;
}

.photoCharmCancel,
.photoCharmSave {
    min-height: 47px;

    padding: 11px 18px;

    border: 0;
    border-radius: 15px;

    font-weight: 900;
    cursor: pointer;

    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.photoCharmCancel {
    color: #7c4a3a;
    background: #f6e4df;
}

.photoCharmSave {
    color: #fff;

    background:
        linear-gradient(135deg,
            #d48d81,
            #a95d53);

    box-shadow:
        0 10px 25px rgba(169, 93, 83, 0.27);
}

.photoCharmSave:hover {
    transform:
        translateY(-2px);

    box-shadow:
        0 15px 32px rgba(169, 93, 83, 0.32);
}

/*
 * ชาร์มที่ประกอบรูปแล้วต้องแสดงภาพเต็ม
 * ไม่ใช้ object-fit: cover แบบชาร์มทั่วไป
 */
.customPhotoPiece img {
    object-fit: contain;
    border-radius: 0;
}

@media (max-width: 600px) {
    .photoCharmModal {
        align-items: flex-end;
        padding: 7px;
    }

    .photoCharmDialog {
        width: 100%;

        max-height:
            calc(100dvh - 14px);

        padding:
            21px 15px 16px;

        border-radius:
            26px 26px 18px 18px;

        transform:
            translateY(100%);
    }

    .photoCharmModal.show .photoCharmDialog {
        transform:
            translateY(0);
    }

    .photoCharmHeader {
        grid-template-columns:
            46px 1fr;

        gap: 11px;
        padding-right: 32px;
        margin-bottom: 14px;
    }

    .photoCharmHeaderIcon {
        width: 46px;
        height: 46px;

        border-radius: 15px;

        font-size: 20px;
    }

    .photoCharmHeader h2 {
        font-size: 21px;
    }

    .photoCharmStage {
        width:
            min(390px, 100%);

        border-radius: 20px;
    }

    .photoCharmFooter {
        position: sticky;
        bottom: -16px;

        margin:
            16px -15px -16px;

        padding:
            11px 15px calc(11px + env(safe-area-inset-bottom));

        background:
            rgba(255,
                250,
                247,
                0.96);

        border-top:
            1px solid rgba(139, 69, 19, 0.08);

        backdrop-filter:
            blur(10px);

        -webkit-backdrop-filter:
            blur(10px);
    }

    .photoCharmCancel,
    .photoCharmSave {
        flex: 1;
    }
}

@media (prefers-reduced-motion: reduce) {

    .photoCharmModal,
    .photoCharmDialog,
    .photoCharmClose,
    .photoCharmSave {
        animation: none !important;
        transition: none !important;
    }
}

.magneticGuide {
    position: absolute;
    left: 7%;
    right: 7%;
    z-index: 2;

    height: 2px;

    pointer-events: none;

    opacity: 0;

    transform:
        translateY(-50%) scaleX(.82);

    transform-origin: center;

    background:
        linear-gradient(90deg,
            transparent,
            rgba(201, 124, 75, .62),
            rgba(255, 211, 197, .95),
            rgba(201, 124, 75, .62),
            transparent);

    box-shadow:
        0 0 14px rgba(201, 124, 75, .28);

    transition:
        opacity .16s ease,
        transform .2s ease;
}

.magneticGuide.show {
    opacity: 1;

    transform:
        translateY(-50%) scaleX(1);
}

.piece.magneticReady img {
    filter:
        drop-shadow(0 0 8px rgba(201, 124, 75, .52)) drop-shadow(0 8px 12px rgba(139, 69, 19, .16));
}

.piece.magneticTarget img {
    filter:
        drop-shadow(0 0 7px rgba(255, 184, 164, .75)) drop-shadow(0 7px 11px rgba(139, 69, 19, .14));
}

.piece.magneticLocked img {
    animation:
        magneticCharmLock .4s cubic-bezier(.2,
            1.5,
            .35,
            1);
}

@keyframes magneticCharmLock {
    0% {
        transform: scale(1);
    }

    48% {
        transform: scale(1.14);
    }

    72% {
        transform: scale(.97);
    }

    100% {
        transform: scale(1);
    }
}


.boardCredit {
    position: absolute;

    left: 50%;
    bottom: 8px;

    z-index: 8;

    transform:
        translateX(-50%);

    max-width:
        calc(100% - 24px);

    color:
        rgba(91, 57, 42, .48);

    font-size: 10px;
    font-weight: 500;
    letter-spacing: .035em;
    line-height: 1.2;

    text-align: center;
    white-space: nowrap;

    pointer-events: none;
    user-select: none;
}

.boardCredit strong {
    color:
        rgba(139, 69, 19, .72);

    font-weight: 800;
}

@media (max-width: 600px) {
    .boardCredit {
        bottom: 6px;
        font-size: 9px;
    }
}

@media (prefers-reduced-motion: reduce) {

    .magneticGuide,
    .piece.magneticLocked img {
        animation: none !important;
        transition: none !important;
    }
}


/* =========================================================
   MAGNETIC SLOT RAIL
   ========================================================= */

.slotRailTrack {
    position: absolute;
    z-index: 2;

    height: 18px;

    pointer-events: none;

    opacity: 0;

    border:
        1px solid rgba(201, 124, 75, .16);

    border-radius: 999px;

    background:
        linear-gradient(180deg,
            rgba(255, 255, 255, .68),
            rgba(255, 229, 220, .20));

    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .85),

        0 7px 20px rgba(139, 69, 19, .08);

    transform:
        translateY(-50%) scaleX(.88);

    transform-origin: center;

    transition:
        opacity .16s ease,
        left .18s ease,
        width .18s ease,
        transform .18s ease;
}

.slotRailTrack.show {
    opacity: 1;

    transform:
        translateY(-50%) scaleX(1);
}

/*
 * เส้นแสดงตำแหน่งที่ชาร์มจะถูกแทรก
 */
.slotRailMarker {
    position: absolute;
    z-index: 7;

    width: 3px;
    height: 72px;

    pointer-events: none;

    opacity: 0;

    border-radius: 999px;

    background:
        linear-gradient(180deg,
            transparent,
            rgba(211, 117, 96, .92),
            transparent);

    box-shadow:
        0 0 11px rgba(211, 117, 96, .50);

    transform:
        translate(-50%, -50%) scaleY(.72);

    transition:
        opacity .14s ease,
        left .15s ease,
        transform .16s ease;
}

.slotRailMarker.show {
    opacity: 1;

    transform:
        translate(-50%, -50%) scaleY(1);
}

/*
 * ชาร์มที่อยู่ในราง
 */
.piece.slotRailMember {
    z-index: 4;
}

/*
 * Animation ตอนชิ้นอื่นเลื่อนเปิดช่อง
 */
.piece.slotRailShifting {
    transition:
        left .19s cubic-bezier(.22, 1, .36, 1),

        top .19s cubic-bezier(.22, 1, .36, 1);
}

/*
 * ชาร์มอื่นที่กำลังถูก Preview
 */
.piece.slotRailPreview img {
    filter:
        drop-shadow(0 0 6px rgba(255, 189, 171, .52)) drop-shadow(0 7px 11px rgba(139, 69, 19, .12));
}

/*
 * ชาร์มที่ลูกค้ากำลังลาก
 */
.piece.slotRailActive {
    z-index: 8;
}

.piece.slotRailActive img {
    filter:
        drop-shadow(0 0 9px rgba(211, 117, 96, .62)) drop-shadow(0 10px 14px rgba(139, 69, 19, .17));
}

/*
 * Animation ตอนปล่อยชาร์มลง Slot
 */
.piece.slotRailCommitted img {
    animation:
        slotRailCommit .42s cubic-bezier(.2, 1.5, .35, 1);
}

@keyframes slotRailCommit {
    0% {
        transform: scale(.92);
    }

    52% {
        transform: scale(1.14);
    }

    78% {
        transform: scale(.98);
    }

    100% {
        transform: scale(1);
    }
}

@media (max-width: 600px) {
    .slotRailTrack {
        height: 16px;
    }

    .slotRailMarker {
        height: 64px;
    }
}

@media (prefers-reduced-motion: reduce) {

    .slotRailTrack,
    .slotRailMarker,
    .piece.slotRailShifting,
    .piece.slotRailCommitted img {
        animation: none !important;
        transition: none !important;
    }
}