/* styles.css — 픽셀대시 네온 황혼 디자인 시스템
 * 캔버스는 논리 320x180 을 CSS 로 16:9 레터박스 확대(image-rendering:pixelated).
 * HUD/메뉴는 DOM 오버레이(접근성·선명한 한글). CRT 스캔라인/비네트는 CSS 오버레이.
 */
:root {
  --bg: #0d0221;
  --indigo: #241b3a;
  --purple: #5b2a86;
  --magenta: #c43d7e;
  --amber: #ff7b54;
  --gold: #ffd166;
  --cyan: #29e7f5;
  --white: #f5f3f7;
  --ground: #10121a;
  --ink: #f5f3f7;
  --muted: #9a8fb5;
  --line: rgba(196, 61, 126, 0.35);
  --panel: rgba(13, 2, 33, 0.92);
  --ff-pixel: "DungGeunMo", "Press Start 2P", system-ui, monospace;
  --ff-disp: "Press Start 2P", "DungGeunMo", monospace;
}
/* ===== 3-way theme (Light/Dark/System) — base :root above = native DARK. Opposite (light) WCAG-aware auto-generated (contrast-solving ink/accent vs worst-case surface). ===== */
:root[data-theme="light"]{
  --bg: #f5f4f6;
  --indigo: #765db3;
  --purple: #8d4cc7;
  --magenta: #bb3978;
  --amber: #cc2f00;
  --gold: #8f6400;
  --cyan: #067780;
  --white: #7a6292;
  --ground: #5e6a99;
  --ink: #5c4a6e;
  --muted: #746599;
  --line: rgba(0,0,0,0.10);
  /* 라이트: 패널을 순백으로 분리 — 페이지(--bg #f5f4f6)와 동색이라 메뉴 카드가 묻히던
     문제 해소 + 텍스트 대비 상승(≈4.7→5.2:1) (design-review) */
  --panel: #ffffff;
}












* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ff-pixel);
  -webkit-font-smoothing: none;
  overscroll-behavior: none;
}
body { overflow: hidden; }

.num { font-family: var(--ff-disp); font-size: 0.78em; letter-spacing: 0; line-height: 1.4; }

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(196,61,126,0.18), transparent 60%),
    radial-gradient(100% 70% at 50% 110%, rgba(91,42,134,0.25), transparent 60%),
    var(--bg);
}

/* ── 게임 스테이지(캔버스) 영역 ─────────────────────── */
.stage-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage {
  position: relative;
  width: min(100%, calc(100vh * 16 / 9));
  width: min(100%, calc(100dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: 100%;
  background: #000;
  box-shadow: 0 0 0 2px rgba(196,61,126,0.25), 0 0 60px rgba(91,42,134,0.4);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* CRT 오버레이 */
.crt-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0.16) 0 1px, transparent 1px 3px),
    radial-gradient(120% 120% at 50% 50%, transparent 60%, rgba(0,0,0,0.45) 100%);
  mix-blend-mode: multiply;
  animation: crtDrift 8s linear infinite;
}
body.crt-on .crt-overlay { opacity: 1; }
body.no-motion .crt-overlay { animation: none; }
@keyframes crtDrift {
  0% { background-position: 0 0, 0 0; }
  100% { background-position: 0 3px, 0 0; }
}

/* ── HUD ────────────────────────────────────────────── */
.hud {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.2% 1.6%;
  font-size: clamp(9px, 2.2vw, 15px);
  color: var(--white);
  text-shadow: 0 0 6px rgba(13,2,33,0.9), 2px 2px 0 #0d0221;
}
.hud-left, .hud-right { display: flex; flex-direction: column; gap: 2px; }
.hud-right { align-items: flex-end; }
.hud-hearts { color: var(--magenta); letter-spacing: 1px; }
.hud-stage { font-size: 0.9em; color: var(--cyan); }
.hud-coins { color: var(--gold); }
.hud-combo { color: var(--amber); min-height: 1em; }
.hud-time { color: var(--white); }
.hud-btn {
  pointer-events: auto;
  margin-top: 4px;
  background: rgba(13,2,33,0.7);
  color: var(--cyan);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: var(--ff-pixel);
  font-size: 0.9em;
  cursor: pointer;
}
.hud-btn:hover { background: var(--magenta); color: #fff; }
.tip-touch {
  position: absolute;
  bottom: 2%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7em;
  color: var(--muted);
  white-space: nowrap;
  text-align: center;
  opacity: 0.7;
}

/* ── 뷰 오버레이(전체 화면) ─────────────────────────── */
.view {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 4%;
  overflow-y: auto;
  background: rgba(5,1,15,0.72);
  backdrop-filter: blur(2px);
}
.view.active { display: flex; }

/* ── HOME ───────────────────────────────────────────── */
.home-inner {
  width: min(680px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 0 50px rgba(196,61,126,0.25), inset 0 0 30px rgba(91,42,134,0.2);
}
.home-top { text-align: center; margin-bottom: 14px; }
.logo {
  font-family: var(--ff-disp);
  font-size: clamp(18px, 5vw, 30px);
  margin: 0;
  letter-spacing: 1px;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(41,231,245,0.6), 3px 3px 0 var(--magenta);
}
.logo-accent { color: var(--gold); text-shadow: 0 0 12px rgba(255,209,102,0.6), 3px 3px 0 var(--magenta); }
.hero { margin: 8px 0 2px; font-size: 1.3em; color: var(--white); text-shadow: 0 0 10px rgba(255,209,102,0.35); }
.subhero { margin: 0; color: #c9bce0; font-size: 0.92em; line-height: 1.5; }

.home-stats { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.stat {
  flex: 1;
  text-align: center;
  background: rgba(91,42,134,0.18);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}
.stat-k { display: block; font-size: 0.7em; color: var(--muted); }
.stat-v { display: block; color: var(--gold); font-size: 1em; margin-top: 2px; }

.section-cap { color: var(--cyan); font-size: 0.85em; margin: 10px 0 6px; }
.home-endless-row { text-align: center; margin: 4px 0 2px; }
.endless-btn { color: var(--gold); border-color: rgba(255,209,102,0.5); }

.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.stage-card {
  position: relative;
  text-align: left;
  background: linear-gradient(160deg, rgba(91,42,134,0.35), rgba(36,27,58,0.6));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  font-family: var(--ff-pixel);
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 8px;
  row-gap: 1px;
  transition: transform 0.08s, box-shadow 0.12s, border-color 0.12s;
}
.stage-card {
  box-shadow: 0 0 0 1px rgba(196,61,126,0.08), 0 2px 10px rgba(13,2,33,0.5);
}
.stage-card:not(.locked):hover { transform: translateY(-3px); border-color: var(--cyan); box-shadow: 0 0 18px rgba(41,231,245,0.45), 0 6px 18px rgba(13,2,33,0.6); }
.stage-card:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.stage-card.locked { opacity: 0.72; cursor: not-allowed; filter: grayscale(0.45) brightness(0.7); }
.sc-num { grid-row: 1 / 4; align-self: center; font-family: var(--ff-disp); color: var(--gold); font-size: 1.1em; }
.sc-name { color: var(--white); }
.sc-region { font-size: 0.72em; color: var(--muted); }
.sc-stars { color: var(--gold); font-size: 0.78em; }
.sc-best { font-size: 0.7em; color: var(--cyan); }
.sc-lock { position: absolute; top: 6px; right: 8px; }

/* ── 도움말/설정 ───────────────────────────────────── */
.how { margin: 8px 0 12px; border: 1px solid var(--line); border-radius: 8px; background: rgba(13,2,33,0.4); }
.how-sum { cursor: pointer; padding: 8px 10px; color: var(--cyan); font-size: 0.9em; }
.how-body { padding: 0 10px 10px; font-size: 0.82em; color: var(--muted); line-height: 1.7; }
.how-body b { color: var(--white); }
.kbd {
  display: inline-block; background: rgba(41,231,245,0.14); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 5px; color: var(--cyan); font-size: 0.9em;
}
.settings { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 12px; }
.settings legend { color: var(--cyan); font-size: 0.8em; padding: 0 6px; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 0.85em; cursor: pointer; color: var(--muted); }
.toggle input { accent-color: var(--magenta); width: 16px; height: 16px; }
.home-foot { text-align: center; color: var(--muted); font-size: 0.7em; margin-top: 10px; opacity: 0.8; }

/* ── 패널(pause/clear) ─────────────────────────────── */
.panel {
  width: min(440px, 100%);
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 22px 18px;
  box-shadow: 0 0 60px rgba(196,61,126,0.3);
}
.panel-title { font-family: var(--ff-disp); color: var(--cyan); margin: 0 0 12px; font-size: 1.3em; text-shadow: 0 0 10px rgba(41,231,245,0.5); }
.clear-stars { font-size: 2em; letter-spacing: 4px; margin: 6px 0 4px; }
.clear-stars .star { color: #4a3560; }
.clear-stars .star.on { color: var(--gold); text-shadow: 0 0 12px rgba(255,209,102,0.7); }
.clear-msg { color: var(--amber); margin: 4px 0 10px; font-size: 0.9em; min-height: 1.2em; }
.clear-metrics { display: flex; gap: 10px; justify-content: center; margin: 8px 0 14px; }
.cm { background: rgba(91,42,134,0.2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
.cm-k { display: block; font-size: 0.7em; color: var(--muted); }
.cm-v { display: block; color: var(--white); margin-top: 2px; }
.panel-actions { display: flex; flex-direction: column; gap: 8px; }
.panel-note { color: var(--muted); font-size: 0.72em; margin-top: 10px; }

.btn {
  font-family: var(--ff-pixel);
  font-size: 0.95em;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(91,42,134,0.3);
  color: var(--white);
  cursor: pointer;
  transition: transform 0.08s, background 0.12s, box-shadow 0.12s;
}
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn.primary {
  background: linear-gradient(180deg, var(--magenta), #8e265b);
  border-color: var(--magenta);
  box-shadow: 0 0 18px rgba(196,61,126,0.5);
}
.btn.primary:hover { box-shadow: 0 0 26px rgba(196,61,126,0.8); }
.btn.ghost { background: transparent; color: var(--muted); }

/* ── 토스트 ────────────────────────────────────────── */
.toast {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: 12%;
  transform: translate(-50%, 10px);
  background: rgba(13,2,33,0.95);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 0 20px rgba(41,231,245,0.3);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── 접근성: 모션 최소화 ───────────────────────────── */
body.no-motion .crt-overlay { animation: none; }
body.no-motion .stage-card,
body.no-motion .btn { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .crt-overlay { animation: none; }
}

/* ── 세로(모바일) 안내 ─────────────────────────────── */
@media (max-width: 640px) and (orientation: portrait) {
  .app::after {
    content: "↻ 가로 모드를 권장해요";
    position: absolute;
    z-index: 30;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(13, 2, 33, 0.88);
    border: 1px solid var(--cyan);
    color: var(--cyan);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.78em;
    pointer-events: none;
    box-shadow: 0 0 16px rgba(41, 231, 245, 0.3);
    white-space: nowrap;
  }
}

/* ── 언어 스위처(네온 다크 테마 덮어쓰기) ───────────── */
/* 스위처 자리표시자: 캔버스 위 좌상단 고정. 게임오버/클리어 패널(z=10)·
   세로안내(z=30) 아래에 두어 오버레이를 가리지 않는다. */
.switch-slot {
  position: absolute;
  top: 1.2%;
  left: 1.2%;
  z-index: 8;
  pointer-events: none;
}
.switch-slot .i18n-switch {
  pointer-events: auto;
  --i18n-switch-bg: rgba(13, 2, 33, 0.72);
  --i18n-switch-border: rgba(196, 61, 126, 0.45);
  --i18n-switch-fg: var(--white);
  --i18n-switch-active-bg: rgba(41, 231, 245, 0.22);
  --i18n-switch-active-fg: var(--cyan);
  --i18n-switch-menu-bg: var(--panel);
  --i18n-switch-menu-border: var(--line);
  --i18n-switch-shadow: 0 0 18px rgba(41, 231, 245, 0.3), 0 4px 14px rgba(0, 0, 0, 0.5);
  /* 패널(z=10)/세로안내(z=30) 아래 */
  --i18n-switch-z: 9;
}
/* 폴백: 자동 주입(fixed) 스위처도 같은 네온 테마 적용 */
.i18n-switch {
  --i18n-switch-bg: rgba(13, 2, 33, 0.72);
  --i18n-switch-border: rgba(196, 61, 126, 0.45);
  --i18n-switch-fg: var(--white);
  --i18n-switch-active-bg: rgba(41, 231, 245, 0.22);
  --i18n-switch-active-fg: var(--cyan);
  --i18n-switch-menu-bg: var(--panel);
  --i18n-switch-menu-border: var(--line);
  --i18n-switch-shadow: 0 0 18px rgba(41, 231, 245, 0.3), 0 4px 14px rgba(0, 0, 0, 0.5);
}

/* .subhero hardcoded color — use readable token in light mode */
:root[data-theme="light"] .subhero { color: var(--muted); }
