/* ─── CSS Variables ─────────────────────────── */
:root {
  --bg: #F5F8FC;
  /* A안: 소프트 파스텔 그라데이션 (전 화면 공용 배경) */
  --app-bg: linear-gradient(160deg, #F2FBFF 0%, #E3EEFA 55%, #DCEAF6 100%);
  --surface: #FFFFFF;
  --text: #344861;
  --text-secondary: #6B7B8D;
  --text-muted: #94A3B8;
  --primary: #325AAF;
  --primary-hover: #2A4E99;
  --border: #E2E8F0;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-hover: 0 4px 16px rgba(0,0,0,.12);
  --radius: 8px;
  --radius-sm: 4px;
  --nav-height: 48px;
  --status-height: 44px;
  --control-height: 64px;
}

[data-theme="dark"] {
  --bg: #121212;
  --app-bg: linear-gradient(160deg, #16191E 0%, #121419 55%, #0E1014 100%);
  --surface: #1E1E1E;
  --text: #E0E0E0;
  --text-secondary: #A0AEC0;
  --text-muted: #718096;
  --primary: #5B8DEF;
  --primary-hover: #4A7BD9;
  --border: #2D3748;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
  --shadow-hover: 0 4px 16px rgba(0,0,0,.4);
}

/* Poki 녹화용 미러 캔버스 — 화면 뒤(z-index 음수)에 깔려 보이지 않지만 버퍼는 캡처됨.
   pointer-events 없음(상호작용 무간섭). Poki 외 플랫폼에선 비워둠. */
#recCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;       /* 화면 맨 뒤. 보드를 실제 위치에 1:1·투명배경으로 그려 비침 없음. */
  pointer-events: none;
}

/* ─── Base ──────────────────────────────────── */
html {
  overflow: hidden;
  height: 100dvh;
  /* 반응형 루트 폰트: 거의 모든 버튼/텍스트가 rem 기반이라, 큰 화면에서 UI 전체가
     비례 확대된다. 폰(작은 vmin)에선 16px floor로 기존과 동일, 태블릿/데스크톱 등
     큰 화면(또는 큰 iframe)에서만 최대 19px까지 커진다. 게임 보드/상태바/컨트롤은
     px 기반이라 영향 없음. (vmin = 렌더 영역의 짧은 변 기준 → 작은 임베드는 확대 안 함) */
  font-size: clamp(16px, 9px + 1.4vmin, 19px);
}
body {
  background: var(--app-bg);
  color: var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
  height: 100dvh;
}

/* ─── Navbar ───────────────────────────────── */
.nav-bar {
  background: transparent;
  position: relative;
  z-index: 100;
  height: 40px;
}

.nav-inner {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 100%;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-back-btn, .nav-icon-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
}
.nav-back-btn:hover, .nav-icon-btn:hover {
  background: rgba(0,0,0,0.06);
}
[data-theme="dark"] .nav-back-btn:hover,
[data-theme="dark"] .nav-icon-btn:hover {
  background: rgba(255,255,255,0.08);
}

.nav-hamburger {
  display: none;
}
.nav-logo-text {
  display: none;
}
.btn-new-game {
  display: none;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 6px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-new-game:hover { background: var(--primary-hover); }

/* ─── Side Menu ────────────────────────────── */
.side-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
}
.side-menu-overlay.open { display: block; }

.side-menu {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100%;
  background: var(--surface);
  z-index: 201;
  transition: left 0.25s ease;
  overflow-y: auto;
}
.side-menu.open { left: 0; }

.side-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.side-menu-close {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
}

.side-menu-items { padding: 8px 0; }

.side-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  font-size: 0.95rem;
  transition: background 0.15s;
}
.side-menu-item:hover { background: var(--bg); }
.side-menu-divider { height: 1px; background: var(--border); margin: 4px 16px; }
.side-menu-app { color: var(--primary); }
.side-menu-app:hover { background: rgba(50,90,175,0.08); }

/* ─── Game Status Bar ──────────────────────── */
.game-status-bar {
  display: none; /* Hidden - Android app doesn't show this */
}

.game-status-inner {
  max-width: 800px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  height: 100%;
}
.game-status-inner > :first-child { justify-self: start; }
.game-status-inner > :nth-child(2) { justify-self: center; }
.game-status-inner > :last-child { justify-self: end; }

/* Difficulty selector (combobox style) */
.difficulty-selector {
  position: relative;
}

.difficulty-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.difficulty-btn:hover { background: var(--bg); }
.difficulty-btn svg { opacity: 0.5; }

.difficulty-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  z-index: 50;
  min-width: 140px;
  padding: 4px 0;
}
.difficulty-dropdown.open { display: block; }

.difficulty-dropdown button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.1s;
}
.difficulty-dropdown button:hover { background: var(--bg); }
.difficulty-dropdown button.active {
  color: var(--primary);
  font-weight: 700;
}

.game-stat {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.game-stat strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.timer { display: flex; align-items: center; gap: 4px; }

/* ─── Main Layout ──────────────────────────── */
.main-layout {
  display: flex;
  justify-content: center;
  padding: 0 4px;
  height: calc(100dvh - 40px);
  overflow: hidden;
}

.game-area {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 600px;
  height: 100%;
  overflow: hidden;
}

.game-minimap {
  position: fixed;
  border: 1px solid #bbb;
  border-radius: 2px;
  background: #fff;
  z-index: 10;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  pointer-events: none;
}
[data-theme="dark"] .game-minimap {
  border-color: #555;
  background: #1E1E1E;
}

.board-container {
  flex: 1 1 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
  /* 하단 버튼 영역 예약 — 정사각/근사정사각 뷰에서 보드가 높이를 다 먹어 버튼이 잘리는 것 방지.
     예약량 = nav-bar(40px) + info row(~27) + 버튼바(~140, 언두/리두 스택 포함) 합 → ~207 커버.
     세로 일반폰은 폭이 높이를 결정해 영향 없음(보드 < 이 cap). 근사정사각에서만 보드가 줄고 버튼 확보. */
  max-height: calc(100dvh - clamp(150px, 28dvh, 220px));
}
/* 튜토리얼: 배너(흐름 상단)가 보드를 밀어내므로 보드는 상단 정렬 유지(중앙정렬 시 버튼 잘림) */

#gameCanvas {
  display: block;
  touch-action: none;
}

/* ─── Game Bottom (info bar + button bar) ──── */
.game-bottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  z-index: 5;
  visibility: hidden; /* hidden until positioned by JS */
}
.game-info-row {
  visibility: hidden; /* hidden until positioned by JS */
}

/* Info row below board — positioned by JS */
.game-info-row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 8px;
  z-index: 5;
}
.game-errors {
  display: flex;
  gap: 3px;
}
.game-size-text {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.8rem;
  color: #aaa;
}
[data-theme="dark"] .game-size-text { color: #777; }

.error-x {
  font-size: 16px;
  font-weight: 700;
  color: #D0D0D0;
  line-height: 1;
}
.error-x.used {
  color: #FF4444;
}
[data-theme="dark"] .error-x { color: #444; }
[data-theme="dark"] .error-x.used { color: #FF6666; }

/* game-size-label removed — shown on board canvas */

/* Button bar row */
.game-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(28px, 8vw, 48px);
  padding: 0 16px;
}

/* Undo/Redo stack */
.game-btn-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 튜토리얼 중엔 언두/리두/힌트 숨김 — 펜/✕(모드) 버튼만 노출해 혼란 최소화 */
.game-area.tutorial-mode .game-btn-stack,
.game-area.tutorial-mode #btnHint {
  display: none !important;
}
/* v164: 본게임 가이드(스테이지 1~7) 도중에도 힌트 버튼 숨김 — 가이드가 떠 있는 동안은
   힌트 광고 유도가 노이즈. (언두/리두 스택은 실퍼즐이라 유지.) 가이드 끝나면 자동 복귀. */
.game-area.guide-mode #btnHint {
  display: none !important;
}
/* 튜토리얼 중 미니맵 숨김 — 5×5에선 쓸모없고 헛클릭 유발(이탈 유저가 툭툭 누름) */
.game-area.tutorial-mode .game-minimap {
  display: none !important;
}
/* fill/x 단계(탭 단계 아님)에선 모드버튼이 어차피 잠겨 있음 → 탭 자체를 막아 "눌렀는데 무반응" 좌절 제거.
   탭 단계(s.tap)에선 tut-btnlock 미부여 → 정상 동작. */
.game-area.tutorial-mode.tut-btnlock #btnPen,
.game-area.tutorial-mode.tut-btnlock #btnCross {
  pointer-events: none;
}

/* Base button style */
/* B 구조(청키·라운드) 유지 + 색은 원래 팔레트 */
.game-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #EDF0F4;
  border: 2.5px solid #CBD3DD;
  color: #5A6470;
  cursor: pointer;
  border-radius: 22%;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 0 #CBD3DD;
  transition: transform .08s, box-shadow .08s;
}
.game-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #CBD3DD;
}
.game-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* Small buttons (Undo, Redo) */
.game-btn--small {
  width: clamp(48px, 13vw, 66px);
  height: clamp(48px, 13vw, 66px);
}
.game-btn--small svg {
  width: clamp(22px, 6vw, 28px);
  height: clamp(22px, 6vw, 28px);
}

/* Large buttons (Pen, Cross, Hint) */
.game-btn--large {
  width: clamp(72px, 20vw, 96px);
  height: clamp(72px, 20vw, 96px);
}
.game-btn--large svg {
  width: clamp(30px, 9vw, 40px);
  height: clamp(30px, 9vw, 40px);
}

/* Active / selected state */
/* 선택(active) = 원래 블루. 배경+테두리로 명확히 구분 */
.game-btn.active {
  background: #3B82C4;
  border-color: #2E6A8F;
  color: #fff;
  box-shadow: 0 4px 0 #2E6A8F;
}

/* Hint button: 원래 회색 */
.game-btn--hint {
  background: #888;
  border: 2.5px solid #6E6E6E;
  color: #fff;
  box-shadow: 0 4px 0 #6E6E6E;
}
.game-btn--hint.active {
  background: #4A94C0;
  border-color: #2E6A8F;
  box-shadow: 0 4px 0 #2E6A8F;
}
[data-theme="dark"] .game-btn--hint {
  background: #555;
}
[data-theme="dark"] .game-btn--hint.active {
  background: #5B8DEF;
  border-color: #3A6BC0;
}
/* hint svg inherits from .game-btn--large svg */

/* Badge on hint button */
.game-btn-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 22px;
  height: 22px;
  background: #4A94C0;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
}
[data-theme="dark"] .game-btn-badge {
  background: #8AACBC;
  color: #121212;
}

/* Dark theme adjustments for game buttons (원래 색 + 청키 유지) */
[data-theme="dark"] .game-btn {
  background: #555;
  border-color: #444;
  box-shadow: 0 4px 0 #3A3A3A;
}
[data-theme="dark"] .game-btn:active {
  box-shadow: 0 2px 0 #3A3A3A;
}
[data-theme="dark"] .game-btn.active {
  background: #5B8DEF;
  border-color: #3A6BC0;
  box-shadow: 0 4px 0 #3A6BC0;
}

/* ─── Fullscreen mode ──────────────────────── */
body.fullscreen .nav-bar,
body.fullscreen .game-status-bar,
body.fullscreen .seo-content { display: none; }

body.fullscreen .main-layout {
  height: 100dvh;
  padding: 4px 4px 0;
}

body.fullscreen .game-btn.fullscreen-btn {
  color: var(--primary);
  border-color: var(--primary);
}

/* ─── Modals ───────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 28px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-hover);
}

.modal-box h2 {
  margin-bottom: 8px;
  font-size: 1.3rem;
}

.modal-box p {
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.clear-time {
  font-size: 1.1rem;
  margin-bottom: 20px;
}
.clear-time strong {
  font-size: 1.5rem;
  color: var(--primary);
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}
/* 설정·오디오 다이얼로그: 마지막 행과 완료 버튼 사이 여백(바짝 붙음 방지) */
.modal-settings .modal-buttons { margin-top: 18px; }

.modal-btn {
  padding: 10px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}
.modal-btn:hover { background: var(--bg); }
.modal-btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.modal-btn.primary:hover { background: var(--primary-hover); }

/* Settings modal */
.modal-settings { text-align: left; }
.modal-settings h2 { text-align: center; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.setting-row:last-of-type { border-bottom: none; }

/* 메뉴 화면(모드 498·그림선택 497·데일리 496)보다 위에 떠야 함 → modal-overlay 기본 300 오버라이드 */
#modalAudio { z-index: 600; }

/* 앱인토스 광고 배너 (토스 빌드 전용). 기본 숨김 — app.js _setAdBanner 가 여유 공간 있을 때만 display:block.
   하단 고정, 높이는 JS가 설정. 보드/버튼은 _fitBoardContainer 가 배너 높이만큼 위로 배치(겹침 없음).
   배경 transparent: noFill/렌더 전이면 광고 콘텐츠가 없어 빈 띠가 보이지 않음(영역 예약은 _bannerRendered 로 별도 게이트). */
.ad-banner {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 56px;
  z-index: 6;
  background: transparent;
  overflow: hidden;
}

/* Section label inside settings modal (그룹 구분: 사운드 / 게임플레이) */
.setting-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 14px 0 2px;
}
.setting-section-label:first-of-type { margin-top: 2px; }
/* 섹션 라벨 바로 앞 행은 구분선 제거(라벨 여백이 구분 역할) */
.setting-row:has(+ .setting-section-label) { border-bottom: none; }

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: 0.2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ─── Platform Banner ─────────────────────── */
.platform-banner {
  width: 320px;
  height: 50px;
  margin: 8px auto 0;
  overflow: hidden;
}

/* 게임화면 우측 여백 배너. 크기는 JS가 여백에 맞춰 동적 설정(반응형 배너). 세로/협소 화면은 JS가 숨김. */
.platform-banner--game {
  position: fixed;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  margin: 0;
  z-index: 4;
}
@media (orientation: portrait) {
  .platform-banner--game { display: none !important; }
}

/* ─── SEO Content ──────────────────────────── */
.seo-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.7;
}
.seo-content h1 {
  font-size: 1.5rem;
  color: var(--text);
  margin-bottom: 12px;
}
.seo-content h2 {
  font-size: 1.1rem;
  color: var(--text);
  margin: 20px 0 8px;
}

/* ─── App Banner ───────────────────────────── */
.app-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  margin: 24px 0;
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(50,90,175,0.1);
}
.app-banner-icon { flex-shrink: 0; }
.app-banner-text { flex: 1; }
.app-banner-text strong { display: block; color: var(--text); font-size: 0.95rem; }
.app-banner-text span { font-size: 0.8rem; color: var(--text-secondary); }
.app-banner-btn {
  flex-shrink: 0;
  padding: 8px 18px;
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}
.app-banner-btn:hover { background: var(--primary-hover); }

/* ─── Responsive ───────────────────────────── */
@media (max-width: 480px) {
  .nav-inner { padding: 0 12px; }
  .game-status-inner { padding: 0 12px; }
  .main-layout { padding: 4px 4px 0; }
  .btn-new-game { padding: 6px 12px; font-size: 0.8rem; }
  .game-btn--small { width: 46px; height: 46px; }
  .game-btn--large { width: 66px; height: 66px; }
  .game-buttons { gap: 16px; }
}

@media (min-width: 769px) {
  .board-container { max-width: 600px; max-height: 600px; }
  .seo-content { display: none; }
}

/* Landscape / wide iframe (CrazyGames 16:9) */

/* Collection fullscreen */
.collection-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 250;
  flex-direction: column;
  overflow: hidden;
}
.collection-screen.open {
  display: flex;
}

.collection-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.collection-back {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  display: flex;
}

.collection-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.collection-tabs {
  display: flex;
  gap: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.col-tab {
  padding: 8px 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.col-tab:hover { color: var(--text); }
.col-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.collection-progress {
  padding: 12px 16px;
  flex-shrink: 0;
}

.collection-progress span {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 6px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}

.collection-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
  align-content: start;
}

.collection-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.collection-item:hover { background: var(--surface); }

.collection-item canvas {
  border: 1px solid var(--border);
  border-radius: 3px;
  display: block;
}

.collection-item .label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
}

.collection-item.locked canvas {
  opacity: 0.3;
}
.collection-item.locked .label {
  color: var(--text-muted);
}

.empty-stats {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}

/* ─── Title Screen ─────────────────────────── */
.title-screen {
  position: fixed;
  inset: 0;
  background: var(--app-bg);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.4s, transform 0.4s;
}
[data-theme="dark"] .title-screen {
  background: var(--app-bg);
}
.title-screen.hiding {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}
.title-screen.hidden { display: none; }

.title-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.title-content {
  text-align: center;
  position: relative;
  z-index: 1;
  animation: titleFadeIn 0.6s ease-out;
}

@keyframes titleFadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.title-main {
  width: 70%;
  max-width: 400px;
  height: auto;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto 0;
}
[data-theme="dark"] .title-main {
  filter: brightness(0) invert(0.88);
}

.title-sub {
  width: 35%;
  max-width: 200px;
  height: auto;
  image-rendering: pixelated;
  display: block;
  margin: 12px auto 0;
}
[data-theme="dark"] .title-sub {
  filter: brightness(0) saturate(100%) invert(72%) sepia(15%) saturate(500%) hue-rotate(165deg);
}

.title-touch {
  font-family: monospace;
  font-size: 0.85rem;
  color: #AAAAAA;
  position: fixed;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  animation: touchBlink 1.2s ease-in-out infinite;
  letter-spacing: 1px;
}
[data-theme="dark"] .title-touch {
  color: #BDBDBD;
}

@keyframes touchBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ─── Mode Select Screen ─────────────────── */
.mode-screen {
  position: fixed;
  inset: 0;
  background: var(--app-bg);
  z-index: 498;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: auto;
}
[data-theme="dark"] .mode-screen {
  background: var(--app-bg);
}
.mode-screen.open { display: flex; }
.mode-screen.hiding {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

.mode-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

/* App bar */
.mode-appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 12px;
  position: relative;
  z-index: 10;
}
.mode-appbar-title {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: #222222;
  letter-spacing: 1px;
}
[data-theme="dark"] .mode-appbar-title { color: #F0F0F0; }
.mode-appbar-actions {
  display: flex;
  gap: 8px;
}
.mode-appbar-btn {
  background: none;
  border: none;
  color: #222222;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.2s;
}
[data-theme="dark"] .mode-appbar-btn { color: #F0F0F0; }
.mode-appbar-btn:hover { background: rgba(0,0,0,0.06); }
[data-theme="dark"] .mode-appbar-btn:hover { background: rgba(255,255,255,0.08); }

/* Show/hide sun/moon icons based on theme */
/* Light mode: show moon (tap to go dark), Dark mode: show sun (tap to go light) */
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* Mode cards container */
.mode-cards-container {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px 16px;
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  min-height: 0;
  width: 100%;
  animation: titleFadeIn 0.4s ease-out;
}

/* Mode card — retro press style */
.mode-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 16px;
  background: #FFFFFF;
  border: 2px solid #4A94C0;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: monospace;
  color: #222222;
  position: relative;
  transition: transform 80ms;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.1);
}
[data-theme="dark"] .mode-card {
  background: #1E1E1E;
  color: #F0F0F0;
  box-shadow: 3px 3px 0 rgba(255,255,255,0.12);
}
.mode-card:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 rgba(0,0,0,0.1);
}

/* Per-mode card borders */
.mode-card--daily { border-color: #4AC4A5; }
.mode-card--classic { border-color: #4A94C0; }
.mode-card--expert { border-color: #3A6AA8; }
[data-theme="dark"] .mode-card--daily { border-color: #7EDCC2; }
[data-theme="dark"] .mode-card--classic { border-color: #8AACBC; }
[data-theme="dark"] .mode-card--expert { border-color: #95A6BC; }

/* Mode card icon */
.mode-card-icon {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 3px solid;
}
.mode-card-icon--daily {
  background: #E8F8F2;
  border-color: #4AC4A5;
}
.mode-card-icon--classic {
  background: #E8F0F8;
  border-color: #4A94C0;
}
.mode-card-icon--expert {
  background: #E4E8F2;
  border-color: #3A6AA8;
}
[data-theme="dark"] .mode-card-icon--daily { background: #152820; border-color: #7EDCC2; }
[data-theme="dark"] .mode-card-icon--classic { background: #1A1A1A; border-color: #8AACBC; }
[data-theme="dark"] .mode-card-icon--expert { background: #1A1A1A; border-color: #95A6BC; }

/* Mode card text */
.mode-card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.mode-card-name {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
}
.mode-card-desc {
  font-size: 0.75rem;
  color: #888888;
  margin-top: 2px;
}
[data-theme="dark"] .mode-card-desc { color: #9E9E9E; }

/* Progress bar */
.mode-card-progressbar {
  width: 100%;
  height: 8px;
  background: #D0D0D0;
  border-radius: 4px;
  border: 1px solid #AAAAAA;
  margin-top: 8px;
  overflow: hidden;
}
[data-theme="dark"] .mode-card-progressbar {
  background: #1A1A1A;
  border-color: #333333;
}
.mode-card-progressbar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}
.mode-card-progressbar-fill--daily { background: #00D1B2; }
.mode-card-progressbar-fill--classic { background: #0077B6; }
.mode-card-progressbar-fill--expert { background: #023E8A; }
[data-theme="dark"] .mode-card-progressbar-fill--daily { background: #7EDCC2; }
[data-theme="dark"] .mode-card-progressbar-fill--classic { background: #8AACBC; }
[data-theme="dark"] .mode-card-progressbar-fill--expert { background: #95A6BC; }

/* Continue button */
.mode-continue-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: monospace;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #FFFFFF;
  background: #0077B6;
  border: 2px solid #005A8C;
  border-radius: 6px;
  padding: 12px 32px;
  margin: 10px 0 0;
  cursor: pointer;
  position: relative;
  z-index: 1;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
  transition: transform 80ms;
}
.mode-continue-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 rgba(0,0,0,0.15);
}
[data-theme="dark"] .mode-continue-btn {
  background: #8AACBC;
  border-color: #6B8FA0;
  color: #121212;
  box-shadow: 3px 3px 0 rgba(255,255,255,0.12);
}
.mode-continue-btn.hidden { display: none; }

/* Stats bar */
.mode-stats-bar {
  flex-shrink: 0;
  width: 100%;
  font-family: monospace;
  font-size: 0.65rem;
  color: #00997A;
  text-align: center;
  padding: 12px;
  margin: 8px 0;
  background: #E8E8E8;
  border: 1px solid #C0C0C0;
  border-radius: 10px;
  position: relative;
  z-index: 1;
  letter-spacing: 1px;
}
/* 라벨(CLEARED/TODAY)과 숫자가 붙어 보이지 않도록 숫자 좌우 여백 + 강조 */
.mode-stats-bar span {
  margin: 0 4px;
  font-weight: 700;
}
[data-theme="dark"] .mode-stats-bar {
  color: #7EDCC2;
  background: #1A1A1A;
  border-color: #333333;
}

/* ─── Daily Calendar Screen ───────────────── */
.daily-screen {
  position: fixed;
  inset: 0;
  background: var(--app-bg);
  z-index: 496;
  display: none;
  flex-direction: column;
  overflow-y: auto;
}
[data-theme="dark"] .daily-screen {
  background: var(--app-bg);
}
.daily-screen.open { display: flex; }
.daily-screen.hiding {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

/* Daily app bar */
.daily-appbar {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  gap: 8px;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}
.daily-appbar-title {
  flex: 1;
  font-family: monospace;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: #222222;
  letter-spacing: 1px;
}
[data-theme="dark"] .daily-appbar-title { color: #F0F0F0; }
.daily-back-btn {
  background: none;
  border: none;
  color: #222222;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.2s;
}
[data-theme="dark"] .daily-back-btn { color: #F0F0F0; }
.daily-back-btn:hover { background: rgba(0,0,0,0.06); }
[data-theme="dark"] .daily-back-btn:hover { background: rgba(255,255,255,0.08); }

/* Today's card */
.daily-today-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  margin: 8px 16px;
  background: #FFFFFF;
  border: 2px solid #4AC4A5;
  border-radius: 6px;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.1);
  position: relative;
  z-index: 1;
}
[data-theme="dark"] .daily-today-card {
  background: #1E1E1E;
  border-color: #7EDCC2;
  box-shadow: 3px 3px 0 rgba(255,255,255,0.12);
}
.daily-today-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.daily-today-label {
  font-family: monospace;
  font-size: 10px;
  color: #888888;
}
[data-theme="dark"] .daily-today-label { color: #9E9E9E; }
.daily-today-date {
  font-family: monospace;
  font-size: 18px;
  font-weight: 700;
  color: #222222;
}
[data-theme="dark"] .daily-today-date { color: #F0F0F0; }
.daily-today-progress {
  width: 100%;
  height: 6px;
  background: #D0D0D0;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}
[data-theme="dark"] .daily-today-progress {
  background: #333333;
}
.daily-today-progress-fill {
  height: 100%;
  background: #00D1B2;
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}
[data-theme="dark"] .daily-today-progress-fill {
  background: #7EDCC2;
}
.daily-today-gauge {
  font-family: monospace;
  font-size: 7px;
  color: #4AC4A5;
  text-align: right;
}
[data-theme="dark"] .daily-today-gauge { color: #7EDCC2; }

/* Start button in today card */
.daily-start-btn {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #FFFFFF;
  background: #4AC4A5;
  border: 2px solid #3AAA8F;
  border-radius: 6px;
  padding: 10px 20px;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.1);
  transition: transform 80ms;
  flex-shrink: 0;
}
.daily-start-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 rgba(0,0,0,0.1);
}
[data-theme="dark"] .daily-start-btn {
  background: #7EDCC2;
  border-color: #5CC0A5;
  color: #121212;
  box-shadow: 3px 3px 0 rgba(255,255,255,0.12);
}

/* Calendar */
.daily-calendar {
  flex: 1;
  margin: 8px 16px;
  position: relative;
  z-index: 1;
}
.daily-cal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.daily-cal-title {
  font-family: monospace;
  font-weight: 700;
  font-size: 1rem;
  color: #222222;
  min-width: 140px;
  text-align: center;
}
[data-theme="dark"] .daily-cal-title { color: #F0F0F0; }
.daily-cal-nav {
  background: none;
  border: none;
  color: #222222;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  transition: background 0.2s;
}
[data-theme="dark"] .daily-cal-nav { color: #F0F0F0; }
.daily-cal-nav:hover { background: rgba(0,0,0,0.06); }
[data-theme="dark"] .daily-cal-nav:hover { background: rgba(255,255,255,0.08); }
.daily-cal-nav:disabled {
  opacity: 0.3;
  cursor: default;
}
.daily-cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  margin-bottom: 4px;
}
.daily-cal-weekday {
  font-family: monospace;
  font-size: 0.65rem;
  font-weight: 700;
  color: #888888;
  padding: 4px 0;
}
[data-theme="dark"] .daily-cal-weekday { color: #9E9E9E; }
.daily-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.daily-cal-day {
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: #222222;
  background: #FFFFFF;
  border: 2px solid transparent;
  border-radius: 6px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  overflow: hidden;
}
.daily-cal-preview {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  object-fit: contain;
}
[data-theme="dark"] .daily-cal-day {
  color: #F0F0F0;
  background: #1E1E1E;
}
.daily-cal-day:hover:not(.daily-cal-day--disabled):not(.daily-cal-day--empty) {
  border-color: #4AC4A5;
}
.daily-cal-day--today {
  border-color: #4AC4A5 !important;
  font-weight: 700;
}
[data-theme="dark"] .daily-cal-day--today {
  border-color: #7EDCC2 !important;
}
.daily-cal-day--cleared {
  background: #E0F7F0 !important;
  color: #2D8A6E;
}
[data-theme="dark"] .daily-cal-day--cleared {
  background: #1A3A2E !important;
  color: #7EDCC2;
}
.daily-cal-day--selected {
  border-color: #4AC4A5 !important;
  border-width: 3px;
  font-weight: 700;
}
[data-theme="dark"] .daily-cal-day--selected {
  border-color: #7EDCC2 !important;
}
.daily-cal-day--disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}
.daily-cal-day--empty {
  visibility: hidden;
  pointer-events: none;
}
.daily-cal-day--outside {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

/* Play button */
.daily-play-btn {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #4AC4A5;
  background: #FFFFFF;
  border: 2px solid #4AC4A5;
  border-radius: 6px;
  padding: 14px 32px;
  margin: 8px 16px 24px;
  cursor: pointer;
  width: calc(100% - 32px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.1);
  transition: transform 80ms;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}
.daily-play-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 rgba(0,0,0,0.1);
}
[data-theme="dark"] .daily-play-btn {
  color: #7EDCC2;
  background: #1E1E1E;
  border-color: #7EDCC2;
  box-shadow: 3px 3px 0 rgba(255,255,255,0.12);
}

/* ─── Puzzle Select Screen ────────────────── */
.select-screen {
  position: fixed;
  inset: 0;
  background: var(--app-bg);
  z-index: 497;
  display: none;
  flex-direction: column;
  touch-action: auto;
}
[data-theme="dark"] .select-screen {
  background: var(--app-bg);
}
.select-screen.open {
  display: flex;
}
.select-screen.hiding {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

/* ─── Screen transition curtain ──────────────
   Covers the whole viewport during game entry so the outgoing screen
   is swapped out while hidden (no ghosting / afterimage cross-fade). */
.transition-curtain {
  position: fixed;
  inset: 0;
  background: var(--bg, #FFFFFF);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.18s ease;
}
.transition-curtain.show {
  opacity: 1;
  pointer-events: all;
}

/* Select app bar */
.select-appbar {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
}
.select-appbar-title {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: #222222;
  letter-spacing: 1px;
  flex: 1;
}
[data-theme="dark"] .select-appbar-title { color: #F0F0F0; }
.select-back-btn {
  background: none;
  border: none;
  color: #222222;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.2s;
}
[data-theme="dark"] .select-back-btn { color: #F0F0F0; }
.select-back-btn:hover { background: rgba(0,0,0,0.06); }
[data-theme="dark"] .select-back-btn:hover { background: rgba(255,255,255,0.08); }

/* Select tabs */
.select-tabs {
  display: flex;
  flex-shrink: 0;
  padding: 0 12px;
  position: relative;
}
.select-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 0;
  background: none;
  border: none;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  color: #888888;
  cursor: pointer;
  transition: color 0.2s;
  letter-spacing: 0.5px;
}
[data-theme="dark"] .select-tab { color: #9E9E9E; }
.select-tab.active { color: #4A94C0; }
.select-screen[data-mode="expert"] .select-tab.active { color: #3A6AA8; }
[data-theme="dark"] .select-tab.active { color: #8AACBC; }
[data-theme="dark"] .select-screen[data-mode="expert"] .select-tab.active { color: #95A6BC; }
.select-tab svg { opacity: 0.6; }
.select-tab.active svg { opacity: 1; }


/* Tab indicator */
.select-tab-indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 4px;
  background: #4A94C0;
  border-radius: 2px;
  width: 33.333%;
  transition: transform 0.25s ease, background 0.25s ease;
  pointer-events: none;
}
[data-theme="dark"] .select-tab-indicator { background: #8AACBC; }
.select-screen[data-mode="expert"] .select-tab-indicator { background: #3A6AA8; }
[data-theme="dark"] .select-screen[data-mode="expert"] .select-tab-indicator { background: #95A6BC; }

/* Puzzle grid */
.select-grid {
  flex: 1;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y !important;
  overscroll-behavior: contain;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  align-content: start;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

@keyframes gridSlideLeft {
  from { opacity: 0; transform: translateX(60px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes gridSlideRight {
  from { opacity: 0; transform: translateX(-60px); }
  to { opacity: 1; transform: translateX(0); }
}

.select-grid.slide-left {
  animation: gridSlideLeft 0.25s ease-out;
}
.select-grid.slide-right {
  animation: gridSlideRight 0.25s ease-out;
}

/* Puzzle item - 정사각 높이는 JS(_squareizeSelectItems)가 height=width로 직접 지정.
   ⚠️ 이 아이템은 <button> + grid(align-items:stretch) 조합이라 CSS 트릭(padding-bottom·aspect-ratio·
   ::before·canvas aspect)이 전부 행 높이를 못 잡아 납작해짐. JS 명시 높이가 Chrome·Safari 모두 확실. (CG #6) */
.select-puzzle-item {
  position: relative;
  width: 100%;
  padding: 0;
  background: #FFFFFF;
  border: 3px solid #888888;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
  transition: transform 80ms, box-shadow 80ms;
  overflow: hidden;
}
[data-theme="dark"] .select-puzzle-item {
  background: #2A2A2A;
  border-color: #555555;
  box-shadow: 3px 3px 0 rgba(255,255,255,0.08);
}
.select-puzzle-item:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 transparent;
}

/* Cleared state */
.select-puzzle-item.cleared {
  border-color: #4A94C0;
}
[data-theme="dark"] .select-puzzle-item.cleared {
  border-color: #8AACBC;
}
.select-screen[data-mode="expert"] .select-puzzle-item.cleared {
  border-color: #3A6AA8;
}
[data-theme="dark"] .select-screen[data-mode="expert"] .select-puzzle-item.cleared {
  border-color: #95A6BC;
}

/* ─── Big Picture Dialog ──────────────────── */
.bigpic-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.bigpic-overlay.open {
  display: flex;
}

.bigpic-dialog {
  background: #FFFFFF;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  max-width: 360px;
  width: 100%;
  margin: auto;
  animation: titleFadeIn 0.2s ease-out;
}
[data-theme="dark"] .bigpic-dialog {
  background: #1E1E1E;
}

.bigpic-size {
  display: block;
  font-family: monospace;
  font-weight: 700;
  font-size: 0.8rem;
  color: #888;
  text-align: right;
  margin-bottom: 4px;
}

.bigpic-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  border: 2px solid #888;
  padding: 2px;
  background: #888;
}

.bigpic-cell {
  aspect-ratio: 1;
  position: relative;
  cursor: pointer;
  background: #FFFFFF;
  overflow: hidden;
  transition: transform 80ms;
}
.bigpic-cell:active {
  transform: scale(0.92);
}
[data-theme="dark"] .bigpic-cell {
  background: #2A2A2A;
}

.bigpic-cell canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  pointer-events: none;
}

/* Canvas inside puzzle item */
.select-puzzle-item canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  touch-action: pan-y;
  pointer-events: none;
}

/* ─── Game Clear Screen ───────────────────── */
.gameclear-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 600;
  background: var(--app-bg);
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}
.gameclear-screen.open {
  display: flex;
}
[data-theme="dark"] .gameclear-screen {
  background: var(--app-bg);
}

.gameclear-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.gameclear-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-height: 0;            /* 짧은 화면서 줄어들 수 있게(미리보기 cap과 함께 오버플로 방지) */
  justify-content: center;
  padding-bottom: 10px;
  animation: gameclearEntry 0.6s ease-out;
}

@keyframes gameclearEntry {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.gameclear-title {
  position: relative;
  z-index: 1;
  width: 60%;
  max-width: 360px;
  height: auto;
  margin-top: max(20px, env(safe-area-inset-top, 20px));
  image-rendering: pixelated;
  animation: gameclearBounce 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}
[data-theme="dark"] .gameclear-title {
  filter: brightness(0) invert(0.88);
}

@keyframes gameclearBounce {
  0% { opacity: 0; transform: scale(0.3) translateY(-40px); }
  60% { opacity: 1; transform: scale(1.08) translateY(4px); }
  80% { transform: scale(0.96) translateY(-2px); }
  100% { transform: scale(1) translateY(0); }
}

.gameclear-preview {
  display: block;
  border: 3px solid #4A94C0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 20px rgba(74, 148, 192, 0.25);
}
[data-theme="dark"] .gameclear-preview {
  border-color: #8AACBC;
  background: #1E1E1E;
  box-shadow: 0 4px 20px rgba(138, 172, 188, 0.2);
}

.gameclear-stats {
  display: flex;
  gap: 32px;
}

.gameclear-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: monospace;
  font-size: 1.2rem;
  font-weight: 700;
  color: #344861;
}
[data-theme="dark"] .gameclear-stat {
  color: #E0E0E0;
}

.gameclear-stat-label {
  font-size: 0.7rem;
  font-weight: 400;
  color: #94A3B8;
  text-transform: uppercase;
  letter-spacing: 1px;
}
[data-theme="dark"] .gameclear-stat-label {
  color: #718096;
}

/* 다음 난이도 진행도 (클리어 화면, 버튼 바로 위에 절대배치) */
.gameclear-nextlevel {
  position: relative;
  z-index: 1;
  width: min(86%, 340px);
  margin: 0 auto 12px;
  background: #fff;
  border-radius: 14px;
  padding: 11px 14px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .07);
}
.gameclear-nextlevel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 800;
  color: #42566e;
  margin-bottom: 8px;
}
.gameclear-nextlevel-cnt { color: #3a6aa8; }
.gameclear-nextlevel-bar {
  height: 11px;
  border-radius: 7px;
  background: #e6edf5;
  overflow: hidden;
}
.gameclear-nextlevel-fill {
  height: 100%;
  width: 0;
  border-radius: 7px;
  background: linear-gradient(90deg, #4f93d8, #3a6aa8);
  transition: width .4s ease;
}
/* 해금 순간 = 골드 + 등장 바운스 + 글로우 (성의/축하 강조) */
.gameclear-nextlevel.unlocked {
  border: 2px solid #FFC24D;
  background: linear-gradient(180deg, #fffdf5, #fff2cf);
  box-shadow: 0 4px 22px rgba(255, 168, 0, .42);
  animation: nlUnlockPop .5s cubic-bezier(.34, 1.56, .64, 1);
}
.gameclear-nextlevel.unlocked .gameclear-nextlevel-row { color: #B5730A; justify-content: center; }
.gameclear-nextlevel.unlocked .gameclear-nextlevel-fill { background: linear-gradient(90deg, #FFD774, #FF9F1C); }
@keyframes nlUnlockPop {
  0% { transform: scale(.9); }
  55% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
[data-theme="dark"] .gameclear-nextlevel { background: #262626; box-shadow: 0 2px 12px rgba(0, 0, 0, .3); }
[data-theme="dark"] .gameclear-nextlevel-row { color: #cfd8e3; }
[data-theme="dark"] .gameclear-nextlevel-cnt { color: #8ab4e0; }
[data-theme="dark"] .gameclear-nextlevel-bar { background: #3a3a3a; }
[data-theme="dark"] .gameclear-nextlevel.unlocked { background: linear-gradient(180deg, #2a2418, #3a2f12); border-color: #C9962E; box-shadow: 0 4px 22px rgba(201, 150, 46, .35); }
[data-theme="dark"] .gameclear-nextlevel.unlocked .gameclear-nextlevel-row { color: #F0C257; }

/* 짧은/가로 화면(Poki 인스펙터 640×380·836×470·1031×580 등): 타이틀·여백 압축해 전부 한 화면에 들어가게 */
@media (max-height: 640px) {
  .gameclear-title { width: 42%; max-width: 220px; margin-top: 6px; }
  .gameclear-content { padding-bottom: 4px; gap: 8px; }
  .gameclear-nextlevel { margin-bottom: 8px; padding: 8px 12px; }
  .gameclear-nextlevel-row { margin-bottom: 6px; font-size: 13px; }
  .gameclear-buttons { gap: 8px; margin-bottom: 10px; }
  .gameclear-btn { height: 44px; }
}

.gameclear-buttons {
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;        /* 모든 버튼(+3힌트/row)을 컨테이너 폭에 맞춤 */
  gap: 10px;
  width: min(400px, 80vw);     /* 미리보기 이미지 폭과 동일 → 버튼 끝이 이미지 끝과 정렬 */
  max-width: calc(100% - 32px);
  margin: 0 auto;              /* 정상 플로우(절대배치X) — content flex:1이 버튼을 하단으로 밀어냄 */
  margin-bottom: max(20px, env(safe-area-inset-bottom, 20px));
}
/* 홈 + 다음게임은 항상 한 줄에 같이, 각자 반반 채워 줄 끝이 이미지 끝과 맞게 */
.gameclear-btn-row {
  display: flex;
  gap: 10px;
}
.gameclear-btn-row .gameclear-btn { flex: 1; }

/* 클리어 버튼 = 인게임 버튼과 같은 디자인 언어(청키 라운드)로 통일. monospace 대문자 폐기. */
.gameclear-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.2px;
  height: 50px;
  min-width: 112px;
  padding: 0 22px;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 80ms, box-shadow 80ms;
  /* 세컨더리(홈/재시도) = 인게임 버튼(.game-btn)과 동일한 회색 청키 톤 — 기둥 또렷하게 */
  background: #EDF0F4;
  color: #5A6470;
  border: 2.5px solid #CBD3DD;
  box-shadow: 0 4px 0 #CBD3DD;
}
.gameclear-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #CBD3DD;
}
[data-theme="dark"] .gameclear-btn {
  background: #555;
  color: #D5DBE2;
  border-color: #444;
  box-shadow: 0 4px 0 #3A3A3A;
}

/* 프라이머리(다음) = 원래 블루 (비-Poki). Poki는 poki-package.js가 그린(#43A047)으로 주입 */
.gameclear-btn--primary {
  background: #4A94C0;
  color: #FFFFFF;
  border-color: #3A7BA8;
  box-shadow: 0 4px 0 #2E6A8F;
}
[data-theme="dark"] .gameclear-btn--primary {
  background: #8AACBC;
  color: #121212;
  border-color: #6B8FA0;
  box-shadow: 0 4px 0 #566F7C;
}

/* 리워드(보너스) = 원래 오렌지 */
.gameclear-btn--reward {
  background: #FF9800;
  color: #FFFFFF;
  border-color: #E68900;
  box-shadow: 0 4px 0 #C77700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  /* +3힌트는 .gameclear-buttons(column) 직속 자식 → 자연 너비로 단독 줄, 가운데 정렬. (홈/다음은 .gameclear-btn-row에 묶임) */
}
.gameclear-btn--reward svg { flex-shrink: 0; stroke: #fff; }
.gameclear-btn--reward:hover { background: #F57C00; }
[data-theme="dark"] .gameclear-btn--reward {
  background: #FF9800;
  color: #FFFFFF;
  border-color: #E68900;
}

/* ─── Improved Game Over Modal ─────────────── */
.modal-gameover { position: relative; }

.gameover-icon {
  margin-bottom: 8px;
  animation: gameoverShake 0.5s ease-in-out;
}

@keyframes gameoverShake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-8deg); }
  40% { transform: rotate(8deg); }
  60% { transform: rotate(-4deg); }
  80% { transform: rotate(4deg); }
}

.gameover-msg {
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.rewarded-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  margin-bottom: 12px;
  background: #FF9800;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s;
}
.rewarded-btn:hover { background: #F57C00; }
.rewarded-btn svg { flex-shrink: 0; stroke: #fff; }

/* ─── How to Play Tutorial ────────────────── */
.tutorial-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 700;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.tutorial-overlay.open { display: flex; }

.tutorial-dialog {
  background: #FFFFFF;
  border: 2px solid #4A94C0;
  border-radius: 6px;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.15);
  max-width: 400px;
  width: 100%;
  padding: 16px;
  animation: titleFadeIn 0.2s ease-out;
  max-height: 90vh;
  overflow-y: auto;
}
[data-theme="dark"] .tutorial-dialog {
  background: #1E1E1E;
  border-color: #8AACBC;
}

.tutorial-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.tutorial-title {
  font-family: monospace;
  font-weight: 700;
  font-size: 1rem;
  color: #222;
}
[data-theme="dark"] .tutorial-title { color: #F0F0F0; }
.tutorial-step {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.8rem;
  color: #4A94C0;
}

.tutorial-image-wrap {
  background: #F5F5F5;
  border: 1px solid #DDD;
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 12px;
  display: flex;
  justify-content: center;
}
[data-theme="dark"] .tutorial-image-wrap {
  background: #2A2A2A;
  border-color: #444;
}
.tutorial-image {
  width: 100%;
  max-height: 50vh;
  object-fit: contain;
  image-rendering: pixelated;
}

.tutorial-desc {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.8rem;
  line-height: 1.5;
  color: #222;
  margin-bottom: 16px;
  white-space: pre-line;
}
[data-theme="dark"] .tutorial-desc { color: #E0E0E0; }

.tutorial-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 14px;
}
.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #D0D0D0;
}
.tutorial-dot.active {
  background: #4A94C0;
}
[data-theme="dark"] .tutorial-dot { background: #444; }
[data-theme="dark"] .tutorial-dot.active { background: #8AACBC; }

.tutorial-buttons {
  display: flex;
  gap: 8px;
}
.tutorial-btn {
  flex: 1;
  height: 44px;
  font-family: monospace;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.12);
  transition: transform 80ms;
}
.tutorial-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 transparent;
}
.tutorial-btn--skip {
  background: #FFF;
  color: #607D8B;
  border-color: #B0BEC5;
}
[data-theme="dark"] .tutorial-btn--skip {
  background: #2A2A2A;
  color: #9E9E9E;
  border-color: #555;
}
.tutorial-btn--next {
  background: #FFF;
  color: #4A94C0;
  border-color: #4A94C0;
}
[data-theme="dark"] .tutorial-btn--next {
  background: #2A2A2A;
  color: #8AACBC;
  border-color: #8AACBC;
}

/* ─── Interactive Tutorial Board ──────────── */
.tutorial-board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}
#tutorialCanvas {
  display: block;
  max-width: 100%;
  touch-action: none;
  border-radius: 4px;
}

.tutorial-mode-toggle {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}
.tutorial-mode-btn {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.7rem;
  padding: 6px 16px;
  border: 2px solid #CCC;
  border-radius: 4px;
  background: #FFF;
  color: #666;
  cursor: pointer;
}
.tutorial-mode-btn.active {
  border-color: #4A94C0;
  color: #4A94C0;
  background: #EBF5FB;
}
[data-theme="dark"] .tutorial-mode-btn { background: #2A2A2A; color: #999; border-color: #555; }
[data-theme="dark"] .tutorial-mode-btn.active { background: #1A3050; color: #8AACBC; border-color: #8AACBC; }

/* (old hint-btn styles removed, now using .game-btn--hint) */

/* ─── In-Game Tutorial Guide Bubble ──────── */
.tutorial-dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 600;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
}
.tutorial-dialog-overlay.visible {
  display: flex;
}
.tutorial-dialog-box {
  background: #fff;
  border-radius: 12px;
  position: relative;          /* 마스코트 삐져나오기 기준 */
  padding: 38px 20px 16px;
  margin: 0 24px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  text-align: center;
  animation: titleFadeIn 0.25s ease-out;
}
[data-theme="dark"] .tutorial-dialog-box {
  background: #1E2A3A;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.tutorial-dialog-text {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.6;
  color: #303030;
  margin: 0 0 16px;
  white-space: pre-line;
}
[data-theme="dark"] .tutorial-dialog-text {
  color: #E0E0E0;
}
.tutorial-dialog-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: stretch;
  flex-wrap: wrap;     /* 평소 가로 2분할, 라벨이 너무 길면(독일어 등) 자동 세로 풀너비 */
}
.tutorial-dialog-btn {
  flex: 1 1 120px;     /* 가로일 땐 같은 너비, 세로로 떨어지면 100% */
  min-width: 0;
  background: #4A94C0;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 14px;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  letter-spacing: 0.3px;
  white-space: normal;       /* 라벨이 길면 버튼 '안에서' 줄바꿈 */
  word-break: keep-all;      /* 한국어 단어 중간 꺾임 방지 */
  overflow-wrap: break-word;
}
.tutorial-dialog-btn:active {
  transform: scale(0.95);
}
[data-theme="dark"] .tutorial-dialog-btn {
  background: #5B8DEF;
}
.tutorial-dialog-btn--skip {
  background: transparent;
  color: #8A9AAD;
  border: 1px solid #C4CDD8;
  padding: 10px 18px;
}
[data-theme="dark"] .tutorial-dialog-btn--skip {
  background: transparent;
  color: #8A9AAD;
  border: 1px solid #3A4658;
}
/* Tutorial button highlight pulse */
@keyframes tutorialPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 148, 192, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(74, 148, 192, 0); }
}
.tutorial-highlight {
  position: relative;
  z-index: 10;
  /* 블루 글로우(게임 분위기에 맞춤 — 움직임은 고스트 손가락이 담당) */
  box-shadow: 0 0 0 2px rgba(74,148,192,0.9), 0 0 10px 3px rgba(74,148,192,0.45) !important;
  border-radius: 12px;
}
/* 버튼 아래에서 끝이 버튼을 가리키는 고스트 손가락 — "여기를 탭" 안내(원작 방식) */
.tutorial-highlight::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;              /* 버튼 중앙 기준 — 손끝 보정은 keyframes transform에서 */
  width: 44px;
  height: 44px;
  /* 칸 스윕과 동일한 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;
  pointer-events: none;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,0.4));
  animation: tutorialFinger 0.9s ease-in-out infinite;
  z-index: 11;
}
/* 손끝(검지 끝)이 버튼 정중앙을 가리키게 — 아이콘 안에서 손끝이 좌측·상단에 치우쳐 있어
   x는 -40%(우측 보정), y는 -12%(손끝을 중앙에)로 맞춤. 50%에서 살짝 아래로 탭. */
@keyframes tutorialFinger {
  0%, 100% { transform: translate(-40%, -12%); }  /* 손끝이 버튼 정중앙 */
  50%      { transform: translate(-40%, 2%); }    /* 살짝 눌렀다 */
}
/* ─── 상시 튜토리얼 안내 배너 (흐름 상단 — 보드를 아래로 밀어냄, 겹침 없음) ─── */
.tutorial-banner {
  position: relative;     /* 좌/우 토글 버튼 위치 기준 */
  display: none;          /* 비활성 시 공간 차지 안 함 */
  flex: 0 0 auto;         /* 활성 시 자기 높이만큼 차지 → 보드를 아래로 */
  align-self: center;
  width: min(94%, 460px);
  margin: 6px auto 2px;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  background: linear-gradient(180deg, rgba(244, 250, 253, 0.98), rgba(230, 242, 250, 0.98));  /* 은은한 옅은 블루 */
  border: 2px solid #4A94C0;   /* 게임 분위기(청록빛 파랑)에 맞춤 — 튜토리얼 다이얼로그와 통일 */
  border-radius: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 20;
}
.tutorial-banner.visible { display: flex; }
/* 가로(짧은 16:9, Poki 기본): 배너를 보드 왼쪽 옆에 세로 배치.
   absolute라 세로 공간을 안 먹어 보드 풀사이즈·버튼 안 잘림 + 보드를 우측으로 밀어 겹침 0. */
@media (min-aspect-ratio: 1/1) {
  /* 가로: 보드는 화면 중앙 유지. 배너는 보드 옆 여백에 absolute(좌/우 토글).
     위치·크기(top/left/right/width/height)는 _fitBoardContainer가 캔버스 기준으로 지정. */
  .game-area.tutorial-mode .tutorial-banner.visible,
  .game-area.guide-mode .tutorial-banner.visible {
    position: fixed;            /* 뷰포트 기준 → game-area(max-width) 밖 여백까지 사용 */
    overflow: visible;          /* 마스코트가 배너 위로 삐져나오게(auto면 클리핑) */
    margin: 0;
    flex-direction: column;     /* 텍스트 위, 스킵 하단 */
    align-items: stretch;
    gap: 8px;
    z-index: 30;
  }
  /* 가로: 마스코트를 배너 위 테두리로 솟아오르게(다이얼로그와 동일 연출) */
  .tutorial-banner-mascot {
    display: block;
    position: absolute;
    left: 50%; top: 0;
    transform: translate(-50%, -80%);
    width: 56px; height: auto;
    margin: 0;
  }
  .game-area.tutorial-mode .tutorial-banner.visible .tutorial-banner-skip,
  .game-area.guide-mode .tutorial-banner.visible .tutorial-banner-skip {
    align-self: center;
    margin-top: 4px;
    padding: 6px 16px;
  }
}
/* 실수 코치 카드 (상단 중앙, 텍스트 + 확인 버튼 — 직접 닫음) */
.hint-toast {
  position: fixed;
  left: 50%; top: 60px;
  transform: translate(-50%, -10px);
  max-width: min(92%, 440px);
  background: rgba(74, 148, 192, 0.97);
  color: #fff;
  padding: 11px 12px 11px 16px;
  border-radius: 14px;
  display: flex; align-items: center; gap: 12px;
  font-size: 0.88rem; font-weight: 600; line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  opacity: 0; pointer-events: none; z-index: 60;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.hint-toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.hint-toast-text { flex: 1; min-width: 0; }
.hint-toast-btn {
  flex: none; background: #fff; color: #2E6A8F;
  border: none; border-radius: 9px; padding: 7px 14px;
  font-weight: 700; font-size: 0.82rem; cursor: pointer; white-space: nowrap;
}
.hint-toast-btn:active { transform: scale(0.95); }
.hint-toast-actions { flex: none; display: flex; flex-direction: column; gap: 5px; align-items: stretch; }
.hint-toast-optout {
  background: transparent; color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.55); border-radius: 9px;
  padding: 5px 12px; font-weight: 600; font-size: 0.72rem;
  cursor: pointer; white-space: nowrap; opacity: 0.9;
}
.hint-toast-optout:active { transform: scale(0.95); }
[data-theme="dark"] .hint-toast { background: rgba(91, 141, 239, 0.97); }
[data-theme="dark"] .hint-toast-btn { color: #2A4E99; }

.tutorial-banner-mascot {
  flex: none;
  width: 64px; height: auto;
  align-self: center;
  margin: -8px 0;            /* 살짝 넘쳐 존재감 */
  pointer-events: none; user-select: none; -webkit-user-drag: none;
}
.tutorial-dialog-mascot {
  position: absolute;          /* 박스 위 테두리로 빼꼼 솟아오름 */
  left: 50%; top: 0;
  transform: translate(-50%, -70%);
  width: 22%; height: auto;   /* 팝업(다이얼로그 박스) 폭에 비례 */
  pointer-events: none; user-select: none; -webkit-user-drag: none;
}
.tutorial-banner-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 5px; justify-content: center;
}
.tutorial-banner-progress {
  display: flex; gap: 5px; align-items: center;
}
.tutorial-banner-progress .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #C2D4E2; transition: background 0.2s, transform 0.2s;
}
.tutorial-banner-progress .dot.active {
  background: #4A94C0; transform: scale(1.3);
}
.tutorial-banner-progress .dot.done {
  background: #8FBBD6;
}
.tutorial-banner-text {
  flex: 1; min-width: 0;
  font-size: 0.9rem; line-height: 1.35; font-weight: 600;
  color: #1f2a44; white-space: pre-line;
  /* 단계마다 줄 수가 달라도 배너 높이를 일정하게 → 보드가 위아래로 안 움직임
     (특히 X 단계 전환 시 보드가 튀어 탭이 빗나가던 문제 방지).
     실제 고정 높이(min-height px)는 JS가 모든 단계 텍스트의 최대 높이로 설정. */
  display: flex; flex-direction: column; justify-content: center;
}
.tutorial-banner-skip {
  flex: none; align-self: center;
  padding: 5px 10px; font-size: 0.72rem; font-weight: 700;
  color: #78889a; background: #eef1f5; border: none; border-radius: 8px; cursor: pointer;
}
[data-theme="dark"] .tutorial-banner { background: rgba(26, 32, 48, 0.97); border-color: #5B8DEF; }
[data-theme="dark"] .tutorial-banner-progress .dot { background: #3A4658; }
[data-theme="dark"] .tutorial-banner-progress .dot.done { background: #44698f; }
[data-theme="dark"] .tutorial-banner-progress .dot.active { background: #5B8DEF; }
[data-theme="dark"] .tutorial-banner-text { color: #e8edf5; }
[data-theme="dark"] .tutorial-banner-skip { background: #2a3346; color: #9fb0c4; }
/* Big picture progress label */
.bigpic-progress {
  display: block;
  font-family: monospace;
  font-size: 0.6rem;
  font-weight: 700;
  color: #4A94C0;
  margin-top: 2px;
  text-align: center;
}
[data-theme="dark"] .bigpic-progress {
  color: #5B8DEF;
}
.bigpic-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px 0;
  color: #999;
  font-size: 14px;
}
.bigpic-name {
  display: block;
  font-size: 10px;
  color: #888;
  text-align: center;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-theme="dark"] .bigpic-name {
  color: #999;
}

/* ─── Landscape Override (game portals: Poki, CrazyGames, GD) ─── */
/*
 * 게임 포털 iframe 해상도:
 *   Poki:        640×360 ~ 1031×580  (16:9)
 *   CrazyGames:  821×462 ~ 1920×1080 (16:9)
 *   GD:          800×600             (4:3)
 *
 * Strategy: clamp() + dvh/vw로 360px~1080px 높이 전체 커버.
 * 모바일 세로에서는 적용 안 됨 (aspect-ratio < 1).
 */
@media (min-aspect-ratio: 1/1) {

  :root {
    --ls-container-w: clamp(300px, 45vw, 480px);
  }

  .seo-content { display: none; }

  /* Appbars */
  .mode-appbar,
  .select-appbar,
  .daily-appbar {
    width: 100%;
    height: clamp(28px, 6dvh, 44px);
    padding: 0 16px;
    box-sizing: border-box;
  }
  .nav-bar {
    height: clamp(28px, 6dvh, 44px);
  }
  .nav-inner {
    width: 100%;
    max-width: 100%;
    height: clamp(28px, 6dvh, 44px);
    padding: 0 16px;
    box-sizing: border-box;
  }

  /* ── MODE SELECT ── */
  .mode-screen {
    overflow: hidden;
    align-items: center;
  }
  .mode-cards-container {
    width: var(--ls-container-w);
    gap: clamp(8px, 2dvh, 16px);
    padding: clamp(8px, 3dvh, 20px) clamp(8px, 1.5vw, 16px);
    justify-content: center;
    align-items: stretch;
    flex: 1 1 auto;
    box-sizing: border-box;
  }
  .mode-card {
    height: clamp(48px, 12dvh, 84px);
    padding: 0 clamp(10px, 2vw, 20px);
    gap: clamp(8px, 1.5vw, 14px);
    border-width: 2px;
    box-sizing: border-box;
  }
  .mode-card-icon {
    width: clamp(32px, 8dvh, 56px);
    height: clamp(32px, 8dvh, 56px);
    border-width: 2px;
    flex-shrink: 0;
  }
  .mode-card-icon svg {
    width: clamp(20px, 5dvh, 36px);
    height: clamp(20px, 5dvh, 36px);
  }
  .mode-card-name {
    font-size: clamp(0.78rem, 2.4dvh, 1.3rem);
    white-space: nowrap;
  }
  .mode-card-desc {
    font-size: clamp(0.6rem, 1.7dvh, 1rem);
    white-space: nowrap;
  }
  .mode-card-progressbar {
    height: clamp(3px, 0.6dvh, 5px);
    margin-top: 2px;
  }
  .mode-continue-btn {
    height: clamp(28px, 7dvh, 44px);
    padding: 0 16px;
    font-size: clamp(0.72rem, 2dvh, 1.05rem);
    margin-top: clamp(4px, 1dvh, 10px);
  }
  .mode-stats-bar {
    position: absolute !important;
    bottom: clamp(4px, 1dvh, 12px);
    left: 0;
    right: 0;
    width: var(--ls-container-w);
    margin: 0 auto !important;
    height: clamp(22px, 5dvh, 36px);
    padding: 0 12px;
    font-size: clamp(0.55rem, 1.3dvh, 0.7rem);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── PUZZLE SELECT ── */
  .select-screen {
    align-items: center;
  }
  .select-screen > *:not(.bigpic-overlay):not(.select-appbar) {
    max-width: var(--ls-container-w);
    width: 100%;
  }

  /* ── BIGPICTURE DIALOG ── */
  .bigpic-overlay {
    padding: clamp(4px, 1dvh, 16px);
  }
  .bigpic-dialog {
    width: clamp(240px, 80dvh, 480px);
    max-width: 92vw;
    max-height: calc(100dvh - clamp(20px, 6dvh, 60px));
    padding: clamp(6px, 1.5dvh, 12px);
    overflow-y: auto;
  }
  .bigpic-size {
    font-size: clamp(0.7rem, 1.8dvh, 1rem);
    margin-bottom: clamp(2px, 0.6dvh, 6px);
  }
  .select-tabs {
    padding: 0 12px;
  }
  .select-tab {
    padding: clamp(6px, 1.5dvh, 12px) 0;
    font-size: clamp(0.65rem, 1.5dvh, 0.85rem);
  }
  .select-tab-indicator {
    height: clamp(2px, 0.5dvh, 4px);
  }
  .select-grid {
    padding: clamp(4px, 1dvh, 8px) 12px;
  }

  /* ── GAME SCREEN ── */
  .main-layout {
    height: 100dvh;
    padding: 0 4px;
  }
  .board-container {
    max-height: calc(100dvh - clamp(130px, 28dvh, 180px));
  }
  .game-buttons {
    gap: clamp(4px, 1vw, 10px);
  }
  .game-btn--small {
    width: clamp(30px, 7dvh, 44px);
    height: clamp(30px, 7dvh, 44px);
  }
  .game-btn--large {
    width: clamp(38px, 9dvh, 52px);
    height: clamp(38px, 9dvh, 52px);
  }

  /* ── DAILY CALENDAR ── */
  .daily-screen {
    overflow: hidden !important;
    align-items: center !important;
  }
  .daily-screen > *:not(.daily-appbar) {
    max-width: var(--ls-container-w) !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  .daily-today-card {
    max-width: var(--ls-container-w) !important;
    margin: clamp(1px, 0.3dvh, 8px) auto !important;
    padding: clamp(4px, 1dvh, 16px) !important;
    gap: clamp(4px, 1vw, 14px) !important;
  }
  .daily-calendar {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    max-width: clamp(200px, 30vw, 360px) !important;
    margin: clamp(1px, 0.3dvh, 6px) auto !important;
    padding: 0 !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .daily-cal-header {
    margin-bottom: clamp(1px, 0.3dvh, 6px);
    flex-shrink: 0;
  }
  .daily-cal-header button {
    font-size: clamp(0.65rem, 1.5dvh, 1rem);
  }
  .daily-cal-weekdays {
    flex-shrink: 0;
    font-size: clamp(0.5rem, 1.2dvh, 0.75rem);
    justify-items: center;
    gap: clamp(3px, 1.2dvh, 8px);
  }
  .daily-cal-grid {
    gap: clamp(3px, 1.1dvh, 8px);
    flex: 0 0 auto;
    align-content: start;
    grid-auto-rows: auto;
    justify-items: center;
    align-items: center;
  }
  .daily-cal-day {
    font-size: clamp(0.5rem, 1.6dvh, 1rem);
    aspect-ratio: 1 !important;
    width: clamp(26px, 7.2dvh, 64px);
    height: clamp(26px, 7.2dvh, 64px);
    max-width: none;
    max-height: none;
  }
  .daily-play-btn {
    flex-shrink: 0 !important;
    height: clamp(24px, 6dvh, 44px) !important;
    margin: clamp(1px, 0.3dvh, 6px) auto clamp(2px, 0.5dvh, 8px) !important;
    padding: 0 16px !important;
    font-size: clamp(0.6rem, 1.4dvh, 0.85rem);
    max-width: var(--ls-container-w) !important;
  }

  /* ── CLEAR SCREEN ── */
  .gameclear-content {
    padding-bottom: 0;
    gap: clamp(8px, 2dvh, 20px);
  }
  .gameclear-title {
    height: auto;
    width: clamp(160px, 25vw, 300px);
    margin-top: clamp(4px, 1dvh, 12px);
  }
  .gameclear-preview {
    max-width: clamp(200px, 50dvh, 450px);
    max-height: clamp(200px, 50dvh, 450px);
  }
  .gameclear-stats {
    gap: clamp(12px, 3vw, 32px);
  }
  .gameclear-stat {
    font-size: clamp(0.85rem, 2dvh, 1.4rem);
  }
  .gameclear-stat-label {
    font-size: clamp(0.5rem, 1.2dvh, 0.7rem);
  }
  .gameclear-buttons {
    position: relative;
    bottom: auto;
    padding: clamp(4px, 1dvh, 12px) 16px;
  }
  .gameclear-btn {
    height: clamp(30px, 7.5dvh, 52px);
    font-size: clamp(0.82rem, 2.5dvh, 1.3rem);
    min-width: clamp(64px, 10vw, 120px);
    padding: 0 clamp(8px, 1.5vw, 20px);
  }

  /* ── GAME OVER ── */
  .gameover-content {
    gap: clamp(8px, 2dvh, 20px);
  }
  .gameover-title {
    font-size: clamp(1.2rem, 4dvh, 2rem);
  }
  .gameover-btn {
    height: clamp(32px, 8dvh, 48px);
    font-size: clamp(0.65rem, 1.5dvh, 0.85rem);
    padding: 0 clamp(12px, 2vw, 24px);
  }
  /* GAME OVER reward button (WATCH AD) — scale down in landscape */
  .rewarded-btn {
    padding: clamp(6px, 1.5dvh, 12px) clamp(10px, 2vw, 20px);
    margin-bottom: clamp(6px, 1.5dvh, 12px);
    font-size: clamp(0.78rem, 2dvh, 1.15rem);
    gap: clamp(4px, 1vw, 8px);
  }
  .rewarded-btn svg {
    width: clamp(13px, 2.2dvh, 18px);
    height: clamp(13px, 2.2dvh, 18px);
  }

  /* ── SETTINGS / MODAL DIALOGS — fit within 360px height ── */
  .modal-overlay { padding: clamp(6px, 2dvh, 20px); }
  .modal-box {
    max-height: calc(100dvh - clamp(12px, 4dvh, 40px));
    overflow-y: auto;
    padding: clamp(12px, 3dvh, 24px);
  }
  .modal-box h2 { margin-bottom: clamp(4px, 1.2dvh, 16px); }
  .modal-settings .setting-row { padding: clamp(4px, 1.1dvh, 12px) 0; }
  .modal-settings .setting-row span { font-size: clamp(0.75rem, 1.7dvh, 0.95rem); }
  .modal-settings .modal-buttons { margin-top: clamp(6px, 1.5dvh, 16px); }

} /* end @media (min-aspect-ratio: 1/1) */
