:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #647089;
  --line: #d9e1ec;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --gold: #d99a1b;
  --shadow: 0 16px 40px rgba(23, 32, 51, 0.12);
  --board: #243447;
  --gap: 12px;
  --tile-size: calc((100% - var(--gap) * 3) / 4);
}

* {
  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: #172033;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 80;
}

.brand {
  font-size: 20px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.desktop-nav {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

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

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

.header-download,
.mobile-menu {
  display: none;
}

main {
  padding: 28px 18px 0;
}

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

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

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

.mode-btn,
.control-bar button,
.mini-board button,
.result-card button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  transition:
    border-color 0.18s,
    background 0.18s,
    color 0.18s;
}

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

.mode-btn.active,
.control-bar button:first-child,
.result-actions button:first-child {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.mode-btn:hover,
.mode-btn:focus-visible,
.control-bar button:hover,
.control-bar button:focus-visible,
.mini-board button:hover,
.mini-board button:focus-visible,
.result-card button:hover,
.result-card button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.control-bar button:disabled {
  cursor: not-allowed;
  color: #97a3b6;
  background: #eef2f7;
  border-color: var(--line);
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(74px, 1fr));
  gap: 8px;
}

.score-grid div {
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  background: #101828;
  color: #fff;
}

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

.score-grid strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 20px;
  line-height: 1;
  color: #f4c95d;
  white-space: nowrap;
}

.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: 42px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #f4d792;
  color: #6b4405;
  font-size: 13px;
  font-weight: 900;
}

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

.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;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) 260px;
  gap: 18px;
  align-items: start;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(37, 99, 235, 0.055) 1px, transparent 1px),
    linear-gradient(rgba(37, 99, 235, 0.055) 1px, transparent 1px), #edf2f8;
  background-size: 18px 18px;
}

.board-panel,
.side-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.board-panel {
  position: relative;
  display: grid;
  place-items: center;
  padding: 14px;
  overflow: hidden;
}

.game-board {
  position: relative;
  width: min(520px, 100%);
  aspect-ratio: 1;
  padding: var(--gap);
  border-radius: 8px;
  background: var(--board);
  cursor: grab;
  outline: none;
  touch-action: none;
  user-select: none;
}

.game-board.dragging {
  cursor: grabbing;
}

.game-board:focus-visible {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.28);
}

.grid-cells,
.tile-layer {
  position: absolute;
  inset: var(--gap);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
}

.grid-cell {
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.16);
}

.tile-layer {
  pointer-events: none;
}

.tile {
  position: absolute;
  left: calc(var(--x) * (var(--tile-size) + var(--gap)));
  top: calc(var(--y) * (var(--tile-size) + var(--gap)));
  width: var(--tile-size);
  height: var(--tile-size);
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #fff;
  font-size: clamp(24px, 7vw, 46px);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(2, 6, 23, 0.16);
  transition:
    left 0.12s ease,
    top 0.12s ease,
    transform 0.12s ease;
}

.tile-2 {
  background: #3b82f6;
}
.tile-4 {
  background: #14b8a6;
}
.tile-8 {
  background: #f59e0b;
}
.tile-16 {
  background: #ef6c35;
}
.tile-32 {
  background: #ef4444;
}
.tile-64 {
  background: #c026d3;
}
.tile-128 {
  background: #7c3aed;
  font-size: clamp(22px, 6vw, 42px);
}
.tile-256 {
  background: #2563eb;
  font-size: clamp(22px, 6vw, 42px);
}
.tile-512 {
  background: #0f766e;
  font-size: clamp(22px, 6vw, 42px);
}
.tile-1024 {
  background: #b45309;
  font-size: clamp(18px, 5vw, 34px);
}
.tile-2048 {
  background: #be123c;
  font-size: clamp(18px, 5vw, 34px);
}
.tile-4096 {
  background: #334155;
  font-size: clamp(18px, 5vw, 34px);
}
.tile-8192 {
  background: #111827;
  font-size: clamp(18px, 5vw, 34px);
}
.tile-16384,
.tile-super {
  background: #020617;
  font-size: clamp(15px, 4.4vw, 28px);
}

.result-overlay {
  position: absolute;
  inset: 14px;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: 8px;
  background: rgba(16, 24, 40, 0.62);
  z-index: 20;
}

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

.result-card {
  width: min(320px, 100%);
  display: grid;
  gap: 10px;
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.result-card strong {
  font-size: 24px;
  line-height: 1.2;
}

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

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.result-card button {
  width: 100%;
}

.side-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.status-card {
  min-height: 74px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.status-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-card strong {
  overflow-wrap: anywhere;
  font-size: 17px;
  line-height: 1.3;
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mini-board button {
  min-height: 48px;
}

.mini-board button:first-child {
  grid-column: 2;
}

.mini-board button:nth-child(2) {
  grid-column: 1;
}

.mini-board button:nth-child(3) {
  grid-column: 2;
}

.mini-board button:nth-child(4) {
  grid-column: 3;
  grid-row: 2;
}

.control-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.control-bar button {
  width: 100%;
  padding: 0 10px;
}

.control-bar button:first-child {
  grid-column: 1 / -1;
}

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

.content-page article {
  margin-bottom: 18px;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

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

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

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

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

.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: #1f7a5c;
}

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

.game-card-icon.mine {
  background: #0f8b8d;
}

.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;
  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);
  font-weight: 800;
  text-decoration: none;
}

@media (max-width: 900px) {
  .game-top,
  .play-area {
    grid-template-columns: 1fr;
  }

  .score-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-bar {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-bar button:first-child {
    grid-column: auto;
  }

  .mini-board {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  :root {
    --gap: 8px;
  }

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

  .brand {
    font-size: 17px;
  }

  .desktop-nav {
    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;
  }

  .mobile-menu {
    display: block;
    position: relative;
  }

  .mobile-menu summary {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    gap: 4px;
    padding: 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    list-style: none;
  }

  .mobile-menu summary::-webkit-details-marker {
    display: none;
  }

  .mobile-menu span {
    width: 18px;
    height: 2px;
    display: block;
    border-radius: 2px;
    background: #fff;
  }

  .mobile-menu nav {
    position: fixed;
    top: 48px;
    right: 8px;
    z-index: 20;
    width: min(220px, calc(100vw - 16px));
    display: grid;
    gap: 4px;
    padding: 10px;
    border-radius: 8px;
    background: #172033;
    box-shadow: var(--shadow);
  }

  .mobile-menu:not([open]) nav {
    display: none;
  }

  .mobile-menu nav a {
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-radius: 6px;
    color: #fff;
    text-decoration: none;
  }

  main {
    padding: 8px 8px 0;
  }

  .game-top {
    gap: 10px;
    padding: 10px;
  }

  .mode-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

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

  .score-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .score-grid div {
    min-height: 42px;
    padding: 3px 4px;
  }

  .score-grid span {
    font-size: 11px;
  }

  .score-grid strong {
    font-size: 16px;
  }

  .client-notice {
    display: none;
  }

  .play-area {
    gap: 8px;
    padding: 8px;
  }

  .board-panel {
    padding: 8px;
  }

  .result-overlay {
    inset: 8px;
    padding: 14px;
  }

  .result-card {
    padding: 18px;
  }

  .result-card strong {
    font-size: 22px;
  }

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

  .status-card {
    min-height: 54px;
    padding: 8px;
  }

  .status-card span {
    font-size: 12px;
  }

  .status-card strong {
    font-size: 14px;
  }

  .mini-board {
    display: none;
  }

  .control-bar {
    gap: 8px;
  }

  .control-bar button {
    min-height: 38px;
    font-size: 14px;
  }

  .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 strong {
    font-size: 17px;
  }

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