@import url('https://fonts.googleapis.com/css2?family=Clear+Sans:wght@700&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #faf8ef;
  color: #776e65;
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  font-weight: bold;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.wrapper {
  width: 100%;
  max-width: 480px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.user-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #bbada0;
}

.avatar-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #bbada0;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: bold;
}

.username {
  text-align: center;
  font-size: 14px;
  color: #8f7a66;
}

.scores {
  text-align: right;
}

.score-box {
  background: #bbada0;
  color: white;
  border-radius: 6px;
  width: 100px;
  padding: 8px 0;
  text-align: center;
  font-size: 13px;
}

.label {
  font-size: 10px;
  opacity: 0.9;
}

.value {
  font-size: 24px;
  margin-top: 4px;
}

.best {
  margin-top: 10px;
  cursor: pointer;
}

.board-wrapper {
  position: relative;
  padding-bottom: 100%;
}

.board {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #bbada0;
  border-radius: 12px;
  padding: 10px;
}

.grid {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
}

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

.tiles {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
}

.tile {
  position: absolute;
  width: calc(25% - 7.5px);
  height: calc(25% - 7.5px);
  background: #eee4da;
  color: #776e65;
  border-radius: 8px;
  font-size: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 140ms ease-in-out;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.tile-2 {
  background: #eee4da;
}

.tile-4 {
  background: #ede0c8;
}

.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: 42px;
}

.tile-256 {
  background: #edcc61;
  color: #f9f6f2;
  font-size: 42px;
}

.tile-512 {
  background: #edc850;
  color: #f9f6f2;
  font-size: 42px;
}

.tile-1024 {
  background: #edc53f;
  color: #f9f6f2;
  font-size: 36px;
}

.tile-2048 {
  background: #edc22e;
  color: #f9f6f2;
  font-size: 36px;
}

.new {
  animation: appear 220ms ease-out;
}

@keyframes appear {
  0% {
    transform: scale(0);
    opacity: 0.8;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.8);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.game-over-text {
  font-size: 48px;
  color: #776e65;
  margin-bottom: 30px;
}

.retry-btn {
  background: #8f7a66;
  color: white;
  border: none;
  padding: 14px 32px;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
}

.buttons {
  margin-top: 35px;
  text-align: center;
}

.btn {
  padding: 12px 28px;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  margin: 0 8px;
}

.primary {
  background: #8f7a66;
  color: white;
}

.secondary {
  background: #a89f94;
  color: white;
}

.secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.notice {
  text-align: center;
  padding: 40px 20px;
  background: #ff9800;
  color: white;
  font-size: 20px;
  border-radius: 12px;
  margin: 20px;
}

/* Score History Modal */
.score-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: #faf8ef;
  border-radius: 12px;
  padding: 30px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
  color: #776e65;
  font-size: 24px;
  margin-bottom: 20px;
  text-align: center;
}

/* Best Score Card */
.best-score-card {
  background: linear-gradient(135deg, #f59563 0%, #f67c5f 100%);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  margin-bottom: 25px;
  box-shadow: 0 4px 12px rgba(245, 149, 99, 0.3);
}

.best-label {
  color: #fff;
  font-size: 14px;
  margin-bottom: 8px;
  opacity: 0.95;
}

.best-number {
  color: #fff;
  font-size: 42px;
  font-weight: bold;
}

/* Recent Scores Title */
.recent-scores-title {
  color: #776e65;
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 12px;
  text-align: center;
}

.no-scores {
  text-align: center;
  color: #999;
  padding: 20px 0;
}

.score-list {
  margin: 15px 0;
}

.score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #eee4da;
  border-radius: 8px;
  margin-bottom: 10px;
  gap: 12px;
}

.score-rank {
  font-size: 16px;
  font-weight: bold;
  color: #8f7a66;
  min-width: 32px;
}

.score-number {
  font-size: 24px;
  font-weight: bold;
  color: #776e65;
  flex: 1;
}

.score-date {
  font-size: 14px;
  color: #999;
  min-width: 80px;
  text-align: right;
}

.close-btn {
  width: 100%;
  padding: 14px;
  background: #8f7a66;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  margin-top: 20px;
}

.close-btn:hover {
  background: #9f8a76;
}

/* Resume Game Modal */
.resume-message {
  text-align: center;
  color: #776e65;
  font-size: 16px;
  margin: 20px 0 30px;
  font-weight: normal;
}

.resume-buttons {
  display: flex;
  gap: 12px;
  flex-direction: column;
}

.resume-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  font-weight: bold;
  transition: background 0.2s;
}

.resume-btn.primary {
  background: #edcf72;
  color: #f9f6f2;
}

.resume-btn.primary:hover {
  background: #edcc61;
}

.resume-btn.secondary {
  background: #a89f94;
  color: white;
}

.resume-btn.secondary:hover {
  background: #9f9690;
}