:root {
  color-scheme: dark;
  --ink: #e8efe9;
  --muted: #8f9b92;
  --signal: #d8ff55;
  --danger: #ff654f;
  --panel: #1a201c;
  --panel-2: #252d27;
  --line: #3a463d;
  --shadow: #080b09;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(216,255,85,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(216,255,85,.025) 1px, transparent 1px),
    #101411;
  background-size: 32px 32px;
}

button, select { font: inherit; }
button { color: inherit; }

.shell {
  width: min(1160px, calc(100% - 24px));
  margin: 0 auto;
  padding: clamp(28px, 6vw, 72px) 0 48px;
}

.masthead {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  border-bottom: 1px solid var(--line);
  padding-bottom: 22px;
}

.eyebrow, .status-light, label span, .readout span {
  color: var(--signal);
  font-size: .72rem;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1 {
  margin: 5px 0 0;
  font: 800 clamp(2.8rem, 9vw, 6.8rem)/.9 system-ui, sans-serif;
  letter-spacing: -.07em;
  text-transform: uppercase;
}

.lede { margin: 16px 0 0; color: var(--muted); max-width: 58ch; }
.status-light { white-space: nowrap; padding-bottom: 5px; }
.status-light span {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 14px var(--signal);
}

.controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 10px;
  margin: 22px 0 10px;
}

.controls label { display: grid; gap: 7px; }
select, .controls button {
  min-height: 45px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0 15px;
}
select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid var(--signal);
  outline-offset: 2px;
}
.primary { background: var(--signal) !important; color: #111 !important; font-weight: 800; }
.mode[aria-pressed="true"] { border-color: var(--signal); color: var(--signal); }

.instrument-panel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: 0;
  box-shadow: 0 8px 30px rgba(0,0,0,.22);
}
.readout { display: flex; align-items: baseline; gap: 12px; }
.readout:last-child { justify-content: flex-end; }
.readout strong {
  min-width: 3.6ch;
  color: var(--signal);
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
}
.face {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  background: #121713;
  color: var(--signal);
  font-size: 1.2rem;
  transform: rotate(45deg);
}
.face > span { transform: rotate(-45deg); }

.board-frame {
  overflow: auto;
  max-width: 100%;
  padding: clamp(10px, 2vw, 18px);
  background: #0c0f0d;
  border: 1px solid var(--line);
  scrollbar-color: var(--signal) var(--panel);
}
.board {
  --cell: clamp(27px, 5vw, 35px);
  display: grid;
  grid-template-columns: repeat(var(--columns), var(--cell));
  width: max-content;
  margin: auto;
  border: 1px solid #455248;
  box-shadow: 8px 8px 0 var(--shadow);
}
.cell {
  display: grid;
  place-items: center;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 1px solid #101411;
  border-top-color: #4d5d51;
  border-left-color: #4d5d51;
  background: var(--panel-2);
  font-weight: 900;
  font-size: calc(var(--cell) * .52);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.cell:hover:not(.revealed) { background: #344038; }
.cell.revealed {
  border-color: #303a33;
  background: #151a17;
  cursor: default;
}
.cell.flagged { color: var(--signal); }
.cell.mine { color: var(--danger); background: #2d1915; }
.cell.exploded { color: #111; background: var(--danger); }
.cell.wrong { color: var(--danger); text-decoration: line-through; }
.cell[data-adjacent="1"] { color: #70b7ff; }
.cell[data-adjacent="2"] { color: #73dc85; }
.cell[data-adjacent="3"] { color: #ff7d69; }
.cell[data-adjacent="4"] { color: #a58aff; }
.cell[data-adjacent="5"] { color: #eab15d; }
.cell[data-adjacent="6"] { color: #62d4d4; }
.cell[data-adjacent="7"] { color: #d0d0d0; }
.cell[data-adjacent="8"] { color: #9a9a9a; }

.message-row {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
#game-status { color: var(--ink); }
.instructions { margin-top: 20px; color: var(--muted); }
.instructions summary { color: var(--signal); cursor: pointer; }
.instructions div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

@media (max-width: 680px) {
  .masthead { align-items: start; }
  .status-light { display: none; }
  .controls { grid-template-columns: 1fr 1fr; }
  .controls label { grid-column: 1 / -1; }
  .instructions div { grid-template-columns: 1fr; gap: 0; }
  .readout { display: grid; gap: 3px; }
  .readout:last-child { justify-items: end; }
  .message-row { font-size: .82rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .cell:not(.revealed) { transition: background-color 100ms ease, transform 100ms ease; }
  .cell:active:not(.revealed) { transform: scale(.91); }
}
