/* =====================================================================
   마법 숲 견습 마법사 — UI 스타일
   · 모바일 가로(844×390·844×344) · 세로(390×844) · 데스크톱(1440×900) 대응
   · HUD(위쪽)와 터치 조작(아래쪽)은 영역을 나눠 겹치지 않는다
   ===================================================================== */
:root {
  --bg: #070a15;
  --panel: rgba(18, 22, 44, 0.88);
  --panel-2: rgba(28, 34, 62, 0.92);
  --line: rgba(150, 172, 255, 0.22);
  --ink: #eef2ff;
  --dim: #a8b4d8;
  --mint: #7ef0c8;
  --violet: #b39dff;
  --blue: #7cc4ff;
  --gold: #ffd479;
  --pink: #ff9ecb;
  --hp: #ff6b8a;
  --mp: #6fb8ff;
  --exp: #ffd479;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  /* iPadOS Safari는 viewport의 user-scalable=no를 무시한다 — 문서 전체에서 핀치·더블탭 확대를 막고,
     세로 스크롤이 필요한 모달 영역만 아래에서 pan-y로 다시 허용한다. */
  touch-action: none;
}

/* 스크롤이 필요한 영역만 세로 스크롤 허용(확대는 계속 차단) */
.overlay, .panel, .help-body, #quiz, #quiz .quiz-panel, #quizQuestion,
.intro-choices, .quiz-choices, .result-scroll {
  touch-action: pan-y;
  -ms-touch-action: pan-y;
}

#app { position: fixed; inset: 0; overflow: hidden; }

#scene {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block; touch-action: none;
  outline: none;
}

#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 50% 46%, rgba(0,0,0,0) 52%, rgba(4, 6, 16, 0.55) 100%);
  mix-blend-mode: multiply;
}
#flash {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 55%, rgba(255, 246, 200, 0.55), rgba(255, 220, 120, 0) 62%);
  transition: opacity .18s ease-out;
}
#damage {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 60, 90, 0) 42%, rgba(255, 42, 76, 0.55) 100%);
  transition: opacity .12s ease-out;
}

.hidden { display: none !important; }

/* ============================ HUD ============================ */
#hud {
  position: absolute; inset: 0;
  pointer-events: none;
  display: flex; flex-direction: column;
  font-size: 13px;
}

.hud-top {
  display: flex; align-items: flex-start; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) 0 calc(10px + env(safe-area-inset-left, 0px));
}

.hud-card {
  background: linear-gradient(160deg, rgba(24, 28, 56, 0.9), rgba(14, 18, 38, 0.86));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.hud-card .row { display: flex; align-items: center; gap: 6px; }
.hud-card .label { color: var(--dim); font-size: 11px; letter-spacing: .04em; }

.stage-block { min-width: 168px; }
.stage-badge {
  display: inline-flex; align-items: baseline; gap: 1px;
  background: linear-gradient(135deg, rgba(126, 240, 200, .22), rgba(124, 196, 255, .18));
  border: 1px solid rgba(126, 240, 200, .45);
  border-radius: 8px; padding: 1px 7px 2px;
  font-size: 10px; color: var(--mint); letter-spacing: .08em;
}
.stage-badge b { font-size: 15px; color: #dffdf2; }
.stage-badge i { font-style: normal; opacity: .7; }
.stage-name { font-size: 12px; font-weight: 700; color: #dfe6ff; }
.sub { display: flex; justify-content: space-between; gap: 8px; color: var(--dim); font-size: 10.5px; margin-top: 2px; }
.sub > span { white-space: nowrap; }
.sub .chest-count { color: #ffe6a6; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* 아이템 효과 타이머 */
.buffs {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 0 calc(10px + env(safe-area-inset-left, 0px));
  width: min(48vw, 330px); pointer-events: none;
}
.buff-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 7px; border-radius: 999px; font-size: 10px; color: #e9f2ff;
  background: rgba(12, 16, 34, .8); border: 1px solid rgba(150, 172, 255, .28);
  font-variant-numeric: tabular-nums;
}
.buff-chip i { font-style: normal; font-size: 10.5px; }
.buff-chip b { font-weight: 700; }
.buff-chip.giant { color: #d9ff8a; border-color: rgba(158, 240, 122, .5); }
.buff-chip.shield { color: #a9dcff; border-color: rgba(143, 212, 255, .5); }
.buff-chip.rapid { color: #ffd9a0; border-color: rgba(255, 196, 107, .5); }
.buff-chip.magnet { color: #ffb6e0; border-color: rgba(255, 143, 208, .5); }
.buff-chip.wind { color: #9ff5d0; border-color: rgba(159, 245, 208, .5); }
.buff-chip.luck { color: #d9ffb0; border-color: rgba(158, 240, 122, .55); }
.buff-chip.freeze { color: #bfeeff; border-color: rgba(143, 228, 255, .55); }
.hud-extra { opacity: .55; }

.bar {
  position: relative; height: 7px; margin-top: 5px;
  background: rgba(6, 9, 20, 0.75);
  border: 1px solid rgba(150, 172, 255, .18);
  border-radius: 999px; overflow: hidden;
}
.bar i {
  display: block; height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--mint), var(--blue));
  transition: width .18s ease-out;
}
.bar.thin { height: 5px; }
.bar.exp i { background: linear-gradient(90deg, #ffb46b, var(--gold)); }
.bar.hp-bar { height: 10px; margin-top: 0; flex: 1; }
.bar.hp-bar i { background: linear-gradient(90deg, #ff7d7d, var(--hp)); }
.bar.mp-bar { height: 10px; margin-top: 0; flex: 1; }
.bar.mp-bar i { background: linear-gradient(90deg, #63e2ff, var(--mp)); }
.bar.boss { height: 12px; margin-top: 4px; border-color: rgba(255, 130, 170, .4); }
.bar.boss i { background: linear-gradient(90deg, #ff5a86, #ff9d5c); }

.level-block { min-width: 132px; }
.level-block .lvl {
  font-weight: 800; font-size: 12px; color: var(--gold);
  background: rgba(255, 212, 121, .12); border: 1px solid rgba(255, 212, 121, .35);
  border-radius: 7px; padding: 0 6px; letter-spacing: .02em;
}
.weapon-line { display: flex; align-items: center; gap: 4px; margin-top: 3px; font-size: 10.5px; color: #e6dcff; white-space: nowrap; }
.weapon-line span:first-child { font-size: 12px; }

.hud-actions {
  margin-left: auto; display: flex; gap: 5px; pointer-events: auto;
}
.hud-actions .btn.icon {
  width: 34px; height: 34px; padding: 0; border-radius: 10px;
  font-size: 15px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(20, 24, 48, .82); border: 1px solid var(--line); color: var(--ink);
}
.hud-actions .btn.icon.bgm { font-size: 9.5px; letter-spacing: .04em; font-weight: 700; }
.hud-actions .btn.icon.fs { width: auto; min-width: 34px; padding: 0 7px; gap: 4px; font-size: 10px; }
.hud-actions .btn.icon:active { transform: translateY(1px); }
.hud-actions .btn.icon[aria-pressed="true"] { border-color: rgba(126, 240, 200, .55); color: var(--mint); }

.hud-vitals {
  display: flex; flex-direction: column; gap: 5px;
  margin: 6px 0 0 calc(10px + env(safe-area-inset-left, 0px));
  width: min(48vw, 330px);
  pointer-events: none;
}.vital {
  display: flex; align-items: center; gap: 6px;
  background: rgba(12, 16, 34, .72);
  border: 1px solid rgba(150, 172, 255, .16);
  border-radius: 10px; padding: 4px 8px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.vital .vk { font-size: 9.5px; letter-spacing: .06em; color: var(--dim); min-width: 20px; }
.vital .vv { font-size: 11.5px; font-variant-numeric: tabular-nums; color: #e9eeff; min-width: 26px; text-align: right; }
.vital .vv.gold { color: var(--gold); min-width: 34px; }
.gold-vital { gap: 8px; }

/* 목숨 — ❤️ 7/7 */
.lives-vital { gap: 5px; }
.lives-hearts { display: flex; gap: 1px; font-size: 10px; line-height: 1; flex: 1; min-width: 0; overflow: hidden; }
.lives-hearts .heart { color: rgba(255, 150, 175, .28); }
.lives-hearts .heart.on { color: #ff7d9c; text-shadow: 0 0 6px rgba(255, 90, 130, .55); }
.vital .vv.lives { color: #ffc0ce; min-width: 34px; }
.lives-vital.low { border-color: rgba(255, 110, 140, .55); animation: livesPulse .9s ease-in-out infinite; }
@keyframes livesPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 90, 130, 0); }
  50% { box-shadow: 0 0 10px rgba(255, 90, 130, .35); }
}
.skill-chip {
  margin-left: auto; font-size: 10px; color: #ffe6a6;
  border: 1px solid rgba(255, 212, 121, .35); background: rgba(255, 212, 121, .1);
  padding: 1px 7px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
.skill-chip.full { color: #241300; background: linear-gradient(90deg, #ffd479, #ffb0e0); border-color: transparent; font-weight: 800; animation: pulse 1s ease-in-out infinite; }

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

.boss-bar {
  position: absolute; left: 50%; bottom: calc(118px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  width: min(46vw, 420px); min-width: 220px;
  background: rgba(28, 10, 24, .82); border: 1px solid rgba(255, 120, 160, .45);
  border-radius: 12px; padding: 5px 10px 8px;
  box-shadow: 0 8px 26px rgba(120, 10, 40, .45);
  pointer-events: none;
}
.boss-head { display: flex; justify-content: space-between; font-size: 11px; color: #ffd7e3; font-weight: 700; }
.boss-head #bossHpText { font-variant-numeric: tabular-nums; color: #ffb0c4; }

.skill-meter {
  position: absolute; left: 50%; bottom: 9px; transform: translateX(-50%);
  width: 58%; height: 4px; border-radius: 999px;
  background: rgba(8, 10, 22, .55); border: 1px solid rgba(255, 212, 121, .35);
  overflow: hidden; pointer-events: none;
}
.skill-meter i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #ffd479, #ff9ecb); }

/* 안내문 — 상단 가운데(좌·우 HUD 사이)의 아주 얇은 한 줄. 잠깐 떴다 부드럽게 사라진다 */
.hud-notice {
  flex: 1 1 120px; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 2px 6px 0;
  pointer-events: none;
}
.hint, .toast {
  max-width: 100%; margin: 0;
  height: 0; padding: 0 10px; border: 0 solid rgba(150, 172, 255, .22);
  border-radius: 999px; opacity: 0;
  background: rgba(9, 13, 28, .82); color: #dfe7ff;
  font-size: 11px; line-height: 1.25; letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transform: translateY(-3px);
  transition: opacity .3s ease, transform .3s ease, height .22s ease, border-width .22s ease;
}
.hint.show, .toast.show {
  opacity: 1; transform: none; height: 21px; line-height: 19px; border-width: 1px;
}

.banner {
  position: absolute; left: 50%; top: 34%; transform: translate(-50%, -10px);
  font-size: clamp(18px, 4.4vmin, 34px); font-weight: 900; letter-spacing: .04em;
  color: #fff7d9; text-shadow: 0 0 18px rgba(255, 210, 120, .75), 0 6px 24px rgba(0, 0, 0, .6);
  opacity: 0; transition: opacity .25s ease, transform .25s ease; pointer-events: none;
  text-align: center; white-space: nowrap;
}
.banner.show { opacity: 1; transform: translate(-50%, 0); }

.combo-pop {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, 0) scale(.9);
  font-size: clamp(13px, 2.6vmin, 20px); font-weight: 800; color: var(--mint);
  text-shadow: 0 0 14px rgba(126, 240, 200, .7); opacity: 0;
  transition: opacity .18s, transform .18s; pointer-events: none;
}
.combo-pop.show { opacity: 1; transform: translate(-50%, -14px) scale(1); }

/* ============================ 터치 조작 ============================ */
.touchpad {
  position: absolute; inset: 0; pointer-events: none;
  padding: 0 calc(14px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(14px + env(safe-area-inset-left, 0px));
}
.joy {
  position: absolute; left: calc(18px + env(safe-area-inset-left, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: 112px; height: 112px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(120, 150, 255, .16), rgba(10, 14, 32, .5) 70%);
  border: 1.5px solid rgba(160, 185, 255, .38);
  pointer-events: auto; touch-action: none;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .38), inset 0 0 22px rgba(120, 160, 255, .12);
}
.joy-base { position: absolute; inset: 0; }
.joy-dir { position: absolute; color: rgba(210, 222, 255, .5); font-size: 10px; }
.joy-dir.d-up { left: 50%; top: 5px; transform: translateX(-50%); }
.joy-dir.d-down { left: 50%; bottom: 5px; transform: translateX(-50%); }
.joy-dir.d-left { left: 6px; top: 50%; transform: translateY(-50%); }
.joy-dir.d-right { right: 6px; top: 50%; transform: translateY(-50%); }
.joy-knob {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px;
  margin: -24px 0 0 -24px; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #dbe6ff, #8fb2ff 55%, #5f7ad8);
  border: 1px solid rgba(255, 255, 255, .55);
  box-shadow: 0 4px 14px rgba(40, 60, 140, .55);
  transition: transform .04s linear;
}

.tp-buttons {
  position: absolute; right: calc(18px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: flex-end; gap: 10px; pointer-events: none;
}
.tbtn {
  position: relative;
  pointer-events: auto; touch-action: none;
  width: 74px; height: 74px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border: 1.5px solid rgba(255, 255, 255, .38);
  background: radial-gradient(circle at 40% 32%, rgba(255, 214, 140, .95), rgba(255, 150, 90, .85) 60%, rgba(196, 96, 60, .9));
  color: #2b1400; font-family: inherit; font-weight: 800;
  box-shadow: 0 6px 20px rgba(120, 50, 10, .45), inset 0 -3px 10px rgba(0, 0, 0, .18);
}
.tbtn .tb-ico { font-size: 22px; line-height: 1; }
.tbtn .tb-label { font-size: 10.5px; letter-spacing: .04em; }
.tbtn.attack { width: 84px; height: 84px; }
.tbtn.skill {
  width: 64px; height: 64px;
  background: radial-gradient(circle at 40% 32%, rgba(214, 190, 255, .95), rgba(150, 120, 255, .88) 60%, rgba(96, 70, 200, .92));
  color: #f4edff; border-color: rgba(220, 205, 255, .55);
}
.tbtn.skill.ready { animation: pulse 1s ease-in-out infinite; box-shadow: 0 0 22px rgba(255, 220, 140, .8), 0 6px 20px rgba(120, 60, 200, .5); }
.tbtn.on { transform: scale(.94); filter: brightness(1.12); }

body:not(.touch-device) .touchpad { display: none !important; }

/* ============================ 공통 버튼·패널 ============================ */
.btn {
  font-family: inherit; font-size: 13px; font-weight: 700;
  color: var(--ink); background: rgba(30, 36, 66, .9);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 16px; cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: rgba(40, 48, 86, .95); border-color: rgba(170, 190, 255, .4); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary {
  background: linear-gradient(135deg, #6ee7c0, #63b8ff 70%);
  color: #08121f; border-color: transparent;
  box-shadow: 0 8px 24px rgba(90, 200, 220, .28);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--dim); }
.btn.small { padding: 7px 12px; font-size: 12px; border-radius: 9px; }
.btn.big { padding: 13px 34px; font-size: 16px; border-radius: 13px; letter-spacing: .06em; }
.btn.icon { cursor: pointer; }

/* 타이틀 「▶ 이어서 하기」 — 진행 중이던 판으로 돌아가기 */
.btn.continue {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  margin: 6px auto 0; padding: 10px 26px; border-radius: 13px; font-size: 14.5px;
  background: rgba(28, 40, 72, .92); border-color: rgba(126, 240, 200, .55);
  color: #d8fff2; box-shadow: 0 6px 20px rgba(90, 200, 220, .18);
}
.btn.continue small { font-size: 10.5px; font-weight: 600; color: var(--mint); letter-spacing: .02em; }
.btn.continue:hover { border-color: rgba(126, 240, 200, .85); background: rgba(34, 50, 86, .96); }

kbd {
  font-family: inherit; font-size: 10px; padding: 1px 5px; border-radius: 4px;
  background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .22);
  margin-left: 3px;
}

.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: radial-gradient(circle at 50% 30%, rgba(30, 20, 70, .82), rgba(5, 7, 16, .94) 72%);
  z-index: 20;
  overflow: auto;
}
.panel {
  background: linear-gradient(165deg, rgba(26, 30, 60, .96), rgba(12, 16, 34, .97));
  border: 1px solid rgba(150, 172, 255, .28);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .06);
  max-width: 560px; width: 100%;
}
.panel.narrow { max-width: 420px; }
.panel.wide { max-width: 640px; }
.panel-title { margin: 0 0 6px; font-size: 20px; letter-spacing: .02em; }
.panel-sub { margin: 0 0 12px; color: var(--dim); font-size: 12.5px; line-height: 1.55; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.panel-actions .btn { flex: 1 1 auto; min-width: 110px; text-align: center; }

/* ============================ 타이틀 ============================ */
.title-screen {
  background:
    radial-gradient(circle at 50% 20%, rgba(140, 110, 240, .3), rgba(5, 7, 18, 0) 58%),
    linear-gradient(180deg, rgba(6, 9, 22, .52), rgba(6, 9, 22, .84) 62%, rgba(6, 9, 22, .92));
  overflow: auto;
}
.title-inner {
  width: 100%; max-width: 640px; text-align: center;
  padding: 10px 4px 24px;
}
.eyebrow {
  margin: 0 0 4px; font-size: 10.5px; letter-spacing: .22em; color: var(--mint);
  text-transform: uppercase;
}
.game-title {
  margin: 0; font-size: clamp(30px, 6.4vmin, 54px); line-height: 1.08;
  letter-spacing: -.01em; text-shadow: 0 0 26px rgba(170, 140, 255, .5), 0 8px 30px rgba(0, 0, 0, .5);
}
.game-title span {
  background: linear-gradient(100deg, #ffe9a8, #ffb3e2 55%, #a9c8ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.title-en {
  margin: 4px 0 0; font-size: 10.5px; letter-spacing: .5em; color: rgba(200, 214, 255, .6);
}
.title-inner .sub {
  display: block; margin: 12px auto 0; font-size: 12.5px; line-height: 1.65;
  color: #c9d5f5; max-width: 520px; word-break: keep-all;
}
.title-inner .sub b { color: #ffe9a8; }

/* 첫 화면 아래 버튼 — 조작법 · 옵션 · 전체화면 */
.title-actions {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin: 14px auto 0; max-width: 470px;
}
.title-actions .btn { padding: 9px 14px; font-size: 12.5px; }

.settings {
  margin: 16px auto 0; max-width: 470px;
  background: rgba(12, 16, 34, .6); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px;
}
.setting-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-row + .setting-row { margin-top: 10px; }
.setting-label { font-size: 11px; color: var(--dim); letter-spacing: .04em; min-width: 74px; text-align: left; }
.setting-actions { display: flex; gap: 8px; margin-left: auto; }
.segmented {
  display: inline-flex; gap: 3px; padding: 3px;
  background: rgba(6, 9, 22, .8); border: 1px solid var(--line); border-radius: 10px;
}
.segmented button {
  font-family: inherit; font-size: 12px; font-weight: 700; color: var(--dim);
  background: transparent; border: 0; border-radius: 7px; padding: 6px 14px; cursor: pointer;
}
.segmented button.active { background: linear-gradient(135deg, rgba(126, 240, 200, .9), rgba(124, 196, 255, .9)); color: #06121c; }
.segmented.tiny button { padding: 4px 10px; font-size: 11px; }
.diff-hint { margin: 6px 0 0; font-size: 10.5px; color: var(--dim); text-align: left; }

.stage-list { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 14px 0 0; }
.stage-chip {
  display: flex; align-items: center; gap: 5px;
  font-size: 10.5px; color: #cfd9f7;
  background: rgba(20, 24, 48, .8); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px 4px 5px;
}
.stage-chip b {
  width: 17px; height: 17px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; background: rgba(126, 240, 200, .22); color: var(--mint);
}
.stage-chip.s2 b { background: rgba(180, 150, 255, .24); color: #cbb9ff; }
.stage-chip.s3 b { background: rgba(124, 196, 255, .24); color: #a6dcff; }
.stage-chip.s4 b { background: rgba(255, 140, 170, .24); color: #ffb0c4; }

#btnStart { margin-top: 16px; }
.status { margin: 8px 0 0; font-size: 11.5px; color: var(--dim); }
.status.best { color: var(--gold); }

/* ============================ 조작법 · 게임 안내 ============================ */
#help { z-index: 26; }
.help-panel {
  max-width: 780px; padding: 14px 18px 12px;
  display: flex; flex-direction: column; max-height: calc(100% - 10px);
}
.help-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.help-head .panel-title { margin: 0; font-size: 17px; }
.help-body { margin-top: 10px; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.help-card {
  background: rgba(10, 14, 30, .66); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 11px;
}
.help-card h3 { margin: 0 0 5px; font-size: 12.5px; color: #ffe9a8; letter-spacing: .01em; }
.help-card ul { margin: 0; padding-left: 14px; }
.help-card li { margin-top: 3px; font-size: 11.5px; line-height: 1.5; color: #c9d5f5; word-break: keep-all; }
.help-card li b { color: #fff2c9; }
.help-card .stage-list { margin: 4px 0 0; justify-content: flex-start; }
.help-note { margin: 8px 0 0; font-size: 11px; color: var(--dim); }
.help-foot { display: flex; justify-content: flex-end; margin-top: 10px; }
.help-foot .btn { min-width: 130px; }

/* ============================ 퀴즈 ============================ */
#quiz { z-index: 30; background: rgba(4, 6, 16, .72); }
.quiz-panel { max-width: 720px; padding: 16px 18px 14px; display: flex; flex-direction: column; max-height: 100%; }
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.tag {
  font-size: 10.5px; letter-spacing: .06em; color: var(--mint);
  background: rgba(126, 240, 200, .12); border: 1px solid rgba(126, 240, 200, .35);
  border-radius: 999px; padding: 2px 9px; white-space: nowrap;
}
.quiz-reason { font-size: 10.5px; color: var(--dim); white-space: nowrap; }
#quizQuestion {
  margin: 2px 0 8px; font-size: clamp(17px, 3.1vmin + 6px, 29px)!important;
  line-height: 1.4; letter-spacing: -.01em; word-break: keep-all;
  white-space: pre-line;            /* 〈보기〉가 있으면 줄을 나눠 보여 준다 */
  flex: 0 1 auto; min-height: 0; overflow-y: auto;
}
/* 긴 문제(〈보기〉 포함) — 글자를 조금 줄여 모바일 가로에서도 한눈에 들어오게 */
#quiz.q-long #quizQuestion { font-size: clamp(16px, 2.6vmin + 5px, 24px)!important; }
.quiz-guard { margin: 0 0 8px; }
.qg-track { height: 5px; border-radius: 999px; background: rgba(8, 11, 24, .85); overflow: hidden; border: 1px solid rgba(150, 172, 255, .2); }
.qg-track i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ffd479, #ff9ecb); transform-origin: left center; }
.qg-label { display: block; margin-top: 3px; font-size: 10px; color: var(--dim); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: 0 0 auto; }
.choice {
  font-family: inherit; text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 9px;
  background: rgba(22, 27, 52, .92); color: var(--ink);
  border: 1.5px solid rgba(150, 172, 255, .26); border-radius: 12px;
  padding: 10px 12px;
  font-size: clamp(16px, 2.5vmin + 8px, 21px); line-height: 1.35;
  transition: background .12s, border-color .12s, transform .08s;
  word-break: keep-all;
}
.choice .num {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: #06121c;
  background: linear-gradient(135deg, #9ef0d0, #8ecbff);
}
.choice:hover:not(:disabled) { background: rgba(34, 42, 78, .95); border-color: rgba(180, 200, 255, .5); }
.choice:disabled { cursor: default; opacity: .92; }
.choice.correct { border-color: #6ef0b0; background: rgba(30, 90, 70, .92); box-shadow: 0 0 0 2px rgba(110, 240, 176, .25) inset; }
.choice.wrong { border-color: #ff7d9b; background: rgba(96, 28, 46, .92); }
.choice.dim { opacity: .5; }

.feedback { margin-top: 10px; border-top: 1px solid rgba(150, 172, 255, .18); padding-top: 9px; flex: 0 0 auto; }
.fb-title { font-size: 15px; font-weight: 900; letter-spacing: .02em; margin-bottom: 3px; }
.fb-title.ok { color: #7ef0c8; }
.fb-title.no { color: #ff9eb3; }
.feedback p { margin: 0 0 8px; font-size: 12.5px; line-height: 1.6; color: #cfd9f7; word-break: keep-all; }
#btnContinue { width: 100%; }

/* ============================ 일시정지·옵션 ============================ */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 2px; }
.mini-stat {
  background: rgba(10, 14, 30, .7); border: 1px solid var(--line); border-radius: 11px;
  padding: 8px; text-align: center;
}
.mini-stat span { display: block; font-size: 10px; color: var(--dim); }
.mini-stat b { font-size: 15px; color: #ffe9a8; }

.opt-list { display: flex; flex-direction: column; gap: 9px; }
.opt-row { display: flex; align-items: center; gap: 10px; }
.opt-label { font-size: 12px; color: #cfd9f7; min-width: 84px; }
.opt-row input[type="range"] { flex: 1; accent-color: #7ef0c8; height: 18px; }
.opt-val { font-size: 11.5px; color: var(--dim); min-width: 26px; text-align: right; font-variant-numeric: tabular-nums; }
.toggle {
  font-family: inherit; font-size: 11.5px; font-weight: 800; cursor: pointer;
  color: var(--dim); background: rgba(10, 14, 30, .8);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px;
}
.toggle.on { color: #06121c; background: linear-gradient(135deg, #7ef0c8, #8ecbff); border-color: transparent; }

/* ============================ 스테이지 카드 ============================ */
.stage-card {
  position: absolute; inset: 0; z-index: 15;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 50%, rgba(20, 30, 70, .55), rgba(4, 6, 16, .9));
  pointer-events: none; text-align: center;
  animation: cardIn .4s ease-out;
}
@keyframes cardIn { from { opacity: 0; } to { opacity: 1; } }
.sc-en { margin: 0; font-size: 11px; letter-spacing: .4em; color: var(--mint); }
.sc-num { font-size: clamp(64px, 17vmin, 130px); font-weight: 900; line-height: 1; color: #fff; text-shadow: 0 0 40px rgba(160, 130, 255, .7); }
.sc-name { margin: 2px 0 0; font-size: clamp(20px, 4.4vmin, 34px); letter-spacing: .02em; }
.sc-desc { margin: 6px 0 0; font-size: 12.5px; color: #c9d5f5; }

/* ============================ 결과 ============================ */
#result { z-index: 40; }
.result-glow {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 50% 40%, rgba(255, 220, 140, .22), rgba(5, 7, 16, 0) 60%);
}
.result-panel { position: relative; }
.result-title {
  margin: 2px 0 4px; font-size: clamp(34px, 8vmin, 62px); letter-spacing: .02em;
  background: linear-gradient(100deg, #ffe9a8, #ffb3e2 55%, #a9c8ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(255, 220, 150, .35);
}
#result.lost .result-title { background: linear-gradient(100deg, #ffb0c4, #cbb9ff); -webkit-background-clip: text; background-clip: text; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 10px; }
.stat {
  background: rgba(10, 14, 30, .72); border: 1px solid var(--line); border-radius: 11px;
  padding: 7px 8px; text-align: center;
}
.stat span { display: block; font-size: 9.5px; color: var(--dim); letter-spacing: .02em; }
.stat b { display: block; margin-top: 2px; font-size: 14px; color: #eaf0ff; }
.stat.hi b { color: #ffe9a8; }
.result-actions { margin-top: 16px; }
.result-actions .btn { flex: 1 1 0; }
.result-hint { margin: 10px 0 0; text-align: center; font-size: 10.5px; color: var(--dim); }

/* ============================ 인트로(프롤로그) ============================ */
#intro {
  position: absolute; inset: 0; z-index: 35;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 0;
  overflow: hidden;
}
.intro-veil {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(6, 8, 18, .35) 0%, rgba(6, 8, 18, .55) 45%, rgba(4, 5, 12, .88) 100%);
}
.intro-skip {
  position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: 12px; z-index: 3;
  display: flex; align-items: center; gap: 4px;
  padding: 6px 11px; border-radius: 999px; cursor: pointer;
  font: 700 12px/1 var(--font); color: #dfe6ff;
  background: rgba(12, 16, 32, .72); border: 1px solid rgba(170, 185, 255, .35);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .35);
}
.intro-skip:hover { background: rgba(26, 32, 58, .9); }
.intro-stage {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 0 clamp(10px, 2.6vw, 26px) calc(14px + env(safe-area-inset-bottom, 0px));
  cursor: pointer;
}
.intro-dialogbox {
  width: min(780px, 96vw);
  display: flex; align-items: flex-start; gap: clamp(9px, 1.6vmin, 16px);
  padding: clamp(10px, 1.7vmin, 18px) clamp(12px, 2vmin, 20px);
  background: linear-gradient(180deg, rgba(20, 25, 50, .96), rgba(9, 12, 26, .98));
  border: 1px solid rgba(160, 140, 255, .42);
  border-radius: 16px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .07);
}
.intro-dialogbox.in { animation: introIn .22s ease-out; }
@keyframes introIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.intro-portrait {
  flex: 0 0 auto;
  width: clamp(42px, 6.6vmin, 72px); height: clamp(42px, 6.6vmin, 72px);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(24px, 4.2vmin, 42px); line-height: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, rgba(255, 238, 180, .28), rgba(90, 80, 160, .22) 70%);
  border: 1px solid rgba(255, 233, 168, .45);
  box-shadow: 0 0 22px rgba(180, 150, 255, .25) inset;
}
.intro-portrait[data-who="hero"] { border-color: rgba(140, 210, 255, .55); }
.intro-portrait[data-who="master"] { border-color: rgba(200, 170, 255, .55); }
.intro-copy { flex: 1 1 auto; min-width: 0; }
.intro-speaker {
  margin: 0 0 4px; font-size: clamp(12px, 1.8vmin, 16px); font-weight: 800;
  color: #ffe9a8; letter-spacing: .02em;
}
.intro-line {
  margin: 0; font-size: clamp(15px, 2.7vmin, 23px); line-height: 1.45;
  color: #eef3ff; word-break: keep-all; text-wrap: pretty;
}
.intro-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: clamp(6px, 1.2vmin, 12px);
}
.intro-dots { display: flex; gap: 5px; align-items: center; }
.intro-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(200, 210, 255, .3); }
.intro-dots i.on { background: #ffe9a8; box-shadow: 0 0 8px rgba(255, 233, 168, .75); }
.intro-next {
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  font: 800 13px/1 var(--font); color: #06101a;
  background: linear-gradient(100deg, var(--mint), #9fd8ff); border: 0;
  box-shadow: 0 6px 18px rgba(120, 240, 200, .25);
}
.intro-next:active { transform: translateY(1px); }
/* 선택지 — 대답에 따라 후속 대사와 성향 보너스가 달라진다 */
.intro-choices { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: clamp(7px, 1.4vmin, 11px); }
.intro-choice {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: clamp(8px, 1.3vmin, 12px) clamp(10px, 1.6vmin, 14px);
  border-radius: 12px; cursor: pointer;
  font: 700 clamp(14px, 2.1vmin, 17px)/1.3 var(--font); color: #eef3ff;
  background: linear-gradient(100deg, rgba(62, 52, 116, .82), rgba(28, 34, 66, .9));
  border: 1px solid rgba(160, 150, 255, .45);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .28);
  transition: transform .12s ease-out, border-color .12s ease-out, background .12s ease-out;
}
.intro-choice:hover, .intro-choice:focus-visible {
  border-color: rgba(255, 233, 168, .85);
  background: linear-gradient(100deg, rgba(92, 74, 150, .9), rgba(38, 46, 86, .95));
  transform: translateX(2px);
}
.intro-choice .ic { font-size: 1.15em; line-height: 1; }
.intro-choice .lb { flex: 1 1 auto; }
.intro-choice .tip { font-size: 10.5px; font-weight: 800; color: #9fe8c8; white-space: nowrap; }

.intro-tap {
  margin: 0; font-size: clamp(10px, 1.5vmin, 12px); color: rgba(214, 222, 245, .62);
}

/* ============================ 엔딩 스토리 ============================ */
/* 최종 보스 격파 → 점수 화면 전에 나오는 2컷 에필로그. 화면 어디를 눌러도 넘어간다. */
#ending {
  position: absolute; inset: 0; z-index: 37;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0 clamp(10px, 2.4vw, 24px);
  cursor: pointer; overflow: hidden;
}
.ending-veil {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 50% 36%, rgba(120, 96, 220, .3), rgba(5, 6, 14, .9) 62%), rgba(4, 5, 12, .5);
}
.ending-stage {
  position: relative; z-index: 2; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: clamp(5px, 1.1vh, 11px);
}
.ending-panel {
  width: min(640px, 94vw);
  max-height: 88vh;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: clamp(10px, 2.2vmin, 20px) clamp(12px, 2.6vmin, 24px);
  background: linear-gradient(180deg, rgba(26, 28, 62, .97), rgba(9, 11, 26, .98));
  border: 1px solid rgba(190, 170, 255, .45);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .08), 0 0 42px rgba(180, 150, 255, .18);
  overflow: hidden;
}
.ending-panel.in { animation: endingIn .26s ease-out; }
@keyframes endingIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.ending-eyebrow {
  margin: 0 0 clamp(4px, .8vmin, 8px); font-size: clamp(9.5px, 1.5vmin, 11.5px);
  letter-spacing: .34em; color: var(--mint);
}
.ending-art {
  flex: 0 0 auto;
  width: clamp(44px, 10vmin, 76px); height: clamp(44px, 10vmin, 76px);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(26px, 6.4vmin, 40px); line-height: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 34%, rgba(255, 238, 180, .32), rgba(104, 88, 190, .26) 72%);
  border: 1px solid rgba(255, 233, 168, .5);
  box-shadow: 0 0 26px rgba(180, 150, 255, .28) inset, 0 0 18px rgba(255, 220, 150, .18);
}
.ending-title {
  margin: clamp(5px, 1vmin, 9px) 0 0;
  font-size: clamp(19px, 3.3vmin, 29px); letter-spacing: .01em; line-height: 1.25;
  color: #f3f7ff; text-shadow: 0 0 22px rgba(180, 150, 255, .35);
}
.ending-text {
  margin: clamp(5px, 1vmin, 10px) 0 0;
  font-size: clamp(16px, 2.5vmin, 20px); line-height: 1.5; color: #dfe8ff;
  word-break: keep-all; text-wrap: pretty;
}
.ending-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; margin-top: clamp(8px, 1.6vmin, 15px);
}
.ending-dots { display: flex; gap: 5px; align-items: center; }
.ending-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(200, 210, 255, .3); }
.ending-dots i.on { background: #ffe9a8; box-shadow: 0 0 8px rgba(255, 233, 168, .75); }
.ending-next {
  padding: 7px 15px; border-radius: 999px; cursor: pointer;
  font: 800 13px/1 var(--font); color: #06101a;
  background: linear-gradient(100deg, var(--mint), #9fd8ff); border: 0;
  box-shadow: 0 6px 18px rgba(120, 240, 200, .25);
}
.ending-next:active { transform: translateY(1px); }
.ending-tap { margin: 0; font-size: clamp(10px, 1.5vmin, 12px); color: rgba(214, 222, 245, .6); }

@media (max-height: 520px) {
  .ending-panel { padding: 9px 14px; border-radius: 14px; }
  .ending-art { width: 40px; height: 40px; font-size: 24px; }
  .ending-title { font-size: 18px; margin-top: 4px; }
  .ending-text { font-size: 16px; margin-top: 4px; line-height: 1.4; }
  .ending-foot { margin-top: 6px; }
  .ending-eyebrow { margin-bottom: 3px; }
  .ending-tap { display: none; }
}

/* ============================ 반응형 ============================ */
/* 낮은 화면(가로 모드 폰) — 세로 여백을 줄여 퀴즈·결과가 잘리지 않게 */
@media (max-height: 520px) {
  .quiz-panel { padding: 10px 14px 8px; max-width: 760px; }
  #quizQuestion { font-size: clamp(19px, 5vmin, 26px)!important; margin: 0 0 5px; line-height: 1.3; }
  .quiz-head { margin-bottom: 4px; }
  .quiz-guard { margin-bottom: 5px; }
  .choices { gap: 6px; }
  .choice { padding: 8px 10px; font-size: clamp(17px, 4.4vmin, 20px); }
  .feedback { margin-top: 7px; padding-top: 6px; }
  .feedback p { font-size: 11.5px; margin-bottom: 6px; }
  .fb-title { font-size: 13.5px; }
  /* 〈보기〉 포함 긴 문제 — 낮은 화면에서도 해설까지 한 화면에 들어오게 여백을 더 줄인다 */
  #quiz.q-long #quizQuestion { line-height: 1.24; margin-bottom: 4px; }
  #quiz.q-long .feedback { margin-top: 6px; padding-top: 5px; }
  #quiz.q-long .feedback p { margin-bottom: 4px; }
  #quiz.q-long .qg-label { display: none; }
  .panel { padding: 14px 16px; }
  .result-title { font-size: clamp(28px, 9vmin, 44px); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 6px; }
  .stat { padding: 5px 6px; }
  .stat b { font-size: 12px; }
  .stat span { font-size: 9px; }
  .panel-sub { margin-bottom: 8px; font-size: 11.5px; }
  .result-actions { margin-top: 10px; }
  .result-hint { display: none; }
  .title-inner { max-width: 720px; }
  .game-title { font-size: clamp(24px, 7.2vmin, 40px); }
  .title-inner .sub { font-size: 11.5px; margin-top: 8px; }
  .settings { margin-top: 10px; padding: 9px 12px; }
  .stage-list { margin-top: 10px; }
  #btnStart { margin-top: 10px; padding: 10px 28px; }
  .boss-bar { bottom: calc(6px + env(safe-area-inset-bottom, 0px)); width: min(46vw, 380px); }
  .sc-num { font-size: clamp(52px, 15vmin, 90px); }
  .joy { width: 100px; height: 100px; }
  .joy-knob { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  .tbtn { width: 66px; height: 66px; }
  .tbtn.attack { width: 74px; height: 74px; }
  .tbtn.skill { width: 58px; height: 58px; }
  /* 인트로 — 낮은 가로 화면에서 대화창이 화면을 넘지 않게 */
  .intro-stage { gap: 4px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .intro-dialogbox { padding: 8px 12px; border-radius: 13px; gap: 9px; }
  .intro-portrait { width: 40px; height: 40px; font-size: 24px; }
  .intro-speaker { font-size: 11.5px; margin-bottom: 2px; }
  .intro-line { font-size: 16px; line-height: 1.38; }
  .intro-foot { margin-top: 5px; }
  .intro-next { padding: 6px 12px; font-size: 12px; }
  .intro-skip { padding: 5px 9px; font-size: 11px; }
  /* 선택지는 가로 3컬럼으로 — 낮은 화면에서도 화면을 넘지 않게 */
  .intro-choices { grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 6px; }
  .intro-choice { flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 8px; font-size: 12.5px; border-radius: 10px; }
  .intro-choice .ic { font-size: 15px; }
  .intro-choice .tip { display: none; }
}

/* 아주 낮은 화면(844×344 — 주소창 있는 가로 모드) */
@media (max-height: 370px) {
  /* 긴 문제(〈보기〉·긴 선지) — 해설과 「계속하기」까지 한 화면에 들어오게 여백을 최소로 */
  #quiz.q-long .quiz-panel { padding: 6px 12px 5px; }
  #quiz.q-long .quiz-reason { display: none; }
  #quiz.q-long .choices { gap: 4px; }
  #quiz.q-long .choice { padding: 5px 8px; }
  #quiz.q-long .feedback { margin-top: 4px; padding-top: 3px; }
  #quiz.q-long .fb-title { font-size: 12.5px; margin-bottom: 2px; }
  #quiz.q-long .feedback p { font-size: 11px; line-height: 1.35; margin-bottom: 3px; }
  #quiz.q-long #btnContinue { padding: 6px 10px; font-size: 14px; }
  .joy { width: 88px; height: 88px; }
  .joy-knob { width: 38px; height: 38px; margin: -19px 0 0 -19px; }
  .tbtn { width: 58px; height: 58px; }
  .tbtn.attack { width: 66px; height: 66px; }
  .tbtn.skill { width: 52px; height: 52px; }
  .tbtn .tb-ico { font-size: 18px; }
  .tbtn .tb-label { font-size: 9px; }
  .boss-bar { bottom: calc(6px + env(safe-area-inset-bottom, 0px)); width: min(48vw, 340px); }
  .choice { padding: 6px 9px; }
  .results .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* =====================================================================
   가로 모드 폰(844×390 · 844×344) — HUD를 최대한 얇게
   · 좌측 상태바: 폭 35% 이내 · 높이 화면의 18~22% 이내(실측 ~14%)
   · 스테이지·레벨/무기는 각각 1줄, HP·MP·골드·필살은 나란히 1줄
   ===================================================================== */
@media (max-height: 540px) {
  .hud-top {
    gap: 4px;
    padding: calc(5px + env(safe-area-inset-top, 0px)) calc(8px + env(safe-area-inset-right, 0px)) 0 calc(8px + env(safe-area-inset-left, 0px));
  }
  .hud-card {
    padding: 2px 7px 3px; border-radius: 9px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .32);
  }
  .hud-card .row { gap: 5px; }

  /* 스테이지 — 얕은 1줄, 진행 바는 카드 밑변에 2px */
  .stage-block {
    min-width: 0; display: flex; flex-wrap: wrap; align-items: center;
    column-gap: 6px; padding-bottom: 6px;
  }
  .stage-block .row { flex: 0 0 auto; }
  .stage-block .sub { order: 2; flex: 0 0 auto; margin: 0; font-size: 9.5px; gap: 6px; justify-content: flex-start; }
  .stage-block .bar.thin { order: 3; flex: 1 1 100%; height: 2px; margin: 3px 0 0; border: 0; }
  .stage-badge { padding: 0 5px 1px; border-radius: 6px; font-size: 8.5px; gap: 0; }
  .stage-badge b { font-size: 12px; }
  .stage-name { font-size: 11px; }

  /* 레벨·무기 — 얕은 1줄, 경험치 바는 카드 밑변에 2px */
  .level-block {
    min-width: 0; display: flex; flex-wrap: wrap; align-items: center;
    column-gap: 5px; padding-bottom: 6px;
  }
  .level-block .row { flex: 0 0 auto; }
  .level-block .label { display: none; }
  .level-block .lvl { font-size: 10.5px; padding: 0 4px; border-radius: 6px; }
  .level-block .weapon-line { order: 2; margin: 0; gap: 3px; font-size: 10px; }
  .level-block .weapon-line span:first-child { font-size: 10.5px; }
  .level-block .bar.exp { order: 3; flex: 1 1 100%; height: 2px; margin: 3px 0 0; border: 0; }

  /* HP · MP · 골드 · 필살 — 나란히 1줄 */
  .hud-vitals {
    flex-direction: row; align-items: stretch; gap: 4px;
    width: min(35vw, 292px);
    margin: 4px 0 0 calc(8px + env(safe-area-inset-left, 0px));
  }
  .vital { flex: 1 1 0; min-width: 0; padding: 1px 6px; gap: 4px; border-radius: 8px; }
  .vital .vk { min-width: 0; font-size: 8.5px; letter-spacing: 0; }
  .vital .vv { min-width: 16px; font-size: 10px; }
  .vital .vv.gold { min-width: 20px; }
  .bar.hp-bar, .bar.mp-bar { height: 5px; }
  .gold-vital { flex: 0 0 auto; gap: 4px; }
  .gold-vital .skill-chip { margin-left: 0; padding: 0 5px; font-size: 8.5px; }
  /* 목숨 — 가로로 얕은 화면에서는 ‘7/7’ 숫자만 */
  .lives-vital { flex: 0 0 auto; gap: 3px; }
  .lives-vital .lives-hearts { display: none; }
  .vital .vv.lives { min-width: 24px; font-size: 10px; }

  /* 아이템 효과 칩 — 한 줄로 얇게 */
  .buffs { gap: 3px; margin: 3px 0 0 calc(8px + env(safe-area-inset-left, 0px)); width: auto; }
  .buff-chip { padding: 0 5px; font-size: 8.5px; gap: 2px; }
  .buff-chip i { font-size: 9px; }

  /* 우측 상단 버튼 — 살짝 콤팩트 */
  .hud-actions { gap: 4px; }
  .hud-actions .btn.icon { width: 30px; height: 30px; font-size: 13px; border-radius: 9px; }
  .hud-actions .btn.icon.bgm { font-size: 8.5px; }
  .hud-actions .btn.icon.fs { min-width: 30px; padding: 0 5px; gap: 3px; font-size: 9px; }
  .hud-actions .btn.icon.fs .fs-txt { display: none; }

  /* 안내문 — 더 얇고 작은 글씨 */
  .hud-notice { padding: 1px 6px 0; }
  .hint, .toast { font-size: 10px; }
  .hint.show, .toast.show { height: 19px; line-height: 17px; }

  /* 첫 화면 · 조작법 — 낮은 가로 화면에 맞게 */
  .title-actions { margin-top: 10px; gap: 6px; }
  .title-actions .btn { padding: 7px 12px; font-size: 12px; }
  .help-panel { max-width: 800px; padding: 10px 14px; }
  .help-body { margin-top: 7px; }
  .help-grid { gap: 6px; }
  .help-card { padding: 7px 9px; }
  .help-card h3 { margin-bottom: 3px; font-size: 11.5px; }
  .help-card li { margin-top: 2px; font-size: 10.5px; line-height: 1.45; }
  .help-card .stage-list { margin-top: 2px; }
  .help-note { margin-top: 5px; font-size: 10px; }
  .help-foot { display: none; }
}

/* 좁은 화면(세로 폰) — HUD 두 줄 배치, 퀴즈 선지는 한 줄에 하나 */
@media (max-width: 560px) {
  .hud-top { flex-wrap: wrap; gap: 6px; }
  .stage-block { min-width: 0; flex: 1 1 132px; }
  .level-block { min-width: 0; flex: 0 0 auto; }
  .hud-actions { order: 4; margin-left: 0; }
  .hud-actions .btn.icon.bgm { display: none; }
  .hud-actions .btn.icon { width: 30px; height: 30px; font-size: 13px; }
  .hud-actions .btn.icon.fs { padding: 0 5px; }
  .hud-actions .btn.icon.fs .fs-txt { display: none; }
  .hud-vitals { width: calc(100% - 20px); max-width: none; flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .hud-vitals .vital { flex: 1 1 45%; }
  /* 목숨은 숫자만 — HP와 한 줄을 나눠 쓰고, 골드·필살은 남은 자리에 */
  .hud-vitals .lives-vital { flex: 0 0 auto; }
  .hud-vitals .gold-vital { flex: 1 1 auto; }
  .choices { grid-template-columns: 1fr; gap: 7px; }
  .choice { padding: 11px 12px; }
  .stage-list { gap: 5px; }
  .stage-chip { font-size: 9.5px; padding: 3px 8px 3px 4px; }
  .game-title { font-size: clamp(28px, 9vw, 40px); }
  /* 인트로 — 세로 폰에서 글자가 잘리지 않게 */
  .intro-dialogbox { width: 100%; gap: 10px; padding: 12px 13px; }
  .intro-portrait { width: 46px; height: 46px; font-size: 27px; }
  .intro-line { font-size: clamp(16px, 4.6vw, 21px); line-height: 1.45; }
  /* 선택지는 한 줄에 하나 — 보너스 안내는 선택지 이름 밑으로 */
  .intro-choice {
    display: grid; grid-template-columns: auto 1fr; grid-template-areas: "ic lb" ". tip";
    align-items: center; column-gap: 8px; row-gap: 2px;
  }
  .intro-choice .ic { grid-area: ic; }
  .intro-choice .lb { grid-area: lb; }
  .intro-choice .tip { grid-area: tip; white-space: normal; font-size: 10.5px; }
  .setting-label { min-width: 0; }
  .segmented button { padding: 6px 11px; font-size: 11.5px; }
  .boss-bar { bottom: calc(178px + env(safe-area-inset-bottom, 0px)); width: calc(100% - 28px); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .title-inner .sub .br-desk { display: none; }
  .joy { width: 104px; height: 104px; }
  .tbtn { width: 70px; height: 70px; }
  .tbtn.attack { width: 78px; height: 78px; }
  .tbtn.skill { width: 60px; height: 60px; }
  /* 안내문은 상단 HUD 아래 한 줄 */
  .hud-notice { order: 3; flex: 1 1 160px; min-width: 0; padding: 4px 4px 0 0; align-items: flex-end; }
  .hint, .toast { font-size: 10px; }
  /* 조작법 안내는 한 칸으로 — 좁은 화면에서 읽기 쉽게 */
  .help-grid { grid-template-columns: 1fr; }
  .help-head .panel-title { font-size: 15px; }
  .help-foot { display: none; }
  .title-actions { gap: 6px; }
  .title-actions .btn { flex: 1 1 auto; padding: 8px 10px; font-size: 12px; }
}

/* 아주 좁은 세로 화면 */
@media (max-width: 400px) {
  .game-title { font-size: 27px; }
  .title-en { letter-spacing: .34em; }
  .panel { padding: 16px 14px; border-radius: 16px; }
  .result-title { font-size: 34px; }
  .stat-grid { gap: 6px; }
}

/* ==========================================================================
   [TB-CSS-BLOCK] 모바일 꾹누르기·드래그 차단 (2026-11-22)
   · 조이스틱·버튼을 꾹 누를 때 생기는 텍스트 선택(파란 하이라이트)을 없앤다
   · iOS 길게 누르기 메뉴(-webkit-touch-callout)와 이미지 끌기를 막는다
   · 문서 전체 overscroll(당겨서 새로고침·바운스)과 확대 제스처를 막는다
   · 스크롤이 필요한 모달은 위쪽 .overlay / .panel 규칙의 touch-action: pan-y 유지
   ========================================================================== */
*,
*::before,
*::after {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
  touch-action: none;
  -ms-touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* 게임 표면(캔버스)과 조이스틱은 손가락 제스처를 브라우저에 넘기지 않는다 */
#scene,
canvas,
#joy,
#joyKnob,
.joy,
.joy-base,
.joy-knob {
  touch-action: none;
  -ms-touch-action: none;
  -webkit-user-drag: none;
}

/* 입력 요소(볼륨 슬라이더·글자 입력)는 손가락 드래그가 살아 있어야 조작된다 */
input,
textarea,
select,
[contenteditable="true"] {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}
