/* ═══════════════════════════════════════════════════════════════════════════
   Secret Agency — Accueil personnalisable (ss-home-edit.css)
   Mode édition façon springboard iOS : logo redimensionnable/déplaçable, cartes
   réordonnables / redimensionnables / supprimables, ajout de modules du menu.
   Chargé uniquement par index.html. Piloté par lib/ss-home-edit.js.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Blocage du menu natif (callout Safari/Android) sur les éléments saisissables ──
   En repos comme en édition : un appui long ne doit jamais ouvrir « Ouvrir dans un
   nouvel onglet » / « Enregistrer l'image ». Le scroll reste normal (touch-action
   n'est passé à none QUE pendant une prise active, classe .he-grab). */
#home, #home *,
#home .hx-card, #home .hx-card *,
#home .hx-logo, #home .hx-logo * {
  -webkit-touch-callout: none !important;   /* tue le callout iOS (lien/image/texte) sur TOUTE la carte */
  -webkit-user-select: none; user-select: none;
}
#home .hx-logo-img,
#home .hx-card img { -webkit-user-drag: none; }
/* Exception : les champs de saisie (code de session) restent sélectionnables/éditables */
#home input, #home textarea {
  -webkit-touch-callout: default !important;
  -webkit-user-select: text; user-select: text;
}

/* ── Mode édition : frémissement iOS ──────────────────────────────────────── */
#home.home-editing .hx-card,
#home.home-editing .hx-logo {
  animation: he-wiggle 0.32s ease-in-out infinite alternate;
}
#home.home-editing .hx-card:nth-child(2n) { animation-delay: 0.11s; }
#home.home-editing .hx-card:nth-child(3n) { animation-delay: 0.06s; }
#home.home-editing .hx-logo { animation-duration: 0.5s; }
@keyframes he-wiggle { from { transform: rotate(-0.9deg); } to { transform: rotate(0.9deg); } }

/* En édition les liens sont inertes (la nav est gérée en JS : capture + preventDefault) */
#home.home-editing .hx-card { cursor: grab; }
#home.home-editing .hx-card:active { transform: none; }

/* Blocage du scroll tactile natif — DOIT être une règle CSS statique (pas posée
   dynamiquement en JS au moment du drag) : le navigateur fige le comportement
   tactile (scroll ou non) dès le premier contact du doigt (touchstart). Si on
   n'active touch-action:none qu'après coup (au franchissement du seuil de
   drag), c'est trop tard — le scroll de page a déjà démarré. En la posant ici,
   dès l'entrée en édition, le tout premier toucher d'une tuile ne déclenche
   jamais de scroll natif ; le défilement programmatique (auto-scroll bords
   haut/bas pendant le drag) continue de fonctionner car il ne passe pas par
   un geste tactile. */
#home.home-editing #nav-grid,
#home.home-editing #nav-grid .hx-card,
#home.home-editing .he-add { touch-action: none; }

/* Élément en cours de saisie : au-dessus, ombre, pas de frémissement */
#home .he-grab {
  animation: none !important;
  z-index: 40; position: relative;
  box-shadow: 0 14px 34px rgba(0,0,0,0.5);
  opacity: 0.92; touch-action: none;
}
#home .hx-card.he-placeholder { opacity: 0.35; }

/* ── Boutons d'action sur chaque carte (visibles en édition) ───────────────── */
.he-del, .he-size {
  position: absolute; z-index: 5;
  width: 26px; height: 26px; border-radius: 50%;
  display: none; place-items: center;
  border: 0; cursor: pointer; padding: 0;
  font-size: 0.8rem; line-height: 1;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
#home.home-editing .hx-card .he-del,
#home.home-editing .hx-card .he-size { display: grid; }
.he-del  { top: -8px; left: -8px; background: #e0344a; color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
.he-size { bottom: -8px; right: -8px; background: rgba(20,26,48,0.92); color: var(--cyan); border: 1px solid rgba(255,255,255,0.18); font-size: 0.62rem; font-weight: 800; }

/* ── Tailles de carte ─────────────────────────────────────────────────────── */
/* ── Tuiles carrées + compactes (accueil) ─────────────────────────────────────
   La colonne fait ~230px : on borne la carte (max-width) et on la centre dans
   sa cellule → tuile carrée plus petite, façon icône d'app iOS. Contenu (icône
   + titre + desc) centré au milieu de la tuile. */
/* Grille springboard : 4 colonnes. Taille M (par défaut) = bloc 2×2. */
#nav-grid { grid-template-columns: repeat(4, 1fr) !important; grid-auto-rows: 1fr; justify-items: center; gap: 10px 6px; }
#nav-grid .hx-card {
  grid-column: span 2; grid-row: span 2;
  aspect-ratio: 1 / 1; min-height: 0;
  width: 100%; max-width: none;
  padding: 10px;
  align-items: center; justify-content: center; text-align: center; gap: 6px;
  overflow: hidden;
}
#nav-grid .hx-card .hx-card-ico {
  margin: 0; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;   /* centre l'emoji/SVG dans son bloc */
}
#nav-grid .hx-card .hx-card-ico-emoji { display: block; text-align: center; }
#nav-grid .hx-card .hx-card-title { margin: 0; font-size: 0.8rem; line-height: 1.15; letter-spacing: 0; }
#nav-grid .hx-card .hx-card-desc { display: none; }   /* trop étroit pour la description en 4 colonnes */

/* Grande (L) : pleine largeur (toute la rangée) — icône + titre + desc lisibles */
#nav-grid .hx-card.he-l {
  grid-column: 1 / -1; grid-row: span 1; aspect-ratio: auto; max-width: none; min-height: 84px;
  flex-direction: row; gap: 12px; text-align: left; justify-content: flex-start; padding: 14px 16px;
}
#nav-grid .hx-card.he-l .hx-card-ico { width: 30px; height: 30px; }
#nav-grid .hx-card.he-l .hx-card-title { font-size: 0.95rem; }
#nav-grid .hx-card.he-l .hx-card-desc { display: block; font-size: 0.68rem; line-height: 1.3; }

/* Emoji seul (E) : tuile 1×1, icône/emoji centrée, aucun texte */
#nav-grid .hx-card.he-e { grid-column: span 1; grid-row: span 1; max-width: 100px; padding: 8px; }
.hx-card.he-e .hx-card-title,
.hx-card.he-e .hx-card-desc,
.hx-card.he-e .hx-card-badge,
.hx-card.he-e .hx-card-dot { display: none !important; }
#nav-grid .hx-card.he-e .hx-card-ico { margin: 0; width: 44px; height: 44px; }
#nav-grid .hx-card.he-e .hx-card-ico-emoji { font-size: 2.4rem; }

/* Carte masquée (retirée par ✕) → réellement hors flux */
.hx-card.he-hidden { display: none !important; }

/* ── Tuile « + » d'ajout de module (édition seulement) ────────────────────── */
.he-add {
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: 100%; max-width: 120px; aspect-ratio: 1 / 1; min-height: 0;
  border-radius: 18px; cursor: pointer;
  border: 1.5px dashed rgba(255,255,255,0.25); background: rgba(255,255,255,0.03);
  color: var(--text-mid-strong); font-size: 0.72rem; font-weight: 700;
}
#home.home-editing #nav-grid .he-add { display: flex; }
.he-add .he-add-plus { font-size: 1.6rem; line-height: 1; }
#home.home-editing .he-add { display: flex; }

/* Icône emoji des cartes-modules ajoutées */
.hx-card .hx-card-ico-emoji { font-size: 1.7rem; line-height: 1; display: block; }

/* ── Barre « Terminé » flottante ──────────────────────────────────────────── */
.he-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h, 64px) + var(--safe-b, 0px) + 12px);
  z-index: 60; display: none;
  padding: 10px 26px; border-radius: 999px; cursor: pointer;
  background: linear-gradient(135deg, var(--cyan), var(--azure)); color: #04121f;
  font-weight: 800; font-size: 0.8rem; letter-spacing: 0.04em;
  border: 0; box-shadow: 0 8px 26px rgba(0,0,0,0.5);
}
#home.home-editing ~ .he-bar, body.home-is-editing .he-bar { display: block; }

/* ── Feuille de sélection de modules (picker) ─────────────────────────────── */
.he-picker {
  position: fixed; inset: 0; z-index: 70; display: none;
  background: rgba(4,6,20,0.55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.he-picker.is-open { display: block; }
.he-picker-sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 78vh; overflow-y: auto;
  background: var(--night-mid, #1b0a44);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  padding: 14px 16px calc(var(--safe-b, 0px) + 20px);
  box-shadow: 0 -12px 40px rgba(0,0,0,0.6);
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.2,0.9,0.3,1);
}
.he-picker.is-open .he-picker-sheet { transform: translateY(0); }
.he-picker-title { font-family: var(--font-display, sans-serif); font-weight: 800; font-size: 1.2rem; color: #fff; margin-bottom: 2px; text-align: center; }
.he-picker-sub { font-size: 0.7rem; color: var(--text-mid-strong); text-align: center; margin-bottom: 12px; }
.he-picker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 8px; }
.he-picker-item {
  background: none; border: 0; cursor: pointer; padding: 6px 2px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  -webkit-tap-highlight-color: transparent;
}
.he-picker-item:active { background: rgba(255,255,255,0.06); }
.he-picker-item .he-pi-ico {
  width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center;
  font-size: 1.7rem; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.08);
}
.he-picker-item .he-pi-lbl { font-size: 0.62rem; color: var(--text-mid-strong); text-align: center; line-height: 1.15; }
.he-picker-empty { text-align: center; color: var(--text-mid); font-size: 0.78rem; padding: 20px 0; }
.he-picker-close {
  display: block; margin: 14px auto 0; padding: 9px 24px; border-radius: 999px;
  background: rgba(255,255,255,0.08); color: #fff; border: 0; font-size: 0.78rem; font-weight: 700; cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  #home.home-editing .hx-card,
  #home.home-editing .hx-logo { animation: none; }
  .he-picker-sheet { transition: none; }
}
