:root {
  color-scheme: dark;
  --bg: #181614;
  --panel: #24211e;
  --panel-soft: #2e2a26;
  --ink: #f8f3e9;
  --muted: #aaa198;
  --accent: #ff6b35;
  --accent-bright: #ff8a3d;
  --line: rgba(255, 255, 255, 0.1);
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.32);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 9%, rgba(255, 107, 53, 0.16), transparent 30rem),
    radial-gradient(circle at 8% 82%, rgba(241, 180, 68, 0.09), transparent 28rem),
    var(--bg);
}

button,
kbd {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 28px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 40px;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--line);
}

.brand-block {
  max-width: 650px;
}

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

h1 {
  display: flex;
  margin: 0;
  font-size: clamp(5rem, 11vw, 9.5rem);
  font-weight: 900;
  letter-spacing: -0.095em;
  line-height: 0.78;
}

h1 span:last-child {
  color: var(--accent);
}

.subtitle {
  max-width: 520px;
  margin: 23px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
  line-height: 1.55;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 10px;
  min-width: 265px;
}

.score-card {
  position: relative;
  overflow: hidden;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
  text-align: right;
}

.score-card::after {
  position: absolute;
  right: -24px;
  bottom: -36px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(255, 107, 53, 0.12);
  content: "";
}

.score-card span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.score-card strong {
  display: block;
  font-size: clamp(1.45rem, 3vw, 2rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.score-card--best {
  background: var(--accent);
}

.score-card--best span {
  color: rgba(255, 255, 255, 0.75);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 0;
}

.toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.toolbar-actions,
.overlay-actions {
  display: flex;
  gap: 10px;
}

.button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

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

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

.button:focus-visible,
.board:focus-visible {
  outline: 3px solid rgba(255, 138, 61, 0.55);
  outline-offset: 3px;
}

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

.button--primary {
  background: var(--accent);
  box-shadow: 0 10px 28px rgba(255, 107, 53, 0.2);
}

.button--primary:hover:not(:disabled) {
  background: var(--accent-bright);
}

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

.button--ghost:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(300px, 1.2fr) minmax(260px, 0.8fr);
  gap: clamp(24px, 5vw, 72px);
  align-items: center;
}

.board {
  position: relative;
  width: 100%;
  max-width: 620px;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: clamp(22px, 4vw, 34px);
  background: #302c28;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
}

.board-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2%;
  padding: 3%;
}

.board-grid span {
  border: 1px solid rgba(255, 255, 255, 0.025);
  border-radius: clamp(11px, 2vw, 22px);
  background: rgba(0, 0, 0, 0.18);
}

.tile-layer {
  position: absolute;
  inset: 0;
}

.tile {
  position: absolute;
  display: grid;
  width: 22%;
  height: 22%;
  place-items: center;
  border-radius: clamp(11px, 2vw, 22px);
  background: #e8dfd0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 10px 25px rgba(0, 0, 0, 0.14);
  color: #332d29;
  font-size: clamp(1.65rem, 6vw, 4.3rem);
  font-weight: 900;
  letter-spacing: -0.055em;
  line-height: 1;
  transition: left 120ms ease, top 120ms ease;
}

.tile--pop {
  animation: tile-pop 180ms ease-out;
}

.tile[data-value="4"] { background: #d9ccb7; }
.tile[data-value="8"] { background: #f4a85b; color: #fffaf2; }
.tile[data-value="16"] { background: #f28b45; color: #fffaf2; }
.tile[data-value="32"] { background: #ec6d3c; color: #fffaf2; }
.tile[data-value="64"] { background: #e74b30; color: #fffaf2; }
.tile[data-value="128"] { background: #ecc94b; color: #2b241c; font-size: clamp(1.45rem, 5.2vw, 3.8rem); }
.tile[data-value="256"] { background: #e8b832; color: #2b241c; font-size: clamp(1.45rem, 5.2vw, 3.8rem); }
.tile[data-value="512"] { background: #dca41b; color: #fffaf2; font-size: clamp(1.45rem, 5.2vw, 3.8rem); }
.tile[data-value="1024"] { background: #bd7dff; color: #fff; font-size: clamp(1.1rem, 4.3vw, 3.15rem); }
.tile[data-value="2048"] { background: linear-gradient(145deg, #ff8a3d, #ff3d62); color: #fff; font-size: clamp(1.1rem, 4.3vw, 3.15rem); box-shadow: 0 0 38px rgba(255, 107, 53, 0.5); }
.tile--super { background: #171411; color: #fff; font-size: clamp(0.9rem, 3.7vw, 2.65rem); }

.game-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  padding: 24px;
  place-items: center;
  background: rgba(24, 22, 20, 0.84);
  backdrop-filter: blur(7px);
  animation: overlay-in 220ms ease-out;
}

.game-overlay[hidden] {
  display: none;
}

.overlay-card {
  width: min(380px, 100%);
  padding: clamp(24px, 5vw, 40px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #24211e;
  box-shadow: var(--shadow);
  text-align: center;
}

.overlay-kicker {
  margin: 0 0 8px;
  color: var(--accent-bright);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.overlay-card h2 {
  margin: 0;
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  letter-spacing: -0.045em;
}

.overlay-card > p:not(.overlay-kicker) {
  margin: 14px 0 24px;
  color: var(--muted);
  line-height: 1.55;
}

.overlay-actions {
  justify-content: center;
  flex-wrap: wrap;
}

.how-to-play {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px 20px;
  align-items: start;
  max-width: 400px;
}

.how-to-play__number {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent-bright);
  font-size: 0.78rem;
  font-weight: 900;
}

.how-to-play h2 {
  margin: 4px 0 10px;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  letter-spacing: -0.045em;
}

.how-to-play p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.key-hint {
  display: grid;
  grid-column: 2;
  grid-template-columns: repeat(3, 44px);
  gap: 7px;
  margin-top: 10px;
}

kbd {
  display: grid;
  width: 44px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-bottom-width: 3px;
  border-radius: 9px;
  background: var(--panel-soft);
  color: var(--ink);
  font-weight: 800;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: 38px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

.footer-mark {
  color: var(--accent-bright);
  font-weight: 800;
  letter-spacing: 0.08em;
}

@keyframes tile-pop {
  0% { transform: scale(0.65); opacity: 0.4; }
  72% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 780px) {
  .app-shell {
    width: min(620px, calc(100% - 28px));
    padding-top: 28px;
  }

  .hero {
    align-items: stretch;
    flex-direction: column;
    gap: 26px;
  }

  .scoreboard {
    min-width: 0;
  }

  .score-card {
    text-align: left;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .board {
    margin: 0 auto;
  }

  .how-to-play {
    margin-top: 10px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 20px, 480px);
    padding-top: 22px;
  }

  .subtitle {
    margin-top: 17px;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
    padding: 17px 0;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .button {
    padding-inline: 12px;
    font-size: 0.88rem;
  }

  .how-to-play {
    grid-template-columns: 1fr;
  }

  .how-to-play__number {
    display: none;
  }

  .key-hint {
    display: none;
  }

  footer {
    flex-direction: column;
  }
}

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