:root {
  --paper: #f8f9f5;
  --card: #ffffff;
  --ink: #23392e;
  --muted: #667066;
  --line: #dfe4da;
  --accent: #2c6647;
  --accent-ink: #ffffff;
  --pale: #edf2e7;
  --gold: #e2a63b;
  --board: #c5d4b8;
  --cell: #dbe6d2;
  --shadow: 0 15px 45px #243d2814;
  --gap: 12px;
  --pad: 14px;
  --slide: 120ms;
  --sans: Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  --mono: "Courier New", Courier, monospace;
  color-scheme: light;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

:root[data-theme="dark"] {
  --paper: #141d18;
  --card: #1c2820;
  --ink: #e6eddf;
  --muted: #9ba995;
  --line: #354333;
  --accent: #b2ce87;
  --accent-ink: #142018;
  --pale: #17241b;
  --board: #2a3b32;
  --cell: #1b2b23;
  --shadow: 0 15px 45px #00000055;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button, a { -webkit-tap-highlight-color: transparent; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

a { color: inherit; text-decoration: none; }

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

button:disabled { cursor: default; opacity: 0.45; }

[hidden] { display: none !important; }

.site-header {
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.site-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  min-height: 76px;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 16px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.04em;
}

.brand-mark { font-weight: 400; font-size: 22px; }

.brand-dot { color: #82a85c; margin-left: -6px; }

nav {
  display: flex;
  gap: 26px;
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
}

nav a:hover,
nav .current { color: var(--ink); }

nav .current { position: relative; }

nav .current::after {
  content: "";
  position: absolute;
  left: calc(50% - 2px);
  bottom: -10px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pale);
  gap: 2px;
}

.lang button {
  min-width: 36px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.lang button.selected {
  background: var(--card);
  box-shadow: 0 1px 3px #22332a1a;
}

.theme-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
}

.theme-btn:hover,
.lang button:hover { background: var(--pale); }

.lang button.selected:hover { background: var(--card); }

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 28px 0;
}

.back {
  display: inline-block;
  margin-bottom: 26px;
  font-size: 12px;
  color: var(--muted);
}

.back:hover { color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(400px, 520px);
  gap: 64px;
  align-items: start;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #73a056;
}

h1 {
  margin: 18px 0 12px;
  font-size: 96px;
  line-height: 0.9;
  letter-spacing: -0.06em;
  font-weight: 650;
}

.title-dot { color: #82a85c; }

.tagline {
  margin: 0 0 14px;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -0.03em;
}

.description {
  margin: 0;
  max-width: 36rem;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.how-to {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  max-width: 360px;
}

.how-to .eyebrow { color: var(--muted); margin-bottom: 12px; }

.instruction {
  display: flex;
  gap: 12px;
  align-items: baseline;
}

.instruction-number {
  font: 700 11px var(--mono);
  color: #8a9c84;
}

.instruction p {
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.55;
}

.tiny-note {
  display: flex;
  gap: 8px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.tiny-note span:first-child { color: var(--accent); }

.game-shell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 8px 16px 16px;
  min-width: 0;
}

.game-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 4px 2px;
}

.game-wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font: 700 13px var(--mono);
  letter-spacing: 0.14em;
}

.scores {
  margin-left: auto;
  display: flex;
  gap: 18px;
}

.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 52px;
}

.stat-label {
  color: var(--muted);
  font: 700 10px var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stat strong {
  font: 600 22px var(--mono);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.best strong { color: #6d8464; }

:root[data-theme="dark"] .best strong { color: #acc28a; }

.score-add {
  position: absolute;
  left: 0;
  top: 12px;
  color: var(--accent);
  font: 700 16px var(--mono);
  pointer-events: none;
  animation: rise 650ms ease-out forwards;
}

@keyframes rise {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-22px); }
}

.new-game {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.new-game:hover { filter: brightness(1.08); }

.new-game:active { transform: translateY(1px); }

.board-wrap { position: relative; }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: var(--pad);
  border-radius: 12px;
  background: var(--board);
  touch-action: none;
  user-select: none;
}

.board.nudge { animation: nudge 160ms ease; }

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}

.layer {
  position: absolute;
  inset: var(--pad);
}

.cell,
.tile {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 8px;
}

.cell { background: var(--cell); }

.tile {
  z-index: 2;
  transition: transform var(--slide) cubic-bezier(0.2, 0.7, 0.25, 1);
}

.board.no-motion .tile { transition: none; }

.face {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 750;
  letter-spacing: -0.04em;
  line-height: 1;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.tile { container-type: size; }

.face { font-size: 46cqmin; }
.face[data-digits="3"] { font-size: 34cqmin; }
.face[data-digits="4"] { font-size: 26cqmin; letter-spacing: -0.06em; }
.face[data-digits="5"] { font-size: 21cqmin; letter-spacing: -0.07em; }

.tile.is-new .face { animation: appear 140ms ease-out; }
.tile.is-merged .face { animation: merge-pop 170ms ease; }

@keyframes appear {
  from { transform: scale(0.35); opacity: 0.35; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes merge-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.face.v-2 { background: #f7faf3; color: #23392e; }
.face.v-4 { background: #e3eedd; color: #23392e; }
.face.v-8 { background: #c5ddb6; color: #1a3326; }
.face.v-16 { background: #9dcc96; color: #143024; }
.face.v-32 { background: #6aaa72; color: #1a3326; }
.face.v-64 { background: #3d7d50; color: #f7fbf5; }
.face.v-128 { background: #2c6647; color: #f8fbf6; }
.face.v-256 { background: #1e4e37; color: #f4f8f2; }
.face.v-512 { background: #163c2b; color: #f3f7f1; }
.face.v-1024 { background: #10281e; color: #f6f3e6; }
.face.v-2048 { background: #e2a63b; color: #1c2414; }
.face.v-4096 { background: #c4842a; color: #1c1408; }
.face.v-8192,
.face.v-super { background: #6e4512; color: #fff4dc; }

:root[data-theme="dark"] .face.v-2 { background: #2c4036; color: #e8f2e6; }
:root[data-theme="dark"] .face.v-4 { background: #375844; color: #e8f2e6; }
:root[data-theme="dark"] .face.v-8 { background: #3f6b4c; color: #f4faf4; }
:root[data-theme="dark"] .face.v-16 { background: #457a56; color: #f7fbf6; }
:root[data-theme="dark"] .face.v-32 { background: #8fbf86; color: #102016; }
:root[data-theme="dark"] .face.v-64 { background: #c5ddb4; color: #122016; }
:root[data-theme="dark"] .face.v-128 { background: #e7f0df; color: #122016; }
:root[data-theme="dark"] .face.v-256 { background: #f4f7f1; color: #142018; }
:root[data-theme="dark"] .face.v-512 { background: #d7b15a; color: #1c180c; }
:root[data-theme="dark"] .face.v-1024 { background: #e2a63b; color: #1c180c; }
:root[data-theme="dark"] .face.v-2048 { background: #f0d48a; color: #1c160c; }
:root[data-theme="dark"] .face.v-4096,
:root[data-theme="dark"] .face.v-8192,
:root[data-theme="dark"] .face.v-super { background: #fff6df; color: #1c160c; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: 12px;
  background: #e7eee2c7;
}

:root[data-theme="dark"] .overlay { background: #101812c7; }

.overlay-card {
  width: min(100%, 320px);
  text-align: center;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 50px #243d2824;
  padding: 26px 22px 20px;
}

.overlay-card .overlay-kicker {
  margin: 0;
  font: 700 11px var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6d8464;
}

:root[data-theme="dark"] .overlay-kicker { color: #acc28a; }

.overlay-card h2 {
  margin: 12px 0 10px;
  font-size: clamp(32px, 7vw, 48px);
  line-height: 1.05;
  letter-spacing: -0.045em;
  font-weight: 650;
}

.overlay-card p { margin: 0 0 16px; }

.overlay-card .overlay-body {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.overlay-card .result-score {
  margin: 0 0 16px;
  color: var(--accent);
  font: 600 28px var(--mono);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.primary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 9px;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 700;
}

.primary:hover { filter: brightness(1.08); }

.primary span[aria-hidden] { font-weight: 400; font-size: 18px; }

.secondary {
  margin-top: 12px;
  color: var(--accent);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.keyboard-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.keyboard-hint .keys { display: flex; align-items: center; gap: 4px; }

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 11px var(--mono);
  color: var(--ink);
}

.swipe-hint { margin-left: auto; }

.touch-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
}

.touch-controls div { display: flex; gap: 6px; }

.touch-controls button {
  width: 52px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pale);
  font-size: 18px;
  touch-action: none;
}

.touch-controls button:active { background: var(--line); }

.noscript {
  max-width: 40rem;
  margin: 24px auto;
  padding: 0 28px;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px 28px;
  flex-wrap: wrap;
  margin-top: 48px;
  padding: 20px 0 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.credit-link {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.credit-link:hover { color: var(--accent); }

.footer-tag { font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; }

html[lang="zh-CN"] .tagline,
html[lang="zh-CN"] h1,
html[lang="zh-CN"] .overlay-card h2 {
  letter-spacing: 0;
}

html[lang="zh-CN"] .overlay-card h2 { line-height: 1.2; }

html[lang="zh-CN"] .stat-label,
html[lang="zh-CN"] .eyebrow,
html[lang="zh-CN"] .overlay-kicker {
  letter-spacing: 0.08em;
}

@media (max-width: 1000px) {
  h1 { font-size: 76px; }
  .layout {
    gap: 36px;
    grid-template-columns: minmax(220px, 1fr) minmax(340px, 1fr);
  }
  .tagline { font-size: 22px; }
}

@media (max-width: 760px) {
  .site-header-inner { padding: 10px 16px; min-height: 64px; }
  .brand { font-size: 16px; }
  nav { display: none; }
  .header-tools { margin-left: auto; }
  main { padding: 18px 16px 0; }
  .back { margin-bottom: 16px; }
  .layout { display: flex; flex-direction: column; gap: 22px; }
  .game-shell { order: -1; }
  h1 { font-size: 64px; margin: 8px 0; }
  .tagline { font-size: 20px; }
  .how-to { display: none; }
  .game-topbar { gap: 10px; min-height: 64px; }
  .scores { gap: 12px; }
  .stat strong { font-size: 20px; }
  .keyboard-hint .keys { display: none; }
  .swipe-hint { margin: 0 auto; font-size: 13px; }
  .touch-controls { display: flex; }
  footer { margin-top: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile.is-new .face,
  .tile.is-merged .face,
  .score-add,
  .board.nudge {
    transition: none !important;
    animation: none !important;
  }
}
