:root {
  color-scheme: light;
  --page: #f4f2ed;
  --surface: #fbfaf7;
  --raised: #eeece5;
  --ink: #252823;
  --muted: #5b6258;
  --line: #d8d9d0;
  --accent: #315d4a;
  --accent-text: #fff;
  --selected: #e0e9e0;
  --well: #e2e6dc;
  --dot: #bfc9bc;
  --tile: #c0cfc2;
  --tile-light: #e4ece1;
  --tile-dark: #879c8d;
  --tile-hover: #d0ded2;
  --open: #eef0e8;
  --grid: #cbd6ca;
  --red: #a03031;
  --blast: #f1c2ba;
  --n1: #2756a2;
  --n2: #236246;
  --n3: #aa3029;
  --n4: #554195;
  --n5: #8c362a;
  --n6: #196568;
  --n7: #342c26;
  --n8: #5a6059;
  --mono: "IBM Plex Mono", "Courier New", monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #191e1c;
  --surface: #202623;
  --raised: #29322d;
  --ink: #edf2e9;
  --muted: #b1bdb3;
  --line: #3c4841;
  --accent: #bbd9c0;
  --accent-text: #14251b;
  --selected: #31463a;
  --well: #171f1b;
  --dot: #334239;
  --tile: #40584a;
  --tile-light: #607b6a;
  --tile-dark: #283c31;
  --tile-hover: #506c5a;
  --open: #25332b;
  --grid: #3a4e42;
  --red: #ff9d92;
  --blast: #61352f;
  --n1: #a1bdff;
  --n2: #9dde9c;
  --n3: #ff9d92;
  --n4: #d4b9ff;
  --n5: #fab68e;
  --n6: #90dad7;
  --n7: #f0e0b8;
  --n8: #bdc9bc;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  background: var(--page);
  font: 16px/1.5 Inter, system-ui, sans-serif;
}
button, input { font: inherit; color: inherit; }
button {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--raised); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
.frame { width: calc(100% - 64px); margin: 0 auto; }
.site-bar { flex: none; border-bottom: 1px solid var(--line); background: var(--surface); }
.header-row, .title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.header-row { min-height: 64px; }
.site-link { color: var(--muted); font-size: 14px; }
.site-link span { margin-left: 8px; }
.title-row { margin: 28px 0 20px; }
h1, h2, p, dl, dd { margin: 0; }
h1 { font-size: clamp(36px, 5vw, 56px); line-height: 1; font-weight: 650; letter-spacing: -.045em; }
h2 { font-size: 16px; font-weight: 650; }
.toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--raised);
}
.toggle button { background: transparent; border-color: transparent; font-size: 13px; min-height: 36px; }
.toggle button:hover { background: var(--surface); }
.toggle button[aria-pressed="true"] { background: var(--surface); border-color: var(--line); }
#solo-mode[aria-disabled="true"] {
  color: var(--red);
  border-color: var(--red);
  background: var(--blast);
  cursor: not-allowed;
}
#game-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#game-shell > :not(.layout) { flex: none; }
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  padding-bottom: 16px;
}
.game, .sidebar {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  min-width: 0;
}
.game {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 16px;
}
.sidebar { align-self: start; max-height: 100%; overflow: auto; }
#settings-toggle { display: none; }
.game-top, .game-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.game-top { padding: 0 4px 12px; }
.stats { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.stats div { display: grid; grid-template-columns: auto auto; align-items: baseline; gap: 8px; }
.stats span { color: var(--muted); font-size: 13px; }
.stats strong { white-space: nowrap; min-width: 2ch; font: 700 22px/1.4 var(--mono); font-variant-numeric: tabular-nums; }
#rival-progress, #series-score {
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--raised);
}
#rival-progress strong, #series-score strong { font-size: 16px; }
#viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: radial-gradient(circle at center, var(--dot) 1px, transparent 1px) 0 0 / 16px 16px, var(--well);
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}
#viewport.dragging, #viewport.dragging .cell { cursor: grabbing; }
#board {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), 36px);
  grid-auto-rows: 36px;
  border: 1px solid var(--tile-dark);
  background: var(--grid);
  transform-origin: top left;
  box-shadow: 0 4px 10px #0002;
}
.cell {
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
  width: 36px;
  height: 36px;
  border: 1px solid var(--grid);
  border-left: 0;
  border-top: 0;
  padding: 0;
  border-radius: 0;
  background: var(--open);
  font: bold 22px/1 var(--mono);
}
.cell:focus-visible { outline-offset: -3px; position: relative; z-index: 1; }
.cell:not(.closed) { cursor: default; }
.cell[data-cell]:not(.spectator) { cursor: pointer; }
.cell:not(.closed):hover { background: var(--open); }
.cell.closed { background: var(--tile); border: 0; box-shadow: inset 2px 2px var(--tile-light), inset -2px -2px var(--tile-dark); }
@media (hover: hover) {
  .cell.closed:not(.spectator):hover { background: var(--tile-hover); }
}
.cell[data-cell="F"], .cell[data-cell="!"] { color: var(--red); }
.cell[data-cell="X"], .cell[data-cell="X"]:hover { background: var(--blast); }
.cell[data-cell="1"] { color: var(--n1); }
.cell[data-cell="2"] { color: var(--n2); }
.cell[data-cell="3"] { color: var(--n3); }
.cell[data-cell="4"] { color: var(--n4); }
.cell[data-cell="5"] { color: var(--n5); }
.cell[data-cell="6"] { color: var(--n6); }
.cell[data-cell="7"] { color: var(--n7); }
.cell[data-cell="8"] { color: var(--n8); }
.cell .flag {
  width: 16px;
  height: 18px;
  background: currentColor;
  clip-path: polygon(8% 0, 100% 10%, 79% 36%, 100% 58%, 21% 51%, 21% 100%, 8% 100%);
}
.cell .mine {
  width: 19px;
  height: 19px;
  background: currentColor;
  clip-path: polygon(44% 0, 56% 0, 56% 22%, 65% 24%, 82% 7%, 93% 18%, 76% 35%, 78% 44%, 100% 44%, 100% 56%, 78% 56%, 76% 65%, 93% 82%, 82% 93%, 65% 76%, 56% 78%, 56% 100%, 44% 100%, 44% 78%, 35% 76%, 18% 93%, 7% 82%, 24% 65%, 22% 56%, 0 56%, 0 44%, 22% 44%, 24% 35%, 7% 18%, 18% 7%, 35% 24%, 44% 22%);
}
#board-message {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  text-align: center;
  overflow: auto;
  justify-content: safe center;
  background: var(--well);
  cursor: default;
  touch-action: pan-y;
  font-weight: 600;
}
#board-message.countdown {
  background: color-mix(in srgb, var(--well) 83%, transparent);
  font: bold 64px/1 var(--mono);
}
#duel-vote { width: min(100%, 300px); margin: 0; }
#duel-vote button[aria-pressed="true"] { opacity: 1; }
.game-bottom { padding-top: 12px; }
#status { flex: 1 1 160px; color: var(--muted); font-size: 14px; }
.zoom-controls { display: flex; gap: 4px; margin-left: auto; }
.zoom-controls button { min-width: 44px; font: 700 14px var(--mono); }
#zoom-reset { white-space: nowrap; font-family: inherit; }
#zoom-percent { margin-left: 4px; color: var(--muted); font-family: var(--mono); }
#search-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
}
.search-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.sidebar section { padding: 16px; }
#settings:not([hidden]) + .help { border-top: 1px solid var(--line); }
.levels { display: grid; margin: 12px 0; gap: 4px; }
.levels button { display: flex; align-items: center; justify-content: space-between; gap: 4px; text-align: left; }
.levels button small { white-space: nowrap; font: 12px/1.4 var(--mono); color: var(--muted); }
.levels button b { font-weight: 400; }
.levels button[aria-pressed="true"] { border-color: var(--accent); background: var(--selected); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.primary:hover { background: color-mix(in srgb, var(--accent) 92%, var(--ink)); }
.sidebar button.primary { width: 100%; }
#custom { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; }
label { display: block; color: var(--muted); font-size: 13px; }
input { display: block; width: 100%; min-height: 44px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); }
.help p, #notice { font-size: 13px; color: var(--muted); }
#notice { padding: 0 4px 8px; }
#notice.error { color: var(--red); }
dl { margin: 8px 0 12px; font-size: 13px; }
dl div { display: flex; justify-content: space-between; gap: 4px; padding: 4px 0; }
dt { color: var(--muted); }
.touch { display: none; }
@media (pointer: coarse) {
  .mouse { display: none; }
  .touch { display: inline; }
}
@media (max-width: 760px) {
  .frame { width: calc(100% - 32px); }
  .header-row { min-height: 56px; }
  .title-row { margin: 20px 0 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout .sidebar { display: none; }
  .settings-open .layout .sidebar { display: block; }
  .settings-open .game { display: none; }
  #settings-toggle { display: block; margin-bottom: 8px; align-self: start; }
  .game { padding: 8px; }
  .game-top { padding-bottom: 8px; }
  #duel-vote { width: min(100%, 300px); margin: 0; }
#duel-vote button[aria-pressed="true"] { opacity: 1; }
.game-bottom { padding-top: 8px; }
}
@media (max-width: 370px) {
  .frame { width: calc(100% - 24px); }
  .title-row { gap: 8px; }
  .toggle button { padding: 0 8px; }
  .stats { gap: 12px; }
}

@media (max-height: 500px) {
  .header-row { min-height: 44px; }
  .title-row { margin: 4px 0 8px; }
  .layout { padding-bottom: 4px; }
  .game { padding: 8px; }
  .game-top { padding-bottom: 4px; }
  .game-bottom { padding-top: 4px; }
  #search-banner { padding: 4px 8px; margin-bottom: 4px; }
}
@media (max-width: 400px) {
  #status { flex-basis: 100%; }
}

.header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
#audio-dialog {
  width: min(calc(100% - 24px), 380px);
  max-height: calc(100dvh - 24px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--surface);
}
#audio-dialog::backdrop { background: #0008; }
.audio-heading, .audio-effects label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.audio-volume {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 12px;
  margin: 12px 0;
}
.audio-volume output { font: 14px var(--mono); color: var(--muted); }
#audio-volume { grid-column: span 2; padding: 0; min-height: 32px; }
.audio-effects label {
  min-height: 40px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
}
.audio-effects input { width: 18px; height: 18px; min-height: 0; margin: 0; }
#audio-volume, .audio-effects input { accent-color: var(--accent); }
#duel-vote .vote-result { border-color: var(--accent); background: var(--selected); }
#solo-mode.next-action, #leave.next-action {
  border-color: var(--accent);
  background: var(--selected);
}
@media (prefers-reduced-motion: no-preference) {
  #duel-vote .vote-result { animation: vote-reveal 670ms ease-in-out 3; }
  #solo-mode.next-action, #leave.next-action { animation: next-action 2.2s ease-in-out infinite; }
}
@keyframes vote-reveal {
  0%, 100% { background: var(--selected); color: var(--ink); }
  50% { background: var(--accent); color: var(--accent-text); }
}
@keyframes next-action {
  0%, 100% { background: var(--selected); }
  50% { background: var(--surface); }
}
@media (max-width: 370px) {
  .site-link span { margin-left: 4px; }
  .header-actions button { padding-inline: 6px; font-size: 13px; }
}

#field-effects {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.confetti-piece, .blast-ring, .blast-spark {
  position: absolute;
  pointer-events: none;
}
.confetti-piece {
  top: 46%;
  width: 7px;
  height: 10px;
  border-radius: 1px;
}
.blast-ring, .blast-spark {
  top: 0;
  left: 0;
  translate: -50% -50%;
  border-radius: 50%;
}
.blast-ring {
  width: 32px;
  height: 32px;
  border: 2px solid var(--red);
  background: radial-gradient(circle, #fff2bd 0%, #ffc15d 32%, transparent 68%);
}
.blast-spark {
  width: 4px;
  height: 4px;
}
@media (max-width: 760px) {
  .stats { gap: 4px 12px; }
}

@view-transition { navigation: auto; }

::view-transition-old(root) {
  animation: minesweeper-page-out 220ms ease both;
}
::view-transition-new(root) {
  animation: minesweeper-page-in 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes minesweeper-page-out {
  to { opacity: 0; transform: translateY(-8px) scale(.99); }
}
@keyframes minesweeper-page-in {
  from { opacity: 0; transform: translateY(18px) scale(.98); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .minesweeper-reveal #game-shell {
    animation: minesweeper-page-in 420ms cubic-bezier(0.16, 1, 0.3, 1);
  }
}
