:root {
  --bg-night: #09111d;
  --bg-dusk: #2a1f3b;
  --bg-sunset: #6d3346;
  --panel: rgba(18, 15, 28, 0.78);
  --line: rgba(255, 170, 106, 0.28);
  --text: #fff3e7;
  --muted: #e1c0ad;
  --accent-gold: #ffd95d;
  --accent-orange: #ff9350;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
  --cell: rgba(255, 255, 255, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Rajdhani", sans-serif;
  color: var(--text);
  min-height: 100vh;
  background:
    radial-gradient(circle at 82% 12%, rgba(255, 217, 93, 0.2), transparent 24%),
    radial-gradient(circle at 68% 24%, rgba(255, 147, 80, 0.24), transparent 34%),
    radial-gradient(circle at 18% 8%, rgba(207, 109, 142, 0.2), transparent 36%),
    linear-gradient(140deg, var(--bg-night), var(--bg-dusk) 54%, var(--bg-sunset));
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 170, 106, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 170, 106, 0.06) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), transparent 78%);
}

.puzzle-shell {
  width: min(1100px, 94vw);
  margin: 20px auto 34px;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr);
  position: relative;
  z-index: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
}

.top-panel,
.stats-panel {
  grid-column: 1 / -1;
}

.top-panel {
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.kicker {
  margin: 0;
  color: #ffd9a0;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  font-size: 0.76rem;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  font-family: "Orbitron", sans-serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

h1 {
  margin-top: 5px;
  font-size: clamp(1.4rem, 2.8vw, 2.1rem);
}

.subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-size: 1.05rem;
}

.action-btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  color: #2b1203;
  background: linear-gradient(90deg, var(--accent-orange), var(--accent-gold));
  font-family: "Orbitron", sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.stats-panel {
  padding: 10px;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.stat {
  border: 1px solid rgba(255, 190, 126, 0.24);
  border-radius: 11px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.stat span {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #ffd6b2;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 1.05rem;
}

.board-panel {
  position: relative;
  padding: 14px;
  display: grid;
  place-items: center;
}

.board {
  width: min(100%, 520px);
  aspect-ratio: 1;
  border-radius: 14px;
  border: 1px solid rgba(255, 190, 126, 0.3);
  background: rgba(8, 16, 28, 0.5);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  touch-action: none;
}

.cell {
  border-radius: 10px;
  background: var(--cell);
  display: grid;
  place-items: center;
  font-family: "Orbitron", sans-serif;
  font-size: clamp(1rem, 2.4vw, 1.7rem);
  font-weight: 700;
  color: #fff6e5;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.cell.empty {
  color: transparent;
}

.tile-2 { background: #edd8b2; color: #3b2a14; }
.tile-4 { background: #f0cf8d; color: #3b2a14; }
.tile-8 { background: #ffb970; color: #40250b; }
.tile-16 { background: #ff9e62; color: #3f1f06; }
.tile-32 { background: #ff8161; color: #3f1509; }
.tile-64 { background: #ff6666; color: #3f100d; }
.tile-128 { background: #ffd95d; color: #392100; }
.tile-256 { background: #f1ff83; color: #2d3000; }
.tile-512 { background: #84ff8a; color: #073009; }
.tile-1024 { background: #5fd1ff; color: #03273b; }
.tile-2048 { background: #c094ff; color: #1e1037; }
.tile-hi { background: #ff69bf; color: #3e0830; }

.overlay {
  position: absolute;
  inset: 14px;
  border-radius: 12px;
  display: none;
  place-items: center;
  text-align: center;
  background: rgba(8, 14, 24, 0.8);
  color: #fff4e7;
  padding: 20px;
}

.overlay.show {
  display: grid;
}

.overlay h2 {
  font-size: clamp(1.2rem, 2.8vw, 1.9rem);
  color: #ffdda5;
}

.overlay p {
  margin-top: 8px;
}

.side-panel {
  padding: 15px;
}

.side-copy {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 1.04rem;
}

@media (max-width: 1020px) {
  .puzzle-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .top-panel {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
