/* «Сапёр» — оформление игры. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #eef2f7;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --cell-gap: clamp(2px, 0.75vw, 4px);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 36px);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(900px 600px at 8% -10%, #dbeafe 0%, rgba(219, 234, 254, 0) 60%),
    radial-gradient(800px 520px at 94% 108%, #fae8ff 0%, rgba(250, 232, 255, 0) 58%),
    radial-gradient(600px 400px at 60% 10%, #f0fdf4 0%, rgba(240, 253, 244, 0) 55%),
    var(--bg);
}

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

.app {
  width: min(100%, 528px);
  padding: clamp(14px, 3.2vw, 22px);
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 26px;
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.05),
    0 14px 34px -16px rgba(15, 23, 42, 0.28),
    0 44px 90px -50px rgba(37, 99, 235, 0.35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* ── Шапка ─────────────────────────────────────────────── */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px;
}

.logo {
  font-size: clamp(22px, 5vw, 28px);
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(15, 23, 42, 0.18));
}

h1 {
  margin: 0;
  font-size: clamp(20px, 4.6vw, 26px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.sub {
  margin: 3px 0 0;
  font-size: clamp(11px, 2.7vw, 12.5px);
  font-weight: 500;
  color: var(--muted);
}

/* ── Счётчики ──────────────────────────────────────────── */

.statusbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin: 10px 0 8px;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  padding: 6px 10px;
  white-space: nowrap;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: inset 0 1px 0 #fff;
}

.stat:last-of-type {
  justify-self: end;
}

.stat .ic {
  font-size: 13px;
  opacity: 0.75;
}

.stat .val {
  font-family: var(--mono);
  font-size: clamp(13px, 3.2vw, 15px);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.reset {
  justify-self: center;
  display: grid;
  place-items: center;
  width: clamp(40px, 10vw, 48px);
  height: clamp(40px, 10vw, 48px);
  padding: 0;
  font-size: clamp(19px, 5vw, 24px);
  line-height: 1;
  cursor: pointer;
  background: linear-gradient(180deg, #ffffff, #eef2f7);
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 50%;
  box-shadow:
    inset 0 1px 0 #fff,
    0 2px 6px rgba(15, 23, 42, 0.12);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.reset:hover {
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 #fff,
    0 4px 10px rgba(15, 23, 42, 0.16);
}

.reset:active {
  transform: scale(0.95);
}

.reset:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.4);
  outline-offset: 2px;
}

/* ── Поле ──────────────────────────────────────────────── */

.board-wrap {
  position: relative;
  border-radius: 17px;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: var(--cell-gap);
  padding: clamp(6px, 1.2vw, 9px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  background: linear-gradient(180deg, #e9eff7, #dde5ef);
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 17px;
  box-shadow:
    inset 0 2px 6px rgba(15, 23, 42, 0.09),
    inset 0 -1px 0 rgba(255, 255, 255, 0.7);
}


.cell {
  appearance: none;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1;
  padding: 0;
  font-family: var(--mono);
  font-size: clamp(12px, 4vw, 20px);
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  background: linear-gradient(180deg, #f2f8fd, #cfdded);
  border: 1px solid rgba(100, 116, 139, 0.4);
  border-radius: 22%;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.95),
    inset -1px -1px 0 rgba(100, 116, 139, 0.16),
    0 1px 2px rgba(15, 23, 42, 0.22),
    0 2px 5px -2px rgba(15, 23, 42, 0.16);
  transition: transform 0.08s ease, background 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
}

@media (hover: hover) and (pointer: fine) {
  .cell.hidden:hover {
    background: linear-gradient(180deg, #fbfdff, #d8e5f2);
    border-color: rgba(100, 116, 139, 0.55);
    transform: translateY(-1px);
  }
}

.cell:active {
  transform: translateY(0) scale(0.95);
}

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

.cell.revealed {
  cursor: default;
  background: #f7fafc;
  border-color: rgba(148, 163, 184, 0.18);
  box-shadow:
    inset 0 1px 3px rgba(15, 23, 42, 0.07),
    inset 0 -1px 0 rgba(255, 255, 255, 0.8);
}

.cell.revealed.empty {
  background: #fafcfe;
}

.cell.revealed:hover,
.cell.revealed:active {
  transform: none;
}

.cell.n1 { color: #2563eb; }
.cell.n2 { color: #15803d; }
.cell.n3 { color: #dc2626; }
.cell.n4 { color: #7c3aed; }
.cell.n5 { color: #b45309; }
.cell.n6 { color: #0e7490; }
.cell.n7 { color: #334155; }
.cell.n8 { color: #64748b; }

.cell.flag {
  background: linear-gradient(180deg, #fffdf4, #fdf0c6);
  border-color: rgba(217, 119, 6, 0.28);
  font-size: clamp(11px, 3.7vw, 19px);
}

.cell.mine {
  cursor: default;
  background: linear-gradient(180deg, #f1f5f9, #e2e8f0);
  border-color: rgba(148, 163, 184, 0.3);
  font-size: clamp(11px, 3.7vw, 19px);
}

.cell.mine.exploded {
  color: #fff;
  background: linear-gradient(180deg, #f87171, #dc2626);
  border-color: #b91c1c;
  animation: boom 0.4s ease;
}

.cell.wrong {
  background: linear-gradient(180deg, #fee2e2, #fecaca);
  border-color: rgba(220, 38, 38, 0.3);
  color: #b91c1c;
  font-size: clamp(11px, 3.7vw, 19px);
}

.cell.mine:hover,
.cell.wrong:hover {
  transform: none;
}

.cell.anim {
  animation: pop 0.17s ease-out both;
}

@keyframes pop {
  from {
    opacity: 0.3;
    transform: scale(0.86);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes boom {
  0% { transform: scale(0.82); }
  45% { transform: scale(1.12); }
  70% { transform: scale(0.98); }
  100% { transform: scale(1); }
}

/* ── Оверлей итога ─────────────────────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 12px;
  visibility: hidden;
  opacity: 0;
  background: rgba(238, 242, 247, 0.62);
  border-radius: 17px;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.24s ease, visibility 0.24s ease;
}

.overlay.show {
  visibility: visible;
  opacity: 1;
}

.overlay-card {
  width: min(100%, 280px);
  padding: 20px 22px;
  text-align: center;
  background: #fff;
  border-radius: 18px;
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.05),
    0 24px 60px -24px rgba(15, 23, 42, 0.45);
  transform: translateY(10px) scale(0.96);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.25);
}

.overlay.show .overlay-card {
  transform: none;
}

.ov-emoji {
  font-size: 40px;
  line-height: 1;
}

.ov-title {
  margin: 6px 0 2px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.ov-sub {
  margin: 0 0 15px;
  font-size: 13px;
  color: var(--muted);
}

.btn-primary {
  padding: 10px 22px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  border: 0;
  border-radius: 12px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 8px 18px -8px rgba(37, 99, 235, 0.7);
  transition: transform 0.12s ease, filter 0.15s ease;
}

.btn-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-primary:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

/* ── Подвал ────────────────────────────────────────────── */

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.actions-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  font: inherit;
  font-size: clamp(11px, 2.7vw, 12.5px);
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(15, 23, 42, 0.05);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.ghost-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.ghost-btn[aria-pressed="true"] {
  color: #1d4ed8;
  background: #eff6ff;
  border-color: #93c5fd;
  box-shadow: inset 0 0 0 1px #bfdbfe;
}

.ghost-btn:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(15, 23, 42, 0.05);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn[aria-pressed="false"] {
  background: #f8fafc;
  color: var(--muted);
}

.icon-btn:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

.keys {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

kbd {
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
}

.hint {
  margin: 8px 2px 0;
  font-size: clamp(10.5px, 2.5vw, 12px);
  line-height: 1.45;
  color: var(--muted);
}

/* На невысоких экранах (ноутбуки 768/720) карточка слегка сжимается,
   чтобы поле и подсказка помещались без прокрутки. */
@media (min-width: 640px) {
  .app {
    width: min(100%, clamp(360px, calc(100dvh - 306px), 528px));
  }
}

@media (max-width: 400px) {
  body {
    padding: 10px;
  }

  .app {
    padding: 13px;
    border-radius: 20px;
  }

  .stat {
    padding: 5px 8px;
  }

  .hint {
    font-size: 10.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }
}
