:root {
  --coral: #e8765a; --green: #4f9d69; --ink: #3a2f28; --cream: #fbf6ee; --line: #eadfd2;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2b2f3a; color: var(--ink);
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; overscroll-behavior: none; }
#game { position: fixed; inset: 0; touch-action: none; }
#game canvas { display: block; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 50% 30%, #3d4456, #23262f); z-index: 20; }
.join-card { background: var(--cream); border-radius: 20px; padding: 22px 20px; width: min(340px, 100%); text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.logo { font-size: 30px; font-weight: 800; letter-spacing: -1px; color: var(--ink); }
.logo span { color: var(--coral); }
.sub { margin: 4px 0 16px; color: #8a7b6e; font-size: 14px; }
.join-card input { width: 100%; font-size: 17px; padding: 12px; border: 2px solid var(--line); border-radius: 12px; outline: none; text-align: center; }
.join-card input:focus { border-color: var(--coral); }
.join-card button { width: 100%; margin-top: 10px; font-size: 17px; font-weight: 700; padding: 12px; border: 0; border-radius: 12px;
  background: var(--coral); color: #fff; }
.join-card button:disabled { opacity: .5; }
.msg { min-height: 18px; margin: 10px 0 0; font-size: 13px; color: #c0504d; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.topbar { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right)); display: flex; justify-content: space-between; gap: 8px; }
.topbar > div { background: rgba(30, 32, 40, .72); color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.me { display: flex; gap: 10px; align-items: center; }
.me .coin b, .online b { color: #ffd36b; }

#chatlog { position: absolute; left: max(10px, env(safe-area-inset-left)); top: 52px; width: min(46vw, 360px);
  display: flex; flex-direction: column; gap: 3px; }
#chatlog div { background: rgba(30, 32, 40, .6); color: #fff; font-size: 13px; padding: 3px 9px; border-radius: 10px;
  width: fit-content; max-width: 100%; word-break: break-all; animation: fade 12s forwards; }
#chatlog b { color: #ffd36b; font-weight: 600; margin-right: 4px; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

#chatbar { position: absolute; left: 50%; transform: translateX(-50%); top: 52px;
  width: min(80vw, 480px); display: flex; gap: 6px; pointer-events: auto; }
#chatbar input { flex: 1; min-width: 0; font-size: 16px; padding: 8px 12px; border-radius: 999px; border: 0; outline: none;
  background: rgba(255,255,255,.92); }
#chatbar button { font-size: 14px; font-weight: 700; padding: 0 14px; border: 0; border-radius: 999px; background: var(--coral); color: #fff; }

#conn { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); background: #c0504d; color: #fff;
  padding: 6px 14px; border-radius: 999px; font-size: 13px; }

#rotate { display: none; position: fixed; inset: 0; z-index: 30; background: #23262f; color: #fff; align-items: center;
  justify-content: center; text-align: center; font-size: 18px; line-height: 1.8; }
@media (orientation: portrait) and (max-width: 700px) {
  body.playing #rotate { display: flex; }
}

.topbar .right { display: flex; gap: 6px; background: none; padding: 0; }
.topbar .right .online { background: rgba(30, 32, 40, .72); color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.hudbtn { pointer-events: auto; border: 0; border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 700;
  background: var(--coral); color: #fff; }

/* ---------- 캐릭터 꾸미기 ---------- */
.cust-card { background: var(--cream); border-radius: 20px; width: min(760px, 100%); max-height: calc(100dvh - 24px);
  display: flex; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.cust-preview { flex: 0 0 38%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 12px; background: radial-gradient(circle at 50% 70%, #fff4e4, #f3e3cc); }
.cust-title { font-weight: 800; font-size: 15px; color: #8a7b6e; }
#custCanvas { height: min(300px, calc(100dvh - 150px)); width: auto; aspect-ratio: 140 / 210; }
.cust-turn { display: flex; gap: 6px; }
.cust-turn button { border: 0; border-radius: 999px; padding: 7px 12px; font-size: 15px; font-weight: 700; background: #fff; color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.cust-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 12px 14px; }
.cust-tabs { display: flex; gap: 4px; background: #efe5d8; border-radius: 12px; padding: 4px; }
.cust-tabs button { flex: 1; border: 0; border-radius: 9px; padding: 7px 0; font-size: 14px; font-weight: 700; background: none; color: #8a7b6e; }
.cust-tabs button.on { background: #fff; color: var(--coral); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.cust-options { flex: 1; overflow-y: auto; padding: 4px 2px 8px; -webkit-overflow-scrolling: touch; }
.cust-options h3 { margin: 10px 0 6px; font-size: 13px; color: #8a7b6e; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--ink); }
.chips button.on { border-color: var(--coral); background: #fff1ec; color: var(--coral); font-weight: 700; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(0,0,0,.12); padding: 0; }
.swatches button.on { outline: 3px solid var(--coral); outline-offset: 2px; }
.cust-actions { display: flex; gap: 8px; padding-top: 8px; }
.cust-actions button { flex: 1; border: 0; border-radius: 12px; padding: 11px; font-size: 16px; font-weight: 800; background: var(--coral); color: #fff; }
.cust-actions button.ghost { flex: 0 0 auto; background: #e9dfd2; color: var(--ink); padding: 11px 16px; }
@media (orientation: portrait) {
  .cust-card { flex-direction: column; }
  .cust-preview { flex: 0 0 auto; }
  #custCanvas { height: min(220px, 30dvh); }
}

/* ---------- 퀴즈 ---------- */
.screen.dim { background: rgba(20, 22, 28, .55); z-index: 15; }
.quiz-card { background: var(--cream); border-radius: 20px; width: min(640px, 100%); max-height: calc(100dvh - 24px); overflow-y: auto;
  padding: 14px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.35); border: 3px solid #e9d6bd; }
.quiz-head { display: flex; align-items: center; gap: 6px; }
.npc-name { font-weight: 800; color: var(--green); font-size: 15px; margin-right: auto; }
.tag { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #efe5d8; color: #8a7b6e; }
.tag.coin { background: #fff3cf; color: #9a6a12; }
.quiz-text { font-size: 19px; font-weight: 700; line-height: 1.45; margin: 10px 2px 12px; word-break: keep-all; }
.quiz-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quiz-choices button { display: flex; align-items: center; gap: 8px; text-align: left; border: 2px solid var(--line); background: #fff;
  border-radius: 14px; padding: 10px 12px; font-size: 16px; color: var(--ink); min-height: 48px; }
.quiz-choices button .n { font-weight: 800; color: var(--coral); }
.quiz-choices button:disabled { opacity: 1; }
.quiz-choices button.picked { border-color: #b9a58f; background: #f6efe6; }
.quiz-choices button.right { border-color: var(--green); background: #e6f4ea; }
.quiz-choices button.right .n { color: var(--green); }
.quiz-choices button.wrong { border-color: #c0504d; background: #fbe9e8; }
.quiz-choices button.wrong .n { color: #c0504d; }
.quiz-result { margin-top: 10px; border-radius: 12px; padding: 10px 12px; }
.quiz-result.ok { background: #e6f4ea; }
.quiz-result.no { background: #fbe9e8; }
.quiz-result b { display: block; font-size: 16px; }
.quiz-result p { margin: 4px 0 0; font-size: 14px; color: #5a4d44; }
.quiz-actions { display: flex; gap: 8px; margin-top: 12px; }
.quiz-actions button { flex: 1; border: 0; border-radius: 12px; padding: 11px; font-size: 16px; font-weight: 800; background: var(--coral); color: #fff; }
.quiz-actions button.ghost { flex: 0 0 auto; background: #e9dfd2; color: var(--ink); padding: 11px 16px; }
@media (max-height: 420px) {
  .quiz-text { font-size: 17px; margin: 6px 2px 8px; }
  .quiz-choices button { min-height: 42px; padding: 7px 10px; font-size: 15px; }
}

/* 로그인 */
.join-card input.gap { margin-top: 8px; }
.join-card .logout { background: none; color: #8a7b6e; font-size: 13px; font-weight: 400; margin-top: 4px; padding: 6px; }
.hudbtn.ghost { background: rgba(30, 32, 40, .72); }

/* 장소 이름 · 알림 · 계단 */
.me .place { background: var(--green); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
#toast { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); background: rgba(30, 32, 40, .85); color: #fff;
  padding: 8px 16px; border-radius: 999px; font-size: 14px; white-space: nowrap; }

/* 방향 버튼 · 행동 버튼 */
#pad { position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom));
  width: 156px; height: 156px; pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
#pad button { position: absolute; width: 54px; height: 54px; border: 0; border-radius: 16px; font-size: 20px;
  background: rgba(255,255,255,.78); color: #3a2f28; box-shadow: 0 2px 6px rgba(0,0,0,.25); touch-action: none; }
#pad button.on { background: var(--coral); color: #fff; }
#pad .u { left: 51px; top: 0; } #pad .d { left: 51px; bottom: 0; } #pad .l { left: 0; top: 51px; } #pad .r { right: 0; top: 51px; }
#acts { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px; pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
#btnAct { border: 0; border-radius: 18px; padding: 14px 18px; font-size: 16px; font-weight: 800; background: var(--coral); color: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.3); max-width: 46vw; animation: pop .25s ease-out; }
#btnJump { width: 72px; height: 72px; border: 0; border-radius: 50%; font-size: 15px; font-weight: 800; background: rgba(255,255,255,.85);
  color: #3a2f28; box-shadow: 0 3px 10px rgba(0,0,0,.3); }
@keyframes pop { from { transform: scale(.85); } to { transform: scale(1); } }

/* E자 미니맵 (건물 안) */
#minimap { position: absolute; top: 52px; right: max(10px, env(safe-area-inset-right)); width: 168px; height: 112px;
  background: rgba(30, 32, 40, .62); border-radius: 12px; }

/* 미니게임 */
.game-card { background: var(--cream); border-radius: 20px; width: min(560px, 100%); max-height: calc(100dvh - 24px); overflow-y: auto;
  padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.35); border: 3px solid #d9c8f0; }
.game-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.game-head b { color: #7b5cc4; font-size: 16px; }
.game-head button { border: 0; background: #e9dfd2; border-radius: 10px; padding: 6px 12px; font-weight: 700; color: var(--ink); }
.ghint { margin: 2px 0 8px; font-size: 14px; font-weight: 700; }
.gstat { margin: 8px 0 0; font-size: 13px; color: #8a7b6e; }
.mem { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.mem .card { aspect-ratio: 1; border: 0; border-radius: 10px; background: linear-gradient(135deg, #9a7bd0, #7b5cc4); color: #fff; font-size: 15px; font-weight: 800; }
.mem .card.open { background: #fff; color: var(--ink); border: 2px solid #d9c8f0; }
.mem .card.open.sym { color: #7b5cc4; font-size: 20px; }
.mem .card.ok { background: #e6f4ea; border-color: var(--green); }
.bar { position: relative; height: 34px; background: #efe5d8; border-radius: 17px; overflow: hidden; }
.bar .zone { position: absolute; top: 0; bottom: 0; width: 18%; background: #8fd19e; }
.bar .cursor { position: absolute; top: -2px; bottom: -2px; width: 6px; margin-left: -3px; background: var(--coral); border-radius: 3px; }
.bar.good { animation: good .3s; } .bar.bad { animation: bad .3s; }
@keyframes good { 50% { box-shadow: 0 0 0 5px #8fd19e; } } @keyframes bad { 50% { box-shadow: 0 0 0 5px #f2a19a; } }
.hit { display: block; width: 100%; margin-top: 10px; border: 0; border-radius: 14px; padding: 16px; font-size: 18px; font-weight: 800; background: #7b5cc4; color: #fff; touch-action: manipulation; }
.cho { font-size: 40px; font-weight: 800; letter-spacing: 8px; text-align: center; color: #7b5cc4; margin: 4px 0; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.opts button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px; font-size: 16px; font-weight: 700; color: var(--ink); }
.opts button.ok { border-color: var(--green); background: #e6f4ea; } .opts button.no { border-color: #c0504d; background: #fbe9e8; }
.game-result { margin-top: 10px; background: #f1eafb; border-radius: 12px; padding: 10px 12px; }
.game-result b { font-size: 18px; } .game-result p { margin: 4px 0 0; font-size: 14px; }
.game-result .reward { font-weight: 700; color: #7b5cc4; }
/* 이스터에그 */
.egg-card { background: var(--cream); border-radius: 22px; width: min(360px, 100%); padding: 18px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.35);
  border: 3px solid #ffd36b; animation: pop .35s ease-out; }
.egg-icon { font-size: 52px; line-height: 1.1; }
.egg-name { font-size: 18px; font-weight: 800; margin: 6px 0; }
.egg-card p { margin: 6px 0; font-size: 14px; line-height: 1.5; }
.egg-sub { color: #9a6a12; font-weight: 700; }
.egg-card button { margin-top: 8px; border: 0; border-radius: 12px; padding: 10px 26px; font-size: 16px; font-weight: 800; background: var(--coral); color: #fff; }

.swatches button.none { background: #fff; color: #b0a395; font-weight: 800; font-size: 14px; }

.cust-note { margin: 12px 2px 0; font-size: 12px; color: #8a7b6e; }
.cust-note.big { font-size: 15px; line-height: 1.7; text-align: center; margin-top: 28px; color: var(--ink); }
.chips.swatches { gap: 8px; }
.chips button.sw { width: 34px; height: 34px; padding: 0; border-radius: 50%; background: var(--c); border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line); }
.chips button.sw.on { background: var(--c); border-color: #fff; box-shadow: 0 0 0 3px var(--coral); }

.role-tabs { display: flex; gap: 4px; background: #efe5d8; border-radius: 12px; padding: 4px; margin: 4px 0 8px; }
.role-tabs button { flex: 1; border: 0; border-radius: 9px; padding: 8px 0; font-size: 15px; font-weight: 700; background: none; color: #8a7b6e; }
.role-tabs button.on { background: #fff; color: var(--coral); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- 미니게임 공통 (시작 화면·다시 하기·넓은 화면·버튼) ---------- */
.game-card.wide { width: min(820px, 100%); }
.gintro { text-align: center; padding: 6px 4px 4px; }
.gicon { font-size: 54px; line-height: 1.1; }
.ghow { font-size: 16px; font-weight: 700; margin: 6px 0; }
.gbest { color: #8a7b6e; font-size: 13px; margin: 0 0 10px; }
.gstart, .gagain { border: 0; border-radius: 14px; padding: 12px 34px; font-size: 18px; font-weight: 800; background: #7b5cc4; color: #fff; }
.gagain { margin-top: 8px; padding: 8px 20px; font-size: 15px; background: var(--coral); }
.arcade { display: flex; gap: 12px; align-items: stretch; justify-content: center; }
.aboard { display: flex; align-items: center; justify-content: center; flex: 0 1 auto; min-width: 0; }
.gcanvas { display: block; height: min(330px, calc(100dvh - 104px)); width: auto; max-width: 100%; border-radius: 10px; touch-action: none; }
.aside { flex: 0 0 190px; display: flex; flex-direction: column; gap: 8px; }
.aside .ghint { margin: 0; font-size: 13px; }
.astat { font-size: 14px; line-height: 1.6; } .astat b { color: #7b5cc4; font-size: 16px; }
.next { width: 64px; height: 48px; aspect-ratio: auto !important; background: #1f2433; border-radius: 8px; }
.gpad { display: grid; gap: 6px; }
.gpad.grid3 { grid-template-columns: repeat(3, 1fr); }
.gpad.one { grid-template-columns: 1fr; }
.gpad button { border: 0; border-radius: 12px; padding: 12px 0; font-size: 20px; font-weight: 800; background: #ece4f7; color: #5b4398;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.gpad button:active { background: #d9c8f0; }
.gpad button.wide2 { grid-column: span 2; }
.gpad button.blank { visibility: hidden; }
.gpad button.gend { font-size: 14px; padding: 8px 0; background: #e9dfd2; color: var(--ink); }
@media (max-height: 430px) {
  .gpad button { padding: 8px 0; font-size: 18px; }
  .aside { flex-basis: 170px; gap: 5px; }
  .gintro .gicon { font-size: 40px; }
}
@media (max-width: 560px) {
  .arcade { flex-direction: column; align-items: center; }
  .aside { flex-basis: auto; width: 100%; }
}
/* 2048 */
.b2048 { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: 6px; padding: 6px; background: #bcae9f; border-radius: 12px;
  width: min(300px, calc(100dvh - 104px)); aspect-ratio: 1; touch-action: none; }
.t2048 { display: flex; align-items: center; justify-content: center; border-radius: 8px; background: #d8ccbf; font-weight: 800; font-size: 22px; color: #6b5d50; }
.t2048.v2 { background: #f3ece2; } .t2048.v4 { background: #efe0c8; }
.t2048.v8 { background: #f2b179; color: #fff; } .t2048.v16 { background: #f59563; color: #fff; }
.t2048.v32 { background: #f67c5f; color: #fff; } .t2048.v64 { background: #f65e3b; color: #fff; }
.t2048.v128, .t2048.v256 { background: #edcf72; color: #fff; font-size: 19px; }
.t2048.v512, .t2048.v1024 { background: #edc53f; color: #fff; font-size: 17px; }
.t2048.v2048, .t2048.v4096 { background: #7b5cc4; color: #fff; font-size: 17px; }
/* 두더지 */
.moles { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 8px; width: min(300px, calc(100dvh - 104px)); aspect-ratio: 1; }
.hole { border: 0; border-radius: 16px; background: linear-gradient(#b5e39a, #94cf72); position: relative; overflow: hidden; touch-action: manipulation; }
.hole::before { content: ''; position: absolute; left: 14%; right: 14%; bottom: 12%; height: 26%; border-radius: 50%; background: #4a3220;
  box-shadow: inset 0 7px 0 #2e1f13, 0 2px 0 #7a5a3a; }
.hole span { position: absolute; left: 0; right: 0; bottom: -70%; font-size: 40px; line-height: 1; transition: bottom .12s; }
.hole.up span { bottom: 22%; }
.hole.hit { background: linear-gradient(#ffe59a, #f5c95a); }
/* 짝맞추기(음식) */
.mem.big .card.open span { font-size: 28px; }
/* 양궁 */
.ahit { margin: 0; min-height: 24px; font-size: 18px; font-weight: 800; color: var(--coral); }
/* 암산 */
.mq { font-size: 34px; font-weight: 800; text-align: center; color: #7b5cc4; margin: 6px 0; }
.mq.bad { animation: bad .3s; }
/* 영단어 */
.smean { font-size: 24px; font-weight: 800; text-align: center; }
.sslots { display: flex; justify-content: center; gap: 6px; margin: 8px 0; }
.sslots span { width: 30px; text-align: center; font-size: 24px; font-weight: 800; border-bottom: 3px solid #d9c8f0; color: #b0a395; }
.sslots span.ok { color: #7b5cc4; border-color: #7b5cc4; }
.stiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.stiles button { width: 44px; height: 44px; border: 0; border-radius: 10px; background: #ece4f7; color: #5b4398; font-size: 22px; font-weight: 800; touch-action: manipulation; }
.stiles button.used { visibility: hidden; }
.stiles button.no { animation: bad .3s; background: #fbe9e8; }
/* 그림 퍼즐 */
.spuz { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 3px; width: min(300px, calc(100dvh - 104px)); aspect-ratio: 1; background: #3a2f28; padding: 3px; border-radius: 10px; }
.ptile { border: 0; border-radius: 4px; background-color: #ddd; color: rgba(255,255,255,.85); font-weight: 800; font-size: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: flex-start; padding: 3px 5px; touch-action: manipulation; }
.ptile.empty { background: transparent; }
.spuz.solved { box-shadow: 0 0 0 4px #8fd19e; }
.spuz.solved .ptile { color: transparent; text-shadow: none; }
.spreview { width: 110px; aspect-ratio: 1; background-size: cover; background-position: center; border-radius: 8px; box-shadow: 0 0 0 2px #d9c8f0; }
/* 결과: 게임판 위에 떠서 보이게 (폰 가로 화면에서 스크롤 없이) */
.game-card { position: relative; }
.game-card .game-result { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); width: min(380px, 92%); margin: 0;
  text-align: center; z-index: 3; background: #fbf7ff; border: 3px solid #d9c8f0; box-shadow: 0 10px 30px rgba(0,0,0,.3); padding: 14px; animation: gpop .3s ease-out; }
@keyframes gpop { from { transform: translate(-50%, -50%) scale(.85); } to { transform: translate(-50%, -50%) scale(1); } }
.game-card .game-result b { font-size: 24px; }
