/* 2048 — lightweight stylesheet.
 * System fonts, solid colors, transform-only animations: cheap for old hardware.
 * No external resources.
 */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #faf8ef;
  color: #776e65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---------- Header ---------- */
.top {
  width: 100%;
  max-width: 480px;
  padding: 14px 12px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

h1 {
  margin: 0;
  font-size: 44px;
  line-height: 1;
  font-weight: 800;
  color: #776e65;
}

.tagline { margin: 3px 0 0; font-size: 13px; color: #8f7a66; }

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

.score-box {
  position: relative;
  min-width: 76px;
  padding: 5px 14px 7px;
  background: #bbada0;
  border-radius: 6px;
  text-align: center;
}
.score-box .label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #eee4da;
}
.score-box .value {
  display: block;
  font-size: 20px;
  font-weight: 800;
  color: #ffffff;
}

.score-pop {
  position: absolute;
  left: 0;
  right: 0;
  top: -6px;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  color: #776e65;
  pointer-events: none;
  animation: popup 0.9s ease-out forwards;
}
@keyframes popup {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-30px); }
}

/* ---------- Actions ---------- */
.actions {
  width: 100%;
  max-width: 480px;
  padding: 4px 12px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #f9f6f2;
  background: #8f7a66;
  border: 0;
  border-radius: 6px;
  padding: 9px 16px;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: #8f7a66; }
.btn.gear {
  background: #bbada0;
  font-size: 16px;
  line-height: 1;
  padding: 8px 13px;
}

/* ---------- Board ---------- */
.board-wrap {
  width: 92vw;
  /* cap by viewport height too, so it fits phone screens without scrolling */
  width: min(92vw, 480px, calc(100vh - 245px));
  min-width: 240px;
  max-width: 480px;
}

.board {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 100%; /* square, compatible without aspect-ratio */
  background: #bbada0;
  border-radius: 8px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.bg, .tiles {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
}

.bg-cell {
  position: absolute;
  top: 0; left: 0;
  background: rgba(238, 228, 218, 0.35);
  border-radius: 5px;
}

.tile {
  position: absolute;
  top: 0; left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-weight: 800;
  line-height: 1;
  transition: transform 130ms ease-in-out;
}

.tile-inner { display: block; }

.tile-new .tile-inner { animation: pop-new 200ms ease; }
@keyframes pop-new {
  0%   { transform: scale(0); }
  100% { transform: scale(1); }
}

.tile-merged .tile-inner { animation: pop-merged 240ms ease; }
@keyframes pop-merged {
  0%   { transform: scale(0.4); }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.board.fresh .tile, .board.fresh .bg-cell { animation: fadein 350ms ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* Tile colors — the classic 2048 palette (solid, GPU-cheap) */
.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; }
.tile-256   { background: #edcc61; color: #f9f6f2; }
.tile-512   { background: #edc850; color: #f9f6f2; }
.tile-1024  { background: #edc53f; color: #f9f6f2; }
.tile-2048  { background: #edc22e; color: #f9f6f2; }
.tile-super { background: #3c3a32; color: #f9f6f2; }

/* ---------- Footer ---------- */
.foot {
  width: 100%;
  max-width: 480px;
  margin: 10px 0 16px;
  padding: 0 12px;
  font-size: 12px;
  color: #a99e93;
  text-align: center;
}

/* ---------- Win / game-over overlay ---------- */
.overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(238, 228, 218, 0.73);
  border-radius: 8px;
  z-index: 20;
}
.overlay.visible { display: flex; animation: fadein 250ms ease; }
.overlay.win { background: rgba(237, 194, 46, 0.55); }

.overlay-box { display: none; text-align: center; padding: 16px; }
.overlay.win #overlay-win { display: block; }
.overlay.over #overlay-over { display: block; }

.overlay-msg { margin: 0 0 14px; font-size: 30px; font-weight: 800; color: #776e65; }
.overlay-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- Settings panel ---------- */
.panel-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(119, 110, 101, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.panel {
  background: #faf8ef;
  border-radius: 10px;
  padding: 18px 20px 20px;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
.panel h2 { margin: 0 0 14px; font-size: 20px; color: #776e65; }
.field { display: block; margin-bottom: 12px; font-size: 14px; font-weight: 600; }
.field > span { display: block; margin-bottom: 4px; color: #8f7a66; }
.field select {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d9cfc1;
  border-radius: 6px;
  background: #ffffff;
  color: #776e65;
}
.panel .btn { width: 100%; margin-top: 4px; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .tile-new .tile-inner,
  .tile-merged .tile-inner,
  .board.fresh .tile,
  .board.fresh .bg-cell,
  .score-pop { animation: none; }
}
