@font-face {
  font-family: 'Poppins';
  src: url('../assets/fonts/poppins-latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Poppins';
  src: url('../assets/fonts/poppins-latin-800-normal.woff2') format('woff2');
  font-weight: 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Poppins';
  src: url('../assets/fonts/poppins-latin-600-normal.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter-latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter-latin-600-normal.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter-latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --bg-deep: #0a0a1f;
  --bg-mid: #14103a;
  --purple: #7c3aed;
  --cyan: #22d3ee;
  --pink: #f472b6;
  --gold: #fbbf24;
  --text-light: #eef1ff;
  --text-dim: #9aa1c9;
  --panel: rgba(20, 18, 50, 0.55);
  --panel-border: rgba(148, 130, 255, 0.28);
  --danger: #f87171;
  --success: #34d399;
  --font-display: 'Poppins', 'Nunito Sans', sans-serif;
  --font-body: 'Inter', 'Nunito Sans', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html.high-contrast {
  --text-dim: #cfd3ff;
  --panel-border: rgba(200, 190, 255, 0.55);
}

body {
  font-family: var(--font-body);
  color: var(--text-light);
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(124, 58, 237, 0.35), transparent 60%),
    radial-gradient(ellipse 70% 50% at 90% 100%, rgba(34, 211, 238, 0.18), transparent 60%),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg-mid) 100%);
}

.app { position: fixed; inset: 0; width: 100%; height: 100%; overflow: hidden; }

#gameCanvas, #fxCanvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none;
}
#fxCanvas { pointer-events: none; }

/* ---------- HUD ---------- */
.hud {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 14px calc(12px + var(--safe-bottom));
  z-index: 20;
}
.hud-top { position: relative; display: flex; align-items: flex-start; justify-content: space-between; }
.hud-stat { display: flex; flex-direction: column; line-height: 1; pointer-events: auto; }
.hud-stat-right { align-items: flex-end; }
.hud-label { font-size: 11px; letter-spacing: 0.12em; color: var(--text-dim); font-weight: 600; margin-bottom: 4px; }
.hud-value {
  font-family: var(--font-display); font-weight: 800; font-size: 26px;
  text-shadow: 0 0 18px rgba(124, 58, 237, 0.6);
  font-variant-numeric: tabular-nums;
}
.top-controls {
  position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  display: flex; gap: 8px; pointer-events: auto;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  background: rgba(6, 4, 16, 0.62);
  border: 1px solid var(--panel-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-light);
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  font-size: 18px;
}
/* Icons carry their own fill/stroke per-path (some need a solid fill, e.g.
   the speaker/pause shapes, others are stroke-only outlines) — only size
   and color are set globally here, never a blanket fill/stroke override. */
.icon-btn svg { width: 18px; height: 18px; color: inherit; }
.icon-btn.active { background: rgba(124, 58, 237, 0.45); border-color: var(--purple); }
.icon-btn.muted { opacity: 0.45; }

.hud-timer {
  position: absolute; left: 50%; top: 48px; transform: translateX(-50%);
  font-family: var(--font-display); font-weight: 800; font-size: 14px;
  color: var(--gold);
  background: rgba(6, 4, 16, 0.62); border: 1px solid var(--panel-border);
  border-radius: 999px; padding: 3px 12px; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.hud-timer.warning { color: var(--danger); animation: pulseScale 0.6s ease infinite; }
@media (prefers-reduced-motion: reduce) { .hud-timer.warning { animation: none; } }

.combo-banner {
  position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%);
  text-align: center; pointer-events: none;
}
.combo-banner.pop { animation: comboPop 0.4s cubic-bezier(.2,1.4,.4,1); }
@keyframes comboPop {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  60% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .combo-banner.pop { animation: none; }
}
.combo-text {
  font-family: var(--font-display); font-weight: 800; font-size: 40px;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(251, 191, 36, 0.85), 0 0 6px #fff;
  letter-spacing: 0.02em;
}
.combo-score {
  font-family: var(--font-display); font-weight: 700; font-size: 22px;
  color: var(--text-light); margin-top: 2px;
  text-shadow: 0 0 14px rgba(124, 58, 237, 0.8);
}

.toast-layer {
  position: absolute; left: 50%; top: 14%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none; z-index: 25;
}
.toast {
  background: rgba(10, 8, 28, 0.85); border: 1px solid var(--panel-border);
  border-radius: 999px; padding: 8px 18px; font-size: 13px; font-weight: 600;
  color: var(--text-light); box-shadow: 0 4px 18px rgba(0,0,0,0.4);
  animation: toastIn 0.35s ease, toastOut 0.4s ease 2.1s forwards;
  white-space: nowrap;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

.hud-bottom { display: flex; align-items: flex-end; justify-content: space-between; pointer-events: auto; }
.next-queue { display: flex; align-items: flex-end; gap: 10px; }
.next-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.next-label { font-size: 10px; letter-spacing: 0.1em; color: var(--text-dim); font-weight: 700; }
.tile-preview {
  width: 58px; height: 58px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--panel-border);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
.tile-preview-mini { width: 40px; height: 40px; opacity: 0.75; }
.undo-btn {
  width: 52px; height: 52px; border-radius: 16px;
  background: rgba(6, 4, 16, 0.62); border: 1px solid var(--panel-border);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-light);
}
.undo-btn:disabled { opacity: 0.35; }
.undo-icon { font-size: 18px; line-height: 1; }
#undoCount { font-size: 11px; font-weight: 700; margin-top: 1px; }

.offline-banner {
  position: absolute; bottom: calc(8px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(248, 113, 113, 0.18); border: 1px solid var(--danger);
  color: #fecaca; font-size: 12px; padding: 6px 14px; border-radius: 999px; z-index: 40;
}

/* ---------- Loading ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; z-index: 30;
}
.loading-screen { background: var(--bg-deep); gap: 22px; }
.logo-mark { display: flex; flex-direction: column; align-items: center; line-height: 0.92; }
.logo-hexa, .logo-merge {
  font-family: var(--font-display); font-weight: 800; letter-spacing: 0.04em;
}
.logo-hexa { font-size: 40px; color: var(--text-light); text-shadow: 0 0 22px rgba(124,58,237,0.7); }
.logo-merge {
  font-size: 40px;
  background: linear-gradient(90deg, var(--cyan), var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(34, 211, 238, 0.55));
}
.logo-mark-lg .logo-hexa, .logo-mark-lg .logo-merge { font-size: 54px; }
.loading-bar { width: 180px; height: 6px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden; }
.loading-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--purple), var(--cyan)); transition: width 0.2s ease; }

/* ---------- Start screen ---------- */
.start-screen {
  gap: 12px; padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  overflow-y: auto;
  /* When content is taller than the viewport, grow downward (scroll to see
     more below) rather than centering — centered overflow clips equally off
     the TOP too, hiding the logo above the fold on shorter phones. */
  justify-content: flex-start;
}
.bg-particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: -1; }
.tagline { color: var(--text-dim); font-size: 14px; margin-bottom: 6px; }

.menu-stats { display: flex; align-items: center; gap: 12px; margin: 4px 0; }
.menu-stat { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.menu-stat-label { font-size: 10px; letter-spacing: 0.1em; color: var(--text-dim); margin-bottom: 4px; }
.menu-stat-value { font-family: var(--font-display); font-weight: 800; font-size: 22px; color: var(--gold); }
.nickname-badge {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 999px;
  padding: 8px 16px; font-size: 12px; font-weight: 700; color: var(--text-light); letter-spacing: 0.03em;
}
.streak-badge {
  background: rgba(251, 191, 36, 0.14); border: 1px solid rgba(251, 191, 36, 0.4);
  color: var(--gold); border-radius: 999px; padding: 5px 14px; font-size: 12px; font-weight: 700;
}

.seo-copy { max-width: 480px; margin-top: 14px; color: var(--text-dim); font-size: 12px; line-height: 1.5; text-align: left; }
.seo-copy h1 { font-family: var(--font-display); font-size: 15px; color: var(--text-light); margin-bottom: 8px; }
.seo-copy h2 { font-size: 12px; color: var(--text-light); margin: 10px 0 4px; }

@media (max-height: 700px) {
  .logo-mark-lg .logo-hexa, .logo-mark-lg .logo-merge { font-size: 40px; }
  .seo-copy { display: none; }
}
