:root {
  --cell-size: 28px;
  --bg: #f3f6fb;
  --panel-bg: #ffffff;
  --cell-bg: #dce6f0;
  --cell-bg-hover: #c8d8e8;
  --cell-bg-checked: #fbfcfe;
  --cell-border: #9aadc0;
  --cell-border-checked: #bdc9d7;
  --cell-raised-shadow: inset 1px 1px 0 rgba(255,255,255,.96), inset -2px -2px 0 rgba(82,105,130,.22);
  --cell-mine: #d9435f;
  --text-main: #263544;
  --text-accent: #168b78;
  --text-warning: #d97706;
  --btn-bg: linear-gradient(100deg, #78cdb6 0%, #69add7 100%);
  --btn-bg-hover: linear-gradient(100deg, #68bda6 0%, #5799c5 100%);
}
.theme-dark {
  --bg: #181c20;
  --panel-bg: #23272f;
  --cell-bg: #344253;
  --cell-bg-hover: #43566b;
  --cell-bg-checked: #1b222b;
  --cell-border: #71849a;
  --cell-border-checked: #465362;
  --cell-raised-shadow: inset 1px 1px 0 rgba(255,255,255,.16), inset -2px -2px 0 rgba(5,10,16,.52);
  --cell-mine: #d11141;
  --text-main: #f3f3f3;
  --text-accent: #7fd1b9;
  --text-warning: #ffc425;
  --btn-bg: linear-gradient(90deg, #7fd1b9 0%, #5ea7d6 100%);
  --btn-bg-hover: linear-gradient(90deg, #5ea7d6 0%, #7fd1b9 100%);
}
.theme-light {
  --bg: #f6f8fa;
  --panel-bg: #fff;
  --cell-bg: #dce6f0;
  --cell-bg-hover: #c8d8e8;
  --cell-bg-checked: #fbfcfe;
  --cell-border: #9aadc0;
  --cell-border-checked: #bdc9d7;
  --cell-raised-shadow: inset 1px 1px 0 rgba(255,255,255,.96), inset -2px -2px 0 rgba(82,105,130,.22);
  --cell-mine: #e53935;
  --text-main: #23272f;
  --text-accent: #009688;
  --text-warning: #ff9800;
  --btn-bg: linear-gradient(90deg, #7fd1b9 0%, #5ea7d6 100%);
  --btn-bg-hover: linear-gradient(90deg, #5ea7d6 0%, #7fd1b9 100%);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-main);
  font-family: 'Lato', 'Segoe UI', Arial, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  cursor: default;
  caret-color: transparent;
}

.container {
  box-sizing: border-box;
  margin: 28px auto;
  background: var(--panel-bg);
  border: 1px solid rgba(194, 207, 221, 0.8);
  border-radius: 20px;
  box-shadow: 0 18px 50px rgba(37, 55, 76, 0.11);
  padding: 26px 24px 24px;
  width: fit-content;
  min-width: 320px;
  max-width: 98vw;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-heading {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 17px;
}

.game-heading-copy { text-align: left; }
.game-back {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  margin-bottom: 11px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #5e7183;
  font: 600 12px/1.2 system-ui, "Microsoft YaHei", sans-serif;
  text-decoration: none;
  transition: background .18s ease, color .18s ease;
}
.game-back:hover { background: #e7eef5; color: #167d70; }
.game-heading h1 {
  margin: 0;
  color: #263544;
  font: 750 25px/1.2 system-ui, "Microsoft YaHei", sans-serif;
  letter-spacing: .01em;
}
.game-heading p {
  margin: 6px 0 0;
  color: #778797;
  font: 400 13px/1.55 system-ui, "Microsoft YaHei", sans-serif;
}
.theme-toggle {
  flex: 0 0 auto;
  margin-top: 30px;
  border: 1px solid #dce5ed;
  border-radius: 12px;
  background: #f8fafc;
  color: #526578;
  padding: 8px 11px;
  font-size: 17px;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease;
}
.theme-toggle:hover { transform: translateY(-1px); background: #eef4f8; }

.parameters, .summary {
  margin: 0 0 18px 0;
}

.summary {
  margin-bottom: 24px;
}

.title {
  font-weight: bold;
  text-decoration: none;
  font-size: 1.1em;
  color: var(--text-accent);
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.table-summary {
  border: 0;
  width: 100%;
}

.table-summary td {
  border: 0;
  padding: 8px 12px;
}

.levels {
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.levels a {
  color: var(--text-accent);
  text-decoration: none;
  padding: 2px 8px;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}
.levels a:hover {
  background: var(--text-accent);
  color: var(--panel-bg);
}

input[type="number"] {
  max-width: 60px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--cell-border);
  background: var(--panel-bg);
  color: var(--text-main);
  font-size: 1em;
  outline: none;
  transition: border 0.2s;
  cursor: text;
  caret-color: var(--text-main);
}
input[type="number"]:focus {
  border: 1.5px solid var(--text-accent);
}

#btnNewGame {
  font-size: 26px;
  width: 100%;
  height: 48px;
  background: var(--btn-bg);
  color: var(--panel-bg);
  border: none;
  border-radius: 12px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(127,209,185,0.10);
  transition: background 0.2s, color 0.2s;
}
#btnNewGame:hover {
  background: var(--btn-bg-hover);
  color: #fff;
}

.board {
  margin-top: 18px;
  display: flex;
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  cursor: default;
}

.board table {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  gap: 2px;
  width: max-content;
  margin-inline: auto;
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
  padding: 8px 8px 18px;
}

.board tr {
  display: grid;
  grid-template-columns: repeat(var(--board-cols, 8), var(--cell-size));
  grid-auto-rows: var(--cell-size);
  gap: 2px;
}

.board tr td, .cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cell-size);
  height: var(--cell-size);
  min-width: var(--cell-size);
  min-height: var(--cell-size);
  max-width: var(--cell-size);
  max-height: var(--cell-size);
  box-sizing: border-box;
  padding: 0;
  cursor: pointer;
  background-color: var(--cell-bg);
  box-shadow: var(--cell-raised-shadow);
  border-radius: 6px;
  border: 1.5px solid var(--cell-border);
  font-weight: bold;
  font-size: 1.1em;
  color: var(--text-accent);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  user-select: none;
  overflow: hidden;
  line-height: 1;
  text-align: center;
  vertical-align: middle;
}

.board tr td:hover, .cell:hover {
  background: var(--cell-bg-hover);
  border-color: var(--text-accent);
}

.board tr td.checked, .board tr td.revealed, .cell.checked, .cell.revealed {
  cursor: default;
  background: var(--cell-bg-checked);
  color: var(--text-main);
  border-color: var(--cell-border-checked);
  box-shadow: none;
}

.board tr td.mined, .cell.mined {
  background: var(--cell-mine);
  color: #fff;
  border-color: var(--cell-mine);
}

.board tr td.flagged, .cell.flagged {
  background: var(--cell-bg);
  color: var(--text-warning);
  border-color: var(--text-warning);
  font-size: 1.2em;
}

.board tr td.exploded, .cell.exploded {
  background: var(--cell-mine);
  color: #fff;
  border-color: var(--cell-mine);
  animation: explosion 0.3s ease-out;
}

.board tr td.disabled, .cell.disabled {
  pointer-events: none;
  opacity: 0.7;
}

.board tr td.wrong-flag, .cell.wrong-flag {
  background: var(--cell-mine);
  color: #fff;
  border-color: var(--cell-mine);
  font-size: 1.1em;
  animation: wrongFlag 0.5s ease-out;
}

@keyframes wrongFlag {
  0% { transform: scale(1); background: var(--text-warning); }
  50% { transform: scale(1.1); background: var(--cell-mine); }
  100% { transform: scale(1); background: var(--cell-mine); }
}

@keyframes explosion {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* Number colors stay readable on the flatter revealed-cell surface. */
.board tr td.number-1, .cell.number-1 { color: #1d4ed8 !important; }
.board tr td.number-2, .cell.number-2 { color: #dc2626 !important; }
.board tr td.number-3, .cell.number-3 { color: #0e7490 !important; }
.board tr td.number-4, .cell.number-4 { color: #c2410c !important; }
.board tr td.number-5, .cell.number-5 { color: #a16207 !important; }
.board tr td.number-6, .cell.number-6 { color: #15803d !important; }
.board tr td.number-7, .cell.number-7 { color: #334155 !important; }
.board tr td.number-8, .cell.number-8 { color: #be185d !important; }

.theme-dark .board tr td.number-1, .theme-dark .cell.number-1 { color: #60a5fa !important; }
.theme-dark .board tr td.number-2, .theme-dark .cell.number-2 { color: #fb7185 !important; }
.theme-dark .board tr td.number-3, .theme-dark .cell.number-3 { color: #22d3ee !important; }
.theme-dark .board tr td.number-4, .theme-dark .cell.number-4 { color: #fb923c !important; }
.theme-dark .board tr td.number-5, .theme-dark .cell.number-5 { color: #fbbf24 !important; }
.theme-dark .board tr td.number-6, .theme-dark .cell.number-6 { color: #4ade80 !important; }
.theme-dark .board tr td.number-7, .theme-dark .cell.number-7 { color: #cbd5e1 !important; }
.theme-dark .board tr td.number-8, .theme-dark .cell.number-8 { color: #f472b6 !important; }

/* Classic Minesweeper-inspired win banner and celebratory board ripple. */
.win-message { position: relative; width: 100%; margin: 0 0 12px; pointer-events: none; }
.win-message[hidden] { display: none; }
.win-banner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  box-sizing: border-box;
  overflow: hidden;
  padding: 10px 18px;
  border: 1px solid #e8c55d;
  border-radius: 14px;
  background: linear-gradient(110deg, #fff9dc, #fff1b8 52%, #fff9dc);
  color: #5d4811;
  box-shadow: 0 5px 18px rgba(185, 139, 25, .14);
  animation: winBannerIn .45s cubic-bezier(.2,.8,.2,1) both;
}
.win-face { flex: 0 0 auto; font-size: 32px; line-height: 1; animation: winFacePop .65s .12s cubic-bezier(.2,1.5,.4,1) both; }
.win-copy { display: flex; flex-direction: column; gap: 2px; }
.win-copy strong { font-size: 17px; }
.win-copy span { color: #816b2d; font-size: 12px; }
.win-stars { margin-left: auto; color: #e1a900; font-size: 20px; letter-spacing: 5px; animation: winSparkle .8s .25s ease-in-out both; }
.win-confetti-piece {
  position: absolute;
  z-index: 2;
  top: -10px;
  left: var(--x);
  width: 7px;
  height: 11px;
  border-radius: 2px;
  background: var(--confetti-color);
  opacity: 0;
  pointer-events: none;
  transform: translateX(0) rotate(0);
}
.win-confetti-piece.is-celebrating { animation: winConfettiFall var(--duration) var(--delay) ease-in both; }
.board.win-celebrating .board-table td.checked,
.board.win-celebrating .board-table td.revealed {
  animation: winCellGlow .72s var(--win-delay, 0ms) ease-out both;
}
#btnNewGame.game-won { animation: winButtonPop .55s cubic-bezier(.2,1.4,.4,1); }
.theme-dark .win-banner {
  border-color: #826d34;
  background: linear-gradient(110deg, #393321, #4a3d1d 52%, #393321);
  color: #fff0b0;
  box-shadow: 0 5px 20px rgba(0,0,0,.22);
}
.theme-dark .win-copy span { color: #d8c68b; }

@keyframes winBannerIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes winFacePop { 0% { transform: scale(.5) rotate(-18deg); } 70% { transform: scale(1.18) rotate(8deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes winSparkle { 0%,100% { opacity: .5; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.12); } }
@keyframes winConfettiFall { 0% { opacity: 0; transform: translate3d(0,-4px,0) rotate(0); } 10% { opacity: 1; } 100% { opacity: 0; transform: translate3d(var(--drift),var(--fall),0) rotate(650deg); } }
@keyframes winCellGlow { 0% { background-color: var(--cell-bg-checked); box-shadow: inset 0 0 0 2px rgba(244, 190, 52, .95); } 100% { background-color: var(--cell-bg-checked); box-shadow: none; } }
@keyframes winButtonPop { 0% { transform: scale(1); } 45% { transform: scale(1.12) rotate(-4deg); } 75% { transform: scale(.96) rotate(3deg); } 100% { transform: scale(1) rotate(0); } }

@media (prefers-reduced-motion: reduce) {
  .win-banner, .win-face, .win-stars, .win-confetti-piece.is-celebrating,
  .board.win-celebrating .board-table td.checked,
  .board.win-celebrating .board-table td.revealed,
  #btnNewGame.game-won { animation: none !important; }
}

.flaggedCounter, .timer {
  font-size: 1.2em;
  font-weight: bold;
  color: var(--text-warning);
  margin-top: 2px;
}

@media (max-width: 600px) {
  :root { --cell-size: 20px; }
  .container {
    max-width: 98vw;
    padding: 10px 2vw 18px 2vw;
  }
}
.container { font-family: system-ui, "Microsoft YaHei", sans-serif; }

@media (max-width: 600px) {
  .container { margin: 14px auto; padding: 17px 12px 16px; min-width: 0; width: calc(100vw - 24px); }
  .game-heading { gap: 8px; }
  .game-heading h1 { font-size: 22px; }
  .game-heading p { max-width: 250px; font-size: 12px; }
  .theme-toggle { margin-top: 28px; padding: 7px 8px; font-size: 15px; }
  .board { margin-inline: auto; }
}
