/* Minesweeper. Functional layout before the design pass; existing tokens only (spec §7.8, D3).
   Mobile: bar (level, mines left, time, pause), the board in its own scroller, then Flag mode
   and New game, then the result after a game.
   The board keeps the saffron swatch in both themes: covered cells in the field tone, open cells
   in the light tone. Number colors are other swatches' field tones mixed toward their deep tone
   (board-view.js); all derived colors are listed for design review in docs/follow-ups.md.
   Deliberately not the classic look (D3): no bevels, no grey chrome, no LED digits, no face. */

.g-mines { padding-block: var(--s3) var(--s7); }
.g-mines__intro { margin-bottom: var(--s3); }
.g-mines__intro h1 { font-size: 24px; }
.g-mines__intro p { margin-top: var(--s1); max-width: 60ch; }
.g-mines__note { margin-bottom: var(--s3); }

/* ---------- game card ---------- */
.g-mines__game {
  position: relative; max-width: 1280px; padding: var(--s2) var(--s1);
  display: grid; gap: var(--s3); grid-template-areas: "bar" "board" "actions" "result" "tools";
}
@media (min-width: 400px) { .g-mines__game { padding: var(--s3); } }
@media (min-width: 720px) { .g-mines__game { padding: var(--s5); } }
.g-mines__game:focus { outline: none; }
.g-mines__bar { grid-area: bar; display: flex; flex-wrap: wrap; align-items: end; gap: var(--s2) var(--s4); padding-inline: var(--s1); }
.g-mines__bar .stat__value { font-size: 18px; }
.g-mines__level { display: grid; gap: 2px; flex: 1 1 100%; }
@media (min-width: 560px) { .g-mines__level { flex: 0 1 auto; } }
.g-mines__select {
  min-height: 44px; padding: 0 var(--s3); border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; max-width: 100%;
}
.g-mines__size-btn { padding-inline: 12px; }
.g-mines__ng { display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; font-size: 15px; font-weight: 500; cursor: pointer; }
.g-mines__ng input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }
.g-mines__ng:has(input:disabled) { color: var(--ink-2); cursor: default; }
.g-mines__bar-note { flex-basis: 100%; font-size: 14px; }
.g-mines__replay { align-self: center; }
.g-mines__pause-btn { margin-left: auto; min-width: 88px; padding-inline: 12px; } /* Pause and Resume keep one width */

/* ---------- board ---------- */
/* Cells fit the width between 28 and 40 px; past that, the board scrolls in here, never the page */
.g-mines__scroller { grid-area: board; container-type: inline-size; overflow: auto; overscroll-behavior-x: contain; position: relative; }
/* No-guess search taking a moment (Phase 3): the board dims under a message */
.g-mines__finding {
  display: none; position: absolute; inset: 0; place-content: center; text-align: center;
  font-weight: 700; font-size: 18px; color: var(--ink); background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.g-mines__game.is-finding .g-mines__finding { display: grid; }
.g-mines__board {
  /* board width = cols × (cell + 1 px gap) − 1 px + 2 × 2 px border */
  --cell: clamp(28px, calc((100cqi - 3px) / var(--cols, 9) - 1px), 40px);
  width: max-content; margin-inline: auto; display: flex; flex-direction: column;
  border: 2px solid var(--deep); background: var(--deep); gap: 1px;
  /* D7: taps without the double-tap delay; pinch-zoom still works. No callout or text selection
     on long-press. */
  touch-action: manipulation; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.g-mines__row { display: flex; gap: 1px; }
.g-mines__cell {
  width: var(--cell); height: var(--cell); display: grid; place-items: center; position: relative;
  background: var(--field); color: var(--deep); cursor: pointer;
  font-weight: 800; font-size: calc(var(--cell) * 0.58); line-height: 1; font-variant-numeric: tabular-nums;
}
.g-mines__cell:focus { outline: none; }
.g-mines__cell:focus-visible { outline: 3px solid var(--deep); outline-offset: -5px; z-index: 1; }
.g-mines__cell.is-number, .g-mines__cell.is-mine, .g-mines__cell.is-wrong-flag { background: var(--light); cursor: default; }
.g-mines__cell.is-exploded { background: var(--state-wrong); color: #FFFFFF; }
.g-mines__cell.is-miss { background: color-mix(in srgb, var(--field) 55%, var(--light)); }
.g-mines__board.is-locked .g-mines__cell { cursor: default; }
.g-mines__board.is-comfortable { --cell: 44px; } /* setting: touch-sized squares, the board scrolls */

.g-mines__icon { width: 64%; height: auto; aspect-ratio: 1; fill: currentColor; pointer-events: none; }
.g-mines__cell .g-mines__icon + .g-mines__icon { position: absolute; width: 72%; color: var(--state-wrong); } /* wrong flag: crossed */
.g-mines__q { font-weight: 800; }

/* Numbers: 1–8 each from its own swatch (board-view.js), darkened so it reads on the light tone */
.g-mines__n { color: color-mix(in srgb, var(--field) 60%, var(--deep)); }
.g-mines__n.is-d40 { color: color-mix(in srgb, var(--field) 40%, var(--deep)); }
.g-mines__n.is-d30 { color: color-mix(in srgb, var(--field) 30%, var(--deep)); }
.g-mines__n.is-deep { color: var(--deep); }

/* ---------- actions ---------- */
.g-mines__actions { grid-area: actions; display: flex; gap: var(--s2); justify-content: center; padding-inline: var(--s1); }
.g-mines__actions .btn { touch-action: manipulation; }
.g-mines__flag-btn { gap: 6px; }
.g-mines__flag-btn .g-mines__icon { width: 20px; }
.g-mines__flag-btn[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

.g-mines__tools { grid-area: tools; display: flex; justify-content: center; gap: var(--s2); }

/* ---------- result ---------- */
.g-mines__result { grid-area: result; display: grid; gap: var(--s3); padding: var(--s4); border-radius: 12px; background: var(--surface-2); }
.g-mines__result[hidden] { display: none; }
.g-mines__result .fig dd { font-size: 24px; }

/* ---------- pause: hides the board (D8) ---------- */
.g-mines__game.is-paused .g-mines__scroller,
.g-mines__game.is-paused .g-mines__actions { visibility: hidden; }
.g-mines__pause { grid-area: board; position: relative; inset: auto; border-radius: 0; align-content: center; padding: var(--s5); min-height: 240px; }

/* ---------- dialogs ---------- */
.g-mines__dlg .fig dd { font-size: 22px; }
.g-mines__stats-levels { margin-bottom: var(--s4); flex-wrap: wrap; }
.g-mines__stats-levels span { min-width: 0; padding-inline: 10px; }
.g-mines__reset { margin-top: var(--s5); }
.g-mines__reset p { font-weight: 600; }
.g-mines__settings { display: grid; }
.g-mines__settings label { display: flex; align-items: center; gap: var(--s3); min-height: 44px; cursor: pointer; }
.g-mines__settings input { flex: none; width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
.g-mines__choice { border: 0; padding: 0; margin: var(--s3) 0 0; }
.g-mines__choice legend { font-weight: 600; padding: 0; }
.g-mines__custom { display: grid; gap: var(--s1); }
.g-mines__custom label { font-weight: 600; margin-top: var(--s3); }
.g-mines__custom input {
  min-height: 44px; padding: 0 var(--s3); border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; /* 16 px: no iOS zoom on focus */
}
.g-mines__custom input[aria-invalid="true"] { border: 2px solid var(--state-wrong); }
.g-mines__err { color: var(--state-wrong); font-size: 14px; font-weight: 600; }
.g-mines__custom .dlg__actions { margin-top: var(--s4); }

/* ---------- text below the game ---------- */
.g-mines__about { max-width: 62ch; margin-top: var(--s6); }
.g-mines__about h2 { margin: var(--s6) 0 var(--s3); }
.g-mines__about h2:first-child { margin-top: 0; }
.g-mines__about ol { padding-left: 1.25em; margin: var(--s3) 0 0; }
.g-mines__about li + li { margin-top: 6px; }
.g-mines__keys { border-collapse: collapse; font-size: 15px; }
.g-mines__keys th, .g-mines__keys td { text-align: left; padding: 6px var(--s4) 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.g-mines__keys th { font-weight: 600; white-space: nowrap; }
