/* Fold — 종이 접기 퍼즐
   분위기: 문구점 책상. 따뜻한 회백 책상, 공책 지도, 도톰한 색종이 조각. */

:root {
  --desk: #efece6;
  --desk-2: #e2ddd3;
  --ink: #2f2a24;
  --ink-soft: #7a7064;
  --line: #b9d3ee;
  --margin: #f08a8a;
  --paper: #fffdf8;
  --accent: #e4553f;
  --gold: #f2b233;
  --shadow: 0 6px 16px rgba(60, 45, 25, 0.18);
  --cell: 60px;
  --speed: 1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.7), transparent 40%),
    repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.012) 0 2px, transparent 2px 6px),
    var(--desk);
  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: 10px; border: 0; background: var(--paper);
  box-shadow: 0 2px 0 rgba(60, 45, 25, 0.2); 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: var(--paper); font-size: 14px; color: var(--ink-soft); }
.pill b { color: var(--ink); }

/* ── 지도: 공책 ── */
.map-head { text-align: center; padding: 14px 0 6px; }
.logo { margin: 0; font-size: 46px; font-weight: 900; letter-spacing: 0.02em; display: inline-flex; align-items: center; gap: 12px; }
.logo-sheet {
  width: 40px; height: 40px; position: relative; background: #e4553f; border-radius: 3px;
  clip-path: polygon(0 0, 62% 0, 100% 38%, 100% 100%, 0 100%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
}
.logo-sheet::after {
  content: ""; position: absolute; right: 0; top: 0; width: 38%; height: 38%;
  background: linear-gradient(225deg, transparent 50%, #b83a28 50%);
}
.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: 6px; text-align: left;
  background: #2f2a24; color: #fffdf8; box-shadow: var(--shadow);
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%);
}
.daily-card .d-icon { font-size: 30px; text-align: center; }
.daily-card .d-title { font-weight: 800; font-size: 17px; display: block; }
.daily-card .d-sub { font-size: 13px; opacity: 0.8; display: block; }
.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: #ffffff2a; color: #fff; }

.chapter {
  position: relative; margin-top: 18px; padding: 18px 14px 20px 44px; border-radius: 4px;
  background:
    linear-gradient(90deg, transparent 32px, var(--margin) 32px 34px, transparent 34px),
    repeating-linear-gradient(180deg, transparent 0 27px, var(--line) 27px 28px),
    var(--paper);
  box-shadow: var(--shadow);
}
.chapter::before { /* 스프링 구멍 */
  content: ""; position: absolute; left: 10px; top: 14px; bottom: 14px; width: 10px;
  background: radial-gradient(circle, #d7d0c4 0 4px, transparent 5px) 0 0 / 10px 28px;
}
.chapter.locked { opacity: 0.55; filter: grayscale(0.7); }
.chapter h2 { margin: 0; font-size: 19px; line-height: 28px; }
.chapter .ch-intro { margin: 0; font-size: 13px; color: var(--ink-soft); line-height: 28px; }
.chapter .ch-stars { position: absolute; right: 14px; top: 18px; font-size: 13px; font-weight: 800; color: #c98c10; line-height: 28px; }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px 8px; padding-top: 12px; }
.lv {
  position: relative; justify-self: center; width: 56px; height: 56px; border: 0; border-radius: 3px;
  background: var(--c, #f2c43d); color: #fff; font-weight: 900; font-size: 20px; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.15);
}
.lv::after { content: ""; position: absolute; right: 0; top: 0; width: 14px; height: 14px; background: linear-gradient(225deg, transparent 50%, rgba(0, 0, 0, 0.25) 50%); }
.lv.boss { width: 62px; height: 62px; }
.lv.boss::before { content: "👑"; position: absolute; left: 50%; top: -2px; transform: translate(-50%, -60%); font-size: 15px; }
.lv.locked { background: #ddd6ca; color: #a79d8f; text-shadow: none; cursor: default; }
.lv.current { animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(-5px) rotate(-3deg); } }
.lv-wrap { position: relative; display: grid; justify-items: center; }
.lv-stars { position: absolute; bottom: -17px; font-size: 11px; letter-spacing: -1px; color: #c98c10; white-space: nowrap; }
.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); }
.folds { display: flex; gap: 4px; }
.fold-chip {
  width: 20px; height: 24px; background: var(--paper); border-radius: 2px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); position: relative;
  clip-path: polygon(0 0, 60% 0, 100% 35%, 100% 100%, 0 100%); transition: opacity 0.3s, transform 0.3s;
}
.fold-chip::after { content: ""; position: absolute; right: 0; top: 0; width: 40%; height: 35%; background: linear-gradient(225deg, transparent 50%, #cfc6b8 50%); }
.fold-chip.used { opacity: 0.18; transform: scale(0.85); }
.goal {
  margin: 10px 0 6px; padding: 8px 14px; border-radius: 10px; background: var(--paper);
  display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; min-height: 42px; white-space: nowrap;
  box-shadow: 0 2px 0 rgba(60, 45, 25, 0.12);
}
.goal .swatch { width: 22px; height: 22px; border-radius: 3px; background: var(--c); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15); display: inline-grid; place-items: center; color: #fff; font-size: 12px; }
.goal.bump { animation: bump 0.35s; }
@keyframes bump { 40% { transform: scale(1.05); } }

/* ── 책상과 판 ── */
.desk { position: relative; display: flex; align-items: center; justify-content: center; margin: 6px 0 0; touch-action: none; user-select: none; }
.board {
  position: relative; width: calc(var(--w) * var(--cell)); height: calc(var(--h) * var(--cell));
  background: var(--paper); border-radius: 4px;
  box-shadow: 0 1px 0 #fff inset, 0 8px 18px rgba(60, 45, 25, 0.22), 0 2px 0 #d9d2c6;
  transition: width calc(0.28s * var(--speed)) ease, height calc(0.28s * var(--speed)) ease;
  perspective: 900px;
}
.board::before { /* 칸 자국 */
  content: ""; position: absolute; inset: 0; border-radius: 4px; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.06) 1px, transparent 1px) 0 0 / var(--cell) var(--cell),
    linear-gradient(180deg, rgba(0, 0, 0, 0.06) 1px, transparent 1px) 0 0 / var(--cell) var(--cell);
}
.tiles, .preview, .fx { position: absolute; inset: 0; pointer-events: none; }
.preview { z-index: 3; }
.fx { z-index: 5; }

.tile {
  position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); padding: 3px;
  transition: transform calc(0.28s * var(--speed)) ease, opacity 0.2s;
}
.tile.no-anim { transition: none; }
.paper {
  position: relative; width: 100%; height: 100%; border-radius: 3px; background: var(--c);
  background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.28), transparent 45%), linear-gradient(0deg, rgba(0, 0, 0, 0.08), transparent 40%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.18), inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  display: grid; place-items: center; color: rgba(255, 255, 255, 0.85); font-size: calc(var(--cell) * 0.26); font-weight: 900;
}
.paper .sym { opacity: 0.7; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2); }
/* 겹 종이: 아래로 종이가 더 깔린 두께감 + 숫자 */
.tile.layered .paper { box-shadow: 3px 3px 0 -1px color-mix(in srgb, var(--c) 75%, #000), 5px 5px 0 -2px color-mix(in srgb, var(--c) 60%, #000), 0 2px 3px rgba(0, 0, 0, 0.18); }
.paper .layers { position: absolute; right: 3px; bottom: 1px; font-size: calc(var(--cell) * 0.24); color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }
/* 클립 */
.paper .clip { position: absolute; top: -9px; left: 50%; transform: translateX(-50%) rotate(-12deg); font-size: calc(var(--cell) * 0.34); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); }
.tile.clip .paper { outline: 2px dashed rgba(255, 255, 255, 0.7); outline-offset: -5px; }
/* 무지개 홀로그램 */
.tile.rainbow .paper { background: conic-gradient(from 30deg, #ff6b6b, #ffd166, #6ee7b7, #60a5fa, #c084fc, #ff6b6b); animation: holo 3s linear infinite; }
@keyframes holo { to { filter: hue-rotate(360deg); } }
/* 돌 */
.tile.stone .paper { background: radial-gradient(circle at 35% 30%, #cdc7bf, #8b847b 60%, #635d56); border-radius: 30% 36% 32% 38%; box-shadow: 0 3px 0 #4c4640, inset 0 -3px 5px rgba(0, 0, 0, 0.25); }
/* 잉크 */
.tile.ink .paper { border-radius: 42% 50% 46% 52% / 50% 44% 54% 46%; }
.paper .drop { position: absolute; font-size: calc(var(--cell) * 0.38); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3)); }

/* 접기 중 들린 쪽 */
.tile.lifted .paper { transform: translateY(-3px); box-shadow: 0 8px 10px rgba(0, 0, 0, 0.25); }
.tile.hint-move .paper { animation: hintPulse 0.9s ease-in-out infinite; }
@keyframes hintPulse { 50% { transform: scale(0.92); box-shadow: 0 0 0 3px var(--gold), 0 0 14px 4px var(--gold); } }
.tile.press .paper { animation: press calc(0.25s * var(--speed)); }
@keyframes press { 40% { transform: scale(0.9); } }
.tile.dust .paper { animation: dust calc(0.28s * var(--speed)) ease-in forwards; }
@keyframes dust { to { transform: scale(0.2) rotate(25deg); opacity: 0; } }

/* 미리보기 */
.fold-line { position: absolute; z-index: 4; border: 0 dashed #2f2a24; opacity: 0.75; }
.fold-line.row { left: -10px; right: -10px; height: 0; border-top-width: 2px; }
.fold-line.col { top: -10px; bottom: -10px; width: 0; border-left-width: 2px; }
.fold-line.bad { border-color: var(--accent); }
.ghost {
  position: absolute; width: var(--cell); height: var(--cell); padding: 6px; display: grid; place-items: center;
}
.ghost .gp { width: 100%; height: 100%; border-radius: 3px; background: var(--c); opacity: 0.55; border: 2px dashed #fff; }
.ghost.vanish .gp { background: transparent; border-color: #2f2a24; opacity: 0.8; }
.ghost.vanish::after { content: "✕"; position: absolute; font-weight: 900; font-size: calc(var(--cell) * 0.4); color: var(--accent); }
.ghost.crush::after { content: "💥"; position: absolute; font-size: calc(var(--cell) * 0.36); }
.ghost .gl { position: absolute; right: 8px; bottom: 5px; font-size: calc(var(--cell) * 0.22); font-weight: 900; color: #fff; text-shadow: 0 1px 2px #000; }

/* 접히는 날개(2.5D) */
.flap { position: absolute; z-index: 6; transform-style: preserve-3d; }
.flap .face { position: absolute; inset: 0; backface-visibility: hidden; }
.flap .back { background: #d8d1c5; transform: rotateX(180deg); border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); }
.flap.col .back { transform: rotateY(180deg); }

.particle { position: absolute; width: 7px; height: 5px; border-radius: 1px; animation: particle calc(0.6s * var(--speed)) ease-out forwards; }
@keyframes particle { to { transform: translate(var(--dx), var(--dy)) rotate(200deg); opacity: 0; } }

.prompt { margin: 14px 0 4px; min-height: 44px; text-align: center; font-size: 14px; color: var(--ink-soft); }
.prompt b { color: var(--ink); }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }
.act {
  border: 0; border-radius: 10px; padding: 10px 6px; background: var(--paper); box-shadow: 0 3px 0 rgba(60, 45, 25, 0.2);
  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, 32, 22, 0.45); animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; } }
.card {
  position: relative; width: min(360px, 100%); padding: 24px 20px 18px; border-radius: 4px; text-align: center;
  background: var(--paper); box-shadow: 0 20px 40px rgba(40, 32, 22, 0.4); animation: cardIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
  clip-path: polygon(0 0, calc(100% - 22px) 0, 100% 22px, 100% 100%, 0 100%);
}
@keyframes cardIn { from { transform: translateY(30px) rotate(-3deg) 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: 54px; 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: 8px; padding: 11px 18px; font-weight: 800; background: #ece6dc; box-shadow: 0 3px 0 #cfc6b8; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 3px 0 #a83522; }
.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); } }
.plane { height: 64px; position: relative; }
.plane svg { position: absolute; left: 50%; top: 8px; width: 64px; margin-left: -32px; animation: fly 1.6s ease-in-out infinite alternate; }
@keyframes fly { from { transform: translate(-40px, 6px) rotate(-8deg); } to { transform: translate(40px, -6px) rotate(6deg); } }
.intro-demo { display: flex; justify-content: center; gap: 6px; margin: 8px 0; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid #ece6dc; text-align: left; }
.setting small { display: block; color: var(--ink-soft); }

.hand { position: fixed; z-index: 15; font-size: 40px; pointer-events: none; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.35)); margin: -6px 0 0 -14px; }
.hand.drag { animation: handDrag 1.8s ease-in-out infinite; }
@keyframes handDrag { 0%, 15% { transform: translate(0, 0) scale(1); } 20% { transform: translate(0, 0) scale(0.9); } 70% { transform: translate(var(--hx), var(--hy)) scale(0.9); } 85%, 100% { transform: translate(var(--hx), var(--hy)) scale(1); opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 30; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 16px; border-radius: 999px; background: rgba(47, 42, 36, 0.9); 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 (max-width: 380px) { .goal { font-size: 14px; gap: 6px; padding: 8px 10px; } }
@media (prefers-reduced-motion: reduce) { .lv.current, .plane svg, .tile.rainbow .paper { animation: none; } }
.board.no-anim { transition: none; }
