:root {
  --bg-deep: #0f0f1e;
  --bg-mid: #1a1a2e;
  --bg-card: #252542;
  --text-primary: #f5f5fa;
  --text-secondary: #a8a8c0;
  --accent: #ffd93d;
  --danger: #ff6b6b;
  --success: #4ecdc4;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

/* user-select:none 은 일부 모바일 브라우저에서 click 이벤트와 간섭하므로
   게임 화면 컨텐츠에만 한정해서 적용 (텍스트 드래그/하이라이트 방지 목적). */
.screen, .game-card, .cta-btn {
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", "Noto Sans KR", sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.4;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: inherit;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.screen.active {
  display: flex;
}

/* ───── 스플래시 ───── */
.splash-screen {
  background: radial-gradient(ellipse at top, #2a1a4a 0%, #1a1a2e 45%, #0f0f1e 100%);
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.32s ease;
}
.splash-screen.splash-fade-out {
  opacity: 0;
  pointer-events: none;
}

.splash-logo {
  width: 96px;
  height: 96px;
  color: var(--accent);
  filter: drop-shadow(0 14px 28px rgba(255, 217, 61, 0.45));
  animation: splashPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.splash-logo svg {
  display: block;
  width: 100%;
  height: 100%;
}
.splash-bg {
  fill: currentColor;
  opacity: 0.14;
}

.splash-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffd93d 0%, #ff6b6b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: splashIn 0.5s ease 0.12s both;
}

.splash-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  animation: splashIn 0.5s ease 0.22s both;
}

@keyframes splashPop {
  0%   { opacity: 0; transform: scale(0.6); }
  60%  { transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes splashIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ───── 메인 메뉴 ───── */
.menu-header {
  text-align: center;
  padding: 32px 20px 20px;
}

.title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffd93d 0%, #ff6b6b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.version-tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  margin-left: 4px;
  border-radius: 6px;
  background: rgba(255, 217, 61, 0.18);
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.game-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 16px 20px;
  align-content: center;
  overflow-y: auto;
}

.game-card {
  position: relative;
  height: 140px;
  background: var(--bg-card);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.12s ease, background 0.2s ease;
  border: 2px solid transparent;
  overflow: hidden;
}

.game-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--card-color);
  opacity: 0.12;
  transition: opacity 0.2s ease;
  pointer-events: none; /* 모바일에서 탭이 ::before 에 막히지 않게 */
  border-radius: inherit;
}

/* :active 상태에서 transform 을 쓰면, 손가락 떼는 순간 카드가 살짝 작아져서
   터치 종료 좌표가 카드 바깥으로 빠지면서 click 이벤트가 안 올라오는 일부
   모바일 브라우저 이슈가 있음. 시각 피드백은 ::before 의 opacity 로만. */
.game-card:active::before {
  opacity: 0.32;
}
.game-card:active {
  filter: brightness(1.08);
}

.card-icon {
  width: 56px;
  height: 56px;
  color: var(--card-color);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.28));
}

.card-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* 게임 인트로(시작 화면)에서 사용하는 동일한 SVG 아이콘 — 더 크게 */
.intro-icon {
  width: 76px;
  height: 76px;
  color: var(--card-color);
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.32));
}

.intro-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ───── 결과 화면 ───── */
.result-icon {
  width: 60px;
  height: 60px;
  color: var(--card-color);
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.3));
}
.result-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.result-score {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.result-score .result-unit {
  font-size: 24px;
  font-weight: 600;
  margin-left: 3px;
  opacity: 0.85;
}

.result-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.result-badge.new-best-badge {
  background: linear-gradient(135deg, #ffd93d 0%, #ff6b6b 100%);
  color: var(--bg-deep);
  animation: bestPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.result-badge.first-badge {
  background: rgba(78, 205, 196, 0.18);
  color: var(--success);
}

@keyframes bestPop {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.18); }
  100% { transform: scale(1); opacity: 1; }
}

.result-compare {
  font-size: 13px;
  color: var(--text-secondary);
}

.result-extra {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.85;
  max-width: 320px;
  line-height: 1.6;
}

.icon-bg {
  fill: currentColor;
  opacity: 0.16;
}

.icon-stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-fill {
  fill: currentColor;
}

.icon-arc {
  opacity: 0.75;
}

.icon-tick,
.icon-grid,
.icon-spark {
  opacity: 0.58;
}

.icon-route {
  stroke-width: 5;
}

.icon-dot,
.icon-panel {
  stroke: rgba(255, 255, 255, 0.68);
  stroke-width: 1.5;
}

.dot-red {
  fill: #ff6b6b;
}

.dot-yellow,
.panel-yellow {
  fill: #ffd93d;
}

.dot-blue,
.panel-blue {
  fill: #60a5fa;
}

.panel-red {
  fill: #ff6b6b;
}

.panel-green {
  fill: #4ecdc4;
}

.card-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-best {
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.menu-footer {
  padding: 12px 20px 16px;
}

.ad-placeholder {
  height: 50px;
  border: 1px dashed var(--text-secondary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.4;
}

/* ───── 게임 헤더 ───── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px;
  gap: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: var(--bg-mid);
}

.back-btn {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: 10px;
  transition: background 0.15s;
}

.back-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.game-title-text {
  font-size: 16px;
  font-weight: 700;
}

.game-score {
  font-size: 14px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  text-align: right;
}

.game-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ───── 공통 게임 UI 컴포넌트 ───── */
.center-stack {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  gap: 16px;
}

.big-text {
  font-size: 48px;
  font-weight: 800;
  line-height: 1.1;
}

.medium-text {
  font-size: 22px;
  font-weight: 600;
}

.small-text {
  font-size: 14px;
  color: var(--text-secondary);
}

.cta-btn {
  background: var(--accent);
  color: var(--bg-deep);
  font-weight: 700;
  padding: 14px 32px;
  border-radius: 999px;
  font-size: 16px;
  margin-top: 16px;
  transition: transform 0.12s, opacity 0.2s;
}

.cta-btn:active {
  filter: brightness(0.92);
  opacity: 0.92;
}

.cta-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

/* 결과 화면 액션 (다시 도전 + 공유) */
.result-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.result-actions .cta-btn {
  margin-top: 0;
}
.result-actions .share-btn {
  padding: 10px 22px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ───── 메뉴 우상단 아이콘 행 (통계 / 설정) ───── */
.menu-actions {
  position: absolute;
  top: calc(var(--safe-top) + 14px);
  right: 14px;
  display: flex;
  gap: 8px;
  z-index: 10;
}
.menu-icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s, transform 0.12s;
}
.menu-icon-btn:active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}
#settings-btn:active {
  transform: rotate(20deg);
}
#stats-btn:active {
  transform: scale(0.92);
}

/* ───── 스트릭 배너 (메인 메뉴 헤더 아래) ───── */
.streak-banner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 5px 14px 5px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.22), rgba(255, 217, 61, 0.22));
  border: 1px solid rgba(255, 217, 61, 0.35);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  animation: streakIn 0.4s ease;
}
.streak-banner[hidden] {
  display: none;
}
.streak-fire {
  font-size: 14px;
  filter: drop-shadow(0 0 6px rgba(255, 159, 67, 0.6));
}
@keyframes streakIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ───── 통계 화면 ───── */
.stats-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 24px;
  gap: 14px;
  overflow-y: auto;
}

.stats-summary {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.stats-card {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
}

.stats-num {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stats-label {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.stats-section-title {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stats-section-meta {
  font-size: 12px;
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.stats-games {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stats-game-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 10px 14px;
  position: relative;
  overflow: hidden;
}

.stats-game-row::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--card-color);
  opacity: 0.10;
  pointer-events: none;
  border-radius: inherit;
}

.stats-game-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  color: var(--card-color);
  position: relative;
}
.stats-game-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.stats-game-meta {
  flex: 1;
  min-width: 0;
  position: relative;
}

.stats-game-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.stats-game-detail {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.achievement-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-bottom: 8px;
}

.achievement {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 14px 12px;
  text-align: center;
  opacity: 0.45;
  transition: opacity 0.2s, transform 0.15s;
  border: 1px solid transparent;
}

.achievement.unlocked {
  opacity: 1;
  border-color: rgba(255, 217, 61, 0.35);
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(255, 217, 61, 0.07) 100%);
}

.achievement-icon {
  font-size: 28px;
  line-height: 1.2;
  filter: grayscale(0.85);
  transition: filter 0.2s;
}

.achievement.unlocked .achievement-icon {
  filter: grayscale(0);
}

.achievement-label {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.achievement-desc {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ───── 설정 화면 ───── */
.settings-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 14px;
  overflow-y: auto;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border-radius: 14px;
  padding: 14px 16px;
}

.settings-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.settings-icon {
  font-size: 20px;
}

.settings-action {
  margin-top: 6px;
  padding: 14px 18px;
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
  border-radius: 14px;
  font-weight: 700;
  font-size: 14px;
  transition: background 0.15s;
}
.settings-action:active {
  background: rgba(255, 107, 107, 0.22);
}

.settings-section-title {
  margin-top: 14px;
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding-left: 4px;
}

.settings-link {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s;
}
.settings-link:active {
  background: rgba(255, 255, 255, 0.05);
}
.settings-link-icon {
  font-size: 18px;
  flex-shrink: 0;
}
.settings-link-text {
  flex: 1;
}
.settings-link-arrow {
  color: var(--text-secondary);
  font-size: 22px;
  line-height: 1;
  font-weight: 400;
}

.settings-info {
  margin-top: auto;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 16px 0;
}

/* ───── 토글 스위치 ───── */
.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  cursor: pointer;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-track {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  transition: background 0.18s;
}
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s, background 0.18s;
}
.toggle input:checked + .toggle-track {
  background: var(--accent);
}
.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(20px);
  background: var(--bg-deep);
}

/* 알림 토스트 */
.toast {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 100;
  animation: toastIn 0.25s ease, toastOut 0.25s ease 1.4s forwards;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translate(-50%, -10px); }
}
