:root {
  --bg: #191715;
  --bg-2: #211d1c;
  --bg-3: #2a2523;
  --line: #3a3532;
  --text: #F1ECEC;
  --muted: #a49c98;
  --faint: #6f6763;
  --accent: #F5B84E;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --gap: 3px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  background:
    radial-gradient(1000px 620px at 50% -8%, #2b2622, transparent 70%),
    radial-gradient(900px 500px at 85% 100%, #241f1c, transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- topbar ---------- */

.topbar {
  width: 100%;
  max-width: 720px;
  padding: 14px 16px 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.back {
  font-family: var(--font-mono);
  font-size: .82rem;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid transparent;
  transition: color .15s, border-color .15s, background .15s;
}

.back:hover {
  color: var(--text);
  background: var(--bg-2);
  border-color: var(--line);
}

.topbar h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.nav-select {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-mono);
  font-size: .8rem;
  letter-spacing: .02em;
  color: var(--text);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a49c98' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center,
    var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 32px 8px 12px;
  cursor: pointer;
  max-width: 190px;
  transition: border-color .15s, filter .15s;
}

.nav-select:hover {
  border-color: var(--faint);
  filter: brightness(1.08);
}

.nav-select:focus-visible {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}

.nav-select option {
  background: var(--bg-2);
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- main ---------- */

main {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 18px 16px 24px;
  width: 100%;
  max-width: 720px;
}

.hint {
  font-family: var(--font-mono);
  font-size: .76rem;
  letter-spacing: .05em;
  color: var(--muted);
  text-align: center;
}

/* ---------- board ---------- */

#board {
  --cell: min(calc((100cqw - 41px) / 10), max(18px, calc((100svh - 300px) / 10)), 44px);
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  grid-template-rows: repeat(10, var(--cell));
  gap: var(--gap);
  background: #100e0d;
  border: 1px solid var(--line);
  padding: 6px;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255, 255, 255, .03);
  touch-action: manipulation;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border: none;
  border-radius: 4px;
  background: var(--bg-3);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: calc(var(--cell) * .5);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s ease, transform .06s ease;
  -webkit-user-select: none;
  user-select: none;
  color: var(--text);
}

.cell:hover:not(.revealed):not(.flagged) {
  background: var(--bg-3);
  filter: brightness(1.22);
}

.cell:active:not(.revealed):not(.flagged) {
  transform: scale(.94);
}

.cell.revealed {
  background: #0d0b0a;
  cursor: default;
}

.cell.flagged {
  background: var(--bg-3);
  color: var(--accent);
  font-size: calc(var(--cell) * .55);
}

.cell.mine.revealed {
  background: #40201e;
}

.cell.n1 { color: #8AA6D9; }
.cell.n2 { color: #9FCB9A; }
.cell.n3 { color: #D98A8A; }
.cell.n4 { color: #C9A6D9; }
.cell.n5 { color: #E8A17A; }
.cell.n6 { color: #8FD3C7; }
.cell.n7 { color: #E88FB4; }
.cell.n8 { color: var(--muted); }

/* ---------- hud ---------- */

.hud {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 96px;
}

.hud-item {
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-item b {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.saper-result-body { padding: 8px 40px 8px 8px; }
#saper-result.hidden { display: none; }

.msg {
  min-height: 1.4rem;
  font-size: .98rem;
  text-align: center;
  color: var(--muted);
}

.msg.win {
  color: #9FCB9A;
}

.msg.lose {
  color: #D98A8A;
}

.restart {
  font: inherit;
  font-weight: 700;
  font-size: .95rem;
  color: #1a1613;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  padding: 11px 26px;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(245, 184, 78, .35);
  transition: transform .1s, filter .15s;
}

.restart:hover {
  filter: brightness(1.08);
}

.restart:active {
  transform: scale(.96);
}

.restart.hidden {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .cell {
    transition: none;
  }
}
