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

:root {
  --bg: #171a38; --panel: #212549; --panel2: #2a2f5e;
  --ink: #eef0ff; --muted: rgba(238,240,255,.6);
  --board: #26315a; --cell: #313c68;
  --gap: 3.2%;
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: radial-gradient(circle at 50% 15%, #232860, var(--bg) 70%);
  font-family: -apple-system, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}

.hidden { display: none !important; }

#app {
  max-width: 480px; margin: 0 auto;
  min-height: 100%;
  display: flex; flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  justify-content: center;
}

header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
h1 { font-size: 40px; font-weight: 900; letter-spacing: 1px; line-height: 1; }
h1 span {
  font-size: 20px;
  background: linear-gradient(135deg, #ffe07a, #edc22e, #ff8a3d);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.sub { color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 4px; }
.sub b { color: #edc22e; }

.scores { display: flex; gap: 8px; }
.scoreBox {
  background: var(--panel); border-radius: 12px; padding: 6px 14px;
  text-align: center; min-width: 68px;
}
.scoreBox span { display: block; font-size: 10px; font-weight: 800; letter-spacing: 1px; color: var(--muted); }
.scoreBox b { font-size: 22px; font-variant-numeric: tabular-nums; }
.scoreBox b.bump { animation: bump .2s ease; }
@keyframes bump { 40% { transform: scale(1.2); color: #edc22e; } }

.bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.bar2 { margin-bottom: 14px; }
.bar2 #dailyBtn, .bar2 #newBtn { flex: 1; }
.bar button, .bar .home { white-space: nowrap; }
.coinChip {
  display: flex; align-items: center; gap: 6px; min-height: 44px;
  background: rgba(0,0,0,.28); border-radius: 16px; padding: 6px 12px;
  color: #ffd75e; font-weight: 800; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
#coins.bump { animation: bump .3s ease; }
.coinIcon {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a0, #f5b820 65%, #c78a00);
}
#dailyBtn {
  border: none; border-radius: 12px; padding: 0 14px; min-height: 44px;
  background: linear-gradient(135deg, #a5d8ff, #4dabf7); color: #0b2d4a;
  font-weight: 900; font-size: 14px; cursor: pointer;
  box-shadow: 0 3px 0 #1c7ed6;
}
#dailyBtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #1c7ed6; }
#dailyBtn.on { background: linear-gradient(135deg, #d0bfff, #9775fa); color: #2b1a55; box-shadow: 0 3px 0 #7048e8; }
#newBtn {
  border: none; border-radius: 12px; padding: 0 18px; min-height: 44px;
  background: linear-gradient(135deg, #ffe07a, #edc22e); color: #5b3a00;
  font-weight: 900; font-size: 14px; cursor: pointer;
  box-shadow: 0 3px 0 #b8901a;
}
#newBtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b8901a; }
#lbBtn {
  border: none; border-radius: 12px; padding: 0 13px; min-height: 44px; min-width: 44px;
  background: rgba(255,255,255,.12); color: #fff;
  font-weight: 900; font-size: 16px; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
#lbBtn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.home {
  margin-left: auto;
  color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 800;
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px;
  background: rgba(255,255,255,.08); border-radius: 12px;
}
.home:active { transform: translateY(1px); }

/* daily scoreboard panel */
#lbPanel {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,12,30,.72); backdrop-filter: blur(6px);
}
#lbCard {
  width: min(360px, 92vw); text-align: center;
  background: #1d2145; border: 1px solid rgba(255,255,255,.14);
  border-radius: 18px; padding: 20px 16px;
  box-shadow: 0 18px 44px rgba(0,0,0,.5);
  animation: lbIn .25s ease;
}
@keyframes lbIn { from { transform: translateY(14px) scale(.97); opacity: 0; } }
#lbCard h3 { font-size: 16px; font-weight: 900; letter-spacing: 1px; }
#lbSub { color: var(--muted); font-size: 12px; font-weight: 700; margin: 4px 0 12px; }
#lbList { max-height: 46vh; overflow-y: auto; }
.lbRow {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px;
  font-weight: 800; font-size: 14px;
}
.lbRow:nth-child(odd) { background: rgba(255,255,255,.05); }
.lbRow.me { background: rgba(237,194,46,.18); color: #ffd75e; }
.lbRow .rank { width: 28px; text-align: left; color: var(--muted); }
.lbRow.me .rank { color: #ffd75e; }
.lbRow .nm { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lbRow .sc { font-variant-numeric: tabular-nums; }
.lbEmpty { color: var(--muted); font-size: 13px; font-weight: 700; padding: 18px 6px; }
#lbClose {
  margin-top: 14px; border: none; border-radius: 12px; padding: 10px 26px;
  background: rgba(255,255,255,.14); color: #fff; font-weight: 900; font-size: 14px; cursor: pointer;
}

#boardWrap {
  position: relative;
  width: 100%; aspect-ratio: 1;
  background: var(--board);
  border-radius: 12px;
  padding: var(--gap);
  box-shadow: 0 16px 44px rgba(0,0,0,.5);
}
#grid {
  position: absolute; inset: var(--gap);
  display: grid;
  grid-template: repeat(4, 1fr) / repeat(4, 1fr);
  gap: var(--gap);
}
#grid .bg { background: var(--cell); border-radius: 9px; }

#tiles { position: absolute; inset: var(--gap); }
.tile {
  position: absolute;
  width: calc((100% - 3 * var(--gap)) / 4);
  height: calc((100% - 3 * var(--gap)) / 4);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900;
  transition: left .12s ease, top .12s ease;
  will-change: left, top;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.tile .num { transition: transform .1s; }
.tile.spawn { animation: spawn .18s ease; }
@keyframes spawn { from { transform: scale(0); } }
.tile.merged { animation: pop .2s cubic-bezier(.3,1.6,.5,1); z-index: 2; }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.26); } 100% { transform: scale(1); } }

/* floating "+score" pops on merge */
#tiles .pluspop {
  position: absolute; z-index: 6; pointer-events: none;
  font-weight: 900; font-size: 4.4vmin; color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
  transform: translate(-50%, -50%);
  animation: plusUp .7s ease-out forwards;
}
@keyframes plusUp {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(.6); }
  22% { opacity: 1; transform: translate(-50%, -60%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -140%) scale(1); }
}
@media (min-width: 480px) { #tiles .pluspop { font-size: 22px; } }

/* particle / confetti overlay */
#fx { position: fixed; inset: 0; z-index: 25; pointer-events: none; }

/* board reaction shake on big merges */
#boardWrap.shake { animation: shake .34s ease; }
@keyframes shake {
  10%,90% { transform: translateX(-1.5px); }
  20%,80% { transform: translateX(3px); }
  30%,50%,70% { transform: translateX(-5px); }
  40%,60% { transform: translateX(5px); }
}

/* tile colors — classic 2048 warm palette on our dark theme */
.t2    { background: #eee4da; color: #6b6154; font-size: 8vmin; }
.t4    { background: #ede0c8; color: #6b6154; font-size: 8vmin; }
.t8    { background: #f2b179; color: #fff; font-size: 8vmin; }
.t16   { background: #f59563; color: #fff; font-size: 7.4vmin; }
.t32   { background: #f67c5f; color: #fff; font-size: 7.4vmin; }
.t64   { background: #f65e3b; color: #fff; font-size: 7.4vmin; }
.t128  { background: #edcf72; color: #fff; font-size: 6.2vmin; box-shadow: 0 0 18px rgba(237,207,114,.5); }
.t256  { background: #edcc61; color: #fff; font-size: 6.2vmin; box-shadow: 0 0 20px rgba(237,204,97,.55); }
.t512  { background: #edc850; color: #fff; font-size: 6.2vmin; box-shadow: 0 0 22px rgba(237,200,80,.6); }
.t1024 { background: #edc53f; color: #fff; font-size: 5vmin; box-shadow: 0 0 26px rgba(237,197,63,.7); }
.t2048 { background: #edc22e; color: #fff; font-size: 5vmin; box-shadow: 0 0 32px rgba(237,194,46,.85); }
.tbig  { background: #3c3a32; color: #fff; font-size: 4.6vmin; box-shadow: 0 0 32px rgba(60,58,50,.8); }
@media (min-width: 480px) {
  .t2, .t4, .t8 { font-size: 38px; } .t16, .t32, .t64 { font-size: 35px; }
  .t128, .t256, .t512 { font-size: 30px; } .t1024, .t2048, .tbig { font-size: 24px; }
}

#overlay {
  position: absolute; inset: 0;
  background: rgba(23,26,56,.86);
  border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; z-index: 5;
  animation: fade .3s ease;
}
@keyframes fade { from { opacity: 0; } }
#ovTitle { font-size: 34px; font-weight: 900; letter-spacing: 1px; }
#ovMsg { color: var(--muted); font-weight: 700; }
#ovBtns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; padding: 0 10px; }
#ovBtns button {
  border: none; border-radius: 14px; padding: 13px 24px;
  font-weight: 900; font-size: 15px; letter-spacing: 1px; cursor: pointer;
  color: #08331a; background: linear-gradient(135deg, #6dedb0, #22c76a);
  box-shadow: 0 4px 0 #169148;
}
#ovBtns button#keepBtn { color: #5b3a00; background: linear-gradient(135deg, #ffe07a, #edc22e); box-shadow: 0 4px 0 #b8901a; }
#ovBtns button#shareBtn { color: #0b2d4a; background: linear-gradient(135deg, #a5d8ff, #4dabf7); box-shadow: 0 4px 0 #1c7ed6; }
#ovBtns button:active { transform: translateY(2px); }

.hint { text-align: center; color: var(--muted); font-size: 12px; font-weight: 600; margin-top: 14px; }
