:root {
  color-scheme: dark;
  --bg: #181818;
  --line: #222224;
  --slot: #101011;
  --gap: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg);
  color: #fff;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  font-weight: 500;
  overscroll-behavior: none;
}

button,
p {
  margin: 0;
}

.sr {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.stage {
  --board: min(100cqw, 100cqh);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  container-type: size;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.stage.show-side {
  --board: min(100cqh, calc(100cqw - 136px));
  justify-content: flex-start;
}

.side {
  display: none;
  flex: none;
  flex-direction: column;
  gap: 18px;
  width: 104px;
  min-height: 0;
}

.stage.show-side .side {
  display: flex;
}

.stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.stat-name {
  color: #3a3a3c;
  font-size: 12px;
}

.stat-num {
  color: #454548;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 1;
}

.board {
  position: relative;
  flex: none;
  width: var(--board);
  height: var(--board);
  padding: var(--gap);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  container-type: inline-size;
  user-select: none;
  -webkit-touch-callout: none;
}

.grid {
  --n: 9;
  --cell: calc(100cqw / var(--n));
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: max(1px, calc(var(--cell) * 0.08));
  height: 100%;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: max(2px, calc(var(--cell) * 0.16));
  background: #232325;
  color: #555;
  font: 600 calc(var(--cell) * 0.5) / 1 "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
}

.cell:hover {
  background: #29292b;
}

.cell.open {
  background: var(--slot);
  cursor: default;
}

.cell.open.has-count {
  cursor: pointer;
}

.cell[data-n="1"] { color: #4a4a4d; }
.cell[data-n="2"] { color: #565659; }
.cell[data-n="3"] { color: #626265; }
.cell[data-n="4"] { color: #6e6e71; }
.cell[data-n="5"],
.cell[data-n="6"],
.cell[data-n="7"],
.cell[data-n="8"] { color: #7a7a7d; }

.cell.flag::before {
  content: "";
  position: absolute;
  left: 34%;
  top: 22%;
  width: 0;
  height: 0;
  border-top: calc(var(--cell) * 0.15) solid transparent;
  border-bottom: calc(var(--cell) * 0.15) solid transparent;
  border-left: calc(var(--cell) * 0.3) solid #7a4a4a;
}

.cell.flag::after {
  content: "";
  position: absolute;
  left: 32%;
  top: 22%;
  width: max(1px, calc(var(--cell) * 0.05));
  height: 56%;
  border-radius: 1px;
  background: #4a4a4c;
}

.cell.mine::before {
  content: "";
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: #4e4e50;
  box-shadow: 0 0 0 max(1px, calc(var(--cell) * 0.05)) #2a2a2c;
}

.cell.mine.flag::before {
  inset: auto;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

.cell.boom {
  background: #3a2424;
}

.cell.boom::before {
  background: #8a4b4b;
}

.cell.wrong::before {
  content: "";
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  border: 0;
  background:
    linear-gradient(45deg, transparent 46%, #6a3f3f 46%, #6a3f3f 54%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, #6a3f3f 46%, #6a3f3f 54%, transparent 54%);
  background-size: 50% 50%;
  background-position: center;
  background-repeat: no-repeat;
}

.cell.wrong::after {
  display: none;
}

.cell.cursor {
  outline: 2px solid #444;
  outline-offset: -2px;
}

.cell:focus-visible {
  outline: 2px solid #444;
  outline-offset: -2px;
}

.veil {
  position: absolute;
  inset: var(--gap);
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 10px;
  background: rgba(24, 24, 24, 0.45);
  pointer-events: none;
}

.veil[hidden] {
  display: none;
}

.note {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 28px;
  border-radius: 12px;
  background: rgba(24, 24, 24, 0.92);
  box-shadow: inset 0 0 0 1px #2a2a2c;
  text-align: center;
  pointer-events: auto;
}

.note p {
  color: #5a5a5c;
  font-size: clamp(16px, 4.6cqw, 26px);
  font-weight: 500;
  line-height: 1.3;
}

.actions {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 8px;
}

.actions button {
  width: 100%;
}

button {
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: #1e1e20;
  color: #3f3f42;
  font: 500 12px/1 "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
}

button:hover {
  background: #242426;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 2px solid #444;
  outline-offset: 3px;
}

button.ghost {
  background: transparent;
  color: #3a3a3c;
  box-shadow: inset 0 0 0 1px #2a2a2c;
}

button.ghost:hover {
  background: #1c1c1e;
}

button.ghost[aria-pressed="true"] {
  background: #241c1c;
  color: #6a4545;
  box-shadow: inset 0 0 0 1px #3a2a2a;
}

.note button.ghost {
  min-height: 34px;
  padding: 0 18px;
  color: #5a5a5c;
  box-shadow: inset 0 0 0 1px #3a3a3c;
  font-size: 13px;
}

.back {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: 6px;
  color: #3a3a3c;
  box-shadow: inset 0 0 0 1px #2a2a2c;
  font-size: 12px;
  text-decoration: none;
}

.back:hover {
  background: #1c1c1e;
}

.back:focus-visible {
  outline: 2px solid #444;
  outline-offset: 3px;
}
