:root {
  color-scheme: dark;
  --bg-a: #080a1f;
  --bg-b: #161233;
  --panel: rgba(18, 23, 54, 0.72);
  --panel-strong: rgba(21, 30, 70, 0.88);
  --border: rgba(148, 163, 255, 0.26);
  --text: #eef4ff;
  --muted: #9da9d6;
  --cyan: #28d8ff;
  --blue: #3b82f6;
  --purple: #9a5cff;
  --pink: #ff4fd8;
  --green: #2ee59d;
  --red: #ff5573;
  --warning: #ffc857;
  --cell-size: 42px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 15% 15%, rgba(40, 216, 255, 0.25), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(154, 92, 255, 0.28), transparent 34%),
    radial-gradient(circle at 50% 92%, rgba(255, 79, 216, 0.16), transparent 32%),
    linear-gradient(135deg, var(--bg-a), var(--bg-b));
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: -24%;
  pointer-events: none;
  background:
    radial-gradient(circle at 30% 35%, rgba(40, 216, 255, 0.16), transparent 22%),
    radial-gradient(circle at 70% 55%, rgba(154, 92, 255, 0.14), transparent 24%);
  filter: blur(12px);
  animation: driftGlow 12s ease-in-out infinite alternate;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1160px, calc(100% - 28px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 24px;
  align-items: center;
  padding: 14px 0;
}

.game-card,
.guide-card {
  border: 1px solid var(--border);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025)),
    linear-gradient(145deg, rgba(17, 22, 52, 0.84), rgba(13, 15, 38, 0.64));
  box-shadow:
    0 22px 60px rgba(0, 0, 0, 0.38),
    0 0 34px rgba(40, 216, 255, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.11);
  backdrop-filter: blur(22px);
}

.game-card {
  min-width: 0;
  padding: clamp(18px, 3vw, 28px);
  border-radius: 26px;
  animation: cardEnter 520ms var(--ease-out);
}

.guide-card {
  position: sticky;
  top: 16px;
  padding: 22px;
  border-radius: 22px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2.15rem, 7vw, 4.7rem);
  line-height: 0.95;
  font-weight: 800;
  text-shadow: 0 0 24px rgba(40, 216, 255, 0.42), 0 0 46px rgba(154, 92, 255, 0.32);
}

h2 {
  font-size: 1.25rem;
}

.icon-button,
.restart-button,
.difficulty-button {
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  transition:
    transform 180ms var(--ease-out),
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease,
    filter 180ms ease;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.icon-button svg,
.restart-icon svg,
.cell svg,
.guide-tile svg,
.modal-icon svg {
  width: 1.15em;
  height: 1.15em;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.difficulty-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 28px 0 18px;
}

.difficulty-button {
  min-height: 46px;
  border-radius: 14px;
  font-weight: 800;
}

.difficulty-button.active,
.difficulty-button:hover,
.icon-button:hover,
.restart-button:hover {
  transform: translateY(-2px);
  border-color: rgba(40, 216, 255, 0.7);
  background: linear-gradient(135deg, rgba(40, 216, 255, 0.22), rgba(154, 92, 255, 0.24));
  box-shadow: 0 0 22px rgba(40, 216, 255, 0.22);
}

.difficulty-button:active,
.icon-button:active,
.restart-button:active {
  transform: translateY(0) scale(0.98);
}

.status-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: center;
}

.stat-panel,
.best-score {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  background: rgba(5, 10, 30, 0.48);
  box-shadow: inset 0 0 20px rgba(40, 216, 255, 0.08);
}

.stat-panel {
  padding: 12px 16px;
  text-align: center;
}

.stat-label,
.best-score span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stat-panel strong,
.best-score strong {
  font-size: 1.38rem;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 16px rgba(40, 216, 255, 0.55);
}

.restart-button {
  min-height: 52px;
  padding: 0 20px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
}

.game-message {
  min-height: 24px;
  margin: 14px 0;
  color: var(--muted);
  text-align: center;
}

.board-wrap {
  display: flex;
  justify-content: center;
  overflow-x: auto;
  padding: 4px 4px 2px;
}

.board {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid rgba(40, 216, 255, 0.22);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(40, 216, 255, 0.08), transparent),
    rgba(2, 6, 23, 0.66);
  box-shadow: 0 0 38px rgba(40, 216, 255, 0.17), inset 0 0 22px rgba(154, 92, 255, 0.06);
  touch-action: manipulation;
}

.board.board-locked {
  pointer-events: none;
}

.cell,
.guide-tile {
  width: var(--cell-size);
  height: var(--cell-size);
  display: grid;
  place-items: center;
  border-radius: 10px;
  user-select: none;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.cell {
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 1.02rem;
  text-shadow: 0 0 14px currentColor;
  transition:
    transform 140ms var(--ease-out),
    background 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease,
    filter 180ms ease;
}

.cell.hidden-cell,
.guide-tile.hidden-cell {
  background: linear-gradient(145deg, rgba(42, 75, 166, 0.9), rgba(109, 70, 207, 0.72));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), 0 0 12px rgba(91, 129, 255, 0.16);
}

.cell.hidden-cell:hover {
  transform: translateY(-2px) scale(1.035);
  border-color: rgba(40, 216, 255, 0.65);
  box-shadow: 0 0 18px rgba(40, 216, 255, 0.3);
}

.revealed-cell {
  background: rgba(232, 240, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.06);
}

.cell.newly-revealed {
  animation: revealPop 220ms var(--ease-out);
}

.flagged-cell {
  color: var(--warning);
  background: linear-gradient(145deg, rgba(255, 200, 87, 0.18), rgba(255, 79, 216, 0.18));
}

.mine-cell {
  color: #fff7d6;
  background: radial-gradient(circle, rgba(255, 200, 87, 0.52), rgba(255, 85, 115, 0.3));
}

.exploded-mine {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.52);
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.34), transparent 34%),
    linear-gradient(145deg, var(--red), var(--pink));
  box-shadow:
    0 0 0 4px rgba(255, 85, 115, 0.16),
    0 0 34px rgba(255, 85, 115, 0.78),
    0 0 58px rgba(255, 79, 216, 0.36);
  animation: explode 640ms var(--ease-out), dangerPulse 900ms ease infinite alternate 640ms;
}

.number-1 { color: #58a6ff; }
.number-2 { color: #2ee59d; }
.number-3 { color: #ff5573; }
.number-4 { color: #a78bfa; }
.number-5 { color: #ffc857; }
.number-6 { color: #22d3ee; }
.number-7 { color: #f472b6; }
.number-8 { color: #d5e2ff; }

.guide-list {
  display: grid;
  gap: 14px;
  margin: 22px 0;
}

.guide-item {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
}

.guide-tile {
  width: 38px;
  height: 38px;
}

.best-score {
  padding: 16px;
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(16px);
}

.modal-backdrop[hidden] {
  display: none;
}

.result-modal {
  width: min(390px, 100%);
  border: 1px solid rgba(148, 163, 255, 0.28);
  border-radius: 24px;
  padding: 28px;
  text-align: center;
  color: var(--text);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03)),
    rgba(15, 21, 52, 0.88);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.46), 0 0 42px rgba(40, 216, 255, 0.18);
  animation: modalIn 280ms var(--ease-out);
}

.modal-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--cyan);
  background: rgba(40, 216, 255, 0.12);
  box-shadow: 0 0 30px rgba(40, 216, 255, 0.28);
}

.modal-icon svg {
  width: 34px;
  height: 34px;
}

.result-modal h2 {
  font-size: 1.7rem;
}

.result-modal p {
  margin: 10px 0 22px;
  color: var(--muted);
}

.modal-stats {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.modal-stat {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.9rem;
}

.modal-stat strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.modal-restart {
  width: 100%;
  justify-content: center;
}

.game-card.restarting .restart-icon {
  animation: spin 420ms var(--ease-out);
}

.game-card.won {
  animation: winGlow 900ms ease;
}

.game-card.game-lost {
  animation: screenShake 520ms var(--ease-out), lossGlow 1500ms ease-out;
}

.game-card.game-lost .board {
  box-shadow:
    0 0 44px rgba(255, 85, 115, 0.22),
    0 0 64px rgba(255, 79, 216, 0.14),
    inset 0 0 24px rgba(255, 85, 115, 0.1);
}

.difficulty-button:disabled,
.restart-button:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

body.light-mode {
  color-scheme: light;
  --bg-a: #eaf5ff;
  --bg-b: #f5ebff;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-strong: rgba(255, 255, 255, 0.9);
  --border: rgba(49, 78, 168, 0.2);
  --text: #111936;
  --muted: #53617f;
}

body.light-mode .game-card,
body.light-mode .guide-card {
  background: rgba(255, 255, 255, 0.72);
}

body.light-mode .board {
  background: rgba(232, 239, 255, 0.74);
}

body.light-mode .result-modal {
  background: rgba(255, 255, 255, 0.9);
}

@keyframes driftGlow {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to { transform: translate3d(2%, 1%, 0) scale(1.05); }
}

@keyframes cardEnter {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes revealPop {
  from { transform: scale(0.72); filter: brightness(1.45); }
  to { transform: scale(1); filter: brightness(1); }
}

@keyframes explode {
  0% { transform: scale(0.52) rotate(-5deg); filter: brightness(1); }
  45% { transform: scale(1.28) rotate(4deg); filter: brightness(2); }
  72% { transform: scale(0.94) rotate(-2deg); filter: brightness(1.25); }
  100% { transform: scale(1) rotate(0deg); filter: brightness(1); }
}

@keyframes dangerPulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes winGlow {
  0%, 100% { box-shadow: 0 22px 60px rgba(0, 0, 0, 0.38), 0 0 34px rgba(40, 216, 255, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.11); }
  45% { box-shadow: 0 22px 60px rgba(0, 0, 0, 0.38), 0 0 58px rgba(46, 229, 157, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.11); }
}

@keyframes screenShake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-8px); }
  30% { transform: translateX(7px); }
  45% { transform: translateX(-5px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

@keyframes lossGlow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 85, 115, 0)); }
  35% { filter: drop-shadow(0 0 26px rgba(255, 85, 115, 0.32)); }
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .guide-card {
    position: static;
  }

  .guide-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  :root {
    --cell-size: clamp(28px, 8.1vw, 34px);
  }

  .app-shell {
    width: min(100% - 16px, 520px);
    padding: 10px 0;
    gap: 14px;
  }

  .game-card {
    padding: 18px 12px;
    border-radius: 22px;
  }

  .game-header {
    align-items: start;
  }

  .header-actions {
    flex-direction: column;
  }

  .difficulty-group,
  .status-bar {
    gap: 8px;
  }

  .difficulty-button {
    min-height: 48px;
  }

  .status-bar {
    grid-template-columns: 1fr 1fr;
  }

  .restart-button {
    grid-column: 1 / -1;
    justify-content: center;
    order: 3;
  }

  .board {
    gap: 4px;
    padding: 7px;
  }

  .guide-list {
    grid-template-columns: 1fr;
  }
}