@font-face { font-family: 'Jua'; src: url('../fonts/Jua-Regular.woff') format('woff'); font-display: swap; }
@font-face { font-family: 'Bagel Fat One'; src: url('../fonts/BagelFatOne-Regular.woff') format('woff'); font-display: swap; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #4fa8ff; font-family: 'Jua', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif; font-weight: 400; letter-spacing: 0; color: #2b2b2b; user-select: none; -webkit-user-select: none; touch-action: none; }
#app { position: fixed; inset: 0; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
small { font-size: 0.8em; }

/* 공통 버튼 */
.btn { border: none; border-radius: 16px; padding: 12px 20px; font-size: 18px; background: #fff; color: #333; box-shadow: 0 4px 0 #c9ced6, 0 6px 14px rgba(0,0,0,.12); transition: transform .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9ced6; }
.btn.primary { background: linear-gradient(#ffb84d, #ff8a1f); color: #fff; box-shadow: 0 4px 0 #d9650a, 0 6px 14px rgba(0,0,0,.15); text-shadow: 0 1px 0 rgba(0,0,0,.2); }
.btn.danger { background: #ffe3e3; color: #c92a2a; box-shadow: 0 4px 0 #ffa8a8; }
.btn.big { font-size: 22px; padding: 15px 28px; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.row.col { flex-direction: column; align-items: stretch; }

/* 로딩 */
#loading { position: absolute; inset: 0; background: linear-gradient(#4fa8ff, #bfe6ff); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; font-size: 24px; z-index: 50; text-align: center; padding: 20px; }
#loading .spin { font-size: 64px; animation: run 0.6s infinite alternate; }
#loading small { color: #fff3bf; font-size: 16px; margin-top: 12px; line-height: 1.5; }
@keyframes run { to { transform: translateX(20px) rotate(8deg); } }

/* 시작 화면 */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; background: radial-gradient(ellipse at center, rgba(255,255,255,.1), rgba(0,40,90,.35)); padding: 16px; }
.title-box { text-align: center; animation: pop .6s; }
.badge { display: inline-block; background: #fff; color: #ff6b3d; padding: 6px 16px; border-radius: 99px; font-size: 18px; box-shadow: 0 3px 0 #ffc9a8; }
.title-box h1 { font-size: clamp(36px, 7vw, 72px); margin: 12px 0 0; color: #fff; text-shadow: 0 4px 0 #ff6b3d, 0 8px 0 #c2410c, 0 12px 20px rgba(0,0,0,.3); letter-spacing: 1px; }
.title-box h2 { font-size: clamp(22px, 4vw, 36px); margin: 8px 0 26px; color: #fff59d; text-shadow: 0 3px 0 #1c7ed6; }
.title-btns { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.tip { color: #fff; font-size: 15px; margin-top: 22px; text-shadow: 0 1px 3px rgba(0,0,0,.5); line-height: 1.6; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

.panel { background: #fffdf6; border-radius: 26px; padding: 24px 28px; width: min(560px, 94vw); max-height: 92vh; overflow: auto; box-shadow: 0 10px 0 #e5d9b8, 0 20px 40px rgba(0,0,0,.25); animation: pop .3s; }
.panel.small { width: min(420px, 92vw); text-align: center; font-size: 19px; }
.panel h2 { margin: 0 0 14px; color: #ff6b3d; text-align: center; }
.lbl { display: block; font-size: 19px; margin: 12px 0 8px; }
#nameInput { width: 100%; font-size: 24px; padding: 12px 16px; border-radius: 14px; border: 3px solid #ffd8a8; font-family: inherit; outline: none; text-align: center; }
#nameInput:focus { border-color: #ff8a1f; }
#gradeBtns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#gradeBtns button { font-size: 21px; padding: 14px 0; border-radius: 14px; border: 3px solid #e7e0cf; background: #fff; }
#gradeBtns button.on { background: #fff3bf; border-color: #ffa94d; transform: scale(1.05); }
.info { text-align: center; color: #666; min-height: 24px; }

/* 캐릭터 선택 */
#charsel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 20; padding: 12px 12px 18px; background: linear-gradient(transparent, rgba(0,0,0,.35)); text-align: center; }
.cs-title { position: fixed; top: 18px; left: 0; right: 0; color: #fff; font-size: clamp(24px, 4vw, 36px); text-shadow: 0 3px 0 #1c7ed6, 0 5px 12px rgba(0,0,0,.3); margin: 0; }
#charCards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; max-width: 900px; margin: 0 auto; }
.char-card { border: 4px solid transparent; border-radius: 18px; background: #fff; padding: 10px 6px; font-size: 20px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 4px 0 #ccc; border-top: 8px solid var(--c); }
.char-card small { font-size: 13px; color: #777; }
.char-card.on { border-color: var(--c); transform: translateY(-6px); box-shadow: 0 8px 0 var(--c); }

/* HUD */
#hud { display: none; }
#hud.show { display: block; }
#objective { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; max-width: min(460px, 56vw); background: rgba(255,255,255,.93); border-radius: 18px; padding: 10px 16px; box-shadow: 0 4px 0 rgba(0,0,0,.08), 0 6px 18px rgba(0,0,0,.12); z-index: 5; border-left: 8px solid #ff8a1f; }
#objective.pulse { animation: pulse .7s; }
@keyframes pulse { 40% { transform: scale(1.05); background: #fff3bf; } }
.obj-top { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
#chapName { background: #ff8a1f; color: #fff; padding: 2px 10px; border-radius: 99px; font-size: 15px; }
#gradeTag { font-size: 13px; color: #888; }
#objText { font-size: 18px; margin-top: 6px; line-height: 1.35; }
#objText b { color: #e8590c; }
#mapWrap { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; width: 150px; height: 150px; border-radius: 20px; overflow: hidden; border: 4px solid #fff; box-shadow: 0 6px 16px rgba(0,0,0,.25); z-index: 5; }
#mapWrap .n { position: absolute; top: 2px; left: 50%; transform: translateX(-50%); font-size: 12px; color: #fff; background: rgba(0,0,0,.35); padding: 0 6px; border-radius: 8px; }
#topBtns { position: absolute; top: calc(max(12px, env(safe-area-inset-top)) + 160px); right: 12px; display: flex; gap: 8px; z-index: 5; }
#topBtns button { width: 46px; height: 46px; border-radius: 14px; border: none; background: rgba(255,255,255,.93); font-size: 22px; box-shadow: 0 3px 0 rgba(0,0,0,.12); position: relative; }
#clueCount { position: absolute; top: -6px; right: -6px; background: #ff4d4d; color: #fff; font-size: 12px; border-radius: 99px; min-width: 20px; padding: 1px 5px; }
#clueCount:empty { display: none; }
.bounce { animation: bounce .4s 3; }
@keyframes bounce { 50% { transform: translateY(-8px) scale(1.1); } }
#prompt { position: absolute; left: 50%; bottom: 28%; transform: translateX(-50%) scale(.8); background: #2b2b2b; color: #fff; padding: 10px 20px; border-radius: 99px; font-size: 20px; opacity: 0; transition: .2s; pointer-events: none; z-index: 6; white-space: nowrap; border: 3px solid #ffd43b; }
#prompt.show { opacity: .95; transform: translateX(-50%) scale(1); }
#distance { position: absolute; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translateX(-50%); color: #fff; font-size: 18px; text-shadow: 0 2px 4px rgba(0,0,0,.6); pointer-events: none; z-index: 4; }

/* 터치 */
#touch { position: absolute; inset: auto 0 0 0; height: 0; z-index: 7; }
#joy { position: fixed; left: max(24px, env(safe-area-inset-left)); bottom: 28px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.28); border: 4px solid rgba(255,255,255,.7); touch-action: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px; border-radius: 50%; background: rgba(255,255,255,.95); box-shadow: 0 4px 10px rgba(0,0,0,.25); pointer-events: none; }
#tbtns { position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: 24px; display: grid; grid-template-columns: 76px 76px; grid-template-areas: 'run jump' 'act act'; gap: 10px; }
#tbtns button { border: none; border-radius: 22px; background: rgba(255,255,255,.88); font-size: 26px; height: 72px; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 4px 0 rgba(0,0,0,.15); touch-action: none; }
#tbtns small { font-size: 12px; }
#tRun { grid-area: run; } #tJump { grid-area: jump; } #tAct { grid-area: act; }
#tRun.on { background: #ffd43b; }
#tAct.ready { background: #ffd43b; animation: pulse .9s infinite; }

/* 대화창 */
#dialog { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(860px, 96vw); display: flex; gap: 14px; align-items: flex-end; z-index: 12; animation: up .25s; }
@keyframes up { from { transform: translate(-50%, 30px); opacity: 0; } }
#dlgFace { font-size: 64px; width: 96px; height: 96px; flex: none; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 26px; box-shadow: 0 5px 0 #e5d9b8; }
#dlgBody { flex: 1; background: #fffdf6; border-radius: 24px; padding: 18px 22px 14px; position: relative; box-shadow: 0 6px 0 #e5d9b8, 0 12px 28px rgba(0,0,0,.25); border: 4px solid #fff; min-height: 120px; }
#dlgName { position: absolute; top: -18px; left: 18px; color: #fff; padding: 4px 16px; border-radius: 99px; font-size: 18px; }
#dlgText { font-size: clamp(19px, 2.4vw, 23px); line-height: 1.5; min-height: 66px; padding-top: 6px; }
#dlgText .hint { color: #e8590c; }
#dlgNext { text-align: right; font-size: 14px; color: #aaa; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
#dialog.narr #dlgBody { background: #fff8e1; }
#choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.choice { text-align: left; font-size: clamp(17px, 2.2vw, 20px); padding: 12px 16px; border-radius: 14px; border: 3px solid #ffd8a8; background: #fff; line-height: 1.35; display: flex; gap: 10px; align-items: center; }
.choice:hover { background: #fff4e6; }
.choice .num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: #ff8a1f; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; }
.choice.hintcard { border-color: #74c0fc; background: #e7f5ff; font-size: clamp(15px, 1.9vw, 17px); }
.choice.hintcard .num { background: #339af0; }
.choice.hintcard small { color: #1c7ed6; }
.clue.orbs { background: #e7f5ff; border-color: #a5d8ff; }
.choice.wrong, .choice:disabled { opacity: .45; border-color: #ffa8a8; text-decoration: line-through; animation: shake .4s; }

/* 미니게임 */
#mg { position: absolute; inset: 0; background: rgba(20,30,60,.55); display: flex; align-items: center; justify-content: center; z-index: 14; padding: 10px; }
#mgBox { background: #fffdf6; border-radius: 28px; width: min(820px, 97vw); max-height: 96vh; overflow: auto; padding: 18px 22px 22px; box-shadow: 0 10px 0 #e5d9b8, 0 20px 50px rgba(0,0,0,.35); animation: pop .3s; text-align: center; }
#mgHead h2 { margin: 0; color: #ff6b3d; font-size: clamp(24px, 3.4vw, 32px); }
#mgHead p { margin: 6px 0 12px; font-size: clamp(16px, 2vw, 19px); color: #555; line-height: 1.45; }
.mg-status { font-size: 19px; min-height: 28px; margin: 10px 0 0; line-height: 1.45; }
.mg-tools { margin-top: 8px; }
.mg-done { margin-top: 14px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.puzzle { display: grid; gap: 4px; width: min(560px, 88vw); max-height: 58vh; margin: 0 auto; background: #c9b991; padding: 4px; border-radius: 12px; }
.puzzle .tile { background-repeat: no-repeat; border-radius: 6px; cursor: pointer; transition: transform .2s; box-shadow: inset 0 0 0 2px rgba(0,0,0,.08); aspect-ratio: 1; }
.puzzle .cell { position: relative; }
.puzzle .rot { position: absolute; right: 4px; bottom: 4px; width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; background: #ff8a1f; color: #fff; font-size: 22px; line-height: 1; box-shadow: 0 2px 6px rgba(0,0,0,.3); z-index: 2; }
.puzzle.solved .rot { display: none; }
.puzzle .tile.sel { outline: 5px solid #ff8a1f; z-index: 1; }
.puzzle .tile.hint { animation: glow .5s 3; }
@keyframes glow { 50% { outline: 6px solid #ffd43b; filter: brightness(1.15); } }
.puzzle.solved { gap: 0; background: #51cf66; }

.tug { user-select: none; }
.tug-field { display: flex; align-items: center; gap: 8px; margin: 6px 0 14px; }
.tug .team { font-size: 28px; line-height: 1.1; width: 120px; }
.tug .team small { font-size: 15px; color: #666; }
.tug .rope { flex: 1; height: 14px; background: repeating-linear-gradient(45deg, #c8a165 0 10px, #a8834a 10px 20px); border-radius: 7px; position: relative; }
.tug .mark { position: absolute; top: -14px; left: 50%; width: 14px; height: 42px; margin-left: -7px; background: #ff3b3b; border-radius: 4px; transition: left .25s; }
.tug .center-line { position: absolute; left: 50%; top: -20px; bottom: -20px; border-left: 3px dashed #888; }
.gauge { position: relative; height: 42px; background: #ffe3e3; border-radius: 21px; margin: 12px auto; width: min(560px, 90%); overflow: visible; border: 3px solid #fff; box-shadow: inset 0 2px 6px rgba(0,0,0,.12); }
.gauge .zone { position: absolute; top: 0; bottom: 0; background: #69db7c; border-radius: 18px; }
.gauge .cursor { position: absolute; top: -26px; font-size: 26px; transform: translateX(-50%); color: #1c7ed6; }
.tug.good .gauge { box-shadow: 0 0 0 6px #69db7c; } .tug.miss .gauge { animation: shake .3s; }
.pull { margin-top: 6px; }

.classify .progress { display: flex; gap: 6px; justify-content: center; margin-bottom: 10px; }
.classify .progress span { width: 16px; height: 16px; border-radius: 50%; background: #e9ecef; }
.classify .progress span.on { background: #51cf66; } .classify .progress span.now { background: #ffa94d; }
.card-area { min-height: 170px; display: flex; justify-content: center; align-items: center; }
.sit-card { background: #fff; border: 4px solid #ffd8a8; border-radius: 22px; padding: 16px 22px; width: min(460px, 86vw); box-shadow: 0 6px 0 #ffe8cc; }
.sit-card .sc-i { font-size: 54px; } .sit-card .sc-t { font-size: clamp(20px, 2.6vw, 24px); line-height: 1.4; }
.classify.easy .sit-card .sc-i { font-size: 72px; }
.sit-card.fly-l { animation: flyl .8s forwards; } .sit-card.fly-r { animation: flyr .8s forwards; }
@keyframes flyl { to { transform: translate(-40%, 140px) scale(.3); opacity: 0; } }
@keyframes flyr { to { transform: translate(40%, 140px) scale(.3); opacity: 0; } }
.baskets { display: flex; gap: 14px; justify-content: center; margin-top: 12px; }
.basket { flex: 1; max-width: 300px; border: none; border-radius: 22px; padding: 14px 10px; font-size: clamp(19px, 2.4vw, 23px); background: var(--c); color: #fff; box-shadow: 0 6px 0 rgba(0,0,0,.2); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.basket .bi { font-size: 40px; } .basket:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.2); }

.phone-frame { background: #222; border-radius: 30px; padding: 14px; width: min(520px, 90vw); margin: 0 auto; }
.ph-top { color: #aaa; font-size: 14px; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; background: #fff; border-radius: 18px; padding: 16px; }
.chip { border: 3px solid #dee2e6; background: #f8f9fa; border-radius: 99px; padding: 10px 16px; font-size: clamp(17px, 2.2vw, 20px); }
.chip.bad { background: #ffe3e3; border-color: #fa5252; color: #c92a2a; text-decoration: line-through; }
.chip.bad::after { content: ' 🚫'; }
.chip.nope { animation: shake .4s; border-color: #adb5bd; }

.order .timeline { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.order .slot { min-height: 120px; border: 3px dashed #ffc078; border-radius: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 30px; color: #ffc078; padding: 6px; }
.order .slot.filled { border-style: solid; background: #fff4e6; color: #333; }
.order .pool { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pic { border: 3px solid #ffd8a8; background: #fff; border-radius: 18px; padding: 10px; }
.pi { font-size: 40px; } .pt { font-size: 16px; line-height: 1.35; }
.order .slot .pt { font-size: 13px; }

.chat .msgs { background: #e7f5ff; border-radius: 20px; padding: 14px; height: min(300px, 38vh); overflow-y: auto; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.bub { max-width: 82%; padding: 10px 14px; border-radius: 18px; font-size: clamp(16px, 2vw, 19px); line-height: 1.4; animation: pop .25s; }
.bub small { display: block; font-size: 12px; opacity: .7; }
.bub.mj { background: #fff; align-self: flex-start; border-bottom-left-radius: 4px; }
.bub.me { background: #ffd8a8; align-self: flex-end; border-bottom-right-radius: 4px; }
.bub.mirror { background: #e5dbff; align-self: center; text-align: center; max-width: 94%; }
.chat .opts { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.info-card { font-size: 19px; line-height: 1.5; }
.ad { border-radius: 16px; padding: 14px; margin: 0 auto 10px; width: min(420px, 90%); font-size: 24px; }
.ad p { margin: 4px 0; } .ad small { font-size: 13px; opacity: .7; }
.ad.dark { background: #111; color: #ffd43b; border: 6px solid #444; }
.ad.yellow { background: #fff59d; color: #c92a2a; border: 4px solid #c92a2a; }
.blink { animation: blink .8s infinite; }
.phone-mock { background: #222; border-radius: 26px; padding: 16px 12px; width: min(340px, 86%); margin: 0 auto 10px; color: #aaa; }
.noti { background: #fff; color: #333; border-radius: 14px; padding: 10px; margin-bottom: 8px; text-align: left; font-size: 17px; }

/* 모달 */
.modal { position: absolute; inset: 0; background: rgba(20,30,60,.5); display: flex; align-items: center; justify-content: center; z-index: 30; }
#confirm { z-index: 40; }
.clue { display: flex; gap: 12px; align-items: flex-start; background: #fff; border-radius: 16px; padding: 10px 14px; margin-bottom: 10px; box-shadow: 0 3px 0 #eee; }
.clue .ci { font-size: 36px; } .clue p { margin: 4px 0 0; color: #555; font-size: 16px; line-height: 1.4; }
.empty { text-align: center; color: #999; }
.help p { font-size: 17px; line-height: 1.55; margin: 8px 0; }

/* 알림 */
#toasts { position: absolute; top: 120px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 16; pointer-events: none; width: min(640px, 92vw); }
.toast { background: rgba(255,255,255,.96); padding: 10px 18px; border-radius: 16px; font-size: 18px; box-shadow: 0 6px 16px rgba(0,0,0,.2); animation: up2 .3s; text-align: center; line-height: 1.4; transition: .4s; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes up2 { from { transform: translateY(10px); opacity: 0; } }
#banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.5); font-size: clamp(30px, 6vw, 56px); color: #fff; text-shadow: 0 4px 0 #ff6b3d, 0 8px 18px rgba(0,0,0,.35); opacity: 0; pointer-events: none; z-index: 17; text-align: center; transition: .3s cubic-bezier(.2,1.6,.4,1); width: 94vw; }
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner small { font-size: .5em; }
#banner .count { font-size: 2.2em; }
#banner.gold { color: #fff3bf; text-shadow: 0 4px 0 #e67700, 0 0 30px #ffd43b; }
#banner.ending { font-size: clamp(24px, 4vw, 40px); background: rgba(255,255,255,.92); color: #e8590c; text-shadow: none; padding: 22px 26px; border-radius: 26px; width: min(820px, 92vw); box-shadow: 0 10px 30px rgba(0,0,0,.25); line-height: 1.4; }
#chapterCard { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(90deg, transparent, rgba(0,0,0,.55) 20%, rgba(0,0,0,.55) 80%, transparent); opacity: 0; pointer-events: none; z-index: 18; transition: .5s; color: #fff; text-align: center; clip-path: inset(30% 0 30% 0); }
#chapterCard.show { opacity: 1; }
.cc-chap { font-size: 24px; color: #ffd43b; letter-spacing: 4px; }
.cc-title { font-size: clamp(28px, 5vw, 48px); margin-top: 8px; line-height: 1.3; text-shadow: 0 3px 8px rgba(0,0,0,.5); }
#fader { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .45s; z-index: 25; }
#fader.on { opacity: 1; }

/* 인증서 */
#cert { position: absolute; inset: 0; background: rgba(20,30,60,.7); display: flex; align-items: center; justify-content: center; z-index: 35; padding: 12px; }
.cert-box { text-align: center; animation: pop .5s; }
#certImg { width: min(900px, 94vw); max-height: 78vh; object-fit: contain; border-radius: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.4); background: #fff; }
#printArea { display: none; }
@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body * { visibility: hidden; }
  html, body { background: #fff; overflow: visible; }
  #printArea, #printArea * { visibility: visible; }
  #printArea { display: block; position: fixed; inset: 0; }
  #printImg { width: 100%; height: 100%; object-fit: contain; }
}

@media (max-width: 700px) {
  #mapWrap { width: 110px; height: 110px; }
  #topBtns { top: calc(max(12px, env(safe-area-inset-top)) + 120px); }
  #objText { font-size: 16px; }
  #dlgFace { width: 64px; height: 64px; font-size: 40px; }
  .order .timeline { grid-template-columns: repeat(2, 1fr); }
  .tug .team { width: 70px; font-size: 20px; }
}
@media (max-height: 560px) {
  #joy { width: 110px; height: 110px; }
  #tbtns button { height: 58px; }
}
#minimap { width: 100%; height: 100%; display: block; }

#mg:not(.hidden) ~ #toasts { top: auto; bottom: 18px; }

/* ── 글꼴 굵기 다듬기 (나눔스퀘어라운드) ── */
h1, h2, .btn, .badge, #chapName, .cc-chap, .cc-title, #banner, #dlgName, .basket, .char-card b, .count, .mg-status b { font-weight: 400; }
#dlgText, .choice, .sit-card .sc-t, .bub, .info-card, .toast, .help p, .clue p, #objText { font-weight: 400; line-height: 1.55; }
.tip, small, .info { font-weight: 400; }
.title-box h1 { letter-spacing: -1px; }
.char-card { padding: 12px 8px; }
.char-card .cf { font-size: 30px; }
.char-card b { font-size: 24px; color: var(--c); }
#charCards { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 760px; }

/* 목적지 표시 */
#tgtMark { position: absolute; display: none; pointer-events: none; z-index: 4; width: 0; height: 0; }
#tgtMark .tm-star { position: absolute; transform: translate(-50%, -100%); background: #fff; border: 3px solid #ffb800; border-radius: 99px; padding: 3px 10px 3px 8px; font-size: 17px; color: #444; white-space: nowrap; box-shadow: 0 3px 8px rgba(0,0,0,.25); animation: tmBob 1s ease-in-out infinite alternate; }
#tgtMark .tm-star span { margin-left: 4px; }
#tgtMark.on .tm-star::after { content: ''; position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); border: 7px solid transparent; border-top-color: #ffb800; }
#tgtMark .tm-arrow { display: none; position: absolute; width: 0; height: 0; border-top: 15px solid transparent; border-bottom: 15px solid transparent; border-left: 26px solid #ffb800; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); transform: translate(-50%, -50%) rotate(var(--rot)) translateX(30px); }
#tgtMark.edge .tm-arrow { display: block; }
#tgtMark.edge .tm-star { transform: translate(-50%, -50%); animation: none; }
@keyframes tmBob { from { margin-top: 0; } to { margin-top: -8px; } }
.sign-font { font-family: 'Bagel Fat One', 'Jua', sans-serif; }
.title-box h1, .cs-title, .cc-title, #chapName, #banner { font-family: 'Bagel Fat One', 'Jua', sans-serif; }

#dlgFace.photo { padding: 0; overflow: hidden; background: linear-gradient(#fff6e0, #ffe3b8); }
#dlgFace img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* 숨참 게이지 (계속 달리면 차오름 · 가득 차면 20초 쉬기) */
#breath { position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,0.92); box-shadow: 0 3px 10px rgba(0,0,0,0.18); font: 14px 'Jua', sans-serif; color: #495057; pointer-events: none; }
#breath.hidden { display: none; }
#breath .bi { font-size: 17px; }
#breath .bb { width: 150px; height: 12px; border-radius: 6px; background: #e9ecef; overflow: hidden; }
#breath .bf { height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, #69db7c, #ffd43b); transition: width 0.1s linear; }
#breath.warn .bf { background: linear-gradient(90deg, #ffd43b, #ff922b); }
#breath.tired .bf { background: #fa5252; }
#breath.tired { color: #c92a2a; }
#breath .bt { min-width: 76px; text-align: left; }
@media (max-width: 600px) { #breath .bb { width: 100px; } #breath { font-size: 12px; } }

/* ═════════ 새 시작 화면 (실시간 3D 배경 + 큰 로고) ═════════ */
#title, #menuScr { position: absolute; inset: 0; z-index: 20; }
#title.hidden, #menuScr.hidden { display: none; }
#title { cursor: pointer; }
.t-shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(100deg, rgba(10,30,80,.55) 0%, rgba(10,30,80,.18) 38%, rgba(0,0,0,0) 60%), linear-gradient(0deg, rgba(0,0,0,.25), rgba(0,0,0,0) 25%); }
.t-logo { position: absolute; left: clamp(18px, 5vw, 72px); top: clamp(18px, 7vh, 80px); display: flex; flex-direction: column; align-items: flex-start; gap: 4px; animation: tIn .7s cubic-bezier(.2,1.4,.4,1) both; }
@keyframes tIn { from { opacity: 0; transform: translateY(-30px) scale(.9); } to { opacity: 1; transform: none; } }
.t-badge { font-family: 'Jua', sans-serif; font-size: clamp(14px, 1.8vw, 19px); color: #1b2a5c; background: #fff; padding: 5px 14px; border-radius: 99px; box-shadow: 0 3px 0 #1b2a5c; margin-bottom: 6px; }
.t-h1 { margin: 0; font-family: 'Bagel Fat One', 'Jua', sans-serif; font-weight: 400; line-height: .98; display: flex; flex-direction: column; letter-spacing: -1px; }
.t-h1 span { --s: #1b2a5c;
  text-shadow: 3px 0 0 var(--s), -3px 0 0 var(--s), 0 3px 0 var(--s), 0 -3px 0 var(--s), 2.5px 2.5px 0 var(--s), -2.5px 2.5px 0 var(--s), 2.5px -2.5px 0 var(--s), -2.5px -2.5px 0 var(--s),
               5px 0 0 var(--s), -5px 0 0 var(--s), 0 5px 0 var(--s), 0 -5px 0 var(--s), 4px 4px 0 var(--s), -4px 4px 0 var(--s), 4px -4px 0 var(--s), -4px -4px 0 var(--s),
               3px 9px 0 var(--s), 6px 11px 0 rgba(0,0,0,.25); }
.t-h1 .l1 { font-size: clamp(34px, 6.2vw, 78px); color: #fff; }
.t-h1 .l2 { font-size: clamp(58px, 11vw, 140px); color: #ffd84a; transform: rotate(-3deg); transform-origin: left center; margin-top: 2px; }
.t-sub { font-family: 'Bagel Fat One', 'Jua', sans-serif; font-size: clamp(17px, 2.4vw, 28px); color: #1b2a5c; background: #ffd84a; padding: 4px 16px 6px; border-radius: 12px; transform: rotate(-4deg); box-shadow: 0 4px 0 #1b2a5c; margin: 10px 0 0 8px; }
.t-start { margin-top: clamp(18px, 4vh, 40px); font-family: 'Bagel Fat One', 'Jua', sans-serif; font-size: clamp(22px, 3vw, 36px); color: #1b2a5c; padding: .45em 1.6em .55em; border-radius: 999px; border: 5px solid #fff; background: linear-gradient(#ffcf4d, #ff8f1f); box-shadow: 0 7px 0 #b85a00, 0 12px 26px rgba(0,0,0,.35); cursor: pointer; animation: tPulse 1.6s ease-in-out infinite; }
.t-start:active { transform: translateY(5px); box-shadow: 0 2px 0 #b85a00; }
@keyframes tPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.t-credit { position: absolute; left: clamp(16px, 4vw, 60px); bottom: max(16px, env(safe-area-inset-bottom)); font-family: 'Jua', sans-serif; font-size: 14px; color: #fff; background: rgba(15,20,40,.75); padding: 6px 14px; border-radius: 99px; }
@media (max-aspect-ratio: 1/1) { .t-shade { background: linear-gradient(180deg, rgba(10,30,80,.6) 0%, rgba(10,30,80,.15) 45%, rgba(0,0,0,0) 60%); } .t-logo { left: 0; right: 0; align-items: center; text-align: center; } .t-h1 { align-items: center; } .t-h1 .l2 { transform-origin: center; } }

/* 메뉴: 어두운 배경 + 큰 카드 */
#menuScr { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(14px, 4vh, 36px); padding: 18px; background: radial-gradient(ellipse at 50% 40%, rgba(20,24,60,.55), rgba(8,10,28,.88)); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); animation: fadeIn .3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.m-title { margin: 0; font-family: 'Bagel Fat One', 'Jua', sans-serif; font-weight: 400; font-size: clamp(28px, 5vw, 56px); color: #fff; text-shadow: 0 0 18px rgba(90,200,255,.9), 0 4px 0 #1b2a5c; text-align: center; }
.m-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(10px, 2vw, 24px); width: min(1100px, 96vw); }
.m-card { position: relative; border: 4px solid rgba(255,255,255,.9); border-radius: 22px; overflow: hidden; padding: 0; background: #f1f3fa; box-shadow: 0 8px 0 rgba(0,0,0,.35), 0 14px 30px rgba(0,0,0,.4); cursor: pointer; text-align: center; transition: transform .15s; animation: cardIn .45s cubic-bezier(.2,1.4,.4,1) both; display: flex; flex-direction: column; }
.m-card:nth-child(2) { animation-delay: .06s; } .m-card:nth-child(3) { animation-delay: .12s; } .m-card:nth-child(4) { animation-delay: .18s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
.m-card:hover { transform: translateY(-6px) scale(1.02); }
.m-card:active { transform: translateY(2px); }
.m-art { position: relative; height: clamp(120px, 26vh, 240px); background: linear-gradient(160deg, var(--g1), var(--g2)); clip-path: polygon(0 0, 100% 0, 100% 78%, 0 100%); display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
.m-art img { height: 104%; width: auto; max-width: 100%; object-fit: contain; filter: drop-shadow(0 6px 6px rgba(0,0,0,.25)); }
.m-emo { font-size: clamp(64px, 11vh, 110px); align-self: center; filter: drop-shadow(0 6px 0 rgba(0,0,0,.18)); }
.m-txt { padding: 10px 10px 16px; background-image: linear-gradient(45deg, #e6e9f5 25%, transparent 25%, transparent 75%, #e6e9f5 75%), linear-gradient(45deg, #e6e9f5 25%, transparent 25%, transparent 75%, #e6e9f5 75%); background-size: 22px 22px; background-position: 0 0, 11px 11px; flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.m-txt b { font-family: 'Bagel Fat One', 'Jua', sans-serif; font-weight: 400; font-size: clamp(20px, 2.6vw, 30px); color: #1b1d3a; }
.m-txt small { font-family: 'Jua', sans-serif; font-size: clamp(12px, 1.4vw, 15px); color: #4a4f6a; }
.m-card.off { filter: grayscale(.85) brightness(.75); cursor: default; }
.m-card.off:hover { transform: none; }
.m-back { font-family: 'Jua', sans-serif; font-size: 17px; color: #fff; background: rgba(255,255,255,.12); border: 2px solid rgba(255,255,255,.5); padding: 8px 20px; border-radius: 99px; cursor: pointer; }
@media (max-width: 760px) { .m-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } .m-art { height: clamp(90px, 18vh, 160px); } }

/* 이름 · 학년 입력: 같은 분위기의 카드 */
#setup { background: radial-gradient(ellipse at 50% 40%, rgba(20,24,60,.5), rgba(8,10,28,.85)); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
#setup .panel { border: 5px solid #fff; border-radius: 26px; background: #fffdf6; box-shadow: 0 10px 0 #1b2a5c, 0 22px 50px rgba(0,0,0,.45); }
#setup .panel h2 { font-family: 'Bagel Fat One', 'Jua', sans-serif; font-size: clamp(26px, 4vw, 36px); color: #ff7a1a; text-shadow: 0 3px 0 #1b2a5c22; }
#gradeBtns button { font-family: 'Jua', sans-serif; border: none; background: #eef1fb; box-shadow: 0 4px 0 #c5cbe3; color: #1b2a5c; transition: transform .1s; }
#gradeBtns button.on { background: linear-gradient(#ffcf4d, #ff8f1f); color: #1b2a5c; box-shadow: 0 4px 0 #b85a00; transform: translateY(-2px) scale(1.05); }
#setupNext, #charGo { font-family: 'Bagel Fat One', 'Jua', sans-serif; color: #1b2a5c; background: linear-gradient(#ffcf4d, #ff8f1f); border: 4px solid #fff; border-radius: 999px; box-shadow: 0 6px 0 #b85a00, 0 10px 20px rgba(0,0,0,.25); text-shadow: none; }

/* 캐릭터 고르기: 큰 제목 + 그림 카드 */
.cs-title { font-family: 'Bagel Fat One', 'Jua', sans-serif; font-weight: 400; color: #ffd84a; --s: #1b2a5c; text-shadow: 3px 0 0 var(--s), -3px 0 0 var(--s), 0 3px 0 var(--s), 0 -3px 0 var(--s), 2px 2px 0 var(--s), -2px 2px 0 var(--s), 2px -2px 0 var(--s), -2px -2px 0 var(--s), 2px 7px 0 var(--s); }
#charCards { gap: clamp(8px, 2vw, 18px); }
.char-card { position: relative; border: 4px solid #fff; border-top: 4px solid #fff; border-radius: 20px; background: #fff; overflow: hidden; padding: 0 0 10px; box-shadow: 0 6px 0 rgba(0,0,0,.3); transition: transform .15s; }
.char-card .cp { display: flex; justify-content: center; align-items: flex-end; height: clamp(64px, 12vh, 104px); background: linear-gradient(160deg, var(--c), color-mix(in srgb, var(--c) 40%, #fff)); clip-path: polygon(0 0, 100% 0, 100% 80%, 0 100%); margin-bottom: 6px; font-size: 44px; }
.char-card .cp img { height: 112%; width: auto; }
.char-card b { font-family: 'Bagel Fat One', 'Jua', sans-serif; color: #1b1d3a !important; }
.char-card .ck { position: absolute; top: 6px; right: 8px; width: 28px; height: 28px; border-radius: 50%; background: #fff; color: var(--c); font-style: normal; font-size: 17px; line-height: 28px; display: none; box-shadow: 0 2px 0 rgba(0,0,0,.2); }
.char-card.on { border-color: #ffd84a; transform: translateY(-10px) scale(1.05); box-shadow: 0 0 0 4px var(--c), 0 10px 0 rgba(0,0,0,.3), 0 0 26px color-mix(in srgb, var(--c) 70%, transparent); }
.char-card.on .ck { display: block; }
/* 시작 화면 일러스트 (img/title.jpg) — 천천히 다가오는 효과 */
.t-art { position: absolute; inset: 0; background: center / cover no-repeat; opacity: 0; transition: opacity .6s; pointer-events: none; }
#title.has-art .t-art { opacity: 1; animation: kenBurns 24s ease-in-out infinite alternate; }
@keyframes kenBurns { from { transform: scale(1.0); } to { transform: scale(1.08) translate(-1%, -1%); } }
#title.has-art .t-shade { background: linear-gradient(100deg, rgba(10,30,80,.45) 0%, rgba(10,30,80,.12) 36%, rgba(0,0,0,0) 55%); }
#title { overflow: hidden; }
@media (max-aspect-ratio: 1/1) { .t-art { background-position: 62% center; } #title.has-art .t-shade { background: linear-gradient(180deg, rgba(10,30,80,.55) 0%, rgba(10,30,80,.1) 42%, rgba(0,0,0,0) 55%); } }
/* 음악실 악기 (피아노 · 실로폰) */
#inst { position: absolute; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; padding: 12px 12px max(14px, env(safe-area-inset-bottom)); background: linear-gradient(transparent 30%, rgba(10,14,40,.55)); }
#inst .ib { width: min(1000px, 98vw); background: #fffdf6; border: 5px solid #fff; border-radius: 24px; box-shadow: 0 8px 0 #1b2a5c, 0 18px 40px rgba(0,0,0,.4); padding: 12px 14px 16px; font-family: 'Jua', sans-serif; animation: cardIn .3s; }
#inst .ih { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
#inst .ih b { font-family: 'Bagel Fat One', 'Jua', sans-serif; font-weight: 400; font-size: 26px; color: #1b2a5c; }
#inst .ih span { color: #6b6f86; font-size: 15px; flex: 1; }
#inst .ix { font-family: 'Jua', sans-serif; font-size: 17px; border: none; border-radius: 99px; padding: 8px 16px; background: #ffe3e3; color: #c92a2a; box-shadow: 0 3px 0 #ffa8a8; cursor: pointer; }
#inst .isong { font-size: 15px; color: #8a5a36; background: #fff3bf; border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; }
#inst .ikeys { position: relative; display: flex; height: clamp(150px, 30vh, 240px); user-select: none; -webkit-user-select: none; touch-action: none; }
#inst.piano .iw { flex: 1; position: relative; border: 2px solid #c9ced6; border-top: none; border-radius: 0 0 10px 10px; background: linear-gradient(#fff 80%, #eef0f4); margin: 0 1px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 8px; font-family: 'Jua', sans-serif; font-size: clamp(13px, 1.8vw, 18px); color: #495057; cursor: pointer; box-shadow: 0 4px 0 #c9ced6; }
#inst.piano .iw small { font-size: 11px; color: #adb5bd; }
#inst.piano .iw.on { background: linear-gradient(#ffe8a3, #ffd43b); transform: translateY(3px); box-shadow: 0 1px 0 #c9ced6; }
#inst.piano .ibk { position: absolute; top: 0; height: 60%; z-index: 2; background: linear-gradient(#3a3f47, #111); border: none; border-radius: 0 0 7px 7px; box-shadow: 0 4px 0 #000; color: #888; font-size: 10px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; cursor: pointer; }
#inst.piano .ibk.on { background: linear-gradient(#ffd43b, #f59f00); transform: translateY(2px); }
#inst.xylo .ikeys { align-items: center; gap: clamp(4px, 1vw, 10px); padding: 0 6px; background: linear-gradient(90deg, transparent, #8a5a36 2%, #8a5a36 98%, transparent) center 25% / 100% 10px no-repeat, linear-gradient(90deg, transparent, #8a5a36 2%, #8a5a36 98%, transparent) center 75% / 100% 10px no-repeat; }
#inst.xylo .iw { flex: 1; border: none; border-radius: 12px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 85%, #000), var(--c) 30%, color-mix(in srgb, var(--c) 70%, #fff) 50%, var(--c) 70%, color-mix(in srgb, var(--c) 85%, #000)); box-shadow: 0 5px 0 rgba(0,0,0,.25); display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: 'Jua', sans-serif; font-size: clamp(14px, 2vw, 20px); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.3); cursor: pointer; position: relative; }
#inst.xylo .iw::before, #inst.xylo .iw::after { content: ''; position: absolute; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: #dee2e6; box-shadow: inset 0 -2px 0 #868e96; }
#inst.xylo .iw::before { top: 8%; } #inst.xylo .iw::after { bottom: 8%; }
#inst.xylo .iw small { font-size: 11px; opacity: .8; }
#inst.xylo .iw.on { transform: translateY(4px) scale(.97); box-shadow: 0 1px 0 rgba(0,0,0,.25); filter: brightness(1.15); }
@media (max-width: 600px) { #inst .ih span { display: none; } #inst .isong { font-size: 13px; } }
