:root {
  --cyan: #40E0D0;
  --dark-cyan: #008B8B;
  --glass-bg: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.2);
  --cell-bg: rgba(0, 0, 0, 0.2);
  --text-main: #fff;
  --font-family: 'Inter', sans-serif;

  --grid-size: 362px;
  --cell-size: 75px;
  --gap: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #091a1f;
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.wave-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -2;
  overflow: hidden;
  background: radial-gradient(circle at center, #0f3038 0%, #03080a 100%);
}

.wave {
  position: absolute;
  width: 200vw;
  height: 200vw;
  background: rgba(64, 224, 208, 0.1);
  border-radius: 43%;
  left: -50vw;
  bottom: -160vw;
  transition: all 0.5s ease;
}

.wave1 {
  animation: waveSpin 25s infinite linear;
  background: rgba(64, 224, 208, 0.15);
}

.wave2 {
  animation: waveSpin 35s infinite linear;
  background: rgba(64, 224, 208, 0.1);
  border-radius: 40%;
  bottom: -155vw;
}

.wave3 {
  animation: waveSpin 45s infinite linear;
  background: rgba(64, 224, 208, 0.05);
  border-radius: 45%;
  bottom: -150vw;
}

body:hover .wave1 {
  animation-duration: 10s;
  background: rgba(64, 224, 208, 0.20);
  box-shadow: 0 0 30px rgba(64, 224, 208, 0.3);
}

body:hover .wave2 {
  animation-duration: 15s;
  background: rgba(64, 224, 208, 0.15);
}

body:hover .wave3 {
  animation-duration: 20s;
  background: rgba(64, 224, 208, 0.10);
}

@keyframes waveSpin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.container {
  position: relative;
  width: 100%;
  max-width: 1200px;
  padding: 2rem;
  z-index: 1;
}

header {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.title-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

h1 {
  font-size: 1.2rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: -1px;
  line-height: 1.1;
  text-shadow: 0 0 15px rgba(64, 224, 208, 0.6);
}

.score-container {
  display: flex;
  gap: 0.6rem;
}

.score-box {
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  padding: 0.5rem 0.9rem;
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3);
}

.score-label {
  font-size: 0.6rem;
  color: var(--cyan);
  font-weight: 900;
  letter-spacing: 1px;
}

#score,
#best-score {
  font-size: 1.1rem;
  font-weight: 900;
  color: #fff;
}

.controls {
  display: flex;
  gap: 1rem;
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  border: 1px solid var(--glass-border);
  padding: 0.8rem;
  border-radius: 16px;
  width: 100%;
}

button {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0.6rem 1.1rem;
  color: rgba(255, 255, 255, 0.7);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}

button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

button.active {
  color: #000;
  background: var(--cyan);
  box-shadow: 0 0 25px rgba(64, 224, 208, 0.6);
}

.play-area {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  width: max-content;
  margin: 0 auto;
  position: relative;
}

.game-wrapper {
  display: flex;
  gap: 2.2rem;
  align-items: center;
  justify-content: center;
  position: relative;
  width: max-content;
}

.indicator-wrapper {
  position: absolute;
  left: -75px;
  top: 0;
  height: 100%;
  display: none;
  justify-content: center;
  align-items: center;
  width: 60px;
}

.indicator-wrapper.visible {
  display: flex;
}

.indicator-arrow {
  width: 34px;
  height: 34px;
  color: var(--cyan);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  opacity: 0;
  transform: scale(0.5);
  overflow: visible;
}

.indicator-arrow.visible {
  opacity: 1;
}

.indicator-arrow.dir-0 {
  transform: scale(1.2) rotate(0deg);
}

.indicator-arrow.dir-1 {
  transform: scale(1.2) rotate(90deg);
}

.indicator-arrow.dir-2 {
  transform: scale(1.2) rotate(180deg);
}

.indicator-arrow.dir-3 {
  transform: scale(1.2) rotate(270deg);
}


.game-container {
  position: relative;
  width: var(--grid-size);
  height: var(--grid-size);
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: var(--gap);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(255, 255, 255, 0.05);
  box-sizing: border-box;
  touch-action: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
  width: 100%;
  height: 100%;
}

.grid-cell {
  width: 100%;
  height: 100%;
  background: var(--cell-bg);
  border-radius: 12px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}

.tile-container {
  position: absolute;
  top: var(--gap);
  left: var(--gap);
  right: var(--gap);
  bottom: var(--gap);
  pointer-events: none;
}

.tile {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.25rem;
  font-weight: 900;
  transition: transform 0.15s ease-in-out;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.tile-new {
  animation: appear 0.2s;
}

.tile-merged {
  z-index: 20;
  animation: pop 0.2s;
}

@keyframes appear {
  0% {
    scale: 0;
    opacity: 0;
  }

  100% {
    scale: 1;
    opacity: 1;
  }
}

@keyframes pop {
  0% {
    scale: 1;
  }

  50% {
    scale: 1.2;
  }

  100% {
    scale: 1;
  }
}

.tile-2 {
  background: rgba(255, 255, 255, 0.05);
  color: #ccc;
}

.tile-4 {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.tile-8 {
  background: rgba(64, 224, 208, 0.2);
  border-color: var(--cyan);
  color: var(--cyan);
}

.tile-16 {
  background: rgba(64, 224, 208, 0.4);
  border-color: var(--cyan);
  color: #fff;
  box-shadow: 0 0 15px rgba(64, 224, 208, 0.3);
}

.tile-32 {
  background: rgba(0, 139, 139, 0.5);
  border-color: var(--dark-cyan);
  color: #fff;
}

.tile-64 {
  background: rgba(0, 139, 139, 0.7);
  border-color: var(--cyan);
  box-shadow: 0 0 20px var(--dark-cyan);
}

.tile-128 {
  background: linear-gradient(135deg, rgba(64, 224, 208, 0.8), rgba(0, 139, 139, 0.8));
  font-size: 1.85rem;
}

.tile-256 {
  background: linear-gradient(135deg, rgba(0, 139, 139, 0.8), rgba(64, 224, 208, 0.8));
  font-size: 1.85rem;
}

.tile-512 {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(64, 224, 208, 0.8));
  font-size: 1.85rem;
  color: #000;
}

.tile-1024 {
  background: linear-gradient(135deg, #fff, var(--cyan));
  font-size: 1.5rem;
  color: #000;
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.tile-2048 {
  background: linear-gradient(135deg, var(--cyan), #fff);
  font-size: 1.5rem;
  color: #000;
  box-shadow: 0 0 15px var(--cyan);
}

.tile-4096,
.tile-8192 {
  font-size: 1.5rem;
  color: #000;
  background: #fff;
  box-shadow: 0 0 20px #fff;
}

.tile-16384,
.tile-32768,
.tile-65536 {
  font-size: 1.1rem;
  color: #000;
  background: linear-gradient(135deg, #fff, var(--cyan));
  border: 2px solid #fff;
  box-shadow: 0 0 25px var(--cyan);
  animation: pulseCyan 2s infinite alternate;
}

@keyframes pulseCyan {
  0% {
    transform: scale(1);
    box-shadow: 0 0 30px var(--dark-cyan);
  }

  100% {
    transform: scale(1.05);
    box-shadow: 0 0 60px var(--cyan);
  }
}

.game-message {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(15px);
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  animation: fadeIn 0.5s ease;
}

.game-message.game-over {
  display: flex;
}

.game-message.game-won {
  display: flex;
  background: rgba(64, 224, 208, 0.2);
}

@keyframes fadeIn {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

.game-message p {
  font-size: 4rem;
  font-weight: 900;
  margin-bottom: 2rem;
  color: #fff;
  text-shadow: 0 0 30px var(--cyan);
}

.retry-button {
  background: var(--cyan);
  color: #000;
  padding: 1.2rem 3rem;
  font-size: 1.5rem;
  font-weight: 900;
  border-radius: 12px;
  box-shadow: 0 0 20px rgba(64, 224, 208, 0.5);
}

.retry-button:hover {
  background: #fff;
  box-shadow: 0 0 30px #fff;
}

.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 15px;
  padding: 1.1rem;
  width: 240px;
  height: var(--grid-size);
  box-sizing: border-box;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.ai-panel h3 {
  font-size: 0.75rem;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0.6rem;
}

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.4rem;
  border-radius: 5px;
}

.stat-label {
  font-size: 0.5rem;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

.stat-value {
  font-size: 1rem;
  font-weight: 900;
  color: #fff;
}

.moves-eval {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.eval-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 5px;
  font-size: 0.65rem;
  font-family: monospace;
}

.eval-row.best {
  background: rgba(64, 224, 208, 0.2);
  border: 1px solid var(--cyan);
  box-shadow: 0 0 8px rgba(64, 224, 208, 0.3);
}

.dir {
  color: var(--cyan);
  font-family: var(--font-family);
  font-weight: 900;
}

.val {
  color: #fff;
}

.best-move {
  text-align: center;
  padding-top: 0.75rem;
  border-top: 1px solid var(--glass-border);
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.7);
}

#ai-action {
  color: var(--cyan);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: block;
  margin-top: 0.2rem;
}

@media (max-width: 1050px) {
  .play-area {
    width: 100%;
    align-items: center;
  }

  .controls,
  header {
    width: var(--grid-size);
  }

  .game-wrapper {
    flex-direction: column;
    gap: 0.8rem;
  }

  .indicator-wrapper {
    position: static;
    order: -1;
    width: 100%;
    height: 40px;
  }

  .indicator-arrow.dir-0 {
    transform: scale(1) rotate(0deg);
  }

  .indicator-arrow.dir-1 {
    transform: scale(1) rotate(90deg);
  }

  .indicator-arrow.dir-2 {
    transform: scale(1) rotate(180deg);
  }

  .indicator-arrow.dir-3 {
    transform: scale(1) rotate(270deg);
  }

  .ai-panel {
    width: var(--grid-size);
    height: auto;
    margin-top: 1.2rem;
  }
}

@media (max-width: 600px) {
  .wave {
    width: 150vh;
    height: 150vh;
    left: auto;
    right: -110vh;
    bottom: -25vh;
  }
  .wave2 { right: -105vh; bottom: -25vh; }
  .wave3 { right: -100vh; bottom: -25vh; }

  :root {
    --grid-size: 332px;
    --cell-size: 68px;
    --gap: 12px;
  }

  .container {
    padding: 1rem;
  }

  .play-area {
    gap: 1rem;
  }

  h1 {
    font-size: 1.8rem;
  }

  .score-box {
    padding: 0.8rem 1.5rem;
  }

  #score,
  #best-score {
    font-size: 1.5rem;
  }

  .tile {
    font-size: 2rem;
  }

  .tile-128,
  .tile-256,
  .tile-512 {
    font-size: 1.6rem;
  }

  .tile-1024,
  .tile-2048,
  .tile-4096,
  .tile-8192 {
    font-size: 1.3rem;
  }

  .tile-16384,
  .tile-32768,
  .tile-65536 {
    font-size: 1.1rem;
  }

  .ai-panel {
    width: var(--grid-size);
    padding: 1.5rem;
  }
}