:root {
  --cream: #f6eee3;
  --paper: #fffaf3;
  --ink: #3b3029;
  --muted: #8b7d70;
  --line: #eadccb;
  --coral: #e8846a;
  --coral-dark: #c96a52;
  --gold: #e9b44c;
  --shadow: 0 6px 18px rgba(92, 66, 40, .14);
  --radius: 20px;
  --cell: 48px;
  --head: "Jua", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  --body: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--cream);
  background-image:
    radial-gradient(circle at 25% 25%, rgba(255,255,255,.55) 0 2px, transparent 3px),
    radial-gradient(circle at 75% 75%, rgba(232,214,192,.45) 0 2px, transparent 3px);
  background-size: 18px 18px;
  color: var(--ink);
  font: 15px/1.45 var(--body);
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
img { display: block; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

#app { max-width: 480px; height: 100dvh; margin: 0 auto; position: relative; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 10px 14px calc(12px + var(--safe-b)); }

/* ---------- shared bits ---------- */
.icon-btn { width: 44px; height: 44px; border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); display: grid; place-items: center; flex: none; }
.icon-btn img { width: 30px; height: 30px; }
.icon-btn:active { transform: scale(.94); }
.lang-btn { width: 40px; font: 15px/1 var(--head); color: var(--coral-dark); }
.sheet .lang-btn { width: 52px; }
.coin { width: 24px; height: 24px; background: url(assets/props/coin.webp) center / contain no-repeat; position: relative; flex: none; display: inline-block; }


/* ---------- home ---------- */
.topbar { display: flex; align-items: center; gap: 10px; }
.brand { flex: 1; display: flex; flex-direction: column; line-height: 1.1; }
.brand b { font: 26px/1 var(--head); color: var(--coral-dark); letter-spacing: .5px; }
.brand small { color: var(--muted); font-size: 12px; margin-top: 3px; }
.brand b { word-break: keep-all; }
#map .brand b { font-size: 22px; }
html[lang="en"] #map .brand b { font-size: 21px; line-height: .95; }
.wallet { display: flex; align-items: center; gap: 6px; background: var(--paper); padding: 8px 12px; border-radius: 999px; box-shadow: var(--shadow); font-weight: 700; }

.week { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 12px 0 10px; }
.day { background: var(--paper); border-radius: 12px; padding: 6px 2px 5px; text-align: center; box-shadow: 0 2px 6px rgba(92,66,40,.08); }
.day b { display: block; font: 17px/1.1 var(--head); }
.day small { display: block; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.day.on { background: var(--coral); color: #fff; }
.day.on small { color: #ffe9df; }
.day.lock { opacity: .55; }

.room-wrap { flex: 1; min-height: 0; display: flex; justify-content: center; align-items: center; }
.room { position: relative; height: 100%; aspect-ratio: 1256 / 2240; max-width: 100%; border-radius: 26px; overflow: hidden; box-shadow: 0 10px 30px rgba(92,66,40,.22); background: #e9d7c2; --p: 0; }
.room-bg { position: absolute; inset: 0; background: center / cover no-repeat; filter: saturate(calc(.35 + .65 * var(--p))) brightness(calc(.82 + .18 * var(--p))); transition: filter 1.2s ease; }
.room::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 40%, transparent 50%, rgba(60,40,25,.18)); }
.spots { position: absolute; inset: 0; z-index: 2; }
.spot { position: absolute; transform: translate(-50%, -50%); width: 54px; height: 54px; display: grid; place-items: center; }
.spot .tangle { width: 52px; height: 52px; object-fit: contain; filter: drop-shadow(0 3px 4px rgba(60,40,25,.35)); animation: wobble 2.6s ease-in-out infinite; }
.spot .num { position: absolute; right: -2px; top: -2px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--paper); font: 13px/22px var(--head); text-align: center; box-shadow: var(--shadow); }
.spot.next::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid rgba(255,255,255,.95); animation: ping 1.6s ease-out infinite; }
.spot.done .tangle { display: none; }
.spot.done::after { content: ""; width: 14px; height: 14px; background: #fff; clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%); filter: drop-shadow(0 0 6px #fff7c9); opacity: .85; animation: twinkle 2.4s ease-in-out infinite; }
.spot.restoring .tangle { animation: unravel .9s ease-in forwards; }
.room-friends { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.rf { position: absolute; transform: translateX(-50%); pointer-events: auto; }
.rf img { height: 100%; width: auto; filter: drop-shadow(0 6px 6px rgba(60,40,25,.3)); }
.rf .zz { position: absolute; top: -4px; right: -6px; font: 15px var(--head); color: #fff; text-shadow: 0 1px 3px rgba(60,40,90,.7); animation: float 2.4s ease-in-out infinite; }

.home-bottom { padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.home-line { margin: 0; text-align: center; color: var(--muted); font-size: 13px; min-height: 19px; }
.play-btn { height: 62px; border-radius: 22px; background: linear-gradient(180deg, #ef977d, var(--coral)); color: #fff; box-shadow: 0 6px 0 var(--coral-dark), var(--shadow); display: flex; align-items: center; justify-content: center; gap: 12px; font: 24px var(--head); }
.play-btn b { background: rgba(255,255,255,.25); border-radius: 12px; padding: 2px 10px; font-weight: 400; }
.play-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--coral-dark), var(--shadow); }

/* ---------- puzzle ---------- */
.pz-top { display: flex; align-items: center; gap: 10px; }
.pz-title { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.pz-title small { color: var(--muted); font-size: 12px; }
.pz-title b { font: 21px var(--head); }
.moves { min-width: 74px; text-align: center; background: var(--paper); border-radius: 16px; padding: 4px 10px; box-shadow: var(--shadow); }
.moves b { display: block; font: 28px/1.05 var(--head); color: var(--coral-dark); }
.moves small { font-size: 11px; color: var(--muted); }
.moves.low b { color: #d9534f; animation: pulse 0.9s ease-in-out infinite; }

.goals { display: flex; gap: 8px; justify-content: center; margin: 10px 0 6px; flex-wrap: wrap; }
.goal { display: flex; align-items: center; gap: 6px; background: var(--paper); border-radius: 14px; padding: 5px 10px 5px 6px; box-shadow: 0 2px 6px rgba(92,66,40,.1); font: 16px var(--head); }
.goal .g-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; }
.goal .g-icon img { width: 24px; height: 24px; }
.goal.done { background: #e9f4df; }
.goal.done .g-num::after { content: " ✓"; color: #5d8a46; }
.goal.bump { animation: bump .35s ease; }

.stage { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; }
.board { position: relative; border-radius: 18px; background: #dcc4a6; box-shadow: inset 0 2px 8px rgba(92,66,40,.18), 0 0 0 6px #fbf3e8, var(--shadow); touch-action: manipulation; }
.board::before { content: ""; position: absolute; inset: 0; border-radius: 18px; background:
  repeating-linear-gradient(45deg, rgba(255,255,255,.12) 0 6px, transparent 6px 12px), repeating-linear-gradient(-45deg, rgba(120,90,60,.06) 0 6px, transparent 6px 12px); pointer-events: none; }
.board.targeting { box-shadow: inset 0 2px 8px rgba(92,66,40,.18), 0 0 0 6px #fff1c7, 0 0 24px #ffd66b; }
.tile { position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); padding: calc(var(--cell) * .055); will-change: transform; transition: transform 180ms cubic-bezier(.3, .7, .4, 1.25); }
.chip { width: 100%; height: 100%; border-radius: 30%; background: var(--c); display: grid; place-items: center; box-shadow: inset 0 -3px 0 rgba(0,0,0,.1), inset 0 2px 0 rgba(255,255,255,.7), 0 0 0 1.5px rgba(255,255,255,.75), 0 3px 4px rgba(92,66,40,.25); }
.chip img { width: 92%; height: 92%; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(92,66,40,.25)); animation: idle var(--d, 3.2s) ease-in-out infinite; animation-delay: var(--dl, 0s); }
.tile.hint .chip { animation: hint .7s ease-in-out infinite; }
.tile.single .chip { animation: nope .28s ease; }
.tile.pop { transition: none; animation: pop .19s ease-in forwards; z-index: 3; }
.tile.flip .chip { animation: flip .32s ease; }
.board.targeting .tile:hover .chip { outline: 3px solid #ffd66b; }

.lint { position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); pointer-events: none; z-index: 2; transition: opacity .25s; }
.lint img { position: absolute; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(110,90,140,.4)); }
.lint .f1 { width: 68%; height: 68%; right: -4%; bottom: -4%; }
.lint .f2 { display: none; width: 58%; height: 58%; left: -4%; top: -4%; }
.lint.l2 .f1 { width: 72%; height: 72%; }
.lint.l2::before { content: ""; position: absolute; inset: 6%; border-radius: 30%; background: rgba(240,232,255,.42); }
.lint.l2 .f2 { display: block; }

.knot { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; display: grid; place-items: center; }
.knot .knot-img { width: 96%; height: 96%; object-fit: contain; filter: drop-shadow(0 4px 6px rgba(80,50,30,.35)); animation: breathe 3s ease-in-out infinite; }
.knot .hp { position: absolute; bottom: 4%; display: flex; gap: 3px; }
.knot .hp i { width: 8px; height: 8px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.knot .hp i.off { background: rgba(255,255,255,.3); }
.knot.hit .knot-img { animation: shake .3s ease; }
.knot.gone { animation: knotgone .6s ease-in forwards; }

.fx { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.bit { position: absolute; width: 9px; height: 5px; border-radius: 4px; }
.ring { position: absolute; border-radius: 50%; border: 3px solid #fff; }
.float { position: absolute; font: 26px var(--head); color: #fff; text-shadow: 0 2px 0 var(--coral-dark), 0 3px 8px rgba(0,0,0,.25); white-space: nowrap; transform: translate(-50%, -50%); }
.beam { position: absolute; border-radius: 999px; background: linear-gradient(90deg, rgba(255,240,180,0), rgba(255,240,180,.95), rgba(255,240,180,0)); }

.pz-line { margin: 8px 0 4px; text-align: center; color: var(--muted); font-size: 13px; min-height: 19px; }
.badges { display: flex; justify-content: center; gap: 12px; padding-bottom: 2px; }
.badge { width: 70px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.badge .face { --p: 0; width: 62px; height: 62px; border-radius: 50%; padding: 5px; background: conic-gradient(var(--c2) calc(var(--p) * 360deg), #eadccb 0); box-shadow: var(--shadow); transition: --p .3s; }
.badge .face span { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--c) var(--img) 50% 22% / 168% auto no-repeat; border: 3px solid var(--paper); }
.badge small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.badge.ready .face { animation: ready 1s ease-in-out infinite; box-shadow: 0 0 0 4px #fff6cf, 0 0 18px #ffd66b, var(--shadow); }
.badge.ready small { color: var(--coral-dark); font-weight: 700; }
.badge.asleep .face span { filter: saturate(.6) brightness(.9); }
.badge.asleep .zz { position: absolute; margin: -6px 0 0 48px; font: 14px var(--head); color: #8f7fb6; animation: float 2.4s ease-in-out infinite; }
.badge.armed .face { box-shadow: 0 0 0 4px var(--coral), 0 0 18px #ffb59c; }
.badge:disabled { cursor: default; }

/* actor: a friend clip that pops up over the screen for powers and reactions */
.stage-actor { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 20; pointer-events: none; }
.clip { background-repeat: no-repeat; flex: none; }

/* ---------- sheets ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(59,48,41,.42); display: grid; place-items: end center; animation: fade .2s ease; }
.sheet { width: min(480px, 100%); background: var(--paper); border-radius: 28px 28px 0 0; padding: 18px 20px calc(20px + var(--safe-b)); box-shadow: 0 -8px 30px rgba(60,40,25,.25); animation: rise .28s cubic-bezier(.2,.9,.3,1.1); text-align: center; max-height: 92dvh; overflow: auto; }
.sheet .eyebrow { font-size: 12px; letter-spacing: .5px; color: var(--muted); }
.sheet h2 { font: 26px/1.25 var(--head); margin: 4px 0 6px; }
.sheet p { margin: 6px 0; color: #5d4f44; }
.sheet .actor { display: flex; justify-content: center; margin: 4px auto 2px; min-height: 150px; align-items: flex-end; }
.sheet .chips { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.sheet .tip { background: #fff3e2; border-radius: 14px; padding: 8px 12px; font-size: 13.5px; color: #7a5a3c; }
.sheet .rewards { display: flex; justify-content: center; gap: 10px; margin: 10px 0 4px; }
.sheet .rewards span { background: #fff3e2; border-radius: 14px; padding: 6px 12px; font: 17px var(--head); display: flex; align-items: center; gap: 6px; }
.btn { width: 100%; height: 54px; border-radius: 18px; font: 21px var(--head); margin-top: 10px; }
.btn.primary { background: linear-gradient(180deg, #ef977d, var(--coral)); color: #fff; box-shadow: 0 5px 0 var(--coral-dark); }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--coral-dark); }
.btn.ghost { background: #f3e8da; color: #6d5a49; }
.restore-peek { width: 100%; height: 150px; border-radius: 18px; margin: 8px 0; background: center / cover no-repeat; position: relative; box-shadow: inset 0 0 0 3px #fff; }
.restore-peek::after { content: "✦"; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); color: #fff; font-size: 34px; text-shadow: 0 0 14px #fff6c9; animation: twinkle 1.4s ease-in-out infinite; }
.setting { display: flex; justify-content: space-between; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.switch { width: 52px; height: 30px; border-radius: 15px; background: #ddd0c0; position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch[aria-checked="true"] { background: var(--coral); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }

.toast { position: fixed; left: 50%; top: 14px; transform: translate(-50%, -140%); background: #3b3029; color: #fff; padding: 10px 16px; border-radius: 14px; z-index: 40; font-size: 14px; transition: transform .25s ease; max-width: 90vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); }

/* ---------- motion ---------- */
@keyframes idle { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-2%) rotate(-3deg); } }
@keyframes hint { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1) rotate(4deg); } }
@keyframes nope { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6%); } 75% { transform: translateX(6%); } }
@keyframes pop { 0% { transform: var(--at) scale(1); opacity: 1; } 45% { transform: var(--at) scale(1.22); opacity: 1; } 100% { transform: var(--at) scale(.2); opacity: 0; } }
@keyframes flip { 0% { transform: rotateY(0); } 50% { transform: rotateY(90deg); } 100% { transform: rotateY(0); } }
@keyframes wobble { 0%,100% { transform: rotate(-6deg) scale(1); } 50% { transform: rotate(6deg) scale(1.06); } }
@keyframes ping { 0% { transform: scale(.8); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }
@keyframes twinkle { 0%,100% { opacity: .5; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.1); } }
@keyframes unravel { 0% { transform: rotate(0) scale(1); opacity: 1; } 60% { transform: rotate(200deg) scale(1.3); opacity: .8; } 100% { transform: rotate(360deg) scale(0); opacity: 0; } }
@keyframes float { 0%,100% { transform: translateY(0); opacity: .9; } 50% { transform: translateY(-6px); opacity: .5; } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes ready { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1.05); } }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@keyframes shake { 0%,100% { transform: translateX(0) rotate(0); } 30% { transform: translateX(-4%) rotate(-4deg); } 70% { transform: translateX(4%) rotate(4deg); } }
@keyframes knotgone { to { transform: scale(1.4) rotate(40deg); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40%); } }

body.reduced *, body.reduced *::before, body.reduced *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
@media (prefers-reduced-motion: reduce) { .chip img, .spot .tangle { animation: none; } }
@media (min-width: 600px) { #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }

/* puzzle backdrop: the chapter room, faint behind the board; deeper at night */
#puzzle { isolation: isolate; }
#puzzle::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--pz-bg) center / cover no-repeat; opacity: .22; filter: blur(2px) saturate(.8); }
#puzzle.night { background: #2c2747; color: #f4eefc; }
#puzzle.night::before { opacity: .55; filter: blur(1px); }
#puzzle.night .pz-title small, #puzzle.night .pz-line, #puzzle.night .badge small { color: #d8cdee; }
#puzzle.night .board { background: #3b3560; box-shadow: inset 0 2px 8px rgba(0,0,0,.35), 0 0 0 6px rgba(255,255,255,.12), 0 8px 24px rgba(0,0,0,.35); }
#puzzle.night .goal { background: rgba(255,250,243,.95); color: var(--ink); }
.rf { background: none; padding: 0; }

.side-link { display: flex; align-items: center; gap: 10px; background: var(--paper); border-radius: 16px; padding: 6px 14px 6px 8px; box-shadow: var(--shadow); color: var(--ink); text-decoration: none; }
.side-link img { width: 38px; height: 38px; object-fit: contain; }
.side-link span { flex: 1; font: 17px var(--head); }
.side-link small { font: 12px var(--body); color: var(--muted); margin-left: 4px; }
.side-link b { font: 20px var(--head); color: var(--coral-dark); }

@media(max-width:360px){#map .topbar{gap:5px}#map .brand{min-width:0}html[lang="en"] #map .brand b{font-size:17px;letter-spacing:0;overflow-wrap:anywhere}#map .brand small{font-size:10px}#map .wallet{padding:7px 8px;gap:3px}}
