/* 2048 — tokens from /assets/base.css */

html, body { min-height: 100%; }

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 16px;
  min-height: 100vh;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

.top {
  width: 100%;
  text-align: center;
  padding-left: 52px;
  padding-right: 8px;
}
.top h1 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel {
  width: 100%;
  background: linear-gradient(145deg, rgba(16, 20, 38, 0.95), #090c18 50%, #05060f 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 26px;
  padding: 20px 18px 18px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.hidden { display: none !important; }
[hidden] { display: none !important; }

/* Menu */
.menu-panel { padding: 28px 22px 22px; gap: 18px; }
.menu-stats {
  display: flex;
  gap: 12px;
  width: 100%;
  justify-content: center;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 100px;
}
.stat-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.menu-tagline {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  letter-spacing: 0.02em;
}
.menu-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.menu-hint {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* HUD */
.hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  align-items: stretch;
}
.hud-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hud-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.hud-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.ghost-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ghost-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.game-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}
.game-actions .ghost-btn {
  border-radius: var(--radius-pill);
  padding: 9px 18px;
}

/* Board */
.board {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1 / 1;
  background: #07090f;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px;
  touch-action: none;
}
.bg-grid, .tiles-layer {
  position: absolute;
  inset: 6px;
}
.bg-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 6px;
}
.bg-cell {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
}
.tiles-layer {
  /* tiles are absolutely positioned via transform */
  pointer-events: none;
}

/* Tile — outer handles position with transition, inner handles look + spawn/merge */
.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  /* width / height set inline at render based on board size */
  transition: transform 130ms cubic-bezier(0.4, 0.0, 0.2, 1);
  will-change: transform;
}
.tile-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-family: var(--font-sans);
  border-radius: 8px;
  color: var(--text);
  letter-spacing: -0.02em;
}
.tile.spawn .tile-inner {
  animation: tile-spawn 170ms ease backwards;
}
.tile.merge .tile-inner {
  animation: tile-merge 170ms ease;
}
@keyframes tile-spawn {
  0% { transform: scale(0.35); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes tile-merge {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* Tile colour palette */
.tile[data-v="2"] .tile-inner    { background: #1e2240; color: var(--text); }
.tile[data-v="4"] .tile-inner    { background: #2a2a55; color: var(--text); }
.tile[data-v="8"] .tile-inner    { background: #3d3787; color: #fff; }
.tile[data-v="16"] .tile-inner   { background: #564db8; color: #fff; }
.tile[data-v="32"] .tile-inner   { background: #7163e6; color: #fff; }
.tile[data-v="64"] .tile-inner   { background: #8a7cff; color: #fff; }
.tile[data-v="128"] .tile-inner  { background: #6e8cff; color: #fff; }
.tile[data-v="256"] .tile-inner  { background: #5dabff; color: #fff; }
.tile[data-v="512"] .tile-inner  { background: #4ec5ff; color: #0b0b12; }
.tile[data-v="1024"] .tile-inner { background: #5cffd4; color: #0b0b12; }
.tile[data-v="2048"] .tile-inner { background: #ffd66e; color: #0b0b12; box-shadow: 0 0 18px rgba(255,214,110,0.5); }
.tile[data-v="4096"] .tile-inner,
.tile[data-v="8192"] .tile-inner { background: #ff9d4e; color: #0b0b12; box-shadow: 0 0 18px rgba(255,157,78,0.5); }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 22, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.overlay-card {
  background: linear-gradient(145deg, #1a1c30, #0d0e1d);
  border: 1px solid rgba(138, 124, 255, 0.3);
  border-radius: 22px;
  padding: 28px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: 0 0 40px rgba(138, 124, 255, 0.2);
  max-width: 320px;
}
.overlay-card h2 {
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.muted { color: var(--muted); font-size: 0.85rem; }
.overlay-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.overlay-actions .ghost-btn {
  border-radius: var(--radius-pill);
  padding: 9px 16px;
}

.primary-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  padding: 11px 24px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}
.primary-btn:hover {
  background: rgba(138, 124, 255, 0.25);
  transform: translateY(-1px);
  box-shadow: 0 0 18px rgba(138, 124, 255, 0.3);
}

@media (max-width: 600px) {
  .panel { padding: 16px 14px 14px; border-radius: 20px; }
  .menu-panel { padding: 22px 16px 18px; }
}
