:root {
  --blue-950: #061645;
  --blue-900: #0a2472;
  --blue-700: #1244b0;
  --blue-600: #1450c8;
  --blue-500: #1f6fe0;
  --yellow: #fbfb08;
  --yellow-dark: #c8c800;
  --ink: #0b1b4a;
  --muted: #4d5b7c;
  --card: #ffffff;
  --err-bg: #fdecea;
  --err: #a8201a;
  --radius: 18px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  color: var(--ink);
  background-color: var(--blue-900);
  background-image: radial-gradient(130% 75% at 50% 0%, #2a7df0 0%, var(--blue-600) 36%, var(--blue-900) 72%, var(--blue-950) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px calc(32px + env(safe-area-inset-bottom));
}

.inapp {
  background: var(--yellow);
  color: var(--blue-950);
  padding: 12px 16px;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}

/* En-tête */
.top { color: #fff; text-align: center; padding: 6px 4px 14px; }
.eyebrow { margin: 0 0 6px; color: var(--yellow); font-weight: 700; font-size: 14px; line-height: 1.35; }
h1 { margin: 0; font-size: clamp(24px, 7vw, 32px); line-height: 1.15; font-weight: 800; letter-spacing: -0.01em; }

/* Carte principale */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 12px 32px rgba(3, 12, 45, 0.4);
}

.stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--blue-900);
  line-height: 0;
}

#preview {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  outline: none;
}
#preview:focus-visible { box-shadow: inset 0 0 0 4px #ff9800; }
body[data-state="editing"] #preview { touch-action: none; cursor: grab; }
body[data-state="editing"] #preview:active { cursor: grabbing; }

/* Indicateur de chargement */
.spinner {
  display: none;
  position: absolute;
  inset: 0;
  margin: auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--yellow);
  animation: spin 0.9s linear infinite;
}
body[data-state="loading"] .spinner,
body[data-busy="1"] .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Édition */
.hint, .zoom-row { display: none; }
body[data-state="editing"] .hint-edit { display: block; }
body[data-state="editing"] .zoom-row { display: flex; }

.hint {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  transition: background-color 0.2s, color 0.2s;
}
.hint--tip { background: #fff5a8; color: var(--blue-950); font-weight: 700; }

.zoom-row { align-items: center; gap: 10px; padding: 4px 6px 0; }
.zoom-row span { width: 26px; text-align: center; font-size: 26px; font-weight: 800; color: var(--blue-600); line-height: 1; }
#zoom { flex: 1; min-width: 0; height: 40px; margin: 0; accent-color: var(--blue-600); }

/* Nom (option) */
.name-slot { margin-top: 12px; }
body[data-state="loading"] .name-slot { display: none; }
.field-label { display: block; font-weight: 700; margin: 0 2px 6px; }
.field {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  border: 2px solid #b9c6e4;
  border-radius: 12px;
  background: #fff;
}
.field:focus { outline: none; border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(20, 80, 200, 0.2); }

/* Erreur */
.error {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--err-bg);
  color: var(--err);
  font-weight: 600;
}

/* Boutons */
.actions { display: grid; gap: 10px; margin-top: 12px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 12px 18px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.btn svg { width: 24px; height: 24px; flex: none; fill: currentColor; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, #photo-input:focus-visible + .btn { outline: 3px solid #ff9800; outline-offset: 2px; }

.btn-primary { background: var(--yellow); color: var(--blue-950); box-shadow: 0 3px 0 var(--yellow-dark); }
.btn-secondary { background: var(--blue-600); color: #fff; box-shadow: 0 3px 0 var(--blue-900); }
.btn-outline { background: #fff; color: var(--blue-600); border: 2px solid var(--blue-600); }
.btn-link { min-height: 48px; background: transparent; color: var(--blue-600); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

.when-empty, .when-editing { display: none; }
body[data-state="empty"] .btn.when-empty,
body[data-state="error"] .btn.when-empty,
body[data-state="editing"] .btn.when-editing { display: flex; }
body[data-busy="1"] .actions { opacity: 0.6; pointer-events: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Résultat */
.result { margin-top: 16px; text-align: center; }
.result h2 { margin: 4px 0 12px; font-size: 22px; color: var(--blue-900); }
.result img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  -webkit-touch-callout: default;
}
.result-hint { margin: 12px 4px 4px; color: var(--muted); font-size: 15px; }

.noscript { color: #fff; text-align: center; padding: 16px; }

@media (min-width: 600px) {
  .wrap { padding-top: 28px; }
  .card { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.5s; }
}
