/* Minesweeper -- used by the /arcade/ page only. */

.mines-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 6vw, 2.6rem);
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.mines-bar li { text-align: center; min-width: 4.2rem; }

.mines-bar b {
  display: block;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.mines-bar span {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.mines-face {
  width: 3.4rem;
  height: 3.4rem;
  border: 1px solid var(--card-line);
  border-radius: 50%;
  background: var(--card);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), transform 0.15s var(--ease);
}

.mines-face:hover { border-color: var(--accent); }
.mines-face:active { transform: scale(0.92); }

/* size picker + flag mode */
.mines-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 0 auto 1rem;
}

.mines-controls button {
  padding: 0.4rem 1rem;
  border: 1px solid var(--card-line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease), background 0.2s var(--ease);
}

.mines-controls button:hover { border-color: var(--accent); color: var(--accent); }

.mines-controls button[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(255,159,46,0.14);
  color: var(--accent);
}

/* the board sits in a wrapper so the cells can size their text off its width */
.mines-wrap {
  width: min(100%, 440px);
  margin: 0 auto;
  container-type: inline-size;
}

.mines-board {
  --cols: 9;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 2px;
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--card-line);
  background: #07090f;
  box-shadow: 0 30px 70px -34px rgba(0,0,0,1), 0 0 40px -18px rgba(255,159,46,0.45);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.mines-cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 1px solid #54402f;
  border-radius: 5px;
  /* untouched ground: packed dirt */
  background: linear-gradient(180deg, #4a3a2c, #33281f);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: calc(100cqw / var(--cols) * 0.56);
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}

.mines-cell:hover { background: linear-gradient(180deg, #5a4837, #3d3025); }
.mines-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 2; }

/* dug up */
.mines-cell.open {
  border-color: #131a2c;
  background: #0b0f1c;
  box-shadow: none;
  cursor: default;
}

.mines-cell.flag { font-size: calc(100cqw / var(--cols) * 0.5); }

.mines-cell.n1 { color: #5ab0ff; }
.mines-cell.n2 { color: #53d37c; }
.mines-cell.n3 { color: #ff6b6b; }
.mines-cell.n4 { color: #a98bff; }
.mines-cell.n5 { color: #ff9f2e; }
.mines-cell.n6 { color: #2fd6d0; }
.mines-cell.n7 { color: #ff2ea6; }
.mines-cell.n8 { color: #cfd6e6; }

/* a flag with no seal under it */
.mines-cell.wrong { background: #3a1a1f; border-color: #ff4d4d; }
.mines-cell.wrong::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ff4d4d;
  font-size: 1.1em;
  text-shadow: 0 0 6px #000;
}

/* ---------- the seals ---------- */

.mines-cell .seal {
  position: relative;
  z-index: 3;
  display: block;
  font-size: 1.15em;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.7));
}

.mines-cell.boom { z-index: 1; }
.mines-cell.boom.hit {
  background: #5a1d22;
  border-color: #ff4d4d;
  z-index: 4;
}

/* the seal bursts up out of the ground, flies, then lands */
.mines-cell.boom .seal {
  animation: mines-burst 1s var(--d, 0ms) cubic-bezier(.2,.8,.3,1) both;
}

/* and a puff of dirt where it came from */
.mines-cell.boom::before {
  content: '';
  position: absolute;
  inset: -40%;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(circle at 22% 30%, #8c5f33 0 7%, transparent 8%),
    radial-gradient(circle at 78% 24%, #6e4825 0 6%, transparent 7%),
    radial-gradient(circle at 50% 12%, #a8743d 0 8%, transparent 9%),
    radial-gradient(circle at 14% 66%, #6e4825 0 6%, transparent 7%),
    radial-gradient(circle at 86% 70%, #8c5f33 0 7%, transparent 8%),
    radial-gradient(circle at 36% 86%, #a8743d 0 6%, transparent 7%),
    radial-gradient(circle at 66% 88%, #6e4825 0 7%, transparent 8%);
  animation: mines-dirt 0.9s var(--d, 0ms) ease-out both;
}

@keyframes mines-burst {
  0%   { transform: translateY(80%) scale(0.2) rotate(0deg); opacity: 0; }
  12%  { opacity: 1; }
  40%  { transform: translateY(-140%) scale(2.1) rotate(-22deg); }
  68%  { transform: translateY(-20%) scale(1.45) rotate(14deg); }
  84%  { transform: translateY(8%) scale(1.1) rotate(-6deg); }
  100% { transform: translateY(0) scale(1.15) rotate(0deg); opacity: 1; }
}

@keyframes mines-dirt {
  0%   { transform: scale(0.15); opacity: 0.95; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* the whole board jolts when the first seal goes off */
@keyframes mines-jolt {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-7px, 4px); }
  22% { transform: translate(6px, -5px); }
  34% { transform: translate(-5px, -3px); }
  46% { transform: translate(5px, 4px); }
  60% { transform: translate(-3px, 2px); }
  75% { transform: translate(2px, -2px); }
}

.mines-board.mines-shake { animation: mines-jolt 0.5s linear; }

/* win: the sleeping seals peek out, pleased */
.mines-cell.friend { background: #0b1a14; border-color: #1c3a2c; }
.mines-cell.friend .seal {
  animation: mines-peek 0.6s var(--d, 0ms) ease-out both;
}

@keyframes mines-peek {
  0%   { transform: translateY(70%) scale(0.4); opacity: 0; }
  100% { transform: translateY(0) scale(1.05); opacity: 1; }
}

/* calm mode and reduced motion: seals just appear */
html.calm .mines-cell .seal,
html.calm .mines-cell.boom::before,
html.calm .mines-board.mines-shake { animation: none; }
html.calm .mines-cell.boom::before { display: none; }

@media (prefers-reduced-motion: reduce) {
  .mines-cell .seal,
  .mines-board.mines-shake { animation: none !important; }
  .mines-cell.boom::before { display: none; }
}

.mines-status {
  min-height: 1.5em;
  margin: 1rem auto 0;
  max-width: 40ch;
  height: auto;
  text-align: center;
  font-size: 0.92rem;
  color: var(--muted);
}

.mines-hint {
  margin: 0.5rem 0 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ---------- fullscreen ----------
   The stage fills the screen and the (square) field is as big as fits between the rows
   around it. .pseudo-full is the same thing pinned by hand for browsers without the API. */
.mines-stage:fullscreen,
.mines-stage:-webkit-full-screen,
.mines-stage.pseudo-full {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  width: 100%;
  height: 100%;
  padding: 0.8rem;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-2) 0%, var(--bg) 70%);
  overflow: hidden;       /* not auto: flying seals would otherwise spawn scrollbars */
}

.mines-stage.pseudo-full {
  position: fixed;
  inset: 0;
  z-index: 200;
  height: 100dvh;
}

/* in the flex column, rows must never squash below their text (that made the status line
   spill over the hint underneath it) */
.mines-stage.is-full > * { flex-shrink: 0; }
.mines-stage.is-full .mines-status,
.mines-stage.is-full .mines-hint { line-height: 1.4; }

.mines-stage.is-full .mines-controls { margin-bottom: 0.5rem; }
.mines-stage.is-full .mines-bar { margin-bottom: 0.5rem; }
.mines-stage.is-full .mines-status { margin-top: 0.5rem; }

/* room left for the controls, counters, status line and hint around the field */
.mines-stage.is-full .mines-wrap {
  width: min(96vw, calc(100vh - 17rem));
  width: min(96vw, calc(100dvh - 17rem));
}

.mines-noscroll, .mines-noscroll body { overflow: hidden; }
