/* ===== 数独挑战 · 专用样式 ===== */

/* ========== 数独区域 ========== */
.sudoku-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
  padding: 20px;
  background-image: url('../assets/focus-illus/sudoku-play-bg.jpg');
  background-size: cover;
  background-position: center;
  border-radius: var(--ft-radius);
  box-shadow: var(--ft-shadow-lg);
  border: 2px solid var(--ft-rule);
  overflow: hidden;
}
.sudoku-area::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.82);
  border-radius: var(--ft-radius);
  z-index: 0;
}
.sudoku-area > * {
  position: relative;
  z-index: 1;
}

/* ========== 数独网格 ========== */
.sudoku-board {
  display: grid;
  gap: 1px;
  background: var(--ft-ink);
  border: 3px solid var(--ft-ink);
  border-radius: var(--ft-radius-xs);
  padding: 3px;
  box-shadow: var(--ft-shadow-lg);
  margin: 0 auto;
  position: relative;
  width: fit-content;
}

/* 不同尺寸的宫格粗边框 */
.sudoku-board.size-4x4 { gap: 1px; border-width: 3px; }
.sudoku-board.size-4x4 .sudoku-cell:nth-child(2n):not(:nth-child(4n)) { border-right: 2px solid var(--ft-ink); }
.sudoku-board.size-4x4 .sudoku-cell:nth-child(n+3):nth-child(-n+4),
.sudoku-board.size-4x4 .sudoku-cell:nth-child(n+7):nth-child(-n+8) { border-bottom: 2px solid var(--ft-ink); }

.sudoku-board.size-6x6 { gap: 1px; border-width: 3px; }
.sudoku-board.size-6x6 .sudoku-cell:nth-child(3n):not(:nth-child(6n)) { border-right: 2px solid var(--ft-ink); }
.sudoku-board.size-6x6 .sudoku-cell:nth-child(n+7):nth-child(-n+12) { border-bottom: 2px solid var(--ft-ink); }

.sudoku-board.size-9x9 { gap: 1px; border-width: 3px; }
.sudoku-board.size-9x9 .sudoku-cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--ft-ink); }
.sudoku-board.size-9x9 .sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-board.size-9x9 .sudoku-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--ft-ink); }

.sudoku-board.size-16x16 { gap: 1px; border-width: 3px; }
.sudoku-board.size-16x16 .sudoku-cell:nth-child(4n):not(:nth-child(16n)) { border-right: 2px solid var(--ft-ink); }
.sudoku-board.size-16x16 .sudoku-cell:nth-child(n+33):nth-child(-n+48),
.sudoku-board.size-16x16 .sudoku-cell:nth-child(n+65):nth-child(-n+80),
.sudoku-board.size-16x16 .sudoku-cell:nth-child(n+97):nth-child(-n+112) { border-bottom: 2px solid var(--ft-ink); }

/* ========== 数独格子 ========== */
.sudoku-cell {
  background: linear-gradient(145deg, #FFFFFF, #FAFAF8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s ease;
  position: relative;
  aspect-ratio: 1;
  font-family: inherit;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.9);
}
.sudoku-cell:hover {
  background: linear-gradient(145deg, #FFF8E1, #FFF3E0);
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.9), 0 0 0 2px rgba(91,155,213,0.15);
}
.sudoku-cell.selected {
  background: linear-gradient(145deg, #E3F2FD, #BBDEFB) !important;
  box-shadow: inset 0 0 0 2px var(--ft-blue), 0 0 8px rgba(91,155,213,0.2);
}
.sudoku-cell.highlight {
  background: linear-gradient(145deg, #FFF3E0, #FFE8CC);
}
.sudoku-cell.same-value {
  background: linear-gradient(145deg, #E8F5E9, #C8E6C9);
}
.sudoku-cell.given {
  color: var(--ft-ink);
  font-weight: 800;
  background: linear-gradient(145deg, #F5F5F0, #EDEAE5);
}

/* 尺寸 */
.sudoku-board.size-4x4 { grid-template-columns: repeat(4, 52px); }
.sudoku-board.size-4x4 .sudoku-cell { font-size: 1.5rem; }

.sudoku-board.size-6x6 { grid-template-columns: repeat(6, 48px); }
.sudoku-board.size-6x6 .sudoku-cell { font-size: 1.4rem; }

.sudoku-board.size-9x9 { grid-template-columns: repeat(9, 44px); }
.sudoku-board.size-9x9 .sudoku-cell { font-size: 1.3rem; }

.sudoku-board.size-16x16 { grid-template-columns: repeat(16, 28px); }
.sudoku-board.size-16x16 .sudoku-cell { font-size: 0.85rem; }

/* 预设数字 */
.sudoku-cell.given {
  color: var(--ft-ink);
  font-weight: 800;
  background: #FAFAF8;
}

/* 选中 */
.sudoku-cell.selected {
  background: var(--ft-blue-soft) !important;
  box-shadow: inset 0 0 0 2px var(--ft-blue);
}

/* 同行同列同宫高亮 */
.sudoku-cell.highlight {
  background: #FFF3E0;
}

/* 填入的数字高亮 */
.sudoku-cell.same-value {
  background: #E8F5E9;
}

/* 错误 */
.sudoku-cell.error {
  color: #E53935 !important;
  background: #FFEBEE !important;
  animation: sudokuError 0.3s ease;
}
@keyframes sudokuError {
  0%, 100% { transform: scale(1); }
  25% { transform: scale(1.05); }
  75% { transform: scale(0.97); }
}

/* 正确填入 */
.sudoku-cell.user-filled {
  color: var(--ft-blue);
}

/* 笔记模式 */
.sudoku-cell .notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
  gap: 1px;
}
.sudoku-cell .notes .note {
  font-size: 0.55rem;
  color: var(--ft-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.sudoku-board.size-16x16 .sudoku-cell .notes { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.sudoku-board.size-16x16 .sudoku-cell .notes .note { font-size: 0.4rem; }
.sudoku-board.size-4x4 .sudoku-cell .notes { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.sudoku-board.size-4x4 .sudoku-cell .notes .note { font-size: 0.65rem; }

/* ========== 数字选板 ========== */
.sudoku-numpad {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
}
.sudoku-num-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--ft-rule);
  background: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ft-text);
  cursor: pointer;
  transition: var(--ft-transition);
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sudoku-num-btn:hover {
  border-color: var(--ft-blue);
  background: var(--ft-blue-soft);
  transform: scale(1.08);
}
.sudoku-num-btn:active { transform: scale(0.95); }

/* 工具按钮 */
.sudoku-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.sudoku-tool-btn {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--ft-rule);
  background: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ft-text);
  cursor: pointer;
  transition: var(--ft-transition);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.sudoku-tool-btn:hover {
  border-color: var(--ft-blue);
  background: var(--ft-blue-soft);
}
.sudoku-tool-btn.active {
  border-color: var(--ft-blue);
  background: var(--ft-blue-soft);
  color: var(--ft-blue);
  box-shadow: 0 2px 8px rgba(91,155,213,0.15);
}

/* 提示次数徽章 */
.sudoku-hint-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 50%;
  background: var(--ft-blue);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
}

/* ========== 规则提示浮层 ========== */
.sudoku-rule-tip {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--ft-blue);
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(91,155,213,0.3);
}
.sudoku-rule-tip:hover { transform: scale(1.1); }

.sudoku-rule-panel {
  position: absolute;
  top: 30px;
  right: -10px;
  background: #fff;
  border-radius: var(--ft-radius-xs);
  padding: 16px;
  box-shadow: var(--ft-shadow-lg);
  border: 1px solid var(--ft-rule);
  max-width: 260px;
  z-index: 100;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--ft-text);
  display: none;
}
.sudoku-rule-panel.show { display: block; }

/* ========== 难度选择（双维度） ========== */
.sudoku-diff-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.sudoku-diff-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ft-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ========== 完成弹窗扩展 ========== */
.sudoku-complete-stats .sudoku-stars {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 8px 0;
}
.sudoku-complete-stats .sudoku-star {
  font-size: 1.8rem;
  opacity: 0.3;
  transition: all 0.3s ease;
}
.sudoku-complete-stats .sudoku-star.earned {
  opacity: 1;
  animation: sudokuStarPop 0.4s ease;
}
@keyframes sudokuStarPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .sudoku-board.size-9x9 { grid-template-columns: repeat(9, 36px); }
  .sudoku-board.size-9x9 .sudoku-cell { font-size: 1.1rem; }
  .sudoku-board.size-6x6 { grid-template-columns: repeat(6, 40px); }
  .sudoku-board.size-6x6 .sudoku-cell { font-size: 1.2rem; }
  .sudoku-board.size-4x4 { grid-template-columns: repeat(4, 48px); }
  .sudoku-board.size-4x4 .sudoku-cell { font-size: 1.4rem; }
  .sudoku-board.size-16x16 { grid-template-columns: repeat(16, 26px); }
  .sudoku-board.size-16x16 .sudoku-cell { font-size: 0.78rem; }
  .sudoku-num-btn { width: 38px; height: 38px; font-size: 1rem; }
}

@media (max-width: 480px) {
  .sudoku-board.size-9x9 { grid-template-columns: repeat(9, 32px); }
  .sudoku-board.size-9x9 .sudoku-cell { font-size: 0.95rem; }
  .sudoku-board.size-6x6 { grid-template-columns: repeat(6, 36px); }
  .sudoku-board.size-6x6 .sudoku-cell { font-size: 1.1rem; }
  .sudoku-board.size-4x4 { grid-template-columns: repeat(4, 44px); }
  .sudoku-board.size-4x4 .sudoku-cell { font-size: 1.3rem; }
  .sudoku-board.size-16x16 { grid-template-columns: repeat(16, 22px); }
  .sudoku-board.size-16x16 .sudoku-cell { font-size: 0.65rem; }
  .sudoku-num-btn { width: 34px; height: 34px; font-size: 0.9rem; }
  .sudoku-tool-btn { padding: 6px 12px; font-size: 0.75rem; }
}
