:root {
  color-scheme: light;
  --bg: #edf8f3;
  --bg-accent: radial-gradient(circle at top left, rgba(0, 133, 86, 0.2), transparent 30%),
    radial-gradient(circle at top right, rgba(74, 214, 161, 0.18), transparent 28%),
    linear-gradient(160deg, #edf8f3 0%, #d7f0e6 52%, #fbfffd 100%);
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: rgba(245, 255, 250, 0.96);
  --text: #113127;
  --muted: #4f6f64;
  --accent: #008556;
  --accent-2: #19a974;
  --accent-3: #62d2a2;
  --danger: #e63946;
  --success: #008556;
  --border: rgba(17, 77, 56, 0.12);
  --shadow: 0 18px 42px rgba(15, 78, 55, 0.15);
  --cell-size: 42px;
  --board-gap: 4px;
}

body.dark {
  color-scheme: dark;
  --bg: #071811;
  --bg-accent: radial-gradient(circle at top left, rgba(0, 133, 86, 0.25), transparent 30%),
    radial-gradient(circle at top right, rgba(98, 210, 162, 0.16), transparent 24%),
    linear-gradient(160deg, #071811 0%, #0d241b 48%, #06120d 100%);
  --surface: rgba(15, 42, 31, 0.84);
  --surface-strong: rgba(18, 54, 39, 0.96);
  --text: #ecfff6;
  --muted: #b4d7c8;
  --accent: #19a974;
  --accent-2: #62d2a2;
  --accent-3: #8be5bf;
  --danger: #ff5a5f;
  --success: #62d2a2;
  --border: rgba(190, 255, 222, 0.12);
  --shadow: 0 20px 44px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Trebuchet MS", Verdana, sans-serif;
  background: var(--bg-accent);
  color: var(--text);
}

button {
  font: inherit;
}

code {
  font-family: Consolas, Monaco, monospace;
  background: rgba(255, 255, 255, 0.42);
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
}

.page-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.hero-card,
.info-card,
.game-card,
.modal-card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.hero-card {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-radius: 28px;
  padding: 26px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", sans-serif;
  margin: 0;
  line-height: 1;
}

h1 {
  font-size: clamp(2.4rem, 5vw, 4.6rem);
}

.hero-text,
.explainer p,
.helper-row p {
  color: var(--muted);
  line-height: 1.6;
}

.theme-toggle,
.mode-button,
.control-button {
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.theme-toggle:hover,
.mode-button:hover,
.control-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.info-card,
.game-card {
  border-radius: 28px;
  padding: 22px;
}

.explainer h2 {
  font-size: 2rem;
  margin-bottom: 16px;
}

.explainer-grid {
  display: grid;
  gap: 14px;
}

.explainer article {
  padding: 16px;
  border-radius: 18px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.explainer h3 {
  font-size: 1.3rem;
  margin-bottom: 8px;
}

.toolbar,
.status-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
}

.mode-picker,
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mode-button,
.control-button {
  padding: 12px 16px;
  font-weight: 700;
}

.mode-button.active,
.control-button.primary {
  background: linear-gradient(135deg, var(--accent), #19a974);
  color: #fffaf7;
  border-color: transparent;
}

.control-button.danger {
  background: linear-gradient(135deg, var(--danger), #ff7b6b);
  color: #fffaf7;
  border-color: transparent;
}

.status-panel {
  margin: 18px 0;
}

.stat-pill {
  min-width: 120px;
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.stat-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.board-shell {
  position: relative;
  overflow: auto;
  border-radius: 26px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.05));
  border: 1px solid var(--border);
}

.board {
  display: grid;
  gap: var(--board-gap);
  width: max-content;
  min-width: 100%;
  justify-content: center;
  touch-action: manipulation;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(25, 169, 116, 0.95), rgba(0, 133, 86, 0.95));
  color: #f3fff9;
  font-size: 1rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.12s ease, filter 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.cell:hover {
  filter: saturate(1.06);
}

.cell:active,
.cell.is-pressed {
  transform: scale(0.96);
}

.cell.revealed {
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.03);
}

body.dark .cell.revealed {
  background: rgba(255, 244, 234, 0.12);
}

.cell.mine {
  position: relative;
  background: linear-gradient(135deg, var(--danger), #ff9b71);
  color: #fff;
}

.cell.mine.exploded {
  animation: blast 0.6s ease-out forwards;
}

.cell.mine.exploded::after {
  content: "";
  position: absolute;
  inset: -10%;
  border-radius: 16px;
  background:
    radial-gradient(circle, rgba(255, 244, 164, 0.95) 0 20%, rgba(255, 162, 0, 0.78) 21% 46%, rgba(230, 57, 70, 0.48) 47% 70%, transparent 71%);
  animation: shockwave 0.6s ease-out forwards;
  pointer-events: none;
}

.cell.flagged {
  background: linear-gradient(135deg, var(--accent-3), #b2f0d2);
}

.cell.n1 { color: #1d4ed8; }
.cell.n2 { color: #15803d; }
.cell.n3 { color: #dc2626; }
.cell.n4 { color: #6d28d9; }
.cell.n5 { color: #b45309; }
.cell.n6 { color: #0f766e; }
.cell.n7 { color: #4338ca; }
.cell.n8 { color: #7c2d12; }

.board-overlay,
.modal {
  position: fixed;
  inset: 0;
}

.board-overlay {
  position: absolute;
  display: grid;
  place-items: center;
  background: rgba(20, 14, 11, 0.42);
  z-index: 2;
  border-radius: 26px;
}

.overlay-card,
.modal-card {
  text-align: center;
}

.overlay-card {
  padding: 18px 26px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  color: #311911;
  font-weight: 700;
}

.helper-row {
  margin-top: 14px;
}

.hidden {
  display: none !important;
}

.modal {
  display: grid;
  place-items: center;
  background: rgba(14, 12, 10, 0.5);
  z-index: 10;
  padding: 18px;
}

.modal-card {
  width: min(420px, 100%);
  border-radius: 28px;
  padding: 28px;
}

.modal-badge {
  display: inline-block;
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 133, 86, 0.14);
  color: var(--accent);
  font-weight: 700;
}

@keyframes blast {
  0% {
    transform: scale(0.85);
    filter: brightness(1.05);
  }
  45% {
    transform: scale(1.16);
    filter: brightness(1.35);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes shockwave {
  0% {
    transform: scale(0.2);
    opacity: 1;
  }
  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

#modalTitle {
  font-size: 2rem;
  margin-bottom: 10px;
}

#modalMessage {
  color: var(--muted);
  line-height: 1.6;
}

.modal-button {
  margin-top: 10px;
  width: 100%;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  :root {
    --cell-size: 34px;
    --board-gap: 3px;
  }

  .page-shell {
    width: min(100% - 18px, 100%);
    padding-top: 16px;
  }

  .hero-card,
  .info-card,
  .game-card {
    border-radius: 22px;
    padding: 18px;
  }

  .hero-card {
    flex-direction: column;
  }

  .toolbar,
  .status-panel {
    align-items: stretch;
  }

  .mode-picker,
  .controls {
    width: 100%;
  }

  .mode-button,
  .control-button,
  .theme-toggle {
    flex: 1 1 120px;
    justify-content: center;
  }
}
