/* ═══════════════════════════════════════════════════
   QuestSync 2048 — style.css
   ═══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Sans:wght@400;500;700&display=swap');

/* ── TOKENS ── */
:root {
  --bg:            #07080d;
  --surface:       #0f1117;
  --panel:         #161b26;
  --border:        rgba(255, 255, 255, 0.08);
  --accent:        #ff4500;
  --accent2:       #ff7a40;
  --gold:          #ffd700;
  --silver:        #c0c0c0;
  --bronze:        #cd7f32;
  --text:          #f0f2f5;
  --muted:         #6b7280;
  --danger:        #ef4444;
  --win:           #f0c040;
  --radius:        14px;
  --glow:          0 0 22px rgba(255, 69, 0, 0.35);
  --font-display:  'Bebas Neue', sans-serif;
  --font-body:     'DM Sans', sans-serif;
}

/* ── RESET ── */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

/* ── GRID BG TEXTURE ── */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(255,69,0,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,69,0,0.025) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
}

/* ── APP SHELL ── */
#app {
  position: relative;
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}

/* ═══════════════════════════════════════════════════
   SCREENS
   ═══════════════════════════════════════════════════ */
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px; z-index: 10;
}
.screen.active {
  display: flex;
  animation: screenIn 0.38s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes screenIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════
   BRANDING
   ═══════════════════════════════════════════════════ */
.brand {
  text-align: center;
  margin-bottom: 36px;
}
.brand-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 2.5px;
  text-transform: uppercase;
  background: rgba(255,69,0,0.15);
  color: var(--accent);
  border: 1px solid rgba(255,69,0,0.35);
  margin-bottom: 18px;
}
.brand-title {
  font-family: var(--font-display);
  font-size: clamp(3.4rem, 11vw, 5.2rem);
  letter-spacing: 5px; line-height: 1; margin: 0;
  color: var(--accent);
  animation: titlePulse 3.5s ease-in-out infinite alternate;
}
@keyframes titlePulse {
  from { text-shadow: 0 0 22px rgba(255,69,0,0.45); }
  to   { text-shadow: 0 0 38px rgba(255,69,0,0.75), 0 0 70px rgba(255,100,30,0.28); }
}
.brand-sub {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 4vw, 1.7rem);
  letter-spacing: 16px; margin-top: 4px; opacity: 0.85;
}
.brand-tagline {
  font-size: 0.72rem; letter-spacing: 3px;
  color: var(--muted); text-transform: uppercase; margin-top: 10px;
}

/* ═══════════════════════════════════════════════════
   CARD
   ═══════════════════════════════════════════════════ */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%; max-width: 340px;
  box-shadow: 0 22px 64px rgba(0,0,0,0.55),
              inset 0 1px 0 rgba(255,255,255,0.05);
}

/* ═══════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════ */
.btn {
  display: block; width: 100%;
  padding: 15px 20px;
  border: none; border-radius: 9px;
  font-family: var(--font-body);
  font-size: 0.88rem; font-weight: 700;
  letter-spacing: 1.6px; text-transform: uppercase;
  cursor: pointer; margin: 7px 0;
  transition: transform 0.14s, box-shadow 0.14s, background 0.2s;
  position: relative; overflow: hidden;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 4px 22px rgba(255,69,0,0.38);
}
.btn-primary:hover { box-shadow: 0 6px 30px rgba(255,69,0,0.58); }
.btn-primary::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(rgba(255,255,255,0.11), transparent);
  pointer-events: none;
}

.btn-ghost {
  background: transparent;
  border: 1.5px solid rgba(255,69,0,0.45);
  color: var(--accent);
}
.btn-ghost:hover {
  border-color: var(--accent);
  background: rgba(255,69,0,0.07);
}

.btn-danger {
  background: transparent;
  border: 1.5px solid rgba(140,140,155,0.28);
  color: var(--muted);
}
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

.btn-win {
  background: linear-gradient(135deg, #c8860a, #f0c040, #c8860a);
  color: #1a1000; font-weight: 900;
  box-shadow: 0 4px 24px rgba(240,192,64,0.45);
}
.btn-win:hover { box-shadow: 0 6px 32px rgba(240,192,64,0.65); }

/* ═══════════════════════════════════════════════════
   SECTION TITLE
   ═══════════════════════════════════════════════════ */
.section-title {
  font-family: var(--font-display);
  font-size: 1.9rem; letter-spacing: 4px;
  color: var(--text); text-transform: uppercase;
  margin: 0 0 24px 0; text-align: center;
}

/* ═══════════════════════════════════════════════════
   DIVIDER
   ═══════════════════════════════════════════════════ */
.divider {
  width: 100%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 8px 0;
}

/* ═══════════════════════════════════════════════════
   MODE SELECT
   ═══════════════════════════════════════════════════ */
.mode-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 10px;
}
.mode-btn {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 18px 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px; background: var(--surface);
  cursor: pointer; transition: all 0.2s; gap: 4px;
}
.mode-btn:hover, .mode-btn:active {
  border-color: var(--accent);
  background: rgba(255,69,0,0.08);
  transform: translateY(-3px);
  box-shadow: 0 8px 22px rgba(255,69,0,0.22);
}
.mode-icon { font-size: 1.7rem; }
.mode-label {
  font-family: var(--font-display);
  font-size: 1.15rem; letter-spacing: 2px; color: var(--text);
}
.mode-desc { font-size: 0.68rem; color: var(--muted); letter-spacing: 0.5px; }

/* ═══════════════════════════════════════════════════
   GAME SCREEN
   ═══════════════════════════════════════════════════ */
#game-screen {
  padding: 16px;
  justify-content: flex-start;
  padding-top: 16px;
}

/* HUD row */
.hud {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; max-width: 520px; margin-bottom: 14px;
  gap: 8px;
}
.hud-left  { display: flex; gap: 8px; align-items: center; }
.hud-center { display: flex; gap: 8px; align-items: center; }
.hud-right { display: flex; gap: 8px; align-items: center; }

/* Icon buttons (home, restart, mute — inside HUD on game screen) */
.icon-btn {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1.1rem;
  transition: all 0.18s; flex-shrink: 0;
}
.icon-btn:hover  { border-color: var(--accent); background: rgba(255,69,0,0.1); }
.icon-btn:active { transform: scale(0.91); }

/* Score boxes */
.score-box {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 14px;
  text-align: center; min-width: 76px;
}
.score-label {
  font-size: 0.58rem; letter-spacing: 2px;
  color: var(--muted); text-transform: uppercase; font-weight: 700;
}
.score-val { font-weight: 700; font-size: 1rem; }

/* ═══════════════════════════════════════════════════
   GRID & TILES
   ═══════════════════════════════════════════════════ */
#grid-container {
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px; display: grid; gap: 8px;
  box-shadow: var(--glow), inset 0 0 0 1px rgba(255,255,255,0.03);
  width: 100%; max-width: 520px;
  aspect-ratio: 1 / 1;
}
.tile {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #fff;
  position: relative; overflow: hidden;
  transition: background 0.1s;
}
.tile::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.08) 0%, transparent 55%);
  pointer-events: none;
}
.tile-pop {
  animation: tilePop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes tilePop {
  0%  { transform: scale(0.35); opacity: 0; }
  80% { transform: scale(1.08); }
  100%{ transform: scale(1);    opacity: 1; }
}
.tile-merge {
  animation: tileMerge 0.24s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes tileMerge {
  0%  { transform: scale(1); }
  50% { transform: scale(1.2); }
  100%{ transform: scale(1); }
}

/* ═══════════════════════════════════════════════════
   OVERLAYS  (tutorial, game-over, win, exit)
   ═══════════════════════════════════════════════════ */
.overlay {
  position: fixed; inset: 0; z-index: 180;
  background: rgba(7, 8, 13, 0.93);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 28px; text-align: center;
}
.overlay.active {
  display: flex;
  animation: screenIn 0.3s ease;
}

/* Overlay typography */
.overlay-icon  { font-size: 2.8rem; margin-bottom: 14px; }
.overlay-title {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  letter-spacing: 5px; margin: 0 0 6px 0;
  color: var(--accent);
}
.overlay-title.win-color { color: var(--win); }
.overlay-sub   { color: var(--muted); font-size: 0.85rem; letter-spacing: 1px; margin-bottom: 26px; }

/* Win overlay particle burst */
@keyframes starBurst {
  0%  { transform: scale(0) rotate(0deg);   opacity: 1; }
  80% { transform: scale(1.3) rotate(180deg); opacity: 0.8; }
  100%{ transform: scale(2) rotate(360deg); opacity: 0; }
}
.win-star {
  position: absolute;
  font-size: 1.4rem;
  animation: starBurst 1.2s ease-out forwards;
  pointer-events: none;
}

/* ── TUTORIAL DOTS ── */
.dots {
  display: flex; gap: 8px; margin-bottom: 24px; justify-content: center;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border); transition: all 0.3s;
}
.dot.active {
  background: var(--accent); width: 26px; border-radius: 4px;
  box-shadow: 0 0 10px var(--accent);
}

.tut-icon  { font-size: 2.6rem; margin-bottom: 14px; }
.tut-title {
  font-family: var(--font-display);
  font-size: 1.9rem; letter-spacing: 3px; color: var(--accent);
  margin: 0 0 10px 0;
}
.tut-text  {
  color: var(--muted); line-height: 1.75; font-size: 0.94rem;
  max-width: 300px; margin: 0 auto 28px;
}

/* ═══════════════════════════════════════════════════
   LEADERBOARD
   ═══════════════════════════════════════════════════ */
#leaderboard-screen {
  justify-content: flex-start;
  padding-top: 44px;
}
.lb-wrap {
  width: 100%; max-width: 400px;
  flex: 1; overflow-y: auto; margin-bottom: 14px;
}
.lb-wrap::-webkit-scrollbar { width: 4px; }
.lb-wrap::-webkit-scrollbar-track { background: transparent; }
.lb-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.lb-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 16px; margin-bottom: 6px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 9px;
}
.lb-row.me {
  border-color: var(--accent);
  background: rgba(255,69,0,0.09);
  box-shadow: 0 0 18px rgba(255,69,0,0.16);
}
.lb-rank {
  font-family: var(--font-display); font-size: 1.1rem;
  letter-spacing: 1px; color: var(--accent); min-width: 34px;
}
.lb-rank.gold   { color: var(--gold);   }
.lb-rank.silver { color: var(--silver); }
.lb-rank.bronze { color: var(--bronze); }
.lb-name  { flex: 1; margin-left: 10px; font-weight: 500; }
.lb-you   { font-size: 0.62rem; color: var(--accent); letter-spacing: 1px; }
.lb-score { font-weight: 700; font-family: var(--font-display); font-size: 1rem; letter-spacing: 1px; }
