/* 2048 - Portal Dark Theme */
#game-container {
  max-width: 500px;
  margin: 0 auto;
  padding: 10px;
}

/* Size Selector */
#size-selector {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 14px;
}

.size-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
  font-family: inherit;
}

.size-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.size-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

/* Score Bar */
#score-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.score-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  text-align: center;
  min-width: 80px;
}

.score-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.score-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

#new-game-btn {
  padding: 10px 18px;
  font-size: 0.85rem;
  margin-left: 4px;
}

#undo-btn,
#stats-btn {
  padding: 10px 14px;
  font-size: 0.85rem;
}

#undo-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Board */
#board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
}

/* Background Grid */
#grid-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
}

.grid-cell {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
}

/* Tiles Container */
#tiles-container {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
  pointer-events: none;
}

/* Individual Tile */
.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  border-radius: 6px;
  transition: top 120ms ease, left 120ms ease;
  z-index: 10;
}

/* Tile appearance animation */
.tile-new {
  animation: tile-pop 200ms ease;
}

.tile-merged {
  animation: tile-merge 200ms ease;
  z-index: 20;
}

@keyframes tile-pop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

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

/* Tile Colors - by value */
.tile-2    { background: #eee4da; color: #776e65; }
.tile-4    { background: #ede0c8; color: #776e65; }
.tile-8    { background: #f2b179; color: #f9f6f2; }
.tile-16   { background: #f59563; color: #f9f6f2; }
.tile-32   { background: #f67c5f; color: #f9f6f2; }
.tile-64   { background: #f65e3b; color: #f9f6f2; }
.tile-128  { background: #edcf72; color: #f9f6f2; font-size: 0.9em; }
.tile-256  { background: #edcc61; color: #f9f6f2; font-size: 0.9em; }
.tile-512  { background: #edc850; color: #f9f6f2; font-size: 0.9em; }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 0.75em; }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 0.75em; box-shadow: 0 0 30px 10px rgba(237, 194, 46, 0.3); }
.tile-super{ background: #3c3a32; color: #f9f6f2; font-size: 0.65em; }

/* Game Over / Win Overlay */
#game-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 15, 26, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  z-index: 100;
  animation: fade-in 400ms ease;
}

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

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

#overlay-content {
  text-align: center;
  padding: 30px;
}

#overlay-title {
  font-size: 2rem;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent), #f0a500);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#overlay-message {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 8px;
}

#overlay-score {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
}

#overlay-btn {
  padding: 12px 32px;
  font-size: 1rem;
}

/* How to Play */
#how-to-play {
  margin-top: 20px;
  max-width: 500px;
}

/* ===== Statistics Modal ===== */
#stats-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fade-in 200ms ease;
}

#stats-modal.hidden {
  display: none;
}

#stats-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 26, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1;
}

#stats-panel {
  position: relative;
  z-index: 2;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: panel-in 250ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes panel-in {
  from { transform: translateY(20px) scale(0.95); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

.stats-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  font-family: inherit;
}

.stats-close:hover {
  color: var(--accent);
  background: rgba(233, 69, 96, 0.08);
}

#stats-title {
  font-size: 1.5rem;
  margin-bottom: 18px;
  color: var(--text-primary);
  background: linear-gradient(135deg, var(--accent), #f0a500);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stats-section {
  margin-bottom: 24px;
}

.stats-section-title {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.stats-sub {
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-secondary);
  opacity: 0.7;
}

.stats-grid {
  display: grid;
  gap: 10px;
}

.overview-grid {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.size-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  text-align: center;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-card.size-card {
  text-align: left;
  padding: 14px 16px;
}

.stat-card.size-card .stat-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.stat-card.size-card .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 0.85rem;
}

.stat-card.size-card .stat-row .label {
  color: var(--text-secondary);
}

.stat-card.size-card .stat-row .val {
  color: var(--text-primary);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Best tile display */
.best-tile-display {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 90px;
  padding: 12px;
}

.best-tile-display .mini-tile {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  border-radius: 8px;
  font-size: 1.6rem;
  color: #f9f6f2;
}

.best-tile-display .no-tile {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 0.9rem;
}

/* Recent games table */
#recent-games-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.recent-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.recent-table th,
.recent-table td {
  padding: 8px 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.recent-table th {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.recent-table tbody tr {
  border-top: 1px solid var(--border);
}

.recent-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.recent-table .result-win {
  color: #4ade80;
  font-weight: 700;
}

.recent-table .result-lose {
  color: #f87171;
  font-weight: 700;
}

.recent-table .result-pending {
  color: var(--text-secondary);
  font-style: italic;
}

.recent-table .empty-row td {
  padding: 24px;
  color: var(--text-secondary);
  font-style: italic;
}

.stats-actions {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

.btn-danger {
  background: #b91c1c;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
}

.btn-danger:hover {
  background: #dc2626;
}

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

/* Responsive */
@media (max-width: 520px) {
  #game-container {
    padding: 5px;
  }
  #score-bar {
    flex-wrap: wrap;
    gap: 6px;
  }
  .score-box {
    min-width: 70px;
    padding: 6px 10px;
  }
  .score-value {
    font-size: 1.1rem;
  }
  .score-label {
    font-size: 0.6rem;
  }
  #new-game-btn,
  #undo-btn,
  #stats-btn {
    padding: 8px 12px;
    font-size: 0.78rem;
  }
  #grid-bg {
    gap: 6px;
    padding: 6px;
  }
  .tile {
    font-size: 0.85em;
  }
  .size-btn {
    padding: 5px 12px;
    font-size: 0.78rem;
  }
  #stats-panel {
    padding: 20px 16px;
  }
  .recent-table {
    font-size: 0.75rem;
  }
  .recent-table th,
  .recent-table td {
    padding: 6px 4px;
  }
}
