.twenty-page {
  background:
    linear-gradient(90deg, rgba(34, 49, 43, 0.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(34, 49, 43, 0.045) 1px, transparent 1px),
    linear-gradient(135deg, #fbf7ed 0%, #eef5ec 54%, #f7efe4 100%);
  background-size: 34px 34px, 34px 34px, auto;
}

.compact-header {
  width: min(1160px, calc(100% - 32px));
  padding: 14px 0 8px;
}

.compact-header .brand-mark {
  width: 34px;
  height: 34px;
  box-shadow: 3px 3px 0 var(--ink);
}

.compact-header .top-nav a {
  padding: 7px 12px;
}

.game-shell {
  width: min(1160px, calc(100% - 32px));
  min-height: calc(100svh - 62px);
}

.game-titlebar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 20px;
  align-items: end;
  padding: 2px 0 12px;
}

.game-titlebar h1 {
  margin: 0;
  font-size: 3rem;
  line-height: 0.95;
}

.game-titlebar p:not(.eyebrow) {
  max-width: 560px;
  margin: 0;
  color: #4d5c55;
  line-height: 1.55;
}

.twenty-layout {
  display: grid;
  grid-template-columns: minmax(320px, 560px) minmax(280px, 360px);
  gap: 24px;
  align-items: start;
  min-width: 0;
}

.twenty-board-panel,
.twenty-control-panel {
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.96), rgba(250, 245, 234, 0.94));
  box-shadow: 8px 8px 0 var(--ink);
  animation: twenty-panel-in 420ms var(--ease-out-quint) both;
}

.twenty-board-panel {
  position: relative;
  display: grid;
  gap: 10px;
  width: fit-content;
  padding: 12px;
}

.twenty-board {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: min(460px, calc(100svh - 270px), 46vw);
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 8px;
  padding: 10px;
  background:
    linear-gradient(135deg, rgba(34, 49, 43, 0.08), transparent 28%),
    #d8cbb8;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  contain: layout paint;
  box-shadow: inset 0 0 0 1px rgba(255, 253, 247, 0.45);
  cursor: grab;
}

.twenty-board:active {
  cursor: grabbing;
}

.tile {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 2px solid rgba(34, 49, 43, 0.22);
  border-radius: 7px;
  background:
    linear-gradient(145deg, rgba(255, 253, 247, 0.72), rgba(255, 253, 247, 0) 48%),
    #f4ead9;
  color: var(--ink);
  font-size: 2rem;
  font-weight: 950;
  transform: translateZ(0);
  box-shadow: inset 0 1px 0 rgba(255, 253, 247, 0.68);
  transition:
    background 140ms var(--ease-out-quart),
    color 140ms var(--ease-out-quart),
    border-color 140ms var(--ease-out-quart),
    filter 140ms var(--ease-out-quart);
  will-change: transform, opacity;
}

.tile:not([data-value="0"]) {
  text-shadow: 0 1px 0 rgba(255, 253, 247, 0.22);
}

.tile.new {
  animation: tile-in 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.tile.merged {
  animation: tile-merge 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.tile[data-value="0"] {
  color: transparent;
  background: rgba(255, 253, 247, 0.34);
  box-shadow: inset 0 0 0 1px rgba(34, 49, 43, 0.05);
}

.tile[data-value="2"] { background: #f7f0df; }
.tile[data-value="4"] { background: #efe1c5; }
.tile[data-value="8"] { background: #f3b64b; }
.tile[data-value="16"] { background: #e99557; color: #fffdf7; }
.tile[data-value="32"] { background: #e96f55; color: #fffdf7; }
.tile[data-value="64"] { background: #d74d3f; color: #fffdf7; }
.tile[data-value="128"] { background: #77a9c9; color: #12242e; }
.tile[data-value="256"] { background: #2f7a5a; color: #fffdf7; }
.tile[data-value="512"] { background: #8c78b9; color: #fffdf7; }
.tile[data-value="1024"],
.tile[data-value="2048"] { background: #22312b; color: #fffdf7; font-size: 1.55rem; }

.twenty-board.move-left { animation: board-left 130ms cubic-bezier(0.25, 1, 0.5, 1); }
.twenty-board.move-right { animation: board-right 130ms cubic-bezier(0.25, 1, 0.5, 1); }
.twenty-board.move-up { animation: board-up 130ms cubic-bezier(0.25, 1, 0.5, 1); }
.twenty-board.move-down { animation: board-down 130ms cubic-bezier(0.25, 1, 0.5, 1); }

.score-pop {
  animation: score-pop 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.twenty-control-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  animation-delay: 80ms;
}

.score-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.score-row span {
  display: grid;
  gap: 4px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fffdf7;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform 160ms var(--ease-out-quart), box-shadow 160ms var(--ease-out-quart);
}

.score-row span:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.score-row strong {
  font-size: 1.45rem;
}

.score-row small,
.hint-text {
  color: var(--muted);
  font-weight: 800;
}

.twenty-control-panel .hint-text {
  display: none;
}

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-width: 0;
  gap: 8px;
}

.direction-pad button {
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  min-height: 44px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition:
    transform 130ms var(--ease-out-quart),
    box-shadow 130ms var(--ease-out-quart),
    background 130ms var(--ease-out-quart);
}

.direction-pad button:has(.control-key) span {
  position: static;
  min-height: 0;
  line-height: 1;
  transform: none;
}

.direction-pad .control-key {
  position: static;
  color: var(--muted);
  font-size: 0.5em;
  font-weight: 600;
  line-height: 1;
  transform: translateY(0.16em) scale(0.7);
  transform-origin: left center;
  white-space: nowrap;
}

.direction-pad button:hover {
  transform: translate(-1px, -1px);
  background: #fff7e6;
  box-shadow: 4px 4px 0 var(--ink);
}

.direction-pad button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.direction-pad button[data-move="up"],
.direction-pad button[data-move="down"] {
  grid-column: 2;
}

.direction-pad button[data-move="left"] {
  grid-column: 1;
}

.direction-pad button[data-move="right"] {
  grid-column: 3;
}

.game-message {
  min-height: 24px;
  margin: 0;
  color: #4d5c55;
  font-weight: 800;
}

.game-rules {
  padding-top: 40px;
}

@media (max-width: 860px) {
  .game-titlebar,
  .twenty-layout {
    grid-template-columns: 1fr;
  }

  .twenty-board-panel {
    width: 100%;
    justify-items: center;
  }

  .twenty-board {
    width: min(calc(100vw - 56px), 520px);
  }
}

@media (max-width: 520px) {
  .compact-header,
  .game-shell {
    width: min(100% - 28px, 1160px);
  }

  .compact-header {
    position: sticky;
    z-index: 30;
    top: 0;
    padding: 10px 0 6px;
    background:
      linear-gradient(90deg, rgba(34, 49, 43, 0.045) 1px, transparent 1px),
      linear-gradient(0deg, rgba(34, 49, 43, 0.045) 1px, transparent 1px),
      linear-gradient(135deg, rgba(251, 247, 237, 0.96), rgba(238, 245, 236, 0.96));
    background-size: 34px 34px, 34px 34px, auto;
  }

  .compact-header .brand strong {
    font-size: 0.9rem;
  }

  .compact-header .brand small {
    display: block;
    font-size: 0.62rem;
    line-height: 1.15;
  }

  .game-shell {
    min-height: auto;
    padding-bottom: 20px;
  }

  .game-titlebar {
    padding: 4px 0 10px;
  }

  .game-titlebar p:not(.eyebrow) {
    display: none;
  }

  .game-titlebar .eyebrow {
    margin-bottom: 6px;
    font-size: 0.68rem;
  }

  .game-titlebar h1 {
    font-size: clamp(1.95rem, 10vw, 2.35rem);
  }

  .twenty-board-panel,
  .twenty-control-panel {
    box-shadow: 5px 5px 0 var(--ink);
  }

  .twenty-board-panel {
    padding: 7px;
  }

  .twenty-board {
    gap: 7px;
    width: min(calc(100vw - 84px), 330px);
    padding: 7px;
  }

  .twenty-control-panel {
    gap: 9px;
    padding: 10px;
    overflow: hidden;
  }

  .score-row {
    gap: 6px;
  }

  .score-row span {
    min-height: 52px;
    padding: 8px;
    box-shadow: 2px 2px 0 var(--ink);
  }

  .score-row strong {
    font-size: 1.15rem;
  }

  .direction-pad {
    border: 2px solid var(--ink);
    border-radius: 8px;
    padding: 8px;
    background: rgba(255, 253, 247, 0.74);
    box-shadow: 2px 2px 0 rgba(34, 49, 43, 0.9);
    gap: 6px;
  }

  .direction-pad button,
  .tool-button {
    min-height: 44px;
  }

  .tile {
    font-size: 1.55rem;
  }

  .tile[data-value="1024"],
  .tile[data-value="2048"] {
    font-size: 1.18rem;
  }
}

@media (max-width: 380px) {
  .twenty-board {
    width: min(calc(100vw - 76px), 314px);
  }

}

@keyframes tile-in {
  from { opacity: 0; transform: scale(0.72); }
  to { opacity: 1; transform: scale(1); }
}

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

@keyframes score-pop {
  0% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes board-left {
  0% { transform: translateX(0); }
  45% { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}

@keyframes board-right {
  0% { transform: translateX(0); }
  45% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

@keyframes board-up {
  0% { transform: translateY(0); }
  45% { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}

@keyframes board-down {
  0% { transform: translateY(0); }
  45% { transform: translateY(3px); }
  100% { transform: translateY(0); }
}

@keyframes twenty-panel-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .twenty-board,
  .score-pop {
    animation: none !important;
    transition: none !important;
  }
}
