/* 2048 Game Styles - Responsive CSS Grid + Transform Animations */

:root {
  --grid-size: 450px;
  --tile-size: 100px;
  --gap: 15px;
  --animation-duration: 200ms;
  --bg-color: #1a1a1a;
  --grid-bg: #2f3237;
  --text-dark: #d1d5db;
  --text-light: #f9f6f2;
  --accent: rgba(140, 180, 255, 0.15);
  --ad-safe-bottom: 0px;     /* Dynamic padding for AdMob banner */
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  margin: 0;
  padding: 20px;
  padding-bottom: calc(20px + var(--ad-safe-bottom));
  background: radial-gradient(circle at top, #2a2a2a, #1a1a1a);
  color: var(--text-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  user-select: none;
  transition: padding-bottom 0.3s ease;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: var(--grid-size);
  margin-bottom: 20px;
}

.title {
  font-size: 80px;
  font-weight: bold;
  color: var(--text-dark);
  margin: 0;
}

.scores {
  display: flex;
  gap: 10px;
}

.score-container {
  background: #35393e;
  padding: 8px 16px;
  border-radius: 3px;
  text-align: center;
  min-width: 70px;
}

.score-label {
  font-size: 11px;
  color: #9ca3af;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.score {
  font-size: 18px;
  font-weight: bold;
  color: #d1d5db;
}

/* Best score visible but de-emphasized - Octile Universe: scores exist for reflection, not comparison */
#best-score {
  /* Visible but same styling as current score - de-emphasized equally */
}

/* Game Container */
#game-container {
  position: relative;
  margin: 20px 0;
}

/* Grid Container - CSS Grid */
.grid-container {
  position: relative;
  width: var(--grid-size);
  height: var(--grid-size);
  background: var(--grid-bg);
  border-radius: 6px;
  padding: var(--gap);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  display: grid;
  grid-template-columns: repeat(4, var(--tile-size));
  grid-template-rows: repeat(4, var(--tile-size));
  gap: var(--gap);
}

/* Background Grid Cells */
.grid-cell {
  background: #3a3f46;
  border-radius: 3px;
}

/* Tiles - Absolute positioning with transforms */
.tile {
  position: absolute;
  width: var(--tile-size);
  height: var(--tile-size);
  background: #eee4da;
  color: var(--text-dark);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--tile-size) * 0.5);
  font-weight: bold;

  /* Transform positioning using CSS variables */
  transform: translate(
    calc(var(--x) * (var(--tile-size) + var(--gap)) + var(--gap)),
    calc(var(--y) * (var(--tile-size) + var(--gap)) + var(--gap))
  );

  /* Smooth transition for movement */
  transition: transform var(--animation-duration) ease-in-out;
}

/* Spawn Animation */
.tile-new {
  animation: spawn 200ms ease-in-out;
  box-shadow: 0 0 10px var(--accent);
}

@keyframes spawn {
  0% {
    transform: translate(
      calc(var(--x) * (var(--tile-size) + var(--gap)) + var(--gap)),
      calc(var(--y) * (var(--tile-size) + var(--gap)) + var(--gap))
    ) scale(0);
  }
  100% {
    transform: translate(
      calc(var(--x) * (var(--tile-size) + var(--gap)) + var(--gap)),
      calc(var(--y) * (var(--tile-size) + var(--gap)) + var(--gap))
    ) scale(1);
  }
}

/* Merge Animation */
.tile-merged {
  animation: merge 300ms ease-in-out;
  box-shadow: 0 0 15px var(--accent);
}

@keyframes merge {
  0%, 100% {
    transform: translate(
      calc(var(--x) * (var(--tile-size) + var(--gap)) + var(--gap)),
      calc(var(--y) * (var(--tile-size) + var(--gap)) + var(--gap))
    ) scale(1);
  }
  50% {
    transform: translate(
      calc(var(--x) * (var(--tile-size) + var(--gap)) + var(--gap)),
      calc(var(--y) * (var(--tile-size) + var(--gap)) + var(--gap))
    ) scale(1.1);
  }
}

/* Controls */
.controls {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--grid-size);
}

.btn {
  padding: 10px 20px;
  background: #3f444a;
  color: #e5e7eb;
  border: none;
  border-radius: 3px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

.btn:hover {
  background: #4a5057;
}

.btn:active {
  background: #353a40;
}

.btn.secondary {
  background: #2a2a2a;
  color: #999999;
}

.btn.secondary:hover {
  background: #3a3a3a;
}

/* Header buttons (help, about, mute) */
.header-buttons {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: #3a3a3a;
  color: #cccccc;
  border: none;
  border-radius: 3px;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  background: #4a4a4a;
}

.icon-button:active {
  background: #2a2a2a;
}

/* Modals - Octile Universe: calm, dark, no dramatic effects */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);  /* Dark overlay (was rgba(255,255,255,0.5)) */
  backdrop-filter: blur(5px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: #2f3237;
  color: #d1d5db;
  padding: 40px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  max-width: 400px;
  width: 90%;
}

.modal-content h2 {
  font-size: 28px;
  margin: 0 0 20px 0;
  color: #d1d5db;
}

.modal-content p {
  font-size: 18px;
  margin: 10px 0;
  color: #9ca3af;
}

.modal-content .final-score,
.modal-content .final-moves {
  font-size: 36px;
  font-weight: bold;
  color: #b0b6bc;
  margin: 10px 0;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 30px;
  justify-content: center;
}

/* Help Modal Specific Styles */
.help-section {
  text-align: left;
  margin: 20px 0;
}

.help-section h3 {
  font-size: 18px;
  color: #cccccc;
  margin-bottom: 10px;
}

.help-section p,
.help-section ul {
  font-size: 16px;
  color: #999999;
  line-height: 1.6;
}

.help-section ul {
  padding-left: 20px;
  margin: 10px 0;
}

.help-section li {
  margin: 8px 0;
}

.help-links {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 20px 0;
}

.help-links a {
  color: #7986b8;
  text-decoration: none;
  font-size: 16px;
}

.help-links a:hover {
  text-decoration: underline;
}

/* About Modal Specific Styles */
.about-name {
  font-size: 32px;
  font-weight: bold;
  color: #cccccc;
  margin: 20px 0;
}

.about-version {
  font-size: 16px;
  color: #999999;
  margin: 10px 0;
}

.about-byline {
  font-size: 16px;
  color: #999999;
  font-style: italic;
  margin: 10px 0;
}

.about-links {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 20px 0;
}

.about-links a {
  color: #7986b8;
  text-decoration: none;
  font-size: 16px;
}

.about-links a:hover {
  text-decoration: underline;
}

.modal-button {
  margin-top: 20px;
}

/* Octile cross-promotion */
.octile-nudge {
  font-size: 14px;
  color: #6b7280;
  margin: 20px 0 0 0;
  line-height: 1.5;
}

.btn-secondary {
  background: transparent;
  color: #9ca3af;
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #d1d5db;
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.02);
}

.footer-link {
  margin-top: 30px;
  font-size: 12px;
  color: #6b7280;
  text-align: center;
}

.footer-link a {
  color: #6b7280;
  text-decoration: none;
}

.footer-link a:hover {
  color: #9ca3af;
}

/* Responsive Design */
@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .title {
    font-size: 50px;
  }

  .header {
    flex-direction: column;
    gap: 15px;
  }

  .scores {
    flex-direction: row;
  }

  .tile {
    font-size: calc(var(--tile-size) * 0.4);
  }
}

@media (max-height: 700px) {
  .title {
    font-size: 50px;
  }

  .header {
    margin-bottom: 10px;
  }

  .controls {
    margin-top: 10px;
  }
}

/* Touch feedback */
@media (hover: none) {
  .btn:hover {
    background: #3f444a;
  }

  .btn:active {
    background: #353a40;
    transform: scale(0.95);
  }

  .btn-secondary:hover {
    background: transparent;
  }

  .btn-secondary:active {
    background: rgba(255, 255, 255, 0.02);
  }
}

/* Update Banner (OTA) */
#update-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #0f3460, #1a5276);
  border-bottom: 2px solid #f1c40f;
  padding: 12px 16px;
  text-align: center;
  animation: slideDown 0.3s ease-out;
}
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
#update-banner.show { display: block; }
#update-banner p { color: #eee; font-size: 13px; margin-bottom: 8px; }
#update-banner .update-actions { display: flex; justify-content: center; gap: 12px; }
#update-banner .btn-update {
  padding: 8px 20px; font-size: 14px; font-weight: 700;
  border: none; border-radius: 6px; cursor: pointer;
  background: #f1c40f; color: #1a1a2e;
}
#update-banner .btn-update:hover { background: #f39c12; }
#update-banner .btn-dismiss {
  padding: 8px 16px; font-size: 14px;
  border: 1px solid #555; border-radius: 6px; cursor: pointer;
  background: none; color: #888;
}
#update-banner .btn-dismiss:hover { border-color: #888; color: #bbb; }
#update-banner.force {
  background: linear-gradient(135deg, #b85c00, #c0392b);
  border-bottom-color: #e74c3c;
}
