:root {
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8b6dff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --cell: 32px;
  --gap: 3px;
  --font:
    "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
    "Segoe UI", sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid #ffd43b;
  outline-offset: 2px;
}

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

.ms-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- HUD ---------- */
.ms-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 10px;
  padding: 8px 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, #232438, #1a1b28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 6px 18px rgba(0, 0, 0, 0.35);
}

.ms-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.ms-brand-icon {
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
  animation: ms-bob 3.2s ease-in-out infinite;
}

.ms-diff {
  display: flex;
  padding: 4px;
  gap: 3px;
  border-radius: 999px;
  background: #11121e;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.ms-diff-btn {
  border: 0;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    transform 0.1s;
}

.ms-diff-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, #8467ff, #5a35f0);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 8px rgba(104, 66, 255, 0.45);
}

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

.ms-short {
  display: none;
}

.ms-stats {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ms-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  background: #11121e;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
  font-variant-numeric: tabular-nums;
}

.ms-chip strong {
  font-size: 18px;
  font-weight: 900;
  min-width: 2.2ch;
  text-align: center;
}

.ms-chip svg {
  width: 20px;
  height: 20px;
  flex: none;
}

.ms-chip-mines strong {
  color: #ff7a8a;
}

.ms-chip-time {
  color: #ffd43b;
}

.ms-chip-time strong {
  min-width: 3ch;
}

.ms-chip-best {
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ms-chip-best strong {
  color: #7ee2a8;
  font-size: 16px;
  text-transform: none;
}

.ms-face {
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #34365a, #25263d);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.14),
    inset 0 -3px 0 rgba(0, 0, 0, 0.35),
    0 4px 10px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.12s;
}

.ms-face:active {
  transform: scale(0.9);
}

.ms-face svg {
  width: 40px;
  height: 40px;
  display: block;
  margin: auto;
}

.face-body {
  fill: #ffd43b;
  stroke: #e0a100;
  stroke-width: 2;
}

.face-shine {
  fill: #fff;
  opacity: 0.55;
}

.face-eyes {
  fill: #2b2140;
  stroke: #2b2140;
  stroke-width: 2.6;
  stroke-linecap: round;
}

.face-normal {
  stroke: none;
}

.face-cool {
  stroke: none;
}

.face-mouth {
  fill: none;
  stroke: #2b2140;
  stroke-width: 2.6;
  stroke-linecap: round;
}

.face-o {
  fill: #2b2140;
  stroke: none;
}

.face-cool,
.face-dead,
.face-o,
.face-sad {
  display: none;
}

.ms-face[data-mood="press"] .face-smile {
  display: none;
}
.ms-face[data-mood="press"] .face-o {
  display: inline;
}
.ms-face[data-mood="won"] .face-normal {
  display: none;
}
.ms-face[data-mood="won"] .face-cool {
  display: inline;
}
.ms-face[data-mood="lost"] .face-normal,
.ms-face[data-mood="lost"] .face-smile {
  display: none;
}
.ms-face[data-mood="lost"] .face-dead,
.ms-face[data-mood="lost"] .face-sad {
  display: inline;
}

.ms-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ms-flagmode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px 0 8px;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -2px 0 rgba(0, 0, 0, 0.3);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
}

.ms-flagmode svg {
  width: 24px;
  height: 24px;
  filter: grayscale(0.7) brightness(0.9);
  transition: filter 0.15s;
}

.ms-flagmode[aria-pressed="true"] {
  background: linear-gradient(180deg, #ff5f7a, #e0294f);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 10px rgba(255, 61, 90, 0.45);
}

.ms-flagmode[aria-pressed="true"] svg {
  filter: none;
}

.ms-flagmode:active {
  transform: scale(0.95);
}

/* ---------- Stage & board ---------- */
.ms-stage {
  position: relative;
  display: flex;
  justify-content: center;
  min-height: 300px;
}

.ms-board-wrap {
  max-width: 100%;
  overflow: auto;
  padding: 10px;
  border-radius: 22px;
  background:
    radial-gradient(
      120% 80% at 50% 0%,
      rgba(104, 66, 255, 0.22),
      transparent 70%
    ),
    linear-gradient(180deg, #232438, #191a27);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 14px 34px rgba(0, 0, 0, 0.45);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

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

.ms-board.shake {
  animation: ms-shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 0;
  border-radius: calc(var(--cell) * 0.24);
  background: linear-gradient(180deg, #6a6fd0 0%, #5156b4 52%, #464a9e 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.32),
    inset 0 -3px 0 rgba(20, 16, 70, 0.45),
    0 2px 3px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * 0.6);
  font-weight: 900;
  line-height: 1;
  transition:
    filter 0.12s,
    transform 0.08s;
}

.cell.alt {
  background: linear-gradient(180deg, #6368c8 0%, #4a4fab 52%, #404494 100%);
}

.cell:focus-visible {
  outline: 3px solid #ffd43b;
  outline-offset: 1px;
  z-index: 2;
}

@media (hover: hover) {
  .cell:not(.revealed):hover {
    filter: brightness(1.14);
  }
}

.cell.pressed:not(.revealed):not(.flagged) {
  transform: scale(0.9);
  filter: brightness(0.85);
}

.cell.revealed {
  cursor: default;
  background: linear-gradient(180deg, #151624, #1b1c2d);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.6),
    inset 0 -1px 0 rgba(255, 255, 255, 0.04);
}

.cell.revealed.num {
  cursor: pointer;
}

.cell svg {
  width: 78%;
  height: 78%;
  pointer-events: none;
}

.cell.flagged svg {
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.cell.flag-pop svg {
  animation: ms-flag 0.32s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.n1 {
  color: #5eb0ff;
}
.n2 {
  color: #52dc86;
}
.n3 {
  color: #ff6275;
}
.n4 {
  color: #b995ff;
}
.n5 {
  color: #ffa94d;
}
.n6 {
  color: #3fe3d2;
}
.n7 {
  color: #ff85dc;
}
.n8 {
  color: #d4d6ea;
}

.cell.num {
  text-shadow:
    0 0 10px currentColor,
    0 1px 0 rgba(0, 0, 0, 0.5);
}

.cell.anim {
  animation: ms-pop 0.3s cubic-bezier(0.25, 1.4, 0.5, 1) backwards;
  animation-delay: var(--d, 0ms);
}

.cell.mine {
  background: radial-gradient(
    circle at 50% 50%,
    #6b4a86 0%,
    #3b2c55 55%,
    #2a2340 100%
  );
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45);
}

.cell.mine svg,
.cell.flagged svg,
.cell.wrong svg {
  width: 86%;
  height: 86%;
}

.cell.mine.anim {
  animation-name: ms-mine;
}

.cell.exploded {
  background: radial-gradient(
    circle at 50% 45%,
    #ffb35c 0%,
    #ff3d5a 45%,
    #9e1236 100%
  );
  box-shadow:
    0 0 18px rgba(255, 70, 90, 0.8),
    inset 0 2px 0 rgba(255, 255, 255, 0.3);
  z-index: 1;
}

.cell.wrong::after {
  content: "";
  position: absolute;
  inset: 12%;
  background:
    linear-gradient(
      45deg,
      transparent 43%,
      #ff3d5a 43%,
      #ff3d5a 57%,
      transparent 57%
    ),
    linear-gradient(
      -45deg,
      transparent 43%,
      #ff3d5a 43%,
      #ff3d5a 57%,
      transparent 57%
    );
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.6));
}

.cell.wrong {
  background: linear-gradient(180deg, #3b3d62, #2c2e4c);
}

.cell.won-glow {
  animation: ms-glow 0.6s ease-out backwards;
  animation-delay: var(--d, 0ms);
}

/* ---------- Overlay ---------- */
.ms-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: 22px;
  background: radial-gradient(
    ellipse 60% 70% at 50% 50%,
    rgba(10, 10, 24, 0.7),
    rgba(10, 10, 24, 0.25) 100%
  );
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.2s;
}

.ms-overlay[hidden] {
  display: none;
}

.ms-card {
  width: min(400px, 100%);
  padding: 20px 20px 18px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(180deg, #2a2b44, #1c1d2d);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 20px 50px rgba(0, 0, 0, 0.55);
  animation: ms-card-in 0.35s cubic-bezier(0.25, 1.4, 0.5, 1);
}

.ms-card-art {
  width: 74px;
  height: 74px;
  margin: -52px auto 4px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #8467ff, #5a35f0);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 10px 24px rgba(104, 66, 255, 0.5);
  transform: rotate(-6deg);
}

.ms-card-art svg {
  width: 52px;
  height: 52px;
}

.ms-card-art.lost {
  background: linear-gradient(180deg, #ff6f7f, #d61f4a);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 10px 24px rgba(255, 61, 90, 0.45);
}

.ms-card-art.won {
  background: linear-gradient(180deg, #5be08f, #1ea65a);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 10px 24px rgba(40, 200, 110, 0.45);
}

.ms-card h2 {
  margin: 6px 0 4px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.ms-card p {
  margin: 0 auto 14px;
  max-width: 32ch;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}

.ms-ov-stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}

.ms-ov-stats[hidden] {
  display: none;
}

.ms-ov-stat {
  min-width: 96px;
  padding: 8px 12px;
  border-radius: 16px;
  background: #11121e;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.ms-ov-stat span {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.ms-ov-stat strong {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.ms-ov-stat.record strong {
  color: #ffd43b;
}

.ms-badge {
  display: inline-block;
  margin: -6px 0 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, #fab005);
  color: #3b2a00;
  font-size: 13px;
  font-weight: 900;
  animation: ms-bob 1.6s ease-in-out infinite;
}

.ms-ov-diff {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.ms-ov-diff[hidden] {
  display: none;
}

.ms-pick {
  min-height: 60px;
  padding: 8px 4px;
  border: 2px solid transparent;
  border-radius: 16px;
  background: var(--secondary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition:
    transform 0.1s,
    border-color 0.15s;
}

.ms-pick strong {
  font-size: 14px;
  font-weight: 900;
}

.ms-pick span {
  font-size: 11px;
  color: var(--muted);
}

.ms-pick[aria-pressed="true"] {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, #3a2f7a, #2a2463);
  box-shadow: 0 4px 14px rgba(104, 66, 255, 0.35);
}

.ms-pick:active {
  transform: scale(0.96);
}

.ms-ov-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ms-btn {
  min-height: 48px;
  min-width: 128px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.1s;
}

.ms-btn[hidden] {
  display: none;
}

.ms-btn-primary {
  min-width: 170px;
  background: linear-gradient(180deg, #8467ff, #5a35f0);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    inset 0 -4px 0 rgba(40, 10, 140, 0.45),
    0 8px 20px rgba(104, 66, 255, 0.5);
  font-size: 20px;
}

.ms-btn:active {
  transform: translateY(2px) scale(0.97);
}

/* ---------- FX ---------- */
.ms-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 6;
}

.ms-confetti {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 3px;
  animation: ms-fall var(--t, 1.6s) cubic-bezier(0.3, 0.6, 0.6, 1) forwards;
  animation-delay: var(--delay, 0s);
}

.ms-spark {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  animation: ms-spark 0.6s ease-out forwards;
}

/* ---------- Help ---------- */
.ms-help {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 14px;
}

.ms-help-touch {
  display: none;
}

@media (pointer: coarse) {
  .ms-help-pointer {
    display: none;
  }
  .ms-help-touch {
    display: inline;
  }
}

kbd {
  display: inline-block;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.35);
  font-family: inherit;
  font-size: 12px;
  color: #fff;
}

/* ---------- Keyframes ---------- */
@keyframes ms-pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes ms-mine {
  0% {
    transform: scale(0.2) rotate(-40deg);
    opacity: 0;
  }
  70% {
    transform: scale(1.2) rotate(8deg);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

@keyframes ms-flag {
  0% {
    transform: translateY(-40%) scale(0.4);
  }
  100% {
    transform: none;
  }
}

@keyframes ms-glow {
  0% {
    filter: brightness(1);
  }
  40% {
    filter: brightness(1.8);
    transform: scale(1.08);
  }
  100% {
    filter: brightness(1);
    transform: none;
  }
}

@keyframes ms-shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-7px);
  }
  40%,
  60% {
    transform: translateX(7px);
  }
}

@keyframes ms-bob {
  0%,
  100% {
    transform: translateY(0) rotate(0);
  }
  50% {
    transform: translateY(-3px) rotate(-4deg);
  }
}

@keyframes ms-card-in {
  0% {
    transform: translateY(16px) scale(0.92);
    opacity: 0;
  }
  100% {
    transform: none;
    opacity: 1;
  }
}

@keyframes ms-fall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--dx, 0), 110vh, 0) rotate(var(--rot, 540deg));
    opacity: 0.9;
  }
}

@keyframes ms-spark {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(0.2);
    opacity: 0;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .ms-long {
    display: none;
  }
  .ms-short {
    display: inline;
  }
}

@media (max-width: 640px) {
  .ms-shell {
    padding: 8px 8px 10px;
    gap: 8px;
  }
  .ms-hud {
    display: grid;
    grid-template-columns: 1fr auto;
    padding: 8px;
    border-radius: 18px;
  }
  .ms-brand {
    font-size: 17px;
  }
  .ms-brand-icon {
    width: 26px;
    height: 26px;
  }
  .ms-diff {
    justify-self: end;
  }
  .ms-diff-btn {
    padding: 0 10px;
    font-size: 13px;
  }
  .ms-stats {
    grid-column: 1 / -1;
    justify-content: space-between;
  }
  .ms-stats .ms-chip {
    flex: 1;
    justify-content: center;
  }
  .ms-tools {
    grid-column: 1 / -1;
    justify-content: space-between;
  }
  .ms-flagmode {
    flex: 1;
    justify-content: center;
    min-height: 44px;
  }
  .ms-board-wrap {
    padding: 8px;
    border-radius: 18px;
  }
  .ms-help-keys {
    display: none;
  }
  .ms-card h2 {
    font-size: 26px;
  }
}

@media (max-width: 440px) {
  .ms-hud > * {
    min-width: 0;
  }
  .ms-diff {
    grid-column: 1 / -1;
    justify-self: stretch;
  }
  .ms-diff-btn {
    flex: 1;
  }
}

@media (max-width: 360px) {
  .ms-brand span {
    font-size: 15px;
  }
  .ms-diff-btn {
    padding: 0 8px;
    font-size: 12px;
  }
  .ms-pick strong {
    font-size: 12px;
  }
}

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