/* 2048 Full Remake */
:root {
  --bg-0: #0f172a;
  --bg-1: #1e293b;
  --panel: rgba(15, 23, 42, 0.78);
  --line: rgba(148, 163, 184, 0.18);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #34d399;
  --accent-2: #fbbf24;
  --danger: #fb7185;
  --board: #334155;
  --cell: rgba(15, 23, 42, 0.45);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --tile-gap: 12px;
  --board-size: min(92vw, 460px);
  --cell-size: calc((var(--board-size) - var(--tile-gap) * 5) / 4);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 12% 18%, rgba(52, 211, 153, 0.14), transparent 28%),
    radial-gradient(circle at 88% 12%, rgba(251, 191, 36, 0.12), transparent 24%),
    linear-gradient(165deg, #0b1220 0%, #111827 45%, #0f172a 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

body.g2048-remake {
  overflow-x: hidden;
}

.g2048-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.g2048-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}
.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #34d399, #fbbf24);
  color: #052e16;
  font-weight: 900;
}
.brand small {
  display: block;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

.top-actions, .mode-tabs, .toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 12px;
  min-height: 40px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn:hover { border-color: rgba(52, 211, 153, 0.45); }
.btn.primary {
  background: linear-gradient(135deg, rgba(52,211,153,0.95), rgba(16,185,129,0.9));
  color: #052e16;
  border-color: transparent;
}
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.mode-tab.active {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.45);
}

.g2048-main {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 18px 16px 28px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.stat-card, .panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card {
  padding: 12px;
}
.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.stat-card strong {
  font-size: 22px;
  font-weight: 800;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.board-shell {
  width: var(--board-size);
  padding: var(--tile-gap);
  border-radius: 24px;
  background: linear-gradient(180deg, #475569, #334155);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
}

.board {
  position: relative;
  width: calc(var(--board-size) - var(--tile-gap) * 2);
  height: calc(var(--board-size) - var(--tile-gap) * 2);
}

.grid-bg {
  display: grid;
  grid-template-columns: repeat(4, var(--cell-size));
  grid-template-rows: repeat(4, var(--cell-size));
  gap: var(--tile-gap);
  position: absolute;
  inset: 0;
}
.grid-bg div {
  background: var(--cell);
  border-radius: 12px;
}

.tiles {
  position: absolute;
  inset: 0;
}

.tile {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 900;
  transition: transform 140ms ease-in-out;
  will-change: transform;
  box-shadow: 0 8px 18px rgba(0,0,0,0.18);
}
.tile.spawn { animation: tile-spawn 150ms ease-out; }
.tile.merge { animation: tile-merge 160ms ease-out; }
.tile .val {
  font-size: clamp(18px, 5.2vw, 34px);
  line-height: 1;
}

@keyframes tile-spawn {
  from { transform: scale(0.45); opacity: 0.2; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes tile-merge {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.tile.v2 { background: #e2e8f0; color: #0f172a; }
.tile.v4 { background: #cbd5e1; color: #0f172a; }
.tile.v8 { background: #fdba74; color: #fff7ed; }
.tile.v16 { background: #fb923c; color: #fff7ed; }
.tile.v32 { background: #f97316; color: #fff7ed; }
.tile.v64 { background: #ea580c; color: #fff7ed; }
.tile.v128 { background: #fbbf24; color: #422006; }
.tile.v256 { background: #f59e0b; color: #422006; }
.tile.v512 { background: #eab308; color: #422006; }
.tile.v1024 { background: #34d399; color: #052e16; }
.tile.v2048 { background: linear-gradient(135deg, #34d399, #fbbf24); color: #052e16; }
.tile.v4096, .tile.v8192, .tile.v16384, .tile.v32768, .tile.v65536 {
  background: linear-gradient(135deg, #a78bfa, #34d399);
  color: #0b1020;
}

.toolbar {
  width: var(--board-size);
  justify-content: space-between;
}
.toolbar .btn { min-width: 72px; }
.hint-line, .status-line {
  width: var(--board-size);
  color: var(--muted);
  font-size: 14px;
  min-height: 20px;
}

.side-stack {
  display: grid;
  gap: 12px;
}
.panel-card { padding: 14px; }
.panel-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
}
.panel-card p, .panel-card li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.panel-card ul {
  margin: 0;
  padding-left: 18px;
}
.achievements, .mode-help {
  display: grid;
  gap: 8px;
}
.ach-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.ach-item.unlocked {
  color: var(--text);
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
}
.ach-item strong { display: block; margin-bottom: 2px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.62);
  display: none;
  place-items: center;
  z-index: 40;
  padding: 16px;
}
.overlay.show { display: grid; }
.overlay-card {
  width: min(420px, 100%);
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.overlay-card h2 { margin: 0 0 8px; }
.overlay-card p { color: var(--muted); margin: 0 0 14px; }
.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.result-grid div {
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 10px;
}
.result-grid span { display:block; color: var(--muted); font-size: 12px; }
.result-grid strong { font-size: 18px; }
.overlay-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15,23,42,0.95);
  border: 1px solid rgba(52,211,153,0.35);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  opacity: 0;
  transition: .2s ease;
  z-index: 50;
  font-weight: 700;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .play-layout { grid-template-columns: 1fr; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-stack { order: 2; }
}
@media (max-width: 640px) {
  :root {
    --tile-gap: 10px;
    --board-size: min(94vw, 420px);
  }
  .g2048-top { padding: 10px 12px; }
  .brand small { display: none; }
  .top-actions .btn-label { display: none; }
  .tile .val { font-size: clamp(16px, 6vw, 28px); }
}
