:root {
  --bg: #1a1a2e; --bg2: #22223a; --bg3: #2a2a45;
  --text: #e8e8f0; --text2: #a0a0b8; --text3: #6b6b85;
  --primary: #d97706; --border: #333355;
  --tile-bg: #2a2a45;
}
[data-theme="light"] {
  --bg: #f5f5fa; --bg2: #fff; --bg3: #eee;
  --text: #1a1a2e; --text2: #555; --text3: #999;
  --primary: #b45309; --border: #ddd;
  --tile-bg: #e0dff0;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; display: flex; justify-content: center;
  -webkit-user-select: none; user-select: none;
}
.game-container {
  width: 100%; max-width: 420px; padding: 16px;
  display: flex; flex-direction: column; align-items: center;
}
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; margin-bottom: 12px;
}
.game-header h1 { font-size: 1.3rem; font-weight: 800; }
.back-btn {
  color: var(--primary); text-decoration: none; font-size: .9rem; font-weight: 600;
  padding: 6px 12px; border-radius: 8px; background: var(--bg2); border: 1px solid var(--border);
}
.back-btn:hover { background: var(--primary); color: #fff; }
.theme-btn {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 1rem;
}
.score-bar {
  display: flex; gap: 12px; width: 100%; margin-bottom: 12px;
}
.score-box {
  flex: 1; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; text-align: center;
}
.score-label { font-size: .72rem; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; }
.score-value { font-size: 1.4rem; font-weight: 800; color: var(--primary); }
.board-wrap {
  position: relative; width: 100%; aspect-ratio: 1;
  max-width: 400px;
}
.board {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  background: var(--bg2); border: 2px solid var(--border); border-radius: 12px;
  padding: 8px; width: 100%; aspect-ratio: 1;
}
.tile {
  display: flex; align-items: center; justify-content: center;
  background: var(--tile-bg); border-radius: 8px;
  font-size: 2rem; font-weight: 700;
  transition: all .12s ease;
  aspect-ratio: 1;
  position: relative;
}
.tile.pop {
  animation: pop .2s ease;
}
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.tile.new {
  animation: appear .2s ease;
}
@keyframes appear {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
/* 타일 색상 */
.tile-2    { background: #3a3a5c; }
.tile-4    { background: #4a4a6c; }
.tile-8    { background: #5b4fa8; color: #fff; }
.tile-16   { background: #6c63ff; color: #fff; }
.tile-32   { background: #f97316; color: #fff; }
.tile-64   { background: #ef4444; color: #fff; }
.tile-128  { background: #eab308; color: #fff; font-size: 1.6rem; }
.tile-256  { background: #22c55e; color: #fff; font-size: 1.6rem; }
.tile-512  { background: #06b6d4; color: #fff; font-size: 1.6rem; }
.tile-1024 { background: #ec4899; color: #fff; font-size: 1.4rem; }
.tile-2048 { background: linear-gradient(135deg, #f97316, #ef4444, #ec4899); color: #fff; font-size: 1.4rem; box-shadow: 0 0 20px rgba(249,115,22,.5); }

[data-theme="light"] .tile-2   { background: #e8e5f0; color: #333; }
[data-theme="light"] .tile-4   { background: #d8d5e8; color: #333; }
[data-theme="light"] .tile-8   { background: #9b8fdb; color: #fff; }
[data-theme="light"] .tile-16  { background: #7c6fff; color: #fff; }
[data-theme="light"] .tile-32  { background: #f97316; color: #fff; }
[data-theme="light"] .tile-64  { background: #ef4444; color: #fff; }
[data-theme="light"] .tile-128 { background: #eab308; color: #fff; }
[data-theme="light"] .tile-256 { background: #22c55e; color: #fff; }
[data-theme="light"] .tile-512 { background: #06b6d4; color: #fff; }
[data-theme="light"] .tile-1024{ background: #ec4899; color: #fff; }

.game-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; z-index: 10;
}
.overlay-content { text-align: center; color: #fff; }
.overlay-content h2 { font-size: 1.8rem; margin-bottom: 8px; }
.overlay-content p { font-size: 1rem; margin-bottom: 16px; color: #ccc; }
.btn-restart {
  padding: 10px 24px; background: var(--primary); color: #fff;
  border: none; border-radius: 10px; font-size: .95rem; font-weight: 700;
  cursor: pointer; transition: transform .1s;
}
.btn-restart:active { transform: scale(.95); }
.ranking-section {
  width: 100%; margin-top: 20px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 12px; padding: 14px;
}
.ranking-section h3 { font-size: .95rem; margin-bottom: 10px; }
.ranking-list { display: flex; flex-direction: column; gap: 6px; }
.ranking-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 8px; background: var(--bg3);
  font-size: .85rem;
}
.ranking-row.mine { border: 1px solid var(--primary); background: rgba(124,111,255,.1); }
.rank-num { font-weight: 800; width: 24px; text-align: center; color: var(--primary); }
.rank-name { flex: 1; }
.rank-score { font-weight: 700; color: var(--text2); }
.ranking-loading { text-align: center; padding: 16px; color: var(--text3); font-size: .82rem; }
.guide {
  margin-top: 16px; text-align: center; color: var(--text3); font-size: .78rem;
  line-height: 1.8;
}
@media (max-width: 440px) {
  .game-container { padding: 10px; }
  .board { gap: 6px; padding: 6px; }
  .tile { font-size: 1.6rem; }
  .tile-128, .tile-256, .tile-512 { font-size: 1.3rem; }
  .tile-1024, .tile-2048 { font-size: 1.1rem; }
}
