/* ═══════════════════════════════════════════════════════════════════════════
   2048 Game — Dark Theme Stylesheet
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Page layout ───────────────────────────────────────────────────────── */
.game-2048-page {
  min-height: 100vh;
  background: #0f0f1a;
  color: #e0e0e0;
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 60px;
}

/* ── Header / scores ──────────────────────────────────────────────────── */
.game-header {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.game-title {
  font-size: 3rem;
  font-weight: 800;
  color: #f5c518;
  margin: 0;
  letter-spacing: -1px;
}

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

.score-box {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  border-radius: 8px;
  padding: 6px 16px;
  text-align: center;
  min-width: 70px;
}

.score-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #8888aa;
  margin-bottom: 2px;
}

.score-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #f5c518;
}

/* ── Subtitle + button row ─────────────────────────────────────────────── */
.game-sub-header {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.game-tagline {
  color: #8888aa;
  font-size: 0.9rem;
  margin: 0;
}

.btn-new-game {
  background: #f5c518;
  color: #0f0f1a;
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-new-game:hover {
  background: #ffd740;
  transform: translateY(-1px);
}

.btn-new-game:active {
  transform: translateY(0);
}

/* ── Game container ────────────────────────────────────────────────────── */
#game-container {
  width: 100%;
  max-width: 500px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ── Grid ──────────────────────────────────────────────────────────────── */
#game-grid {
  background: #1a1a2e;
  border-radius: 12px;
  padding: 12px;
  position: relative;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
}

.grid-cell {
  background: #252540;
  border-radius: 8px;
}

/* ── Tile layer (absolute overlay on grid) ─────────────────────────────── */
#tile-layer {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  --gap: 10px;
  --cell: calc((100% - 3 * var(--gap)) / 4);
  --step: calc(var(--cell) + var(--gap));
}

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  border-radius: 8px;
  width: var(--cell);
  height: var(--cell);
  transition: top 100ms ease, left 100ms ease;
  z-index: 10;
}

/* ── Tile positions ────────────────────────────────────────────────────── */
.tile-pos-0-0 { top: 0;                       left: 0; }
.tile-pos-0-1 { top: 0;                       left: calc(1 * var(--step)); }
.tile-pos-0-2 { top: 0;                       left: calc(2 * var(--step)); }
.tile-pos-0-3 { top: 0;                       left: calc(3 * var(--step)); }
.tile-pos-1-0 { top: calc(1 * var(--step));   left: 0; }
.tile-pos-1-1 { top: calc(1 * var(--step));   left: calc(1 * var(--step)); }
.tile-pos-1-2 { top: calc(1 * var(--step));   left: calc(2 * var(--step)); }
.tile-pos-1-3 { top: calc(1 * var(--step));   left: calc(3 * var(--step)); }
.tile-pos-2-0 { top: calc(2 * var(--step));   left: 0; }
.tile-pos-2-1 { top: calc(2 * var(--step));   left: calc(1 * var(--step)); }
.tile-pos-2-2 { top: calc(2 * var(--step));   left: calc(2 * var(--step)); }
.tile-pos-2-3 { top: calc(2 * var(--step));   left: calc(3 * var(--step)); }
.tile-pos-3-0 { top: calc(3 * var(--step));   left: 0; }
.tile-pos-3-1 { top: calc(3 * var(--step));   left: calc(1 * var(--step)); }
.tile-pos-3-2 { top: calc(3 * var(--step));   left: calc(2 * var(--step)); }
.tile-pos-3-3 { top: calc(3 * var(--step));   left: calc(3 * var(--step)); }

/* ── Tile colors ───────────────────────────────────────────────────────── */
.tile-2    { background: #eee4da; color: #776e65; font-size: 2.2rem; }
.tile-4    { background: #ede0c8; color: #776e65; font-size: 2.2rem; }
.tile-8    { background: #f2b179; color: #fff;    font-size: 2.2rem; }
.tile-16   { background: #f59563; color: #fff;    font-size: 2.1rem; }
.tile-32   { background: #f67c5f; color: #fff;    font-size: 2.1rem; }
.tile-64   { background: #f65e3b; color: #fff;    font-size: 2.1rem; }
.tile-128  { background: #edcf72; color: #fff;    font-size: 1.8rem; }
.tile-256  { background: #edcc61; color: #fff;    font-size: 1.8rem; }
.tile-512  { background: #edc850; color: #fff;    font-size: 1.8rem; }
.tile-1024 { background: #edc53f; color: #fff;    font-size: 1.5rem; }
.tile-2048 {
  background: #edc22e;
  color: #fff;
  font-size: 1.5rem;
  box-shadow: 0 0 20px 8px rgba(237, 194, 46, 0.4);
}
.tile-super {
  background: #3c3a32;
  color: #fff;
  font-size: 1.3rem;
}

/* ── Animations ────────────────────────────────────────────────────────── */
@keyframes tile-pop {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}

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

.tile-new {
  animation: tile-pop 200ms ease-out;
}

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

/* Ghost tiles slide to merge target then vanish */
.tile-moving {
  z-index: 5;
  animation: none;
}

/* ── Game message overlay ──────────────────────────────────────────────── */
.game-message {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.game-message.active {
  opacity: 1;
  pointer-events: auto;
}

.game-message-over {
  background: rgba(15, 15, 26, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.game-message-win {
  background: rgba(237, 194, 46, 0.15);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.game-message h2 {
  font-size: 2.4rem;
  font-weight: 800;
  margin: 0 0 8px;
}

.game-message-over h2 { color: #f67c5f; }
.game-message-win h2  { color: #f5c518; }

.game-message p {
  font-size: 1rem;
  color: #aaa;
  margin: 0 0 24px;
}

.game-message button {
  background: #f5c518;
  color: #0f0f1a;
  border: none;
  border-radius: 6px;
  padding: 10px 28px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.game-message button:hover { background: #ffd740; }

/* ── How to play ───────────────────────────────────────────────────────── */
.how-to-play {
  width: 100%;
  max-width: 500px;
  margin-top: 24px;
  padding: 16px 20px;
  background: #1a1a2e;
  border-radius: 10px;
  border: 1px solid #2a2a40;
}

.how-to-play h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: #ccc;
  display: flex;
  align-items: center;
  gap: 6px;
}

.how-to-play h3::before {
  content: '\2139';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #2a2a40;
  font-size: 0.75rem;
  color: #8888aa;
}

.how-to-play p {
  margin: 0;
  font-size: 0.9rem;
  color: #8888aa;
  line-height: 1.6;
}

/* ── Ad slots ──────────────────────────────────────────────────────────── */
.ad-wrap {
  width: 100%;
  max-width: 500px;
  margin: 16px auto;
  min-height: 0;
}

/* ── Mobile responsive ─────────────────────────────────────────────────── */
@media (max-width: 540px) {
  .game-2048-page { padding: 12px 10px 40px; }
  .game-title { font-size: 2.2rem; }
  .score-box { padding: 4px 10px; min-width: 58px; }
  .score-value { font-size: 1.1rem; }
  .score-label { font-size: 0.6rem; }

  .tile-2, .tile-4       { font-size: 1.7rem; }
  .tile-8, .tile-16,
  .tile-32, .tile-64      { font-size: 1.6rem; }
  .tile-128, .tile-256,
  .tile-512               { font-size: 1.4rem; }
  .tile-1024              { font-size: 1.1rem; }
  .tile-2048              { font-size: 1.1rem; }
  .tile-super             { font-size: 1rem; }

  .game-message h2 { font-size: 1.8rem; }
}

@media (max-width: 380px) {
  #game-grid { padding: 8px; gap: 7px; }
  #tile-layer { top: 8px; left: 8px; right: 8px; bottom: 8px; --gap: 7px; }
  .game-title { font-size: 1.8rem; }
}
