:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  color: #1f2937;
  background: #edf2f7;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --board-gap: 7px;
  --tile-size: min(calc((100vw - 149px) / 8), 58px);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  padding: 28px 16px 36px;
  background: #edf2f7;
}

button { font: inherit; }

.game-shell {
  width: min(100%, 620px);
  margin: 0 auto;
}

.game-header { margin-bottom: 22px; text-align: center; }
.eyebrow {
  margin: 0 0 7px;
  color: #64748b;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}
h1 { margin: 0; font-size: clamp(1.8rem, 6vw, 2.5rem); letter-spacing: 0.02em; }
.subtitle { margin: 9px 0 0; color: #64748b; font-size: 0.98rem; }

.game-panel {
  padding: clamp(14px, 4vw, 24px);
  border: 1px solid #dce4ee;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 14px 36px rgb(30 54 82 / 9%);
}

.game-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.score-card { display: flex; align-items: baseline; gap: 10px; }
.score-label { color: #64748b; font-size: 0.9rem; font-weight: 700; }
.score-value { color: #172554; font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-divider { margin: 0 5px; color: #94a3b8; font-size: 1rem; font-weight: 500; }

.restart-button {
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 11px;
  color: #fff;
  background: #3157a4;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}
.restart-button:hover:not(:disabled) { background: #244581; }
.restart-button:active:not(:disabled) { transform: translateY(1px); }
.restart-button:disabled { cursor: wait; opacity: 0.55; }

.progress-track {
  height: 9px;
  margin: 13px 0 17px;
  overflow: hidden;
  border-radius: 99px;
  background: #e8edf4;
}
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: #38a77b; transition: width 180ms ease; }

.board-frame {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 9px;
  border: 1px solid #dbe4ef;
  border-radius: 17px;
  background: #f2f6fb;
}
.board {
  display: flex;
  flex-direction: column;
  gap: var(--board-gap);
  min-height: calc(var(--tile-size) * 8 + var(--board-gap) * 7);
  align-content: center;
  justify-content: center;
  align-items: center;
}
.board-row { display: grid; grid-template-columns: repeat(8, var(--tile-size)); gap: var(--board-gap); }
.loading-message { grid-column: 1 / -1; align-self: center; margin: 0; padding: 24px; color: #64748b; text-align: center; }

.tile {
  display: grid;
  width: var(--tile-size);
  height: var(--tile-size);
  place-items: center;
  padding: 0;
  border: 2px solid rgb(15 23 42 / 10%);
  border-radius: 13px;
  color: #fff;
  font-size: clamp(1.05rem, 4vw, 1.65rem);
  line-height: 1;
  text-shadow: 0 1px 2px rgb(0 0 0 / 20%);
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgb(15 23 42 / 12%), 0 2px 4px rgb(15 23 42 / 9%);
  transition: transform 120ms ease, outline-color 120ms ease, filter 120ms ease;
}
.tile:hover:not(:disabled) { z-index: 1; transform: translateY(-2px); filter: brightness(1.05); }
.tile:focus-visible { z-index: 2; outline: 3px solid #172554; outline-offset: 3px; }
.tile[aria-pressed="true"] { z-index: 1; outline: 4px solid #172554; outline-offset: 2px; transform: scale(0.92); }
.tile:disabled { cursor: default; }
.tile--0 { background: #e05260; }
.tile--1 { background: #3478c8; }
.tile--2 { background: #2c9a72; }
.tile--3 { background: #d18b22; }
.tile--4 { background: #8758b5; }

.game-status { min-height: 1.5em; margin: 17px 0 5px; color: #334155; font-weight: 700; text-align: center; }
.game-status.is-won { color: #14734d; }
.game-status.is-error { color: #b42332; }
.instructions { margin: 0; color: #64748b; font-size: 0.88rem; text-align: center; }
.game-footer { margin-top: 17px; color: #64748b; font-size: 0.86rem; line-height: 1.6; text-align: center; }

@media (max-width: 480px) {
  :root { --board-gap: 4px; --tile-size: min(calc((100vw - 86px) / 8), 44px); }
  body { padding: 20px 10px 28px; }
  .game-header { margin-bottom: 16px; }
  .game-panel { border-radius: 17px; }
  .board-frame { padding: 6px; border-radius: 12px; }
  .tile { border-radius: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
