:root {
  color-scheme: light;
  font-family: "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  background: #f5f2e9;
  color: #2b3544;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
button:focus-visible, a:focus-visible { outline: 3px solid #0e8f89; outline-offset: 3px; }
[hidden] { display: none !important; }

.app-shell {
  min-height: 100svh;
  max-width: 1232px;
  margin: auto;
  padding: max(20px, env(safe-area-inset-top)) 28px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.site-header, .brand-wrap, .header-actions, .brand, .game-heading, .score-row, .section-heading, .site-footer {
  display: flex;
  align-items: center;
}
.site-header { justify-content: space-between; gap: 16px; padding-bottom: 24px; }
.brand-wrap { gap: 22px; }
.back-link { color: #677480; font-weight: 700; text-decoration: none; white-space: nowrap; }
.back-link:hover, .text-button:hover { color: #0a7470; }
.brand { gap: 10px; font-size: 26px; font-weight: 900; letter-spacing: -1px; color: #233447; }
.brand-mark {
  display: grid; place-items: center; width: 37px; height: 37px;
  border-radius: 11px; background: #127d79; color: white; font-size: 16px; letter-spacing: 0;
  box-shadow: 0 4px 0 #0b605d;
}
.header-actions { gap: 10px; }
.language-button { min-width: 49px; padding-inline: 10px; }
.quiet-button, .primary-button {
  min-height: 43px; border-radius: 12px; padding: 9px 17px; font-size: 14px; font-weight: 800;
  transition: transform .16s, background .16s, box-shadow .16s;
}
.quiet-button { border: 1px solid #d7dfdc; color: #31525a; background: #fffdf7; }
.quiet-button:hover { background: #edf7f3; }
.primary-button { border: 1px solid #0e7771; color: white; background: #138b83; box-shadow: 0 4px 0 #0c665f; }
.primary-button:hover { background: #0f7974; }
.quiet-button:active, .primary-button:active { transform: translateY(2px); box-shadow: none; }

.main-layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 330px;
  align-items: start; gap: 28px;
}
.play-area { min-width: 0; }
.game-heading { justify-content: space-between; align-items: end; gap: 16px; margin: 8px 0 18px; }
.eyebrow { margin: 0 0 5px; color: #147b76; font-size: 12px; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(22px, 3vw, 36px); letter-spacing: -.035em; line-height: 1.15; }
h1 span { color: #138b83; }
.score-row { gap: 8px; flex-shrink: 0; }
.score-card {
  min-width: 91px; padding: 8px 10px; border: 1px solid #d9dfd8; border-radius: 12px;
  background: #fffdf7; text-align: center;
}
.score-card span { display: block; color: #718089; font-size: 11px; font-weight: 800; white-space: nowrap; }
.score-card strong { display: block; margin-top: 2px; color: #263747; font-size: 19px; line-height: 1.15; }
.score-card.best { background: #e4f3eb; border-color: #cce5d7; }

.board-wrap { max-width: 500px; margin: 0 auto; }
.board {
  width: 100%; aspect-ratio: 1; padding: clamp(8px, 1.3vw, 13px);
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr);
  gap: clamp(8px, 1.3vw, 13px); border-radius: 20px; background: #9a8b7c;
  box-shadow: 0 12px 32px #564b3e22, inset 0 2px 4px #6c605348;
  touch-action: none; user-select: none;
}
.cell {
  display: grid; place-items: center; padding: 0; min-width: 0; min-height: 0;
  border: 0; border-radius: clamp(8px, 1.1vw, 13px);
  background: #b9ab9b; color: #36434b;
  font-size: clamp(23px, 5vw, 52px); font-weight: 900; letter-spacing: -.055em;
  line-height: 1; font-variant-numeric: tabular-nums;
  transition: background .16s, transform .16s;
}
.cell[data-value="0"] { color: transparent; }
.cell:not([data-value="0"]) { box-shadow: 0 3px 0 #56453626; }
.cell[data-value="2"] { background: #f8f0dc; }
.cell[data-value="4"] { background: #f3e4bc; }
.cell[data-value="8"] { background: #f5c48b; color: #653e27; }
.cell[data-value="16"] { background: #eea474; color: #fffdf8; }
.cell[data-value="32"] { background: #e98568; color: #fffdf8; }
.cell[data-value="64"] { background: #de695d; color: #fffdf8; }
.cell[data-value="128"] { background: #d8d880; color: #3d4b39; }
.cell[data-value="256"] { background: #b5d8a0; color: #2d4a44; }
.cell[data-value="512"] { background: #74c9b7; color: #164b4d; }
.cell[data-value="1024"] { background: #44a9a9; color: white; font-size: clamp(20px, 4.3vw, 43px); }
.cell[data-value="2048"] { background: #177f80; color: white; font-size: clamp(20px, 4.3vw, 43px); box-shadow: 0 0 22px #2fc3b1a3; }
.cell[data-value="4096"], .cell[data-value="8192"], .cell[data-value="16384"], .cell[data-value="32768"], .cell[data-value="65536"], .cell[data-value="131072"] {
  background: #265b7c; color: white; font-size: clamp(17px, 3.7vw, 35px);
}
.cell-selected { outline: 5px solid #1b928d; outline-offset: -5px; transform: scale(.96); }
.board-caption { min-height: 24px; margin: 13px 4px 0; color: #72818a; font-size: 13px; text-align: center; }

.side-panel { display: grid; gap: 14px; padding-top: 6px; }
.panel-card { border: 1px solid #e2e6de; border-radius: 20px; background: #fffdf8; padding: 19px; box-shadow: 0 5px 18px #30443c0b; }
.section-heading { justify-content: space-between; gap: 6px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; font-size: 17px; }
.section-heading span { color: #87938f; font-size: 11px; text-align: right; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 4px; border-radius: 12px; background: #edf0e8; }
.mode-button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; color: #7a8788; font-size: 14px; font-weight: 800; }
.mode-button[aria-pressed="true"] { background: #fffefa; color: #0d7772; box-shadow: 0 2px 7px #37443d1c; }
.small-copy, .tool-hint { margin: 12px 1px 0; color: #78868d; font-size: 12px; line-height: 1.55; }
.tools-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tool-button {
  min-height: 85px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: 1px solid #e3e8e5; border-radius: 13px; background: #f5f8f4;
  color: #2e5d5a; font-size: 13px; font-weight: 800;
}
.tool-button:hover:not(:disabled), .tool-button.active { background: #dbf1e9; border-color: #79bfaa; }
.tool-button:disabled { opacity: .5; }
.tool-icon { font-size: 25px; line-height: 1.05; }
.tool-button small { color: #819591; font-size: 10px; }
.help-card ol { margin: 0; padding-left: 19px; color: #586971; font-size: 13px; line-height: 1.6; }
.help-card li + li { margin-top: 6px; }
.text-button { display: inline-block; margin-top: 12px; padding: 0; border: 0; background: none; color: #16867e; font-size: 13px; font-weight: 800; }
.site-footer { justify-content: space-between; gap: 20px; flex-wrap: wrap; padding-top: 25px; color: #87938e; font-size: 11px; }

.game-dialog { width: min(92vw, 480px); max-height: min(90svh, 680px); padding: 0; border: 0; border-radius: 22px; background: #fffdf8; color: #2b3544; box-shadow: 0 25px 80px #182d2f55; }
.game-dialog::backdrop { background: #172b30a8; backdrop-filter: blur(3px); }
.dialog-inner { position: relative; padding: 28px; }
.dialog-inner h2 { margin: 0 0 11px; font-size: 25px; }
.dialog-inner p:not(.eyebrow) { margin: 0; color: #61717a; line-height: 1.6; font-size: 14px; }
.close-button { position: absolute; right: 18px; top: 15px; border: 0; background: transparent; color: #72818a; font-size: 28px; line-height: 1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 24px; }
.tutorial-demo { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 23px; }
.demo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; padding: 5px; border-radius: 9px; background: #a39484; }
.demo-cell { aspect-ratio: 1; display: grid; place-items: center; border-radius: 5px; background: #c0b3a4; font-weight: 900; font-size: clamp(11px, 3vw, 21px); }
.demo-cell[data-value="2"], .demo-cell[data-value="4"] { background: #f8edd6; }
.demo-cell[data-value="8"], .demo-cell[data-value="128"], .demo-cell[data-value="256"] { background: #efd49d; }
.demo-cell[data-value="512"] { background: #72c9b6; }
.demo-arrow { color: #138b83; font-size: 23px; font-weight: 900; white-space: nowrap; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: max(26px, env(safe-area-inset-bottom)); transform: translate(-50%, 15px); opacity: 0; pointer-events: none; padding: 11px 18px; border-radius: 100px; background: #263e42; color: white; box-shadow: 0 8px 22px #1b383c33; font-size: 13px; font-weight: 700; white-space: nowrap; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .main-layout { grid-template-columns: minmax(0, 1fr) 275px; gap: 16px; }
  .game-heading { flex-direction: column; align-items: stretch; }
  .score-row { justify-content: flex-start; }
  .panel-card { padding: 15px; }
}

@media (max-width: 690px) {
  .app-shell { padding: max(12px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)); }
  .site-header { padding-bottom: 13px; }
  .brand-wrap { gap: 10px; }
  .brand { font-size: 23px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 9px; }
  .back-link { font-size: 12px; }
  .header-actions { gap: 6px; }
  .header-actions .language-button { min-width: 40px; }
  .header-actions .quiet-button, .header-actions .primary-button { min-height: 36px; padding: 7px 10px; font-size: 12px; }
  .main-layout { display: flex; flex-direction: column; gap: 13px; }
  .play-area, .side-panel { width: 100%; }
  .game-heading { flex-direction: row; align-items: end; margin: 2px 0 11px; }
  h1 { font-size: clamp(19px, 5vw, 28px); max-width: 190px; }
  .score-card { min-width: 65px; padding: 6px; }
  .score-card span { font-size: 9px; }
  .score-card strong { font-size: 16px; }
  .board { padding: 8px; gap: 8px; border-radius: 15px; }
  .cell { border-radius: 9px; font-size: clamp(24px, 9vw, 44px); }
  .cell[data-value="1024"], .cell[data-value="2048"] { font-size: clamp(20px, 7.3vw, 35px); }
  .cell[data-value="4096"], .cell[data-value="8192"], .cell[data-value="16384"], .cell[data-value="32768"], .cell[data-value="65536"], .cell[data-value="131072"] { font-size: clamp(15px, 6vw, 28px); }
  .board-caption { font-size: 11px; margin-top: 8px; }
  .side-panel { display: grid; grid-template-columns: 1fr; gap: 10px; padding: 0; }
  .mode-card, .tools-card { padding: 12px 13px; }
  .mode-card .section-heading, .tools-card .section-heading { margin-bottom: 8px; }
  .mode-card .section-heading h2, .tools-card .section-heading h2 { font-size: 15px; }
  .mode-button { min-height: 37px; font-size: 13px; }
  .small-copy { margin-top: 7px; font-size: 11px; }
  .tool-button { min-height: 61px; display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; align-content: center; column-gap: 5px; }
  .tool-icon { grid-row: 1 / 3; font-size: 23px; }
  .tool-button small { grid-column: 2; }
  .tool-hint { margin-top: 7px; font-size: 11px; }
  .help-card { padding: 14px; }
  .site-footer { padding-top: 16px; }
}

@media (max-width: 390px) {
  .back-link { display: none; }
  .header-actions .quiet-button { padding-inline: 8px; }
  h1 { max-width: 150px; font-size: 19px; }
  .score-card { min-width: 62px; }
  .score-row { gap: 4px; }
}

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