/* ==========================================================================
   2048 Cupcakes & Classic 2048 — Master Stylesheet
   3 Modes (Cupcakes, Classic 2048, Pop Eras) + 3 Visual Themes
   ========================================================================== */

:root, [data-theme="bakery"] {
  --bg-page: radial-gradient(circle at 50% 15%, #2f1f42 0%, #1c1328 58%, #110b19 100%);
  --bg-card: linear-gradient(145deg, #322246 0%, #221631 100%);
  --border-card: #563b78;
  --board-bg: linear-gradient(145deg, #392750 0%, #271a38 100%);
  --board-border: #66468f;
  --socket-bg: rgba(16, 10, 25, 0.58);
  --socket-border: rgba(255, 255, 255, 0.08);
  --text-main: #fff8fc;
  --text-muted: #cbb4e3;
  --accent-pink: #f472b6;
  --accent-gold: #fbbf24;
}

[data-theme="pastel"] {
  --bg-page: radial-gradient(circle at 50% 15%, #fff7f9 0%, #f7ebe8 65%, #efe0dc 100%);
  --bg-card: linear-gradient(145deg, #ffffff 0%, #f9f1ef 100%);
  --border-card: #e2c9c2;
  --board-bg: linear-gradient(145deg, #bbada0 0%, #a69688 100%);
  --board-border: #8f7a66;
  --socket-bg: rgba(238, 228, 218, 0.38);
  --socket-border: rgba(255, 255, 255, 0.22);
  --text-main: #4a3531;
  --text-muted: #8c6f68;
  --accent-pink: #db2777;
  --accent-gold: #d97706;
}

[data-theme="midnight"] {
  --bg-page: radial-gradient(circle at 50% 15%, #1e2f5d 0%, #131e3d 60%, #0b1226 100%);
  --bg-card: linear-gradient(145deg, #213363 0%, #162347 100%);
  --border-card: #3d5a9e;
  --board-bg: linear-gradient(145deg, #24376b 0%, #172449 100%);
  --board-border: #4868b5;
  --socket-bg: rgba(10, 16, 36, 0.6);
  --socket-border: rgba(148, 184, 255, 0.14);
  --text-main: #f8fafc;
  --text-muted: #93b4ef;
  --accent-pink: #38bdf8;
  --accent-gold: #facc15;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  min-height: 100%;
  background: var(--bg-page);
  background-attachment: fixed;
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 120;
}

.app-container {
  width: 100%;
  max-width: 470px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  font-size: 1.9rem;
  line-height: 1;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.35));
}

.brand-titles {
  display: flex;
  flex-direction: column;
}

.game-title {
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: 0.8px;
  line-height: 1.05;
  background: linear-gradient(135deg, #fde047 0%, #f472b6 55%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="pastel"] .game-title {
  background: linear-gradient(135deg, #db2777 0%, #9333ea 60%, #d97706 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.game-subtitle {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1.8px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-card);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent-gold);
}

.svg-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Mode Switcher + Scores */
.top-dashboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: nowrap;
}

.mode-pills {
  display: inline-flex;
  background: var(--bg-card);
  border: 1.5px solid var(--border-card);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}

.mode-pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 6px 8px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.mode-pill.active {
  background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(236, 72, 153, 0.4);
}

.score-cards {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
}

.score-box {
  background: var(--bg-card);
  border: 1.5px solid var(--border-card);
  border-radius: 11px;
  padding: 3px 8px;
  min-width: 68px;
  text-align: center;
  display: flex;
  flex-direction: column;
}

.score-lbl {
  font-size: 0.6rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.8px;
}

.score-val {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--accent-gold);
}

/* Cupcake Evolution Strip */
.evolution-strip {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 4px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-card);
  border-radius: 13px;
  padding: 6px 8px;
}

.evo-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3px 1px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0.38;
  filter: grayscale(0.6);
  transition: all 0.2s ease;
}

.evo-item.unlocked {
  opacity: 1;
  filter: none;
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.45);
}

.evo-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.evo-num {
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--text-main);
}

/* Main 4x4 Board */
.board-viewport {
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-frame {
  position: relative;
  width: min(90vw, 410px, 50vh);
  height: min(90vw, 410px, 50vh);
  background: var(--board-bg);
  border: 3px solid var(--board-border);
  border-radius: 22px;
  padding: 10px;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.45), inset 0 2px 5px rgba(255, 255, 255, 0.12);
  touch-action: none;
}

.grid-background {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
}

.grid-socket {
  background: var(--socket-bg);
  border: 1.5px solid var(--socket-border);
  border-radius: 14px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35);
}

.tiles-layer {
  position: absolute;
  inset: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  pointer-events: none;
}

.tile-cell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-card {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 4px;
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.55),
    inset 0 -3px 3px rgba(0, 0, 0, 0.22),
    0 5px 12px rgba(0, 0, 0, 0.32);
  transition: transform 0.14s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tile-card.spawn-pop {
  animation: tileSpawn 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tile-card.merge-pop {
  animation: tileMerge 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tileSpawn {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes tileMerge {
  0% { transform: scale(0.85); }
  50% { transform: scale(1.16); filter: brightness(1.18); }
  100% { transform: scale(1); }
}

.tile-badge {
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 0.58rem;
  font-weight: 900;
  padding: 1px 4px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.24);
  color: inherit;
  line-height: 1.1;
}

.tile-art {
  width: 62%;
  height: 62%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-art svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.22));
}

.tile-label {
  font-size: 0.62rem;
  font-weight: 900;
  text-align: center;
  line-height: 1.05;
  margin-top: 2px;
  max-width: 95%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-classic-num {
  font-size: 1.65rem;
  font-weight: 900;
  letter-spacing: -0.5px;
}

.tile-classic-num.sm {
  font-size: 1.28rem;
}

/* Tier Color Palettes (2 to 4096) */
.tier-2    { background: linear-gradient(145deg, #fff5e4 0%, #fde2b8 100%); color: #5c3a1e; }
.tier-4    { background: linear-gradient(145deg, #ffd6e7 0%, #ffadd2 100%); color: #69143d; }
.tier-8    { background: linear-gradient(145deg, #fef08a 0%, #facc15 100%); color: #573b04; }
.tier-16   { background: linear-gradient(145deg, #fed7aa 0%, #fb923c 100%); color: #4a1d05; }
.tier-32   { background: linear-gradient(145deg, #fda4af 0%, #f43f5e 100%); color: #ffffff; }
.tier-64   { background: linear-gradient(145deg, #6ee7b7 0%, #10b981 100%); color: #053321; }
.tier-128  { background: linear-gradient(145deg, #e11d48 0%, #9f1239 100%); color: #fff1f2; }
.tier-256  { background: linear-gradient(145deg, #fcd34d 0%, #d97706 100%); color: #2e1502; }
.tier-512  { background: linear-gradient(145deg, #93c5fd 0%, #2563eb 100%); color: #ffffff; }
.tier-1024 { background: linear-gradient(145deg, #d8b4fe 0%, #9333ea 100%); color: #ffffff; }
.tier-2048 {
  background: linear-gradient(135deg, #f43f5e 0%, #f59e0b 25%, #10b981 50%, #3b82f6 75%, #a855f7 100%);
  color: #ffffff;
  box-shadow: 0 0 18px rgba(250, 204, 21, 0.75), inset 0 2px 3px rgba(255, 255, 255, 0.65);
}
.tier-4096 {
  background: linear-gradient(135deg, #0f172a 0%, #4c1d95 50%, #be185d 100%);
  color: #fde047;
  border: 2px solid #fde047;
}

/* AI Hint Toast */
.hint-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(17, 11, 25, 0.92);
  color: #fde047;
  border: 2px solid #fde047;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 1rem;
  font-weight: 900;
  pointer-events: none;
  opacity: 0;
  transition: all 0.2s ease;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65);
  z-index: 30;
  white-space: nowrap;
}

.hint-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Booster Bar */
.booster-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.booster-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-card);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.booster-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--accent-gold);
}

.booster-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.booster-count {
  background: rgba(251, 191, 36, 0.2);
  color: var(--accent-gold);
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 0.72rem;
  font-weight: 900;
}

/* Below-the-fold SEO Section */
.seo-section {
  max-width: 720px;
  margin: 28px auto 48px;
  padding: 0 16px;
}

.seo-inner {
  background: var(--bg-card);
  border: 1.5px solid var(--border-card);
  border-radius: 20px;
  padding: 28px 22px;
}

.seo-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(244, 114, 182, 0.18);
  color: var(--accent-pink);
  margin-bottom: 10px;
}

.seo-h2 {
  font-size: 1.4rem;
  font-weight: 900;
  margin-bottom: 10px;
}

.seo-h3 {
  font-size: 1.1rem;
  font-weight: 800;
  margin: 22px 0 10px;
  color: var(--accent-gold);
}

.seo-intro {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.cupcake-table-wrap {
  overflow-x: auto;
  margin-top: 8px;
}

.cupcake-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.cupcake-table th, .cupcake-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-align: left;
}

.cupcake-table th {
  color: var(--accent-gold);
  font-weight: 800;
}

.seo-list {
  padding-left: 18px;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-muted);
}

.seo-list li {
  margin-bottom: 8px;
}

.seo-footer {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 16, 0.78);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 110;
  padding: 16px;
}

.modal-backdrop.show {
  display: flex;
}

.modal-card {
  background: var(--bg-card);
  border: 2px solid var(--border-card);
  border-radius: 22px;
  padding: 24px 20px;
  width: 100%;
  max-width: 350px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-emoji {
  font-size: 3rem;
  margin-bottom: 8px;
}

.modal-title {
  font-size: 1.35rem;
  font-weight: 900;
  margin-bottom: 6px;
}

.modal-sub {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.modal-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.m-stat {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.m-stat span {
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--text-muted);
}

.m-stat strong {
  font-size: 1.25rem;
  color: var(--accent-gold);
}

.modal-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-primary, .btn-secondary {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
  color: #fff;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  border: 1.5px solid var(--border-card);
}
