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

html, body {
  height: 100%;
  font-family: 'Segoe UI', 'Malgun Gothic', sans-serif;
  background: linear-gradient(180deg, #a8e063, #56ab2f);
  overscroll-behavior: none;
}

/* 아이폰 사파리: 주소창/하단바를 뺀 실제 보이는 높이 사용 */
@supports (height: 100dvh) {
  body { height: 100dvh; }
}

body {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ── 상단 바 ── */
#topbar {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 0 0 14px 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

#topbar .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.stat { font-size: 15px; font-weight: 700; color: #333; white-space: nowrap; }

.lv-stat { display: flex; align-items: center; gap: 6px; flex: 1; }

.lv-badge {
  background: #7b1fa2; color: #fff;
  padding: 2px 8px; border-radius: 10px;
  font-size: 13px;
}

.xp-bar {
  flex: 1; max-width: 80px; height: 8px;
  background: #e1bee7; border-radius: 4px; overflow: hidden;
}

#xp-fill { height: 100%; width: 0%; background: #ab47bc; transition: width 0.3s; }

#sound-btn, #help-btn {
  border: none; background: none;
  font-size: 20px; cursor: pointer;
}

#topbar { position: relative; }

#sound-menu {
  position: absolute;
  top: 100%; right: 12px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 150;
}

#sound-menu button {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px; font-weight: 700;
  background: #e8f5e9; color: #2e7d32;
  cursor: pointer;
  white-space: nowrap;
}

#sound-menu button.off { background: #f5f5f5; color: #9e9e9e; }

/* ── 탭 ── */
#tabs { display: flex; gap: 6px; padding: 8px 14px 0; }

.tab {
  flex: 1;
  padding: 9px 4px;
  font-size: 15px; font-weight: 700;
  border: none; border-radius: 12px 12px 0 0;
  background: rgba(255,255,255,0.5);
  color: #444;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active { background: #fff; color: #2e7d32; }

main {
  flex: 1;
  background: #fff;
  margin: 0 14px 14px;
  border-radius: 0 0 14px 14px;
  padding: 10px;
  /* 아이폰 사파리 하단 바에 안 가리게 여유 공간 */
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

main h2 { font-size: 17px; color: #2e7d32; margin: 12px 0 8px; }
main h2 small { font-size: 11px; color: #999; font-weight: 400; }

/* ── 주문 ── */
#orders {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.order {
  flex: 1;
  background: #fffde7;
  border: 1px solid #ffe082;
  border-radius: 10px;
  padding: 6px 4px;
  text-align: center;
  position: relative;
  font-size: 12px;
}

.order .cust { font-size: 24px; line-height: 1.1; }

.order .reroll {
  position: absolute;
  top: -6px; right: -5px;
  width: 24px; height: 24px;
  border: 1px solid #ffcc80;
  border-radius: 50%;
  background: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.order .reroll:active { transform: rotate(180deg); }

.order .req { margin: 2px 0; font-size: 14px; }
.order .req .short { color: #e53935; font-weight: 700; }
.order .req .enough { color: #43a047; font-weight: 700; }
.order .reward { color: #f57f17; font-weight: 700; font-size: 12px; }

.order .deliver-btn {
  margin-top: 4px;
  width: 90%;
  padding: 4px 0;
  border: none; border-radius: 7px;
  background: #ff9800; color: #fff;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
}

.order .deliver-btn:disabled { background: #e0e0e0; color: #9e9e9e; }

.order.vip {
  background: linear-gradient(160deg, #fff8e1, #ffe57f);
  border: 2px solid #ffb300;
  box-shadow: 0 0 8px rgba(255, 179, 0, 0.5);
}

.order .vip-time {
  font-size: 11px;
  font-weight: 800;
  color: #d84315;
}

/* ── 머지 보드 ── */
#board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  /* 빈 칸·덩굴 위에서는 위아래로 쓸어서 화면 스크롤 가능 */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

/* 아이템이 있는 칸만 드래그 전용 (스크롤 차단) */
.cell.filled { touch-action: none; }

.cell {
  aspect-ratio: 1;
  background: #e8f5e9;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(22px, 8vw, 38px);
  position: relative;
  cursor: pointer;
}

.cell.selected { outline: 3px solid #ff9800; outline-offset: -3px; }
.cell.gen { background: #c8e6c9; }
.cell.vine { background: #33691e; font-size: clamp(18px, 6.5vw, 30px); }

.cell.gift {
  background: #fff3e0;
  animation: giftwiggle 1.6s ease-in-out infinite;
}

@keyframes giftwiggle {
  0%, 100% { transform: rotate(0); }
  10% { transform: rotate(-6deg); }
  20% { transform: rotate(6deg); }
  30% { transform: rotate(0); }
}

.cell .lv {
  position: absolute;
  bottom: 2px; right: 4px;
  font-size: 10px; font-weight: 700;
  color: #666;
}

.cell.pop > span.item { animation: pop 0.25s ease; }

@keyframes pop {
  0% { transform: scale(0.3); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ── 창고 ── */
#storage-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 8px;
  background: #efebe9;
  border-radius: 10px;
}

.store-label { font-size: 18px; }

#storage { display: flex; gap: 6px; flex: 1; }

.store-slot {
  width: 44px; height: 44px;
  background: #fff;
  border: 2px dashed #bcaaa4;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  cursor: pointer;
  position: relative;
}

.store-slot:not(.empty) { border-style: solid; border-color: #8d6e63; }

.store-del {
  position: absolute;
  top: -7px; right: -7px;
  width: 18px; height: 18px;
  border: none; border-radius: 50%;
  background: #e53935; color: #fff;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
}

.store-add {
  height: 44px;
  padding: 0 10px;
  border: none; border-radius: 8px;
  background: #d7ccc8; color: #4e342e;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
}

#info-bar {
  margin-top: 8px;
  padding: 8px 12px;
  background: #fff8e1;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

#action-btn, #store-btn {
  padding: 6px 14px;
  border: none; border-radius: 8px;
  background: #ff9800; color: #fff;
  font-size: 14px; font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

#store-btn { background: #8d6e63; }

#hint-btn {
  display: block;
  margin: 10px auto 0;
  padding: 8px 22px;
  border: none; border-radius: 20px;
  background: #fff3e0; color: #e65100;
  font-size: 14px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ── 마을 지표 (자연·행복) ── */
#vstats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.vstat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.vstat-label { font-weight: 700; color: #33691e; width: 66px; }

.vstat-bar {
  width: 90px; height: 9px;
  background: #eee;
  border-radius: 5px;
  overflow: hidden;
  flex-shrink: 0;
}

.vstat-bar > div { height: 100%; border-radius: 5px; transition: width 0.5s; }
.vstat-bar > .nature { background: linear-gradient(90deg, #aed581, #558b2f); }
.vstat-bar > .happy { background: linear-gradient(90deg, #ffe082, #fb8c00); }

.vstat-num { font-weight: 800; color: #555; width: 24px; }
.vstat-row small { color: #999; font-size: 11px; }

#vguide {
  background: #fff8e1;
  border: 2px dashed #ffb300;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: #6d4c41;
  margin-bottom: 8px;
  animation: coachbounce 1.2s ease-in-out infinite;
}

/* ── 마을 맵 (그림 지도 + 팬/줌) ── */
#vmap {
  position: relative;
  height: 430px;
  border-radius: 14px;
  overflow: hidden;
  background: #558b2f;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.3);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#vworld {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

#vworld > svg {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

#vzoom {
  position: absolute;
  right: 8px; bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

#vzoom button {
  width: 38px; height: 38px;
  border: none; border-radius: 50%;
  background: rgba(255,255,255,0.9);
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

/* 배치 슬롯 */
.vslot {
  position: absolute;
  width: 12.5%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.vslot.empty::after {
  content: '';
  width: 42%; height: 42%;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.4);
  background: radial-gradient(circle, rgba(255,255,255,0.16), transparent 70%);
}

.vslot.vtarget {
  border: 3px dashed #fff59d;
  background: radial-gradient(circle, rgba(255,245,157,0.5), transparent 70%);
  animation: targetblink 0.9s ease-in-out infinite;
}

@keyframes targetblink {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.15); }
}

.vslot.vsel {
  background: radial-gradient(circle, rgba(255,152,0,0.35), transparent 70%);
  border: 3px solid #ff9800;
}

.vslot .vemoji {
  line-height: 1;
  filter: drop-shadow(0 3px 2px rgba(0,0,0,0.35));
}

/* 티어가 높을수록 큰 건물 */
.vslot .vemoji.t1 { font-size: 27px; }
.vslot .vemoji.t2 { font-size: 33px; }
.vslot .vemoji.t3 { font-size: 40px; }
.vslot .vemoji.td { font-size: 22px; }

/* 건물 바닥 그림자 */
.vslot.built::before, .vslot.decor::before {
  content: '';
  position: absolute;
  bottom: 12%;
  width: 60%; height: 16%;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 50%;
  z-index: -1;
}

/* 건설 중 진행바 */
.vslot .vprog {
  position: absolute;
  bottom: 6%;
  width: 80%; height: 7px;
  background: rgba(0,0,0,0.4);
  border-radius: 4px;
  overflow: hidden;
}

.vslot .vprog > div {
  height: 100%;
  background: linear-gradient(90deg, #ffd54f, #ff9800);
  border-radius: 4px;
}

.vslot .vstock {
  position: absolute;
  top: 0; right: 0;
  min-width: 17px; height: 17px;
  background: #e53935; color: #fff;
  border: 1.5px solid #fff;
  border-radius: 9px;
  font-size: 10px; font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  z-index: 2;
}

.vslot .vworking {
  position: absolute;
  top: 0; right: 2%;
  font-size: 12px;
  z-index: 2;
}

/* 입힐 수 있는 스킨이 있는 건물 표시 */
.vslot .vskin-badge {
  position: absolute;
  top: -2px; left: 0;
  font-size: 11px;
  z-index: 2;
  animation: bubblepop 1.4s ease-in-out infinite;
}

.count-note {
  font-size: 11px;
  color: #1565c0;
  background: #e3f2fd;
  border-radius: 8px;
  padding: 1px 6px;
  white-space: nowrap;
}

.skin-note {
  font-size: 11px;
  color: #7b1fa2;
  background: #f3e5f5;
  border-radius: 8px;
  padding: 1px 6px;
  white-space: nowrap;
}

/* ── 잠긴 구역 안개 ── */
.vfog {
  position: absolute;
  left: 0; right: 0;
  background: rgba(38, 50, 56, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
}

.vfog-btn {
  border: 2px solid #fff;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: #37474f;
  font-size: 14px; font-weight: 700;
  padding: 12px 20px;
  cursor: pointer;
  line-height: 1.6;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.vfog-btn b { color: #e65100; font-size: 16px; }
.vfog-btn:disabled { opacity: 0.7; cursor: default; }
.vfog-btn:disabled b { color: #90a4ae; font-size: 13px; }

/* ── 주민 (이모지 머리 + 그린 몸통!) ── */
.vpeep {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -85%);
  pointer-events: auto;
  cursor: grab;
  transition: left 1s linear, top 1s linear;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
}

.pchar { position: relative; width: 22px; height: 31px; }

.phead {
  position: absolute;
  top: -3px; left: 50%;
  transform: translateX(-50%);
  font-size: 15px;
  line-height: 1;
  z-index: 2;
}

.ptorso {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  width: 12px; height: 11px;
  border-radius: 6px 6px 4px 4px;
  background: var(--pc, #42a5f5);
}

.parm {
  position: absolute;
  top: 13px;
  width: 3px; height: 8px;
  border-radius: 2px;
  background: var(--pc, #42a5f5);
  transform-origin: top center;
}
.parm.left { left: 3.5px; }
.parm.right { right: 3.5px; }

.pleg {
  position: absolute;
  top: 22.5px;
  width: 3.5px; height: 8px;
  border-radius: 2px;
  background: #5d4037;
  transform-origin: top center;
}
.pleg.left { left: 6.5px; }
.pleg.right { right: 6.5px; }

.ptool {
  position: absolute;
  top: 7px; right: -9px;
  font-size: 11px;
  display: none;
  transform-origin: bottom left;
}

/* 걷기: 팔다리 휘적휘적 + 통통 */
.vpeep.walking .pchar { animation: peepbob 0.5s ease-in-out infinite; }
.vpeep.walking .pleg.left { animation: legswing 0.5s ease-in-out infinite; }
.vpeep.walking .pleg.right { animation: legswing 0.5s ease-in-out infinite reverse; }
.vpeep.walking .parm.left { animation: armswing 0.5s ease-in-out infinite reverse; }
.vpeep.walking .parm.right { animation: armswing 0.5s ease-in-out infinite; }

@keyframes peepbob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2.5px); } }
@keyframes legswing { 0%, 100% { transform: rotate(26deg); } 50% { transform: rotate(-26deg); } }
@keyframes armswing { 0%, 100% { transform: rotate(20deg); } 50% { transform: rotate(-20deg); } }

/* 일하기: 몸 기울여 망치질! */
.vpeep.working { transform: translate(-8%, -80%) scale(0.9); }
.vpeep.working .pchar { transform: rotate(6deg); }
.vpeep.working .ptool { display: block; animation: hammer 0.5s ease-in-out infinite; }
.vpeep.working .parm.right { animation: hammer 0.5s ease-in-out infinite; }

@keyframes hammer {
  0%, 100% { transform: rotate(-55deg); }
  45% { transform: rotate(10deg); }
}

/* 놀기: 만세하고 점프! */
.vpeep.playing .pchar { animation: peepjump 0.6s ease-in-out infinite; }
.vpeep.playing .parm.left { transform: rotate(150deg); }
.vpeep.playing .parm.right { transform: rotate(-150deg); }
.vpeep.playing .pleg.left { animation: legsplit 0.6s ease-in-out infinite; }
.vpeep.playing .pleg.right { animation: legsplit 0.6s ease-in-out infinite reverse; }

@keyframes peepjump {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-8px) rotate(4deg); }
}
@keyframes legsplit { 0%, 100% { transform: rotate(12deg); } 50% { transform: rotate(-12deg); } }

/* 쉬기: 기대서 꾸벅꾸벅 */
.vpeep.resting .pchar { animation: peepnod 2.4s ease-in-out infinite; }
.vpeep.resting .parm.left, .vpeep.resting .parm.right { transform: rotate(8deg); }

@keyframes peepnod {
  0%, 100% { transform: rotate(6deg); }
  55% { transform: rotate(18deg) translateY(1.5px); }
}

/* 말풍선 대사 */
.pspeech {
  position: absolute;
  bottom: 105%;
  left: 50%;
  transform: translateX(-50%);
  min-width: 60px;
  max-width: 110px;
  background: #fff;
  border: 1.5px solid #d7ccc8;
  border-radius: 10px;
  padding: 4px 7px;
  font-size: 9px;
  line-height: 1.35;
  color: #4e342e;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  z-index: 25;
  animation: storyup 0.2s ease;
}

.pspeech::after {
  content: '';
  position: absolute;
  top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #fff;
}

/* 드래그 중: 붕 떠서 대롱대롱 */
.vpeep.dragging {
  transition: none;
  z-index: 20;
  cursor: grabbing;
  filter: drop-shadow(0 8px 6px rgba(0,0,0,0.35));
}
.vpeep.dragging .pchar { transform: scale(1.25) rotate(-6deg); }
.vpeep.dragging .pleg.left { transform: rotate(18deg); }
.vpeep.dragging .pleg.right { transform: rotate(-14deg); }

.vpeep .pbubble {
  position: absolute;
  top: -15px; left: 55%;
  font-size: 12px;
  background: rgba(255,255,255,0.95);
  border-radius: 50%;
  padding: 2px 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  animation: bubblepop 1.4s ease-in-out infinite;
}

@keyframes bubblepop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

/* ── 건물 정보 패널 ── */
#vinfo {
  margin-top: 8px;
  padding: 10px 12px;
  background: #f1f8e9;
  border: 1px solid #c5e1a5;
  border-radius: 10px;
}

.vinfo-title { font-size: 16px; font-weight: 700; color: #33691e; margin-bottom: 4px; }
.vinfo-title small { font-size: 11px; color: #999; font-weight: 400; }
.vinfo-line { font-size: 13px; color: #555; margin: 3px 0; }
.vinfo-line.short-note { color: #e65100; font-weight: 700; }

.vbtn {
  margin: 5px 5px 0 0;
  padding: 7px 12px;
  border: none; border-radius: 8px;
  background: #a5d6a7; color: #1b5e20;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
}

.vbtn.primary { background: #ff9800; color: #fff; }
.vbtn.small { padding: 5px 8px; font-size: 12px; }
.vbtn:disabled { background: #e0e0e0; color: #9e9e9e; }

/* ── 재료함 ── */
.mat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid #eee;
  border-radius: 10px;
  margin-bottom: 6px;
}

.mat-row .mat-emoji { font-size: 24px; }
.mat-row .desc { flex: 1; font-size: 14px; }
.empty-note { font-size: 13px; color: #999; padding: 6px 2px; }

/* ── 건설 메뉴 시트 ── */
#build-sheet, #skin-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#skin-modal { align-items: center; padding: 16px; }

#build-box {
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 75vh;
  overflow-y: auto;
}

#build-box h3 { font-size: 15px; color: #2e7d32; margin: 8px 0 6px; }

#sheet-handle {
  width: 44px; height: 5px;
  background: #ccc;
  border-radius: 3px;
  margin: 0 auto 10px;
}

#build-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.btab {
  flex: 1;
  padding: 9px 4px;
  border: none;
  border-radius: 10px;
  background: #f1f1f1;
  color: #666;
  font-size: 14px; font-weight: 700;
  cursor: pointer;
}

.btab.active { background: #4caf50; color: #fff; }

.build-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  margin-bottom: 6px;
}

.build-item.locked { opacity: 0.55; }
.build-item .emoji { font-size: 28px; }
.build-item .desc { flex: 1; }
.build-item .desc b { display: block; font-size: 14px; }
.build-item .desc b small { color: #7b1fa2; font-size: 11px; }
.build-item .desc small { color: #777; font-size: 11px; }

.buy-btn {
  padding: 8px 10px;
  border: none; border-radius: 8px;
  background: #4caf50; color: #fff;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.buy-btn:disabled { background: #bdbdbd; cursor: default; }

#build-close {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  border: none; border-radius: 10px;
  background: #eee; color: #555;
  font-size: 15px; font-weight: 700;
  cursor: pointer;
}

/* ── 스킨 선택 ── */
#skin-box {
  background: #fff;
  border-radius: 16px;
  padding: 20px 16px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

#skin-box h3 { color: #7b1fa2; font-size: 20px; }
#skin-sub { font-size: 13px; color: #777; margin: 6px 0 14px; }

#skin-options { display: flex; gap: 10px; justify-content: center; }

.skin-option {
  width: 84px; height: 84px;
  font-size: 44px;
  border: 3px solid #e1bee7;
  border-radius: 14px;
  background: #fce4ec;
  cursor: pointer;
  animation: skinshine 1.5s ease-in-out infinite;
}

.skin-option:active { transform: scale(0.92); }

@keyframes skinshine {
  0%, 100% { box-shadow: 0 0 4px rgba(171, 71, 188, 0.4); }
  50% { box-shadow: 0 0 16px rgba(171, 71, 188, 0.9); }
}

/* ── 퍼즐 허브 (게임 선택) ── */
#game-menu { display: flex; flex-direction: column; gap: 10px; padding: 6px 0; }

.game-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 2px solid #f8bbd0;
  border-radius: 14px;
  background: linear-gradient(150deg, #fff, #fce4ec);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.game-card.locked { filter: grayscale(0.8); opacity: 0.65; }
.game-card .game-emoji { font-size: 36px; }
.game-card .game-info { flex: 1; }
.game-card .game-info b { display: block; font-size: 16px; color: #880e4f; }
.game-card .game-info small { color: #777; font-size: 12px; line-height: 1.4; }

.game-card .game-progress {
  font-size: 12px; font-weight: 700;
  color: #d81b60;
  background: #fce4ec;
  border-radius: 10px;
  padding: 3px 8px;
  white-space: nowrap;
}

.game-back {
  border: none;
  background: #f5f5f5;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 13px; font-weight: 700;
  color: #666;
  cursor: pointer;
  margin-bottom: 8px;
}

/* ── 오목 ── */
#omok-board {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 1px;
  background: #c8a165;
  border: 6px solid #a1783f;
  border-radius: 10px;
  padding: 3px;
  user-select: none;
  -webkit-user-select: none;
}

.omok-cell {
  aspect-ratio: 1;
  border: 1px solid #b08d55;
  background: #deb877;
  font-size: clamp(11px, 5.5vw, 24px);
  padding: 0;
  cursor: pointer;
  line-height: 1;
}

.omok-cell.omok-last { background: #ffe082; }

#omok-over {
  margin-top: 10px;
  padding: 14px;
  background: #fff3e0;
  border-radius: 12px;
  text-align: center;
}

#omok-over-text { font-size: 16px; font-weight: 700; color: #5d4037; margin-bottom: 4px; }
.omok-next { font-size: 13px; color: #d81b60; font-weight: 700; margin-bottom: 8px; }

#omok-again {
  padding: 10px 24px;
  border: none; border-radius: 10px;
  background: #8d6e63; color: #fff;
  font-size: 15px; font-weight: 700;
  cursor: pointer;
}

/* ── 퍼즐 (매치3) ── */
#m3top {
  display: flex;
  justify-content: space-around;
  padding: 6px 0 10px;
}

.m3stat { font-size: 14px; color: #555; }
.m3stat b { color: #d81b60; font-size: 16px; }

#m3board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: linear-gradient(160deg, #4a148c, #880e4f);
  padding: 7px;
  border-radius: 14px;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.4), 0 3px 8px rgba(0,0,0,0.25);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.m3cell {
  aspect-ratio: 1;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.12);
  font-size: clamp(18px, 7vw, 32px);
  cursor: pointer;
  padding: 0;
  position: relative;
  text-shadow: 0 2px 3px rgba(0,0,0,0.25);
  transition: transform 0.1s;
}

/* 캔디별 광택 캡슐 */
.m3cell.c0 { background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.85), transparent 42%), linear-gradient(150deg, #ff8a9e, #e91e63); }
.m3cell.c1 { background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.85), transparent 42%), linear-gradient(150deg, #b388ff, #7c4dff); }
.m3cell.c2 { background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.85), transparent 42%), linear-gradient(150deg, #a1887f, #5d4037); }
.m3cell.c3 { background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.85), transparent 42%), linear-gradient(150deg, #ffcc80, #f57c00); }
.m3cell.c4 { background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.85), transparent 42%), linear-gradient(150deg, #fff59d, #fbc02d); }

/* 특수 캔디: 금빛으로 번쩍번쩍 */
.m3cell.spec {
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.95), transparent 45%), linear-gradient(150deg, #ffe082, #ff6f00);
  animation: specglow 0.9s ease-in-out infinite;
  z-index: 1;
}

@keyframes specglow {
  0%, 100% { box-shadow: 0 0 6px 2px rgba(255, 215, 0, 0.8); transform: scale(1); }
  50% { box-shadow: 0 0 16px 5px rgba(255, 235, 59, 1); transform: scale(1.07); }
}

.m3cell.m3sel {
  outline: 3px solid #fff;
  outline-offset: -3px;
  transform: scale(1.1);
  z-index: 2;
}

.m3cell.m3pop { animation: m3vanish 0.24s ease forwards; }

@keyframes m3vanish {
  40% { transform: scale(1.25) rotate(10deg); }
  100% { transform: scale(0) rotate(-30deg); opacity: 0; }
}

.m3cell.m3fall { animation: m3drop 0.25s ease-out; }

@keyframes m3drop {
  from { transform: translateY(-16px); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}

#m3over {
  margin-top: 10px;
  padding: 14px;
  background: #fce4ec;
  border-radius: 12px;
  text-align: center;
}

#m3over-text { font-size: 16px; font-weight: 700; color: #880e4f; margin-bottom: 8px; }

#m3over-btn {
  padding: 10px 24px;
  border: none; border-radius: 10px;
  background: #d81b60; color: #fff;
  font-size: 15px; font-weight: 700;
  cursor: pointer;
}

#m3hint { margin-top: 10px; font-size: 12px; color: #999; text-align: center; line-height: 1.6; }

/* ── 스토리 북 ── */
.book-count { font-size: 12px; color: #8d6e63; margin-bottom: 6px; font-weight: 700; }

.book-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 5px;
  border: 1.5px solid #e8ddca;
  border-radius: 10px;
  background: linear-gradient(160deg, #fffdf5, #fdf3dd);
  cursor: pointer;
  text-align: left;
}

.book-row.locked { opacity: 0.45; cursor: default; background: #f5f5f5; }
.book-row .book-face { font-size: 20px; }
.book-row .book-title { flex: 1; font-size: 14px; font-weight: 700; color: #6d4c41; font-style: italic; }
.book-row .book-play { color: #bcaaa4; font-size: 15px; }

/* ── 업적 ── */
.ach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid #eee;
  border-radius: 10px;
  margin-bottom: 6px;
}

.ach-item.done { background: #f1f8e9; }
.ach-item .ach-check { font-size: 18px; }
.ach-item .desc { flex: 1; }
.ach-item .desc b { display: block; font-size: 14px; }
.ach-item .desc small { color: #888; font-size: 12px; }
.ach-item .ach-reward { font-size: 13px; font-weight: 700; color: #f57f17; white-space: nowrap; }

/* ── 도감 ── */
.coll-chain { margin-bottom: 10px; }
.coll-chain h3 { font-size: 14px; color: #555; margin-bottom: 4px; }

.coll-items { display: flex; gap: 4px; }

.coll-item {
  flex: 1;
  aspect-ratio: 1;
  background: #f5f5f5;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 6vw, 26px);
}

.coll-item.locked { filter: grayscale(1); opacity: 0.4; font-size: 16px; }

/* ── 안내 모달 ── */
#help-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#help-box {
  background: #fff;
  border-radius: 16px;
  padding: 18px 16px;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

#help-box h2 { color: #2e7d32; text-align: center; font-size: 22px; }

.help-sub { text-align: center; color: #777; font-size: 13px; margin: 4px 0 12px; }

.help-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.help-emoji { font-size: 26px; line-height: 1.2; }

.help-step p { font-size: 14px; color: #444; line-height: 1.5; }

.help-chain { font-size: 15px; letter-spacing: 1px; }

#help-close {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: none; border-radius: 12px;
  background: #4caf50; color: #fff;
  font-size: 17px; font-weight: 700;
  cursor: pointer;
}

/* ── 스토리 모달 ── */
#story-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 20, 0.6);
  z-index: 250;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
}

#story-box {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(170deg, #fffdf5, #fff3d6);
  border: 3px solid #d7b98e;
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 30px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  animation: storyup 0.35s ease;
}

@keyframes storyup {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

#story-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

#story-face {
  width: 52px; height: 52px;
  background: #fff;
  border: 2.5px solid #d7b98e;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
}

#story-name {
  font-size: 16px; font-weight: 800;
  color: #6d4c41;
}

#story-text {
  font-size: 15px;
  color: #4e342e;
  line-height: 1.65;
  min-height: 52px;
  font-style: italic;
}

#story-btns {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

#story-next {
  padding: 9px 22px;
  border: none; border-radius: 10px;
  background: #8d6e63; color: #fff;
  font-size: 14px; font-weight: 700;
  cursor: pointer;
}

#story-skip {
  padding: 9px 14px;
  border: none; border-radius: 10px;
  background: none; color: #a1887f;
  font-size: 13px;
  cursor: pointer;
}

/* ── 개발자 오버레이 ── */
#dev-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#dev-overlay.hidden { display: none; }

#dev-overlay-box {
  background: #263238;
  color: #eceff1;
  border-radius: 14px;
  padding: 16px;
  width: 100%;
  max-width: 440px;
  max-height: 82vh;
  overflow-y: auto;
}

#dev-overlay-box h3 { color: #80cbc4; margin-bottom: 10px; }

.dev-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid #37474f;
  font-size: 13px;
}

.dev-note { font-size: 12px; color: #b0bec5; margin-top: 10px; line-height: 1.5; }

.dev-scene { margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid #37474f; }
.dev-scene b { font-size: 14px; color: #ffcc80; }
.dev-scene small { color: #90a4ae; display: block; margin: 2px 0 4px; }
.dev-scene p { font-size: 13px; font-style: italic; color: #eceff1; margin: 2px 0; }

#dev-overlay-close {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  border: none; border-radius: 10px;
  background: #455a64; color: #fff;
  font-weight: 700;
  cursor: pointer;
}

/* ── 코치마크 / 힌트 ── */
#coach {
  position: fixed;
  z-index: 95;
  background: #37474f;
  color: #fff;
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  max-width: 82vw;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
  animation: coachbounce 1.2s ease-in-out infinite;
}

@keyframes coachbounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.tut-glow {
  animation: glowpulse 1s ease-in-out infinite;
  border-radius: 10px;
}

@keyframes glowpulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 152, 0, 0.9), 0 0 14px rgba(255, 152, 0, 0.7); }
  50% { box-shadow: 0 0 0 6px rgba(255, 193, 7, 0.5), 0 0 22px rgba(255, 193, 7, 0.9); }
}

/* ── 개발자 모드 ── */
#dev-fab {
  position: fixed;
  left: 10px; bottom: 10px;
  width: 44px; height: 44px;
  border: none; border-radius: 50%;
  background: #263238; color: #fff;
  font-size: 20px;
  z-index: 400;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
}

#dev-panel {
  position: fixed;
  left: 10px; bottom: 60px;
  background: #263238;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 400;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}

#dev-panel button {
  border: none; border-radius: 8px;
  background: #455a64; color: #fff;
  font-size: 13px; font-weight: 700;
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
}

#dev-panel button:active { background: #607d8b; }

/* ── 토스트/드래그/이펙트 ── */
#toast {
  position: fixed;
  left: 50%; bottom: 80px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.78);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 300;
  animation: fadein 0.2s;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

#drag-ghost {
  position: fixed;
  z-index: 99;
  font-size: 36px;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.float-txt {
  position: fixed;
  z-index: 98;
  font-size: 16px;
  font-weight: 800;
  color: #f57f17;
  text-shadow: 0 1px 3px rgba(255,255,255,0.9);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: floatup 1s ease-out forwards;
  white-space: nowrap;
}

.float-txt.big { font-size: 20px; color: #7b1fa2; }

@keyframes floatup {
  0% { opacity: 1; margin-top: 0; }
  100% { opacity: 0; margin-top: -50px; }
}
