/* ================= 全局配色：极简黑白灰 ================= */
:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-border: #e5e5ea;
  --inset: #f2f2f5;
  --text: #1d1d1f;
  --muted: #86868b;
  --accent: #1d1d1f;
  --lose: #d70015;

  --tile-top: #d3e6ff;
  --tile-bottom: #bcd8fc;
  --tile-hover-top: #e2eeff;
  --tile-hover-bottom: #cce1fd;
  --tile-edge: #9dbde8;
  --opened: #ffffff;
  --board-bg: #e9eff7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

.app {
  width: 100%;
  padding: 32px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* ================= 标题 ================= */
.header {
  text-align: center;
}

.title {
  margin: 0;
  padding-left: 10px;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 10px;
  color: var(--text);
}

/* ================= 主面板 ================= */
.panel {
  max-width: calc(100vw - 24px);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  box-shadow: 0 20px 40px -24px rgba(0, 0, 0, 0.18);
}

/* ---------- 难度：分段选择器 ---------- */
.levels {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 4px;
  background: var(--inset);
  border-radius: 14px;
}

.levels button {
  min-width: 84px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.levels button span {
  font-size: 15px;
  font-weight: 600;
}

.levels button small {
  font-size: 11px;
  color: var(--muted);
}

.levels button:hover {
  background: rgba(0, 0, 0, 0.05);
}

.levels button.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.4);
}

.levels button.active small {
  color: rgba(255, 255, 255, 0.7);
}

/* ---------- 自定义表单 ---------- */
.custom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.custom-fields {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 10px;
}

.custom label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.custom input {
  width: 76px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.custom input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.btn-primary {
  padding: 9px 20px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-primary:hover {
  opacity: 0.85;
}

.btn-primary:active {
  transform: translateY(1px);
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.hint.warn {
  color: #c76a00;
}

/* ---------- 状态栏 ---------- */
.status {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--inset);
  border-radius: 14px;
}

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

.stat-right {
  align-items: flex-end;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.face {
  width: 52px;
  height: 52px;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px -6px rgba(0, 0, 0, 0.3);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s;
}

.face:hover {
  transform: scale(1.08) rotate(-8deg);
}

.face:active {
  transform: scale(0.95);
}

/* ================= 棋盘 ================= */
.board-wrap {
  max-width: 100%;
  overflow: auto;
  border-radius: 14px;
}

.board-wrap.shake {
  animation: shake 0.4s ease-in-out;
}

.board {
  --cell: 32px;
  --gap: 3px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 9), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  width: max-content;
  padding: 10px;
  background: var(--board-bg);
  border-radius: 14px;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.08);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: box-shadow 0.4s;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--cell) * 0.2);
  background: linear-gradient(180deg, var(--tile-top), var(--tile-bottom));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 2px 0 var(--tile-edge);
  font-size: calc(var(--cell) * 0.56);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
}

.cell:not(.revealed):hover {
  background: linear-gradient(180deg, var(--tile-hover-top), var(--tile-hover-bottom));
}

.cell:not(.revealed):active {
  transform: translateY(1px);
}

.cell.revealed {
  background: var(--opened);
  box-shadow: none;
  cursor: default;
  animation: reveal 0.18s ease-out;
}

.cell.flagged {
  font-size: calc(var(--cell) * 0.5);
  animation: flag 0.2s ease-out;
}

.cell.mine {
  background: #ffe5e3;
  font-size: calc(var(--cell) * 0.55);
}

.cell.exploded {
  background: #ff3b30;
  box-shadow: 0 0 14px 2px rgba(255, 59, 48, 0.45);
  animation: explode 0.5s ease-out;
}

.cell.wrong {
  background: #fff1d6;
  font-size: calc(var(--cell) * 0.45);
}

/* 数字颜色：保留经典的区分度，色调偏沉稳 */
.n1 { color: #007aff; }
.n2 { color: #2f9e6f; }
.n3 { color: #ff3b30; }
.n4 { color: #5856d6; }
.n5 { color: #c93400; }
.n6 { color: #0a9dbd; }
.n7 { color: #1d1d1f; }
.n8 { color: #8e8e93; }

/* 游戏结束后格子不再响应悬停 */
.board.over .cell {
  cursor: default;
}

.board.over .cell:not(.revealed):hover {
  background: linear-gradient(180deg, var(--tile-top), var(--tile-bottom));
}

.board.win {
  box-shadow:
    inset 0 1px 4px rgba(0, 0, 0, 0.08),
    0 0 0 2px var(--accent),
    0 12px 30px -10px rgba(0, 0, 0, 0.35);
}

/* ================= 结果提示 ================= */
.result-row {
  min-height: 36px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.message,
.best {
  margin: 0;
}

.message:empty,
.best:empty {
  display: none;
}

.message {
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  background: var(--inset);
  color: var(--muted);
  animation: fade-in 0.3s ease-out;
}

.message.win {
  background: var(--accent);
  color: #fff;
}

.message.lose {
  background: #fff0ef;
  color: var(--lose);
  box-shadow: inset 0 0 0 1px #ffc9c5;
}

.best {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

/* ================= 操作说明 ================= */
.tips {
  max-width: 680px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  font-size: 13px;
  color: var(--muted);
}

.tips li {
  display: flex;
  align-items: center;
  gap: 6px;
}

kbd {
  padding: 2px 8px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #d2d2d7;
  border-bottom-width: 2px;
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
}

/* ================= 动画 ================= */
@keyframes reveal {
  from { transform: scale(0.6); opacity: 0.2; }
  to   { transform: scale(1);   opacity: 1; }
}

@keyframes flag {
  0%   { transform: scale(0.4) rotate(-20deg); }
  70%  { transform: scale(1.15) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes explode {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

/* ================= 窄屏 ================= */
@media (max-width: 480px) {
  .title {
    font-size: 32px;
  }

  .panel {
    padding: 12px;
    border-radius: 18px;
  }

  .levels button {
    min-width: 70px;
    padding: 7px 8px;
  }

  .stat-value {
    font-size: 22px;
  }
}
