@import url(fonts/clear-sans.css);
html,
body {
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #0f0f23 0%, #1a1a3a 100%);
  color: #e6e6fa;
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 18px;
}

body {
  margin: 40px 0;
}

/* Header styles */
.heading {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.heading:after {
  content: "";
  display: block;
  clear: both;
}

/* Desktop layout - title left, scores right */
h1.title {
  font-size: 80px;
  font-weight: bold;
  margin: 0;
  background: linear-gradient(45deg, #ffd700, #ffb347);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

/* Hide mobile elements on desktop */
.mobile-header-bar {
  display: none;
}

/* Mobile hamburger menu - hidden by default */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: #ffd700;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: background-color 0.3s ease;
}

.mobile-menu-btn:hover {
  background-color: rgba(255, 215, 0, 0.1);
}

.mobile-refresh-btn {
  display: none;
  background: none;
  border: none;
  color: #ffd700;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.mobile-refresh-btn:hover {
  background-color: rgba(255, 215, 0, 0.1);
  transform: rotate(180deg);
}

/* Restart button spin animation */
.mobile-refresh-btn.spinning {
  animation: spinRestart 2s linear;
  background-color: rgba(255, 215, 0, 0.3) !important;
  transform-origin: center center !important;
  display: inline-flex !important;
}

@keyframes spinRestart {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(720deg);
  }
}

/* Game Action Buttons Below Game */
.game-actions-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
  padding: 20px 24px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(15px);
  border-radius: 20px;
  max-width: 220px;
  margin-left: auto;
  margin-right: auto;
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.game-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  background: rgba(255, 255, 255, 0.25);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(8px);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.game-action-btn:hover {
  background: rgba(255, 215, 0, 0.4);
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(255, 215, 0, 0.3);
  border-color: rgba(255, 215, 0, 0.4);
}

.game-action-btn:active {
  transform: translateY(0);
}

.game-action-btn.disabled {
  background: rgba(100, 100, 100, 0.2);
  cursor: not-allowed;
  opacity: 0.5;
  pointer-events: none;
}

.game-action-btn.disabled:hover {
  background: rgba(100, 100, 100, 0.2);
  transform: none;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
}

.game-action-btn.disabled .action-icon {
  color: #666;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.action-icon {
  width: 24px;
  height: 24px;
  color: #d4c4a8;
  transition: transform 0.3s ease, color 0.3s ease;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
  flex-shrink: 0;
}

.power-up-counter {
  position: absolute;
  top: 2px;
  right: 2px;
  background: #ffd700;
  color: #1a1a3a;
  font-size: 10px;
  font-weight: bold;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

.power-up-counter.zero {
  background: #666;
  color: #ccc;
}

.game-action-btn:hover .action-icon {
  color: #ffd700;
  filter: drop-shadow(0 2px 4px rgba(255, 215, 0, 0.4));
}

/* Specific button animations */
.undo-btn.undoing .action-icon {
  animation: undoRotate 0.8s ease-in-out;
}

.replace-btn.replacing .action-icon {
  animation: replaceFlip 1s ease-in-out;
}

.menu-btn.pulsing .action-icon {
  animation: pulse 0.8s ease-in-out;
}

@keyframes undoRotate {
  0% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(-180deg) scale(1.2);
  }
  100% {
    transform: rotate(-360deg) scale(1);
  }
}

@keyframes replaceFlip {
  0% {
    transform: rotateY(0deg);
  }
  50% {
    transform: rotateY(180deg) scale(1.1);
  }
  100% {
    transform: rotateY(360deg) scale(1);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

/* Mobile responsive */
@media screen and (max-width: 520px) {
  .game-actions-container {
    max-width: 200px;
    gap: 12px;
    padding: 16px 20px;
  }

  .game-action-btn {
    width: 48px;
    height: 48px;
  }

  .action-icon {
    width: 22px;
    height: 22px;
  }
}

/* Restart Animation Overlay */
.restart-animation-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 15, 35, 0.98);
  backdrop-filter: blur(15px);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.restart-animation-overlay.active {
  opacity: 1;
  visibility: visible;
}

.restart-spinner {
  width: 80px;
  height: 80px;
  border: 4px solid rgba(255, 215, 0, 0.2);
  border-top: 4px solid #ffd700;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

.restart-text {
  color: #ffd700;
  font-size: 18px;
  font-weight: 600;
  text-shadow: 0 2px 10px rgba(255, 215, 0, 0.3);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

/* Mobile Menu Popup - Premium Design matching other modals */
.mobile-menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 15, 35, 0.95);
  z-index: 1000;
  animation: fadeIn 0.4s ease;
}

.mobile-menu-overlay.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0px;
  box-sizing: border-box;
}

.mobile-menu-content {
  background: linear-gradient(135deg, #2d1b69, #1a1a3a);
  border-radius: 12px;
  padding: 0;
  width: 90%;
  max-width: 350px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 8px 32px rgba(45, 27, 105, 0.3);
  border: 2px solid rgba(255, 215, 0, 0.1);
  margin: 10px;
  overflow: hidden;
  animation: slideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.mobile-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(
    135deg,
    rgba(255, 215, 0, 0.1),
    rgba(255, 179, 71, 0.05)
  );
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
}

.mobile-menu-header h2 {
  margin: 0;
  color: #ffd700;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  background: linear-gradient(45deg, #ffd700, #ffb347);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.5px;
}

.mobile-menu-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: linear-gradient(135deg, #6c757d, #495057);
  border: none;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 50%;
  font-weight: bold;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(108, 117, 125, 0.4);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-menu-close:hover {
  transform: scale(1.1);
}

.mobile-menu-items {
  padding: 20px 24px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mobile-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
  text-decoration: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.mobile-menu-item:hover {
  background: rgba(255, 215, 0, 0.12);
  border-color: rgba(255, 215, 0, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 215, 0, 0.2);
}

.mobile-menu-item.restart-button {
  background: linear-gradient(135deg, #ffd700, #ffb347);
  color: #1a1a3a;
  border-color: rgba(255, 215, 0, 0.3);
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
  width: 100%;
  padding: 16px 20px;
  border-radius: 12px;
  display: flex;
  align-items: center;
}

.mobile-menu-item.restart-button:hover {
  background: linear-gradient(135deg, #ffed4e, #ffc947);
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(255, 215, 0, 0.4);
}

.menu-icon {
  margin-right: 14px;
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@-webkit-keyframes move-up {
  0% {
    top: 25px;
    opacity: 1;
  }

  100% {
    top: -50px;
    opacity: 0;
  }
}
@-moz-keyframes move-up {
  0% {
    top: 25px;
    opacity: 1;
  }

  100% {
    top: -50px;
    opacity: 0;
  }
}
@keyframes move-up {
  0% {
    top: 25px;
    opacity: 1;
  }

  100% {
    top: -50px;
    opacity: 0;
  }
}
.scores-container {
  float: right;
  text-align: right;
}

.score-container,
.best-container {
  position: relative;
  display: inline-block;
  background: linear-gradient(135deg, #2d1b69, #11998e);
  padding: 15px 25px;
  font-size: 25px;
  height: 25px;
  line-height: 47px;
  font-weight: bold;
  border-radius: 3px;
  color: #ffffff;
  margin-top: 8px;
  text-align: center;
  box-shadow: 0 4px 15px rgba(45, 27, 105, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.score-container:after,
.best-container:after {
  position: absolute;
  width: 100%;
  top: 10px;
  left: 0;
  text-transform: uppercase;
  font-size: 13px;
  line-height: 13px;
  text-align: center;
  color: #b8b8ff;
}
.score-container .score-addition,
.best-container .score-addition {
  position: absolute;
  right: 30px;
  font-size: 25px;
  line-height: 25px;
  font-weight: bold;
  color: #f5576c !important;
  text-shadow: 0 2px 4px rgba(245, 87, 108, 0.6);
  z-index: 100;
  -webkit-animation: move-up 600ms ease-in;
  -moz-animation: move-up 600ms ease-in;
  animation: move-up 600ms ease-in;
  -webkit-animation-fill-mode: both;
  -moz-animation-fill-mode: both;
  animation-fill-mode: both;
}

.score-container:after {
  content: "Score";
}

.best-container:after {
  content: "Best";
}

p {
  margin-top: 0;
  margin-bottom: 10px;
  line-height: 1.65;
}

a {
  color: #ffd700;
  font-weight: bold;
  text-decoration: underline;
  cursor: pointer;
}

strong.important {
  text-transform: uppercase;
}

hr {
  border: none;
  border-bottom: 1px solid #4a4a6a;
  margin-top: 20px;
  margin-bottom: 30px;
}

.container {
  width: 500px;
  margin: 0 auto;
  padding: 0 10px;
}

@-webkit-keyframes fade-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
@-moz-keyframes fade-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
@keyframes fade-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
.game-container {
  margin-top: 40px;
  position: relative;
  padding: 15px;
  cursor: default;
  -webkit-touch-callout: none;
  -ms-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -ms-touch-action: manipulation;
  touch-action: none;
  background: linear-gradient(135deg, #2d1b69, #1a1a3a);
  border-radius: 6px;
  width: 500px;
  height: 500px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  box-shadow: 0 8px 32px rgba(45, 27, 105, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  -webkit-tap-highlight-color: transparent;
}
.game-container .game-message {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 15, 35, 0.9);
  z-index: 100;
  text-align: center;
  -webkit-animation: fade-in 800ms ease 1200ms;
  -moz-animation: fade-in 800ms ease 1200ms;
  animation: fade-in 800ms ease 1200ms;
  -webkit-animation-fill-mode: both;
  -moz-animation-fill-mode: both;
  animation-fill-mode: both;
}
.game-container .game-message p {
  font-size: 60px;
  font-weight: bold;
  height: 60px;
  line-height: 60px;
  margin-top: 222px;
}
.game-container .game-message .lower {
  display: block;
  margin-top: 59px;
}
.game-container .game-message a {
  display: inline-block;
  background: linear-gradient(135deg, #ffd700, #ffb347);
  border-radius: 3px;
  padding: 0 20px;
  text-decoration: none;
  color: #1a1a3a;
  height: 40px;
  line-height: 42px;
  margin-left: 9px;
  font-weight: bold;
  box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
}
.game-container .game-message a.keep-playing-button {
  display: none;
}
.game-container .game-message.game-won {
  background: rgba(237, 194, 46, 0.5);
  color: #f9f6f2;
}
.game-container .game-message.game-won a.keep-playing-button {
  display: inline-block;
}
.game-container .game-message.game-won,
.game-container .game-message.game-over {
  display: block;
}

.grid-container {
  position: absolute;
  z-index: 1;
  /* top: 0;
  left: 0; */
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  transform: translateZ(0);
}

.grid-row {
  margin-bottom: 15px;
}
.grid-row:last-child {
  margin-bottom: 0;
}
.grid-row:after {
  content: "";
  display: block;
  clear: both;
}

.grid-cell {
  width: 106.25px;
  height: 106.25px;
  margin-right: 15px;
  float: left;
  border-radius: 3px;
  background: rgba(45, 27, 105, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.grid-cell:last-child {
  margin-right: 0;
}

.tile-container {
  position: absolute;
  z-index: 2;
  /* top: 0;
  left: 0; */
  -webkit-touch-callout: none;
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  transform: translateZ(0);
  will-change: contents;
}

.tile,
.tile .tile-inner {
  width: 107px;
  height: 107px;
  line-height: 107px;
}
.tile.tile-position-1-1 {
  -webkit-transform: translate(0px, 0px);
  -moz-transform: translate(0px, 0px);
  -ms-transform: translate(0px, 0px);
  transform: translate(0px, 0px);
}
.tile.tile-position-1-2 {
  -webkit-transform: translate(0px, 121px);
  -moz-transform: translate(0px, 121px);
  -ms-transform: translate(0px, 121px);
  transform: translate(0px, 121px);
}
.tile.tile-position-1-3 {
  -webkit-transform: translate(0px, 242px);
  -moz-transform: translate(0px, 242px);
  -ms-transform: translate(0px, 242px);
  transform: translate(0px, 242px);
}
.tile.tile-position-1-4 {
  -webkit-transform: translate(0px, 363px);
  -moz-transform: translate(0px, 363px);
  -ms-transform: translate(0px, 363px);
  transform: translate(0px, 363px);
}
.tile.tile-position-2-1 {
  -webkit-transform: translate(121px, 0px);
  -moz-transform: translate(121px, 0px);
  -ms-transform: translate(121px, 0px);
  transform: translate(121px, 0px);
}
.tile.tile-position-2-2 {
  -webkit-transform: translate(121px, 121px);
  -moz-transform: translate(121px, 121px);
  -ms-transform: translate(121px, 121px);
  transform: translate(121px, 121px);
}
.tile.tile-position-2-3 {
  -webkit-transform: translate(121px, 242px);
  -moz-transform: translate(121px, 242px);
  -ms-transform: translate(121px, 242px);
  transform: translate(121px, 242px);
}
.tile.tile-position-2-4 {
  -webkit-transform: translate(121px, 363px);
  -moz-transform: translate(121px, 363px);
  -ms-transform: translate(121px, 363px);
  transform: translate(121px, 363px);
}
.tile.tile-position-3-1 {
  -webkit-transform: translate(242px, 0px);
  -moz-transform: translate(242px, 0px);
  -ms-transform: translate(242px, 0px);
  transform: translate(242px, 0px);
}
.tile.tile-position-3-2 {
  -webkit-transform: translate(242px, 121px);
  -moz-transform: translate(242px, 121px);
  -ms-transform: translate(242px, 121px);
  transform: translate(242px, 121px);
}
.tile.tile-position-3-3 {
  -webkit-transform: translate(242px, 242px);
  -moz-transform: translate(242px, 242px);
  -ms-transform: translate(242px, 242px);
  transform: translate(242px, 242px);
}
.tile.tile-position-3-4 {
  -webkit-transform: translate(242px, 363px);
  -moz-transform: translate(242px, 363px);
  -ms-transform: translate(242px, 363px);
  transform: translate(242px, 363px);
}
.tile.tile-position-4-1 {
  -webkit-transform: translate(363px, 0px);
  -moz-transform: translate(363px, 0px);
  -ms-transform: translate(363px, 0px);
  transform: translate(363px, 0px);
}
.tile.tile-position-4-2 {
  -webkit-transform: translate(363px, 121px);
  -moz-transform: translate(363px, 121px);
  -ms-transform: translate(363px, 121px);
  transform: translate(363px, 121px);
}
.tile.tile-position-4-3 {
  -webkit-transform: translate(363px, 242px);
  -moz-transform: translate(363px, 242px);
  -ms-transform: translate(363px, 242px);
  transform: translate(363px, 242px);
}
.tile.tile-position-4-4 {
  -webkit-transform: translate(363px, 363px);
  -moz-transform: translate(363px, 363px);
  -ms-transform: translate(363px, 363px);
  transform: translate(363px, 363px);
}

.tile {
  position: absolute;
  -webkit-transition: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  -moz-transition: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  transition: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-transition-property: -webkit-transform;
  -moz-transition-property: -moz-transform;
  transition-property: transform;
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  transform: translateZ(0);
  will-change: transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.tile .tile-inner {
  border-radius: 3px;
  background: linear-gradient(135deg, #4a4a6a, #6a6a8a);
  text-align: center;
  font-weight: bold;
  z-index: 10;
  font-size: 55px;
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.tile.tile-2 .tile-inner {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.tile.tile-4 .tile-inner {
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(240, 147, 251, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.tile.tile-8 .tile-inner {
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(79, 172, 254, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.tile.tile-16 .tile-inner {
  background: linear-gradient(135deg, #43e97b, #38f9d7);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(67, 233, 123, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.tile.tile-32 .tile-inner {
  background: linear-gradient(135deg, #fa709a, #fee140);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(250, 112, 154, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.tile.tile-64 .tile-inner {
  background: linear-gradient(135deg, #a8edea, #fed6e3);
  color: #2d1b69;
  box-shadow: 0 4px 15px rgba(168, 237, 234, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.tile.tile-128 .tile-inner {
  background: linear-gradient(135deg, #ffecd2, #fcb69f);
  color: #2d1b69;
  box-shadow: 0 6px 20px rgba(255, 236, 210, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  font-size: 45px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
@media screen and (max-width: 520px) {
  .tile.tile-128 .tile-inner {
    font-size: 25px;
  }
}
.tile.tile-256 .tile-inner {
  background: linear-gradient(135deg, #ffd89b, #19547b);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(255, 216, 155, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  font-size: 45px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
@media screen and (max-width: 520px) {
  .tile.tile-256 .tile-inner {
    font-size: 25px;
  }
}
.tile.tile-512 .tile-inner {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #ffffff;
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  font-size: 45px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
@media screen and (max-width: 520px) {
  .tile.tile-512 .tile-inner {
    font-size: 25px;
  }
}
.tile.tile-1024 .tile-inner {
  background: linear-gradient(135deg, #ffd700, #ffb347);
  color: #1a1a3a;
  box-shadow: 0 8px 30px rgba(255, 215, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  font-size: 35px;
  font-weight: 900;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
@media screen and (max-width: 520px) {
  .tile.tile-1024 .tile-inner {
    font-size: 15px;
  }
}
.tile.tile-2048 .tile-inner {
  background: linear-gradient(135deg, #ff6b6b, #ffd93d);
  color: #1a1a3a;
  box-shadow: 0 10px 40px rgba(255, 107, 107, 0.7),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
  font-size: 35px;
  font-weight: 900;
  animation: glow 2s ease-in-out infinite alternate;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
@media screen and (max-width: 520px) {
  .tile.tile-2048 .tile-inner {
    font-size: 15px;
  }
}
.tile.tile-super .tile-inner {
  background: linear-gradient(135deg, #2d1b69, #11998e);
  color: #ffd700;
  font-size: 30px;
  box-shadow: 0 10px 40px rgba(45, 27, 105, 0.8),
    inset 0 2px 0 rgba(255, 215, 0, 0.3);
  font-weight: 900;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
@media screen and (max-width: 520px) {
  .tile.tile-super .tile-inner {
    font-size: 10px;
  }
}

@-webkit-keyframes appear {
  0% {
    opacity: 0;
    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);
  }

  100% {
    opacity: 1;
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
  }
}
@-moz-keyframes appear {
  0% {
    opacity: 0;
    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);
  }

  100% {
    opacity: 1;
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
  }
}
@keyframes appear {
  0% {
    opacity: 0;
    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);
  }

  100% {
    opacity: 1;
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
  }
}

@keyframes glow {
  0% {
    box-shadow: 0 10px 40px rgba(255, 107, 107, 0.7),
      inset 0 2px 0 rgba(255, 255, 255, 0.5);
  }
  100% {
    box-shadow: 0 15px 50px rgba(255, 107, 107, 1),
      inset 0 2px 0 rgba(255, 255, 255, 0.7);
  }
}
.tile-new .tile-inner {
  -webkit-animation: appear 80ms cubic-bezier(0.23, 1, 0.32, 1) 10ms;
  -moz-animation: appear 80ms cubic-bezier(0.23, 1, 0.32, 1) 10ms;
  animation: appear 80ms cubic-bezier(0.23, 1, 0.32, 1) 10ms;
  -webkit-animation-fill-mode: backwards;
  -moz-animation-fill-mode: backwards;
  animation-fill-mode: backwards;
}

@-webkit-keyframes pop {
  0% {
    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);
  }

  50% {
    -webkit-transform: scale(1.2);
    -moz-transform: scale(1.2);
    -ms-transform: scale(1.2);
    transform: scale(1.2);
  }

  100% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
  }
}
@-moz-keyframes pop {
  0% {
    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);
  }

  50% {
    -webkit-transform: scale(1.2);
    -moz-transform: scale(1.2);
    -ms-transform: scale(1.2);
    transform: scale(1.2);
  }

  100% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
  }
}
@keyframes pop {
  0% {
    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);
  }

  50% {
    -webkit-transform: scale(1.2);
    -moz-transform: scale(1.2);
    -ms-transform: scale(1.2);
    transform: scale(1.2);
  }

  100% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
  }
}
.tile-merged .tile-inner {
  z-index: 20;
  -webkit-animation: pop 120ms cubic-bezier(0.23, 1, 0.32, 1) 40ms;
  -moz-animation: pop 120ms cubic-bezier(0.23, 1, 0.32, 1) 40ms;
  animation: pop 120ms cubic-bezier(0.23, 1, 0.32, 1) 40ms;
  -webkit-animation-fill-mode: backwards;
  -moz-animation-fill-mode: backwards;
  animation-fill-mode: backwards;
}

/* Merging tiles - smooth fade out during animation to prevent flickering */
.tile-merging {
  z-index: 1;
}

.tile-merging .tile-inner {
  opacity: 0.1;
  transition: opacity 100ms ease-out;
}

/* Delayed merging tiles - gradual fade for smoother animation */
.tile-merging-delayed {
  z-index: 1;
}

.tile-merging-delayed .tile-inner {
  /* Transitions are applied via JavaScript for precise timing */
}

.above-game:after {
  content: "";
  display: block;
  clear: both;
}

.game-intro {
  float: left;
  line-height: 42px;
  margin-bottom: 0;
}

.restart-button {
  display: inline-block;
  background: linear-gradient(135deg, #ffd700, #ffb347);
  border-radius: 3px;
  padding: 0 20px;
  text-decoration: none;
  color: #1a1a3a;
  height: 40px;
  line-height: 42px;
  display: block;
  text-align: center;
  float: right;
  font-weight: bold;
  box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
  transition: all 0.3s ease;
}

.restart-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4);
}

.game-explanation {
  margin-top: 50px;
}

@media screen and (max-width: 520px) {
  html,
  body {
    font-size: 15px;
  }

  body {
    margin: 15px 0;
    padding: 0px;
  }

  .container {
    width: 100%;
    margin: 0 auto;
    padding: 0 10px;
    box-sizing: border-box;
  }

  /* Mobile header layout */
  .heading {
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 20px;
    width: 100%;
  }

  /* Hide desktop title */
  .desktop-title {
    display: none !important;
  }

  /* Mobile header bar first */
  .mobile-header-bar {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    width: 100%;
    padding: 0;
  }

  .mobile-menu-btn,
  .mobile-refresh-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    min-width: 50px;
    flex-shrink: 0;
    font-size: 24px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
  }

  .mobile-header-bar h1.title {
    font-size: 36px;
    margin: 0;
    text-align: center;
    flex: 1;
    padding: 0 20px;
    white-space: nowrap;
    font-weight: bold;
  }

  /* Mobile scores layout - below header bar */
  .scores-container {
    display: flex;
    gap: 10px;
    width: 100%;
    float: none;
    text-align: center;
    margin: 0 0 18px 0;
    padding: 0;
  }

  .score-container,
  .best-container {
    flex: 1;
    margin-top: 0;
    padding: 10px 6px 14px 6px;
    min-width: 0;
    font-size: 24px;
    height: auto;
    line-height: 1.1;
    box-sizing: border-box;
    border-radius: 14px;
    background: linear-gradient(135deg, #1a4a5c, #0d3544);
    color: #ffffff;
    font-weight: bold;
    box-shadow: 0 4px 20px rgba(26, 74, 92, 0.4),
      0 1px 0 rgba(255, 255, 255, 0.1) inset, 0 -1px 0 rgba(0, 0, 0, 0.2) inset;
    border: 1px solid rgba(0, 212, 255, 0.3);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
  }

  .score-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(26, 74, 92, 0.5),
      0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 -1px 0 rgba(0, 0, 0, 0.2) inset;
  }

  .best-container {
    background: linear-gradient(135deg, #1a4a3c, #0d3525);
    box-shadow: 0 4px 20px rgba(26, 74, 60, 0.4),
      0 1px 0 rgba(255, 255, 255, 0.1) inset, 0 -1px 0 rgba(0, 0, 0, 0.2) inset;
    border: 1px solid rgba(0, 255, 136, 0.3);
  }

  .best-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(26, 74, 60, 0.5),
      0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 -1px 0 rgba(0, 0, 0, 0.2) inset;
  }

  .score-container:after,
  .best-container:after {
    font-size: 11px;
    top: 10px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 700;
    letter-spacing: 1.2px;
    position: absolute;
    width: 100%;
    left: 0;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }

  .score-number {
    margin-top: 6px;
    font-size: 20px;
    font-weight: 900;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    letter-spacing: 0.5px;
  }

  /* Mobile game intro and restart button */
  .game-intro {
    width: 100%;
    display: block;
    box-sizing: border-box;
    line-height: 1.65;
    float: none;
    text-align: center;
    margin-bottom: 20px;
    font-size: 15px;
    color: #e6e6fa;
    font-weight: 500;
    letter-spacing: 0.3px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    padding: 0;
  }

  .game-intro strong {
    background: linear-gradient(45deg, #ffd700, #ffb347);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
    text-shadow: none;
  }

  .restart-button {
    width: 100%;
    margin: 0;
    display: block;
    padding: 16px 24px;
    font-size: 17px;
    font-weight: 600;
    border-radius: 12px;
    background: linear-gradient(135deg, #ffd700, #ffb347);
    color: #1a1a3a;
    text-decoration: none;
    text-align: center;
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4),
      0 1px 0 rgba(255, 255, 255, 0.2) inset;
    border: 1px solid rgba(255, 215, 0, 0.3);
    transition: all 0.3s ease;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
  }

  .restart-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.5),
      0 1px 0 rgba(255, 255, 255, 0.3) inset;
  }

  .heading {
    margin-bottom: 15px;
  }

  /* Additional responsive breakpoint for very small screens */
  @media screen and (max-width: 360px) {
    .mobile-header-bar h1.title {
      font-size: 24px;
    }

    .mobile-menu-btn,
    .mobile-refresh-btn {
      width: 36px;
      height: 36px;
      font-size: 20px;
    }

    .score-container,
    .best-container {
      padding: 10px 6px;
      font-size: 16px;
    }

    .score-container:after,
    .best-container:after {
      font-size: 10px;
      top: 6px;
    }
  }

  /* Responsive breakpoint for larger mobile screens */
  @media screen and (min-width: 521px) and (max-width: 768px) {
    .heading {
      margin-bottom: 25px;
    }

    h1.title {
      font-size: 60px;
    }

    .score-container,
    .best-container {
      padding: 18px 20px;
      font-size: 22px;
    }
  }

  .heading {
    margin-bottom: 0px;
  }

  .game-intro {
    width: 100%;
    display: block;
    box-sizing: border-box;
    line-height: 1.65;
    float: none;
    text-align: center;
    margin-bottom: 20px;
    font-size: 15px;
    color: #e6e6fa;
    font-weight: 500;
    letter-spacing: 0.3px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    padding: 0;
  }

  .restart-button {
    width: 42%;
    padding: 0;
    display: block;
    box-sizing: border-box;
    margin-top: 2px;
  }

  .game-container {
    margin-top: 17px;
    position: relative;
    padding: 10px;
    cursor: default;
    -webkit-touch-callout: none;
    -ms-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    background: linear-gradient(135deg, #2d1b69, #1a1a3a);
    border-radius: 6px;
    width: calc(100vw - 40px);
    max-width: 320px;
    height: calc(100vw - 40px);
    max-height: 320px;
    margin: 0 auto;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    box-shadow: 0 8px 32px rgba(45, 27, 105, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    -webkit-tap-highlight-color: transparent;
  }
  .game-container .game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(15, 15, 35, 0.9);
    z-index: 100;
    text-align: center;
    -webkit-animation: fade-in 800ms ease 1200ms;
    -moz-animation: fade-in 800ms ease 1200ms;
    animation: fade-in 800ms ease 1200ms;
    -webkit-animation-fill-mode: both;
    -moz-animation-fill-mode: both;
    animation-fill-mode: both;
  }
  .game-container .game-message p {
    font-size: 60px;
    font-weight: bold;
    height: 60px;
    line-height: 60px;
    margin-top: 222px;
  }
  .game-container .game-message .lower {
    display: block;
    margin-top: 59px;
  }
  .game-container .game-message a {
    display: inline-block;
    background: linear-gradient(135deg, #ffd700, #ffb347);
    border-radius: 3px;
    padding: 0 20px;
    text-decoration: none;
    color: #1a1a3a;
    height: 40px;
    line-height: 42px;
    margin-left: 9px;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
  }
  .game-container .game-message a.keep-playing-button {
    display: none;
  }
  .game-container .game-message.game-won {
    background: rgba(255, 215, 0, 0.2);
    color: #ffd700;
  }
  .game-container .game-message.game-won a.keep-playing-button {
    display: inline-block;
  }
  .game-container .game-message.game-won,
  .game-container .game-message.game-over {
    display: block;
  }

  .grid-container {
    position: absolute;
    z-index: 1;
  }

  .grid-row {
    margin-bottom: 10px;
  }
  .grid-row:last-child {
    margin-bottom: 0;
  }
  .grid-row:after {
    content: "";
    display: block;
    clear: both;
  }

  .grid-cell {
    width: 67px;
    height: 67px;
    margin-right: 10px;
    float: left;
    border-radius: 3px;
    background: rgba(45, 27, 105, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
  }
  .grid-cell:last-child {
    margin-right: 0;
  }

  .tile-container {
    position: absolute;
    z-index: 2;
  }

  .tile,
  .tile .tile-inner {
    width: 68px;
    height: 68px;
    line-height: 68px;
  }
  .tile.tile-position-1-1 {
    -webkit-transform: translate(0px, 0px);
    -moz-transform: translate(0px, 0px);
    -ms-transform: translate(0px, 0px);
    transform: translate(0px, 0px);
  }
  .tile.tile-position-1-2 {
    -webkit-transform: translate(0px, 77px);
    -moz-transform: translate(0px, 77px);
    -ms-transform: translate(0px, 77px);
    transform: translate(0px, 77px);
  }
  .tile.tile-position-1-3 {
    -webkit-transform: translate(0px, 154px);
    -moz-transform: translate(0px, 154px);
    -ms-transform: translate(0px, 154px);
    transform: translate(0px, 154px);
  }
  .tile.tile-position-1-4 {
    -webkit-transform: translate(0px, 231px);
    -moz-transform: translate(0px, 231px);
    -ms-transform: translate(0px, 231px);
    transform: translate(0px, 231px);
  }
  .tile.tile-position-2-1 {
    -webkit-transform: translate(77px, 0px);
    -moz-transform: translate(77px, 0px);
    -ms-transform: translate(77px, 0px);
    transform: translate(77px, 0px);
  }
  .tile.tile-position-2-2 {
    -webkit-transform: translate(77px, 77px);
    -moz-transform: translate(77px, 77px);
    -ms-transform: translate(77px, 77px);
    transform: translate(77px, 77px);
  }
  .tile.tile-position-2-3 {
    -webkit-transform: translate(77px, 154px);
    -moz-transform: translate(77px, 154px);
    -ms-transform: translate(77px, 154px);
    transform: translate(77px, 154px);
  }
  .tile.tile-position-2-4 {
    -webkit-transform: translate(77px, 231px);
    -moz-transform: translate(77px, 231px);
    -ms-transform: translate(77px, 231px);
    transform: translate(77px, 231px);
  }
  .tile.tile-position-3-1 {
    -webkit-transform: translate(154px, 0px);
    -moz-transform: translate(154px, 0px);
    -ms-transform: translate(154px, 0px);
    transform: translate(154px, 0px);
  }
  .tile.tile-position-3-2 {
    -webkit-transform: translate(154px, 77px);
    -moz-transform: translate(154px, 77px);
    -ms-transform: translate(154px, 77px);
    transform: translate(154px, 77px);
  }
  .tile.tile-position-3-3 {
    -webkit-transform: translate(154px, 154px);
    -moz-transform: translate(154px, 154px);
    -ms-transform: translate(154px, 154px);
    transform: translate(154px, 154px);
  }
  .tile.tile-position-3-4 {
    -webkit-transform: translate(154px, 231px);
    -moz-transform: translate(154px, 231px);
    -ms-transform: translate(154px, 231px);
    transform: translate(154px, 231px);
  }
  .tile.tile-position-4-1 {
    -webkit-transform: translate(231px, 0px);
    -moz-transform: translate(231px, 0px);
    -ms-transform: translate(231px, 0px);
    transform: translate(231px, 0px);
  }
  .tile.tile-position-4-2 {
    -webkit-transform: translate(231px, 77px);
    -moz-transform: translate(231px, 77px);
    -ms-transform: translate(231px, 77px);
    transform: translate(231px, 77px);
  }
  .tile.tile-position-4-3 {
    -webkit-transform: translate(231px, 154px);
    -moz-transform: translate(231px, 154px);
    -ms-transform: translate(231px, 154px);
    transform: translate(231px, 154px);
  }
  .tile.tile-position-4-4 {
    -webkit-transform: translate(231px, 231px);
    -moz-transform: translate(231px, 231px);
    -ms-transform: translate(231px, 231px);
    transform: translate(231px, 231px);
  }

  .tile .tile-inner {
    font-size: 40px;
  }

  .game-message p {
    font-size: 30px !important;
    height: 30px !important;
    line-height: 30px !important;
    margin-top: 90px !important;
  }
  .game-message .lower {
    margin-top: 30px !important;
  }
}

/* Optimization for 800x600 and similar short desktop screens */
@media screen and (min-width: 521px) and (max-height: 750px) {
  body {
    margin: 0;
    padding: 10px 0;
    overflow: hidden; /* Try to fit without scroll */
    height: 100vh;
    box-sizing: border-box;
  }
  
  .container {
    transform: scale(0.65); /* Scale down to fit 600px height */
    transform-origin: top center;
    margin-top: 0;
  }
}
