/* ============================================================
 * mobile-friendly.css — Pass mobile global pour pages HTML statiques.
 * Inject\u00e9 via scripts/inject-gamification.mjs (v4) + GamificationHUD.tsx.
 *
 * Objectifs : moins encombr\u00e9, navigation plus respirable, cibles
 * tactiles >= 44px, scroll horizontal fluide, opacit\u00e9 contr\u00f4l\u00e9e,
 * meilleure lisibilit\u00e9 mobile.
 * ============================================================ */

/* Viewport et reset doux */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }

/* Cibles tactiles minimum 44x44 (Apple HIG) */
@media (max-width: 768px) {
  a, button, .btn, [role="button"], input[type="submit"], input[type="button"] {
    min-height: 44px;
    touch-action: manipulation;
  }
  input, textarea, select {
    min-height: 44px;
    font-size: 16px; /* \u00e9vite le zoom auto iOS */
  }

  /* Typographie respirable */
  body { line-height: 1.55; }
  h1 { font-size: clamp(1.5rem, 5vw, 2rem); line-height: 1.2; }
  h2 { font-size: clamp(1.25rem, 4vw, 1.5rem); line-height: 1.25; }
  h3 { font-size: clamp(1.1rem, 3.5vw, 1.25rem); line-height: 1.3; }
  p, li { font-size: clamp(0.95rem, 2.6vw, 1rem); }

  /* Conteneurs : padding lat\u00e9ral coh\u00e9rent */
  main, .container, .wrap, .content, section, article {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    box-sizing: border-box;
  }

  /* Images & m\u00e9dias responsive par d\u00e9faut */
  img, video, iframe, canvas, svg { max-width: 100%; height: auto; }

  /* Tableaux scrollables sans casser le layout */
  table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Padding bas pour ne pas \u00eatre cach\u00e9 par bottom nav React (h-16 = 64px) */
  body { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* Navigations natives HTML : compactage */
  nav ul, nav ol { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0; list-style: none; }
  nav a { padding: 10px 12px; border-radius: 10px; }

  /* R\u00e9duction encombrement visuel : opacit\u00e9 douce sur d\u00e9corations */
  .decoration, .ornament, .deco, .bg-decoration { opacity: 0.6; }
}

/* Carrousels & sliders : scroll horizontal natif tactile */
@media (max-width: 768px) {
  .scroll-x, .horizontal-scroll, .h-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
  }
  .scroll-x > *, .horizontal-scroll > *, .h-scroll > * {
    scroll-snap-align: start;
    flex-shrink: 0;
  }
}

/* Skeleton g\u00e9n\u00e9rique r\u00e9utilisable */
.dp-skeleton {
  display: inline-block;
  background: linear-gradient(90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.10) 50%,
    rgba(255,255,255,0.04) 100%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: dp-skeleton-shimmer 1.4s ease-in-out infinite;
}
.dp-skeleton-line { height: 12px; width: 100%; margin: 6px 0; }
.dp-skeleton-square { width: 56px; height: 56px; border-radius: 10px; }
.dp-skeleton-card { height: 120px; border-radius: 12px; width: 100%; }
@keyframes dp-skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Loading squares (4 carr\u00e9s pulse) — wrapper class .dp-loading-squares */
.dp-loading-squares {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.dp-loading-squares > i {
  display: block;
  width: 8px; height: 8px;
  background: var(--game-blue, #5aa9ff);
  border-radius: 2px;
  opacity: 0.6;
  animation: dp-square-pulse 0.9s ease-in-out infinite;
}
.dp-loading-squares > i:nth-child(2) { animation-delay: .12s; }
.dp-loading-squares > i:nth-child(3) { animation-delay: .24s; }
.dp-loading-squares > i:nth-child(4) { animation-delay: .36s; }
@keyframes dp-square-pulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.4); opacity: 1; }
}

/* Notifications inline standardis\u00e9es */
.dp-alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  margin: 12px 0;
  font-size: 14px;
  line-height: 1.5;
}
.dp-alert--error   { border-color: rgba(255,107,107,0.45); background: rgba(255,107,107,0.10); color: #ffb3b3; }
.dp-alert--warning { border-color: rgba(255,181,71,0.45);  background: rgba(255,181,71,0.10);  color: #ffd58a; }
.dp-alert--success { border-color: rgba(93,211,158,0.45);  background: rgba(93,211,158,0.10);  color: #b8eed3; }
.dp-alert--info    { border-color: rgba(90,169,255,0.45);  background: rgba(90,169,255,0.10);  color: #b8d8ff; }

/* R\u00e9duction d\u00e9clutter : masquer \u00e9l\u00e9ments lourds purement d\u00e9coratifs sur tr\u00e8s petits \u00e9crans */
@media (max-width: 480px) {
  .desktop-only, .hide-mobile { display: none !important; }
  .ornamental, .background-pattern { display: none !important; }
}

/* Respect motion preferences */
@media (prefers-reduced-motion: reduce) {
  .dp-skeleton, .dp-loading-squares > i { animation: none; }
  .dp-skeleton { background: rgba(255,255,255,0.06); }
}

/* Focus visible accessible */
:focus-visible {
  outline: 2px solid var(--game-blue, #5aa9ff);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================
 * Tiny mobile hardening v3 (iPhone SE2 / iPod-size / 320px)
 * ============================================================ */
html, body { max-width: 100%; overflow-x: hidden; }
html { scrollbar-gutter: stable; }

/* Long words / URLs must wrap, never push the layout */
body, p, li, h1, h2, h3, h4, h5, h6, a, span, td, th, code, pre {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Flex/grid children must allow shrinking to avoid horizontal overflow */
@media (max-width: 768px) {
  .row > *, .flex > *, [class*="grid"] > * { min-width: 0; }
}

/* Modals sized to dynamic viewport with safe-area + internal scroll */
.dp-modal,
[role="dialog"][aria-modal="true"] {
  max-height: 100dvh;
  max-width: 100vw;
  overflow: auto;
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Floating panels (Sun Hub etc.) must stay clear of bottom nav and notch */
.dp-floating, .sun-hub, .sun-donation {
  bottom: max(80px, calc(72px + env(safe-area-inset-bottom))) !important;
  right: max(12px, env(safe-area-inset-right));
  max-width: calc(100vw - 24px);
}

/* On very small screens, push the Sun Hub even higher so it never
   covers the quiz fixed .action-row (bottom: ~12px + safe-area). */
@media (max-width: 480px) {
  .dp-floating, .sun-hub, .sun-donation, .sun-btn, .sun-links {
    bottom: max(140px, calc(132px + env(safe-area-inset-bottom))) !important;
  }
}

/* Quiz/auth surfaces hide decorative floating UI when a sticky CTA
   needs the bottom space. Toggle with body[data-no-floating="true"]. */
body[data-no-floating="true"] .sun-btn,
body[data-no-floating="true"] .sun-links,
body[data-auth-surface="true"] .sun-btn,
body[data-auth-surface="true"] .sun-links {
  display: none !important;
}

@media (max-width: 375px) {
  .dp-floating, .sun-hub-panel { max-height: 60dvh; overflow: auto; }
}

/* Disabled / pending button visual + click-spam guard */
button[aria-busy="true"], button[disabled],
[role="button"][aria-busy="true"], [role="button"][aria-disabled="true"] {
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.7;
}

/* Z-index layering contract:
   modal (10000+) > auth panel (1000) > Sun panel (500) > Sun btn (400) > content (auto) */
.sun-btn { z-index: 400; }
.sun-links, .sun-hub-panel { z-index: 500; }
[role="dialog"][aria-modal="true"] { z-index: 10000; }


/* ============================================================
 * Readability v1 — daily-use, white-collar tone, 4L (Locate, Learn, Launch, Link)
 * ============================================================ */

/* Body sets a sane default so static HTML pages without their own
   typography rules still inherit a readable baseline. */
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
code, kbd, pre, samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* Reading width — keep paragraphs scannable on desktop without changing layout. */
main p, main li, article p, article li, .prose p, .prose li {
  max-width: 70ch;
}

/* One-idea-per-section spacing rhythm. */
main section, article section { margin-block: clamp(24px, 4vw, 48px); }
main h1, article h1 { font-size: clamp(1.75rem, 4vw, 2.25rem); line-height: 1.15; margin-bottom: 0.5em; }
main h2, article h2 { font-size: clamp(1.25rem, 3vw, 1.5rem);  line-height: 1.2;  margin-top: 1.25em; }
main h3, article h3 { font-size: clamp(1.05rem, 2.4vw, 1.2rem); line-height: 1.25; }

/* Status regions announced to assistive tech without overriding visuals. */
.dp-status, [role="status"], [aria-live="polite"], [aria-live="assertive"] {
  min-height: 1.2em;
}

/* Visible focus everywhere, even on custom controls. */
:focus-visible {
  outline: 2px solid var(--accent, #5aa9ff);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Print: hide floating decorations so receipts/articles print clean. */
@media print {
  .sun-btn, .sun-links, .dp-floating, nav, footer { display: none !important; }
  body { background: #fff !important; color: #000 !important; }
}
