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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #1a1a2e;
  color: #eee;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 8px 12px;
  background: #16213e;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 4px 0;
  gap: 8px;
}

.score-panel {
  display: flex;
  gap: 6px;
  flex: 1;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0f3460;
  border-radius: 8px;
  padding: 4px 12px;
  min-width: 70px;
  flex: 1;
}

.score-box.best {
  background: #533483;
}

.score-label {
  font-size: 10px;
  font-weight: 600;
  color: #a8a8c8;
  letter-spacing: 1px;
}

.score-value {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
}

.btn-restart {
  background: #e94560;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.btn-restart:active {
  background: #c73652;
  transform: scale(0.96);
}

.next-area {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 0;
}

.next-label {
  font-size: 12px;
  color: #a8a8c8;
  font-weight: 600;
  white-space: nowrap;
}

.next-blocks {
  display: flex;
  gap: 6px;
}

.next-block {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  animation: next-pop 300ms ease;
}

@keyframes next-pop {
  0%   { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.board-outer {
  position: relative;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.drop-zone {
  position: relative;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.03);
  border-radius: 8px 8px 0 0;
  border: 1px dashed rgba(255,255,255,0.1);
  border-bottom: none;
}

.active-block-wrapper {
  transition: transform 120ms ease;
}

.active-block {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: active-pulse 800ms ease-in-out infinite;
}

@keyframes active-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.arrow-hint {
  position: absolute;
  bottom: 2px;
  display: flex;
  gap: 16px;
  opacity: 0.3;
}

.arrow-left::after  { content: "◀"; font-size: 10px; }
.arrow-right::after { content: "▶"; font-size: 10px; }

.board {
  flex: 1;
  background: rgba(0,0,0,0.2);
  border-radius: 0 0 8px 8px;
  padding: 4px;
  min-height: 0;
  overflow: hidden;
}

.grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 3px;
  width: 100%;
  height: 100%;
}

.cell {
  border-radius: 4px;
  background: rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  transition: transform 100ms ease, background 150ms ease;
  position: relative;
}

.cell.filled {
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.cell.merge-pop {
  animation: merge-pop 300ms ease;
  z-index: 2;
}

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

@keyframes drop-in {
  0%   { transform: translateY(-100%); opacity: 0.5; }
  60%  { transform: translateY(0); opacity: 1; }
  75%  { transform: translateY(-4px); }
  100% { transform: translateY(0); }
}

.cell.drop-in {
  animation: drop-in 250ms ease-out;
}

/* Block colors */
.cell[data-value="2"]     { background: #3498db; color: #fff; }
.cell[data-value="4"]     { background: #2ecc71; color: #fff; }
.cell[data-value="8"]     { background: #e67e22; color: #fff; }
.cell[data-value="16"]    { background: #e74c3c; color: #fff; }
.cell[data-value="32"]    { background: #9b59b6; color: #fff; }
.cell[data-value="64"]    { background: #1abc9c; color: #fff; }
.cell[data-value="128"]   { background: #f39c12; color: #fff; }
.cell[data-value="256"]   { background: #c0392b; color: #fff; }
.cell[data-value="512"]   { background: #2980b9; color: #fff; }
.cell[data-value="1024"]  { background: #27ae60; color: #fff; font-size: 0.85em; }
.cell[data-value="2048"]  { background: #f1c40f; color: #1a1a2e; font-size: 0.85em; }
.cell[data-value="4096"]  { background: #8e44ad; color: #fff; font-size: 0.8em; }
.cell[data-value="8192"]  { background: #d35400; color: #fff; font-size: 0.75em; }

/* Active block color follows same scheme */
.active-block[data-value="2"]     { background: #3498db; color: #fff; }
.active-block[data-value="4"]     { background: #2ecc71; color: #fff; }
.active-block[data-value="8"]     { background: #e67e22; color: #fff; }
.active-block[data-value="16"]    { background: #e74c3c; color: #fff; }
.active-block[data-value="32"]    { background: #9b59b6; color: #fff; }
.active-block[data-value="64"]    { background: #1abc9c; color: #fff; }
.active-block[data-value="128"]   { background: #f39c12; color: #fff; }
.active-block[data-value="256"]   { background: #c0392b; color: #fff; }
.active-block[data-value="512"]   { background: #2980b9; color: #fff; }
.active-block[data-value="1024"]  { background: #27ae60; color: #fff; }
.active-block[data-value="2048"]  { background: #f1c40f; color: #1a1a2e; }
.active-block[data-value="4096"]  { background: #8e44ad; color: #fff; }
.active-block[data-value="8192"]  { background: #d35400; color: #fff; }

/* Next block preview colors */
.next-block[data-value="2"]     { background: #3498db; color: #fff; }
.next-block[data-value="4"]     { background: #2ecc71; color: #fff; }
.next-block[data-value="8"]     { background: #e67e22; color: #fff; }
.next-block[data-value="16"]    { background: #e74c3c; color: #fff; }
.next-block[data-value="32"]    { background: #9b59b6; color: #fff; }
.next-block[data-value="64"]    { background: #1abc9c; color: #fff; }
.next-block[data-value="128"]   { background: #f39c12; color: #fff; }
.next-block[data-value="256"]   { background: #c0392b; color: #fff; }
.next-block[data-value="512"]   { background: #2980b9; color: #fff; }
.next-block[data-value="1024"]  { background: #27ae60; color: #fff; }
.next-block[data-value="2048"]  { background: #f1c40f; color: #1a1a2e; }
.next-block[data-value="4096"]  { background: #8e44ad; color: #fff; }
.next-block[data-value="8192"]  { background: #d35400; color: #fff; }

.controls {
  display: flex;
  gap: 12px;
  padding: 10px 0 6px;
  width: 100%;
  justify-content: center;
}

.ctrl-btn {
  width: 60px;
  height: 48px;
  border-radius: 10px;
  border: none;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f3460;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

.ctrl-btn:active {
  background: #1a4a8a;
  transform: scale(0.94);
}

.btn-drop {
  width: 100px;
  font-size: 16px;
  background: #e94560;
}

.btn-drop:active {
  background: #c73652;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-content {
  text-align: center;
  background: #1a1a2e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 32px 40px;
}

.overlay-message {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 20px;
}

.btn-overlay {
  background: #e94560;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 14px 36px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.btn-overlay:active {
  background: #c73652;
  transform: scale(0.96);
}

@media (max-height: 640px) {
  .drop-zone { height: 40px; }
  .active-block { width: 36px; height: 36px; font-size: 15px; }
  .controls { padding: 6px 0 4px; }
  .ctrl-btn { height: 40px; }
  .next-block { width: 30px; height: 30px; font-size: 12px; }
}