/* 안드로이드 res/values/colors.xml 매핑 */
:root {
  --bg-primary: #5b7ba5;
  --bg-secondary: #4a6a94;
  --text-primary: #ffffff;
  --text-secondary: #d0d8e8;
  --accent: #e8945a;
  --accent-dark: #c07840;
  --surface: #ffffff;
  /* ② Dark Premium 공용 배경 그라데이션 (타이틀·게임·튜토리얼 통일) */
  --premium-grad: radial-gradient(120% 80% at 50% 40%, #2a3c57 0%, #1b2740 55%, #121a2b 100%);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  overscroll-behavior: none;
}
#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.screen {
  position: absolute;
  inset: 0;
  display: none;
}
.screen.active {
  display: block;
}
.hidden {
  display: none !important;
}
/* i18n 적용 전 영어 깜빡임(FOUC) 방지 — 번역 준비되면 노출 */
#app {
  visibility: hidden;
}
html.i18n-ready #app {
  visibility: visible;
}

/* 공통 버튼 */
.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary {
  display: block;
  width: 240px;
  max-width: 80vw;
  height: 56px;
  margin: 0 auto;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 28px;
  box-shadow: 0 6px 16px rgba(192, 120, 64, 0.4);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn-primary:active {
  transform: scale(0.97);
  filter: brightness(0.95);
}
.btn-text {
  display: block;
  margin: 10px auto 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 15px;
  font-weight: 600;
  padding: 8px 16px;
}

.gear-btn {
  position: absolute;
  /* 토스 네이티브 헤더가 상단 인셋을 처리하므로 safe-area-top 미적용(빈공간 회수) */
  top: 4px;
  right: 8px;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  z-index: 5;
}

/* ── 타이틀 ───────────────────────────── */
#screen-title {
  background: var(--premium-grad);
}
.title-bg {
  position: absolute;
  inset: -20px; /* blur 가장자리 가림 */
  width: calc(100% + 40px);
  height: calc(100% + 40px);
  object-fit: cover;
  filter: blur(8px);
  opacity: 0; /* 로드 완료 시 .loaded 로 페이드인 (큰 webp 늦게 떠도 툭 안 튐) */
  transition: opacity 0.4s ease;
}
.title-bg.loaded {
  opacity: 0.85;
}
.title-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.19);
}
.glass-card {
  position: absolute;
  z-index: 2; /* 배경 데코(::after 글로우) 위로 카드 유지 */
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  width: calc(100% - 64px);
  max-width: 360px;
  max-height: calc(100% - 24px); /* 짧은 화면에서 화면 밖으로 잘리지 않게(최후 안전망) */
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 24px;
  padding: 40px 24px;
  text-align: center;
}
.title-icon {
  font-size: 64px;
  margin-bottom: 16px;
  line-height: 1;
}
.game-title {
  margin: 0;
  font-size: 48px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.05em;
  text-shadow: 0 3px 6px rgba(0, 0, 0, 0.38);
}
.game-subtitle {
  margin: 6px 0 36px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 0.12em;
}

/* 짧은/가로 화면(예: 가로모드, 낮은 높이)에서 타이틀 카드가 위아래로 잘리지 않게 축소·중앙정렬 */
@media (max-height: 600px) {
  .glass-card {
    top: 50%; /* 42% → 중앙정렬로 상하 여백 균등(상단 클리핑 방지) */
    padding: 22px 24px;
  }
  .title-icon {
    font-size: 44px;
    margin-bottom: 8px;
  }
  .game-title {
    font-size: 34px;
  }
  .game-subtitle {
    margin: 4px 0 18px;
  }
  /* 클리어/설정 다이얼로그도 짧은 화면에서 잘리지 않게 축소 */
  .dialog-card {
    padding: 18px 22px;
  }
  .dialog-emoji {
    font-size: 34px;
  }
  .dialog-title {
    margin: 8px 0 0;
    font-size: 20px;
  }
  .dialog-msg {
    margin: 6px 0 14px;
  }
  .btn-primary {
    height: 48px;
  }
}

/* ── 게임 ─────────────────────────────── */
#screen-game {
  /* 인게임 배경: ② Dark Premium (딥 네이비). 데코는 파일 하단 ::before/::after */
  background: var(--premium-grad);
}
.game-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  /* 콘텐츠 높이 = 기어 버튼 높이 → Level 글자가 기어와 세로 중앙 정렬.
     보드 영역 최대화 위해 최대한 상단으로 바짝. */
  height: 40px;
  padding: 4px 12px 0;
  z-index: 4;
}
.hud-level {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
}
.board-wrap {
  position: absolute;
  /* 상단바(40px) 바로 아래부터 보드. safe-area-top 미적용(토스 헤더가 처리) */
  top: 42px;
  /* 양쪽 기기 마진은 아주 조금만 → 이미지 최대 */
  left: 6px;
  right: 6px;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 하단 여백 최소화(이미지 최대). 배너 모드에선 아래에서 별도 처리 */
  padding-bottom: 1vh;
}
.board-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
}
/* ── 앱인토스 배너 광고 ────────────────────────────────────
   기본 숨김. 실제 배너가 렌더되면 platform.js 가 #app 에 .toss-banner 를
   붙여 노출 + 보드 영역을 배너 높이만큼 확보한다(노필 시 빈 막대 방지). */
.ad-banner {
  display: none;
}
#app.toss-banner .ad-banner {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  /* SDK 래퍼가 height:100% 이므로 컨테이너에 확정 높이 필요.
     토스 실 배너 = AdSize.BANNER(50dp). 64px 는 위아래 레터박스 여백이 생겨 50px 로 밀착.
     하단 safe-area 미적용(토스 네이티브 크롬이 처리 → 중복 48px 제거, 배너를 바닥에 밀착). */
  height: 50px;
  background: var(--bg-primary);
  z-index: 5;
}
#app.toss-banner .board-wrap {
  bottom: 50px;
  /* 배너가 하단 공간을 차지하므로 추가 여백 최소화 → 보드 최대화 */
  padding-bottom: 4px;
}
#board {
  touch-action: none;
  display: block;
}
/* 드래그 셀 오버레이 — board-wrap 전체를 덮어 보드 밖(배경)까지 드래그 셀이 보이게.
   포인터 이벤트는 통과(메인 #board 가 입력 처리). board-stage(글로우/펄스) 위, game-top(z4) 아래. */
.drag-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}
/* 황금빛 글로우 (클리어 축하) */
.board-glow {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: #ffd700;
  opacity: 0;
  pointer-events: none;
}
.board-glow.show {
  animation: jm-glow 700ms ease-out;
}
@keyframes jm-glow {
  0% {
    opacity: 0;
  }
  40% {
    opacity: 0.45;
  }
  100% {
    opacity: 0;
  }
}
/* 보드 펄스 (클리어 축하: 1.0 → 1.05 → 1.0) */
.board-celebrate {
  animation: jm-pulse 600ms ease-in-out;
}
@keyframes jm-pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* ── 튜토리얼 오버레이 ─────────────────── */
.tutorial-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.tutorial-overlay.active {
  display: flex;
}
.tutorial-inner {
  text-align: center;
  padding: 40px;
}
.tut-icon {
  font-size: 64px;
  line-height: 1;
}
.tut-text {
  margin-top: 24px;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}
.tut-continue {
  margin-top: 32px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.67);
}
.tut-dots {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  justify-content: center;
}
.tut-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
}
.tut-dot.active {
  background: #fff;
}

/* ── 다이얼로그 (완료 / 설정) ──────────── */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px; /* 짧은 화면에서 카드가 화면 가장자리에 닿지 않게 */
  background: rgba(0, 0, 0, 0.5);
  z-index: 30;
}
.modal.active {
  display: flex;
}
.dialog-card {
  background: var(--surface);
  color: #222;
  border-radius: 28px;
  padding: 32px 28px;
  width: 320px;
  max-width: 86vw;
  max-height: 100%; /* 짧은/가로 화면에서 잘리지 않게 — 넘치면 내부 스크롤 */
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.dialog-left {
  text-align: left;
}
.dialog-emoji {
  font-size: 48px;
  line-height: 1;
}
.dialog-title {
  margin: 12px 0 0;
  font-size: 24px;
  font-weight: 700;
  color: #222;
}
.dialog-msg {
  margin: 8px 0 24px;
  font-size: 15px;
  color: #666;
}
.dialog-h3 {
  margin: 0 0 20px;
  font-size: 20px;
  font-weight: 700;
  color: #222;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 16px;
  color: #222;
}

/* Material3 스위치 (안드로이드 switch_*_color 그대로) */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.27); /* OFF track #44000000 */
  cursor: pointer;
  outline: none;
  transition: background 0.2s ease;
}
.switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff; /* OFF thumb — 흰색(그림자로 구분). 회색 #bdbdbd 는 OFF 트랙과 동일 명도라 흰 다이얼로그에서 안 보였음 */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); /* Material elevation: 트랙과 분리되어 동그라미가 항상 보임 */
  transition: transform 0.2s ease, background 0.2s ease;
}
.switch:checked {
  background: rgba(91, 123, 165, 0.6); /* ON track #995B7BA5 */
}
.switch:checked::before {
  transform: translateX(18px);
  background: #5b7ba5; /* ON thumb dialog_primary */
}

/* 다이얼로그 하단 액션 영역 + 텍스트 버튼 (Material 다이얼로그 버튼) */
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}
.btn-dialog {
  background: transparent;
  border: none;
  cursor: pointer;
  color: #5b7ba5; /* dialog_primary */
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 12px;
  border-radius: 8px;
}
.btn-dialog:active {
  background: rgba(91, 123, 165, 0.12);
}

/* ── 인터랙티브 튜토리얼 ───────────────────────── */
.tut-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 8px calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--premium-grad);
}
.tut-screen.active {
  display: flex;
}
.tut-head {
  position: relative;
  z-index: 1; /* 배경 데코 위로 */
  flex: 0 0 auto;
  text-align: center;
  max-width: 92vw;
}
.tut-h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.tut-p {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-secondary);
}
.tut-stage-wrap {
  position: relative;
  z-index: 1; /* 배경 데코 위로 */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0; /* flex 자식이 줄어들 수 있게 → 보드가 가용공간 꽉 채움 */
  padding: 0 4px;
}
.tut-stage {
  position: relative;
  display: inline-block;
  /* 실제 크기는 JS(board.layout)가 캔버스 기준으로 지정 */
  /* border-radius 제거: 둥근 모서리가 사각 사진의 네 귀퉁이를 잘랐음(게임 보드와 동일하게 각지게) */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
#tut-board {
  display: block;
}
/* 손가락 가이드 + 탭 링 (보드 좌표계 = stage 좌상단 기준) */
.tut-hand,
.tut-ring {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  will-change: transform, opacity;
}
.tut-hand {
  width: 50px;
  height: 50px;
  opacity: 0;
  /* 손끝(검지 끝)이 아이콘 박스의 (40%,12%) 지점 → transform 앵커를 손끝에 맞춤 */
  transform-origin: 40% 12%;
  /* 네모네모 출시본과 동일: Tabler hand-finger (흰 채움 + 블루 외곽선, 기기 무관 동일) */
  background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cg%20fill%3D%22none%22%20stroke%3D%22%23ffffff%22%20stroke-width%3D%224%22%3E%3Cpath%20d%3D%22M8%2013v-8.5a1.5%201.5%200%200%201%203%200v7.5%22%2F%3E%3Cpath%20d%3D%22M11%2011.5v-2a1.5%201.5%200%201%201%203%200v2.5%22%2F%3E%3Cpath%20d%3D%22M14%2010.5a1.5%201.5%200%200%201%203%200v1.5%22%2F%3E%3Cpath%20d%3D%22M17%2011.5a1.5%201.5%200%200%201%203%200v4.5a6%206%200%200%201%20-6%206h-2h.208a6%206%200%200%201%20-5.012%20-2.7a69.74%2069.74%200%200%201%20-.196%20-.3c-.312%20-.479%20-1.407%20-2.388%20-3.286%20-5.728a1.5%201.5%200%200%201%20.536%20-2.022a1.867%201.867%200%200%201%202.28%20.28l1.47%201.47%22%2F%3E%3C%2Fg%3E%3Cg%20fill%3D%22%23ffffff%22%20stroke%3D%22%2315538f%22%20stroke-width%3D%222%22%3E%3Cpath%20d%3D%22M8%2013v-8.5a1.5%201.5%200%200%201%203%200v7.5%22%2F%3E%3Cpath%20d%3D%22M11%2011.5v-2a1.5%201.5%200%201%201%203%200v2.5%22%2F%3E%3Cpath%20d%3D%22M14%2010.5a1.5%201.5%200%200%201%203%200v1.5%22%2F%3E%3Cpath%20d%3D%22M17%2011.5a1.5%201.5%200%200%201%203%200v4.5a6%206%200%200%201%20-6%206h-2h.208a6%206%200%200%201%20-5.012%20-2.7a69.74%2069.74%200%200%201%20-.196%20-.3c-.312%20-.479%20-1.407%20-2.388%20-3.286%20-5.728a1.5%201.5%200%200%201%20.536%20-2.022a1.867%201.867%200%200%201%202.28%20.28l1.47%201.47%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E") center / contain no-repeat;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.4));
  z-index: 3;
}
.tut-ring {
  width: 54px;
  height: 54px;
  margin: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  border: 3px solid rgba(255, 255, 255, 0.85);
  opacity: 0;
  z-index: 2;
}
.tut-skip {
  position: relative;
  z-index: 1; /* 배경 데코 위로 */
  background: transparent;
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 9px 22px;
  border-radius: 22px;
  cursor: pointer;
}
.tut-skip:active {
  background: rgba(255, 255, 255, 0.15);
}
/* 성공 배너 — 보드 중앙 오버레이 (밑에 깔리지 않게) */
.tut-done-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  padding: 12px 22px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(2px);
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  animation: tutBannerPop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
  pointer-events: none;
}
/* translate(-50%,-50%) 를 유지한 채 스케일 → 중앙 고정(순간이동 방지) */
@keyframes tutBannerPop {
  0% {
    transform: translate(-50%, -50%) scale(0.6);
    opacity: 0;
  }
  60% {
    transform: translate(-50%, -50%) scale(1.12);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}
/* 컨페티 — 전체화면 오버레이 */
.tut-confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}
@keyframes tutPop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  60% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===================================================================
   인게임 배경: ② Dark Premium (상시 적용, 순수 CSS·0바이트)
   딥 네이비 그라데이션 + 골드 더스트(::before) + 따뜻한 글로우·비네트(::after).
   세로/가로 공통(반응형). 보드는 항상 데코 위(z-index).
   배경 그라데이션 본체는 위쪽 #screen-game 규칙에 정의.
   =================================================================== */
.board-wrap {
  z-index: 1; /* 배경 데코 위에 보드 유지 */
}
#screen-title::before,
#screen-title::after,
#screen-game::before,
#screen-game::after,
.tut-screen::before,
.tut-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
/* 골드 더스트 입자 */
#screen-title::before,
#screen-game::before,
.tut-screen::before {
  background:
    radial-gradient(circle at 78% 30%, rgba(232, 196, 120, 0.5) 0 0.5%, transparent 1.2%),
    radial-gradient(circle at 85% 45%, rgba(232, 196, 120, 0.4) 0 0.4%, transparent 1%),
    radial-gradient(circle at 70% 55%, rgba(232, 196, 120, 0.35) 0 0.4%, transparent 1%),
    radial-gradient(circle at 88% 60%, rgba(232, 196, 120, 0.3) 0 0.5%, transparent 1.2%),
    radial-gradient(circle at 20% 35%, rgba(232, 196, 120, 0.25) 0 0.4%, transparent 1%),
    radial-gradient(circle at 26% 64%, rgba(232, 196, 120, 0.22) 0 0.4%, transparent 1%);
}
/* 보드 뒤 따뜻한 글로우 + 가장자리 비네트 */
#screen-title::after,
#screen-game::after,
.tut-screen::after {
  background:
    radial-gradient(ellipse 60% 40% at 50% 48%, rgba(232, 148, 90, 0.18), transparent 70%),
    radial-gradient(120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
}
