/* ===== 主题变量 ===== */
:root {
  /* 亮色（默认） */
  --bg: #e8f4f8;
  --cell: #a8d4f0;
  --cell-hover: #8bc4e8;
  --blocked: #1a3a5c;
  --cat: #333333;
  --text-primary: #1a3a5c;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --button-bg: #1a3a5c;
  --button-text: #ffffff;
  --button-hover: #2a4a6c;
  --win: #2ecc71;
  --lose: #e74c3c;
  --toggle-border: #999999;
  color-scheme: light;
}

/* 暗色：跟随系统 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a2b3c;
    --cell: #2c3e50;
    --cell-hover: #3a4f63;
    --blocked: #7fb8d8;
    --cat: #888888;
    --text-primary: #7fb8d8;
    --text-secondary: #aab2bd;
    --text-tertiary: #6c7a89;
    --button-bg: #7fb8d8;
    --button-text: #1a2b3c;
    --button-hover: #8bc4e8;
    --toggle-border: #6c7a89;
    color-scheme: dark;
  }
}

/* 暗色：手动覆盖（在亮色系统下强制暗色） */
body.theme-dark {
  --bg: #1a2b3c;
  --cell: #2c3e50;
  --cell-hover: #3a4f63;
  --blocked: #7fb8d8;
  --cat: #888888;
  --text-primary: #7fb8d8;
  --text-secondary: #aab2bd;
  --text-tertiary: #6c7a89;
  --button-bg: #7fb8d8;
  --button-text: #1a2b3c;
  --button-hover: #8bc4e8;
  --toggle-border: #6c7a89;
  color-scheme: dark;
}

/* 亮色：手动覆盖（在暗色系统下强制亮色） */
body.theme-light {
  --bg: #e8f4f8;
  --cell: #a8d4f0;
  --cell-hover: #8bc4e8;
  --blocked: #1a3a5c;
  --cat: #333333;
  --text-primary: #1a3a5c;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --button-bg: #1a3a5c;
  --button-text: #ffffff;
  --button-hover: #2a4a6c;
  --toggle-border: #999999;
  color-scheme: light;
}

/* ===== 基础样式 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: background 0.2s ease;
}

.container {
  text-align: center;
  padding: 20px;
}

header h1 {
  font-size: 120px;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 10px;
  transition: color 0.2s ease;
}

.subtitle {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  transition: color 0.2s ease;
}

.hint {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-bottom: 30px;
  transition: color 0.2s ease;
}

/* ===== 主题切换按钮 ===== */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  min-width: 56px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--toggle-border);
  border-radius: 16px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
}

.theme-toggle:hover {
  background: var(--text-tertiary);
  color: var(--bg);
  transform: scale(1.05);
}

.theme-toggle:active {
  transform: scale(0.98);
}

/* 声音开关按钮（叠在主题按钮下方） */
.sound-toggle {
  position: fixed;
  top: 60px;
  right: 20px;
  min-width: 56px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--toggle-border);
  border-radius: 16px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
}

.sound-toggle:hover {
  background: var(--text-tertiary);
  color: var(--bg);
  transform: scale(1.05);
}

.sound-toggle:active {
  transform: scale(0.98);
}

/* 声音图标切换：通过 .muted 类切换两个 SVG 的可见性 */
.sound-toggle .sound-icon-off { display: none; }
.sound-toggle.muted .sound-icon-on { display: none; }
.sound-toggle.muted .sound-icon-off { display: block; }

/* ===== Canvas 样式 ===== */
#gameCanvas {
  display: block;
  margin: 0 auto;
  cursor: pointer;
  touch-action: none; /* 阻止移动端双指缩放/滚动 */
}

/* ===== 重置按钮 ===== */
.reset-btn {
  margin-top: 20px;
  padding: 12px 30px;
  font-size: 16px;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.reset-btn:hover {
  background: var(--button-hover);
  transform: scale(1.05);
}

.reset-btn:active {
  transform: scale(0.98);
}

/* ===== 撤销按钮（次要风格） ===== */
.undo-btn {
  margin-top: 20px;
  margin-right: 12px;
  padding: 12px 30px;
  font-size: 16px;
  background: transparent;
  color: var(--button-bg);
  border: 2px solid var(--button-bg);
  border-radius: 25px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.undo-btn:hover:not(:disabled) {
  background: var(--button-bg);
  color: var(--button-text);
  transform: scale(1.05);
}

.undo-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.undo-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ===== 难度选择 ===== */
.difficulty-picker {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 14px;
}

.difficulty-btn {
  padding: 6px 18px;
  font-size: 14px;
  font-family: inherit;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--toggle-border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.difficulty-btn:hover:not(.active) {
  border-color: var(--button-bg);
  color: var(--button-bg);
}

.difficulty-btn.active {
  background: var(--button-bg);
  color: var(--button-text);
  border-color: var(--button-bg);
  font-weight: 600;
}

/* ===== HUD（步数 + 计时） ===== */
.hud {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.hud strong {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: inline-block;
  min-width: 1.5em;
  text-align: center;
}

.hud-sep {
  color: var(--text-tertiary);
}

/* ===== 结束面板（胜负/统计/最佳/再来一局） ===== */
.message {
  margin-top: 20px;
  min-height: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.message .result {
  font-size: 24px;
  font-weight: bold;
}

.message.win .result { color: var(--win); }
.message.lose .result { color: var(--lose); }

.message .result-stats {
  font-size: 14px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.message .result-best {
  font-size: 13px;
  color: var(--text-tertiary);
}

.message .result-new {
  font-size: 13px;
  color: var(--win);
  font-weight: 600;
}

.play-again-btn {
  margin-top: 4px;
  padding: 8px 22px;
  font-size: 14px;
  font-family: inherit;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 18px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.play-again-btn:hover {
  background: var(--button-hover);
  transform: scale(1.04);
}

.play-again-btn:active {
  transform: scale(0.97);
}
