:root {
  color-scheme: only light;
  --bg-start: #f8c173;
  --bg-end: #f06b6b;
  --panel: rgba(255, 255, 255, 0.85);
  --panel-strong: #fff1e1;
  --text-main: #2c1f18;
  --text-muted: rgba(44, 31, 24, 0.7);
  --accent: #ff6b3d;
  --accent-dark: #e3522c;
  --board: #b88d6a;
  --cell: rgba(255, 255, 255, 0.35);
  --tile-empty: rgba(255, 255, 255, 0.1);
  --tile-shadow: rgba(32, 18, 9, 0.2);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "Futura", "Trebuchet MS", "Gill Sans", sans-serif;
  color: var(--text-main);
  background: radial-gradient(circle at top, var(--bg-start), var(--bg-end));
}

body {
  overflow: hidden;
}

.app {
  min-height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: clamp(12px, 3vmin, 32px);
}

.screens {
  width: min(1200px, 100%);
  flex: 1;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: clamp(16px, 3vmin, 28px);
  opacity: 0;
  transform: translateY(20px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.35s ease;
}

.screen--active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.hero {
  width: min(720px, 100%);
  background: var(--panel);
  padding: clamp(18px, 4vmin, 40px);
  border-radius: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
  text-align: center;
}

.hero h1 {
  font-size: clamp(48px, 12vmin, 112px);
  margin: 0 0 12px;
  letter-spacing: 0.05em;
}

.badge {
  display: inline-block;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.2em;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--accent-dark);
}

.subtitle {
  margin: 0;
  font-size: clamp(16px, 2.3vmin, 22px);
  color: var(--text-muted);
}

.hero-actions {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:active {
  transform: translateY(2px) scale(0.98);
}

.btn--primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 12px 24px rgba(255, 107, 61, 0.3);
}

.btn--primary:hover {
  background: var(--accent-dark);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.7);
  color: var(--text-main);
}

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

.btn--play {
  font-size: 26px;
  padding: 18px 52px;
  animation: pulse 1.6s ease-in-out infinite;
}

.btn--small {
  font-size: 12px;
  padding: 6px 16px;
}

.howto {
  width: min(720px, 100%);
  background: rgba(255, 255, 255, 0.6);
  padding: 0 clamp(12px, 2.6vmin, 22px);
  border-radius: 24px;
  max-height: 0;
  opacity: 0;
  transform: translateY(-10px);
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease, transform 0.3s ease;
  text-align: center;
}

.howto--open {
  max-height: 220px;
  opacity: 1;
  padding: clamp(12px, 2.6vmin, 22px);
  transform: translateY(0);
}

.howto h2 {
  margin: 0 0 8px;
}

.howto ul {
  padding-left: 20px;
  margin: 0;
  color: var(--text-muted);
  display: inline-block;
  text-align: left;
}

.victory-card {
  width: min(680px, 100%);
  background: var(--panel);
  padding: clamp(20px, 4vmin, 36px);
  border-radius: 28px;
  text-align: center;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.2);
}

.victory-card h2 {
  margin: 10px 0 8px;
  font-size: clamp(36px, 7vmin, 72px);
}

.victory-actions {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.game-header {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
}

.title-block .title {
  font-size: clamp(32px, 6vmin, 56px);
  font-weight: 700;
}

.title-block .subtitle {
  color: var(--text-muted);
}

.scoreboard {
  display: flex;
  gap: 12px;
}

.score {
  min-width: 110px;
  background: var(--panel);
  padding: 12px 16px;
  border-radius: 16px;
  text-align: center;
  font-size: 14px;
}

.score strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.board-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.board {
  width: min(86vmin, 520px);
  aspect-ratio: 1 / 1;
  background: var(--board);
  border-radius: 28px;
  padding: clamp(10px, 2.4vmin, 18px);
  position: relative;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
  touch-action: none;
}

.cell-layer,
.tile-layer {
  position: absolute;
  inset: clamp(10px, 2.4vmin, 18px);
  gap: clamp(10px, 2.4vmin, 18px);
}

.cell {
  background: var(--cell);
  border-radius: 16px;
}

.cell-layer {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

.tile-layer {
  pointer-events: none;
  position: absolute;
  --cell-size: 0px;
  --gap: 0px;
}

.tile {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 16px;
  font-weight: 700;
  font-size: clamp(20px, 5vmin, 42px);
  color: #3a2614;
  background: var(--tile-empty);
  box-shadow: 0 10px 20px var(--tile-shadow);
  transform: translate(var(--tx, 0px), var(--ty, 0px));
  transition: transform 0.15s ease-out;
}

.tile__value {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  transform-origin: center;
}

.tile--new {
}

.tile--new {
  animation: tile-pop 0.16s ease;
}

.tile--merge {
  animation: tile-merge 0.16s ease;
}

.tile--merge-out {
  animation: merge-out 0.18s ease-out forwards;
}
.tile--small {
  font-size: clamp(18px, 4.2vmin, 32px);
}

.tile--smaller {
  font-size: clamp(16px, 3.5vmin, 28px);
}

.tile--2 {
  background: #f3e1d4;
}
.tile--4 {
  background: #f2d0b1;
}
.tile--8 {
  background: #f2b27f;
  color: #fff;
}
.tile--16 {
  background: #ef9966;
  color: #fff;
}
.tile--32 {
  background: #ed7d57;
  color: #fff;
}
.tile--64 {
  background: #ea6147;
  color: #fff;
}
.tile--128 {
  background: #f3ce6b;
}
.tile--256 {
  background: #f1c248;
}
.tile--512 {
  background: #f0b531;
  color: #fff;
}
.tile--1024 {
  background: #e8a114;
  color: #fff;
}
.tile--2048 {
  background: #e2871a;
  color: #fff;
  box-shadow: 0 0 30px rgba(226, 135, 26, 0.6);
}

.hint {
  margin: 0;
  color: var(--panel-strong);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(18, 10, 5, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal--visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: min(420px, 90vw);
  background: #fff6ef;
  padding: 24px;
  border-radius: 24px;
  text-align: center;
  transform: translateY(12px) scale(0.96);
  transition: transform 0.25s ease;
}

.modal--visible .modal-card {
  transform: translateY(0) scale(1);
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@keyframes tile-pop {
  from {
    transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(0.2);
  }
  to {
    transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(1);
  }
}

@keyframes tile-merge {
  0% {
    filter: brightness(1);
    box-shadow: 0 10px 20px var(--tile-shadow);
    transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(1);
  }
  50% {
    filter: brightness(1.15);
    box-shadow: 0 14px 28px rgba(32, 18, 9, 0.35);
    transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(1.06);
  }
  100% {
    filter: brightness(1);
    box-shadow: 0 10px 20px var(--tile-shadow);
    transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(1);
  }
}

@keyframes merge-out {
  0%,
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 12px 24px rgba(255, 107, 61, 0.3);
  }
  50% {
    transform: scale(1.04);
    box-shadow: 0 18px 34px rgba(255, 107, 61, 0.45);
  }
}

@media (max-width: 860px) {
  .game-header {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .scoreboard,
  .controls {
    justify-content: center;
  }
}
