* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --ink: #14201c;
  --muted: #4d635a;
  --paper: #eef5f1;
  --teal: #1f6f5b;
  --mint: #7ec8a3;
  --sky: #3d8ea5;
  --coral: #e07a5f;
  --line: rgba(20, 32, 28, 0.15);
  --cell-bg: #c7d4cf;
  --cell-bg-open: #eef5f1;
}

html,
body {
  height: 100%;
}

body {
  font-family: "IBM Plex Sans", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 0% 0%, rgba(61, 142, 165, 0.25), transparent 60%),
    radial-gradient(800px 420px at 100% 10%, rgba(31, 111, 91, 0.18), transparent 55%),
    var(--paper);
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding:
    max(6px, env(safe-area-inset-top))
    max(0px, env(safe-area-inset-right))
    max(0px, env(safe-area-inset-bottom))
    max(0px, env(safe-area-inset-left));
  overflow-y: auto;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#box {
  width: min(720px, 100vw);
  max-width: 100%;
  padding: clamp(0.6rem, 2.4vw, 1rem);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.back-home {
  align-self: flex-start;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--teal);
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
  text-decoration: none;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title-row h1 {
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: clamp(2rem, 8vw, 2.6rem);
  color: var(--sky);
  letter-spacing: -0.02em;
}

.face {
  font-size: 1.6rem;
  width: 54px;
  height: 54px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(20, 32, 28, 0.08);
}

.face:active { background: #fff; }

.diff-row {
  display: flex;
  justify-content: center;
}

.diff-list {
  display: inline-flex;
  gap: 0.45rem;
  padding: 3px;
  border-radius: 10px;
  background: rgba(61, 142, 165, 0.12);
}

.diff-btn {
  font: inherit;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.diff-btn.active {
  background: #fff;
  color: var(--sky);
  box-shadow: 0 2px 8px rgba(20, 32, 28, 0.1);
}

.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.3rem 0.2rem;
}

.stat span { color: var(--sky); font-weight: 800; }

.flag-btn {
  font: inherit;
  font-weight: 700;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.flag-btn.on {
  background: var(--coral);
  color: #fff;
  border-color: var(--coral);
}

.board-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.board {
  display: grid;
  gap: 3px;
  background: rgba(31, 111, 91, 0.1);
  padding: 6px;
  border-radius: 12px;
  margin: 0 auto;
  /* 格子尺寸通过 JS 动态写入 grid-template-cols/rows，确保小屏适合，大屏不糊 */
}

.cell {
  --size: 30px;
  width: var(--size);
  height: var(--size);
  border-radius: 6px;
  background: var(--cell-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(20, 32, 28, 0.1);
  transition: transform 0.05s ease;
}

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

.cell.open {
  background: var(--cell-bg-open);
  box-shadow: none;
  cursor: default;
  border: 1px solid var(--line);
}

.cell.flagged {
  background: #fff3e3;
}

.cell.mine {
  background: var(--coral);
  color: #fff;
}

.cell.exploded {
  background: #d13b1e;
}

.cell[data-n="1"] { color: #1976d2; }
.cell[data-n="2"] { color: #388e3c; }
.cell[data-n="3"] { color: #d32f2f; }
.cell[data-n="4"] { color: #7b1fa2; }
.cell[data-n="5"] { color: #795548; }
.cell[data-n="6"] { color: #0097a7; }
.cell[data-n="7"] { color: #455a64; }
.cell[data-n="8"] { color: #000; }

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

/* 手机竖屏自动缩小格子 */
@media (max-width: 520px) {
  .cell {
    --size: max(22px, min(30px, calc((100vw - 48px) / 9)));
    font-size: 0.85rem;
  }
}

/* 高级模式：30×16，格子略小 */
.board.expert .cell {
  --size: 24px;
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  .board.expert .cell {
    --size: max(18px, min(24px, calc((100vw - 40px) / 30)));
    font-size: 0.75rem;
  }
}
