/**
 * 2048 Game Specific Styles
 * Popyca Games Casual Aesthetic
 * Light warm-neutral palette, amber accents, tactile tiles, crisp contrast.
 */

:root {
  --board-size: min(92vw, 460px);
  --grid-gap: clamp(8px, 2.2vw, 14px);
  --cell-size: calc((var(--board-size) - (var(--grid-gap) * 5)) / 4);
  --border-radius-board: 14px;
  --border-radius-tile: 10px;

  /* Tile Palette - Warm, distinct, high-contrast, non-candy */
  --tile-empty-bg: #e6dfd3;
  --tile-2-bg: #f8f6f0;
  --tile-2-color: #3d342a;
  --tile-4-bg: #eee4ce;
  --tile-4-color: #3d342a;
  --tile-8-bg: #e9a85c;
  --tile-8-color: #ffffff;
  --tile-16-bg: #e78b3e;
  --tile-16-color: #ffffff;
  --tile-32-bg: #e26938;
  --tile-32-color: #ffffff;
  --tile-64-bg: #d94829;
  --tile-64-color: #ffffff;
  --tile-128-bg: #e5b93d;
  --tile-128-color: #ffffff;
  --tile-256-bg: #deb02b;
  --tile-256-color: #ffffff;
  --tile-512-bg: #d19f18;
  --tile-512-color: #ffffff;
  --tile-1024-bg: #bf8d0b;
  --tile-1024-color: #ffffff;
  --tile-2048-bg: #b07d00;
  --tile-2048-color: #ffffff;
  --tile-super-bg: #2d4059;
  --tile-super-color: #ffffff;
}

/* Game Page Layout Container */
.game-view-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

/* Header & Scores Area */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: var(--board-size);
  margin-bottom: 12px;
}

.game-title-group h1 {
  font-size: clamp(2rem, 6vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--color-ink, #1f1d1a);
  margin: 0;
  line-height: 1;
}

.game-subtitle {
  font-size: 0.85rem;
  color: var(--color-ink-muted, #686055);
  margin-top: 4px;
}

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

.score-box {
  position: relative;
  background: #ebe4d8;
  border-radius: 8px;
  padding: 6px 14px;
  min-width: 70px;
  text-align: center;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

.score-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #7d7365;
}

.score-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 800;
  color: #1f1d1a;
  line-height: 1.2;
}

/* Score floating delta animation */
.score-addition {
  position: absolute;
  top: -8px;
  right: 12px;
  font-size: 1rem;
  font-weight: 800;
  color: #e26938;
  pointer-events: none;
  animation: scoreFadeUp 650ms ease-out forwards;
}

@keyframes scoreFadeUp {
  0% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-24px);
  }
}

/* Control Bar */
.game-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: var(--board-size);
  margin-bottom: 14px;
  gap: 10px;
}

.game-intro-text {
  font-size: 0.9rem;
  color: #554d42;
  margin: 0;
  line-height: 1.35;
}

.game-action-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-game-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  user-select: none;
}

.btn-game-action:active {
  transform: scale(0.97);
}

.btn-restart {
  background-color: #8c7a65;
  color: #ffffff;
}

.btn-restart:hover {
  background-color: #796853;
}

.btn-undo {
  background-color: #ded6c8;
  color: #3d342a;
}

.btn-undo:hover:not(:disabled) {
  background-color: #d1c7b6;
}

.btn-undo:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Game Board */
.board-container {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background-color: #cbbeab;
  border-radius: var(--border-radius-board);
  padding: var(--grid-gap);
  box-sizing: border-box;
  touch-action: none; /* Prevents pull-to-refresh & screen dragging */
  user-select: none;
  box-shadow: 0 4px 12px rgba(60, 50, 40, 0.08);
}

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

.grid-cell {
  background-color: var(--tile-empty-bg);
  border-radius: var(--border-radius-tile);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.04);
}

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

/* Base Tile */
.tile {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--border-radius-tile);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: transform 105ms ease-in-out;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
  z-index: 10;
}

.tile-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: calc(var(--cell-size) * 0.44);
  line-height: 1;
}

/* Length-based font scaling */
.tile[data-value="128"] .tile-inner,
.tile[data-value="256"] .tile-inner,
.tile[data-value="512"] .tile-inner {
  font-size: calc(var(--cell-size) * 0.38);
}

.tile[data-value="1024"] .tile-inner,
.tile[data-value="2048"] .tile-inner {
  font-size: calc(var(--cell-size) * 0.30);
}

.tile-super .tile-inner {
  font-size: calc(var(--cell-size) * 0.25);
}

/* Tile Appearance Animation */
.tile-new {
  animation: tileAppear 140ms ease-out forwards;
}

@keyframes tileAppear {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Tile Merge Animation */
.tile-merged {
  animation: tilePop 190ms ease-in-out forwards;
  z-index: 20;
}

@keyframes tilePop {
  0% {
    transform: scale(0.9);
  }
  50% {
    transform: scale(1.16);
  }
  100% {
    transform: scale(1);
  }
}

.tile-removed {
  opacity: 0;
  transition: opacity 80ms ease;
  z-index: 5;
}

/* Individual Tile Colors */
.tile-2 {
  background-color: var(--tile-2-bg);
  color: var(--tile-2-color);
}

.tile-4 {
  background-color: var(--tile-4-bg);
  color: var(--tile-4-color);
}

.tile-8 {
  background-color: var(--tile-8-bg);
  color: var(--tile-8-color);
}

.tile-16 {
  background-color: var(--tile-16-bg);
  color: var(--tile-16-color);
}

.tile-32 {
  background-color: var(--tile-32-bg);
  color: var(--tile-32-color);
}

.tile-64 {
  background-color: var(--tile-64-bg);
  color: var(--tile-64-color);
}

.tile-128 {
  background-color: var(--tile-128-bg);
  color: var(--tile-128-color);
  box-shadow: 0 0 10px rgba(229, 185, 61, 0.4);
}

.tile-256 {
  background-color: var(--tile-256-bg);
  color: var(--tile-256-color);
  box-shadow: 0 0 14px rgba(222, 176, 43, 0.45);
}

.tile-512 {
  background-color: var(--tile-512-bg);
  color: var(--tile-512-color);
  box-shadow: 0 0 18px rgba(209, 159, 24, 0.5);
}

.tile-1024 {
  background-color: var(--tile-1024-bg);
  color: var(--tile-1024-color);
  box-shadow: 0 0 22px rgba(191, 141, 11, 0.55);
}

.tile-2048 {
  background-color: var(--tile-2048-bg);
  color: var(--tile-2048-color);
  box-shadow: 0 0 28px rgba(176, 125, 0, 0.65);
}

.tile-super {
  background-color: var(--tile-super-bg);
  color: var(--tile-super-color);
  box-shadow: 0 0 24px rgba(45, 64, 89, 0.6);
}

/* Modals Overlay (Win & Game Over) */
.game-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(246, 243, 237, 0.92);
  border-radius: var(--border-radius-board);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  z-index: 100;
  backdrop-filter: blur(2px);
  animation: modalFadeIn 200ms ease-out forwards;
}

.game-modal-overlay.hidden {
  display: none;
}

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

.modal-title {
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-weight: 800;
  color: #1f1d1a;
  margin: 0 0 8px;
}

.modal-subtitle {
  font-size: 1rem;
  color: #554d42;
  margin: 0 0 20px;
}

.modal-score-badge {
  background: #ebe4d8;
  padding: 8px 18px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 1.25rem;
  color: #1f1d1a;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-modal-primary {
  background-color: #e26938;
  color: #ffffff;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-modal-primary:hover {
  background-color: #d15625;
}

.btn-modal-secondary {
  background-color: #8c7a65;
  color: #ffffff;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-modal-secondary:hover {
  background-color: #796853;
}

/* Touch Instruction Hint */
.controls-hint {
  display: flex;
  justify-content: space-between;
  width: var(--board-size);
  margin-top: 10px;
  font-size: 0.8rem;
  color: #7d7365;
}

/* Game Explanations & Content Section */
.game-info-section {
  width: var(--board-size);
  margin-top: 24px;
  line-height: 1.6;
  color: #38332c;
}

.game-info-section h2 {
  font-size: 1.25rem;
  font-weight: 800;
  color: #1f1d1a;
  margin: 18px 0 8px;
}

.game-info-section p,
.game-info-section ul {
  font-size: 0.95rem;
  margin: 0 0 12px;
}

.game-info-section ul {
  padding-left: 20px;
}

.game-info-section li {
  margin-bottom: 4px;
}

/* Screen reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
