:root {
  --background: #0e1522;
  --foreground: #f4f7fb;
  --night: #0e1522;
  --panel: #182232;
  --mist: #a8b3c4;
  --gold: #f0c14a;
  --gold-hot: #ffd15c;
  --header: #3a4d68;
  --stage: #1b2838;
  --chip: #121a27;
  --board: #bbada0;
  --cell: #cdc1b4;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.15);
  --line-header: rgba(255, 255, 255, 0.2);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--foreground);
  font-family: Outfit, "Avenir Next", "Segoe UI", sans-serif;
}

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

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

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

::selection {
  background: var(--gold);
  color: var(--night);
}

summary::-webkit-details-marker {
  display: none;
}

.skip {
  position: absolute;
  left: -9999px;
  top: auto;
}

.skip:focus {
  left: 1rem;
  top: 1rem;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--gold);
  color: var(--night);
  border-radius: 0.5rem;
}

/* Header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--line-header);
  background: var(--header);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(72rem, 100%);
  height: 4rem;
  margin: 0 auto;
  padding: 0 1rem;
}

@media (min-width: 640px) {
  .site-header-inner {
    padding: 0 1.5rem;
  }
}

.logo {
  display: inline-flex;
  align-items: baseline;
  line-height: 1;
}

.logo-game {
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: #fff;
}

.logo-2048 {
  font-family: "Titan One", cursive;
  font-size: 1.55rem;
  line-height: 1;
  color: var(--gold);
}

.site-nav {
  display: none;
  align-items: center;
  gap: 2rem;
  font-size: 1rem;
}

.site-nav a {
  color: var(--mist);
}

.site-nav a:hover {
  color: #fff;
}

.site-nav a.is-accent {
  font-weight: 600;
  color: var(--gold);
}

.menu-toggle {
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: #fff;
  font-size: 0.875rem;
}

.mobile-nav {
  border-top: 1px solid var(--line);
  padding: 0.75rem 1rem;
}

.mobile-nav a {
  display: block;
  padding: 0.75rem 0;
  font-size: 1.125rem;
  color: #fff;
}

@media (min-width: 768px) {
  .site-nav {
    display: flex;
  }

  .menu-toggle,
  .mobile-nav {
    display: none !important;
  }
}

/* Layout */

.wrap {
  width: min(72rem, 100%);
  margin: 0 auto;
  padding: 0 1rem;
}

@media (min-width: 640px) {
  .wrap {
    padding: 0 1.5rem;
  }
}

.scroll-mt {
  scroll-margin-top: 5rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}

.mist {
  color: var(--mist);
}

.gold {
  color: var(--gold);
}

/* Game section */

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(72rem, 100%);
  margin: 0 auto;
  padding: 1rem;
}

@media (min-width: 640px) {
  .game-layout {
    padding: 1rem 1.5rem;
  }
}

@media (min-width: 1024px) {
  .game-layout {
    width: fit-content;
    flex-direction: row;
    align-items: flex-start;
    gap: 1.25rem;
  }
}

.game-main {
  width: 100%;
}

@media (min-width: 1024px) {
  .game-main {
    width: min(calc(100vw - 22rem), calc(100svh - 16rem));
  }
}

.game-intro {
  text-align: center;
}

.game-intro h1 {
  margin: 0.25rem 0 0;
  font-size: clamp(1.875rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.game-intro p {
  margin: 0.25rem auto 0;
  max-width: 36rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--mist);
}

.stage {
  position: relative;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--stage);
  box-shadow: 0 30px 70px -36px rgba(0, 0, 0, 0.85);
}

@media (min-width: 640px) {
  .stage {
    padding: 1rem;
  }
}

.stage:fullscreen {
  display: flex;
  width: 100%;
  max-width: none;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  background: var(--night);
}

.stage:fullscreen .board {
  width: min(100%, calc(100vh - 11rem));
  margin-inline: auto;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.chips,
.actions {
  display: flex;
  gap: 0.5rem;
}

.chip {
  min-width: 4.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 1rem;
  background: var(--chip);
  text-align: center;
}

.chip-label {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mist);
}

.chip-value {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.chip-value.is-gold {
  color: var(--gold);
}

.btn {
  height: 2.5rem;
  padding: 0 0.875rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-ghost {
  border: 1px solid var(--line-strong);
  color: #fff;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-gold {
  background: var(--gold);
  color: var(--night);
}

.btn-gold:hover {
  background: var(--gold-hot);
}

.btn-solid {
  height: 2.5rem;
  padding: 0 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.btn-white {
  background: #fff;
  color: var(--night);
}

.touch-zone {
  touch-action: none;
}

.board {
  --size: 4;
  --gap: 0.5rem;
  --pad: 0.5rem;
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  border-radius: 0.75rem;
  background: var(--board);
}

@media (min-width: 640px) {
  .board {
    --gap: 0.75rem;
    --pad: 0.75rem;
  }
}

.board-3 {
  --size: 3;
}

.board-4 {
  --size: 4;
}

.board-grid,
.board-tiles {
  display: grid;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  gap: var(--gap);
  padding: var(--pad);
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
}

.board-tiles {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.cell {
  border-radius: 0.375rem;
  background: var(--cell);
}

.tile {
  z-index: 2;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 0.375rem;
  will-change: transform;
  transition: transform 120ms ease-in;
}

.tile-face {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: inherit;
  color: inherit;
  font-weight: 700;
  font-size: clamp(1.5rem, 6vw, 3.75rem);
  line-height: 1;
}

.tile-lg .tile-face {
  font-size: clamp(1.25rem, 4vw, 2.25rem);
}

.tile-2 {
  background: #eee4da;
  color: #776e65;
}
.tile-4 {
  background: #ede0c8;
  color: #776e65;
}
.tile-8 {
  background: #f2b179;
  color: #f9f6f2;
}
.tile-16 {
  background: #f59563;
  color: #f9f6f2;
}
.tile-32 {
  background: #f67c5f;
  color: #f9f6f2;
}
.tile-64 {
  background: #f65e3b;
  color: #f9f6f2;
}
.tile-128 {
  background: #edcf72;
  color: #f9f6f2;
}
.tile-256 {
  background: #edcc61;
  color: #f9f6f2;
}
.tile-512 {
  background: #edc850;
  color: #f9f6f2;
}
.tile-1024 {
  background: #edc53f;
  color: #f9f6f2;
}
.tile-2048 {
  background: #edc22e;
  color: #f9f6f2;
}

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

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

.tile-face.tile-new {
  animation: appear 140ms ease-out;
}

.tile-face.tile-merge {
  animation: merge-pop 160ms ease-out;
}

.tile:has(.tile-new),
.tile:has(.tile-merge) {
  z-index: 4;
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    transition: none;
  }

  .tile-face.tile-new,
  .tile-face.tile-merge {
    animation: none;
  }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  border-radius: 1rem;
  background: rgba(14, 21, 34, 0.8);
  text-align: center;
}

.overlay[hidden] {
  display: none;
}

.overlay-title {
  margin: 0;
  font-size: 1.875rem;
  font-weight: 700;
  color: #fff;
}

.overlay-body {
  margin: 0.5rem 0 0;
  color: var(--mist);
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.aside {
  width: 100%;
  flex-shrink: 0;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--stage);
}

@media (min-width: 640px) {
  .aside {
    padding: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .aside {
    width: 18rem;
    overflow-y: auto;
  }
}

.aside-label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mist);
}

.aside-best {
  margin: 0.75rem 0 0;
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--gold);
}

.aside > .mist {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.aside h3 {
  margin: 2rem 0 0;
  font-size: 1.125rem;
  font-weight: 700;
  color: #fff;
}

.benchmarks {
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.benchmarks li + li {
  margin-top: 1rem;
}

.benchmarks strong {
  display: block;
  font-weight: 700;
  color: #fff;
}

.benchmarks p {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--mist);
}

/* Content sections */

.prose {
  max-width: 48rem;
}

.section {
  padding: 1.5rem 0;
}

.section-lg {
  padding: 2rem 0;
}

.section h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 1.875rem);
  font-weight: 700;
  color: #fff;
}

.section .lead {
  margin: 0.75rem 0 0;
  max-width: 48rem;
  line-height: 1.75;
  color: var(--mist);
}

.section .lead + .lead {
  margin-top: 0.75rem;
}

.modes-head .mist {
  margin: 0;
  font-size: 0.875rem;
}

.modes-head h2 {
  margin-top: 0.25rem;
}

.modes-grid {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

@media (min-width: 640px) {
  .modes-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.mode-card {
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--panel);
}

.mode-card.is-active {
  border-color: var(--gold);
}

.mode-card h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.mode-card p {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--mist);
}

.link-btn {
  margin-top: 1rem;
  padding: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gold);
  background: none;
  border: 0;
}

.how-panel {
  padding: 2rem 1.25rem;
  border-radius: 1rem;
  background: var(--panel);
}

@media (min-width: 640px) {
  .how-panel {
    padding: 2.5rem 2rem;
  }
}

.how-panel h2 {
  font-size: 1.875rem;
}

.guide {
  margin-top: 2rem;
  max-width: 48rem;
}

.guide h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.guide p {
  margin: 0.75rem 0 0;
  line-height: 1.75;
  color: var(--mist);
}

.faq details {
  border-bottom: 1px solid var(--line);
  padding: 1rem 0;
}

.faq summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  list-style: none;
  cursor: pointer;
  font-size: 1.125rem;
  font-weight: 600;
  color: #fff;
}

.faq-mark {
  color: var(--gold);
  transition: transform 150ms ease;
}

.faq details[open] .faq-mark {
  transform: rotate(45deg);
}

.faq details p {
  max-width: 42rem;
  margin: 0.5rem 0 0;
  line-height: 1.75;
  color: var(--mist);
}

/* Footer */

.site-footer {
  border-top: 1px solid var(--line-header);
  background: var(--header);
}

.footer-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(72rem, 100%);
  margin: 0 auto;
  padding: 2rem 1rem;
  font-size: 1rem;
  color: var(--mist);
}

@media (min-width: 640px) {
  .footer-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 2rem 1.5rem;
  }
}

.footer-nav,
.legal-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

.footer-nav a:hover,
.legal-nav a:hover {
  color: #fff;
}

.legal-nav {
  width: min(72rem, 100%);
  margin: 0 auto;
  padding: 0 1rem 1.5rem;
  font-size: 0.875rem;
  color: var(--mist);
}

@media (min-width: 640px) {
  .legal-nav {
    padding: 0 1.5rem 1.5rem;
  }
}

/* Legal pages */

.legal-main {
  width: min(48rem, 100%);
  margin: 0 auto;
  padding: 3rem 1rem;
}

@media (min-width: 640px) {
  .legal-main {
    padding: 4rem 1.5rem;
  }
}

.legal-main .eyebrow {
  letter-spacing: 0.18em;
}

.legal-main h1 {
  margin: 0.75rem 0 0;
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.legal-meta {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  color: var(--mist);
}

.legal-section {
  margin-top: 2rem;
}

.legal-section h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.legal-section p {
  margin: 0.75rem 0 0;
  font-size: 1rem;
  line-height: 1.75;
  color: var(--mist);
}

.legal-section a {
  font-weight: 600;
  color: var(--gold);
}

.back-link {
  display: inline-block;
  margin-top: 3rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gold);
}
