/* Trade — 시장 교환 퍼즐
   분위기: 오후의 시장 거리. 크림색 하늘, 줄무늬 차양, 나무 진열대, 둥근 상품 코인. */

:root {
  --sky-1: #fff4df;
  --sky-2: #ffd9b0;
  --ink: #3b2416;
  --ink-soft: #7a5a44;
  --wood-1: #b8733f;
  --wood-2: #8a4f27;
  --wood-3: #5e3217;
  --slot: #6b3a1c;
  --cream: #fff8ec;
  --accent: #e8483f;
  --gold: #f5b82e;
  --good: #3fa35a;
  --shadow: 0 6px 18px rgba(80, 40, 10, 0.25);
  --cell: 56px;
  --speed: 1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 100%) fixed;
  font: 16px/1.5 "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app { max-width: 480px; margin: 0 auto; min-height: 100%; position: relative; overflow-x: hidden; }
.screen { padding: 12px 16px 24px; }

/* ── 공통 ── */
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: rgba(255, 255, 255, 0.7); box-shadow: 0 2px 0 rgba(94, 50, 23, 0.25);
  font-size: 18px; display: grid; place-items: center;
}
.icon-btn:active { transform: translateY(2px); box-shadow: none; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.75); font-size: 14px; color: var(--ink-soft);
}
.pill b { color: var(--ink); }

/* ── 지도 ── */
.map-head { text-align: center; padding: 12px 0 8px; }
.logo { display: inline-flex; align-items: center; gap: 10px; }
.logo h1 {
  margin: 0; font-size: 44px; letter-spacing: 0.02em; font-weight: 900;
  color: var(--wood-3); text-shadow: 0 3px 0 #ffd28f;
}
.logo-coins { position: relative; width: 44px; height: 32px; }
.logo-coins i {
  position: absolute; width: 28px; height: 28px; border-radius: 50%; top: 2px;
  border: 3px solid rgba(255, 255, 255, 0.8); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
  animation: logoSwap 3.2s ease-in-out infinite;
}
.logo-coins .c0 { left: 0; background: #e8483f; }
.logo-coins .c1 { left: 14px; background: #3f7fe0; animation-delay: -1.6s; }
@keyframes logoSwap { 0%, 40% { transform: translateX(0); } 50%, 90% { transform: translateX(0) scale(1.08); } }
.tagline { margin: 4px 0 12px; color: var(--ink-soft); font-size: 14px; }
.map-stats { display: flex; justify-content: center; align-items: center; gap: 8px; }

.daily-card {
  width: 100%; margin: 12px 0 8px; padding: 14px 16px; border: 0; border-radius: 18px; text-align: left;
  background: linear-gradient(135deg, #3b2416, #6b3a1c); color: var(--cream); box-shadow: var(--shadow);
  display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center;
}
.daily-card .d-icon { font-size: 32px; text-align: center; }
.daily-card .d-title { font-weight: 800; font-size: 17px; }
.daily-card .d-sub { font-size: 13px; opacity: 0.8; }
.daily-card .d-go {
  padding: 8px 14px; border-radius: 999px; background: var(--gold); color: var(--ink); font-weight: 800; font-size: 14px;
}
.daily-card.done .d-go { background: #ffffff33; color: var(--cream); }

.chapter {
  margin-top: 18px; border-radius: 20px; overflow: hidden; background: rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow);
}
.chapter.locked { filter: grayscale(0.85); opacity: 0.7; }
.chapter-sign {
  position: relative; padding: 22px 16px 12px; color: var(--cream);
  background: linear-gradient(180deg, var(--wood-1), var(--wood-2));
}
.chapter-sign::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 12px;
  background: repeating-linear-gradient(90deg, #e8483f 0 18px, #fff8ec 18px 36px);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.chapter-sign h2 { margin: 0; font-size: 19px; }
.chapter-sign p { margin: 2px 0 0; font-size: 13px; opacity: 0.85; }
.chapter-sign .ch-stars { position: absolute; right: 14px; top: 22px; font-size: 13px; font-weight: 700; }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 8px; padding: 16px 12px 18px; }
.lv {
  position: relative; justify-self: center; width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 35% 30%, #fff6d8, #f5b82e 60%, #c98710);
  box-shadow: 0 4px 0 #9a6208, 0 6px 10px rgba(0, 0, 0, 0.15);
  font-weight: 900; font-size: 19px; color: var(--wood-3);
}
.lv:active { transform: translateY(3px); box-shadow: 0 1px 0 #9a6208; }
.lv.boss { width: 64px; height: 64px; background: radial-gradient(circle at 35% 30%, #ffe0d6, #e8483f 60%, #9c2019); color: #fff; box-shadow: 0 4px 0 #6f1510, 0 6px 10px rgba(0, 0, 0, 0.15); }
.lv.boss::after { content: "👑"; position: absolute; top: -14px; left: 50%; transform: translateX(-50%); font-size: 16px; }
.lv.locked { background: #d8c9b6; color: #9b8a76; box-shadow: 0 4px 0 #b09c85; cursor: default; }
.lv.current { animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.lv .stars { position: absolute; bottom: -15px; left: 50%; transform: translateX(-50%); font-size: 11px; letter-spacing: -1px; white-space: nowrap; color: #c98710; }
.lv .stars .off { color: rgba(0, 0, 0, 0.15); }
.map-foot { margin: 24px 0 8px; text-align: center; font-size: 12px; color: var(--ink-soft); opacity: 0.7; }

/* ── 게임 HUD ── */
.hud { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px; }
.hud-title { line-height: 1.2; }
.hud-title b { font-size: 20px; }
.hud-title span { display: block; font-size: 12px; color: var(--ink-soft); }
.trades { display: flex; gap: 4px; align-items: flex-end; }
.weight {
  width: 20px; height: 24px; border-radius: 5px 5px 8px 8px; position: relative;
  background: linear-gradient(180deg, #8d8d95, #55555c); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.3s, opacity 0.3s;
}
.weight::before { content: ""; position: absolute; top: -6px; left: 6px; width: 8px; height: 6px; border: 2px solid #55555c; border-bottom: 0; border-radius: 6px 6px 0 0; }
.weight.used { opacity: 0.2; transform: translateY(4px) scale(0.9); }
.weight.pulse { animation: weightPulse 0.5s ease-out; }
@keyframes weightPulse { 50% { transform: scale(1.3); } }

.goal {
  margin: 10px 0 8px; padding: 8px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.8);
  display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; min-height: 42px;
  box-shadow: 0 2px 0 rgba(94, 50, 23, 0.15);
}
.goal .g-icon { font-size: 22px; }
.goal .g-bar { flex: 0 1 120px; height: 10px; border-radius: 99px; background: #eadbc6; overflow: hidden; }
.goal .g-bar i { display: block; height: 100%; background: var(--good); border-radius: 99px; transition: width 0.4s; }
.goal.bump { animation: bump 0.35s; }
@keyframes bump { 40% { transform: scale(1.06); } }

/* ── 진열대와 판 ── */
.stall { position: relative; margin: 8px auto 0; width: fit-content; }
.awning {
  height: 26px; margin: 0 -10px; border-radius: 14px 14px 4px 4px;
  background: repeating-linear-gradient(90deg, #e8483f 0 24px, #fff8ec 24px 48px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
  -webkit-mask: radial-gradient(12px at 12px 100%, transparent 98%, #000) 0 0 / 24px 100%;
  mask: radial-gradient(12px at 12px 100%, transparent 98%, #000) 0 0 / 24px 100%;
}
.board-wrap {
  position: relative; padding: 10px; border-radius: 0 0 18px 18px;
  background: linear-gradient(180deg, var(--wood-1), var(--wood-2)); box-shadow: var(--shadow), inset 0 -4px 0 var(--wood-3);
}
.board-wrap.shake { animation: shake calc(0.4s * var(--speed)); }
@keyframes shake { 20% { transform: translate(-4px, 2px); } 40% { transform: translate(4px, -2px); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, 0); } }
.board {
  position: relative; width: calc(var(--cols) * var(--cell)); height: calc(var(--rows) * var(--cell));
  background:
    radial-gradient(circle, rgba(0, 0, 0, 0.28) 0 calc(var(--cell) * 0.36), transparent calc(var(--cell) * 0.37)) 0 0 / var(--cell) var(--cell),
    var(--slot);
  border-radius: 10px;
  touch-action: none;
}
.fx { position: absolute; inset: 10px; pointer-events: none; }
.chain {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(0.6); pointer-events: none;
  font-weight: 900; font-size: 34px; color: #fff; text-shadow: 0 3px 0 var(--accent), 0 0 18px rgba(0, 0, 0, 0.35); opacity: 0;
  white-space: nowrap;
}
.chain.show { animation: chainPop calc(0.9s * var(--speed)) ease-out; }
@keyframes chainPop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); } 25% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); } 70% { opacity: 1; transform: translate(-50%, -60%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -80%) scale(1); } }

/* 칸 하나 = 타일 하나. 위치는 transform, 떨어질 때 transition */
.tile {
  position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell);
  transition: transform calc(0.22s * var(--speed)) cubic-bezier(0.5, 0, 0.9, 0.6);
  display: grid; place-items: center; pointer-events: none;
}
.tile.no-anim { transition: none; }
.coin {
  width: 86%; height: 86%; border-radius: 50%; display: grid; place-items: center; position: relative;
  background: radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.75) 0 12%, transparent 13%),
              radial-gradient(circle at 50% 45%, var(--c) 0 58%, color-mix(in srgb, var(--c) 70%, #000) 100%);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--c) 55%, #000), inset 0 -3px 4px rgba(0, 0, 0, 0.2);
  font-size: calc(var(--cell) * 0.42); line-height: 1;
  transition: transform calc(0.15s * var(--speed)), filter 0.15s;
}
.coin .e { filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.25)); }
.tile.selected .coin { transform: translateY(-5px) scale(1.06); filter: brightness(1.12); box-shadow: 0 7px 0 color-mix(in srgb, var(--c) 55%, #000), 0 0 0 3px #fff, 0 0 16px 4px rgba(255, 255, 255, 0.8); }
.tile.dim .coin { filter: saturate(0.5) brightness(0.8); }
.tile.hint .coin { animation: hintPulse 0.9s ease-in-out infinite; }
@keyframes hintPulse { 50% { transform: scale(1.12); box-shadow: 0 0 0 3px var(--gold), 0 0 20px 6px var(--gold); } }

/* 자물쇠 상자: 코인 둘레에 나무 상자 */
.tile.lock .coin::after {
  content: ""; position: absolute; inset: -6%; border-radius: 22%;
  border: calc(var(--cell) * 0.07) solid #a8703e; box-shadow: inset 0 0 0 2px #6e4420, 0 0 0 2px #6e4420;
}
.tile.lock .badge, .tile.bomb .badge {
  position: absolute; right: 2%; bottom: 2%; font-size: calc(var(--cell) * 0.28); line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5));
}
.tile.unlock .coin::after { animation: crateBreak calc(0.35s * var(--speed)) forwards; }
@keyframes crateBreak { to { transform: scale(1.4) rotate(8deg); opacity: 0; } }

.stone {
  width: 92%; height: 92%; border-radius: 26% 32% 28% 34%;
  background: radial-gradient(circle at 35% 30%, #c9c3bb, #8a837b 60%, #625c55);
  box-shadow: 0 3px 0 #4c4640, inset 0 -3px 5px rgba(0, 0, 0, 0.25);
}
.gem-tile .coin { background: radial-gradient(circle at 40% 30%, #ffffff, #bdf1ff 50%, #5cc3e8); box-shadow: 0 3px 0 #2e8fb5, 0 0 12px 2px rgba(140, 230, 255, 0.9); }

/* 변색: 코인이 뒤집히며 다른 상품이 된다 */
.tile.flip .coin { animation: coinFlip calc(0.32s * var(--speed)) ease-in-out; }
@keyframes coinFlip { 0% { transform: rotateY(0); } 50% { transform: rotateY(90deg) scale(1.1); } 100% { transform: rotateY(0); } }

/* 팔림 */
.tile.pop .coin, .tile.pop .stone { animation: pop calc(0.3s * var(--speed)) ease-in forwards; }
@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(1.25); filter: brightness(1.4); } 100% { transform: scale(0); opacity: 0; } }
.tile.gem-out .coin { animation: gemOut calc(0.5s * var(--speed)) ease-in forwards; }
@keyframes gemOut { to { transform: translateY(80%) scale(0.4); opacity: 0; } }

/* 미리보기: 바뀔 칸에 목적 상품 고스트, 팔릴 칸 깜빡임 */
.tile .ghost {
  position: absolute; inset: 7%; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--g) 80%, transparent); font-size: calc(var(--cell) * 0.42);
  border: 2px dashed #fff; opacity: 0.9; animation: ghostIn 0.15s ease-out;
}
@keyframes ghostIn { from { transform: scale(0.6); opacity: 0; } }
.tile.will-pop .coin, .tile.will-pop .ghost { animation: willPop 0.5s ease-in-out infinite alternate; }
@keyframes willPop { to { transform: scale(0.88); filter: brightness(1.35); } }

.particle { position: absolute; width: 8px; height: 8px; border-radius: 50%; animation: particle calc(0.55s * var(--speed)) ease-out forwards; }
@keyframes particle { to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; } }
.float-text { position: absolute; font-weight: 900; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); animation: floatUp calc(0.8s * var(--speed)) ease-out forwards; pointer-events: none; font-size: 18px; }
@keyframes floatUp { to { transform: translateY(-36px); opacity: 0; } }
.blast { position: absolute; border-radius: 50%; background: radial-gradient(circle, #fff6b0, #ff8a1f 45%, rgba(232, 72, 63, 0) 70%); animation: blast calc(0.4s * var(--speed)) ease-out forwards; }
@keyframes blast { from { transform: scale(0.3); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }

/* ── 팔레트와 버튼 ── */
.prompt { margin: 12px 0 4px; min-height: 22px; text-align: center; font-size: 14px; color: var(--ink-soft); }
.prompt b { color: var(--ink); }
.palette { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; min-height: 64px; padding: 6px 0; touch-action: none; }
.pal {
  position: relative; width: 52px; height: 52px; border: 0; padding: 0; background: none;
  transition: transform calc(0.15s * var(--speed));
}
.pal .coin { width: 100%; height: 100%; font-size: 24px; }
.pal .count { position: absolute; right: -4px; top: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; background: var(--ink); color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center; }
.pal.selected { transform: translateY(-8px); }
.pal.selected .coin { box-shadow: 0 0 0 3px #fff, 0 0 16px 4px rgba(255, 255, 255, 0.9); }
.pal.fixed .coin { filter: saturate(0.55); }
.pal.fixed::after { content: "🔒"; position: absolute; left: -4px; top: -6px; font-size: 14px; }
.pal.hint .coin { animation: hintPulse 0.9s ease-in-out infinite; }
.pal.target .coin { box-shadow: 0 0 0 3px var(--gold), 0 0 16px 4px var(--gold); }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.act {
  border: 0; border-radius: 14px; padding: 10px 6px; background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 3px 0 rgba(94, 50, 23, 0.25); font-weight: 700; font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.act span { font-size: 20px; line-height: 1; }
.act:active { transform: translateY(3px); box-shadow: none; }
.act:disabled { opacity: 0.4; cursor: default; }

/* ── 겹창 ── */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(40, 20, 8, 0.45); animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } }
.card {
  width: min(360px, 100%); padding: 22px 20px 18px; border-radius: 24px; text-align: center;
  background: var(--cream); box-shadow: 0 20px 40px rgba(40, 20, 8, 0.4); animation: cardIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes cardIn { from { transform: translateY(30px) scale(0.9); opacity: 0; } }
.card h2 { margin: 0 0 4px; font-size: 26px; }
.card p { margin: 6px 0; color: var(--ink-soft); }
.card .big { font-size: 56px; line-height: 1.1; margin: 4px 0; }
.card .row { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 14px; padding: 11px 18px; font-weight: 800; background: #eadbc6; box-shadow: 0 3px 0 #c7b297;
}
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 3px 0 #9c2019; }
.btn.gold { background: var(--gold); box-shadow: 0 3px 0 #b8841b; }
.btn:active { transform: translateY(3px); box-shadow: none; }
.result-stars { font-size: 44px; letter-spacing: 6px; margin: 6px 0; }
.result-stars i { display: inline-block; font-style: normal; color: rgba(0, 0, 0, 0.12); }
.result-stars i.on { color: var(--gold); animation: starIn 0.4s cubic-bezier(0.2, 1.6, 0.4, 1) backwards; text-shadow: 0 2px 0 #b8841b; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); } }
.merchant { font-size: 54px; display: inline-block; animation: bounce 0.8s ease-in-out infinite alternate; }
@keyframes bounce { to { transform: translateY(-6px) rotate(-4deg); } }
.intro-demo { display: flex; justify-content: center; align-items: center; gap: 8px; margin: 12px 0 4px; font-size: 30px; }
.intro-demo .mini { width: 44px; height: 44px; font-size: 22px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid #eadbc6; text-align: left; }
.setting small { display: block; color: var(--ink-soft); }

/* 손가락 가이드 */
.hand {
  position: fixed; z-index: 15; font-size: 40px; pointer-events: none; transform: translate(-30%, 10%);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.35)); animation: handTap 1s ease-in-out infinite;
}
@keyframes handTap { 50% { transform: translate(-30%, 25%) scale(0.9); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 30; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 16px; border-radius: 999px; background: rgba(40, 20, 8, 0.85); color: #fff; font-size: 14px;
  transition: opacity 0.2s, transform 0.2s; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .lv.current, .merchant, .logo-coins i { animation: none; }
}

/* 고추: 코인 둘레에 불꽃 테두리, 고추 표식은 크게 */
.tile.bomb .coin { box-shadow: 0 3px 0 color-mix(in srgb, var(--c) 55%, #000), 0 0 0 3px #ff8a1f, 0 0 10px 3px rgba(255, 120, 30, 0.8); }
.tile.bomb .badge { font-size: calc(var(--cell) * 0.36); right: -2%; bottom: -2%; }
.goal { white-space: nowrap; }
.goal .g-bar { min-width: 40px; }
@media (max-width: 380px) { .goal { font-size: 14px; gap: 6px; padding: 8px 10px; } }
