:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --panel: #fbfaf6;
  --text: #1f2933;
  --muted: #667085;
  --line: #d7dce1;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d8f1ed;
  --tile: #ffffff;
  --tile-hover: #eef9f6;
  --tile-shadow: rgba(37, 47, 63, 0.16);
  --board: #243241;
  --win: rgba(15, 23, 42, 0.78);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: linear-gradient(135deg, #f7f2e9 0%, #eef5f5 52%, #f7f0e6 100%);
  color: var(--text);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.game-panel {
  width: min(100%, 560px);
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 3rem;
  line-height: 1;
  letter-spacing: 0;
}

.difficulty {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
}

.difficulty-btn,
.restart-btn {
  border: 0;
  cursor: pointer;
  transition:
    transform 150ms ease,
    background-color 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease;
}

.difficulty-btn {
  min-width: 66px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.difficulty-btn.is-active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.22);
}

.difficulty-btn:focus-visible,
.restart-btn:focus-visible,
.tile:focus-visible {
  outline: 3px solid rgba(14, 165, 156, 0.4);
  outline-offset: 3px;
}

.difficulty-btn:hover,
.restart-btn:hover,
.tile.can-move:hover {
  transform: translateY(-1px);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 52px;
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.stat span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
}

.restart-btn {
  width: 52px;
  min-height: 52px;
  border-radius: 8px;
  background: var(--accent-dark);
  color: #ffffff;
  box-shadow: 0 12px 24px rgba(17, 94, 89, 0.22);
}

.restart-btn span {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.board-wrap {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1;
}

.board {
  --size: 4;
  --gap: clamp(6px, 1.6vw, 10px);
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--gap);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent),
    var(--board);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    0 24px 70px rgba(31, 41, 51, 0.22);
}

.tile,
.empty-cell {
  min-width: 0;
  min-height: 0;
  border-radius: 8px;
}

.tile {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border: 0;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(235, 242, 243, 0.9)),
    var(--tile);
  color: var(--text);
  box-shadow:
    0 10px 18px var(--tile-shadow),
    inset 0 0 0 1px rgba(255, 255, 255, 0.82);
  cursor: default;
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  transition:
    transform 150ms ease,
    background-color 150ms ease,
    box-shadow 150ms ease;
}

.tile.can-move {
  cursor: pointer;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(216, 241, 237, 0.96)),
    var(--tile-hover);
}

.tile:disabled {
  color: var(--text);
  opacity: 1;
}

.empty-cell {
  background:
    linear-gradient(145deg, rgba(0, 0, 0, 0.12), transparent),
    rgba(15, 23, 42, 0.28);
  box-shadow: inset 0 6px 16px rgba(0, 0, 0, 0.18);
}

.win-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  border-radius: 8px;
  background: var(--win);
  backdrop-filter: blur(3px);
}

.win-layer[hidden] {
  display: none;
}

.win-message {
  width: min(100%, 300px);
  padding: 22px;
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.24);
}

.win-message strong {
  display: block;
  margin-bottom: 8px;
  font-size: 32px;
  line-height: 1.1;
}

.win-message span {
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 560px) {
  .game-shell {
    align-items: start;
    padding: 18px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .difficulty {
    width: 100%;
  }

  .difficulty-btn {
    flex: 1;
  }

  .stats {
    grid-template-columns: 1fr 1fr 48px;
  }

  .restart-btn {
    width: 48px;
    min-height: 48px;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 2.4rem;
  }

  .tile {
    font-size: 1.45rem;
  }
}
