:root {
  color-scheme: dark;
  --bg: #070b12;
  --surface: #101722;
  --surface-raised: #172130;
  --cell: #1b2737;
  --cell-hover: #24354a;
  --cell-open: #0c121c;
  --text: #edf7f6;
  --muted: #8b9bab;
  --accent: #48e0c2;
  --accent-strong: #79f6dd;
  --danger: #ff6577;
  --line: #243142;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% 18%, rgba(72, 224, 194, 0.09), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
select {
  font: inherit;
}

button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(1040px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0;
}

.header-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text);
  font-weight: 780;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.35rem;
  aspect-ratio: 1;
  border: 1px solid rgba(72, 224, 194, 0.4);
  border-radius: 9px;
  background: rgba(72, 224, 194, 0.1);
  color: var(--accent-strong);
  font-size: 0.78rem;
}

.control-select select {
  min-height: 2.45rem;
  padding: 0.35rem 2.2rem 0.35rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.game-shell {
  display: grid;
  place-items: center;
  padding: 2.5rem 1rem 4rem;
}

.game-card {
  width: min(100%, 1120px);
  padding: clamp(1.25rem, 4vw, 2rem);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.025), transparent 35%), var(--surface);
  box-shadow: var(--shadow);
}

.game-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.045em;
}

.new-game {
  min-height: 2.65rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid rgba(72, 224, 194, 0.45);
  border-radius: 8px;
  background: rgba(72, 224, 194, 0.1);
  color: var(--accent-strong);
  font-weight: 750;
  cursor: pointer;
}

.new-game:hover {
  background: rgba(72, 224, 194, 0.18);
}

.game-stats {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b111a;
}

.stat {
  display: flex;
  flex-direction: column;
}

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

.stat-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.stat strong {
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.unit {
  margin-left: 0.2rem;
  color: var(--muted);
  font-size: 0.7rem;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(72, 224, 194, 0.7);
}

.status.lost .status-dot {
  background: var(--danger);
  box-shadow: 0 0 10px rgba(255, 101, 119, 0.7);
}

.board-viewport {
  width: 100%;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-color: var(--line) transparent;
}

.board {
  --board-cols: 9;
  --board-cell-size: clamp(1.45rem, 4.8vw, 2.15rem);
  --board-gap: clamp(2px, 0.45vw, 5px);
  display: grid;
  grid-template-columns: repeat(var(--board-cols), var(--board-cell-size));
  gap: var(--board-gap);
  width: max-content;
  max-width: none;
  margin-inline: auto;
  padding: clamp(5px, 1.5vw, 10px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #080d14;
}

.cell {
  display: grid;
  place-items: center;
  width: var(--board-cell-size);
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid #304057;
  border-radius: clamp(3px, 1vw, 6px);
  background: linear-gradient(145deg, #223148, var(--cell));
  color: var(--text);
  font-size: clamp(0.72rem, 3vw, 1.1rem);
  font-weight: 850;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.cell:hover:not(.revealed) {
  background: var(--cell-hover);
  border-color: #3c526c;
}

.cell.revealed {
  border-color: #172231;
  background: var(--cell-open);
  cursor: default;
}

.cell.flagged {
  color: #ffd166;
}

.cell.mine {
  background: rgba(255, 101, 119, 0.16);
  color: var(--danger);
}

.cell.exploded {
  border-color: var(--danger);
  background: rgba(255, 101, 119, 0.3);
}

.cell[data-number="1"] { color: #67b7ff; }
.cell[data-number="2"] { color: #63e6a4; }
.cell[data-number="3"] { color: #ff7b8b; }
.cell[data-number="4"] { color: #ae8cff; }
.cell[data-number="5"] { color: #ffad66; }
.cell[data-number="6"] { color: #58dce5; }
.cell[data-number="7"] { color: #d9e2ec; }
.cell[data-number="8"] { color: #8b9bab; }

.instructions {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.footer {
  padding: 1.5rem 1rem 2rem;
  border-top: 1px solid rgba(36, 49, 66, 0.6);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.footer p {
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 520px) {
  .site-header {
    width: calc(100% - 1.5rem);
    align-items: flex-start;
    flex-direction: column;
  }

  .header-controls {
    justify-content: flex-start;
    width: 100%;
  }

  .control-select select {
    max-width: calc(100vw - 1.5rem);
  }

  .brand-mark {
    display: none;
  }

  .game-shell {
    padding: 1.25rem 0.75rem 3rem;
  }

  .game-card {
    padding: 1rem;
    border-radius: 14px;
  }

  .game-heading {
    align-items: center;
  }

  .game-stats {
    padding-inline: 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
