:root {
  --bg: #fff6ee;
  --paper: #ffffff;
  --ink: #3b3350;
  --muted: #8a819c;
  --line: #efe3f4;
  --pink: #ff8fb1;
  --pink-d: #e8618e;
  --mint: #4fc79c;
  --mint-d: #2fa47b;
  --violet: #9b7ad9;
  --sun: #ffd23f;
  --shadow: 0 6px 20px rgba(89, 60, 120, .10);
  --radius: 18px;
  --head: 'Jua', 'Gowun Dodum', system-ui, sans-serif;
  --body: 'Gowun Dodum', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  overflow-x: hidden;
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
/* 마을 화면은 휴대폰에서도 화면에 꽉 맞게 (페이지 전체가 밀리지 않도록) */
body.world-mode { height: 100vh; height: 100dvh; overflow: hidden; }
body.world-mode main { min-height: 0; }
.install-btn.hidden { display: none; }
button, input, select { font: inherit; color: inherit; }
/* 아이폰 Safari는 입력칸 기본 폭이 커서 화면을 밀어내므로, 칸이 부모보다 커지지 않게 함 */
input, select, textarea { max-width: 100%; min-width: 0; }
img, svg, canvas { max-width: 100%; }
h2, h3, h4 { font-family: var(--head); font-weight: 400; margin: 0; }

/* ---------- 상단 ---------- */
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--paper); border-bottom: 2px solid var(--line);
  position: sticky; top: 0; z-index: 50; flex-wrap: wrap;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right));
}
.brand { font-family: var(--head); font-size: 24px; display: flex; align-items: center; gap: 10px; }
.install-btn { justify-self: end; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%;
  background: radial-gradient(circle at 35% 40%, #3b3350 0 3px, transparent 3.5px), radial-gradient(circle at 65% 40%, #3b3350 0 3px, transparent 3.5px), #ffd8bb;
  box-shadow: inset 0 -4px 0 #f6c39f, 0 0 0 3px var(--pink);
}
.tabs { display: flex; gap: 6px; background: #f8f0fb; padding: 5px; border-radius: 999px; }
.tabs button {
  border: 0; background: transparent; padding: 8px 18px; border-radius: 999px; cursor: pointer;
  font-family: var(--head); font-size: 17px; color: var(--muted);
}
.tabs button.active { background: var(--paper); color: var(--ink); box-shadow: 0 2px 8px rgba(89, 60, 120, .12); }
.tabs .count:not(:empty) {
  display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 2px; border-radius: 999px;
  background: var(--pink); color: #fff; font-size: 13px; line-height: 20px;
}

main { flex: 1; display: flex; min-height: 0; }
.view { display: none; flex: 1; min-width: 0; }
.view.active { display: flex; flex-direction: column; }

/* ---------- 버튼 ---------- */
.btn {
  border: 2px solid var(--line); background: var(--paper); border-radius: 14px; padding: 10px 16px;
  font-family: var(--head); font-size: 16px; cursor: pointer; transition: transform .08s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #e2cdea; background: #fffafd; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--pink); border-color: var(--pink); color: #fff; }
.btn.primary:hover { background: var(--pink-d); border-color: var(--pink-d); }
.btn.accent { background: var(--mint); border-color: var(--mint); color: #fff; }
.btn.accent:hover { background: var(--mint-d); border-color: var(--mint-d); }
.btn.small { padding: 7px 12px; font-size: 15px; border-radius: 12px; }
.btn.tiny { padding: 5px 9px; font-size: 14px; border-radius: 10px; }
.btn.ghost { background: transparent; }
.btn.danger { color: #d9475f; }
.btn.on { background: #ece4ff; border-color: var(--violet); color: #5b3fa8; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 0; white-space: normal; line-height: 1.25; }
.btn-row.center { justify-content: center; }
.btn-row.center .btn { flex: 0 0 auto; }

/* ---------- 꾸미기 ---------- */
.editor {
  display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px;
  padding: 20px; flex: 1; min-height: 0; max-width: 1280px; width: 100%; margin: 0 auto;
}
.stage-card {
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  display: flex; flex-direction: column; gap: 12px; align-self: start; position: sticky; top: 80px;
}
.stage {
  border-radius: 14px; aspect-ratio: 1 / 1.15;
  background:
    radial-gradient(ellipse 45% 7% at 50% 92%, rgba(120, 80, 140, .16), transparent 70%),
    linear-gradient(#fdeef6, #eef6ff 70%, #e8f7e4 70%);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.stage .char-svg { height: 94%; width: auto; }
.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.fields input, .fields select {
  width: 100%; min-width: 0; height: 44px;
  border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; background: #fffdfb; font-size: 16px; color: var(--ink);
}
.fields input:focus, .fields select:focus, .chat-form input:focus { outline: none; border-color: var(--pink); }
.edit-state { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }

.closet { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cat-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-tab {
  border: 2px solid var(--line); background: var(--paper); border-radius: 999px; padding: 7px 15px; cursor: pointer;
  font-family: var(--head); font-size: 16px;
}
.cat-tab.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.cat-panel { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.panel-head h3 { font-size: 22px; }
.hint { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.group-title { font-size: 17px; margin: 18px 0 8px; color: var(--violet); }

.swatch-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.swatch-label { font-size: 13px; color: var(--muted); min-width: 64px; }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, .12); background: var(--c);
  cursor: pointer; padding: 0; position: relative;
}
.swatch.on { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.swatch.custom {
  background: conic-gradient(#ff6b6b, #ffd23f, #7fcf6a, #6fb7ff, #b48cff, #ff6b6b); overflow: hidden; display: inline-block;
}
.swatch.custom input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }

.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.opt {
  border: 2px solid var(--line); background: #fffaf6; border-radius: 14px; padding: 6px 6px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; transition: border-color .15s, transform .1s;
}
.opt:hover { border-color: #e2cdea; transform: translateY(-1px); }
.opt.on { border-color: var(--pink); background: #fff0f5; box-shadow: 0 0 0 2px var(--pink) inset; }
.opt .opt-svg { width: 100%; aspect-ratio: 1 / 0.8; }
.opt span { font-size: 13px; }
.opt.is-none span { color: var(--muted); }
.opt .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 1px solid rgba(0, 0, 0, .15); }

/* ---------- 내 캐릭터 ---------- */
#view-gallery { padding: 20px; max-width: 1280px; width: 100%; margin: 0 auto; gap: 12px; }
.gallery-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.gallery-head h2 { font-size: 28px; }
.gallery-head p { margin: 4px 0 0; color: var(--muted); }
.bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bulk label { display: flex; align-items: center; gap: 6px; font-family: var(--head); }
.bulk input { width: 64px; border: 2px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; }
.gallery-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.char-card {
  background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.char-card-art {
  background: linear-gradient(#fdeef6, #eef6ff); border-radius: 12px; height: 200px;
  display: flex; align-items: center; justify-content: center;
}
.char-card-art .char-svg { height: 92%; }
.char-card-info { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.char-card-info b { font-family: var(--head); font-weight: 400; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 12px; background: #f3ecff; color: #6b4fb8; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.village-toggle { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; cursor: pointer; }
.village-toggle input { accent-color: var(--mint); width: 16px; height: 16px; }
.char-card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.empty { grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--muted); background: var(--paper); border-radius: var(--radius); }

/* ---------- 마을 ---------- */
#view-world { min-height: 0; }
.world-hud {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--paper);
  border-bottom: 2px solid var(--line); flex-wrap: wrap;
}
.hud-selected { display: flex; align-items: center; gap: 8px; min-width: 200px; font-size: 15px; }
.hud-selected b { font-family: var(--head); font-weight: 400; font-size: 18px; }
.hud-face { width: 40px; height: 34px; display: inline-flex; background: #fdeef6; border-radius: 10px; }
.hud-face svg { width: 100%; height: 100%; }
.hud-hint { color: var(--muted); }
.hud-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-form { display: flex; gap: 6px; margin-left: auto; flex: 1 1 280px; max-width: 460px; min-width: 0; }
.chat-form input { flex: 1 1 0; width: 0; min-width: 0; border: 2px solid var(--line); border-radius: 12px; padding: 7px 12px; }

.world-stage { flex: 1; position: relative; display: flex; min-height: 180px; }
.world-viewport { flex: 1; position: relative; overflow: auto; display: flex; background: #a9dc8c; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.world-sizer { position: relative; margin: auto; flex: 0 0 auto; }
.world {
  position: absolute; left: 0; top: 0; width: 1400px; height: 860px; transform-origin: 0 0;
  overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: pan-x pan-y; cursor: pointer;
}
#worldBg, #entityLayer, #bubbleLayer { position: absolute; inset: 0; }
#worldBg svg { display: block; }
#entityLayer { z-index: 1; pointer-events: none; }
#bubbleLayer { z-index: 2; pointer-events: none; }

.zone-pad {
  position: absolute; border: 3px dashed var(--zc); border-radius: 18px;
  background: color-mix(in srgb, var(--zc) 22%, transparent);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; transition: background .2s;
}
.zone-pad span { font-family: var(--head); font-size: 13px; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .35); }
.zone-pad.active { border-style: solid; background: color-mix(in srgb, var(--zc) 45%, transparent); animation: padGlow 1s ease-in-out infinite alternate; }
@keyframes padGlow { to { box-shadow: 0 0 0 8px color-mix(in srgb, var(--zc) 30%, transparent); } }

.ent { position: absolute; left: 0; top: 0; width: 70px; height: 113px; pointer-events: auto; cursor: pointer; will-change: transform; }
.ent .char-svg { width: 70px; height: 113px; display: block; overflow: visible; }
.ent-shadow { position: absolute; left: 13px; top: 102px; width: 44px; height: 12px; border-radius: 50%; background: rgba(40, 70, 30, .22); }
.ent-bob { position: absolute; inset: 0; transform-origin: 50% 96%; }
.ent-flip { width: 100%; height: 100%; }
.ent-flip { transition: transform .18s ease-out; }
/* 걷기: 다리와 팔이 번갈아 움직이고, 몸은 거의 흔들리지 않음. --walk = 한 걸음 주기(속도에 맞춰 바뀜) */
.ent .leg, .ent .arm { transform-box: view-box; }
.ent .leg-l { transform-origin: 88px 224px; }
.ent .leg-r { transform-origin: 112px 224px; }
.ent .arm-l { transform-origin: 76px 167px; }
.ent .arm-r { transform-origin: 124px 167px; }
.walking .leg-l { animation: legSwing var(--walk, .8s) linear infinite; }
.walking .leg-r { animation: legSwing var(--walk, .8s) linear infinite; animation-delay: calc(var(--walk, .8s) / -2); }
.walking .arm-l { animation: armSwing var(--walk, .8s) ease-in-out infinite; animation-delay: calc(var(--walk, .8s) / -2); }
.walking .arm-r { animation: armSwing var(--walk, .8s) ease-in-out infinite; }
.walking .ent-bob { animation: step calc(var(--walk, .8s) / 2) ease-in-out infinite; }
/* 앞으로 내딛는 다리는 살짝 들리고, 뒤로 미는 다리는 바닥에 붙어 있음 */
@keyframes legSwing {
  0%   { transform: rotate(9deg); animation-timing-function: ease-in-out; }
  25%  { transform: rotate(0deg) translateY(-2.5px); animation-timing-function: ease-in-out; }
  50%  { transform: rotate(-9deg); animation-timing-function: linear; }
  100% { transform: rotate(9deg); }
}
@keyframes armSwing { 0%, 100% { transform: rotate(7deg); } 50% { transform: rotate(-7deg); } }
@keyframes step { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-0.8px); } }
.ent-name {
  position: absolute; top: 113px; left: 50%; transform: translateX(-50%);
  font-family: var(--head); font-size: 12px; background: rgba(255, 255, 255, .88); padding: 0 8px; border-radius: 10px; white-space: nowrap;
}
.ent-ring, .ent-arrow { display: none; }
.selected .ent-ring {
  display: block; position: absolute; left: 5px; top: 98px; width: 60px; height: 20px; border-radius: 50%;
  border: 3px solid #ffd23f; background: rgba(255, 210, 63, .25); animation: ring 1s ease-in-out infinite alternate;
}
.selected .ent-name { background: #ffd23f; }
.selected .ent-arrow {
  display: block; position: absolute; left: 50%; top: -18px; width: 0; height: 0; transform: translateX(-50%);
  border: 9px solid transparent; border-top: 12px solid #ff8fb1; animation: arrow .6s ease-in-out infinite alternate;
}
@keyframes ring { to { transform: scale(1.08); } }
@keyframes arrow { to { transform: translate(-50%, -5px); } }

.bubble {
  position: absolute; left: 0; top: 0; width: max-content; max-width: 190px; padding: 6px 11px;
  background: #fff; border: 2px solid var(--ink); border-radius: 14px; font-size: 14px; line-height: 1.35;
  opacity: 0; transition: opacity .18s; text-align: center; word-break: keep-all;
}
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -9px; width: 12px; height: 12px; background: #fff;
  border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: translateX(-50%) rotate(45deg);
}
.bubble.show { opacity: 1; }

.click-marker {
  position: absolute; width: 30px; height: 14px; margin: -7px 0 0 -15px; border-radius: 50%;
  border: 3px solid #fff; animation: mark .7s ease-out forwards;
}
@keyframes mark { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }

.zone-bar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 12px 14px 12px 20px; background: var(--paper);
  border-radius: 18px; border: 3px solid var(--zc); box-shadow: 0 10px 30px rgba(60, 40, 90, .25);
  animation: rise .25s ease-out; width: max-content; max-width: calc(100% - 24px);
}
.zone-bar div { display: flex; flex-direction: column; min-width: 0; }
.zone-bar b { font-family: var(--head); font-weight: 400; font-size: 20px; }
.zone-bar span { font-size: 13px; color: var(--muted); }
.zone-bar.hidden { display: none; }
@keyframes rise { from { transform: translate(-50%, 20px); opacity: 0; } }

.world-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 30; background: rgba(255, 246, 238, .55); }
.world-empty.hidden { display: none; }
.world-empty-card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; text-align: center; max-width: 360px; }
.world-empty-card h3 { font-size: 24px; margin-bottom: 6px; }
.world-empty-card p { color: var(--muted); margin: 0 0 16px; }

/* ---------- 게임 창 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(43, 34, 70, .55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--paper); border-radius: 22px; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  padding: 18px 20px 22px; box-shadow: 0 20px 60px rgba(30, 20, 60, .35); animation: pop .2s ease-out;
}
@keyframes pop { from { transform: scale(.95); opacity: 0; } }
.game-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.game-title h2 { font-size: 24px; }
.game-title p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.icon-btn { border: 0; background: #f6f0fa; width: 38px; height: 38px; border-radius: 50%; cursor: pointer; font-size: 16px; flex: 0 0 auto; }
.icon-btn:hover { background: #ece2f4; }
.game-stats { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; font-size: 15px; min-height: 22px; }
.game-stats b { font-family: var(--head); font-weight: 400; font-size: 19px; color: var(--pink-d); }
.game-stats .lives { color: #ff5d8a; letter-spacing: 2px; }

.mem-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: min(100%, calc((100dvh - 210px) * 0.97)); margin: 0 auto; }
.mem-card { border: 0; background: none; padding: 0; aspect-ratio: 1 / 1.05; cursor: pointer; }
.mem-inner { display: block; position: relative; width: 100%; height: 100%; animation: flipA .3s ease-in-out; }
.mem-card.open .mem-inner { animation: flipB .3s ease-in-out; }
@keyframes flipA { 50% { transform: scaleX(0); } }
@keyframes flipB { 50% { transform: scaleX(0); } }
.mem-face {
  position: absolute; inset: 0; border-radius: 14px; transition: opacity 0s .15s;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.mem-card.open .mem-back { opacity: 0; }
.mem-front { opacity: 0; }
.mem-card.open .mem-front { opacity: 1; }
.mem-back {
  background: repeating-linear-gradient(45deg, #ff9db0 0 10px, #ffb3c4 10px 20px); border: 3px solid #fff; box-shadow: 0 3px 0 #e8618e;
}
.mem-back span { font-family: var(--head); font-size: 34px; color: #fff; }
.mem-front { background: #fff7fb; border: 3px solid #ffd0de; padding: 4px; }
.mem-front svg { width: 100%; flex: 1; min-height: 0; }
.mem-front em { font-style: normal; font-family: var(--head); font-size: 13px; }
.mem-card.matched .mem-front { border-color: var(--mint); background: #effbf5; }

.whack-grid { --hh: clamp(64px, calc((100dvh - 240px) / 3), 150px); display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: calc(var(--hh) * 4.6); margin: 0 auto; }
.hole {
  position: relative; height: var(--hh); overflow: hidden; border-radius: 18px; cursor: pointer;
  background: linear-gradient(#c9ecff, #e8f7e4);
}
.hole::before { content: ''; position: absolute; left: 14%; right: 14%; bottom: calc(var(--hh) * .13); height: calc(var(--hh) * .23); border-radius: 50%; background: #5a3b26; }
.mole { position: absolute; left: 50%; bottom: calc(var(--hh) * .2); width: min(118px, calc(var(--hh) * .78), 90%); transform: translate(-50%, 130%); transition: transform .12s ease-out; }
.mole svg { width: 100%; display: block; }
.hole.up .mole { transform: translate(-50%, 0); }
.hole.gold.up .mole { filter: drop-shadow(0 0 10px #ffd23f); }
.hole-front { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--hh) * .25); background: #8fd17f; border-top: 4px solid #6bbf58; border-radius: 50% 50% 0 0 / 40% 40% 0 0; }
.floater { position: absolute; left: 50%; top: 20%; transform: translateX(-50%); font-family: var(--head); font-size: 26px; color: var(--pink-d); animation: floatUp .7s ease-out forwards; pointer-events: none; }
@keyframes floatUp { to { transform: translate(-50%, -30px); opacity: 0; } }

.catch-canvas { width: 100%; max-width: calc((100dvh - 190px) * 1.52); margin: 0 auto; border-radius: 16px; display: block; touch-action: none; cursor: none; }

.rps { display: grid; grid-template-columns: 1fr 1.1fr 1fr; gap: 10px; align-items: end; }
.rps-side { display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; padding-top: 50px; }
.rps-side .char-svg { width: auto; max-width: 100%; height: clamp(90px, calc(100dvh - 340px), 240px); }
.rps-side b { font-family: var(--head); font-weight: 400; font-size: 18px; }
.rps-bubble {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%) scale(.6); opacity: 0;
  background: #fff; border: 3px solid var(--ink); border-radius: 50%; width: 62px; height: 62px;
  display: flex; align-items: center; justify-content: center; font-size: 32px; transition: transform .2s, opacity .2s;
}
.rps-bubble.show { opacity: 1; transform: translateX(-50%) scale(1); }
.rps-mid { text-align: center; align-self: center; }
.rps-score { font-family: var(--head); font-size: 44px; display: flex; justify-content: center; gap: 12px; }
.rps-score i { font-style: normal; color: var(--muted); }
.rps-msg { font-family: var(--head); font-size: 22px; min-height: 64px; }
.rps-msg small { display: block; font-family: var(--body); font-size: 14px; color: var(--muted); margin-top: 6px; }
.rps-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.rps-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 96px; font-size: 16px; }
.rps-btn span { font-size: 34px; line-height: 1.1; }

.game-result { text-align: center; padding: 10px 0; }
.result-art { height: 200px; display: flex; justify-content: center; }
.result-art .char-svg { height: 100%; animation: hop .6s ease-in-out infinite alternate; }
@keyframes hop { to { transform: translateY(-8px); } }
.game-result h3 { font-size: 30px; margin-top: 8px; }
.game-result p { color: var(--muted); margin: 6px 0; }
.game-result .best { color: var(--violet); font-family: var(--head); font-size: 17px; }
.game-result .btn-row { margin-top: 16px; }

/* ---------- 여럿이 하기 ---------- */
.mini-face { display: inline-flex; width: 26px; height: 22px; vertical-align: middle; margin-right: 4px; border-radius: 6px; background: #fdeef6; }
.mini-face svg { width: 100%; height: 100%; }
.game-stats .turn-now { background: #fff0f5; border: 2px solid var(--pink); border-radius: 999px; padding: 1px 10px 1px 4px; }
.game-stats > span { display: inline-flex; align-items: center; gap: 2px; border: 2px solid transparent; padding: 1px 10px 1px 4px; }
.turn-card { text-align: center; padding: 6px 0 4px; }
.turn-art { height: clamp(90px, calc(100dvh - 360px), 220px); display: flex; justify-content: center; }
.turn-art .char-svg { height: 100%; width: auto; animation: hop .6s ease-in-out infinite alternate; }
.turn-card h3 { font-size: 26px; margin-top: 6px; }
.turn-card p { color: var(--muted); margin: 4px 0 14px; }
.ranking { list-style: none; padding: 0; margin: 12px auto 4px; max-width: 340px; text-align: left; }
.ranking li { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 12px; }
.ranking li.first { background: #fff6d6; }
.ranking .rank { font-family: var(--head); width: 34px; color: var(--violet); }
.ranking b { flex: 1; font-family: var(--head); font-weight: 400; font-size: 17px; }
.ranking em { font-style: normal; font-family: var(--head); color: var(--pink-d); }
.result-art { gap: 6px; }
.rps-side.turn { background: #fff0f5; border-radius: 16px; box-shadow: 0 0 0 3px var(--pink) inset; }
.party-line { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 2px; }
.party-face { display: inline-flex; width: 24px; height: 20px; margin-right: 2px; }
.party-face svg { width: 100%; height: 100%; }
.in-party .ent-ring { display: block; position: absolute; left: 7px; top: 100px; width: 56px; height: 18px; border-radius: 50%; border: 3px dashed var(--pink); }
@media (max-height: 520px) {
  .turn-art { height: clamp(60px, calc(100dvh - 250px), 160px); }
  .turn-card h3 { font-size: 20px; }
  .turn-card p { margin: 2px 0 8px; }
}

/* ---------- v2: 잠긴 아이템 ---------- */
.opt { position: relative; }
.opt.locked .opt-svg { filter: grayscale(.85) brightness(1.08); opacity: .55; }
.opt.locked { background: #f7f3fa; border-style: dashed; }
.opt-badge {
  position: absolute; top: 5px; right: 5px; display: inline-flex; align-items: center; gap: 2px;
  font-style: normal; font-size: 11px; line-height: 1; padding: 3px 6px; border-radius: 999px;
  background: #5b3fa8; color: #ffd23f; letter-spacing: -1px;
}
.opt-badge.open { background: #e6f8ef; color: #2fa47b; letter-spacing: 0; }
.lock-ico { display: inline-block; width: 9px; height: 8px; margin: 2px 3px 0 0; background: #fff; border-radius: 2px; position: relative; }
.lock-ico::before { content: ''; position: absolute; left: 1.5px; top: -5px; width: 4px; height: 5px; border: 1.5px solid #fff; border-bottom: 0; border-radius: 4px 4px 0 0; }
.lock-hint { margin: -4px 0 12px; font-size: 13px; color: var(--muted); }
.lock-hint b { color: #5b3fa8; margin-right: 6px; font-family: var(--head); font-weight: 400; }

/* ---------- v2: 퀴즈 ---------- */
.quiz-modal { z-index: 150; }
.quiz-card { width: min(560px, 100%); }
.quiz-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.quiz-title h2 { font-size: 24px; }
.quiz-title p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.quiz-body { display: flex; gap: 16px; align-items: center; margin-top: 10px; }
.quiz-preview { flex: 0 0 120px; height: 120px; background: linear-gradient(#fdeef6, #eef6ff); border-radius: 16px; display: flex; align-items: center; justify-content: center; }
.quiz-preview svg { width: 92%; height: 92%; }
.quiz-preview.big { width: 160px; height: 160px; flex: none; margin: 0 auto; }
.quiz-main { flex: 1; min-width: 0; text-align: center; }
.quiz-stars { font-size: 26px; letter-spacing: 4px; color: #e5dcef; text-align: center; }
.quiz-stars .on { color: #ffc93c; text-shadow: 0 2px 0 #e0a800; }
.quiz-q { font-family: var(--head); font-size: 46px; display: flex; justify-content: center; align-items: center; gap: 10px; margin: 6px 0 2px; }
.quiz-q .op { color: var(--pink-d); }
.quiz-q .ans { min-width: 1.6em; padding: 0 8px; border-bottom: 4px solid var(--violet); color: var(--violet); }
.quiz-q .ans.empty { color: #d6cbe6; }
.quiz-q.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
.quiz-dots { min-height: 4px; font-size: 18px; color: #ff8fb1; letter-spacing: 1px; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.quiz-dots .op { color: var(--muted); }
.quiz-dots .minus { color: #b9b0c8; text-decoration: line-through; }
.hole-hint { font-size: 14px; color: var(--violet); font-family: var(--head); }
.quiz-q { flex-wrap: wrap; row-gap: 0; }
.quiz-q.long { font-size: 36px; gap: 6px; }
@media (max-width: 520px), (max-height: 700px) { .quiz-q.long { font-size: 28px; } }
.quiz-msg { min-height: 24px; margin: 6px 0; font-family: var(--head); font-size: 17px; color: var(--muted); }
.quiz-msg.good { color: var(--mint-d); }
.quiz-msg.bad { color: #d9475f; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 300px; margin: 0 auto; }
.key {
  border: 2px solid var(--line); background: #fffaf6; border-radius: 14px; height: 54px; cursor: pointer;
  font-family: var(--head); font-size: 26px; box-shadow: 0 3px 0 #eadff5;
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 #eadff5; }
.key-sub { color: var(--muted); }
.key-ok { background: var(--mint); border-color: var(--mint); color: #fff; font-size: 20px; box-shadow: 0 3px 0 var(--mint-d); }
.quiz-done { text-align: center; width: 100%; padding: 10px 0; }
.quiz-done h3 { font-size: 26px; margin: 12px 0 14px; }

.quiz-body.spell { flex-direction: column; align-items: stretch; text-align: center; }
.spell-ask { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.spell-sentence { font-size: 24px; line-height: 1.6; margin: 8px 0 4px; word-break: keep-all; }
.spell-sentence .blank { display: inline-block; min-width: 3.2em; border-bottom: 3px solid var(--violet); text-decoration: none; }
.spell-sentence .filled { color: var(--mint-d); border-bottom: 3px solid var(--mint); padding: 0 4px; }
.spell-choices { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 8px 0 2px; }
.spell-choice { min-width: 130px; font-size: 22px; padding: 12px 18px; }
.spell-choice.right { background: #e6f8ef; border-color: var(--mint); color: var(--mint-d); }
.spell-choice.wrong { background: #ffecef; border-color: #f2a3b0; color: #d9475f; text-decoration: line-through; }
.spell-choice:disabled { opacity: 1; cursor: default; }
.spell-tip { font-size: 14px; color: var(--ink); border-radius: 12px; }
.spell-tip:not(:empty) { padding: 8px 12px; background: #fff8e1; }
.spell-next { align-self: center; margin-top: 10px; min-width: 160px; }
.spell-next.hidden { display: none; }
@media (max-width: 520px) {
  .quiz-body:not(.spell) { flex-direction: column; gap: 6px; }
  .quiz-preview { flex: none; width: 96px; height: 96px; }
  .quiz-q { font-size: 38px; }
  .spell-sentence { font-size: 20px; }
  .spell-choice { min-width: 0; flex: 1; font-size: 19px; }
}
@media (max-height: 700px) {
  .quiz-preview:not(.big) { display: none; }
  .quiz-title h2 { font-size: 21px; }
  .quiz-q { font-size: 36px; margin: 2px 0; }
  .key { height: 46px; font-size: 22px; }
  .keypad { gap: 6px; }
  .quiz-msg { margin: 4px 0; }
}
@media (max-height: 560px) {
  .quiz-preview { display: none; }
  .quiz-preview.big { display: flex; width: 100px; height: 100px; }
  .quiz-q { font-size: 32px; margin: 2px 0; }
  .key { height: 40px; font-size: 20px; }
  .keypad { grid-template-columns: repeat(6, 1fr); max-width: 420px; gap: 6px; }
  .spell-sentence { font-size: 18px; margin: 2px 0; }
  .spell-choice { padding: 6px 14px; font-size: 17px; }
  .spell-choices { margin: 4px 0 0; }
  .spell-ask { display: none; }
  .quiz-stars { font-size: 20px; }
  .quiz-title p { font-size: 12px; margin-top: 2px; }
  .quiz-body { margin-top: 4px; }
  .quiz-msg { margin: 2px 0; font-size: 15px; min-height: 20px; }
  .spell-tip:not(:empty) { font-size: 12px; padding: 5px 10px; }
  .spell-next { margin-top: 6px; padding: 7px 14px; }
}

/* ---------- 알림 ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 200; font-size: 15px;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 860px) {
  .editor { grid-template-columns: minmax(0, 1fr); padding: 12px; }
  .stage-card { position: static; }
  .stage { aspect-ratio: auto; height: 300px; }
  .topbar { padding: 8px 12px; }
  .tabs button { padding: 7px 12px; font-size: 15px; }
  #view-gallery { padding: 12px; }
  .chat-form { margin-left: 0; max-width: none; }
  .rps-score { font-size: 32px; }
  .rps-msg { font-size: 18px; }
}
@media (max-width: 600px) {
  .topbar { display: flex; gap: 8px; flex-wrap: nowrap; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); padding-bottom: 8px; }
  .brand-text { display: none; }
  .tabs { flex: 1; justify-content: center; min-width: 0; }
  .tabs button { padding: 7px 10px; font-size: 15px; flex: 0 1 auto; white-space: nowrap; }
  .install-btn { padding: 6px 9px; font-size: 13px; }
  .gal-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .char-card { padding: 8px; }
  .char-card-art { height: 170px; }
  .char-card-actions .btn { white-space: normal; padding: 5px 4px; }
  .gallery-head .bulk { width: 100%; }
  .gallery-head .bulk .btn { flex: 1; }
  .world-hud { padding: 8px 10px; gap: 6px; }
  .hud-selected { min-width: 0; flex: 1 1 100%; }
  .hud-actions .btn { padding: 6px 9px; font-size: 14px; }
  .modal { padding: 8px; }
  .modal-card { padding: 14px 12px 16px; max-height: calc(100dvh - 16px); }
  .game-title h2 { font-size: 20px; }
  .mem-grid { gap: 6px; }
  .rps-btn { min-width: 0; flex: 1; }
  .zone-bar { bottom: max(12px, env(safe-area-inset-bottom)); gap: 10px; padding: 10px 10px 10px 14px; }
}
@media (max-width: 360px) {
  .brand { display: none; }
  .tabs button { padding: 6px 8px; font-size: 14px; }
}
/* 가로로 눕힌 휴대폰처럼 세로가 짧은 화면 */
@media (max-height: 520px) {
  .topbar { padding-top: max(5px, env(safe-area-inset-top)); padding-bottom: 5px; }
  .brand { font-size: 18px; }
  .brand-mark { width: 22px; height: 22px; }
  .tabs { padding: 3px; }
  .tabs button { padding: 5px 12px; font-size: 14px; }
  .world-hud { flex-wrap: nowrap; overflow-x: auto; padding: 5px 10px; gap: 6px; scrollbar-width: none; }
  .world-hud::-webkit-scrollbar { display: none; }
  .hud-selected { flex: 0 0 auto; min-width: 0; }
  .hud-hint { display: none; }
  .hud-face { width: 32px; height: 28px; }
  .hud-actions { flex-wrap: nowrap; }
  .hud-actions .btn, .chat-form .btn { padding: 5px 9px; font-size: 13px; }
  .chat-form { flex: 1 0 200px; margin-left: 0; }
  .chat-form input { padding: 5px 10px; }
  .modal { padding: 6px; }
  .modal-card { padding: 10px 14px 12px; max-height: calc(100dvh - 12px); }
  .game-title h2 { font-size: 18px; }
  .game-title p { font-size: 12px; margin-top: 2px; }
  .game-stats { margin: 6px 0; }
  .icon-btn { width: 32px; height: 32px; }
  .mem-grid { grid-template-columns: repeat(8, 1fr); gap: 6px; width: min(100%, calc((100dvh - 150px) * 3.7)); }
  .whack-grid { --hh: clamp(56px, calc((100dvh - 170px) / 3), 150px); }
  .catch-canvas { max-width: calc((100dvh - 140px) * 1.52); }
  .rps-side { padding-top: 40px; }
  .rps-side .char-svg { height: clamp(64px, calc(100dvh - 268px), 240px); }
  .rps-msg { min-height: 40px; font-size: 17px; }
  .rps-score { font-size: 28px; }
  .rps-buttons { margin-top: 8px; }
  .rps-btn span { font-size: 24px; }
  .game-result .result-art { height: clamp(80px, calc(100dvh - 260px), 200px); }
  .game-result h3 { font-size: 22px; }
  .zone-bar { padding: 6px 8px 6px 12px; }
  .zone-bar b { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
}
