/* ==========================================================================
   우주 기지 방어 · 국어 퀴즈 디펜스
   SF 네온 / 다크 UI · 모바일·태블릿·PC 반응형
   (태블릿에서 화면이 꺼지는 문제를 피하려고 backdrop-filter는 쓰지 않습니다)
   ========================================================================== */

:root {
  --cyan: #3fe6ff;
  --cyan-soft: #7ff3ff;
  --magenta: #ff3ea5;
  --violet: #9a6bff;
  --lime: #64ffb4;
  --amber: #ffc75a;
  --danger: #ff5566;

  --bg: #04060e;
  --panel: rgba(9, 14, 28, 0.94);
  --panel-solid: #0a1120;
  --line: rgba(86, 190, 255, 0.22);
  --line-strong: rgba(86, 220, 255, 0.45);
  --text: #eaf4ff;
  --muted: #8ba2c0;

  --font: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo',
    'Malgun Gothic', 'Noto Sans KR', 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SFMono-Regular', 'DIN Alternate', 'Roboto Mono', ui-monospace, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  position: fixed;
  inset: 0;
}

#app { position: relative; width: 100%; height: 100%; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(ellipse at 50% 55%, transparent 42%, rgba(2, 4, 10, 0.6) 100%),
    linear-gradient(180deg, rgba(4, 7, 16, 0.55) 0%, transparent 22%, transparent 76%, rgba(3, 5, 12, 0.7) 100%);
}

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  transition: opacity 0.28s ease-out;
  background: radial-gradient(circle at 50% 45%, rgba(220, 250, 255, 0.95) 0%, rgba(90, 200, 255, 0.35) 38%, transparent 72%);
}

.hidden { display: none !important; }

/* ============================ HUD ============================ */
#hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(12px + var(--safe-left));
}

.hud-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.hud-block {
  justify-self: start;
  max-width: 320px;
  background: linear-gradient(180deg, rgba(8, 14, 26, 0.62), rgba(5, 9, 17, 0.5));
  border: 1px solid rgba(96, 190, 255, 0.14);
  border-radius: 10px;
  padding: 6px 10px 7px;
  min-width: 0;
  backdrop-filter: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.hud-block.center { text-align: center; padding: 6px 16px 7px; justify-self: center; max-width: none; }
.hud-block.right { text-align: right; justify-self: end; }

.label {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(150, 175, 205, 0.85);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--cyan-soft);
  letter-spacing: 0.02em;
}

.value.big {
  font-size: 18px;
  font-weight: 700;
  color: #f2fbff;
  letter-spacing: 0.01em;
  text-shadow: 0 0 10px rgba(80, 210, 255, 0.3);
}

.mult {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--lime);
  margin-top: 2px;
  text-shadow: 0 0 10px rgba(100, 255, 180, 0.35);
}

.bar {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(120, 200, 255, 0.1);
  overflow: hidden;
}

.bar.thin { height: 4px; }

.bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #1fd2ff, #7ff3ff);
  box-shadow: 0 0 8px rgba(60, 210, 255, 0.45);
  transition: width 0.18s linear, background 0.3s ease;
}

.bar > i.warn { background: linear-gradient(90deg, #ffb347, #ffd98a); box-shadow: 0 0 12px rgba(255, 190, 90, 0.7); }
.bar > i.danger { background: linear-gradient(90deg, #ff4455, #ff8a95); box-shadow: 0 0 14px rgba(255, 70, 90, 0.8); }
#energyFill { background: linear-gradient(90deg, #8f5cff, #3fe6ff); box-shadow: 0 0 12px rgba(120, 120, 255, 0.65); }
#energyFill.low { background: linear-gradient(90deg, #ff5566, #ffb347); animation: pulseBar 0.9s infinite; }

@keyframes pulseBar { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.boss-wrap { margin-top: 6px; min-width: 150px; }
.bar.boss { height: 4px; }
.bar.boss > i {
  background: linear-gradient(90deg, #ff3ea5, #9a6bff, #ff3ea5);
  background-size: 200% 100%;
  box-shadow: 0 0 14px rgba(255, 70, 180, 0.8);
  animation: bossFlow 2s linear infinite;
}
@keyframes bossFlow { to { background-position: 200% 0; } }

.hud-bottom {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.energy-block { flex: 1 1 auto; max-width: 420px; }
.hint-key {
  display: inline-block;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  font-size: 10px;
  color: var(--cyan-soft);
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
}

/* ============================ 버튼 ============================ */
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(20, 44, 74, 0.9), rgba(10, 20, 36, 0.95));
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  box-shadow: 0 0 0 rgba(60, 200, 255, 0);
  touch-action: manipulation;
  white-space: nowrap;
}

.btn:hover { border-color: var(--cyan); box-shadow: 0 0 22px rgba(60, 200, 255, 0.3); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.btn.primary {
  background: linear-gradient(180deg, #1ec8f0, #0d84c9);
  border-color: #8ef0ff;
  color: #03121c;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  box-shadow: 0 6px 26px rgba(30, 180, 240, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.btn.primary:hover { box-shadow: 0 8px 34px rgba(60, 210, 255, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.55); }

.btn.big {
  font-size: clamp(17px, 4.2vw, 21px);
  letter-spacing: 0.14em;
  padding: 15px 46px;
  border-radius: 12px;
}

.btn.ghost { background: transparent; border-color: rgba(140, 180, 220, 0.35); color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--line-strong); }

/* V22 — 타이틀의 「이어서 하기」: START 보다 한 단계 낮춰 눈에 띄게 */
.btn.resume {
  margin-top: 8px;
  padding: 10px 26px;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: #ffe6a8;
  border-color: rgba(255, 210, 122, 0.55);
  background: linear-gradient(180deg, rgba(64, 48, 16, 0.85), rgba(28, 20, 6, 0.92));
}
.btn.resume:hover { border-color: #ffd27a; box-shadow: 0 0 20px rgba(255, 210, 122, 0.28); }
.btn.resume.hidden { display: none; }

.btn.small { font-size: 13px; padding: 9px 14px; border-radius: 9px; }
.btn.icon { font-size: 14px; padding: 9px 12px; min-width: 42px; border-radius: 9px; position: relative; }
.btn.icon.bgm {
  font-size: 12px;
  letter-spacing: 0.06em;
  min-width: 50px;
  padding: 9px 10px;
  color: var(--cyan-soft);
  border-color: rgba(120, 220, 255, 0.42);
}

/* 🎵 토글: 꺼졌을 때 아이콘 위에 사선을 그어 한눈에 보이게 */
.btn.icon.muted { opacity: 0.55; color: var(--muted); }
.btn.icon.muted::after {
  content: '';
  position: absolute;
  left: 22%;
  right: 22%;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  border-radius: 2px;
  background: #ff8aa0;
  box-shadow: 0 0 8px rgba(255, 110, 150, 0.85);
  transform: rotate(-32deg);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none; }

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  margin-left: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  vertical-align: 1px;
}
.btn.primary kbd { background: rgba(0, 0, 0, 0.18); border-color: rgba(0, 0, 0, 0.25); }

/* ============================ 오버레이 공통 ============================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  /* V11 — 내용이 화면 높이보다 길어도 위쪽이 잘리지 않도록 '안전 정렬'.
     가운데 정렬(align-items:center)은 넘치는 내용을 위로 밀어 내 스크롤로도 닿지 않게 만든다.
     그래서 교차축은 flex-start로 두고, 남는 공간은 자식의 margin:auto가 가운데로 나눠 갖는다. */
  align-items: flex-start;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at 50% 40%, rgba(10, 30, 60, 0.55), rgba(3, 5, 12, 0.9) 70%, rgba(2, 4, 9, 0.96));
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: linear-gradient(180deg, rgba(11, 18, 34, 0.96), rgba(5, 9, 18, 0.98));
  border: 1px solid rgba(96, 190, 255, 0.2);
  border-radius: 14px;
  padding: clamp(18px, 3.6vw, 30px);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  margin: auto;
  animation: panelIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.panel.narrow { max-width: 420px; text-align: center; }
.panel.wide { max-width: 620px; text-align: center; }

.panel-title {
  margin: 0 0 8px;
  font-size: clamp(22px, 5vw, 28px);
  letter-spacing: -0.01em;
}

.panel-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.65; }

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
}

/* ============================ 타이틀 ============================ */
.title-screen { align-items: flex-start; }

.title-inner {
  width: 100%;
  max-width: 720px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 넘칠 때는 위에서부터, 여유가 있을 때만 가운데 — 세로 auto 마진 */
  margin: auto 0;
  padding: clamp(16px, 3vw, 30px) 0;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--cyan);
  opacity: 0.85;
}

.glow-title {
  margin: 0;
  font-size: clamp(38px, 10vw, 76px);
  line-height: 1.02;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #ffffff 12%, #b9f2ff 45%, #3fc6ff 78%, #1b7fd6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 26px rgba(60, 190, 255, 0.55)) drop-shadow(0 6px 30px rgba(120, 60, 255, 0.28));
}

.sub {
  margin: 14px auto 26px;
  max-width: 30em;
  font-size: clamp(14px, 2.6vw, 16px);
  line-height: 1.7;
  color: #a9c2dc;
}

/* V19 — 첫 화면에는 난이도만 남았으므로 박스를 한 줄짜리로 슬림하게 */
.settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 11px 16px;
  margin: 0 auto 22px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(8, 14, 28, 0.72);
  width: min(330px, 100%);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.setting-label {
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* V15 · 옵션 버튼 옆 전체화면 토글 */
.setting-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.btn.fs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* HUD 아이콘 버튼은 옆 버튼들과 높이를 맞춘다 */
.btn.icon.fs { line-height: 1.05; }

.btn .fs-ico {
  font-size: 1.05em;
  line-height: 1;
  opacity: 0.92;
}

.btn.fs .fs-txt {
  letter-spacing: 0.02em;
}

.btn.fs[aria-pressed="true"] {
  border-color: rgba(120, 235, 255, 0.72);
  color: #d9fbff;
  background: linear-gradient(180deg, rgba(32, 96, 140, 0.92), rgba(12, 34, 56, 0.96));
  box-shadow: 0 0 18px rgba(60, 210, 255, 0.32);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(120, 200, 255, 0.16);
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.segmented button.active {
  color: #03121c;
  background: linear-gradient(180deg, #8ff0ff, #38cdf5);
  box-shadow: 0 0 16px rgba(60, 210, 255, 0.45);
}

.toggle {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 8px 16px;
  border-radius: 9px;
  cursor: pointer;
  min-width: 62px;
  transition: all 0.18s ease;
}
.toggle.on {
  color: #04121a;
  background: linear-gradient(180deg, #7cf6c4, #2bd39a);
  border-color: #b6ffe0;
  box-shadow: 0 0 18px rgba(60, 240, 170, 0.4);
}

.status {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.status.best { color: var(--amber); }

/* V16 — 결과 카드 안내 문구. ‘다시 도전’·‘타이틀로’ 버튼을 없앤 대신
   누를 수 없는 작은 안내만 남긴다(실수로 눌러 결과가 사라지는 일 방지). */
.result-hint {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-align: center;
}

/* V18 — 중간에 죽었을 때(GAME OVER) 결과 카드에만 나오는 ‘다시 시작’ 버튼.
   손이 바로 가도록 기본 버튼보다 조금 크게, 결과 카드 아래 가운데에 놓는다. */
#result .result-actions { margin-top: 16px; }
#result .btn.retry {
  font-size: 16px;
  padding: 13px 38px;
  border-radius: 11px;
  letter-spacing: 0.02em;
}

#btnStart { margin-top: 4px; }

/* V19 — START 아래 「📖 조작법 · ⚙ 옵션 · ⛶ 전체화면」 한 줄 */
.title-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 16px;
}
.title-actions .btn {
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  color: #cfe6f8;
}
.title-actions .btn:hover { color: #fff; }
.title-actions .btn.fs[aria-pressed="true"] { color: #d9fbff; }

/* ============================ 조작법 (V19) ============================
   타이틀에서 떼어 낸 ‘다음 페이지’. 카드가 화면 높이를 넘으면 카드 안에서만
   스크롤되고(제목·돌아가기 버튼은 고정), 가로모드에서는 여백·관리 글자를 줄인다. */
#howto { z-index: 21; }

.howto-panel {
  max-width: 560px;
  max-height: calc(100dvh - 40px - var(--safe-top) - var(--safe-bottom));
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: clamp(16px, 3vw, 26px);
}
.howto-panel .eyebrow { margin: 0 0 4px; }
.howto-panel .panel-title { margin: 0 0 4px; }
.howto-lead {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.ht-scroll {
  display: grid;
  gap: 9px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px 8px;
  min-height: 0;
  /* 얇은 스크롤바 — 카드 안에서 더 스크롤할 내용이 있다는 것만 알려 준다 */
  scrollbar-width: thin;
  scrollbar-color: rgba(90, 200, 255, 0.45) transparent;
}
.ht-scroll::-webkit-scrollbar { width: 6px; }
.ht-scroll::-webkit-scrollbar-track { background: rgba(120, 200, 255, 0.07); border-radius: 3px; }
.ht-scroll::-webkit-scrollbar-thumb {
  background: rgba(90, 200, 255, 0.42);
  border-radius: 3px;
}
.ht-scroll::-webkit-scrollbar-thumb:hover { background: rgba(140, 230, 255, 0.62); }

.ht-sec {
  border: 1px solid rgba(96, 190, 255, 0.14);
  border-radius: 12px;
  background: rgba(8, 14, 28, 0.6);
  padding: 10px 14px 11px;
}

.ht-head {
  margin: 0 0 6px;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--cyan-soft);
}

.ht-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 5px;
}
.ht-list li {
  position: relative;
  padding-left: 14px;
  font-size: 13px;
  line-height: 1.6;
  color: #b6cde4;
}
.ht-list li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.62em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 9px var(--cyan);
}
.ht-list b, .ht-note b { color: #e4f6ff; font-weight: 700; }
.ht-list kbd { font-size: 9.5px; padding: 1px 4px; margin-left: 2px; }

.ht-note {
  margin: 6px 0 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: #8aa6c4;
}

.ht-sec .stage-list { margin: 2px 0 0; width: 100%; gap: 6px; }
.ht-sec .diff-hint { margin: 0; text-align: left; }

.howto-panel .panel-actions { margin-top: 14px; }

/* ============================ 퀴즈 ============================ */
/* V9 — 카드가 화면 높이를 넘으면 카드 안에서 스크롤되고, 절대 화면 밖으로 잘리지 않는다 */
.quiz-panel {
  max-width: 640px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.tag {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #05101c;
  background: linear-gradient(180deg, #9df6ff, #45d4ff);
  box-shadow: 0 0 18px rgba(60, 210, 255, 0.4);
}

.quiz-reason { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
/* V23 — 재출제 문제 표시(↻ 배지)는 없앴다: 퀴즈 창은 문제·보기·해설만 */

/* ---------- 퀴즈 오클릭 방지 경계 (V8) ----------
   모달이 뜬 뒤 0.8초 동안 보기를 잠그고, 그 사이 '문제 시간'으로 넘어가는 경계를 보여 준다. */
.quiz-guard {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -8px 0 16px;
}

.quiz-guard .qg-track {
  flex: 1 1 auto;
  height: 3px;
  border-radius: 2px;
  background: rgba(120, 200, 255, 0.16);
  overflow: hidden;
}

.quiz-guard .qg-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, #3fc6ff, #b6f4ff);
  box-shadow: 0 0 12px rgba(90, 220, 255, 0.75);
}

.quiz-guard .qg-label {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: rgba(170, 225, 255, 0.78);
}

#quiz.locked .quiz-guard .qg-label { color: #bdefff; }

/* 잠금 중에는 보기가 '대기' 상태로 보인다 */
#quiz.locked .choice {
  opacity: 0.4;
  filter: saturate(0.45);
  cursor: default;
}
#quiz.locked .choice:hover {
  background: rgba(255, 255, 255, 0.045);
  border-color: rgba(120, 200, 255, 0.2);
}
#quiz.locked .skip { opacity: 0.35; }

/* 해설이 뜬 뒤에는 '사격 정지' 게이지를 내려 해설·계속하기에 자리를 준다 */
#quiz.answered .quiz-guard { display: none; }
/* 잠금이 풀린 뒤에도 안내 막대를 남기지 않는다 — 오답 재선택 중에 '잠시 후 선택'이 남지 않게 */
#quiz.released .quiz-guard { display: none; }

/* 잠금이 풀리는 순간 — 테두리가 번지고 보기가 차례로 살아난다 */
#quiz.armed .quiz-panel { animation: quizArm 0.55s ease-out; }
#quiz.armed #quizQuestion { color: #ffffff; }

@keyframes quizArm {
  0% { box-shadow: 0 0 0 0 rgba(120, 225, 255, 0.55), 0 18px 54px rgba(0, 0, 0, 0.55); }
  100% { box-shadow: 0 0 0 16px rgba(120, 225, 255, 0), 0 18px 54px rgba(0, 0, 0, 0.55); }
}

#quiz.armed .choice { animation: choiceArm 0.34s cubic-bezier(0.2, 0.9, 0.3, 1) backwards; }
#quiz.armed .choice:nth-child(2) { animation-delay: 0.035s; }
#quiz.armed .choice:nth-child(3) { animation-delay: 0.07s; }
#quiz.armed .choice:nth-child(4) { animation-delay: 0.105s; }
#quiz.armed .choice:nth-child(5) { animation-delay: 0.14s; }
#quiz.armed .choice:nth-child(6) { animation-delay: 0.175s; }

@keyframes choiceArm {
  from { opacity: 0.35; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

/* 잠금 중에 눌렀을 때의 짧은 흔들림 */
#quiz.guard-hit .quiz-panel { animation: quizNudge 0.3s ease; }
@keyframes quizNudge {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  65% { transform: translateX(3px); }
}

#quizQuestion {
  margin: 0 0 20px;
  font-size: clamp(18px, 3.4vw, 22px);
  line-height: 1.5;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.01em;
  word-break: keep-all;
}

.choices { display: grid; gap: 10px; }

.choice {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 54px;
  padding: 12px 16px;
  text-align: left;
  font-family: inherit;
  font-size: clamp(14.5px, 2.9vw, 16px);
  line-height: 1.45;
  color: #e7f3ff;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(120, 200, 255, 0.2);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.1s ease;
  word-break: keep-all;
  touch-action: manipulation;
}

.choice:hover:not(:disabled) {
  background: rgba(70, 200, 255, 0.12);
  border-color: var(--cyan);
}
.choice:active:not(:disabled) { transform: scale(0.994); }
.choice:disabled { cursor: default; }

.choice .key {
  flex: 0 0 auto;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--cyan-soft);
  background: rgba(60, 200, 255, 0.1);
  border: 1px solid rgba(90, 220, 255, 0.35);
}

.choice .txt { flex: 1 1 auto; }

.choice.correct {
  background: rgba(50, 230, 150, 0.16);
  border-color: #4dffb0;
  box-shadow: 0 0 26px rgba(50, 230, 150, 0.28) inset, 0 0 18px rgba(50, 230, 150, 0.18);
}
.choice.correct .key { color: #04120c; background: #6dffc0; border-color: #b6ffe2; }

.choice.wrong {
  background: rgba(255, 70, 90, 0.14);
  border-color: #ff6b7d;
  box-shadow: 0 0 22px rgba(255, 70, 90, 0.22) inset;
}
.choice.wrong .key { color: #1a0206; background: #ff8090; border-color: #ffc2c9; }

.choice.dim { opacity: 0.42; }

.feedback {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed rgba(120, 200, 255, 0.28);
  animation: fadeIn 0.25s ease-out;
}

.fb-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}
.fb-title.ok { color: #6dffc0; text-shadow: 0 0 18px rgba(80, 255, 180, 0.4); }
.fb-title.no { color: #ff8b9a; text-shadow: 0 0 18px rgba(255, 90, 110, 0.35); }

.feedback p {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.75;
  color: #b9d0e8;
  word-break: keep-all;
}

.feedback .btn { width: 100%; }

.skip {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 8px;
}
.skip:hover { color: #cfe6ff; }

/* ============================ 결과 ============================ */
.result-title {
  margin: 0 0 10px;
  font-size: clamp(26px, 6vw, 36px);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #ffffff, #8fe6ff 70%, #35a8ef);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px rgba(60, 190, 255, 0.45));
}
.result-title.lose {
  background: linear-gradient(180deg, #ffffff, #ffb3c0 70%, #ff5570);
  /* background 단축 속성이 background-clip 을 border-box 로 되돌려
     ‘기지 함락’ 글자가 통째로 분홍 막대가 되던 문제(V18 수정) */
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 22px rgba(255, 80, 110, 0.4));
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 22px 0 6px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(120, 200, 255, 0.16);
}

.stat-label { font-size: 11.5px; letter-spacing: 0.1em; color: var(--muted); }
.stat b {
  font-family: var(--font-mono);
  font-size: clamp(18px, 4.5vw, 22px);
  color: #fff;
  font-variant-numeric: tabular-nums;
}

/* ============================ 배너 / 토스트 ============================ */
.banner {
  position: absolute;
  top: 26%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(30px, 8.5vw, 64px);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #eafcff;
  text-shadow: 0 0 30px rgba(60, 210, 255, 0.85), 0 0 70px rgba(80, 120, 255, 0.5);
  opacity: 0;
  pointer-events: none;
}

.banner.show { animation: bannerPop 2.1s cubic-bezier(0.2, 0.9, 0.2, 1) forwards; }

@keyframes bannerPop {
  0% { opacity: 0; transform: translateY(18px) scale(0.94); letter-spacing: 0.4em; }
  18% { opacity: 1; transform: translateY(0) scale(1); letter-spacing: 0.08em; }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px) scale(1.02); }
}

.reticle {
  position: fixed;
  left: 0;
  top: 0;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 1px solid rgba(120, 235, 255, 0.65);
  border-radius: 50%;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.18s ease;
  box-shadow: 0 0 14px rgba(60, 210, 255, 0.35), inset 0 0 10px rgba(60, 210, 255, 0.2);
  will-change: transform;
}
.reticle.on { opacity: 0.9; }
.reticle i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: #9ff6ff;
  box-shadow: 0 0 10px #6cf0ff;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translate(-50%, 10px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(8, 16, 30, 0.95);
  border: 1px solid var(--line-strong);
  color: #d9f1ff;
  font-size: 13px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  box-shadow: 0 0 26px rgba(30, 130, 210, 0.28);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================ 반응형 ============================ */
@media (max-width: 860px) {
  .hud-block { padding: 7px 9px 8px; border-radius: 10px; }
  .hud-block.center { padding: 7px 10px 8px; }
  .value.big { font-size: 17px; }
  .label { font-size: 10px; letter-spacing: 0.06em; }
  .boss-wrap { min-width: 96px; }
  .energy-block { max-width: 300px; }
}

@media (max-width: 620px) {
  #hud { padding: calc(8px + var(--safe-top)) calc(9px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(9px + var(--safe-left)); }
  .hud-top { gap: 7px; }
  .hud-block { padding: 6px 8px 7px; }
  .label { font-size: 9px; margin-bottom: 4px; }
  .value { font-size: 12px; }
  .value.big { font-size: 15px; }
  .mult { font-size: 10.5px; }
  .bar { height: 7px; }
  .energy-block { max-width: 170px; }
  .btn.small { font-size: 12px; padding: 8px 10px; }
  .btn.icon { min-width: 38px; padding: 8px 9px; font-size: 12px; }
  .btn.icon.bgm { min-width: 44px; padding: 8px 8px; font-size: 11px; }
  /* 좁은 화면에서는 HUD 전체화면 버튼을 아이콘만 남긴다 */
  .btn.icon.fs { min-width: 38px; padding: 8px 9px; }
  .btn.icon.fs .fs-txt { display: none; }
  .actions { gap: 6px; }
  .toast { bottom: calc(88px + var(--safe-bottom)); font-size: 12px; padding: 8px 14px; }
  .settings { padding: 14px; width: 100%; }
  .panel { border-radius: 16px; }
  .choice { padding: 11px 13px; gap: 10px; border-radius: 11px; }
  .stat { padding: 12px 10px; }
  .banner { top: 30%; }
}

/* HUD 버튼이 4개(퀴즈·일시정지·사운드·BGM)라 좁은 폰에서 한 줄에 들어가도록 조정 */
@media (max-width: 430px) {
  #hud { padding-left: calc(7px + var(--safe-left)); padding-right: calc(7px + var(--safe-right)); }
  .hud-bottom { gap: 6px; }
  .energy-block { min-width: 0; max-width: 150px; }
  .actions { gap: 4px; }
  .btn.small { font-size: 11px; padding: 8px 8px; }
  .btn.small kbd { display: none; }
  .btn.icon { min-width: 34px; padding: 8px 7px; }
  .btn.icon.bgm { min-width: 40px; padding: 8px 6px; letter-spacing: 0.02em; }
  .btn.icon.fs { min-width: 34px; padding: 8px 6px; }
  .setting-actions { gap: 6px; }
  .btn.fs .fs-txt { font-size: 11px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .glow-title { font-size: clamp(28px, 6vh, 44px); }
  .sub { margin: 8px auto 14px; }
  .settings { margin-bottom: 14px; padding: 10px 14px; }
  .title-inner { padding: 8px 0; }
  .panel { padding: 18px 22px; }
  #quizQuestion { margin-bottom: 12px; font-size: 17px; }
  .choice { min-height: 44px; padding: 8px 12px; }
}

/* ---------- V16 · 모바일 가로모드(낮은 화면) — 퀴즈 글자를 시원하게 ----------
   세로로 긴 목록 대신 보기를 2×2 그리드로 놓아 가로 폭을 살리고,
   남는 세로 공간을 글자 크기와 보기 여백에 모두 쓴다.
   문제 19px · 보기 16px · 해설 14.5~15px 로 키우면서도
   문제 · 보기 4개 · 해설 · 계속 전투 버튼이 844×344 / 844×390 에서
   스크롤·잘림 없이 한 화면에 들어오는 선(실측)에 맞췄다. */
@media (max-height: 540px) {
  #quiz {
    align-items: center;
    padding: calc(3px + var(--safe-top)) calc(8px + var(--safe-right)) calc(3px + var(--safe-bottom)) calc(8px + var(--safe-left));
  }
  #quiz .quiz-panel {
    max-width: 812px;
    max-height: calc(100dvh - 6px - var(--safe-top) - var(--safe-bottom));
    padding: 7px 15px 8px;
    border-radius: 12px;
  }
  .quiz-head { margin-bottom: 6px; gap: 10px; }
  .quiz-head .tag { padding: 3px 11px; font-size: 11.5px; letter-spacing: 0.04em; }
  .quiz-reason { font-size: 11px; }
  #quizQuestion {
    margin: 0 0 6px;
    font-size: 19px;
    line-height: 1.36;
    max-height: 2.75em;
    overflow-y: auto;
  }
  .quiz-guard { margin: 0 0 5px; gap: 8px; }
  .quiz-guard .qg-track { height: 3px; }
  .quiz-guard .qg-label { font-size: 10.5px; letter-spacing: 0.12em; }
  #quizChoices.choices {
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }
  #quiz .choice {
    min-height: 0;
    padding: 10px 11px;
    gap: 9px;
    border-radius: 9px;
    font-size: 16px;
    line-height: 1.32;
  }
  #quiz .choice .key {
    width: 23px;
    height: 23px;
    border-radius: 7px;
    font-size: 12px;
  }
  .feedback {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 3px 10px;
    align-items: center;
    margin-top: 6px;
    padding-top: 6px;
  }
  .fb-title {
    grid-column: 1 / -1;
    margin-bottom: 1px;
    font-size: 14.5px;
    line-height: 1.3;
  }
  .feedback p {
    grid-column: 1;
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
    max-height: 3.1em;
    overflow-y: auto;
  }
  .feedback .btn {
    grid-column: 2;
    width: auto;
    min-width: 132px;
    padding: 9px 16px;
    font-size: 14.5px;
  }
  .skip {
    margin: 1px auto 0;
    padding: 1px 6px;
    font-size: 12px;
  }
}

@media (hover: none) {
  .btn:hover { box-shadow: none; }
  .choice:hover:not(:disabled) { background: rgba(255, 255, 255, 0.045); border-color: rgba(120, 200, 255, 0.2); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   V2 · 무기 진화 HUD / 포탑 과열 / 시점·줌 / 옵션
   ========================================================================== */

/* 화면 가장자리 과열 경고 */
#heatEdge {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.25s ease;
  background:
    radial-gradient(ellipse at 50% 115%, rgba(255, 70, 50, 0.55), transparent 55%),
    radial-gradient(ellipse at 50% -15%, rgba(255, 120, 40, 0.35), transparent 55%);
  mix-blend-mode: screen;
}
#heatEdge.on { opacity: var(--heat-op, 0.5); }

/* HUD 좌측 세로 배치 */
.hud-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-self: start;
  min-width: 0;
}

.weapon-block { min-width: 172px; }

.weapon-lv {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #04121c;
  background: linear-gradient(180deg, #9df6ff, #45d4ff);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 4px;
  vertical-align: 1px;
}

.weapon-name {
  font-size: 13px;
  font-weight: 700;
  color: #d9f4ff;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 14px rgba(70, 220, 255, 0.45);
  margin-bottom: 6px;
}

.parts-row { display: flex; align-items: center; gap: 7px; }
.bar.thin.parts { flex: 1 1 auto; height: 5px; }
#partsFill {
  background: linear-gradient(90deg, #ffd85a, #ff9f3d);
  box-shadow: 0 0 10px rgba(255, 200, 90, 0.7);
}
.parts-text {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--amber);
  white-space: nowrap;
}

/* 포탑 온도 */
.heat-line {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  max-width: 300px;
}
.heat-label {
  flex: 0 0 auto;
  font-size: 9.5px;
  letter-spacing: 0.06em;
  color: #8ba2c0;
  text-transform: uppercase;
}
.bar.thin.heat { flex: 1 1 auto; height: 5px; }
#heatFill {
  width: 0%;
  background: linear-gradient(90deg, #59ffcf, #ffd85a 60%, #ff5566);
  box-shadow: 0 0 10px rgba(255, 160, 70, 0.55);
}
.bar.thin.heat > i.hot { animation: pulseBar 0.7s infinite; }
.heat-value {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: #9fb6d0;
  min-width: 30px;
  text-align: right;
}

/* 시점 · 줌 패드 */
.viewpad {
  position: absolute;
  right: calc(12px + var(--safe-right));
  bottom: calc(74px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: auto;
  z-index: 6;
}
.viewbtn {
  appearance: none;
  width: 44px;
  height: 38px;
  border-radius: 9px;
  border: 1px solid rgba(86, 200, 255, 0.32);
  background: rgba(8, 16, 30, 0.72);
  color: #cdf1ff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 0 14px rgba(30, 130, 210, 0.16);
}
.viewbtn:active { background: rgba(40, 120, 190, 0.65); border-color: var(--cyan); }

@media (hover: hover) and (pointer: fine) {
  .viewpad { display: none; }
}

.zoom-badge {
  position: absolute;
  left: 50%;
  top: calc(76px + var(--safe-top));
  transform: translateX(-50%);
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid rgba(120, 235, 255, 0.5);
  background: rgba(6, 16, 30, 0.82);
  color: #d6f7ff;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  pointer-events: none;
  box-shadow: 0 0 20px rgba(40, 190, 255, 0.3);
}

/* 옵션 패널 */
.options-panel { max-width: 460px; }

.opt-list { display: flex; flex-direction: column; gap: 12px; margin: 8px 0 4px; }

.opt-row {
  display: grid;
  grid-template-columns: 1fr 150px auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(120, 200, 255, 0.14);
  text-align: left;
}

.opt-label { font-size: 13px; color: #b6cee6; letter-spacing: 0.02em; }

.opt-row .toggle,
.opt-row .btn { justify-self: end; }

.opt-val {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--cyan-soft);
  min-width: 30px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1fd2ff, #8f5cff);
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1fd2ff, #8f5cff);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  background: #eafcff;
  border: 2px solid #2fc9ff;
  box-shadow: 0 0 12px rgba(60, 210, 255, 0.8);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #eafcff;
  border: 2px solid #2fc9ff;
}

/* 무기 진화 배너 강조 */
.banner.upgrade { color: #fff3c9; text-shadow: 0 0 26px rgba(255, 200, 80, 0.9), 0 0 70px rgba(255, 130, 40, 0.5); }

@media (max-width: 620px) {
  .weapon-block { min-width: 0; }
  .weapon-name { font-size: 11.5px; }
  .opt-row { grid-template-columns: 1fr 108px auto; gap: 8px; padding: 7px 10px; }
  .opt-label { font-size: 12px; }
  .viewpad { bottom: calc(66px + var(--safe-bottom)); right: calc(8px + var(--safe-right)); }
  .viewbtn { width: 40px; height: 34px; font-size: 13px; }
  .zoom-badge { top: calc(66px + var(--safe-top)); font-size: 11px; }
  .heat-line { max-width: 200px; }
}

@media (max-width: 430px) {
  .heat-label { display: none; }
  .heat-line { max-width: 150px; }
  .actions .btn.icon { padding: 8px 6px; }
}


/* ============================ 미니 레이더 ============================ */
.radar-wrap {
  position: absolute;
  left: calc(12px + var(--safe-left));
  top: 50%;
  transform: translateY(-50%);
  width: 112px;
  height: 112px;
  pointer-events: none;
  z-index: 5;
}
#radar {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 0 10px rgba(40, 180, 255, 0.28));
}
.radar-warn {
  position: absolute;
  left: 50%;
  bottom: -18px;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(120, 10, 30, 0.8);
  border: 1px solid rgba(255, 90, 120, 0.75);
  color: #ffd0d8;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  animation: pulseBar 1s infinite;
}

@media (max-width: 860px) {
  .radar-wrap { width: 92px; height: 92px; }
  .radar-warn { bottom: -16px; font-size: 10px; }
}

@media (max-width: 620px) {
  .radar-wrap { width: 78px; height: 78px; left: calc(8px + var(--safe-left)); }
  .viewbtn { width: 52px; height: 44px; font-size: 16px; }
  .viewpad { gap: 8px; }
}

/* ==========================================================================
   V4 · 우주전쟁 — 스테이지 1~4 / 난이도 / 최종 보스 / 각성
   ========================================================================== */

:root {
  --stage-accent: #4fe8ff;
}

/* ---------- HUD 중앙: 스테이지 ---------- */
.stage-block { padding: 7px 16px 8px; }

.stage-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.stage-line .label { margin-bottom: 3px; }

.stage-pips { display: inline-flex; gap: 3px; }
.stage-pips i {
  width: 12px;
  height: 4px;
  border-radius: 999px;
  background: rgba(160, 200, 230, 0.22);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}
.stage-pips i.done { background: rgba(160, 200, 230, 0.55); }
.stage-pips i.on {
  background: var(--stage-accent);
  box-shadow: 0 0 9px var(--stage-accent);
}

.stage-value {
  font-size: 21px;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 0 16px var(--stage-accent);
}
.stage-value .stage-max {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  margin-left: 2px;
}

.stage-name {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--stage-accent);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 230px;
}

.wave-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #9fb6d0;
  margin-top: 3px;
}

/* ---------- 최종 보스 체력바 (전장을 가리지 않는 슬림 한 줄) ---------- */
.final-boss {
  position: static;
  width: 100%;
  margin: 6px 0 0;
  padding: 5px 0 0;
  border: 0;
  border-top: 1px solid rgba(255, 140, 80, 0.22);
  display: flex;
  align-items: center;
  gap: 7px;
  background: none;
  box-shadow: none;
  pointer-events: none;
  opacity: 0.95;
}

.fb-tag {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: #2a0a04;
  background: linear-gradient(180deg, #ffd98a, #ff9a3c);
  border-radius: 3px;
  padding: 1px 5px;
  flex: 0 0 auto;
}
.fb-name {
  font-size: 10px;
  font-weight: 600;
  color: #ffd6ad;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 0 10px rgba(255, 120, 40, 0.45);
  flex: 0 0 auto;
}
.final-boss .bar.boss.final {
  flex: 1 1 auto;
  min-width: 60px;
  height: 5px;
  background: rgba(255, 120, 70, 0.14);
  border: 1px solid rgba(255, 140, 80, 0.28);
}
.bar.boss.final > i {
  background: linear-gradient(90deg, #ff5a2a, #ffa53c 60%, #ffd98a);
  box-shadow: 0 0 10px rgba(255, 120, 40, 0.55);
  transition: width 0.18s linear;
}
.fb-hp {
  font-family: var(--font-mono);
  font-size: 9px;
  color: rgba(255, 195, 155, 0.9);
  white-space: nowrap;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.fb-meta {
  font-size: 8px;
  letter-spacing: 0.06em;
  color: rgba(215, 165, 135, 0.8);
  flex: 0 0 auto;
}

/* ---------- 최종 보스 경고 (시야를 가리지 않는 상단 띠) ---------- */
.boss-warn {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: calc(112px + var(--safe-top));
  background: none;
  opacity: 0;
}
.boss-warn.show { animation: bossWarnFlash 2.4s ease-out forwards; }
@keyframes bossWarnFlash {
  0% { opacity: 0; transform: translateY(-6px); }
  10% { opacity: 1; transform: translateY(0); }
  22% { opacity: 0.55; }
  34% { opacity: 1; }
  80% { opacity: 0.9; }
  100% { opacity: 0; }
}
.bw-frame { display: none; }
.bw-inner {
  text-align: center;
  padding: 5px 18px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255, 90, 50, 0.4);
  background: rgba(46, 5, 3, 0.42);
}
.bw-title {
  font-size: clamp(13px, 3vw, 18px);
  font-weight: 800;
  letter-spacing: 0.42em;
  color: #ffe6d6;
  text-shadow: 0 0 16px rgba(255, 70, 25, 0.75);
}
.bw-sub {
  margin-top: 1px;
  font-size: clamp(9px, 2vw, 11px);
  letter-spacing: 0.16em;
  color: rgba(255, 201, 168, 0.9);
}

/* ---------- 스테이지 카드 ---------- */
.stage-card {
  position: fixed;
  left: 0;
  right: 0;
  top: 42%;
  transform: translateY(-50%);
  z-index: 9;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  padding: 0 18px;
}
.stage-card.show { animation: stageCardIn 2.4s cubic-bezier(0.2, 0.9, 0.2, 1) forwards; }
@keyframes stageCardIn {
  0% { opacity: 0; transform: translateY(-50%) scale(0.92); letter-spacing: 0.4em; }
  14% { opacity: 1; transform: translateY(-50%) scale(1); letter-spacing: 0.12em; }
  74% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-56%) scale(1.02); }
}
.sc-en {
  margin: 0 0 2px;
  font-size: clamp(10px, 2.2vw, 13px);
  letter-spacing: 0.34em;
  color: var(--stage-accent);
  text-shadow: 0 0 16px var(--stage-accent);
}
.sc-num {
  font-family: var(--font-mono);
  font-size: clamp(54px, 16vw, 120px);
  font-weight: 800;
  line-height: 0.95;
  color: rgba(255, 255, 255, 0.1);
  text-shadow: 0 0 40px var(--stage-accent);
}
.sc-name {
  margin: 2px 0 0;
  font-size: clamp(22px, 5.6vw, 40px);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #f2fbff;
  text-shadow: 0 0 26px rgba(255, 255, 255, 0.35), 0 0 60px var(--stage-accent);
}
.sc-desc {
  margin: 8px auto 0;
  max-width: 30em;
  font-size: clamp(11px, 2.4vw, 14px);
  letter-spacing: 0.02em;
  color: #cfe4f5;
  opacity: 0.9;
}

/* ---------- 각성 배지 ---------- */
.awaken-badge {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #2a1600;
  background: linear-gradient(180deg, #ffe6a8, #ffb43b);
  box-shadow: 0 0 12px rgba(255, 190, 80, 0.8);
  vertical-align: 1px;
}

/* ---------- 타이틀 추가 요소 ---------- */
.title-sub-line {
  margin: 6px 0 0;
  font-size: clamp(9px, 2vw, 12px);
  letter-spacing: 0.42em;
  color: rgba(150, 200, 230, 0.7);
  text-transform: uppercase;
}

.diff-hint {
  margin: -2px 0 2px;
  font-size: 11.5px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  color: #8fb6d4;
  text-align: center;
}

.stage-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: min(470px, 100%);
  margin: 0 auto 22px;
}
.stage-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 7px;
  border-radius: 10px;
  border: 1px solid rgba(120, 200, 255, 0.16);
  background: rgba(8, 14, 28, 0.62);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: #9fbdd8;
  white-space: nowrap;
  overflow: hidden;
}
.stage-chip b {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 800;
  color: #dff4ff;
}
.stage-chip.s1 { border-color: rgba(79, 232, 255, 0.45); box-shadow: 0 0 14px rgba(79, 232, 255, 0.16); }
.stage-chip.s2 { border-color: rgba(255, 138, 74, 0.45); box-shadow: 0 0 14px rgba(255, 138, 74, 0.16); }
.stage-chip.s3 { border-color: rgba(179, 136, 255, 0.45); box-shadow: 0 0 14px rgba(179, 136, 255, 0.16); }
.stage-chip.s4 {
  border-color: rgba(255, 180, 59, 0.6);
  box-shadow: 0 0 16px rgba(255, 140, 40, 0.28);
  background: linear-gradient(180deg, rgba(60, 10, 4, 0.75), rgba(20, 4, 2, 0.7));
  color: #ffd6a8;
}
.stage-chip.s4 b { color: #ffc75a; }
.stage-list.hard .stage-chip.s4 { animation: pulseBar 1.6s infinite; }

/* ---------- 반응형 ---------- */
@media (max-width: 860px) {
  .stage-value { font-size: 18px; }
  .stage-name { font-size: 9.5px; max-width: 180px; }
  .final-boss { width: 100%; margin-top: 5px; }
  .fb-name { font-size: 9px; }
  .bar.boss.final { height: 9px; }
}

@media (max-width: 620px) {
  .stage-block { padding: 5px 8px 6px; }
  .stage-value { font-size: 15px; }
  .stage-value .stage-max { font-size: 9px; }
  .stage-name { font-size: 8.5px; max-width: 132px; letter-spacing: 0; }
  .wave-sub { font-size: 8.5px; }
  .stage-pips i { width: 9px; height: 3px; }
  .final-boss { width: 100%; gap: 5px; margin-top: 4px; padding-top: 4px; }
  .fb-tag { font-size: 7.5px; padding: 1px 4px; }
  .fb-name { font-size: 8.5px; }
  .fb-hp { font-size: 8px; }
  .bar.boss.final { height: 8px; }
  .fb-meta { display: none; }
  .stage-card { top: 38%; }
  .boss-warn { padding-top: calc(96px + var(--safe-top)); }
  .sc-desc { max-width: 22em; }
  .difficulty-hint, .diff-hint { font-size: 10.5px; }
  .stage-chip { font-size: 9.5px; padding: 6px 2px 5px; }
  .stage-chip b { font-size: 13px; }
  .br-desk { display: none; }
}

@media (max-width: 430px) {
  .stage-name { display: none; }
  .stage-value { font-size: 14px; }
  .stage-list { gap: 5px; }
  .stage-chip span { font-size: 9px; }
}

/* 스테이지 카드 가독성을 위한 어두운 후광 */
.stage-card::before {
  content: '';
  position: absolute;
  inset: -12% -18%;
  z-index: -1;
  background: radial-gradient(ellipse at 50% 50%, rgba(2, 6, 16, 0.72) 0%, rgba(2, 6, 16, 0.5) 45%, rgba(2, 6, 16, 0) 72%);
}

/* 홀수 개 통계는 마지막 항목이 두 칸을 차지하게 */
.stat-grid .stat:last-child:nth-child(odd) { grid-column: span 2; }

/* ==========================================================================
   V5 — 최종 보스 격파 승리 시네마틱 & 화려한 결과 카드
   ========================================================================== */

/* --- 시네마틱 동안 HUD는 조용히 물러난다 --- */
#hud.cine { pointer-events: none; }
#hud.cine .hud-top,
#hud.cine .hud-bottom,
#hud.cine .radar-wrap,
#hud.cine .viewpad,
#hud.cine .zoom-badge,
#hud.cine .reticle,
#hud.cine .final-boss,
#hud.cine .toast {
  opacity: 0;
  transition: opacity 0.55s ease;
  pointer-events: none;
}

/* --- V12 격파 연출의 오버레이 — 장식을 덜어낸 '격파!' 한 줄 --- */
.win-cine {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
}
.win-cine.show { animation: wcIn 0.42s cubic-bezier(0.16, 0.9, 0.2, 1) forwards; }
.win-cine.fade { animation: wcOut 0.38s ease forwards; }

@keyframes wcIn {
  0% { opacity: 0; transform: scale(1.07); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes wcOut {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.03); }
}

.win-cine .wc-inner { position: relative; z-index: 2; padding: 0 18px; }
/* 밝게 터지는 배경 위에서도 글자가 또렷하게 읽히도록 뒤에 어두운 후광을 깐다 */
.win-cine .wc-inner::before {
  content: '';
  position: absolute;
  inset: -80% -26%;
  z-index: -1;
  background: radial-gradient(ellipse at 50% 50%, rgba(5, 7, 16, 0.68) 0%, rgba(5, 7, 16, 0.44) 44%, rgba(5, 7, 16, 0) 76%);
}

.wc-title {
  margin: 0;
  font-size: clamp(46px, 13vw, 112px);
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1;
  color: #fffdf4;
  text-shadow: 0 0 28px rgba(255, 205, 120, 0.55), 0 0 90px rgba(255, 150, 40, 0.28);
}
.wc-sub {
  margin: 12px 0 0;
  font-family: var(--font-mono);
  font-size: clamp(10px, 2.4vw, 13px);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: #ffeccc;
  text-shadow: 0 0 16px rgba(255, 175, 70, 0.45);
}
.wc-bar {
  height: 1px;
  width: min(46vw, 340px);
  margin: 18px auto 0;
  background: linear-gradient(90deg, rgba(255, 220, 150, 0), #ffe9c4 50%, rgba(255, 220, 150, 0));
  transform-origin: 50% 50%;
  animation: wcBar 0.5s cubic-bezier(0.2, 0.9, 0.2, 1) both;
}
@keyframes wcBar {
  0% { transform: scaleX(0); opacity: 0; }
  100% { transform: scaleX(1); opacity: 1; }
}

/* --- V20 엔딩 스토리 — 격파 연출과 점수 카드 사이의 짧은 에필로그 3컷 ---
   화면 전체가 ‘넘기기’ 영역이다(버튼 없음). 카드는 어떤 화면에서도 잘리지 않고
   스크롤이 생기지 않도록 높이를 vh 기준으로 잡는다. */
.ending {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  overflow: hidden;
  cursor: pointer;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(8, 16, 34, 0.5) 0%, rgba(3, 6, 14, 0.86) 68%, rgba(1, 3, 8, 0.95) 100%);
  animation: fadeIn 0.3s ease-out;
}

.end-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 100%;
  padding: clamp(16px, 3.4vh, 26px) clamp(18px, 3vw, 30px) clamp(14px, 3vh, 22px);
  text-align: center;
  border-radius: 16px;
  border: 1px solid rgba(120, 200, 255, 0.22);
  background: linear-gradient(180deg, rgba(10, 18, 34, 0.9), rgba(5, 9, 18, 0.94));
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

/* 카드 위쪽의 얇은 빛줄기 */
.end-card::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  width: min(72%, 320px);
  height: 1px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(127, 243, 255, 0), rgba(190, 245, 255, 0.85) 50%, rgba(127, 243, 255, 0));
}

.end-card.cut-in { animation: endCutIn 0.42s cubic-bezier(0.2, 0.9, 0.25, 1) both; }
@keyframes endCutIn {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: none; }
}

.end-art {
  width: clamp(48px, 9.6vh, 66px);
  height: clamp(48px, 9.6vh, 66px);
  margin: 0 auto clamp(8px, 1.8vh, 12px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 4.8vh, 32px);
  line-height: 1;
  border-radius: 50%;
  border: 1px solid rgba(120, 220, 255, 0.32);
  background: radial-gradient(circle at 50% 38%, rgba(120, 220, 255, 0.2), rgba(8, 18, 36, 0.72) 70%);
  box-shadow: 0 0 26px rgba(60, 180, 255, 0.22), inset 0 0 18px rgba(90, 210, 255, 0.12);
}

.end-step {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-size: clamp(9px, 1.9vh, 11px);
  letter-spacing: 0.28em;
  color: var(--cyan-soft);
  opacity: 0.85;
}

.end-title {
  margin: 0 0 8px;
  font-size: clamp(19px, 4.4vh, 27px);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #f2fbff;
  text-shadow: 0 0 20px rgba(90, 200, 255, 0.35);
}

.end-text {
  margin: 0;
  white-space: pre-line;
  font-size: clamp(13px, 2.9vh, 16px);
  line-height: 1.6;
  color: #d6e6f7;
  word-break: keep-all;
}

.end-dots {
  display: flex;
  gap: 7px;
  justify-content: center;
  margin: clamp(10px, 2.2vh, 16px) 0 0;
}
.end-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(140, 180, 220, 0.28);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}
.end-dots i.on {
  background: var(--cyan-soft);
  box-shadow: 0 0 9px rgba(120, 240, 255, 0.75);
}

.end-tap {
  margin: clamp(8px, 1.8vh, 14px) 0 0;
  font-size: clamp(10px, 2.1vh, 12px);
  letter-spacing: 0.06em;
  color: var(--muted);
  animation: endTapPulse 1.9s ease-in-out infinite;
}
@keyframes endTapPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* --- 결과 카드 — 승리 버전 --- */
#result .result-rays {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 160vmax;
  height: 160vmax;
  margin: -80vmax 0 0 -80vmax;
  z-index: 0;
  opacity: 0;
  pointer-events: none;
  background: conic-gradient(
    from 0deg,
    rgba(255, 205, 115, 0.16) 0deg 5deg,
    rgba(255, 205, 115, 0) 5deg 24deg,
    rgba(255, 230, 170, 0.12) 24deg 28deg,
    rgba(255, 230, 170, 0) 28deg 48deg
  );
}
#result.win .result-rays { opacity: 0; animation: none; }
#result .panel { z-index: 1; }
/* V12 — 결과 카드는 오로지 한 번, 아래에서 도란도란 올라온다 */
#result .panel { animation: resultRise 0.62s cubic-bezier(0.16, 0.9, 0.2, 1) both; }
@keyframes resultRise {
  0% { opacity: 0; transform: translateY(26px) scale(0.988); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

#result.win .panel {
  border-color: rgba(255, 208, 125, 0.34);
  box-shadow: 0 0 0 1px rgba(255, 205, 120, 0.10), 0 22px 70px rgba(0, 0, 0, 0.68),
    0 0 70px rgba(255, 165, 60, 0.14);
  background: linear-gradient(180deg, rgba(20, 17, 12, 0.97), rgba(9, 8, 7, 0.985));
}
#result.win .panel::after {
  content: none;
  position: absolute;
  inset: -1px;
  border-radius: 14px;
  pointer-events: none;
  background: linear-gradient(115deg, rgba(255, 240, 200, 0) 35%, rgba(255, 240, 200, 0.22) 48%, rgba(255, 240, 200, 0) 60%);
  background-size: 260% 100%;
  animation: resultShine 3.6s ease-in-out infinite;
}
@keyframes resultShine {
  0% { background-position: 180% 0; }
  60%, 100% { background-position: -80% 0; }
}

#result.win .result-title {
  background: linear-gradient(180deg, #fffdf4 0%, #ffe6ad 52%, #ffb547 76%, #ff8a2c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 26px rgba(255, 190, 80, 0.7));
}
/* V12 — 금빛 카드에 맞춰 버튼도 차분하게 물들인다 */
#result.win .btn.primary {
  background: linear-gradient(180deg, #ffe3a6, #f0a53a);
  border-color: rgba(255, 226, 170, 0.75);
  color: #2b1c05;
  box-shadow: 0 6px 24px rgba(255, 160, 40, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
#result.win .btn.primary:hover {
  box-shadow: 0 8px 30px rgba(255, 175, 60, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
#result.win .btn.ghost {
  border-color: rgba(255, 208, 125, 0.32);
  color: #e8c691;
}
#result.win .btn.ghost:hover { color: #fff3d8; border-color: rgba(255, 216, 145, 0.55); }
#result.win .eyebrow { color: #ffe3ac; }

#result.win .stat.hi {
  border-color: rgba(255, 205, 120, 0.26);
  background: linear-gradient(180deg, rgba(255, 190, 90, 0.10), rgba(255, 190, 90, 0.03));
  animation: none;
}
#result.win .stat.hi b { color: #ffe9bd; text-shadow: 0 0 18px rgba(255, 180, 60, 0.55); }
#result.win .stat.hi .stat-label { color: #f0cf94; }
@keyframes statGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 170, 60, 0); }
  50% { box-shadow: 0 0 26px rgba(255, 170, 60, 0.26); }
}

/* 축하 배지 */
.result-badge {
  font-size: clamp(38px, 9vw, 52px);
  line-height: 1;
  margin: -6px 0 2px;
  filter: drop-shadow(0 0 24px rgba(255, 190, 70, 0.9));
  animation: badgePop 0.9s cubic-bezier(0.2, 1.5, 0.4, 1) both, badgeFloat 3.4s ease-in-out 0.9s infinite;
}
@keyframes badgePop {
  0% { transform: scale(0.15) rotate(-22deg); opacity: 0; }
  70% { transform: scale(1.12) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
@keyframes badgeFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* 색종이 */
.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 14px;
  pointer-events: none;
  z-index: 2;
}
.confetti {
  position: absolute;
  top: -14%;
  display: block;
  border-radius: 2px;
  opacity: 0;
  animation-name: confettiFall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(-10%) rotate(0deg); opacity: 0; }
  8% { opacity: 0.95; }
  100% { transform: translateY(620px) rotate(620deg); opacity: 0; }
}

@media (max-width: 430px) {
  .wc-sub { letter-spacing: 0.08em; }
  .result-badge { margin-top: -10px; }
}

/* ---------- V11 · 모바일 가로모드(낮은 화면) — 타이틀·옵션·결과 카드가 위로 잘리지 않고 한눈에 ----------
   844×390 같은 ‘짧은 높이’에서는 타이틀 내용(키보드 안내 포함)이 화면보다 길어
   가운데 정렬 상태에서 위쪽 제목이 스크롤로도 닿지 않게 잘렸다.
   → 정렬은 위에서 시작(flex-start)하고 여백·글자·버튼을 콤팩트하게 줄여
     ‘우주전쟁’ 제목부터 START 버튼까지 스크롤 없이 한 화면에 들어오게 한다.
   844×390 / 844×344(주소창 포함) 실측 기준. */
@media (max-height: 540px) {
  /* 오버레이 여백을 줄여 세로 공간을 확보 */
  .overlay {
    padding-top: calc(6px + var(--safe-top));
    padding-bottom: calc(6px + var(--safe-bottom));
  }

  /* --- 타이틀 --- */
  .title-inner { padding: 0; }
  .eyebrow { margin: 0 0 2px; font-size: 10px; letter-spacing: 0.34em; }
  .glow-title { font-size: clamp(24px, 8vh, 34px); }
  .title-sub-line { margin: 2px 0 0; font-size: 9px; letter-spacing: 0.34em; }
  .sub {
    margin: 3px auto 8px;
    max-width: 100%;
    font-size: 11.5px;
    line-height: 1.35;
  }
  .br-desk { display: none; }

  /* 난이도·옵션 박스 */
  .settings {
    gap: 5px;
    width: min(430px, 100%);
    margin: 0 auto 7px;
    padding: 5px 10px;
    border-radius: 10px;
  }
  .setting-row { gap: 10px; }
  .setting-label { font-size: 11px; }
  .segmented { padding: 2px; gap: 2px; }
  .segmented button { padding: 4px 10px; font-size: 11.5px; }
  .diff-hint { margin: 0; font-size: 9.5px; line-height: 1.3; }

  /* 스테이지 1~4 칩 (이제 조작법 페이지 안) */
  .ht-sec .stage-chip {
    gap: 1px;
    padding: 3px 2px 2px;
    border-radius: 8px;
    font-size: 8.5px;
  }
  .ht-sec .stage-chip b { font-size: 12px; }

  /* START 버튼과 상태 문구 */
  #btnStart.btn.big {
    padding: 8px 34px;
    font-size: 15px;
    letter-spacing: 0.1em;
  }
  /* V22 — 낮은 화면에서도 「이어서 하기」가 한 줄에 작게 들어가게 */
  .btn.resume { margin-top: 4px; padding: 6px 18px; font-size: 12.5px; }
  #questionsStatus,
  #bestScore { margin-top: 5px; font-size: 10.5px; }

  /* 조작법 페이지 — 844×390 처럼 낮은 화면에서도 카드가 화면을 넘지 않게 */
  #howto .howto-panel {
    max-height: calc(100dvh - 12px - var(--safe-top) - var(--safe-bottom));
    padding: 9px 13px 8px;
    border-radius: 12px;
  }
  #howto .eyebrow { display: none; }
  #howto .panel-title { margin: 0 0 3px; font-size: 16px; }
  #howto .howto-lead { margin: 0 0 7px; font-size: 10.5px; }
  #howto .ht-scroll { gap: 6px; }
  #howto .ht-sec { padding: 6px 10px 7px; border-radius: 9px; }
  #howto .ht-head { margin: 0 0 4px; font-size: 11.5px; }
  #howto .ht-list { gap: 3px; }
  #howto .ht-list li { padding-left: 12px; font-size: 11.5px; line-height: 1.45; }
  #howto .ht-list li::before { top: 0.55em; width: 4px; height: 4px; }
  #howto .ht-note { margin-top: 4px; font-size: 10px; line-height: 1.45; }
  #howto .ht-sec .stage-list { gap: 4px; }
  #howto .ht-sec .stage-chip { font-size: 8px; padding: 2px 1px; }
  #howto .ht-sec .stage-chip b { font-size: 10.5px; }
  #howto .ht-sec .diff-hint { font-size: 10px; }
  #howto .panel-actions { margin-top: 8px; }
  #howto .panel-actions .btn { padding: 6px 20px; font-size: 12.5px; }

  /* 타이틀의 세 버튼도 한 줄에 납작하게 */
  .title-actions { gap: 7px; margin-top: 9px; }
  .title-actions .btn { font-size: 11.5px; padding: 6px 12px; border-radius: 8px; }
  .title-actions .btn .fs-ico { font-size: 1em; }

  /* --- 옵션 창 --- */
  #options .panel { padding: 10px 14px 9px; border-radius: 12px; }
  #options .panel-title { margin: 0 0 4px; font-size: 17px; }
  #options .opt-list { gap: 5px; margin: 2px 0 0; }
  #options .opt-row {
    grid-template-columns: 1fr 116px auto;
    gap: 8px;
    padding: 3px 9px;
    border-radius: 8px;
  }
  #options .opt-label { font-size: 11.5px; }
  #options .opt-val { font-size: 11px; }
  #options input[type="range"] { height: 18px; }
  #options .toggle { min-width: 52px; padding: 4px 10px; font-size: 11px; }
  #options .panel-actions { gap: 8px; margin-top: 8px; }
  #options .panel-actions .btn { padding: 6px 16px; font-size: 12.5px; }

  /* --- 결과(승리/패배) 카드 --- */
  #result .panel { padding: 10px 16px; }
  #result .result-badge { margin: -6px 0 0; font-size: 28px; }
  #result .eyebrow { margin: 0 0 2px; font-size: 9.5px; }
  #result .result-title { margin: 0 0 4px; font-size: clamp(18px, 4.4vh, 26px); }
  #result .panel-sub { margin: 0 0 6px; font-size: 11px; line-height: 1.4; }
  #result .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    margin: 8px 0 4px;
  }
  /* 7개 통계 — 마지막 한 칸은 가운데 칸에 놓아 줄이 어긋나 보이지 않게 */
  #result .stat-grid .stat:last-child:nth-child(odd) { grid-column: 2; }
  #result .stat { gap: 3px; padding: 4px 6px; border-radius: 8px; }
  #result .stat-label { font-size: 8px; letter-spacing: 0.04em; }
  #result .stat b { font-size: 12px; }
  #result .status { margin-top: 4px; font-size: 10px; }
  #result .result-hint { margin-top: 6px; font-size: 10.5px; }
  #result .panel-actions { gap: 8px; margin-top: 8px; }
  #result .panel-actions .btn { padding: 7px 18px; font-size: 12.5px; }

  /* --- V20 엔딩 스토리 카드 — 844×344 에서도 잘림·스크롤 없이 --- */
  .ending {
    padding: calc(4px + var(--safe-top)) calc(10px + var(--safe-right)) calc(4px + var(--safe-bottom)) calc(10px + var(--safe-left));
  }
  .end-card {
    width: min(680px, 100%);
    padding: 12px 20px 10px;
    border-radius: 12px;
  }
  .end-art {
    width: 40px;
    height: 40px;
    margin: 0 auto 4px;
    font-size: 20px;
  }
  .end-step { margin: 0 0 2px; font-size: 9.5px; letter-spacing: 0.24em; }
  .end-title { margin: 0 0 5px; font-size: 18px; }
  .end-text { font-size: 13.5px; line-height: 1.45; }
  .end-dots { gap: 6px; margin-top: 8px; }
  .end-dots i { width: 6px; height: 6px; }
  .end-tap { margin-top: 6px; font-size: 10.5px; }
}
