:root {
  color-scheme: light;
  --bg: #f1f0f6;
  --ink: #202720;
  --muted: #62636e;
  --panel: #fffdf8;
  --line: rgba(32, 39, 32, 0.12);
  --accent: #7b5aa6;
  --accent-dark: #63458a;
  --good: #2f7f73;
  --bad: #c64c3e;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(123, 90, 166, 0.18), transparent 32%),
    linear-gradient(315deg, rgba(198, 76, 62, 0.14), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button {
  height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

.game-shell {
  width: min(100%, 680px);
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin-bottom: 12px;
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(40px, 9vw, 64px);
  line-height: 1;
  letter-spacing: 0;
}

.game-header p {
  margin-top: 10px;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(82px, 1fr));
  gap: 10px;
}

.stats div {
  padding: 12px;
  border-radius: 8px;
  background: #fffdf8;
  border: 1px solid var(--line);
  text-align: center;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  line-height: 1;
}

.actions {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.board-wrap {
  position: relative;
}

.board {
  width: min(100vw - 44px, 680px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: clamp(5px, 1.4vw, 9px);
  padding: clamp(8px, 2vw, 12px);
  border-radius: 8px;
  background: rgba(32, 39, 32, 0.15);
  user-select: none;
}

.tile {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #fffdf8;
  color: #202720;
  font-size: clamp(22px, 6vw, 38px);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, opacity 150ms ease;
}

.tile:hover {
  transform: translateY(-1px);
}

.tile.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(123, 90, 166, 0.18);
}

.tile.matched {
  opacity: 0;
  pointer-events: none;
}

.line-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.link-line {
  fill: none;
  stroke: var(--good);
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: 8px;
  background: rgba(241, 240, 246, 0.82);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(100%, 280px);
  padding: 22px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(32, 39, 32, 0.18);
  text-align: center;
}

.panel p {
  margin: 8px 0 16px;
  color: var(--muted);
}

.panel button {
  width: 100%;
}

.message {
  min-height: 24px;
  margin-top: 12px;
  color: var(--muted);
  text-align: center;
}

.message.good {
  color: var(--good);
}

.message.bad {
  color: var(--bad);
}

@media (max-width: 560px) {
  body {
    align-items: start;
    padding: 16px;
  }

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

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

  .board {
    width: calc(100vw - 32px);
  }
}
