:root {
  color-scheme: dark;
  --page: #0c0f15;
  --panel: rgba(24, 29, 39, 0.94);
  --panel-2: #202735;
  --line: rgba(255, 255, 255, 0.10);
  --text: #f4f7fb;
  --muted: #aab3c4;
  --accent: #ffcc4d;
  --cell-size: 34px;
  --cell-gap: 3px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 15%, rgba(92, 111, 255, 0.19), transparent 30rem),
    radial-gradient(circle at 85% 80%, rgba(255, 116, 92, 0.16), transparent 28rem),
    var(--page);
}

button,
select {
  font: inherit;
}

button {
  color: inherit;
}

.page-shell {
  width: min(100% - 24px, 1180px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  place-items: center;
}

.game-card {
  width: 100%;
  padding: clamp(18px, 4vw, 34px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.hero-avatar {
  flex: 0 0 auto;
  border-radius: 22px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 5vw, 2.7rem);
  line-height: 1.05;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(190px, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.difficulty-label {
  color: var(--muted);
  font-size: 0.92rem;
}

select,
.restart-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}

select {
  width: 100%;
  padding: 0 38px 0 13px;
  color: var(--text);
}

.restart-button {
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.restart-button:hover {
  border-color: rgba(255, 204, 77, 0.58);
  background: #293244;
}

.restart-button:active {
  transform: translateY(1px);
}

#face {
  font-size: 1.25rem;
}

.scoreboard {
  min-height: 72px;
  margin-bottom: 14px;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 1fr minmax(120px, 1.4fr) 1fr;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(8, 11, 17, 0.56);
}

.counter {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.counter:last-child {
  text-align: right;
}

.counter-label {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.counter strong {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color: var(--accent);
  font-size: 1.5rem;
  letter-spacing: 0.08em;
}

.status {
  color: var(--text);
  text-align: center;
  font-weight: 750;
}

.board-scroller {
  max-width: 100%;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    linear-gradient(145deg, rgba(255,255,255,0.035), transparent),
    rgba(4, 7, 12, 0.62);
  overscroll-behavior: contain;
}

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

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 7px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.10), transparent),
    #2b3445;
  box-shadow:
    inset 1px 1px rgba(255,255,255,0.09),
    0 2px 4px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  font-weight: 900;
  font-size: calc(var(--cell-size) * 0.55);
  line-height: 1;
  transition: transform 80ms ease, filter 100ms ease, background 120ms ease;
}

.cell:hover:not(.revealed) {
  filter: brightness(1.15);
}

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

.cell:focus-visible {
  outline: 3px solid rgba(255, 204, 77, 0.72);
  outline-offset: 1px;
}

.cell.revealed {
  cursor: default;
  border-color: rgba(255, 255, 255, 0.055);
  background: #151b25;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
}

.cell.flagged::before {
  content: "🚩";
  font-size: calc(var(--cell-size) * 0.56);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}

.cell.mine {
  padding: 2px;
  background: #8b2535;
}

.cell.mine img {
  width: 100%;
  height: 100%;
  border-radius: 5px;
  object-fit: cover;
}

.cell.exploded {
  animation: pulse 650ms ease-in-out infinite alternate;
}

.cell.wrong-flag::after {
  content: "✕";
  position: absolute;
  color: #ff5d73;
  font-size: calc(var(--cell-size) * 0.74);
  text-shadow: 0 2px 2px #000;
}

.cell.wrong-flag {
  position: relative;
}

.n1 { color: #6aa9ff; }
.n2 { color: #69d58c; }
.n3 { color: #ff6f7d; }
.n4 { color: #b498ff; }
.n5 { color: #ff9f61; }
.n6 { color: #63d6df; }
.n7 { color: #e8edf6; }
.n8 { color: #99a3b5; }

.instructions {
  margin: 15px 2px 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.footer {
  margin-top: 16px;
  padding-top: 15px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

.footer strong {
  color: var(--text);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  padding: 11px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(17, 22, 31, 0.96);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes pulse {
  from { filter: brightness(0.9); }
  to { filter: brightness(1.35); }
}

@media (max-width: 700px) {
  :root {
    --cell-size: 31px;
    --cell-gap: 2px;
  }

  .page-shell {
    width: min(100% - 12px, 1180px);
    padding: 6px 0;
  }

  .game-card {
    border-radius: 20px;
  }

  .hero-avatar {
    width: 58px;
    height: 58px;
    border-radius: 17px;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .toolbar {
    grid-template-columns: 1fr auto;
  }

  .difficulty-label {
    display: none;
  }

  .restart-button span:last-child {
    display: none;
  }

  .restart-button {
    width: 46px;
    padding: 0;
    justify-content: center;
  }

  .scoreboard {
    grid-template-columns: 1fr 1.2fr 1fr;
    padding-inline: 12px;
  }

  .status {
    font-size: 0.9rem;
  }

  .footer {
    flex-direction: column;
  }
}

@media (max-width: 390px) {
  :root {
    --cell-size: 29px;
  }

  .game-card {
    padding-inline: 12px;
  }

  .board-scroller {
    padding: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
