/* Minesweeper: raised tiles over a sandy field. */

:root {
  --tile: #d8dde3;
  --tile-hi: #f4f6f8;
  --tile-lo: #a9b1ba;
  --ground: #efe9dc;
  --ground-line: rgba(90, 70, 40, 0.12);
  --n1: #1f5fbf;
  --n2: #2e8540;
  --n3: #c9302c;
  --n4: #203a7a;
  --n5: #8a2a1c;
  --n6: #1d8a8a;
  --n7: #222;
  --n8: #777;
  --flag: #d23c2e;
  --why: #ffcf3d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --tile: #3b424b;
    --tile-hi: #56606b;
    --tile-lo: #22272d;
    --ground: #1c1f23;
    --ground-line: rgba(255, 255, 255, 0.05);
    --n1: #6ea8ff;
    --n2: #6fd08a;
    --n3: #ff7a70;
    --n4: #a8b8ff;
    --n5: #ffab91;
    --n6: #6fe3e3;
    --n7: #eee;
    --n8: #aaa;
  }
}
:root[data-theme='dark'] {
  --tile: #3b424b;
  --tile-hi: #56606b;
  --tile-lo: #22272d;
  --ground: #1c1f23;
  --ground-line: rgba(255, 255, 255, 0.05);
  --n1: #6ea8ff;
  --n2: #6fd08a;
  --n3: #ff7a70;
  --n4: #a8b8ff;
  --n5: #ffab91;
  --n6: #6fe3e3;
  --n7: #eee;
  --n8: #aaa;
}
:root[data-theme='hallows'] {
  --tile: #3a2d52;
  --tile-hi: #54457a;
  --tile-lo: #1c1330;
  --ground: #1a1328;
  --ground-line: rgba(232, 176, 74, 0.08);
  --n1: #9fb6ff;
  --n2: #8fe3a0;
  --n3: #ff9a7a;
  --n4: #c7b0ff;
  --n5: #ffc27a;
  --n6: #7fe3e3;
  --n7: #f4e8cc;
  --n8: #b8a78a;
  --flag: #f08a24;
}
:root[data-theme='hallows'] .hw-candle {
  display: none;
}
:root[data-theme='hallows'] .title-main {
  font-family: var(--font-display);
  letter-spacing: 0;
}
body {
  min-height: var(--app-height);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
#announce {
  margin: 0;
  top: 0;
}
.app {
  display: flex;
  flex-direction: column;
  height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom));
  min-height: 520px;
  max-width: 520px;
  margin: 0 auto;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 6px;
}
.title-btn {
  appearance: none;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 12px;
  color: var(--text);
  min-width: 0;
}
.title-btn:hover {
  background: var(--accent-soft);
}
.title-main {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.title-main::after {
  content: ' ▾';
  font-size: 0.7em;
  color: var(--text-muted);
}
.title-sub {
  display: block;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
}
.score {
  display: flex;
  gap: 8px;
}
.chip {
  min-width: 64px;
  text-align: center;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.chip small {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.chip b {
  display: block;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

.stage {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 6px 10px;
  container-type: size;
}
.field-wrap {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}
.field-grid {
  --cell: min(calc((100cqw - 8px) / var(--w)), calc((100cqh - 8px) / var(--h)), 44px);
  display: grid;
  grid-template-columns: repeat(var(--w), var(--cell));
  grid-template-rows: repeat(var(--h), var(--cell));
  gap: 0;
  padding: 4px;
  border-radius: 10px;
  background: var(--tile-lo);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.sq {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  position: relative;
  background: var(--tile);
  box-shadow: inset 2px 2px 0 var(--tile-hi), inset -2px -2px 0 var(--tile-lo);
  font: inherit;
  font-weight: 900;
  font-size: calc(var(--cell) * 0.58);
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}
.sq.open {
  background: var(--ground);
  box-shadow: inset -1px -1px 0 var(--ground-line), inset 1px 1px 0 var(--ground-line);
  cursor: default;
}
.sq.n1 { color: var(--n1); }
.sq.n2 { color: var(--n2); }
.sq.n3 { color: var(--n3); }
.sq.n4 { color: var(--n4); }
.sq.n5 { color: var(--n5); }
.sq.n6 { color: var(--n6); }
.sq.n7 { color: var(--n7); }
.sq.n8 { color: var(--n8); }
.sq.flag::after,
.sq.mine::after {
  content: '';
  position: absolute;
  inset: 22%;
}
.sq.flag::after {
  background: var(--flag);
  clip-path: polygon(20% 5%, 90% 30%, 20% 55%, 20% 95%, 10% 95%, 10% 5%);
}
.sq.mine::after {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #888, #111 60%);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.2);
}
.sq.mine {
  background: var(--ground);
  box-shadow: none;
}
.sq.boom {
  background: var(--flag);
  animation: boom 0.5s ease;
}
.sq.wrong::after {
  background: var(--text-muted);
}
.sq.why {
  outline: 3px solid var(--why);
  outline-offset: -3px;
  z-index: 1;
}
.sq.safe-hint {
  box-shadow: inset 0 0 0 3px var(--n2);
  animation: breathe 1.2s ease-in-out infinite;
}
.sq.mine-hint {
  box-shadow: inset 0 0 0 3px var(--flag);
  animation: breathe 1.2s ease-in-out infinite;
}
@keyframes breathe {
  50% {
    filter: brightness(1.2);
  }
}
@keyframes boom {
  30% {
    transform: scale(1.5);
  }
}
@media (prefers-reduced-motion: reduce) {
  .sq.boom,
  .sq.safe-hint,
  .sq.mine-hint {
    animation: none;
  }
}
.tool.on {
  background: var(--accent);
  color: var(--accent-contrast);
}
.results .stamp {
  opacity: 1;
  transform: none;
}
/* ---------- Toolbar and menus ---------- */

.toolbar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 6px 8px 10px;
}
.tool {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 64px;
  min-height: 50px;
  padding: 6px 8px;
  border-radius: 14px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}
.tool:hover:not(:disabled) {
  background: var(--accent-soft);
}
.tool:disabled {
  opacity: 0.38;
}
.menu-list {
  display: grid;
  gap: 10px;
}
.menu-card {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.menu-card .menu-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}
.menu-card b {
  display: block;
  font-size: 1.05rem;
}
.menu-card small {
  color: var(--text-muted);
}
.menu-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.menu-row .btn {
  flex: 1;
}
@media (prefers-reduced-motion: reduce) {
  .row.reveal .pegs .peg {
    animation: none;
  }
}
