:root {
  --bg: #0b0b14;
  --panel: rgba(13, 18, 48, 0.9);
  --line: rgba(255, 255, 255, 0.16);
  --cyan: #2ee6ff;
  --pink: #ff4fd8;
  --yellow: #ffe14d;
  --green: #3dff8a;
  --ink: #0b0b14;
  --muted: #b9bdd3;
  --display: 'Black Han Sans', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --pixel: 'Press Start 2P', monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #000; color: #fff;
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ─────────── 화면 공통 ─────────── */
.screen {
  position: absolute; inset: 0; overflow-y: auto; display: flex; z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(8, 10, 28, 0.72);
  touch-action: pan-y;
}
#scr-result, #scr-settings, #scr-help, #scr-pause, #scr-theme { background: rgba(8, 10, 28, 0.86); }
#scr-title { background: radial-gradient(ellipse at center, rgba(8, 10, 28, 0.35), rgba(8, 10, 28, 0.85)); }
.inner { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 560px; }
.inner.wide { max-width: 860px; }
h2 { font-family: var(--display); font-weight: 400; margin: 0; font-size: 30px; color: var(--yellow); text-align: center; text-shadow: 0 3px 0 var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.btn {
  font-family: var(--display); font-size: 21px; color: #fff; line-height: 1.15;
  background: #1c2350; border: 3px solid var(--cyan); border-radius: 12px;
  padding: 8px 20px; min-width: 200px; cursor: pointer; box-shadow: 0 4px 0 #05061a;
  transition: transform 0.08s, background 0.1s;
}
.btn small { display: block; font-family: inherit; font-size: 12px; color: var(--muted); letter-spacing: 0.3px; }
.btn.small { font-size: 16px; min-width: 110px; padding: 7px 14px; }
.btn.primary { background: var(--pink); color: var(--ink); border-color: #ffd0f4; box-shadow: 0 4px 0 #a3168a; }
.btn.primary small { color: #3a0634; }
.btn:hover, .btn:focus-visible { outline: none; background: var(--yellow); color: var(--ink); border-color: #fff; transform: translateY(-2px); }
.btn:hover small, .btn:focus-visible small { color: #3a2a00; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #05061a; }
.btn.off { opacity: 0.55; }

/* ─────────── 타이틀 ─────────── */
.logo { text-align: center; }
.logo-top { font-family: var(--pixel); font-size: 15px; color: var(--cyan); letter-spacing: 6px; text-shadow: 3px 3px 0 var(--ink); }
.logo-main {
  font-family: var(--pixel); font-size: 48px; line-height: 1.15; color: var(--yellow); margin-top: 8px;
  text-shadow: 4px 4px 0 #b02a9a, 8px 8px 0 var(--ink);
  animation: bob 2.4s ease-in-out infinite;
}
.logo-main span { font-family: var(--display); font-size: 44px; color: #fff; }
.logo-sub { font-family: var(--display); font-size: 15px; color: #fff; margin-top: 8px; text-shadow: 0 2px 0 var(--ink); }
@keyframes bob { 50% { transform: translateY(-4px); } }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.menu .btn { min-width: 0; width: 100%; }
.my-card { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 6px 14px; font-family: var(--display); font-size: 16px; }
.my-card img { width: 30px; height: 20px; border: 1px solid #fff8; }
.my-card .pb { font-family: var(--pixel); font-size: 11px; color: var(--yellow); }
.copyright { font-size: 12px; color: rgba(255, 255, 255, 0.8); text-decoration: none; text-shadow: 0 1px 2px #000; }
.copyright:hover { color: var(--yellow); text-decoration: underline; }
#btn-sound, #btn-menu {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--cyan); background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 18px; cursor: pointer;
}
#btn-sound { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); z-index: 20; }
#hud-btns { position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); z-index: 5; }

/* ─────────── 설정·도움말 ─────────── */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; max-width: 420px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; font-family: var(--display); font-size: 17px; }
.seg { display: flex; gap: 6px; }
.tips { margin: 0; padding: 14px 18px 14px 34px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; line-height: 1.7; font-size: 15px; max-width: 560px; }
.tips b { color: var(--yellow); font-weight: 600; }
kbd { font-family: var(--pixel); font-size: 10px; background: #1c2350; border: 1px solid var(--cyan); border-bottom-width: 3px; border-radius: 5px; padding: 2px 6px; }

/* ─────────── 경기 중 큰 글자 ─────────── */
#callout {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 6; pointer-events: none;
  font-family: var(--display); font-size: clamp(34px, 9vh, 72px); color: #fff; white-space: nowrap; text-align: center;
  text-shadow: 0 4px 0 var(--ink), 0 0 18px rgba(0, 0, 0, 0.6);
}
#callout.pop { animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
#callout.gun { color: var(--yellow); font-size: clamp(48px, 14vh, 110px); }
#callout.bad { color: #ff5a5a; }
#callout.gold { color: var(--yellow); }
#callout small { display: block; font-size: 0.38em; color: #fff; margin-top: 4px; }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* ─────────── 결과 ─────────── */
.res-head { font-family: var(--display); font-size: 36px; color: var(--yellow); text-shadow: 0 3px 0 var(--ink); text-align: center; }
.res-head small { display: block; font-size: 15px; color: #fff; }
.respect { margin: 0; font-family: var(--display); font-size: 16px; color: var(--green); text-align: center; }
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 640px; }
.res-col { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; gap: 3px; }
.res-col.me { border-color: var(--pink); }
.stat-line { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }
.stat-line b { font-family: var(--pixel); font-size: 12px; color: #fff; font-weight: 400; }
.note { font-size: 12.5px; color: var(--muted); margin: 0; text-align: center; }
a.btn { text-decoration: none; display: inline-block; text-align: center; }

/* ─────────── 세로 화면 안내 ─────────── */
#rotate { display: none; position: absolute; inset: 0; z-index: 50; background: var(--bg); flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-family: var(--display); }
#rotate div { font-size: 56px; animation: tilt 1.6s ease-in-out infinite; }
#rotate p { margin: 0; font-size: 20px; }
@keyframes tilt { 50% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 820px) { #rotate { display: flex; } }

/* ─────────── 버튼 위치 ─────────── */
#btn-sound, #btn-menu {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--cyan); background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 18px; cursor: pointer;
}
#btn-sound { position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); z-index: 20; }
#hud-btns { position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); z-index: 5; }
#app.playing #btn-sound { display: none; }
#toast {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); z-index: 30; pointer-events: none;
  background: rgba(11, 11, 20, 0.9); border: 2px solid var(--cyan); border-radius: 12px; padding: 8px 16px; font-family: var(--display); font-size: 16px;
  opacity: 0; transition: opacity 0.25s;
}
#toast.show { opacity: 1; }
#callout.combo { color: var(--yellow); }
#callout.p1 { color: var(--pink); }
#callout.p2 { color: var(--cyan); }
#callout.turn { font-size: clamp(26px, 7vh, 46px); }

/* ─────────── 메모리 카드 타이틀 ─────────── */
.logo-main { font-family: var(--display); font-size: 56px; color: #fff; }
.logo-main span { font-size: inherit; color: var(--yellow); }

/* ─────────── 테마 고르기 ─────────── */
.theme-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; width: 100%; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; cursor: pointer;
  background: #1c2350; border: 3px solid var(--line); border-radius: 12px; color: #fff; font-family: var(--display); font-size: 15px;
  box-shadow: 0 3px 0 #05061a;
}
.tile canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.tile .st { font-family: var(--pixel); font-size: 9px; color: var(--yellow); }
.tile.on { border-color: var(--yellow); background: #3a2a6a; transform: translateY(-2px); box-shadow: 0 0 0 3px rgba(255, 225, 77, 0.25), 0 3px 0 #05061a; }
.theme-foot { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.chip { font-family: var(--display); font-size: 15px; color: #fff; background: #1c2350; border: 2px solid var(--line); border-radius: 9px; padding: 6px 12px; cursor: pointer; }
.chip small { font-size: 11px; color: var(--muted); margin-left: 4px; }
.chip.on { border-color: var(--pink); background: #3a1450; }

/* ─────────── 결과 ─────────── */
.big-stars { font-size: 48px; letter-spacing: 6px; line-height: 1; }
.big-stars i { font-style: normal; display: inline-block; filter: grayscale(1) brightness(0.45); }
.big-stars i.on { filter: none; animation: starPop 0.45s cubic-bezier(.2, 1.6, .4, 1) both; }
.big-stars i:nth-child(2) { animation-delay: 0.25s; }
.big-stars i:nth-child(3) { animation-delay: 0.5s; }
@keyframes starPop { from { transform: scale(0); } to { transform: scale(1); } }
.res-stats { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.res-stat { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 6px 14px; text-align: center; font-size: 13px; color: var(--muted); min-width: 96px; }
.res-stat b { display: block; font-family: var(--pixel); font-size: 15px; color: #fff; font-weight: 400; margin-top: 4px; }
.res-stat.p1 { border-color: var(--pink); }
.res-stat.p2 { border-color: var(--cyan); }
.badge { font-family: var(--display); font-size: 15px; background: var(--yellow); color: var(--ink); border-radius: 8px; padding: 2px 10px; }

/* ─────────── 낮은 가로 화면 (폰) ─────────── */
@media (max-height: 460px) {
  .inner { gap: 8px; }
  .logo-top { font-size: 11px; }
  .logo-main { font-size: 38px; margin-top: 4px; }
  .logo-sub { font-size: 13px; margin-top: 4px; }
  .btn { font-size: 18px; padding: 6px 14px; }
  .btn small { font-size: 11px; }
  .btn.small { font-size: 14px; padding: 5px 12px; }
  h2 { font-size: 22px; }
  .res-head { font-size: 26px; }
  .theme-grid { gap: 6px; }
  .tile { font-size: 13px; padding: 4px 2px; }
  .tile canvas { width: 40px; height: 40px; }
  .chip { font-size: 13px; padding: 4px 9px; }
  .big-stars { font-size: 38px; }
  .tips { font-size: 13.5px; line-height: 1.55; }
}
/* 카드 위에서도 잘 읽히게 큰 글자 뒤에 어두운 바탕 */
#callout { background: rgba(11, 13, 36, 0.8); border-radius: 18px; padding: 4px 24px 8px; }
