/* ========== 基础重置与变量 ========== */
:root {
  --bg-primary: #0f0f12;
  --bg-secondary: #1a1a1e;
  --bg-tertiary: #252529;
  --text-primary: #e8e6e3;
  --text-secondary: #9e9b97;
  --accent: #c9a96e;
  --accent-hover: #d4b87a;
  --accent-dim: #8a734a;
  --border: #333336;
  --border-light: #3a3a3e;
  --error: #c94f4f;
  --error-bg: rgba(201, 79, 79, 0.15);
  --success: #5a9e6e;
  --cell-bg: #1c1c20;
  --cell-fixed: #252529;
  --highlight: rgba(201, 169, 110, 0.12);
  --highlight-strong: rgba(201, 169, 110, 0.25);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-sm: 4px;
  --font-serif: 'Noto Serif SC', 'Songti SC', 'STSong', serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* 水墨主题 */
.theme-ink {
  --bg-primary: #0c0c0f;
  --bg-secondary: #141418;
  --accent: #7a9eb5;
  --accent-hover: #8ab3cc;
  --accent-dim: #4a6a7d;
  --highlight: rgba(122, 158, 181, 0.12);
  --highlight-strong: rgba(122, 158, 181, 0.22);
}

/* 暗金主题（默认） */
.theme-gold {
  --bg-primary: #0f0f12;
  --bg-secondary: #1a1a1e;
  --accent: #c9a96e;
  --accent-hover: #d4b87a;
  --accent-dim: #8a734a;
  --highlight: rgba(201, 169, 110, 0.12);
  --highlight-strong: rgba(201, 169, 110, 0.25);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-serif);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.8;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ========== 导航 ========== */
.nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(15, 15, 18, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
}

.nav-brand {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 4px;
}

.nav-links {
  display: flex;
  gap: 32px;
}

.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.3s;
  position: relative;
}

.nav-links a:hover {
  color: var(--accent);
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  transition: width 0.3s;
}

.nav-links a:hover::after {
  width: 100%;
}

.nav-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* ========== 区块通用样式 ========== */
.section {
  padding: 100px 24px 60px;
  max-width: 900px;
  margin: 0 auto;
}

.section-number {
  font-size: 0.85rem;
  color: var(--accent-dim);
  font-family: var(--font-mono);
  margin-bottom: 8px;
  letter-spacing: 2px;
}

.section-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 32px;
  color: var(--text-primary);
  letter-spacing: 2px;
}

/* ========== 首屏 Hero ========== */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 120px 24px 80px;
  position: relative;
}

.hero::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, var(--highlight-strong) 0%, transparent 70%);
  pointer-events: none;
  opacity: 0.6;
}

.hero-title {
  font-size: 3.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 12px;
  margin-bottom: 16px;
  position: relative;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 48px;
  letter-spacing: 4px;
}

.hero-cta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ========== 按钮 ========== */
.btn {
  padding: 12px 32px;
  border: 1px solid var(--accent-dim);
  background: transparent;
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: 1rem;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.3s ease;
  letter-spacing: 2px;
  position: relative;
  overflow: hidden;
}

.btn:hover {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(201, 169, 110, 0.3);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  font-weight: 700;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 30px rgba(201, 169, 110, 0.4);
}

.btn-small {
  padding: 8px 20px;
  font-size: 0.9rem;
}

.btn.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

/* ========== 起局区块（菜单） ========== */
.setup-area {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.difficulty-selector {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 32px;
  justify-content: center;
}

.difficulty-btn {
  padding: 10px 24px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-family: var(--font-serif);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.3s;
  font-size: 0.95rem;
}

.difficulty-btn:hover {
  border-color: var(--accent-dim);
  color: var(--text-primary);
}

.difficulty-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--highlight);
}

.start-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ========== 游戏面板 ========== */
.game-area {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 32px;
  align-items: start;
}

.game-board-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
}

#sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 1px;
  background: var(--border);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 2px;
  width: 100%;
  max-width: 540px;
  aspect-ratio: 1;
}

.cell {
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  font-family: var(--font-serif);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  position: relative;
  aspect-ratio: 1;
}

.cell:hover {
  background: var(--bg-tertiary);
}

.cell.fixed {
  background: var(--cell-fixed);
  color: var(--text-primary);
  font-weight: 700;
}

.cell.user-fill {
  color: var(--accent);
  font-weight: 600;
}

.cell.selected {
  background: var(--highlight-strong) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cell.highlight-line {
  background: var(--highlight);
}

.cell.highlight-same {
  background: rgba(201, 169, 110, 0.18);
}

.cell.conflict {
  animation: conflictPulse 0.5s ease;
  background: var(--error-bg) !important;
  color: var(--error) !important;
}

.cell.error-check {
  animation: errorShake 0.4s ease;
  background: var(--error-bg) !important;
  color: var(--error) !important;
}

@keyframes conflictPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes errorShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* 笔记 */
.note-cell {
  padding: 2px;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  font-size: clamp(0.5rem, 1.5vw, 0.75rem);
  color: var(--text-secondary);
}

.notes-grid span {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 宫格粗边框 */
.cell.border-top {
  border-top: 2px solid var(--border-light) !important;
  margin-top: 1px;
}

.cell.border-left {
  border-left: 2px solid var(--border-light) !important;
  margin-left: 1px;
}

.cell.border-right {
  border-right: 2px solid var(--border-light) !important;
}

.cell.border-bottom {
  border-bottom: 2px solid var(--border-light) !important;
}

/* 暂停遮罩 */
#board-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 18, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  border-radius: var(--radius-sm);
}

#board-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.board-overlay-text {
  font-size: 1.5rem;
  color: var(--accent);
  letter-spacing: 8px;
  margin-bottom: 24px;
}

/* ========== 侧边控制面板 ========== */
.control-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 手机端垂直布局：棋盘顶上，底部左右分布 */
@media (max-width: 768px) {
  .game-area {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  #sudoku-grid {
    max-width: 100%;
  }
  
  /* 非对局态隐藏控制面板和空棋盘 */
  #section-game:not(.active) .control-panel,
  #section-game:not(.active) .game-board-wrapper {
    display: none;
  }
  
  .control-panel {
    position: static;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 8px;
    padding: 8px 12px 12px;
    border-radius: var(--radius);
    box-shadow: none;
    background: var(--bg-primary);
    border: none;
  }
  
  .status-display {
    display: none;
  }
  
  /* 左：3×3 数字九宫格 */
  .num-pad {
    flex: 0 0 60%;
    order: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  
  .num-btn {
    width: 100%;
    aspect-ratio: 1;
    font-size: 1.1rem;
    padding: 0;
  }
  
  /* 右：功能按钮竖排 */
  .action-grid {
    flex: 1;
    order: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  
  .action-btn {
    flex: 1;
    width: 100%;
    padding: 4px 6px;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  #btn-new-game {
    display: none;
  }
}

.status-display {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.status-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.status-label {
  color: var(--text-secondary);
}

.status-value {
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 600;
}

/* 数字键盘 */
.num-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.num-btn {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.num-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--highlight);
}

/* 功能按钮 */
.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.action-btn {
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-family: var(--font-serif);
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.action-btn:hover {
  border-color: var(--accent-dim);
  color: var(--text-primary);
}

.action-btn.active {
  background: var(--highlight);
  border-color: var(--accent);
  color: var(--accent);
}

/* ========== 历史记录 ========== */
#history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  transition: all 0.3s;
}

.history-item:hover {
  border-color: var(--border-light);
  transform: translateX(4px);
}

.history-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 8px;
}

.history-rank {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
  min-width: 60px;
}

.history-diff {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.history-time {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.history-sub {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px;
  font-style: italic;
}

/* ========== 统计 ========== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  transition: all 0.3s;
}

.stat-card:hover {
  border-color: var(--accent-dim);
}

.stat-value {
  font-size: 2rem;
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 700;
  margin-bottom: 8px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ========== 规则说明 ========== */
.rules-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.rules-content h3 {
  color: var(--accent);
  margin: 24px 0 12px;
  font-size: 1.1rem;
}

.rules-content h3:first-child {
  margin-top: 0;
}

.rules-content p, .rules-content li {
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.rules-content ul {
  margin-left: 20px;
}

/* ========== 胜利弹窗 ========== */
#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 18, 0.94);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}

#win-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.win-card {
  background: var(--bg-secondary);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 48px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  position: relative;
}

.win-title {
  font-size: 1.8rem;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 4px;
}

.win-subtitle {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 0.95rem;
}

.win-stats {
  display: flex;
  justify-content: space-around;
  margin-bottom: 32px;
  padding: 20px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.win-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.win-stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.win-stat-value {
  font-size: 1.3rem;
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
}

.win-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ========== Toast 提示 ========== */
#toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  border: 1px solid var(--accent-dim);
  color: var(--text-primary);
  padding: 14px 32px;
  border-radius: var(--radius);
  z-index: 150;
  opacity: 0;
  transition: all 0.4s ease;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========== 页脚 ========== */
.footer {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .hero-title {
    font-size: 2.2rem;
    letter-spacing: 6px;
  }
  
  .section {
    padding: 80px 16px 40px;
  }
  
  .nav-links {
    display: none;
  }
  
  .win-card {
    padding: 32px 24px;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ========== 滚动条美化 ========== */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}
