* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #FAF8EF;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

.hidden {
  display: none !important;
}

/* Splash */
#splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  pointer-events: none;
}
#splash img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Milestone overlay */
#milestone-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.53);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
#milestone-overlay img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Dialogs */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.dialog {
  background: #FAF8EF;
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  max-height: 80vh;
  overflow-y: auto;
}
.dialog h2 {
  margin: 0 0 16px 0;
  color: #776E65;
  font-size: 20px;
  text-align: center;
}
.dialog input {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #BBADA0;
  font-size: 16px;
  margin-bottom: 16px;
  background: white;
  color: #333;
}
.dialog button {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: #8F7A66;
  color: white;
  font-weight: bold;
  font-size: 16px;
}

/* App layout */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  min-height: 100vh;
}

.title {
  font-size: 26px;
  font-weight: bold;
  color: #FF66CC;
  text-align: center;
  margin: 16px 0 4px 0;
  line-height: 1.2;
}

.player-label {
  font-size: 15px;
  color: #776E65;
  margin-bottom: 8px;
  min-height: 18px;
}

.topbar {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 8px;
}

.score-box {
  background: #BBADA0;
  border-radius: 8px;
  padding: 8px 18px;
  text-align: center;
}
.score-label {
  color: #EEE4DA;
  font-size: 11px;
  font-weight: bold;
}
.score-value {
  color: white;
  font-size: 20px;
  font-weight: bold;
}

.button-row {
  display: flex;
  gap: 8px;
}
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: bold;
  font-size: 13px;
  color: white;
}
.btn-gold { background: #EDC22E; }
.btn-default { background: #8F7A66; }

.gameover-text {
  font-size: 30px;
  font-weight: bold;
  color: #E74C3C;
  margin-bottom: 8px;
}

.board {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  background: #BBADA0;
  border-radius: 8px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
}

.tile {
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 32px;
  background: #CDC1B4;
  color: #776E65;
  transition: background-color 0.1s ease;
}
.tile[data-v="2"] { background: #EEE4DA; color: #776E65; }
.tile[data-v="4"] { background: #EDE0C8; color: #776E65; }
.tile[data-v="8"] { background: #F2B179; color: #fff; font-size: 30px; }
.tile[data-v="16"] { background: #F59563; color: #fff; font-size: 30px; }
.tile[data-v="32"] { background: #F67C5F; color: #fff; font-size: 30px; }
.tile[data-v="64"] { background: #F65E3B; color: #fff; font-size: 30px; }
.tile[data-v="128"] { background: #A8D08D; color: #fff; font-size: 28px; }
.tile[data-v="256"] { background: #8BC569; color: #fff; font-size: 28px; }
.tile[data-v="512"] { background: #6FBA46; color: #fff; font-size: 28px; }
.tile[data-v="1024"] { background: #4FA82E; color: #fff; font-size: 22px; }
.tile[data-v="2048"] { background: #2E8B1F; color: #fff; font-size: 22px; }
.tile[data-v="0"] { background: #CDC1B4; }

.bottom-text {
  font-size: 14px;
  color: #776E65;
  text-align: center;
  margin-top: 16px;
  max-width: 420px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: #EEE4DA;
}
.leaderboard-row.rank-1 { background: #FFF8DC; }
.leaderboard-row.rank-2 { background: #F5F5F5; }
.leaderboard-row.rank-3 { background: #FFF0E0; }
.lb-rank {
  width: 32px;
  text-align: center;
  font-weight: bold;
  color: #776E65;
  font-size: 14px;
}
.lb-name {
  flex: 1;
  font-size: 15px;
  color: #776E65;
}
.lb-score {
  font-weight: bold;
  font-size: 15px;
  color: #776E65;
}
.leaderboard-header {
  display: flex;
  background: #BBADA0;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  color: white;
  font-weight: bold;
  font-size: 13px;
}
.leaderboard-header .lb-rank { color: white; }
.leaderboard-header .lb-name { flex: 1; color: white; }
.empty-leaderboard {
  text-align: center;
  color: #776E65;
  font-size: 14px;
  padding: 24px 0;
}
