/* 2048 → 4096 · Baithak — bright theme, warm amber/orange tiles */
:root {
  --bg0: #fff8e7;
  --bg1: #ffefd9;
  --amber: #ffb020;
  --amber-light: #ffd166;
  --amber-deep: #c77e00;
  --ink: #2a1f08;
  --text: #3a2c1c;
  --text-dim: #8a755c;
  --card: #fffdf8;
  --card-border: #eadfc8;
  --cell-bg: #f1e6cf;
  --radius: 16px;
}
body[data-bgfx="g2048"] { --accent: #ffb020; --accent-2: #ff7a1a; }

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

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  /* viewport lock: flex column shell (topbar + main); shared baithak.css
     pins height to 100dvh and disables page scroll */
  display: flex;
  flex-direction: column;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  /* page background comes from shared baithak.css (bright gradient) */
  overflow-x: hidden;
}

/* floating background orbs — soft pastel, bright-compatible */
.bg-orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.orb { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .5; animation: drift 14s ease-in-out infinite alternate; }
.o1 { width: 280px; height: 280px; left: -80px; top: 8%; background: #ffc4d6; }
.o2 { width: 220px; height: 220px; right: -60px; top: 46%; background: #ffd9a0; animation-delay: -5s; }
.o3 { width: 200px; height: 200px; left: 12%; bottom: -60px; background: #bfe3ff; animation-delay: -9s; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(46px, -34px) scale(1.12); }
}

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

.topbar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 520px; margin: 0 auto; padding: 14px 18px 0;
}
.back {
  color: var(--amber-deep); text-decoration: none; font-weight: 800; font-size: 15px;
  padding: 8px 14px; border-radius: 999px; border: 2px solid var(--card-border);
  background: var(--card); transition: transform .15s ease;
  box-shadow: 0 2px 8px rgba(120, 80, 20, .08);
}
.back:hover { transform: translateY(-2px); }
.top-tag { color: var(--text-dim); font-size: 13px; }

.wrap { position: relative; z-index: 2; max-width: 520px; margin: 0 auto; padding: 6px 18px 48px; }

.title-row { text-align: center; margin: 10px 0 14px; }
.game-title {
  margin: 0; font-size: clamp(52px, 15vw, 76px); font-weight: 900; letter-spacing: -2px;
  background: linear-gradient(180deg, var(--amber-light), var(--amber) 60%, #f59e0b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 18px rgba(255, 176, 32, .35));
  animation: title-bounce 3.2s ease-in-out infinite;
}
@keyframes title-bounce {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-6px) rotate(1deg); }
}
.tagline { margin: 6px 0 0; color: var(--text-dim); font-size: 16px; }
.tagline b { color: var(--amber-light); }

/* ---------- HUD ---------- */
.hud { display: flex; align-items: stretch; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.scores { display: flex; gap: 10px; }
.score-box {
  position: relative; min-width: 86px; padding: 8px 14px 10px; text-align: center;
  background: var(--card); border: 2px solid var(--card-border); border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(120, 80, 20, .10);
  overflow: visible;
}
.score-box .label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--amber-deep); font-weight: 800; }
.score-box .value { display: block; font-size: 24px; font-weight: 900; color: var(--text); line-height: 1.25; }
.score-pop {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%);
  color: var(--amber-light); font-weight: 900; font-size: 18px; white-space: nowrap;
  animation: score-float .8s ease-out forwards; pointer-events: none;
}
@keyframes score-float {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -34px); }
}
.actions { display: flex; gap: 10px; align-items: stretch; }

.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; font-size: 15px; font-weight: 800;
  cursor: pointer; font-family: inherit; min-height: 48px;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.btn:active { transform: translateY(2px) scale(.97); }
.btn.gold {
  background: linear-gradient(180deg, var(--amber-light), var(--amber)); color: var(--ink);
  box-shadow: 0 4px 0 var(--amber-deep), 0 8px 20px rgba(255, 176, 32, .35);
}
.btn.gold:hover { filter: brightness(1.06); transform: translateY(-2px); }
.btn.ghost {
  background: #fffdf8; color: #3a2c1c;
  border: 2px solid #eadfc8; box-shadow: 0 2px 8px rgba(120, 80, 20, .08);
}
.btn.ghost:hover:not(:disabled) { background: #fbf3e2; }
.btn:disabled { opacity: .4; cursor: default; }

/* ---------- Board ---------- */
.board {
  position: relative; width: min(100%, 54dvh); margin-inline: auto; aspect-ratio: 1 / 1;
  background: #f7efdc; border: 2px solid var(--card-border);
  border-radius: 20px; padding: 0; touch-action: none; user-select: none;
  box-shadow: 0 14px 44px rgba(120, 80, 20, .15), 0 0 34px rgba(255, 176, 32, .15);
  overflow: hidden;
}
.grid-bg {
  position: absolute; inset: 0; padding: var(--gap, 10px);
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr);
  gap: var(--gap, 10px);
}
.grid-bg i { background: var(--cell-bg); border-radius: 10px; box-shadow: inset 0 2px 6px rgba(120, 80, 20, .12); }
.tiles { position: absolute; inset: 0; }
.tile {
  position: absolute; left: 0; top: 0;
  width: var(--cell, 100px); height: var(--cell, 100px);
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; font-weight: 900;
  font-size: calc(var(--cell, 100px) * .40);
  transition: transform 125ms ease-in-out;
  will-change: transform;
}
.board.no-anim .tile { transition: none !important; }
.tile > span { display: block; line-height: 1; animation: none; }
.tile.digits4 { font-size: calc(var(--cell, 100px) * .34); }
.tile.digits5 { font-size: calc(var(--cell, 100px) * .27); }

/* spawn + merge pops (inner span so they don't fight the slide transform) */
.tile.spawn > span { animation: tile-spawn 200ms cubic-bezier(.2, 1.7, .4, 1); }
@keyframes tile-spawn { from { transform: scale(0); } to { transform: scale(1); } }
.tile.pop > span { animation: tile-pop 180ms cubic-bezier(.2, 1.7, .4, 1); }
@keyframes tile-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); }
  100% { transform: scale(1); }
}
.tile.dying > span { transition: opacity 110ms ease, transform 110ms ease; opacity: 0; transform: scale(.3); }

/* ---------- Tile colors: warm amber/orange ladder 2 → 8192+ ---------- */
.t2     { background: linear-gradient(135deg, #fff6e3, #ffe3ae); color: #7c4a08; box-shadow: 0 3px 10px rgba(255,200,120,.45); }
.t4     { background: linear-gradient(135deg, #ffedb8, #ffda85); color: #7c4a08; box-shadow: 0 3px 10px rgba(255,200,110,.5); }
.t8     { background: linear-gradient(135deg, #ffdd96, #ffc45e); color: #6f3d05; box-shadow: 0 3px 12px rgba(255,180,80,.55); }
.t16    { background: linear-gradient(135deg, #ffd07a, #ffab3d); color: #fff; text-shadow: 0 1px 3px rgba(90,40,0,.45); box-shadow: 0 3px 12px rgba(255,170,60,.6); }
.t32    { background: linear-gradient(135deg, #ffc35c, #ff9a1f); color: #fff; text-shadow: 0 1px 3px rgba(90,40,0,.5); box-shadow: 0 3px 12px rgba(255,155,30,.6); }
.t64    { background: linear-gradient(135deg, #ffae3d, #ff8a00); color: #fff; text-shadow: 0 1px 3px rgba(90,35,0,.5); box-shadow: 0 3px 14px rgba(255,140,0,.65); }
.t128   { background: linear-gradient(135deg, #ff9830, #f96d00); color: #fff; text-shadow: 0 1px 3px rgba(80,30,0,.5); box-shadow: 0 3px 14px rgba(250,110,0,.7); }
.t256   { background: linear-gradient(135deg, #ff8326, #ef5f00); color: #fff; text-shadow: 0 1px 3px rgba(80,25,0,.55); box-shadow: 0 3px 16px rgba(240,100,0,.72); }
.t512   { background: linear-gradient(135deg, #ff7038, #e04e00); color: #fff; text-shadow: 0 1px 3px rgba(80,20,0,.55); box-shadow: 0 3px 18px rgba(230,85,0,.78); }
.t1024  { background: linear-gradient(135deg, #fb6a2e, #d14400); color: #fff; text-shadow: 0 1px 4px rgba(70,20,0,.6); box-shadow: 0 3px 20px rgba(215,75,0,.82); }
.t2048  { background: linear-gradient(135deg, #ff8a3d, #e04e00); color: #fff; text-shadow: 0 1px 4px rgba(70,20,0,.6); box-shadow: 0 0 24px rgba(255,120,20,.95), 0 0 60px rgba(255,140,30,.5); }
/* win tier and beyond: intense golden glow + pulse */
.t4096  {
  background: linear-gradient(135deg, #ffd166, #ff8c1a); color: #5a2c00;
  box-shadow: 0 0 26px rgba(255,150,20,.95), 0 0 60px rgba(255,150,20,.5);
  animation: win-pulse 1.6s ease-in-out infinite;
}
.t8192  {
  background: linear-gradient(135deg, #fff3c4, #ffb020); color: #5a2c00; text-shadow: none;
  box-shadow: 0 0 30px rgba(255,176,32,1), 0 0 70px rgba(255,176,32,.55);
  animation: win-pulse 1.4s ease-in-out infinite;
}
.tsuper {
  background: linear-gradient(135deg, #fff8e6, #ffd166 45%, #ff9a3d); color: #5a2c00;
  box-shadow: 0 0 34px rgba(255,220,150,.95), 0 0 80px rgba(255,170,60,.6);
  animation: win-pulse 1.2s ease-in-out infinite;
}
@keyframes win-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

/* ---------- Overlay ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(58, 44, 28, .5); backdrop-filter: blur(4px);
  border-radius: 18px; transition: opacity .25s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.panel {
  text-align: center; padding: 30px 34px; margin: 0 18px;
  background: #fffdf8;
  border: 2px solid var(--card-border); border-radius: 20px;
  box-shadow: 0 18px 50px rgba(120, 80, 20, .25), 0 0 40px rgba(255, 176, 32, .18);
  animation: panel-in 350ms cubic-bezier(.2, 1.5, .4, 1);
  max-width: 90%;
}
@keyframes panel-in {
  from { transform: scale(.6) rotate(-3deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}
.panel h2 {
  margin: 0 0 8px; font-size: 38px; font-weight: 900;
  background: linear-gradient(180deg, var(--amber-light), var(--amber));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.panel p { margin: 0 0 20px; color: var(--text-dim); font-size: 16px; }
.panel p b { color: #3a2c1c; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.hint { text-align: center; color: var(--text-dim); font-size: 13px; margin: 14px 0 22px; }

.how {
  background: var(--card); border: 2px solid var(--card-border);
  border-radius: var(--radius); padding: 16px 20px;
  box-shadow: 0 4px 14px rgba(120, 80, 20, .10);
}
.how h3 { margin: 0 0 8px; color: var(--amber-deep); font-size: 17px; }
.how ul { margin: 0; padding-left: 20px; color: var(--text-dim); font-size: 14px; line-height: 1.7; }
.how b { color: #3a2c1c; }

@media (max-width: 420px) {
  .hud { flex-direction: column; }
  .scores { justify-content: center; }
  .actions { justify-content: center; }
  .btn { flex: 1; }
  .panel h2 { font-size: 30px; }
}

/* ---------- Baithak bright theme accents: g2048 ---------- */
.board { animation: board-glow 4.5s ease-in-out infinite; }
@keyframes board-glow {
  0%, 100% { box-shadow: 0 14px 44px rgba(120, 80, 20, .15), 0 0 22px rgba(255, 150, 40, .12); }
  50% { box-shadow: 0 14px 44px rgba(120, 80, 20, .15), 0 0 46px rgba(255, 150, 40, .30); }
}
.btn.gold { transition: transform .12s ease, box-shadow .12s ease, filter .12s ease; }
@media (prefers-reduced-motion: reduce) {
  .game-title, .orb, .t4096, .t8192, .tsuper, .board { animation: none !important; }
}
