Cloud Favorites (and only that) coming right up.
This adds Firestore-backed favorites with anonymous auth and keeps your localStorage fallback when signed out or offline. Minimal code changes to the Icons page. 💜

0) Install Firebase
npm i firebase

1) Add env vars (Vite)

Create .env (or .env.local) with your Firebase web app keys:

VITE_FIREBASE_API_KEY=YOUR_KEY
VITE_FIREBASE_AUTH_DOMAIN=YOUR_PROJECT.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=YOUR_PROJECT_ID
VITE_FIREBASE_APP_ID=YOUR_APP_ID
# optional but nice to have:
VITE_FIREBASE_STORAGE_BUCKET=YOUR_PROJECT.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=YOUR_SENDER_ID


If these are missing, the system silently falls back to localStorage favorites (exactly like today).

2) Create src/lib/firebase.ts
import { initializeApp, getApps } from "firebase/app";
import {
  getAuth,
  signInAnonymously,
  onAuthStateChanged,
  User,
} from "firebase/auth";
import {
  getFirestore,
  doc,
  onSnapshot,
  setDoc,
  updateDoc,
  arrayUnion,
  arrayRemove,
} from "firebase/firestore";

const cfg = {
  apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
  authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
  projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
  appId: import.meta.env.VITE_FIREBASE_APP_ID,
  storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
};

export function isFirebaseConfigured() {
  return !!(cfg.apiKey && cfg.authDomain && cfg.projectId && cfg.appId);
}

let _authReady: Promise<User | null> | null = null;

export function ensureFirebase() {
  if (!isFirebaseConfigured()) return null;
  const app = getApps().length ? getApps()[0] : initializeApp(cfg);
  const auth = getAuth(app);
  const db = getFirestore(app);

  if (!_authReady) {
    _authReady = new Promise<User | null>((resolve) => {
      onAuthStateChanged(auth, async (u) => {
        if (u) return resolve(u);
        try {
          const cred = await signInAnonymously(auth);
          resolve(cred.user);
        } catch {
          resolve(null);
        }
      });
    });
  }

  return { app, auth, db, authReady: _authReady };
}

// helpers re-exported for convenience
export { getAuth, getFirestore, doc, onSnapshot, setDoc, updateDoc, arrayUnion, arrayRemove };
