:root {
  color-scheme: light;
  --page-scale: 0.75;
  --paper: #f1eadf;
  --paper-deep: #e5dacb;
  --ink: #1d1d1b;
  --muted: #716d66;
  --line: rgba(29, 29, 27, 0.16);
  --grid-line: rgba(29, 29, 27, 0.045);
  --coral: #e65d3d;
  --green: #225f50;
  --guide: #225f50;
  --board: #252522;
  --score-bg: #1d1d1b;
  --score-text: #fff9ef;
  --score-best-bg: #e5dacb;
  --score-best-text: #1d1d1b;
  --primary-button-bg: #1d1d1b;
  --primary-button-text: #fffaf1;
  --control-surface: #faf6ef;
  --soft-surface: rgba(255, 255, 255, 0.24);
  --board-gap: 12px;
  --board-radius: 24px;
  --shadow: 0 28px 70px rgba(55, 41, 25, 0.16);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #151613;
  --paper-deep: #292b26;
  --ink: #f3ede3;
  --muted: #aaa49a;
  --line: rgba(243, 237, 227, 0.15);
  --grid-line: rgba(243, 237, 227, 0.045);
  --coral: #ff7654;
  --green: #67b69d;
  --guide: #183f35;
  --board: #0f100e;
  --score-bg: #f3ede3;
  --score-text: #171815;
  --score-best-bg: #292b26;
  --score-best-text: #f3ede3;
  --primary-button-bg: #f3ede3;
  --primary-button-text: #171815;
  --control-surface: #252722;
  --soft-surface: rgba(255, 255, 255, 0.055);
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 300px;
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--paper);
  background-size: 48px 48px;
  -webkit-font-smoothing: antialiased;
}

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

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
.board:focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 4px;
}

.page-shell {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  zoom: var(--page-scale);
}

.topbar {
  min-height: 118px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -0.09em;
  line-height: 1;
}

.brand-mark span {
  color: var(--coral);
}

.brand-tagline {
  padding-left: 18px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1.45;
  text-transform: uppercase;
  border-left: 1px solid var(--line);
}

.topbar-note {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.theme-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft-surface);
  cursor: pointer;
  transition:
    transform 0.16s ease,
    background-color 0.2s ease,
    color 0.2s ease;
}

.theme-toggle:hover {
  transform: translateY(-2px);
}

.theme-toggle-icon {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  color: var(--paper);
  border-radius: 50%;
  background: var(--ink);
}

.theme-toggle-icon::before {
  content: "☾";
  font-size: 12px;
  line-height: 1;
}

:root[data-theme="dark"] .theme-toggle-icon::before {
  content: "☀";
  font-size: 11px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(34, 95, 80, 0.12);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: clamp(46px, 7vw, 96px);
  padding: clamp(50px, 7vw, 92px) 0 64px;
  align-items: start;
}

.game-column {
  min-width: 0;
}

.game-heading-row {
  width: 100%;
  max-width: 660px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

@supports not (zoom: 1) {
  .page-shell {
    transform: scale(var(--page-scale));
    transform-origin: top center;
  }
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--coral);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}

.game-heading-row h1 {
  max-width: 560px;
  margin: 0;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(42px, 6vw, 76px);
  font-weight: 900;
  letter-spacing: -0.075em;
  line-height: 0.92;
}

.scores {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

.score-card {
  position: relative;
  min-width: 84px;
  padding: 11px 16px 12px;
  color: var(--score-text);
  text-align: center;
  border-radius: 13px;
  background: var(--score-bg);
  box-shadow: 0 10px 24px rgba(29, 29, 27, 0.1);
}

.score-card--best {
  color: var(--score-best-text);
  background: var(--score-best-bg);
  box-shadow: none;
}

.score-card span {
  display: block;
  margin-bottom: 2px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  opacity: 0.66;
}

.score-card strong {
  display: block;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 21px;
  letter-spacing: -0.03em;
  line-height: 1;
}

#score-gain {
  position: absolute;
  left: 50%;
  bottom: -2px;
  color: var(--coral);
  font-size: 14px;
  font-style: normal;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0);
}

#score-gain.is-visible {
  animation: score-rise 0.72s ease-out;
}

.board-wrap {
  width: 100%;
  max-width: 660px;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: var(--board-gap);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--board-radius);
  background:
    radial-gradient(circle at 25% 10%, rgba(255, 255, 255, 0.08), transparent 35%),
    var(--board);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
}

.cell-layer,
.tile-layer {
  position: absolute;
  inset: var(--board-gap);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--board-gap);
}

.cell {
  border-radius: 15px;
  background: rgba(255, 249, 239, 0.075);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.tile {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-width: 0;
  color: #383530;
  border-radius: 15px;
  background: #ede5d8;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 7px 12px rgba(0, 0, 0, 0.13);
}

.tile span {
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(27px, 7.2vw, 66px);
  font-weight: 900;
  letter-spacing: -0.07em;
  line-height: 1;
}

.tile[data-digits="3"] span {
  font-size: clamp(24px, 6vw, 55px);
}

.tile[data-digits="4"] span {
  font-size: clamp(20px, 5vw, 46px);
}

.tile[data-digits="5"] span,
.tile[data-digits="6"] span {
  font-size: clamp(16px, 4vw, 36px);
}

.tile--new {
  animation: tile-enter 0.18s ease-out;
}

.tile--merged {
  z-index: 2;
  animation: tile-merge 0.24s ease-out;
}

.tile--awaiting {
  opacity: 0;
  animation: none;
}

.tile--ghost {
  z-index: 6;
  pointer-events: none;
  will-change: transform;
  animation-name: tile-slide;
  animation-timing-function: cubic-bezier(0.22, 0.78, 0.26, 1);
  animation-fill-mode: both;
}

.tile[data-value="4"] {
  background: #e7d7be;
}

.tile[data-value="8"] {
  color: #fffaf0;
  background: #e8a054;
}

.tile[data-value="16"] {
  color: #fffaf0;
  background: #e27c49;
}

.tile[data-value="32"] {
  color: #fffaf0;
  background: #e55d3d;
}

.tile[data-value="64"] {
  color: #fffaf0;
  background: #bf3d2c;
}

.tile[data-value="128"] {
  color: #332b1f;
  background: #edcf72;
}

.tile[data-value="256"] {
  color: #332b1f;
  background: #edc75c;
}

.tile[data-value="512"] {
  color: #302719;
  background: #eabf43;
}

.tile[data-value="1024"] {
  color: #2d2519;
  background: #efba31;
}

.tile[data-value="2048"] {
  color: #272117;
  background:
    radial-gradient(circle at 50% 15%, #ffeaa2, transparent 38%),
    #f4bd32;
  box-shadow:
    0 0 30px rgba(244, 189, 50, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.tile[data-value="4096"],
.tile[data-value="8192"],
.tile[data-value="16384"],
.tile[data-value="32768"],
.tile[data-value="65536"] {
  color: #fffaf0;
  background: var(--green);
}

.game-message {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 34px;
  color: #fffaf1;
  text-align: center;
  background: rgba(29, 29, 27, 0.9);
  backdrop-filter: blur(8px);
  animation: message-enter 0.28s ease-out;
}

.game-message p {
  max-width: 390px;
}

.game-message > p:first-child {
  margin: 0 0 10px;
  color: #f4bd32;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.game-message h2 {
  margin: 0;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(34px, 6vw, 62px);
  letter-spacing: -0.06em;
  line-height: 0.98;
}

.game-message > p:nth-of-type(2) {
  margin: 16px 0 24px;
  color: rgba(255, 250, 241, 0.72);
  font-size: 14px;
  line-height: 1.6;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.game-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
}

.button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 18px;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    color 0.16s ease,
    opacity 0.16s ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.36;
}

.button--dark {
  color: var(--primary-button-text);
  background: var(--primary-button-bg);
}

.button--outline {
  color: var(--ink);
  border-color: var(--line);
  background: transparent;
}

.button--outline:hover:not(:disabled) {
  background: rgba(29, 29, 27, 0.06);
}

.button--light {
  color: var(--ink);
  background: #fffaf1;
}

.button--accent {
  color: #fffaf1;
  background: var(--coral);
}

.swipe-note {
  margin: 0 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.swipe-note span {
  margin-right: 5px;
  color: var(--green);
  font-size: 16px;
}

.guide {
  position: sticky;
  top: 30px;
  overflow: hidden;
  padding: clamp(30px, 4vw, 48px);
  color: #f8f2e9;
  border-radius: 26px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.06), transparent 42%),
    var(--guide);
  box-shadow: 0 24px 60px rgba(34, 95, 80, 0.19);
}

.guide::after {
  content: "2048";
  position: absolute;
  right: -20px;
  bottom: -30px;
  color: rgba(255, 255, 255, 0.035);
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 120px;
  letter-spacing: -0.1em;
  pointer-events: none;
}

.guide-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.eyebrow--light {
  margin: 0;
  color: #f2c767;
}

.guide-number {
  color: rgba(255, 255, 255, 0.38);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
}

.guide h2 {
  margin: 30px 0 18px;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(34px, 4vw, 52px);
  letter-spacing: -0.06em;
  line-height: 1;
}

.guide h2 span {
  color: #f2c767;
}

.guide-intro {
  max-width: 370px;
  margin: 0 0 34px;
  color: rgba(248, 242, 233, 0.68);
  font-size: 14px;
  line-height: 1.65;
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.steps li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  padding: 17px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.steps li > span {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  margin-top: 1px;
  color: var(--green);
  font-size: 10px;
  font-weight: 900;
  border-radius: 50%;
  background: #f2c767;
}

.steps p {
  margin: 0;
  color: rgba(248, 242, 233, 0.7);
  font-size: 13px;
  line-height: 1.55;
}

.steps strong {
  color: #fffaf1;
}

.key-guide {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 27px;
}

.keys {
  width: 76px;
  display: grid;
  grid-template-columns: repeat(3, 22px);
  grid-template-rows: repeat(2, 22px);
  gap: 3px;
}

.keys kbd {
  display: grid;
  place-items: center;
  color: var(--green);
  font-family: inherit;
  font-size: 11px;
  font-weight: 900;
  border-radius: 5px;
  background: #f4eee5;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}

.keys kbd:first-child {
  grid-column: 2;
}

.key-guide strong,
.key-guide span {
  display: block;
}

.key-guide strong {
  font-size: 12px;
  letter-spacing: 0.04em;
}

.key-guide span {
  margin-top: 3px;
  color: rgba(248, 242, 233, 0.5);
  font-size: 10px;
}

blockquote {
  position: relative;
  z-index: 1;
  margin: 34px 0 0;
  padding: 21px 0 0;
  color: rgba(248, 242, 233, 0.88);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-style: italic;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

blockquote cite {
  display: block;
  margin-top: 5px;
  color: rgba(248, 242, 233, 0.45);
  font-family: Inter, ui-sans-serif, sans-serif;
  font-size: 9px;
  font-style: normal;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.tap-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: -20px 0 48px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--soft-surface);
}

.tap-controls p {
  margin: 0;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.direction-pad {
  display: flex;
  gap: 7px;
}

.direction-pad button {
  width: 42px;
  height: 42px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--control-surface);
  cursor: pointer;
}

footer {
  min-height: 94px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  font-size: 11px;
  border-top: 1px solid var(--line);
}

footer p {
  margin: 0;
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0.03em;
}

footer span {
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

[hidden] {
  display: none !important;
}

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

@keyframes tile-merge {
  0% {
    transform: scale(0.82);
  }
  62% {
    transform: scale(1.13);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes tile-slide {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(var(--move-x), var(--move-y), 0);
  }
}

@keyframes score-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, 5px);
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -30px);
  }
}

@keyframes message-enter {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

  .board-wrap {
    max-width: none;
  }

  .guide {
    position: relative;
    top: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 38px;
  }

  .guide-top,
  .guide h2,
  .guide-intro {
    grid-column: 1;
  }

  .steps {
    grid-column: 2;
    grid-row: 1 / span 4;
  }

  .key-guide {
    grid-column: 1;
  }

  blockquote {
    grid-column: 1 / -1;
  }

  .tap-controls {
    display: flex;
  }
}

@media (max-width: 640px) {
  :root {
    --board-gap: 8px;
    --board-radius: 18px;
  }

  body {
    background-size: 36px 36px;
  }

  .page-shell {
    width: min(100% - 24px, 560px);
  }

  .topbar {
    min-height: 86px;
  }

  .brand {
    gap: 12px;
  }

  .brand-mark {
    font-size: 27px;
  }

  .brand-tagline {
    display: none;
  }

  .topbar-note {
    display: none;
  }

  .game-layout {
    gap: 34px;
    padding: 42px 0 46px;
  }

  .game-heading-row {
    display: block;
    margin-bottom: 20px;
  }

  .game-heading-row h1 {
    font-size: clamp(42px, 15vw, 66px);
  }

  .scores {
    margin-top: 22px;
  }

  .score-card {
    flex: 1;
  }

  .cell,
  .tile {
    border-radius: 10px;
  }

  .game-actions {
    flex-wrap: wrap;
  }

  .game-actions .button {
    flex: 1;
  }

  .swipe-note {
    width: 100%;
    margin: 8px 0 0;
    text-align: center;
  }

  .guide {
    display: block;
    padding: 30px 26px;
    border-radius: 20px;
  }

  .guide h2 {
    margin-top: 26px;
  }

  .steps {
    margin-top: 26px;
  }

  .tap-controls {
    display: block;
    margin-top: -12px;
    text-align: center;
  }

  .direction-pad {
    justify-content: center;
    margin-top: 12px;
  }

  footer {
    min-height: 116px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
  }
}

@media (max-width: 370px) {
  .page-shell {
    width: min(100% - 16px, 560px);
  }

  .topbar-note {
    display: none;
  }

  .theme-toggle {
    min-height: 38px;
    padding: 0 10px;
  }

  #theme-toggle-label {
    display: none;
  }

  .direction-pad button {
    width: 40px;
    height: 40px;
  }

  .game-message {
    padding: 20px;
  }

  .message-actions .button {
    min-height: 40px;
    padding: 0 14px;
  }
}

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