:root {
  --bg: #0f0f13;
  --panel: #17171d;
  --text: #f5f6fa;
  --subtle: #a7adbb;
  --accent: #7c5cff;
  --tile-text: #f6f8fa; /* lighter text for darker, sleek tiles */
  --gap: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1000px 600px at 70% -10%, #1a1b26 0%, var(--bg) 60%);
  color: var(--text);
  overflow: hidden; /* prevent scrollbars on phones */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px clamp(8px, 3vw, 14px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: relative; /* anchor popover */
}

.toolbar { display: flex; justify-content: center; align-items: center; gap: 8px; }

.brand {
  font-weight: 800;
  letter-spacing: 0.2px;
}

.top-left { display: flex; gap: 10px; align-items: center; flex-wrap: nowrap; }
.top-right { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }
.stats { display: flex; gap: 12px; align-items: center; }
.stat { display: flex; gap: 8px; align-items: baseline; }
.label { color: var(--subtle); font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
.stat span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }

.scores { display: flex; align-items: center; justify-content: center; }
.scores .stats { gap: 16px; }
.scores .label { font-size: 10px; letter-spacing: 0.5px; }
.scores .stat { gap: 6px; }
.scores .stat span:last-child { font-size: 12px; }

/* Make score/best appear as subtle symmetric pills */
.scores .stat {
  background: #16161d;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 2px 8px;
}

main {
  flex: 1;
  min-height: 0; /* allow child to size without forcing overflow */
  display: grid;
  grid-template-rows: 1fr; /* only board area */
  align-items: center;
  justify-items: center;
  padding: 8px 12px 12px;
}

.legal-links {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  padding: 6px 10px 10px;
  font-size: 11px;
  color: var(--subtle);
  opacity: 0.85;
}
.legal-links a { color: var(--subtle); text-decoration: none; }
.legal-links a:hover { text-decoration: underline; }

/* Tutorial modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.78); display: grid; place-items: center; z-index: 1200; }
.modal-overlay[hidden] { display: none; }
.tutorial-modal { position: relative; background: #14141a; border: 1px solid rgba(255,255,255,0.12); border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,0.5); width: min(92vw, 720px); padding: 10px; }
.tutorial-modal .video-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; }
/* Vertical variant for portrait-first experience */
.tutorial-modal.vertical { width: min(88vw, 360px); padding: 8px; }
.tutorial-modal.vertical .video-wrap { aspect-ratio: 9 / 16; }
.tutorial-modal .video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.tutorial-close {
  position: absolute; top: 8px; right: 8px;
  width: 36px; height: 36px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.35);
  background: linear-gradient(180deg, rgba(0,0,0,0.65), rgba(0,0,0,0.35));
  color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 20px; line-height: 1;
  box-shadow: 0 6px 16px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.2);
  cursor: pointer;
}
.tutorial-close:hover { filter: brightness(1.1); }

#board-container {
  width: min(94vw, 520px);
  aspect-ratio: 5 / 7; /* 5 columns x 7 rows */
  background: linear-gradient(180deg, #16161b, #121216);
  border-radius: 16px;
  padding: var(--gap);
  box-shadow: 0 10px 40px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
  max-height: 100%;
}

#board {
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: var(--gap);
}

.cell {
  border-radius: 12px;
  background: #1c1d25;
  position: relative;
  overflow: hidden;
}

/* Absolute-positioned tile layer on top of grid cells */
#tiles {
  position: absolute;
  inset: var(--gap);
  /* Mirrors grid area minus padding */
  pointer-events: auto;
  touch-action: manipulation;
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(16px, 6vw, 28px);
  color: var(--tile-text);
  user-select: none;
  /* Slower movement so it’s clearly visible */
  transition: transform 420ms cubic-bezier(.22,.61,.36,1), filter 180ms ease, opacity 260ms ease;
  transform: translate(var(--x, 0px), var(--y, 0px)) scale(1);
  box-shadow: none;
  text-shadow: none;
}

.tile.match {
  box-shadow: 0 0 0 3px rgba(255,255,255,0.9) !important;
  filter: brightness(1.06) contrast(1.05);
}

.tile.selected {
  outline: 3px solid rgba(255,255,255,0.55);
  transform: translate(var(--x, 0px), var(--y, 0px)) scale(1.04);
}

.tile.appearing { animation: pop 280ms ease-out; }
@keyframes pop {
  from { transform: translate(var(--x, 0px), calc(var(--y, 0px))) scale(0.8); opacity: 0; }
  to { transform: translate(var(--x, 0px), var(--y, 0px)) scale(1); opacity: 1; }
}

.tile.merged { animation: bump 260ms ease-out; }
@keyframes bump {
  0% { transform: translate(var(--x, 0px), var(--y, 0px)) scale(0.94); }
  70% { transform: translate(var(--x, 0px), var(--y, 0px)) scale(1.08); }
  100% { transform: translate(var(--x, 0px), var(--y, 0px)) scale(1); }
}

.tile.removing { animation: fadeaway 260ms ease forwards; }
@keyframes fadeaway {
  to { opacity: 0; transform: translate(var(--x, 0px), var(--y, 0px)) scale(0.75); }
}

/* Removed glossy overlay for flat look */

/* Particle burst */
.particle {
  position: absolute;
  left: 0; top: 0;
  width: 6px; height: 6px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 1;
  will-change: transform, opacity;
  transition: transform 600ms cubic-bezier(.17,.67,.2,1.03), opacity 650ms ease-out;
  z-index: 6;
}

/* Helper to disable transitions during resize/layout corrections */
.no-transition *, .no-transition {
  transition: none !important;
  animation: none !important;
}

.btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  box-shadow: 0 6px 14px rgba(124,92,255,0.28);
  height: 28px;
  display: inline-flex;
  align-items: center;
}
.btn.small { padding: 0 10px; font-size: 13px; height: 28px; }
.btn.xs { padding: 4px 6px; font-size: 12px; border-radius: 8px; }
.btn.icon { width: 28px; height: 28px; padding: 0; display: grid; place-items: center; }
.btn.icon svg { width: 18px; height: 18px; display: block; }
.btn:active { transform: translateY(1px); }

.btn.has-badge { display: inline-flex; align-items: center; gap: 6px; }
.badge {
  background: #262632;
  color: var(--text);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1.2;
  border: 1px solid rgba(255,255,255,0.06);
  min-width: 20px;
  text-align: center;
}

/* Popover for Support purchase */
.popover {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: calc(100% + 6px);
  background: #14141a;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04);
  z-index: 1000;
  display: grid;
  gap: 8px;
  min-width: 220px;
}
.popover .row { display: flex; gap: 8px; align-items: center; justify-content: center; }
.popover .msg { font-size: 12px; color: var(--subtle); font-style: italic; padding-top: 2px; }
.popover .chip-button {
  background: #222230;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
}
.popover .chip-button.selected { background: var(--accent); border-color: transparent; }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.14); box-shadow: none; color: var(--text); }

/* .controls removed; new game is in top bar */

/* hint removed */

/* Larger screens */
@media (min-width: 720px) {
  .topbar { padding-inline: 24px; }
}

/* no hint */
