/* ===== 우리집 스도쿠 ===== */
:root {
  --bg: #FDF4E6;
  --ink: #4A3B32;
  --sub: #9C8570;
  --card: #FFFFFF;
  --accent: #FF8A3D;
  --accent-dark: #F07B2D;
  --line: #F0E2CC;
  --line-strong: #C9AE8C;
  --cell-given: #FBF0DC;
  --sel: #FFE08A;
  --peer: #FFF6DE;
  --same: #FFE9B8;
  --bad: #FF595E;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

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

body {
  font-family: "Segoe UI", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background:
    radial-gradient(600px 400px at 85% -10%, #FFE3C2 0%, transparent 60%),
    radial-gradient(500px 350px at -10% 100%, #FFEFD4 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

/* 아이폰 노치/안드로이드 제스처 영역 대응 (앱 포장 대비) */
#app {
  width: 100%; max-width: 520px;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 16px calc(40px + env(safe-area-inset-bottom, 0px));
}

button { font-family: inherit; color: inherit; border: none; background: none; cursor: pointer; touch-action: manipulation; }
button:focus { outline: none; }
button:focus-visible { outline: 3px solid #FFB703; outline-offset: 2px; }

.screen { display: none; flex-direction: column; align-items: center; gap: 18px; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ---------- 숫자 색깔 ---------- */
.n1 { color: #FF595E; } .n2 { color: #F4762C; } .n3 { color: #E0A800; }
.n4 { color: #6BA82F; } .n5 { color: #1982C4; } .n6 { color: #4356A5; }
.n7 { color: #8446B8; } .n8 { color: #C4319E; } .n9 { color: #8A5A3B; }

/* ---------- 홈 화면 ---------- */
.home-head { text-align: center; margin-top: 10px; }
.home-mascot { font-size: 54px; line-height: 1; margin-bottom: 8px; }
h1 { font-size: clamp(28px, 8vw, 36px); letter-spacing: -1px; }
.tagline { color: var(--sub); margin-top: 6px; font-weight: 600; }

.stat-line {
  font-weight: 700; color: #B47E33; background: #FFF3D6;
  padding: 8px 18px; border-radius: 999px; font-size: 15px;
}

.pick-title { font-weight: 800; font-size: 15px; color: var(--sub); align-self: flex-start; }

.size-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.size-card {
  background: var(--card); border: 3px solid var(--line); border-radius: 20px;
  padding: 14px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform .25s var(--ease), border-color .25s, background .25s;
  box-shadow: 0 4px 14px rgba(180, 120, 60, .08);
}
.size-card b { font-size: 20px; }
.size-card small { color: var(--sub); font-weight: 600; }
.size-emoji { font-size: 30px; line-height: 1; }
.size-card.sel { border-color: var(--accent); background: #FFF4E6; transform: scale(1.04); }

.diff-chips { display: flex; gap: 8px; width: 100%; }
.chip {
  flex: 1; background: var(--card); border: 3px solid var(--line); border-radius: 999px;
  padding: 11px 0; font-weight: 800; font-size: 15px;
  transition: border-color .25s, background .25s;
}
.chip.sel { border-color: var(--accent); background: #FFF4E6; }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; background: var(--card); border: 3px solid var(--line);
  border-radius: 16px; padding: 13px 16px; font-weight: 700; cursor: pointer;
}
.toggle-row input { display: none; }
.switch {
  width: 52px; height: 30px; background: #E8D9C3; border-radius: 999px;
  position: relative; transition: background .25s; flex-shrink: 0;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: left .25s var(--ease);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .15);
}
.toggle-row input:checked + .switch { background: var(--accent); }
.toggle-row input:checked + .switch::after { left: 25px; }

.btn {
  border-radius: 18px; font-weight: 800; font-size: 17px; padding: 14px 22px;
  transition: transform .2s var(--ease), box-shadow .2s;
}
.btn.primary {
  background: linear-gradient(180deg, #FF9D53, #F07B2D); color: #fff;
  box-shadow: 0 6px 16px rgba(240, 123, 45, .35);
}
.btn.primary:active { transform: scale(.97); }
.btn.primary[disabled] { opacity: .6; }
.btn.big { width: 100%; font-size: 20px; padding: 16px; }
.btn.ghost { background: #fff; border: 3px solid var(--line); color: var(--sub); }
.btn.continue { width: 100%; background: #fff; border: 3px dashed var(--accent); color: var(--accent-dark); }

.home-foot { color: #C7B299; font-size: 13px; font-weight: 600; margin-top: 4px; }

/* ---------- 게임 화면 ---------- */
.top-bar { display: flex; align-items: center; gap: 8px; width: 100%; }
.icon-btn {
  font-size: 21px; width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0;
  background: #fff; border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.game-info { font-weight: 800; font-size: 14px; color: var(--sub); flex: 1; }
.timer {
  font-weight: 800; font-variant-numeric: tabular-nums; font-size: 15px;
  background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 9px 10px;
}

.board {
  --n: 4;
  width: min(92vw, 440px); aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  background: #fff; border: 3px solid var(--line-strong); border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(180, 120, 60, .15);
}
.cell {
  display: flex; align-items: center; justify-content: center;
  border-top: 1px solid var(--line); border-left: 1px solid var(--line);
  font-weight: 800; line-height: 1; padding: 0;
  font-size: calc(min(92vw, 440px) / var(--n) * .48);
  background: #fff; transition: background .12s;
}
.cell.t0 { border-top: none; }
.cell.l0 { border-left: none; }
.cell.bt { border-top: 3px solid var(--line-strong); }
.cell.bl { border-left: 3px solid var(--line-strong); }
.cell.given { background: var(--cell-given); color: var(--ink); }
.cell.bad { background: #FFE3E4; color: var(--bad); }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.sel { background: var(--sel) !important; }

.pop { animation: pop .3s var(--ease); }
.shakeit { animation: shakekf .3s; }
@keyframes pop { 0% { transform: scale(.5); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shakekf { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.pad { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; width: 100%; max-width: 440px; }
.pad-btn {
  width: clamp(46px, 12.5vw, 58px); height: clamp(46px, 12.5vw, 58px);
  border-radius: 16px; font-size: clamp(20px, 6vw, 26px); font-weight: 800;
  background: #fff; border: 2px solid var(--line); box-shadow: 0 3px 0 #EAD9BE;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s var(--ease);
}
.pad-btn:active { transform: translateY(2px); box-shadow: none; }
.pad-btn.done { opacity: .25; pointer-events: none; }

.tools { display: flex; gap: 10px; width: 100%; max-width: 440px; }
.tool-btn {
  flex: 1; background: #fff; border: 2px solid var(--line); border-radius: 16px;
  padding: 13px; font-weight: 800; font-size: 16px; box-shadow: 0 3px 0 #EAD9BE;
}
.tool-btn:active { transform: translateY(2px); box-shadow: none; }
.tool-btn[disabled] { opacity: .4; }
#hintCount {
  display: inline-block; background: var(--accent); color: #fff;
  border-radius: 999px; padding: 1px 8px; font-size: 13px; margin-left: 2px;
}

/* ---------- 완료 오버레이 ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(74, 59, 50, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.win-card {
  background: #fff; border-radius: 26px; padding: 30px 26px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  width: min(84vw, 340px); text-align: center;
  animation: rise .5s var(--ease);
  box-shadow: 0 30px 60px rgba(0, 0, 0, .25);
}
@keyframes rise { from { transform: translateY(40px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.win-stars { font-size: 44px; letter-spacing: 4px; }
.win-stars span { display: inline-block; animation: starpop .5s var(--ease) backwards; }
.win-stars span:nth-child(2) { animation-delay: .15s; }
.win-stars span:nth-child(3) { animation-delay: .3s; }
.win-stars span.dim { filter: grayscale(1); opacity: .25; }
@keyframes starpop { from { transform: scale(0) rotate(-30deg); } to { transform: scale(1) rotate(0); } }
.win-card h2 { font-size: 24px; }
.win-card p { color: var(--sub); font-weight: 600; }
.win-card .btn { width: 100%; }

#confettiWrap { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
.confetti { position: absolute; top: -20px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- 놀이터 (게임 선택) ---------- */
.game-cards { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.game-card {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--card); border: 3px solid var(--line); border-radius: 20px;
  padding: 16px 18px; box-shadow: 0 4px 14px rgba(180, 120, 60, .08);
  transition: transform .2s var(--ease);
}
button.game-card:active { transform: scale(.98); }
.game-card.open { border-color: var(--accent); background: #FFF8EE; box-shadow: 0 6px 16px rgba(240, 123, 45, .18); }
.game-card.soon { opacity: .55; }
.game-emoji { font-size: 34px; line-height: 1; }
.game-name { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.game-name b { font-size: 19px; }
.game-name small { color: var(--sub); font-weight: 600; }
.game-lock { font-size: 18px; }

/* ---------- 모험 모드 ---------- */
.mode-card {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  background: linear-gradient(135deg, #FFE9CF, #FFF7EA);
  border: 3px solid var(--accent); border-radius: 20px; padding: 16px 18px;
  box-shadow: 0 6px 16px rgba(240, 123, 45, .18);
  transition: transform .2s var(--ease);
}
.mode-card:active { transform: scale(.98); }
.mode-emoji { font-size: 34px; line-height: 1; }
.mode-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.mode-text b { font-size: 19px; }
.mode-text small { color: var(--sub); font-weight: 600; }
.mode-arrow { color: var(--accent); font-size: 18px; font-weight: 800; }

.divider { display: flex; align-items: center; gap: 10px; width: 100%; color: var(--sub); font-weight: 800; font-size: 14px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 2px; background: var(--line); border-radius: 2px; }

.stage-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; width: 100%; }
.stage-sect { grid-column: 1 / -1; font-weight: 800; color: var(--sub); font-size: 14px; margin-top: 8px; }
.stage-btn {
  aspect-ratio: 1 / 1; border-radius: 18px; background: #fff; border: 3px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-weight: 800; font-size: 18px; box-shadow: 0 3px 0 #EAD9BE;
  transition: transform .15s var(--ease);
}
.stage-btn:active { transform: translateY(2px); box-shadow: none; }
.stage-btn .st-stars { font-size: 9px; letter-spacing: 1px; line-height: 1; }
.stage-btn.cleared { border-color: #8AC926; background: #F4FBE9; }
.stage-btn.current { border-color: var(--accent); background: #FFF4E6; animation: pulsekf 1.6s infinite; }
.stage-btn.locked { opacity: .45; box-shadow: none; pointer-events: none; }
@keyframes pulsekf { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

/* ---------- 씽씽 레이싱 ---------- */
/* 주행 중엔 화면 어디서든 드래그 조종 — 자식 요소까지 스크롤 차단해야 iOS에서 안 끊김 */
#raceGame, #raceGame * { touch-action: none; }
.race-wrap { position: relative; width: 100%; }
#raceCanvas {
  width: 100%;
  height: min(60vh, 540px);
  height: min(calc(100dvh - 240px), 620px); /* 폰 화면 높이에 맞춰 최대한 크게 */
  display: block;
  border-radius: 18px; border: 3px solid var(--line-strong);
  background: #C8ECFA; touch-action: none;
  box-shadow: 0 12px 30px rgba(180, 120, 60, .15);
}
.race-msg {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  background: rgba(74, 59, 50, .85); color: #fff; font-weight: 800;
  padding: 8px 16px; border-radius: 999px; font-size: 16px; white-space: nowrap;
  animation: toastin .25s var(--ease);
}
.race-help { color: var(--sub); font-weight: 600; font-size: 13px; text-align: center; }
.engine-row { justify-content: center; font-weight: 800; font-size: 16px; }
.engine-row[disabled] { opacity: .5; }

/* ---------- 블록 팡 ---------- */
#blockGame, #blockGame * { touch-action: none; } /* 자식 요소까지 — iOS 드래그 끊김 방지 */
.block-wrap { position: relative; display: flex; justify-content: center; width: 100%; }
#blockCanvas {
  height: min(52vh, 480px);
  height: min(calc(100dvh - 275px), 580px); /* 폰 화면 높이에 맞춰 최대한 크게 */
  aspect-ratio: 10 / 16; max-width: 88vw;
  display: block; border-radius: 16px; border: 3px solid var(--line-strong);
  background: #FFFDF5; touch-action: none;
  box-shadow: 0 12px 30px rgba(180, 120, 60, .15);
}
#nextCanvas {
  width: 44px; height: 44px; flex-shrink: 0;
  background: #fff; border: 2px solid var(--line); border-radius: 12px;
}
.block-controls { display: flex; gap: 10px; width: 100%; max-width: 400px; }
.ctl-btn {
  flex: 1; font-size: 24px; padding: 13px 0; font-weight: 800;
  background: #fff; border: 2px solid var(--line); border-radius: 16px;
  box-shadow: 0 3px 0 #EAD9BE; touch-action: none;
}
.ctl-btn:active { transform: translateY(2px); box-shadow: none; }

/* ---------- 같은 그림 찾기 ---------- */
.mem-grid { display: grid; grid-template-columns: repeat(var(--mc, 4), 1fr); gap: 8px; width: 100%; max-width: 420px; }
.mem-card { aspect-ratio: 3 / 4; position: relative; perspective: 600px; padding: 0; }
.mem-in { position: absolute; inset: 0; transition: transform .35s var(--ease); transform-style: preserve-3d; }
.mem-card.flip .mem-in, .mem-card.done .mem-in { transform: rotateY(180deg); }
.mem-face {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  border-radius: 14px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  font-size: clamp(24px, 9vw, 38px); border: 2px solid var(--line);
  box-shadow: 0 3px 0 #EAD9BE; background: #fff;
}
.mem-front { background: linear-gradient(135deg, #FFE3B3, #FFC53D); font-size: clamp(18px, 6vw, 26px); }
.mem-back { transform: rotateY(180deg); }
.mem-card.done .mem-back { background: #F4FBE9; border-color: #8AC926; }
.mem-card.done { pointer-events: none; }

/* ---------- 두더지 잡기 ---------- */
.mole-wrap { position: relative; width: 100%; display: flex; justify-content: center; }
.mole-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; max-width: 420px; }
.hole {
  aspect-ratio: 1; position: relative; overflow: hidden; padding: 0;
  background: radial-gradient(ellipse 62% 32% at 50% 80%, #B08968 0%, #C9A87C 55%, #EFDCBE 56%);
  border: 3px solid var(--line); border-radius: 22px;
  box-shadow: inset 0 -6px 12px rgba(140, 100, 60, .22);
}
.hole .mole {
  position: absolute; left: 50%; bottom: 6%;
  transform: translate(-50%, 140%);
  font-size: clamp(36px, 12vw, 54px); line-height: 1;
  transition: transform .15s var(--ease);
}
.hole.up .mole { transform: translate(-50%, 0); }
.hole.gold {
  border-color: #FFB703;
  box-shadow: inset 0 -6px 12px rgba(140, 100, 60, .22), 0 0 14px rgba(255, 183, 3, .55);
}

/* ---------- 안내 말풍선 ---------- */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-weight: 700; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; z-index: 70; white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
  animation: toastin .3s var(--ease);
}
@keyframes toastin { from { transform: translate(-50%, -16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
