/* ============================================
   Sudoku Web — sudoku.com 벤치마크 스타일
   반응형 (모바일 퍼스트)
   ============================================ */

/* CSS Variables (Light theme) */
:root {
  --bg: #F5F8FC;
  --surface: #FFFFFF;
  --text: #344861;
  --text-secondary: #94A3B7;
  --primary: #325AAF;
  --primary-light: #E2EAF5;
  --danger: #E55C6C;
  --success: #27AE60;
  --border: #BFC6D4;
  --nav-bg: #FFFFFF;
  --nav-shadow: 0 2px 8px rgba(0,0,0,0.08);
  --cell-selected: #BBDEFB;
  --cell-related: #E2EAF5;
  --cell-same: #C8E6C9;
  --btn-bg: #FFFFFF;
  --btn-hover: #E2EAF5;
  --btn-active: #325AAF;
  --btn-active-text: #FFFFFF;
  --modal-bg: rgba(0,0,0,0.5);
  --num-btn-size: 56px;
  --font-main: 'Roboto', system-ui, -apple-system, sans-serif;
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #0B1422;
  --surface: #16213E;
  --text: #E0E0E0;
  --text-secondary: #7A8BA5;
  --primary: #5BA4E6;
  --primary-light: #1a3358;
  --danger: #EF5350;
  --success: #2ECC71;
  --border: #4a5e82;
  --nav-bg: #16213E;
  --nav-shadow: 0 2px 8px rgba(0,0,0,0.3);
  --btn-bg: #1a2744;
  --btn-hover: #1a3358;
  --btn-active: #5BA4E6;
  --btn-active-text: #0B1422;
  --modal-bg: rgba(0,0,0,0.7);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100dvh;
}

a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }

/* ============================================
   네비게이션 바
   ============================================ */
.nav-bar {
  background: var(--nav-bg);
  box-shadow: var(--nav-shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  gap: 12px;
}
.nav-left { display: flex; align-items: center; gap: 12px; }
.nav-tabs { display: flex; gap: 4px; }
.nav-tab {
  padding: 8px 16px;
  border-radius: 18px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.nav-tab:hover { color: var(--text); background: var(--primary-light); }
.nav-tab.active { color: var(--primary); background: var(--primary-light); font-weight: 600; }

.nav-right { display: flex; align-items: center; gap: 10px; }
.nav-link {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 6px;
  transition: color 0.2s;
}
.nav-link:hover { color: var(--text); }
.btn-icon { font-size: 18px; padding: 4px; }

/* 로고 */
.nav-logo-text {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

/* 2행: 게임 상태 바 */
.game-status-bar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.game-status-inner {
  max-width: 550px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  gap: 16px;
}
.pause-btn {
  font-size: 14px;
  padding: 2px 4px;
  opacity: 0.6;
  transition: opacity 0.2s;
  vertical-align: middle;
}
.pause-btn:hover { opacity: 1; }
.game-stat {
  font-size: 15px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.game-stat strong {
  color: var(--text);
}
.timer { cursor: pointer; }

/* ============================================
   메인 레이아웃
   ============================================ */
.main-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  gap: 24px;
  justify-content: center;
}
.game-area {
  flex: 0 1 500px;
  max-width: 500px;
  width: 100%;
}
.sidebar {
  flex: 0 0 300px;
  display: none;
}

/* ============================================
   난이도 셀렉터 (로고 통합)
   ============================================ */
.difficulty-selector { position: relative; }
.difficulty-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 8px;
  transition: all 0.2s;
}
.difficulty-btn:hover { opacity: 0.8; }
.difficulty-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  overflow: hidden;
  z-index: 50;
  min-width: 160px;
}
.difficulty-dropdown.open { display: block; }
.difficulty-dropdown button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  font-size: 14px;
  transition: background 0.15s;
}
.difficulty-dropdown button:hover { background: var(--primary-light); }
.difficulty-dropdown button.active { color: var(--primary); font-weight: 600; }

/* New Game 버튼 */
.btn-new-game {
  padding: 8px 18px;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.2s;
}
.btn-new-game:hover { opacity: 0.85; }

#mistakeValue { font-weight: 600; }
.timer { cursor: pointer; }

/* ============================================
   게임 보드
   ============================================ */
.board-container {
  width: 100%;
  aspect-ratio: 1;
  max-width: 500px;
  margin: 0 auto;
  touch-action: none; /* 스크롤 방지 */
}
#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
}

/* ============================================
   숫자 패드
   ============================================ */
.number-pad {
  display: flex;
  justify-content: center;
  gap: clamp(2px, 1vw, 6px);
  padding: 14px 0 8px;
}
.num-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: var(--num-btn-size);
  min-width: 30px;
  max-width: 56px;
  flex: 1 1 0;
  height: calc(var(--num-btn-size) + 8px);
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 28px;
  font-weight: 600;
  color: var(--primary);
  transition: all 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.num-btn:hover { background: var(--btn-hover); }
.num-btn:active { transform: scale(0.95); }
.num-btn:focus { outline: none; }
.num-btn.pressed { background: var(--btn-hover); transform: scale(0.93); }
.num-btn.disabled { opacity: 0.3; pointer-events: none; }

/* Notes 모드 시 숫자 패드 스타일 변경 */
.number-pad.notes-mode .num-btn {
  border-style: dashed;
  color: var(--text-secondary);
  font-size: 18px;
}
.number-pad.notes-mode .num-btn:not(.disabled) {
  border-color: var(--primary);
}

/* 격려 메시지 */
.emoji-message {
  text-align: center;
  height: 28px;
  line-height: 28px;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  opacity: 0;
  transition: opacity 0.3s;
}
.emoji-message.show {
  opacity: 1;
  animation: emojiPop 0.4s ease-out;
}
@keyframes emojiPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* ============================================
   컨트롤 바
   ============================================ */
.control-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 0 12px;
}
.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 15px;
  color: var(--text-secondary);
  transition: all 0.15s;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn svg { width: 22px; height: 22px; }
.ctrl-btn:hover { background: var(--btn-hover); color: var(--text); }
.ctrl-btn:active { transform: scale(0.95); }
.ctrl-btn:focus { outline: none; }
/* Notes ON 상태 — 토글 모드 */
.ctrl-btn.active {
  background: var(--primary);
  color: #FFFFFF;
  border-radius: 10px;
}
/* Undo/Erase 클릭 피드백 — 0.15초 후 사라짐 */
.ctrl-btn.pressed {
  background: var(--btn-hover);
  transform: scale(0.92);
}
.hint-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  background: var(--primary);
  color: white;
  font-size: 9px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   모달
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
}
.modal h2 { font-size: 24px; margin-bottom: 12px; }
.modal p { color: var(--text-secondary); margin-bottom: 12px; }
.second-chance-desc {
  font-size: 13px;
  color: var(--text-secondary);
  opacity: 0.7;
  margin-bottom: 20px;
}

.modal-actions { display: flex; gap: 12px; justify-content: center; }
.btn-primary {
  padding: 10px 28px;
  background: var(--primary);
  color: white;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-secondary {
  padding: 10px 28px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--btn-hover); }

/* 클리어 모달 */
.modal-clear h2 { font-size: 28px; }
.clear-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
}
.clear-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.clear-label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; }
.clear-value { font-size: 20px; font-weight: 700; color: var(--primary); }

/* ============================================
   SEO 콘텐츠
   ============================================ */
.seo-content {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 48px 16px;
  margin-top: 24px;
}
.seo-inner {
  max-width: 700px;
  margin: 0 auto;
}
.seo-content h1 {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}
.seo-content h2 {
  font-size: 26px;
  font-weight: 600;
  margin: 32px 0 12px;
  color: var(--text);
}
.seo-content p {
  color: var(--text-secondary);
  font-size: 17px;
  line-height: 1.8;
}

/* ============================================
   푸터
   ============================================ */
.footer {
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  padding: 24px 16px;
}
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}
.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin-bottom: 12px;
}
.footer-links a {
  font-size: 13px;
  color: var(--text-secondary);
}
.footer-links a:hover { color: var(--text); }
.footer-copy { font-size: 12px; color: var(--text-secondary); }

/* ============================================
   광고 플레이스홀더
   ============================================ */
/* 사이드바 광고 (데스크톱) */
.ad-placeholder {
  background: var(--primary-light);
  border: 2px dashed var(--border);
  border-radius: 8px;
  height: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* 하단 배너 광고 (모바일+태블릿) */
.ad-banner-bottom {
  margin-top: 8px;
  text-align: center;
}
.ad-placeholder-banner {
  height: 60px;
  border-radius: 6px;
}

/* 데스크톱에서는 하단 배너 숨기고 사이드바만 표시 */
@media (min-width: 769px) {
  .ad-banner-bottom { display: none; }
}

/* ============================================
   반응형
   ============================================ */

/* 모바일 (기본) */
@media (max-width: 480px) {
  :root { --num-btn-size: 36px; }
  .nav-inner { height: 42px; padding: 0 10px; }
  .nav-logo-text { font-size: 16px; }
  .nav-tabs { gap: 2px; }
  .nav-tab { padding: 4px 8px; font-size: 12px; }
  .btn-new-game { padding: 4px 8px; font-size: 11px; }
  .game-status-inner { padding: 4px 10px; }
  .game-stat { font-size: 12px; }
  .main-layout { padding: 4px 4px; }
  .game-area { max-width: 100%; }
  .num-btn { width: 36px; height: 44px; font-size: 18px; border-radius: 8px; }
  .number-pad { gap: 4px; }
  .ctrl-btn { padding: 6px 12px; }
  .ctrl-btn svg { width: 20px; height: 20px; }
  .seo-content { padding: 32px 12px; }
}

/* 태블릿 */
@media (min-width: 481px) and (max-width: 768px) {
  .game-area { max-width: 480px; }
}

/* 데스크톱 */
@media (min-width: 769px) {
  .sidebar { display: block; }
  .game-area { max-width: 500px; }
  .num-btn { width: 58px; height: 70px; font-size: 28px; }
  .ctrl-btn { padding: 12px 24px; font-size: 14px; }
  .ctrl-btn svg { width: 26px; height: 26px; }
}

@media (min-width: 1024px) {
  .main-layout { padding: 20px 32px; }
}
