:root {
  color-scheme: dark;
  --bg: #0e1116;
  --bg-soft: #121821;
  --panel: rgba(21, 27, 35, 0.88);
  --panel-strong: #151b23;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e8edf3;
  --muted: #9aa7b5;
  --accent: #f2b84b;
  --accent-strong: #ffd27a;
  --mint: #5cc8a1;
  --danger: #f27b6b;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --radius: 20px;
  font-family: "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -10%, rgba(242, 184, 75, 0.13), transparent 34rem),
    radial-gradient(circle at 92% 8%, rgba(92, 200, 161, 0.1), transparent 30rem),
    linear-gradient(180deg, #0e1116 0%, #0b0f14 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, #000 0%, transparent 70%);
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(242, 184, 75, 0.55);
  outline-offset: 3px;
}

.site-header,
.page,
.site-footer {
  width: min(1040px, calc(100% - 40px));
  margin: 0 auto;
}

.site-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 0 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  grid-template-rows: repeat(2, 9px);
  gap: 3px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
}

.brand-mark span {
  border-radius: 3px;
  background: var(--accent);
}

.brand-mark span:nth-child(2),
.brand-mark span:nth-child(3) {
  background: var(--mint);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 0.94rem;
}

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

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

.page {
  position: relative;
  z-index: 1;
  padding: 52px 0 86px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(260px, 0.75fr);
  align-items: end;
  gap: 44px;
  margin-bottom: 38px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.045em;
  line-height: 1.04;
}

h1 {
  max-width: 16ch;
  font-size: clamp(2.6rem, 6.4vw, 5.5rem);
}

h2 {
  font-size: clamp(1.45rem, 3.2vw, 2.15rem);
}

.lead {
  max-width: 60ch;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.6vw, 1.16rem);
  line-height: 1.65;
}

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

.score-card {
  display: flex;
  min-height: 116px;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
}

.score-card-best {
  border-color: rgba(242, 184, 75, 0.26);
  background: linear-gradient(160deg, rgba(242, 184, 75, 0.13), rgba(242, 184, 75, 0.03));
}

.score-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.score-value {
  color: var(--text);
  font-size: clamp(1.9rem, 4vw, 3rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.score-card-best .score-value {
  color: var(--accent-strong);
}

.game-shell {
  padding: clamp(18px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.game-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.game-head h2 {
  font-size: clamp(1.25rem, 2.4vw, 1.7rem);
  letter-spacing: -0.03em;
}

.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 800;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
  text-decoration: none;
}

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

.button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

.button-primary {
  color: #15100a;
  background: var(--accent);
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-ghost {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
}

.button-ghost:hover {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.07);
}

.board-wrap {
  position: relative;
  width: min(100%, 560px);
  margin: 0 auto;
}

.board {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: clamp(7px, 1.8vw, 12px);
  padding: clamp(9px, 2vw, 14px);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 24px;
  background: #0a0e13;
  box-shadow: inset 0 2px 24px rgba(0, 0, 0, 0.48);
  touch-action: none;
  user-select: none;
}

.cell {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border-radius: clamp(9px, 1.9vw, 14px);
  color: #12100b;
  font-size: clamp(1.08rem, 4.4vw, 2.35rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.06em;
  line-height: 1;
  transition: background-color 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.cell.is-empty {
  background: rgba(255, 255, 255, 0.035);
}

.tile-2 {
  background: #eee4da;
}

.tile-4 {
  background: #ede0c8;
}

.tile-8 {
  color: #fff8ef;
  background: #f2b179;
}

.tile-16 {
  color: #fff8ef;
  background: #f59563;
}

.tile-32 {
  color: #fff8ef;
  background: #f67c5f;
}

.tile-64 {
  color: #fff8ef;
  background: #f65e3b;
}

.tile-128 {
  color: #fff8ef;
  background: #edcf72;
  font-size: clamp(0.94rem, 3.8vw, 2rem);
}

.tile-256 {
  color: #fff8ef;
  background: #edcc61;
  font-size: clamp(0.94rem, 3.8vw, 2rem);
}

.tile-512 {
  color: #fff8ef;
  background: #edc850;
  font-size: clamp(0.94rem, 3.8vw, 2rem);
}

.tile-1024 {
  color: #fff8ef;
  background: #edc53f;
  font-size: clamp(0.78rem, 3.2vw, 1.65rem);
}

.tile-2048 {
  color: #fff8ef;
  background: #edc22e;
  box-shadow: 0 0 34px rgba(237, 194, 46, 0.34);
  font-size: clamp(0.78rem, 3.2vw, 1.65rem);
}

.tile-max {
  color: #f7eaff;
  background: #4f3a7a;
  font-size: clamp(0.78rem, 3.2vw, 1.65rem);
}

.cell.is-new {
  animation: tile-pop 0.2s ease-out;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  border-radius: 24px;
  background: rgba(7, 10, 14, 0.72);
  backdrop-filter: blur(10px);
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  width: min(100%, 390px);
  padding: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  text-align: center;
}

.overlay-card h2 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}

.overlay-card p:not(.eyebrow) {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

.hint {
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
  text-align: center;
}

.how {
  display: grid;
  grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.3fr);
  gap: 34px;
  margin-top: 54px;
  padding-top: 34px;
  border-top: 1px solid var(--line);
}

.how ol {
  display: grid;
  gap: 14px;
  margin: 0;
  padding-left: 1.3em;
  color: var(--muted);
  line-height: 1.65;
}

.how li::marker {
  color: var(--accent);
  font-weight: 800;
}

.site-footer {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 24px 0 34px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer a {
  color: var(--muted);
}

.site-footer a:hover {
  color: var(--text);
}

.footer-sep {
  opacity: 0.5;
}

.page-about {
  max-width: 760px;
  padding-top: 74px;
}

.page-about h1 {
  max-width: 18ch;
  font-size: clamp(2.2rem, 5.4vw, 4rem);
}

.page-about p {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.7vw, 1.15rem);
  line-height: 1.7;
}

.page-about .button {
  margin-top: 28px;
}

@media (max-width: 760px) {
  .site-header,
  .page,
  .site-footer {
    width: min(100% - 28px, 1040px);
  }

  .site-header {
    padding-top: 18px;
  }

  .page {
    padding-top: 34px;
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 26px;
    margin-bottom: 28px;
  }

  h1 {
    max-width: 14ch;
  }

  .scoreboard {
    max-width: 360px;
  }

  .score-card {
    min-height: 94px;
    padding: 15px;
  }

  .game-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 16px;
  }

  .game-actions {
    width: 100%;
    justify-content: stretch;
  }

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

  .how {
    grid-template-columns: 1fr;
    gap: 18px;
    margin-top: 38px;
  }

  .board {
    border-radius: 20px;
  }

  .overlay {
    border-radius: 20px;
  }
}

@media (max-width: 420px) {
  .scoreboard {
    gap: 8px;
  }

  .score-card {
    min-height: 84px;
    padding: 12px;
  }

  .score-value {
    font-size: 1.8rem;
  }

  .game-shell {
    padding: 14px;
  }

  .overlay-card {
    padding: 20px;
  }
}

@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;
  }
}
