/* Minesweeper tool. Every rule is scoped to .pv-minesweeper (the site root) or its pv-minesweeper__*
   parts and reads only the site's theme tokens (src/site/site.css: --text, --muted, --line, --panel,
   --accent, --danger, --pv-*), so the light/dark switch restyles it without re-mounting.
   One game workbench laid out as the board-first play deck (GAME_UIUX_IMPROVEMENT_SPEC §4, §5): the
   HUD (board name, flags left, counts, time; status with Start/Continue and New game at the row end),
   the board, the result right after it and the side deck (Open/Flag, mode sentence, rules/help) —
   below the board, beside it from 60rem (Expert keeps one column). The board is never shrunk: 44px
   native button cells in rows of repeat(9, 44px) with no gap, 8px halo padding around them (412px
   intrinsic width), inside the only scroll region of the page (overflow: auto, up to
   max(60vh, 100svh − 14rem) tall, visible border and scrollbars); below 30rem that region spans the
   page gutters so more of the board shows, and its overflow stays inside it. Everything else reflows
   at 320 CSS px and 200% text; nothing here hides page overflow. No sticky/fixed parts; [hidden]
   always wins; states never rely on colour alone (numbers, glyphs, text, the closed-cell bevel). */

.pv-minesweeper {
  min-width: 0;
  max-width: 100%;
  color: var(--text);
  overflow-wrap: anywhere;
}

.pv-minesweeper [hidden],
.pv-minesweeper__game [hidden] {
  display: none !important;
}

.pv-minesweeper__game {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
}

.pv-minesweeper__game > * {
  min-width: 0;
}

.pv-minesweeper__selectors {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
}

.pv-minesweeper__segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
}

.pv-minesweeper__level {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-minesweeper__notes {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.pv-minesweeper__note,
.pv-minesweeper__board-help {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-minesweeper__note--notice {
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--pv-info-line);
  background: var(--pv-info-bg);
}

.pv-minesweeper__js {
  margin: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--pv-warning-line);
  border-radius: 0.5rem;
  background: var(--pv-warning-bg);
  font-weight: 600;
}

.pv-minesweeper__workbench {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--panel);
}

.pv-minesweeper__workbench > * {
  min-width: 0;
}

@media (min-width: 48rem) {
  .pv-minesweeper__workbench {
    gap: 1.25rem;
    padding: 1.25rem;
  }
}

.pv-minesweeper__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
}

.pv-minesweeper__button {
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent-dark);
  font: inherit;
  font-weight: 600;
  word-break: keep-all;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
}

/* The selected mode is filled and underlined, so it is not shown by colour alone. */
.pv-minesweeper__button[aria-pressed="true"],
.pv-minesweeper__button--primary {
  background: var(--accent);
  color: var(--pv-on-primary);
}

.pv-minesweeper__button[aria-pressed="true"] {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}

.pv-minesweeper__button:disabled,
.pv-minesweeper__button[aria-disabled="true"] {
  border-color: var(--pv-disabled-line);
  background: var(--pv-disabled-bg);
  color: var(--pv-disabled-text);
  cursor: not-allowed;
}

.pv-minesweeper__button:focus-visible {
  outline: 3px solid var(--pv-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--pv-halo);
}

/* HUD: the board name and meters, then the status row whose one contextual action (Start or
   Continue) sits left and the board-replacing New game sits at the row end, apart from it. */
.pv-minesweeper__hud {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
}

.pv-minesweeper__hud-top,
.pv-minesweeper__meters {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1rem;
  min-width: 0;
}

.pv-minesweeper__hud-top {
  justify-content: space-between;
}

.pv-minesweeper__flags-left {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pv-minesweeper__state {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  min-width: 0;
}

.pv-minesweeper__game-actions {
  margin-inline-start: auto;
}

/* Side deck: Open/Flag, the live mode sentence, then the rules and the board help. */
.pv-minesweeper__side,
.pv-minesweeper__legend {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
  align-content: start;
}

.pv-minesweeper__legend {
  gap: 0.25rem;
}

.pv-minesweeper__controls .pv-minesweeper__button {
  min-width: 6rem;
}

.pv-minesweeper__mode-line {
  min-height: 1.6em;
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-minesweeper__status {
  flex: 1 1 100%;
  min-height: 1.6em;
  margin: 0;
  font-weight: 700;
}

.pv-minesweeper__alert {
  flex: 1 1 100%;
  margin: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--pv-error-bg);
  color: var(--danger);
  font-weight: 600;
}

.pv-minesweeper__counts,
.pv-minesweeper__time {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.pv-minesweeper__counts {
  color: var(--muted);
  font-size: 0.9375rem;
}

.pv-minesweeper__time {
  font-size: 1.125rem;
  font-weight: 700;
}

.pv-minesweeper__board-help {
  color: var(--muted);
}

/* The one intentional 2D scroll region: the board only, hugging it when there is room. */
.pv-minesweeper__scroll {
  position: relative;
  box-sizing: border-box;
  width: max-content;
  max-width: 100%;
  min-width: 0;
  max-height: 60vh;
  overflow: auto;
  border: 1px solid var(--pv-control);
  border-radius: 0.5rem;
  background: var(--pv-sunken);
}

/* Where small viewport units exist, a taller board region so Beginner fits a 667px-high phone. */
@supports (height: 1svh) {
  .pv-minesweeper__scroll {
    max-height: max(60vh, calc(100svh - 14rem));
  }
}

.pv-minesweeper__board {
  box-sizing: border-box;
  display: grid;
  width: calc(9 * 44px + 2 * 8px);
  min-width: calc(9 * 44px + 2 * 8px);
  padding: 8px;
  font-size: 1.125rem;
}

.pv-minesweeper__row {
  display: grid;
  grid-template-columns: repeat(9, 44px);
  gap: 0;
}

/* Larger free boards (replay spec §3): the same 44px cells and 8px halo, wider intrinsic boards that
   scroll inside the one board region (16 columns: 720px, 30 columns: 1336px). */
.pv-minesweeper__board--intermediate {
  width: calc(16 * 44px + 2 * 8px);
  min-width: calc(16 * 44px + 2 * 8px);
}

.pv-minesweeper__board--intermediate .pv-minesweeper__row {
  grid-template-columns: repeat(16, 44px);
}

.pv-minesweeper__board--expert {
  width: calc(30 * 44px + 2 * 8px);
  min-width: calc(30 * 44px + 2 * 8px);
}

.pv-minesweeper__board--expert .pv-minesweeper__row {
  grid-template-columns: repeat(30, 44px);
}

.pv-minesweeper__gridcell {
  display: flex;
  min-width: 0;
}

.pv-minesweeper__cell {
  box-sizing: border-box;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--pv-control);
  border-radius: 0;
  background: var(--pv-soft);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

/* Still-closed cells keep a 3px bottom bevel: a shape cue that separates them from open empty cells. */
.pv-minesweeper__cell--closed,
.pv-minesweeper__cell--flagged {
  box-shadow: inset 0 -3px 0 var(--pv-control);
}

.pv-minesweeper__cell--open {
  border-color: var(--pv-rule);
  background: var(--panel);
}

.pv-minesweeper__cell--mine,
.pv-minesweeper__cell--flagged-mine {
  background: var(--pv-warning-bg);
}

.pv-minesweeper__cell--exploded {
  border: 2px solid var(--danger);
  background: var(--pv-error-bg);
  color: var(--danger);
}

.pv-minesweeper__cell--wrong-flag {
  border: 2px dashed var(--danger);
  color: var(--danger);
}

.pv-minesweeper__cell[aria-disabled="true"] {
  cursor: default;
}

/* The halo (5px) stays inside the 8px board padding, so the scroll clip never cuts it. */
.pv-minesweeper__cell:focus-visible {
  position: relative;
  z-index: 1;
  outline: 3px solid var(--pv-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--pv-halo);
}

.pv-minesweeper__cell--closed:focus-visible,
.pv-minesweeper__cell--flagged:focus-visible {
  box-shadow: inset 0 -3px 0 var(--pv-control), 0 0 0 5px var(--pv-halo);
}

.pv-minesweeper__glyph {
  font-variant-emoji: text;
}

.pv-minesweeper__dialog {
  box-sizing: border-box;
  max-width: min(28rem, calc(100% - 2rem));
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--panel);
  color: var(--text);
}

.pv-minesweeper__dialog::backdrop {
  background: var(--pv-backdrop, rgb(0 0 0 / 0.45));
}

.pv-minesweeper__dialog-message {
  margin: 0 0 1rem;
  font-weight: 600;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-minesweeper__dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.pv-minesweeper__dialog-detail {
  margin: 0 0 1rem;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* Replay extension: storage state, saved-game choice, result and the folded panels. All of it is
   normal document flow outside the board's scroll region; buttons keep the 44px minimum. */

.pv-minesweeper__storage {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.pv-minesweeper__alert--storage {
  border-color: var(--pv-warning-line);
  background: var(--pv-warning-bg);
  color: var(--text);
}

.pv-minesweeper__restore {
  box-sizing: border-box;
  display: grid;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--pv-info-line);
  border-radius: 0.5rem;
  background: var(--pv-info-bg);
}

.pv-minesweeper__restore-text,
.pv-minesweeper__result-line,
.pv-minesweeper__scope,
.pv-minesweeper__subhead {
  margin: 0;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-minesweeper__restore-text,
.pv-minesweeper__subhead {
  font-weight: 600;
}

.pv-minesweeper__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
}

.pv-minesweeper__result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.pv-minesweeper__result-line {
  flex: 1 1 100%;
}

.pv-minesweeper__panels {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
}

.pv-minesweeper__panel {
  box-sizing: border-box;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
}

.pv-minesweeper__summary {
  box-sizing: border-box;
  min-height: 44px;
  padding: 0.625rem 1rem;
  font-weight: 700;
  cursor: pointer;
}

.pv-minesweeper__summary:focus-visible {
  outline: 3px solid var(--pv-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--pv-halo);
}

.pv-minesweeper__panel-body {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
  padding: 0 1rem 1rem;
}

.pv-minesweeper__scope {
  color: var(--muted);
}

.pv-minesweeper__list {
  display: grid;
  gap: 0.25rem;
  margin: 0;
  padding-left: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.pv-minesweeper__item {
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-minesweeper__note--date {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Challenge calendar (replay spec §5.1): read-only; statuses are text marks (✓ completed, • attempted)
   and accessible names, not colour. Day buttons keep 44px; narrow screens wrap the days as a list
   instead of overflowing, and only where seven 44px columns fit do they line up as weeks. */
.pv-minesweeper__month-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.pv-minesweeper__month {
  flex: 1 1 8rem;
  margin: 0;
  font-weight: 700;
  text-align: center;
}

.pv-minesweeper__days {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 0.25rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pv-minesweeper__day-slot {
  display: flex;
  min-width: 0;
}

.pv-minesweeper__day {
  box-sizing: border-box;
  flex: 1 1 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0.25rem;
  border: 1px solid var(--pv-control);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.pv-minesweeper__day[aria-pressed="true"] {
  border-width: 2px;
  border-color: var(--accent);
  background: var(--pv-selected);
  font-weight: 700;
}

.pv-minesweeper__day:focus-visible {
  outline: 3px solid var(--pv-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--pv-halo);
}

@media (min-width: 26rem) {
  .pv-minesweeper__days {
    grid-template-columns: repeat(7, minmax(44px, 1fr));
  }

  .pv-minesweeper__day-slot--mon {
    grid-column-start: 2;
  }

  .pv-minesweeper__day-slot--tue {
    grid-column-start: 3;
  }

  .pv-minesweeper__day-slot--wed {
    grid-column-start: 4;
  }

  .pv-minesweeper__day-slot--thu {
    grid-column-start: 5;
  }

  .pv-minesweeper__day-slot--fri {
    grid-column-start: 6;
  }

  .pv-minesweeper__day-slot--sat {
    grid-column-start: 7;
  }
}

/* Under 30rem: the workbench card gives its side padding and frame back to the board, and the board
   region spans the page gutters (its outer width is exactly the document width, so the page never
   overflows); a board wider than that scrolls inside the region. Open/Flag share the row. */
@media not all and (min-width: 30rem) {
  .pv-minesweeper__workbench {
    padding-inline: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .pv-minesweeper__scroll {
    width: calc(100% + 2 * var(--pv-gutter));
    max-width: none;
    margin-inline: calc(-1 * var(--pv-gutter));
    border-inline-width: 0;
    border-radius: 0;
  }

  .pv-minesweeper__board {
    margin-inline: auto;
  }

  .pv-minesweeper__controls .pv-minesweeper__button {
    flex: 1 1 0;
  }
}

/* From 60rem the side deck sits beside the board (DOM order: HUD, board, result, side). Expert keeps
   one column so its 30 columns get the full width. */
@media (min-width: 60rem) {
  .pv-minesweeper__workbench {
    grid-template-columns: minmax(0, max-content) minmax(14rem, 18rem);
    grid-template-areas: "hud hud" "board side" "result side";
    column-gap: 2rem;
    justify-content: start;
    align-items: start;
  }

  .pv-minesweeper__hud {
    grid-area: hud;
  }

  .pv-minesweeper__scroll {
    grid-area: board;
  }

  .pv-minesweeper__result {
    grid-area: result;
  }

  .pv-minesweeper__side {
    grid-area: side;
  }

  .pv-minesweeper__workbench:has(.pv-minesweeper__board--expert) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "hud" "board" "result" "side";
  }
}
