/* ==========================================================================
   Mosaïk : feuille de style
   Les couleurs sont définies une seule fois (variables CSS) puis réutilisées.
   Le mode sombre redéfinit simplement ces variables.
   ========================================================================== */

:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --text: #1c1b1a;
  --muted: #6b6a66;
  --line: #e2e0da;
  --accent: #ff5a36;
  --accent-ink: #ffffff;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151413;
    --panel: #1f1e1c;
    --text: #f1efeb;
    --muted: #9b988f;
    --line: #34322e;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Mise en page générale : panneau à gauche, aperçu à droite ---------- */

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  height: 100dvh;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 20px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

section h2 {
  margin: 0 0 10px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Champs de formulaire ---------- */

.field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 8px;
  margin-bottom: 12px;
}

.field output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.field input[type="range"],
.field select {
  grid-column: 1 / -1;
  width: 100%;
}

.field.inline input[type="color"] {
  width: 44px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

select {
  font: inherit;
  padding: 7px 8px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

input[type="range"] { accent-color: var(--accent); }

.hint {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.selection-title {
  margin: 14px 0 8px;
  font-weight: 600;
}

/* ---------- Boutons ---------- */

.btn {
  font: inherit;
  padding: 9px 14px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--text); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  width: 100%;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.btn.primary:hover:not(:disabled) { filter: brightness(1.07); border-color: var(--accent); }

.btn.share { margin-top: 8px; }

/* Bouton seul sur sa ligne, sur toute la largeur */
.btn.block { width: 100%; margin-top: 8px; }

.btn:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.row .btn { flex: 1; }

/* Bouton à deux choix (Cadrer / Échanger) */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segmented label {
  position: relative;
  padding: 8px;
  text-align: center;
  font-size: 0.9rem;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  color: var(--bg);
  background: var(--text);
}

.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---------- Zone d'aperçu ---------- */

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 16px;
  overflow: hidden;
}

#board {
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  touch-action: none; /* indispensable : le doigt déplace la photo au lieu de faire défiler la page, et le pincement zoome la photo */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* évite le menu « enregistrer l'image » d'iOS lors d'un appui long */
}

.stage.dropping #board {
  outline: 3px dashed var(--accent);
  outline-offset: 4px;
}

.status {
  position: absolute;
  right: 16px;
  bottom: 8px;
  left: 16px;
  min-height: 1.2em;
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---------- Petits écrans : l'aperçu passe en haut, le panneau dessous ---------- */

@media (max-width: 820px) {
  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
  }

  .stage {
    order: -1;
    position: sticky;
    top: 0;
    z-index: 1;
    height: 55dvh;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
  }

  .panel {
    overflow: visible;
    border-right: none;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  /* iOS zoome automatiquement la page quand on touche un champ dont le texte
     fait moins de 16 px : on évite cet effet gênant. */
  select,
  input {
    font-size: 16px;
  }

  /* Cibles tactiles plus grandes */
  .btn { padding: 12px 14px; }
}
