:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #657086;
  --line: #d9e0ea;
  --accent: #0f8b8d;
  --accent-dark: #0b5f60;
  --gold: #d99a1b;
  --danger: #c2413b;
  --tile: #d8dee8;
  --tile-top: #f7f9fc;
  --tile-open: #eef2f7;
  --shadow: 0 16px 40px rgba(22, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial,
    sans-serif;
  line-height: 1.6;
  letter-spacing: 0;
  overscroll-behavior-y: contain;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.site-header {
  height: 60px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 0 28px;
  background: #1d2433;
  color: #fff;
  overflow: hidden;
  position: sticky;
  top: 0;
  z-index: 80;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 800;
  font-size: 20px;
  text-decoration: none;
  white-space: nowrap;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.top-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  border-radius: 6px;
}

.top-nav a:hover,
.top-nav a:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.header-download {
  display: none;
}

.menu-toggle,
.menu-backdrop {
  display: none;
}

main {
  padding: 28px 18px 0;
}

.game-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.game-toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 18px;
  padding: 18px;
  background: #f9fbfe;
  border-bottom: 1px solid var(--line);
}

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-btn,
.action-btn,
.custom-panel button,
.dialog-actions button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition:
    background 0.18s,
    border-color 0.18s,
    color 0.18s,
    transform 0.18s;
}

.mode-btn {
  padding: 0 16px;
  font-weight: 700;
}

.mode-btn:hover,
.action-btn:hover,
.mode-btn:focus-visible,
.action-btn:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.mode-btn.active,
.action-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.play-tools {
  display: grid;
  grid-template-columns: auto auto;
  gap: 8px;
  align-items: center;
}

.action-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(58px, 1fr));
  gap: 6px;
}

.action-btn {
  min-width: 58px;
  padding: 0 12px;
  font-weight: 800;
}

.score-strip {
  display: grid;
  grid-template-columns: 84px 48px 84px;
  gap: 10px;
  align-items: center;
}

.score-item {
  min-width: 0;
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 1px solid #ccd4df;
  border-radius: 6px;
  background: #111827;
  color: #fff;
}

.score-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.62);
}

.score-item strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 22px;
  line-height: 1;
  color: #f14f45;
}

.reset-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid #ccd4df;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 24px;
}

.reset-btn:hover,
.reset-btn:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.custom-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr)) auto;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.custom-panel[hidden] {
  display: none;
}

.custom-panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.custom-panel input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
}

.custom-panel input:focus {
  border-color: var(--accent);
  outline: none;
}

.custom-panel button {
  align-self: end;
  padding: 0 20px;
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.client-notice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: #fff7e6;
  border-bottom: 1px solid #f1d39b;
  color: #68430d;
}

.client-notice.hidden {
  display: none;
}

.client-notice-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #f4d792;
  color: #6b4405;
  font-size: 18px;
  font-weight: 900;
}

.client-notice p {
  margin: 0;
  display: grid;
  gap: 2px;
  min-width: 0;
}

.client-notice strong {
  line-height: 1.25;
}

.client-notice span {
  color: #7a5a25;
  font-size: 14px;
}

.client-notice a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border-radius: 6px;
  background: var(--gold);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.client-notice-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: rgba(104, 67, 13, 0.1);
  color: #68430d;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.board-wrap {
  overflow: auto;
  padding: 22px;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(90deg, rgba(15, 139, 141, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(15, 139, 141, 0.06) 1px, transparent 1px), #edf2f8;
  background-size: 18px 18px;
}

.board-frame {
  width: max-content;
  margin: 0 auto;
  padding: 12px;
  background: #b9c2cf;
  border: 1px solid #8e9aaa;
  border-radius: 6px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    inset 0 -2px 0 rgba(37, 45, 59, 0.2);
}

.board {
  --cell-size: 34px;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-auto-rows: var(--cell-size);
  gap: 2px;
  touch-action: manipulation;
  user-select: none;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: linear-gradient(145deg, var(--tile-top), var(--tile));
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(12px, calc(var(--cell-size) * 0.52), 18px);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.86),
    inset -2px -2px 0 rgba(75, 85, 99, 0.26);
}

.cell:hover,
.cell:focus-visible {
  filter: brightness(1.04);
  outline: 2px solid rgba(15, 139, 141, 0.42);
  outline-offset: -2px;
}

.cell.revealed {
  background: var(--tile-open);
  box-shadow: inset 0 0 0 1px rgba(134, 146, 164, 0.55);
  cursor: default;
}

.cell.flagged {
  color: var(--danger);
}

.cell.exploded {
  background: #f7c7c4;
  color: #7f1d1d;
}

.cell.mine {
  color: #111827;
}

.cell[data-number="1"] {
  color: #2563eb;
}
.cell[data-number="2"] {
  color: #16803c;
}
.cell[data-number="3"] {
  color: #dc2626;
}
.cell[data-number="4"] {
  color: #4c1d95;
}
.cell[data-number="5"] {
  color: #a14416;
}
.cell[data-number="6"] {
  color: #087b83;
}
.cell[data-number="7"] {
  color: #111827;
}
.cell[data-number="8"] {
  color: #6b7280;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: #fff;
}

.status-row p {
  margin: 0;
}

#bestText {
  font-weight: 700;
  color: var(--accent-dark);
  text-align: right;
}

.content-page article,
.result-dialog {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.content-page h1,
.content-page h2,
.result-dialog h2 {
  margin: 0 0 10px;
  line-height: 1.25;
}

.content-page p,
.content-page li {
  color: var(--muted);
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 24, 39, 0.55);
  z-index: 20;
}

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

.result-dialog {
  width: min(420px, 100%);
  padding: 26px;
  box-shadow: var(--shadow);
}

.result-dialog p {
  margin: 0 0 20px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.dialog-actions button {
  padding: 0 18px;
}

.dialog-actions button:first-child {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.content-page {
  width: min(980px, 100%);
  margin: 28px auto 0;
  padding: 0 18px;
}

.content-page article {
  padding: 28px;
  margin-bottom: 18px;
}

.content-page h1 {
  font-size: 32px;
}

.content-page h2 {
  font-size: 23px;
  margin-top: 24px;
}

.content-page ul,
.content-page ol {
  padding-left: 22px;
}

.content-page a {
  color: var(--accent-dark);
  font-weight: 700;
}

.game-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.game-card {
  min-height: 78px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  text-decoration: none;
}

.game-card:hover,
.game-card:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.game-card-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
}

.game-card-icon.snake,
.game-card-icon.spider {
  background: #16a34a;
}

.game-card-icon.gomoku,
.game-card-icon.block {
  background: #172033;
}

.game-card-icon.tile {
  background: #2563eb;
  font-size: 13px;
}

.game-card strong {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.2;
}

.game-card-icon.jump {
  background: #d93a2f;
}

.game-card-icon.sudoku {
  background: #2f6f9f;
}

.site-footer {
  margin-top: 34px;
  padding: 22px 18px;
  background: transparent;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--line);
}

.site-footer p {
  margin: 6px 0;
}

.site-footer a {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 700;
}

.site-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 900px) {
  .game-toolbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .score-strip {
    justify-self: stretch;
    grid-template-columns: 1fr 52px 1fr;
  }

  .action-toggle {
    grid-template-columns: repeat(2, 1fr);
  }

  .play-tools {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body.menu-open {
    overflow: hidden;
  }

  .site-header {
    height: 48px;
    grid-template-columns: minmax(0, 1fr) auto 40px;
    gap: 6px;
    padding: 0 8px;
    overflow: visible;
  }

  .brand {
    gap: 7px;
    font-size: 17px;
  }

  .top-nav {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 30;
    width: min(78vw, 280px);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    padding: 64px 14px 18px;
    background: #1d2433;
    box-shadow: -18px 0 36px rgba(17, 24, 39, 0.28);
    transform: translateX(100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
    white-space: normal;
  }

  .top-nav a {
    min-height: 44px;
    justify-content: flex-start;
    padding: 0 12px;
    font-size: 15px;
    border-radius: 6px;
    color: #fff;
  }

  .top-nav .nav-download {
    display: none;
  }

  .header-download {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border-radius: 6px;
    background: #fff7e6;
    color: #68430d;
    border: 1px solid #e5c16b;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
  }

  .menu-open .top-nav {
    transform: translateX(0);
  }

  .menu-toggle {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    gap: 4px;
    padding: 10px;
    border: 0;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    z-index: 40;
  }

  .menu-toggle span {
    width: 18px;
    height: 2px;
    display: block;
    background: #fff;
    border-radius: 2px;
    transition:
      transform 0.18s,
      opacity 0.18s;
  }

  .menu-toggle.active span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  .menu-toggle.active span:nth-child(2) {
    opacity: 0;
  }

  .menu-toggle.active span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    border: 0;
    background: rgba(15, 23, 42, 0.42);
  }

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

  main {
    padding: 8px 8px 0;
  }

  .game-toolbar,
  .custom-panel,
  .status-row {
    padding: 10px;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .mode-btn {
    min-height: 34px;
    padding: 0 4px;
    font-size: 13px;
  }

  .score-strip {
    grid-template-columns: 1fr 44px 1fr;
    gap: 6px;
  }

  .score-item {
    min-height: 44px;
  }

  .score-label {
    font-size: 11px;
  }

  .score-item strong {
    font-size: 20px;
  }

  .reset-btn {
    width: 44px;
    height: 44px;
  }

  .action-btn {
    min-height: 36px;
  }

  .client-notice {
    display: none;
  }

  .custom-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .custom-panel label {
    font-size: 12px;
  }

  .custom-panel input {
    height: 36px;
    padding: 0 8px;
  }

  .custom-panel button {
    grid-column: 1 / -1;
    align-self: stretch;
  }

  .board-wrap {
    padding: 8px;
  }

  .board-frame {
    padding: 6px;
  }

  .cell {
    border-radius: 3px;
  }

  .status-row {
    display: grid;
    gap: 6px;
    font-size: 13px;
  }

  #bestText {
    text-align: left;
  }

  .content-page {
    margin-top: 14px;
    padding: 0 10px;
  }

  .content-page article {
    padding: 20px;
  }

  .game-card-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .game-card {
    min-height: 64px;
    padding: 10px;
  }

  .game-card-icon {
    width: 38px;
    height: 38px;
    font-size: 17px;
  }

  .game-card-icon.tile {
    font-size: 12px;
  }

  .game-card strong {
    font-size: 17px;
  }

  .site-footer {
    margin-top: 20px;
    padding: 18px 12px;
    font-size: 13px;
  }
}
