/* BASIC css start */
:root {
    --muted: #6b7684;
    --line: #e2e6ea;
    --danger: #e0483e;
    --ok: #1c9c6b;
    --radius: 14px;
    /* PC에서 stage-wrap이 아무리 눌려도 보장할 최소 높이. script.js도
       (panel 높이 하한 계산 시) 이 값을 그대로 읽어 쓰므로 여기서만 바꾸면 된다. */
    --min-cap-height: 220px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    color: var(--black);
    -webkit-tap-highlight-color: transparent;
}
#pageContainer {
    background: linear-gradient(
        0deg,
        rgba(64, 129, 206, 1) 0%,
        rgba(17, 17, 17, 1) 100%
    );
}
.headerWrapper * {
    background: #b5f965 !important;
}
.headerNews {
    display: none !important;
}
.nav2Search fieldset {
    border: 2px solid #000;
}
.nav2Category .depth1 > a {
    border-bottom: none !important;
}
#footer {
    background: #b5f965 !important;
}
.footerDown {
    background: #000 !important;
}
.footerDown * {
    color: #fff !important;
}
/* header 및 기본 설정 */
.app {
    max-width: 1440px;
    min-width: 300px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}
.app-header {
    display: flex;
    flex-flow: column nowrap;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0;
}
.app-header * {
    color: var(--white);
}
.app-header h1 {
    font-size: 5rem;
    text-align: center;
}
.app-header h3 {
    font-size: 1rem;
    text-align: center;
}
.app-header .sub {
    color: var(--bordergrey);
    font-size: 0.875rem;
    text-align: center;
}

.layout {
    display: grid;
    gap: 20px;
    align-items: stretch;
}

/* ---------- canvas / stage ---------- */

.canvas-panel {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    height: min-content;
}

.stage-block + .stage-block {
    margin-top: 18px;
}

.stage-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 700;
}

.stage-label .side-count {
    font-weight: 600;
    color: var(--muted);
}

.stage-label .mini-clear {
    margin-left: auto;
    border: 1px solid var(--line);
    background: #fafbfc;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 999px;
    cursor: pointer;
}

.stage-wrap {
    position: relative;
    background: linear-gradient(180deg, #eef4fb 0%, #dfeaf6 100%);
    border-radius: 12px;
    padding: 20px 0 0 0;
}

.cap-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 468 / 416; /* 모자 SVG 실제 비율   절대 다른 값으로 덮어쓰면 안 됨 */
    margin: 0 auto;
    /* touch-action은 여기 두지 않는다   캡 배경까지 none이면 모바일에서
       화면 대부분을 차지하는 이 영역 위에서 페이지 스크롤이 아예 안 먹힌다.
       실제로 커스텀 드래그가 필요한 .placed-sticker/.sticker-tile에만 건다. */
}

.cap-shape {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.cap-shape svg {
    width: 100%;
    height: 100%;
    display: block;
    filter: drop-shadow(0 10px 18px rgba(20, 40, 80, 0.12));
}

.drop-zone {
    position: absolute;
    inset: 0;
}

/* 인쇄 가능 영역 가이드   위치/크기는 PRINT_AREA_PCT 기준으로 JS가 인라인으로 지정 */
.print-area {
    position: absolute;
    border: 2px solid #1a3fd6;
    box-sizing: border-box;
    pointer-events: none;
}

/* 배치 완료 상태: 가이드 숨기고 편집 잠금 */
.layout.finished .print-area {
    display: none;
}
.layout.finished .placed-sticker {
    pointer-events: none;
}
.layout.finished .mini-clear,
.layout.finished #clear-all,
.layout.finished .sticker-tile {
    opacity: 0.45;
    pointer-events: none;
}

.placed-sticker {
    position: absolute;
    /* width/height는 실제 이미지 해상도 비율에 맞춰 JS에서 개별 지정 */
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none; /* iOS 롱프레스 시 이미지 콜아웃/선택 메뉴 방지 */
    /* pan-y로 두면 "누르고 버티기" 타이머와 브라우저 자체 스크롤 판정이
       동시에 경쟁하면서 스크롤과 드래그가 같이 발생하는 문제가 생긴다.
       그래서 none으로 완전히 브라우저 기본 동작을 끄고, 대기 중 손가락이
       움직이면 JS가 직접 스크롤을 흉내내준다 (startHoldToDrag 참고). */
    touch-action: none;
}
.placed-sticker.dragging {
    cursor: grabbing;
    z-index: 999 !important;
}

.placed-sticker .sticker-face {
    width: 100%;
    height: 100%;
}
.placed-sticker .sticker-face img {
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: none; /* 히트테스트가 항상 .placed-sticker로 가도록 */
}

.placed-sticker .remove-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: 2px solid #fff;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}
.placed-sticker:hover .remove-btn,
.placed-sticker.active .remove-btn {
    opacity: 1;
    pointer-events: auto;
}

.stage-info {
    margin-top: 12px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    gap: 6px;
    justify-content: center;
}
.stage-info .dot {
    opacity: 0.5;
}
.stage-info.warn #logo-status,
#logo-status.warn {
    color: var(--danger);
    font-weight: 600;
}
#logo-status.ok {
    color: var(--ok);
    font-weight: 600;
}

.canvas-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}
.canvas-actions button {
    flex: 1;
    padding: 10px 0;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    color: var(--black);
    cursor: pointer;
}
.canvas-actions button.primary {
    color: #fff;
    background: var(--black);
}

/* ---------- sticker tray ---------- */

.sticker-tray {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tray-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    padding: 0;
    margin: 0 0 12px;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: default;
}
.sticker-tray h2 {
    font-size: 15px;
    margin: 0;
}
.tray-toggle-icon {
    display: none;
}

.category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.category-tab {
    border: 1px solid var(--line);
    background: #fafbfc;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
}

.category-tab.active {
    color: #fff;
    background: var(--black);
}
.sticker-grid-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.sticker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    padding-right: 2px;
}

.sticker-tile {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #f6f8fa;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none; /* iOS 롱프레스 시 이미지 콜아웃/선택 메뉴 방지 */
    /* pan-y로 두면 "누르고 버티기" 타이머와 브라우저 자체 스크롤 판정이
       동시에 경쟁하면서 스크롤과 드래그가 같이 발생하는 문제가 생긴다.
       그래서 none으로 완전히 브라우저 기본 동작을 끄고, 대기 중 손가락이
       움직이면 JS가 직접 sticker-grid-wrapper를 스크롤시켜준다
       (startHoldToDrag 참고). */
    touch-action: none;
}
.sticker-tile:active {
    cursor: grabbing;
}
.sticker-tile.tile-hidden {
    display: none;
}
.sticker-tile img {
    width: 78%;
    height: 78%;
    object-fit: contain;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: none; /* 히트테스트가 항상 .sticker-tile로 가도록 */
}

/* ghost element that follows the pointer while dragging from tray */
.drag-ghost {
    position: fixed;
    top: 0;
    left: 0;
    /* width/height는 실제 이미지 해상도 비율에 맞춰 JS에서 개별 지정 */
    pointer-events: none;
    z-index: 2000;
    opacity: 0.9;
    transform: translate(-50%, -50%);
}
.drag-ghost img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
}

/* ---------- guide footer ---------- */

.guide {
    margin-top: 24px;
    background: var(--black);
    border-radius: var(--radius);
    padding: 18px 20px;
}
.guide h3 {
    margin: 0 0 10px;
    font-size: 16px;
    letter-spacing: 0.5px;
    color: var(--white);
    font-weight: 800;
}
.guide ol {
    margin: 0;
    padding-left: 18px;
    font-size: 14px;
}
.guide ol li {
    color: var(--white);
    line-height: 1.5rem;
    list-style: decimal;
}
/* ---------- toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%) translateY(12px);
    background: rgba(20, 24, 30, 0.92);
    color: #fff;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
    z-index: 3000;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
/* 카톡 버튼  */
.visualNavPromotion {
    display: flex;
    flex-flow: column nowrap;
    align-items: center;
    justify-content: center;
    gap: 0.875rem;
    margin: 3rem 0;
}
.visualNavPromotionBtn {
    padding: 0.875rem 3rem;
    border-radius: 1.5rem;
    background-color: #b5f965;
    color: var(--black);
    font-weight: 600;
}
.visualNavPromotionBtn:hover {
    background-color: var(--black);
    color: #b5f965;
}
.visualNavPromotion h5 {
    text-align: center;
    /* background-color: #b5f965; */
    border-bottom: 2px solid #b5f965;
    padding: 0.25rem 0.5rem;
    /* color: var(--black); */
    color: #b5f965;
    font-weight: 500;
}
.visualNavPromotion p {
    color: #b5f965;
}
/*  */

/* ============================================================
    미디어 쿼리 (반응형 규칙 모음   전부 여기 하단에 모아둠)
   ============================================================ */

/* PC: canvas-panel/sticker-tray 높이는 JS가 뷰포트에 맞춰 지정해준다.
    그 안의 stage-wrap(캡을 감싸는 박스) 크기는 순수 CSS로 해결한다  
    aspect-ratio를 1:1~1.5:1 사이(1.1/1)로 고정하고 min-height로 바닥을
    깔아주면, stage-block이 flex로 아무리 눌리거나 늘어나도 stage-wrap
    자체는 항상 이 비율/최소 높이를 유지한다. 캡(cap-stage)의 실제 468:416
    비율(1.125)은 stage-wrap의 1.1 비율보다 살짝 더 "세로로 긴" 쪽이라
    stage-wrap 안에 꽉 채워도 절대 넘치지 않는다   JS로 픽셀을 계산할
   필요가 없다. 모바일은 기존 방식(너비 기준) 그대로. */
@media (min-width: 761px) {
    .canvas-panel {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }
    .stage-block {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    .stage-wrap {
        width: 100%;
        min-height: var(--min-cap-height);
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .cap-stage {
        width: 100%;
        height: auto;
    }

    /* 한 화면에 CUSTOM GUIDE까지 들어오도록 여백을 살짝 줄임 */
    .app {
        padding: 16px 16px 24px;
    }
    .app-header .sub {
        margin-bottom: 12px;
    }
    .guide {
        margin-top: 16px;
        padding: 14px 20px;
    }
    .guide ol {
        line-height: 1.5;
    }
}

@media (min-width: 1081px) {
    .layout {
        grid-template-columns: 0.7fr 1fr;
    }
    .sticker-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}
@media (max-width: 1080px) {
    .layout {
        grid-template-columns: 1fr 1fr;
    }
    .sticker-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}
@media (max-width: 760px) {
    .layout {
        grid-template-columns: 1fr;
    }
    .cap-stage {
        width: 100%;
        height: auto;
    }

    /* 모바일에서는 canvas-panel이 세로로 먼저 쌓이고, sticker-tray는 화면
       하단에 고정된 바텀시트로 붙는다. 평소엔 "스티커 선택" 헤더 바만
       보이고, 탭하면 위로 펼쳐진다 (토글은 script.js에서 처리). */
    .app {
        padding-bottom: 76px;
    }
    .sticker-tray {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 500;
        margin: 0;
        border: none;
        border-top: 1px solid var(--line);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -6px 24px rgba(20, 40, 80, 0.16);
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        /* max-height가 아니라 height를 명확히 지정해야 한다   flex:1인
            sticker-grid-wrapper가 "auto 높이 + max-height로 상한만 걸린"
            부모 안에서는 펼쳐질 기준(definite height)이 없어서 그냥
            찌그러져버린다 (데스크톱 레이아웃에서 겪었던 것과 같은 문제). */
        height: 60px;
        overflow: hidden;
        transition: height 0.25s ease;
    }
    .sticker-tray.expanded {
        height: 50vh;
    }
    .sticker-tray:not(.expanded) .category-tabs,
    .sticker-tray:not(.expanded) .sticker-grid-wrapper {
        display: none;
    }
    .tray-header {
        cursor: pointer;
        padding: 0.25rem;
        margin-bottom: 0;
    }
    .sticker-tray.expanded .tray-header {
        margin-bottom: 12px;
    }
    .tray-toggle-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 22px;
        height: 22px;
        font-size: 15px;
        color: var(--muted);
        flex-shrink: 0;
    }
    .sticker-grid-wrapper {
        overflow-y: auto;
    }
    .sticker-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}
@media (max-width: 540px) {
    .sticker-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (max-width: 420px) {
    .sticker-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* BASIC css end */

