/* 끌림 다꾸 화면 스타일: 상단 바, 꾸미는 책상, 스티커 서랍, 구매 목록, 휴대폰 대응 */
:root {
  --bg: #f2f4f6; --surface: #fff; --text: #191f28; --sub: #6b7684; --muted: #8b95a1; --line: #e5e8eb;
  --primary: #3182f6; --primary-soft: #e8f3ff; --primary-press: #1b64da; --danger: #f04452; --ink: #1b1f27;
  --desk: #ece6dc; --radius: 16px; --top: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-synthesis: none;
  font-family: "Gowun Dodum", Pretendard, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; }
button { font-family: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid rgba(49,130,246,.45); outline-offset: 2px; }

/* 상단 바 */
#topbar { position: sticky; top: 0; z-index: 20; height: var(--top); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; padding: 0 20px; }
#logo { font-family: "Gowun Batang", serif; font-weight: 700; font-size: 21px; white-space: nowrap; }
#logo { color: inherit; text-decoration: none; }
#logo em { font-style: normal; color: var(--primary); }
.beta { font-size: 11px; letter-spacing: .06em; color: var(--primary); background: var(--primary-soft); border-radius: 999px; padding: 3px 8px; margin-left: 2px; }
.spacer { flex: 1; }
.btn { cursor: pointer; border: none; border-radius: 12px; padding: 10px 16px; font-size: 14px; white-space: nowrap; transition: background .15s, transform .1s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn-ghost { background: var(--bg); color: #333d4b; }
.btn-ghost:hover:not(:disabled) { background: #e5e8eb; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-press); }

/* 배치: 넓은 화면은 서랍 | 책상 | 구매 목록 */
#app { display: grid; grid-template-columns: 300px 1fr 280px; grid-template-areas: "drawer desk cart";
  height: calc(100vh - var(--top)); height: calc(100dvh - var(--top)); }

/* 책상과 페이지 */
#desk { grid-area: desk; position: relative; background: var(--desk); overflow: hidden; min-height: 0;
  background-image: radial-gradient(rgba(120,95,60,.08) 1px, transparent 1px); background-size: 14px 14px; }
/* 확대하면 이 안에서 스크롤. 손가락 동작(이동·확대)은 스크립트가 직접 처리 */
#deskScroll { position: absolute; inset: 0; overflow: auto; display: flex; touch-action: none; scrollbar-width: thin; }
/* margin:auto로 가운데 두면, 확대해서 커져도 왼쪽·위가 잘리지 않고 스크롤된다 */
#pageBox { position: relative; flex: none; margin: auto; box-shadow: 0 1px 2px rgba(60,40,20,.12), 0 12px 32px rgba(60,40,20,.16); border-radius: 4px; }
#pageBox::after { content: ""; position: absolute; right: -32px; bottom: -32px; width: 1px; height: 1px; } /* 확대 시 오른쪽·아래 여백 */
#zoomCtl { position: absolute; right: 14px; top: 14px; z-index: 5; display: flex; align-items: center; background: var(--surface); border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12); padding: 3px; }
#zoomCtl button { border: none; background: none; color: #333d4b; font-size: 18px; width: 34px; height: 34px; border-radius: 999px; cursor: pointer; line-height: 1; }
#zoomCtl #zoomReset { width: auto; min-width: 52px; font-size: 13px; padding: 0 6px; }
#zoomCtl button:hover:not(:disabled) { background: var(--bg); }
#zoomCtl button:disabled { opacity: .35; cursor: default; }
#page { position: absolute; left: 0; top: 0; width: 600px; height: 848px; transform-origin: 0 0; touch-action: none; --inv: 1; }
#paper, #paper svg, #items { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#paper { overflow: hidden; border-radius: 4px; }
#hint { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; text-align: center; pointer-events: none;
  color: #a39684; font-size: 15px; line-height: 1.7; }
#hint[hidden] { display: none; }

.item { position: absolute; touch-action: none; cursor: grab; filter: drop-shadow(0 1px 1.5px rgba(60,40,20,.28)); }
.item:active { cursor: grabbing; }
.item > svg { width: 100%; height: 100%; display: block; pointer-events: none; overflow: visible; }
.item.selected { outline: calc(2px * var(--inv)) dashed var(--primary); outline-offset: calc(5px * var(--inv)); }
.h { display: none; position: absolute; width: calc(30px * var(--inv)); height: calc(30px * var(--inv)); border-radius: 50%; padding: 0; border: none;
  box-shadow: 0 2px 6px rgba(0,0,0,.2); place-items: center; touch-action: none; }
.item.selected .h { display: grid; }
.h-del { left: calc(-20px * var(--inv)); top: calc(-20px * var(--inv)); background: #fff; color: var(--danger); font-size: calc(20px * var(--inv)); line-height: 1; cursor: pointer; }
.h-rot { right: calc(-20px * var(--inv)); bottom: calc(-20px * var(--inv)); background: var(--primary); cursor: nwse-resize;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 12a8 8 0 1 1-2.3-5.6'/%3E%3Cpath d='M20 4v4h-4'/%3E%3C/svg%3E");
  background-size: 58%; background-repeat: no-repeat; background-position: center; }
/* 띠·테이프 길이 손잡이: 오른쪽 끝 바깥, 회전 손잡이와 겹치지 않게 조금 떨어뜨린다 */
.h-len { right: calc(-50px * var(--inv)); top: 50%; margin-top: calc(-15px * var(--inv)); background: #fff; cursor: ew-resize;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233182f6' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12h16M8 8l-4 4 4 4M16 8l4 4-4 4'/%3E%3C/svg%3E");
  background-size: 62%; background-repeat: no-repeat; background-position: center; }

/* 선택 도구 */
#toolbar { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; gap: 4px; padding: 6px; z-index: 5;
  background: var(--ink); border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
#toolbar[hidden] { display: none; }
#toolbar button, #toolbar a { border: none; background: transparent; color: #fff; font-size: 14px; padding: 8px 14px; border-radius: 999px; cursor: pointer; text-decoration: none; white-space: nowrap; }
#toolbar button:hover, #toolbar a:hover { background: rgba(255,255,255,.12); }
#toolbar .danger { color: #ff8a95; }
#toolbar a { background: var(--primary); }
#toolbar [data-act="photo"] { color: #ffd166; }
#toolbar [hidden] { display: none; }
#notice { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 6; margin: 0; width: max-content; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; font-size: 14px; padding: 10px 16px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
#notice[hidden] { display: none; }
#toolbar a:hover { background: var(--primary-press); }

/* 스티커 서랍 */
#drawer { grid-area: drawer; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#tabs { display: flex; gap: 6px; padding: 16px 16px 12px; flex-wrap: wrap; }
#tabs button { border: none; background: var(--bg); color: #4e5968; border-radius: 999px; padding: 8px 14px; font-size: 14px; cursor: pointer; }
#tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
#tray { flex: 1; overflow-y: auto; padding: 4px 16px 20px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-content: start; }
#tray[data-kind="paper"] { grid-template-columns: repeat(2, 1fr); }
#tray[data-cat="letter"] { grid-template-columns: repeat(4, 1fr); gap: 8px; }
#tray[data-cat="letter"] .t-sticker { padding: 6px; }
.t-sticker { aspect-ratio: 1; border: none; background: #faf8f4; border-radius: 14px; padding: 12px; cursor: grab; touch-action: pan-y;
  display: grid; place-items: center; transition: background .15s, transform .1s; }
.t-sticker:hover { background: #f3eee6; }
.t-sticker:active { transform: scale(.94); }
.t-sticker svg { width: 100%; height: 100%; pointer-events: none; filter: drop-shadow(0 1px 1px rgba(60,40,20,.25)); }
/* 띠·테이프처럼 긴 스티커는 가로로 넓은 칸 */
.t-sticker.wide { grid-column: span 3; aspect-ratio: auto; height: 60px; padding: 10px 18px; }
.t-paper { border: 2px solid transparent; background: none; padding: 0; cursor: pointer; text-align: center; font-size: 13px; color: var(--sub); }
.t-paper svg { display: block; width: 100%; height: auto; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.12); margin-bottom: 6px; pointer-events: none; }
.t-paper.on { color: var(--primary); }
.t-paper.on svg { outline: 3px solid var(--primary); outline-offset: 2px; }

/* 끌고 가는 동안 손가락을 따라오는 스티커 */
.ghost { position: fixed; z-index: 100; pointer-events: none; transform: translate(-50%, -50%) scale(1.06); opacity: .9; filter: drop-shadow(0 6px 10px rgba(0,0,0,.25)); }
.ghost svg { width: 100%; height: 100%; display: block; }

/* 구매 목록 */
#cart { grid-area: cart; background: var(--surface); border-left: 1px solid var(--line); padding: 20px 18px; overflow-y: auto; min-height: 0; }
#cart h2 { font-family: "Gowun Batang", serif; font-weight: 700; font-size: 18px; margin: 0 0 4px; }
#cartCount { font-family: "Gowun Dodum", sans-serif; font-weight: 400; font-size: 13px; color: var(--primary); background: var(--primary-soft); border-radius: 999px; padding: 2px 8px; vertical-align: 2px; }
.cart-sub { margin: 0 0 14px; color: var(--sub); font-size: 13px; }
#cartList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#cartList li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; background: #faf8f4; }
.c-thumb { flex: none; width: 44px; height: 44px; display: grid; place-items: center; }
.c-thumb svg { max-width: 100%; max-height: 100%; }
.c-name { flex: 1; min-width: 0; font-size: 14px; line-height: 1.35; }
.c-name small { display: block; color: var(--muted); font-size: 12px; }
.c-buy { flex: none; font-size: 13px; color: var(--primary); background: var(--primary-soft); text-decoration: none; padding: 7px 10px; border-radius: 10px; white-space: nowrap; }
.c-buy:hover { background: #d6e8ff; }
.cart-note { margin: 16px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* 중간 화면: 구매 목록을 서랍 아래로 */
@media (max-width: 1100px) {
  #app { grid-template-columns: 280px 1fr; grid-template-areas: "drawer desk" "cart desk"; grid-template-rows: 1fr auto; }
  #cart { border-left: none; border-right: 1px solid var(--line); border-top: 1px solid var(--line); max-height: 40vh; }
}

/* 휴대폰: 책상 위, 서랍은 가로로 넘기기, 구매 목록은 맨 아래 */
@media (max-width: 760px) {
  :root { --top: 56px; }
  #topbar { padding: 0 12px; gap: 6px; }
  #logo { font-size: 19px; }
  .btn { padding: 8px 10px; font-size: 13px; }
  .beta { font-size: 9px; padding: 2px 5px; }
  .btn.icon .lab { display: none; }
  #app { display: block; height: auto; }
  #desk { height: 62vh; height: 62svh; }
  #toolbar { bottom: 10px; }
  #toolbar button, #toolbar a { padding: 8px 11px; font-size: 13px; }
  #drawer { border-right: none; border-bottom: 1px solid var(--line); }
  #tabs { flex-wrap: nowrap; overflow-x: auto; padding: 12px 12px 8px; scrollbar-width: none; }
  #tabs button { flex: none; }
  #tray, #tray[data-kind="paper"] { display: flex; overflow-x: auto; overflow-y: hidden; gap: 8px; padding: 4px 12px 14px; }
  .t-sticker { flex: none; width: 76px; height: 76px; padding: 10px; touch-action: pan-x; }
  .t-sticker.wide { width: 170px; height: 76px; padding: 10px 14px; }
  #tray[data-cat="letter"] .t-sticker { width: 60px; height: 60px; }
  .t-paper { flex: none; width: 72px; }
  #cart { border: none; max-height: none; padding: 20px 16px 32px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
