:root {
  color-scheme: dark;
  --bg: #070b12;
  --bg-soft: #101827;
  --panel: rgba(14, 23, 38, 0.78);
  --panel-strong: rgba(20, 31, 50, 0.94);
  --line: rgba(148, 163, 184, 0.18);
  --line-strong: rgba(148, 163, 184, 0.34);
  --text: #e5edf8;
  --muted: #8fa2bb;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --cell-size: 36px;
  --radius-lg: 28px;
  --radius-md: 18px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.46);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(14, 165, 233, 0.24), transparent 34rem),
    radial-gradient(circle at 80% 10%, rgba(52, 211, 153, 0.14), transparent 30rem),
    var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(15, 23, 42, 0.86), rgba(2, 6, 23, 0.92)),
    repeating-linear-gradient(90deg, rgba(148, 163, 184, 0.035) 0 1px, transparent 1px 96px);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 20px;
  align-items: stretch;
  margin-bottom: 22px;
}

.hero-copy,
.hero-card,
.glass-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.hero-copy {
  min-height: 188px;
  padding: 34px;
  border-radius: var(--radius-lg);
}

.hero-copy h1 {
  margin: 8px 0 12px;
  font-size: clamp(2.5rem, 6vw, 5.5rem);
  line-height: 0.9;
  letter-spacing: -0.08em;
}

.hero-copy p:last-child {
  max-width: 780px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.hero-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 26px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(155deg, rgba(56, 189, 248, 0.22), rgba(15, 23, 42, 0.76)),
    var(--panel);
}

.hero-card span,
.hero-card small,
.eyebrow,
.hud span,
.result-stats span,
.score-form label {
  color: var(--muted);
  letter-spacing: 0.08em;
}

.hero-card strong {
  font-size: 2.2rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 22px;
  align-items: start;
}

.glass-panel {
  border-radius: var(--radius-lg);
}

.game-panel,
.leaderboard-panel {
  padding: 22px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-heading h2 {
  margin: 3px 0 0;
  font-size: 1.45rem;
}

.status-pill {
  min-width: 96px;
  padding: 9px 14px;
  border: 1px solid rgba(56, 189, 248, 0.34);
  border-radius: 999px;
  color: #bae6fd;
  background: rgba(14, 165, 233, 0.12);
  text-align: center;
  font-weight: 800;
}

.status-pill.is-win {
  border-color: rgba(52, 211, 153, 0.45);
  color: #bbf7d0;
  background: rgba(52, 211, 153, 0.13);
}

.status-pill.is-loss {
  border-color: rgba(251, 113, 133, 0.45);
  color: #fecdd3;
  background: rgba(251, 113, 133, 0.13);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.mode-card,
.tool-button,
.secondary-button,
.primary-button,
.leaderboard-tab,
.icon-button,
.modal-close {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.72);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.mode-card {
  display: flex;
  min-height: 82px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 7px;
  padding: 16px;
  text-align: left;
}

.mode-card strong {
  font-size: 1.05rem;
}

.mode-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.mode-card:hover,
.tool-button:hover,
.secondary-button:hover,
.leaderboard-tab:hover,
.icon-button:hover,
.modal-close:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: rgba(30, 41, 59, 0.86);
}

.mode-card.is-active,
.tool-button.is-active,
.leaderboard-tab.is-active {
  border-color: rgba(56, 189, 248, 0.66);
  color: #e0f2fe;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.26), rgba(30, 41, 59, 0.82));
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.hud > div,
.result-stats > div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(2, 6, 23, 0.36);
}

.hud span,
.result-stats span {
  display: block;
  margin-bottom: 7px;
  font-size: 0.72rem;
}

.hud strong,
.result-stats strong {
  font-size: 1.25rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.tool-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(2, 6, 23, 0.34);
}

.tool-button {
  min-width: 92px;
  padding: 10px 14px;
  font-weight: 800;
}

.secondary-button,
.primary-button {
  min-height: 44px;
  padding: 10px 18px;
  font-weight: 900;
}

.primary-button {
  border-color: rgba(56, 189, 248, 0.58);
  color: #06111f;
  background: linear-gradient(135deg, #67e8f9, #38bdf8 58%, #0ea5e9);
}

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

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.board-shell {
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    radial-gradient(circle at 20% 0, rgba(56, 189, 248, 0.12), transparent 26rem),
    rgba(2, 6, 23, 0.38);
  padding: 14px;
}

.board-scroll {
  overflow: auto;
  padding-bottom: 4px;
  scrollbar-color: rgba(56, 189, 248, 0.48) rgba(15, 23, 42, 0.8);
}

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

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: grid;
  place-items: center;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 9px;
  color: #e0f2fe;
  background:
    linear-gradient(145deg, rgba(30, 41, 59, 0.96), rgba(15, 23, 42, 0.96)),
    #0f172a;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 10px rgba(0, 0, 0, 0.22);
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  font-weight: 950;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.cell:hover:not(:disabled) {
  border-color: rgba(56, 189, 248, 0.58);
  background:
    linear-gradient(145deg, rgba(51, 65, 85, 1), rgba(30, 41, 59, 0.98)),
    #1e293b;
}

.cell.is-revealed {
  border-color: rgba(148, 163, 184, 0.1);
  color: #dbeafe;
  background: rgba(15, 23, 42, 0.42);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
  cursor: default;
}

.cell.is-empty {
  color: transparent;
}

.cell.is-flagged {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.36);
}

.cell.is-mine {
  color: #fecdd3;
  border-color: rgba(251, 113, 133, 0.38);
  background: rgba(127, 29, 29, 0.52);
}

.cell.is-exploded {
  color: #fff1f2;
  border-color: rgba(251, 113, 133, 0.9);
  background: linear-gradient(135deg, #fb7185, #881337);
}

.cell.is-wrong {
  color: #fecdd3;
  border-color: rgba(251, 113, 133, 0.7);
}

.cell[data-number="1"] {
  color: #7dd3fc;
}

.cell[data-number="2"] {
  color: #86efac;
}

.cell[data-number="3"] {
  color: #fca5a5;
}

.cell[data-number="4"] {
  color: #c4b5fd;
}

.cell[data-number="5"] {
  color: #fcd34d;
}

.cell[data-number="6"] {
  color: #67e8f9;
}

.cell[data-number="7"] {
  color: #e2e8f0;
}

.cell[data-number="8"] {
  color: #94a3b8;
}

.leaderboard-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.leaderboard-tab {
  min-height: 40px;
  padding: 8px 10px;
  font-weight: 800;
}

.icon-button,
.modal-close {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}

.leaderboard-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(2, 6, 23, 0.32);
}

.leaderboard-rank {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 12px;
  color: #bae6fd;
  background: rgba(56, 189, 248, 0.12);
  font-weight: 950;
}

.leaderboard-player strong,
.leaderboard-player small {
  display: block;
}

.leaderboard-player strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-player small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.leaderboard-score {
  color: #e0f2fe;
  font-weight: 950;
  text-align: right;
}

.muted-state {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(14px);
  z-index: 20;
}

.modal-backdrop[hidden] {
  display: none;
}

.result-card {
  position: relative;
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  padding: 28px;
  background: var(--panel-strong);
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
}

.result-kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 950;
  letter-spacing: 0.16em;
}

.result-card h2 {
  margin: 0 46px 8px 0;
  font-size: clamp(2rem, 6vw, 3.2rem);
  line-height: 1;
}

.result-card > p {
  color: var(--muted);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0;
}

.score-form {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(2, 6, 23, 0.34);
}

.score-form[hidden] {
  display: none;
}

.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.score-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(15, 23, 42, 0.88);
  outline: none;
}

.score-form input:focus {
  border-color: rgba(56, 189, 248, 0.66);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.12);
}

.score-form p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.score-form p.is-error {
  color: #fecdd3;
}

.score-form p.is-success {
  color: #bbf7d0;
}

.result-leaderboard {
  margin-top: 16px;
}

.result-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 1100px) {
  .hero,
  .layout {
    grid-template-columns: 1fr;
  }

  .hero-card {
    min-height: 132px;
  }
}

@media (max-width: 720px) {
  :root {
    --cell-size: 32px;
  }

  .app-shell {
    padding: 14px;
  }

  .hero-copy,
  .hero-card,
  .game-panel,
  .leaderboard-panel,
  .result-card {
    padding: 18px;
    border-radius: 22px;
  }

  .hero-copy {
    min-height: auto;
  }

  .mode-grid,
  .hud,
  .result-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar,
  .result-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .tool-toggle {
    width: 100%;
  }

  .secondary-button,
  .primary-button {
    width: 100%;
  }

  .score-row {
    grid-template-columns: 1fr;
  }

  .leaderboard-row {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .leaderboard-score {
    grid-column: 2;
    text-align: left;
  }
}

@media (max-width: 420px) {
  :root {
    --cell-size: 30px;
  }

  .mode-grid,
  .hud,
  .result-stats {
    grid-template-columns: 1fr;
  }
}
