@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: cover;
    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 {
    position: absolute;
    display: flex;
    gap: 6px;
    padding: 6px;
    background: rgba(255, 255, 255, .9);
    border-radius: 12px;
    z-index: 50;
    border: 1px solid rgba(0, 0, 0, .1);
}

.transformUI.hidden {
    display: none;
}

.transformUI button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    padding: 0;
    font-size: 16px;
    background: #ffe4e1;
    color: #8b4513;
    border: 1px solid rgba(0, 0, 0, .1);
}

.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%;
        justify-content: flex-start;
        gap: 8px;
    }

    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 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .trayItem {
        width: 80px;
        height: 80px;
    }
}


/* ===== 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 {
        padding: 8px;
        gap: 8px;
        border-radius: 14px;
    }

    .transformUI button {
        width: 40px;
        height: 40px;
        font-size: 17px;
    }
}

@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));
    }
}