/* ==========================================================================
   2048 Game Modern Stylesheet
   ========================================================================== */

:root {
  --bg-color: #faf8ef;
  --text-main: #776e65;
  --text-light: #f9f6f2;
  --grid-bg: #bbada0;
  --cell-bg: rgba(238, 228, 218, 0.35);
  
  --cell-size: 96px;
  --grid-gap: 14px;
  --border-radius: 8px;
  --board-radius: 12px;
  
  --primary-color: #8f7a66;
  --primary-hover: #7c6854;
  --accent-color: #f65e3b;
  --success-color: #48bb78;

  --shadow-subtle: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-card: 0 10px 25px rgba(0, 0, 0, 0.12);
  --font-heading: 'Fredoka', 'Poppins', sans-serif;
  --font-body: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Header & Scores */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.title-area {
  display: flex;
  flex-direction: column;
}

.game-title {
  font-family: var(--font-heading);
  font-size: 3.4rem;
  font-weight: 700;
  line-height: 0.95;
  color: #776e65;
  letter-spacing: -2px;
  text-shadow: 2px 2px 0px rgba(255, 255, 255, 0.8);
}

.game-subtitle {
  font-size: 0.85rem;
  color: #8f7a66;
  margin-top: 4px;
}

.scores-container {
  display: flex;
  gap: 8px;
}

.score-box {
  background: var(--grid-bg);
  padding: 8px 14px;
  border-radius: var(--border-radius);
  text-align: center;
  min-width: 80px;
  color: var(--text-light);
  position: relative;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

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

.score-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #eee4da;
  text-transform: uppercase;
}

.score-value {
  display: block;
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.1;
}

.score-addition {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: 700;
  font-size: 1.1rem;
  color: #f65e3b;
  pointer-events: none;
  opacity: 0;
  z-index: 100;
}

.score-addition.active {
  animation: floatScore 800ms ease-out forwards;
}

@keyframes floatScore {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -180%) scale(1.3);
  }
}

/* Action Toolbar */
.action-toolbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--border-radius);
  padding: 10px 16px;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-subtle);
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--primary-color);
  color: var(--text-light);
}

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

.btn-secondary {
  background: #d8cebe;
  color: #776e65;
}

.btn-secondary:hover:not(:disabled) {
  background: #c7bca9;
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-success {
  background: var(--success-color);
  color: #fff;
}

.btn-success:hover {
  background: #38a169;
}

.btn-icon {
  background: #eee4da;
  color: #776e65;
  padding: 10px;
  border-radius: var(--border-radius);
}

.btn-icon:hover {
  background: #e0d5c8;
}

.btn-large {
  padding: 12px 24px;
  font-size: 1rem;
}

.icon {
  display: block;
}

.hidden {
  display: none !important;
}

/* Game Area & Board */
.game-area {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

.board-container {
  position: relative;
  padding: var(--grid-gap);
  background: var(--grid-bg);
  border-radius: var(--board-radius);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.15), var(--shadow-card);
  touch-action: none;
  cursor: grab;
}

.board-container:active {
  cursor: grabbing;
}

.grid-background {
  display: grid;
  grid-template-columns: repeat(4, var(--cell-size));
  grid-template-rows: repeat(4, var(--cell-size));
  gap: var(--grid-gap);
}

.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--cell-bg);
  border-radius: var(--border-radius);
}

/* Dynamic Tile Layer */
.tile-layer {
  position: absolute;
  top: var(--grid-gap);
  left: var(--grid-gap);
  right: var(--grid-gap);
  bottom: var(--grid-gap);
  pointer-events: none;
}

.tile {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 2.3rem;
  line-height: 1;
  text-align: center;
  z-index: 10;
  transform: translate(
    calc(var(--col) * (var(--cell-size) + var(--grid-gap))),
    calc(var(--row) * (var(--cell-size) + var(--grid-gap)))
  );
  transition: transform 110ms cubic-bezier(0.2, 0.9, 0.3, 1);
  will-change: transform;
}

/* Animations */
.tile-new {
  animation: tileSpawn 200ms cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

.tile-merged {
  z-index: 20;
  animation: tileBump 220ms ease-in-out;
}

@keyframes tileSpawn {
  0% {
    opacity: 0;
    transform: translate(
      calc(var(--col) * (var(--cell-size) + var(--grid-gap))),
      calc(var(--row) * (var(--cell-size) + var(--grid-gap)))
    ) scale(0.2);
  }
  100% {
    opacity: 1;
    transform: translate(
      calc(var(--col) * (var(--cell-size) + var(--grid-gap))),
      calc(var(--row) * (var(--cell-size) + var(--grid-gap)))
    ) scale(1);
  }
}

@keyframes tileBump {
  0% {
    transform: translate(
      calc(var(--col) * (var(--cell-size) + var(--grid-gap))),
      calc(var(--row) * (var(--cell-size) + var(--grid-gap)))
    ) scale(1);
  }
  50% {
    transform: translate(
      calc(var(--col) * (var(--cell-size) + var(--grid-gap))),
      calc(var(--row) * (var(--cell-size) + var(--grid-gap)))
    ) scale(1.18);
  }
  100% {
    transform: translate(
      calc(var(--col) * (var(--cell-size) + var(--grid-gap))),
      calc(var(--row) * (var(--cell-size) + var(--grid-gap)))
    ) scale(1);
  }
}

/* Tile Themes by Value */
.tile-2 {
  background: #eee4da;
  color: #776e65;
  box-shadow: 0 3px 0 #d6cdc4;
}

.tile-4 {
  background: #ede0c8;
  color: #776e65;
  box-shadow: 0 3px 0 #d5c8b1;
}

.tile-8 {
  background: #f2b179;
  color: #f9f6f2;
  box-shadow: 0 3px 0 #d8965f;
}

.tile-16 {
  background: #f59563;
  color: #f9f6f2;
  box-shadow: 0 3px 0 #d87747;
}

.tile-32 {
  background: #f67c5f;
  color: #f9f6f2;
  box-shadow: 0 3px 0 #d85c40;
}

.tile-64 {
  background: #f65e3b;
  color: #f9f6f2;
  box-shadow: 0 3px 0 #d64221;
}

.tile-128 {
  background: #edcf72;
  color: #f9f6f2;
  font-size: 2rem;
  box-shadow: 0 0 14px rgba(243, 215, 116, 0.4), 0 3px 0 #ccb056;
}

.tile-256 {
  background: #edcc61;
  color: #f9f6f2;
  font-size: 2rem;
  box-shadow: 0 0 18px rgba(243, 215, 116, 0.5), 0 3px 0 #cbac48;
}

.tile-512 {
  background: #edc850;
  color: #f9f6f2;
  font-size: 2rem;
  box-shadow: 0 0 22px rgba(243, 215, 116, 0.6), 0 3px 0 #caa63a;
}

.tile-1024 {
  background: #edc53f;
  color: #f9f6f2;
  font-size: 1.6rem;
  box-shadow: 0 0 26px rgba(243, 215, 116, 0.7), 0 3px 0 #c7a02c;
}

.tile-2048 {
  background: linear-gradient(135deg, #ffd700, #edc22e, #ffb300);
  color: #ffffff;
  font-size: 1.6rem;
  box-shadow: 0 0 32px rgba(255, 215, 0, 0.85), 0 4px 0 #b38b15;
  animation: goldShimmer 2s infinite alternate;
}

.tile-super {
  background: linear-gradient(135deg, #9b51e0, #3c3a32, #111);
  color: #ffffff;
  font-size: 1.4rem;
  box-shadow: 0 0 35px rgba(155, 81, 224, 0.8);
}

@keyframes goldShimmer {
  0% {
    filter: brightness(1);
  }
  100% {
    filter: brightness(1.15) drop-shadow(0 0 10px rgba(255, 223, 0, 0.6));
  }
}

/* Overlays (Game Over & Victory) */
.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.92);
  backdrop-filter: blur(4px);
  border-radius: var(--board-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 300ms ease-out;
}

.victory-overlay {
  background: rgba(243, 235, 203, 0.94);
}

.overlay-content {
  text-align: center;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.overlay-badge {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 20px;
  color: white;
}

.game-over-badge {
  background: #e53e3e;
}

.victory-badge {
  background: #d69e2e;
}

.overlay-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--text-main);
}

.overlay-score-text {
  font-size: 1rem;
  color: #8f7a66;
}

.highlight-score {
  font-weight: 700;
  color: #f65e3b;
  font-size: 1.3rem;
}

.overlay-buttons {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Touch Hint */
.touch-hint {
  font-size: 0.8rem;
  color: #9c8e80;
  text-align: center;
}

/* Modal Help */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  animation: fadeIn 200ms ease;
}

.modal-card {
  background: #fff;
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid #f0eee9;
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  color: var(--text-main);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  color: #a39281;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.help-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.step-num {
  background: #f2b179;
  color: white;
  font-family: var(--font-heading);
  font-weight: 700;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.help-step p {
  font-size: 0.9rem;
  color: #665e56;
  line-height: 1.4;
}

.modal-footer {
  padding: 14px 20px 20px;
  display: flex;
  justify-content: flex-end;
}

/* Footer */
.game-footer {
  font-size: 0.75rem;
  color: #a89d91;
  text-align: center;
  margin-top: 8px;
}

/* Responsive adjustments for Mobile */
@media (max-width: 480px) {
  :root {
    --cell-size: 68px;
    --grid-gap: 10px;
  }

  body {
    padding: 8px;
  }

  .game-title {
    font-size: 2.6rem;
  }

  .score-box {
    padding: 6px 10px;
    min-width: 65px;
  }

  .score-value {
    font-size: 1.15rem;
  }

  .tile {
    font-size: 1.8rem;
  }

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

  .tile-1024, .tile-2048 {
    font-size: 1.25rem;
  }

  .btn {
    padding: 8px 12px;
    font-size: 0.82rem;
  }
}

@media (max-width: 350px) {
  :root {
    --cell-size: 58px;
    --grid-gap: 8px;
  }

  .tile {
    font-size: 1.5rem;
  }
}

