/* ============================================================
   Minesweeper — clean, minimal, sans-serif only.
   Near-monochrome UI; the only color comes from the digits.
   ============================================================ */

:root {
  /* surfaces */
  --bg:          #ecece7;
  --bg-tint:     #f6f6f2;
  --surface:     #ffffff;
  --line:        #e3e3dd;

  /* cells */
  --cell:        #e7e7e1;
  --cell-edge:   #d7d7cf;
  --cell-hi:     #efefe9;
  --revealed:    #fafaf8;

  /* ink */
  --ink:         #1b1b18;
  --ink-soft:    #54544e;
  --muted:       #9a9a92;

  /* states */
  --accent:      #2f6fed;
  --flag:        #e5484d;
  --good:        #1f9d5b;

  /* number palette (classic, refined) */
  --n1: #2f6fed;
  --n2: #1f9d5b;
  --n3: #e5484d;
  --n4: #6741d9;
  --n5: #b8763e;
  --n6: #0c8599;
  --n7: #343a40;
  --n8: #8a8a82;

  --cell-size: 32px;
  --radius:    18px;
  --shadow:    0 1px 0 rgba(0,0,0,.02), 0 18px 40px -22px rgba(20,20,15,.35);

  font-family: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-tint), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #fff8, transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100%;
  padding: clamp(20px, 5vh, 64px) 18px 56px;
}

/* faint paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: min(96vw, 1040px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

/* ---------- Masthead ---------- */
.masthead { text-align: center; }

.wordmark {
  margin: 0;
  font-weight: 800;
  font-size: clamp(28px, 5vw, 40px);
  letter-spacing: -0.035em;
  line-height: 1;
}

.tagline {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* ---------- Difficulty segmented control ---------- */
.difficulty {
  position: relative;
  display: inline-flex;
  padding: 5px;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.seg {
  position: relative;
  z-index: 1;
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-soft);
  padding: 9px 18px;
  border-radius: 999px;
  transition: color .25s ease;
}
.seg:hover { color: var(--ink); }
.seg.is-active { color: #fff; }

.seg-thumb {
  position: absolute;
  z-index: 0;
  top: 5px;
  left: 5px;
  height: calc(100% - 10px);
  background: var(--ink);
  border-radius: 999px;
  transition: transform .32s cubic-bezier(.34,1.3,.4,1), width .32s cubic-bezier(.34,1.3,.4,1);
}

/* ---------- Panel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  max-width: 100%;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  padding: 0 4px;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-soft);
  min-width: 92px;
}
.stat:last-child { justify-content: flex-end; }

.ico { width: 20px; height: 20px; }

.readout {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* reset / status face */
.reset {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-tint);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease;
}
.reset:hover { transform: translateY(-1px); box-shadow: 0 8px 18px -10px rgba(20,20,15,.5); }
.reset:active { transform: scale(.94); }

.face { width: 38px; height: 38px; }
.face-bg { fill: #ffd84d; stroke: #1b1b18; stroke-width: 2.4; }
.face-mark .eye   { fill: #1b1b18; }
.face-mark .mouth { fill: none; stroke: #1b1b18; }

/* win face — content, cool green */
.reset.is-win .face-bg { fill: var(--good); }
.reset.is-win .eye    { fill: #fff; }
.reset.is-win .mouth  { stroke: #fff; }

/* lose face — flat line, red */
.reset.is-lose .face-bg { fill: var(--flag); }
.reset.is-lose .eye   { fill: #fff; }
.reset.is-lose .mouth { stroke: #fff; }

/* ---------- Board ---------- */
.board-wrap {
  position: relative;
  border-radius: 14px;
  overflow: auto;
  background: var(--bg-tint);
  padding: 7px;
  border: 1px solid var(--line);
}

.board {
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  margin: 0 auto;
  width: max-content;
  touch-action: manipulation;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  font-size: calc(var(--cell-size) * 0.5);
  font-variant-numeric: tabular-nums;
  display: grid;
  place-items: center;
  color: transparent;
  background: linear-gradient(180deg, var(--cell-hi), var(--cell));
  box-shadow: inset 0 0 0 1px var(--cell-edge);
  transition: background .12s ease, transform .08s ease, box-shadow .12s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(.is-open):not(.is-flag) {
  background: linear-gradient(180deg, #f4f4ee, var(--cell-hi));
}
.cell:active:not(.is-open) { transform: scale(.92); }

.cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell.is-open {
  cursor: default;
  background: var(--revealed);
  box-shadow: inset 0 0 0 1px var(--line);
  animation: pop .18s ease both;
}

@keyframes pop {
  0%   { transform: scale(.86); }
  100% { transform: scale(1); }
}

/* number colors */
.cell[data-n="1"] { color: var(--n1); }
.cell[data-n="2"] { color: var(--n2); }
.cell[data-n="3"] { color: var(--n3); }
.cell[data-n="4"] { color: var(--n4); }
.cell[data-n="5"] { color: var(--n5); }
.cell[data-n="6"] { color: var(--n6); }
.cell[data-n="7"] { color: var(--n7); }
.cell[data-n="8"] { color: var(--n8); }

/* flag */
.cell.is-flag {
  color: var(--flag);
  position: relative;
}
.cell.is-flag::after {
  content: "";
  width: 50%;
  height: 50%;
  background: var(--flag);
  /* pole + pennant, drawn as one shape */
  clip-path: polygon(38% 0, 92% 22%, 38% 44%, 38% 100%, 30% 100%, 30% 0);
  animation: plant .18s cubic-bezier(.34,1.4,.5,1) both;
}
@keyframes plant {
  0% { transform: scale(.2) rotate(-12deg); }
  100% { transform: scale(1) rotate(0); }
}

/* mine */
.cell.is-mine {
  background: var(--revealed);
}
.cell.is-mine::after {
  content: "";
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #4a4a44, #151513 70%);
  box-shadow: 0 0 0 2px rgba(0,0,0,.06);
  animation: reveal-mine .26s cubic-bezier(.34,1.4,.5,1) both;
}
.cell.is-mine.is-boom {
  background: var(--flag);
}
.cell.is-mine.is-boom::after {
  background: radial-gradient(circle at 35% 32%, #fff, #151513 72%);
}

@keyframes reveal-mine {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* wrongly flagged cell after a loss */
.cell.is-wrong { background: #f6e7e7; }
.cell.is-wrong::after {
  content: "";
  width: 50%;
  height: 50%;
  background:
    linear-gradient(45deg, transparent 44%, var(--flag) 44% 56%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, var(--flag) 44% 56%, transparent 56%);
}

/* ---------- Win / lose overlay ---------- */
.overlay {
  position: absolute;
  inset: 7px;
  border-radius: 10px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 6px;
  background: rgba(252, 252, 250, .82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade .3s ease both;
  z-index: 5;
}
.overlay[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.overlay-title {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.overlay-sub {
  margin: 0;
  color: var(--ink-soft);
  font-weight: 500;
}
.again {
  margin-top: 10px;
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  background: var(--ink);
  padding: 11px 22px;
  border-radius: 999px;
  transition: transform .15s ease, opacity .2s ease;
}
.again:hover { transform: translateY(-1px); }
.again:active { transform: scale(.96); }

/* ---------- Footer ---------- */
.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 24px;
  width: 100%;
  max-width: 640px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.best { color: var(--ink-soft); font-weight: 600; }
.hint b { color: var(--ink-soft); font-weight: 700; }

@media (max-width: 520px) {
  .meta { justify-content: center; text-align: center; }
  .seg { padding: 9px 13px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
