:root {
  color-scheme: light;
  --bg: #eef3f0;
  --panel: #ffffff;
  --ink: #18211f;
  --muted: #697570;
  --line: #d8e0dc;
  --accent: #127b66;
  --warm: #f0b84d;
  --bad: #d84a42;
  --ok: #4a9d72;
  --tile: #f9fbfa;
  --tile-hit: #d7ede5;
  --shadow: rgba(22, 45, 38, 0.14);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(18, 123, 102, 0.12), transparent 32%),
    linear-gradient(225deg, rgba(240, 184, 77, 0.14), transparent 28%),
    var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  padding: 18px;
  user-select: none;
}

button,
a {
  font: inherit;
}

.page {
  width: min(760px, 100%);
  min-height: calc(100vh - 36px);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.back-link {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: clamp(25px, 7vw, 40px);
  line-height: 1.1;
  letter-spacing: 0;
}

.intro,
.status {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

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

.stat,
.game-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 18px 45px var(--shadow);
}

.stat {
  min-height: 70px;
  padding: 10px;
  display: grid;
  align-content: center;
  gap: 4px;
}

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

.stat strong {
  font-size: 21px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.game-card {
  padding: clamp(14px, 4vw, 24px);
  display: grid;
  gap: 16px;
}

.game-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.target {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.target-number {
  min-width: 38px;
  min-height: 38px;
  border-radius: 50%;
  background: var(--warm);
  color: #241a09;
  display: inline-grid;
  place-items: center;
  font-size: 19px;
}

.board-wrap {
  display: grid;
  place-items: center;
}

.board {
  width: min(100%, 560px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  gap: clamp(7px, 1.4vw, 12px);
}

.cell {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(22, 45, 38, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  font-size: clamp(24px, calc(72px / var(--size) + 2vw), 70px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, opacity 120ms ease;
}

.cell:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(22, 45, 38, 0.12);
}

.cell.hit {
  background: var(--tile-hit);
  color: var(--accent);
  opacity: 0.54;
  transform: scale(0.96);
  cursor: default;
}

.cell.wrong {
  animation: shake 220ms ease;
  border-color: rgba(216, 74, 66, 0.8);
  background: #fff4f2;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.control-btn {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.control-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.status {
  min-height: 44px;
  border-left: 4px solid var(--accent);
  background: #f3f8f6;
  border-radius: 6px;
  padding: 10px 12px;
}

.status.error {
  border-left-color: var(--bad);
  color: #84312c;
  background: #fff2f0;
}

.status.done {
  border-left-color: var(--ok);
  color: #276345;
  background: #eef9f2;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(24, 33, 31, 0.42);
}

.dialog-backdrop.show {
  display: grid;
}

.result-dialog {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(22, 45, 38, 0.24);
  padding: 20px;
  display: grid;
  gap: 14px;
}

.result-lines {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.result-lines strong {
  color: var(--ink);
}

@keyframes shake {
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

@media (max-width: 560px) {
  .topbar,
  .game-head {
    align-items: flex-start;
    flex-direction: column;
  }

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