/* PhophoToto - styles de la page (chargés par index.html). */

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

:root {
  color-scheme: light dark;
  --bg: #f3f1ec;
  --surface: #ffffff;
  --surface-2: #f7f5f1;
  --text: #1c1e22;
  --muted: #666b75;
  --border: #e3dfd7;
  --accent: #e4572e;
  --accent-hover: #cc4822;
  --accent-ink: #ffffff;
  --accent-soft: #fbe4db;
  --warn: #c62828;
  --stage: #202329;
  --ring: 0 0 0 3px rgba(228, 87, 46, 0.35);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.06), 0 10px 30px rgba(20, 20, 20, 0.07);
  --header-h: 60px; /* meme hauteur de barre que les autres outils Barbatools */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #23272e;
    --text: #eceef2;
    --muted: #9ba1ac;
    --border: #30343c;
    --accent: #ff6b42;
    --accent-hover: #ff8461;
    --accent-ink: #1d0e08;
    --accent-soft: #3b241c;
    --warn: #ff6b6b;
    --stage: #0e1013;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- En-tête et étapes ---------- */
header.top {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 18px 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.brand small { font-weight: 500; font-size: 13px; color: var(--muted); letter-spacing: 0; margin-left: 10px; }
.brand svg { width: 34px; height: 34px; flex: none; }

.stepper { display: flex; gap: 4px; list-style: none; margin: 0 0 0 auto; padding: 0; }

/* Menu Barbatools : icone tout a droite de la barre sur grand ecran ; chevron a cote du
   logo sur ecran etroit (seuil plus bas, choisi par mesure). Meme menu : Barbatools et
   les autres outils. */
.brand .barba-mobile { display: none; margin-left: -8px; }
.stepper button {
  display: flex; align-items: center; gap: 8px;
  border: 0; background: none; color: var(--muted);
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 6px 12px 6px 6px; border-radius: 999px; cursor: pointer;
}
.stepper button:hover:not(:disabled) { color: var(--text); }
.stepper button:disabled { cursor: default; opacity: 0.5; }
.stepper button:focus-visible { outline: none; box-shadow: var(--ring); }
.stepper .num {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  border: 1.5px solid currentColor; font-size: 12px;
}
.stepper button.done .num { background: var(--text); border-color: var(--text); color: var(--surface); }
.stepper button[aria-current="step"] { color: var(--accent); background: var(--accent-soft); }
.stepper button[aria-current="step"] .num { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

main { padding: 20px; }
.noscript { margin: 0; padding: 12px 20px; background: var(--accent-soft); color: var(--text); font-weight: 600; text-align: center; }

/* ---------- Boutons et champs ---------- */
.btn {
  font: inherit; font-weight: 600;
  border: 1.5px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.small { padding: 5px 9px; font-size: 13px; border-radius: 8px; font-variant-numeric: tabular-nums; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

input[type="text"] {
  width: 100%;
  font: inherit; font-size: 17px;
  padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
}
input[type="text"]:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 17px; height: 17px; margin: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Étape 1 ---------- */
.card {
  max-width: 900px; margin: 16px auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 28px;
}
.drop {
  position: relative; aspect-ratio: 1;
  display: grid; place-items: center; text-align: center;
  border: 2px dashed var(--border); border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer; overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-within { box-shadow: var(--ring); border-color: var(--accent); }
.drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.drop-text { padding: 16px; display: grid; gap: 6px; justify-items: center; }
.drop-text strong { font-size: 16px; }
.drop-text span { color: var(--muted); font-size: 13px; }
.drop-text svg { width: 40px; height: 40px; color: var(--accent); }
.drop.has-image .drop-text {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  padding: 7px 10px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.62); color: #fff;
}
.drop.has-image .drop-text svg, .drop.has-image .drop-text span { display: none; }
.drop.has-image .drop-text strong { font-size: 14px; }

.intro h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.intro p { margin: 0 0 18px; color: var(--muted); }
.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.case1 { margin-top: 14px; gap: 6px; }
.case1 .label { font-size: 13px; }

.preview-title { margin: 20px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
/* Démo : un mini-montage en fond blanc (bordure = 2 x séparation, comme le vrai) */
.demo {
  position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 3px;
  width: 100%; max-width: 340px;
  padding: 6px; background: #fff;
  border: 1px solid var(--border); border-radius: 10px;   /* délimite le blanc sur la carte */
}
.demo-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.demo-cell {
  position: relative; aspect-ratio: 1; min-width: 0; overflow: hidden;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 4px 7px;
  background: #dfe6ee;
}
.demo-cell > svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.demo-cell.split { justify-content: space-around; padding: 0 0 7px; }
.demo-cell.split > .meme { width: 50%; padding: 0 3px; text-align: center; }
.meme {
  position: relative;
  font-family: RobotoMeme, Roboto, Arial, sans-serif; font-weight: 700;
  font-size: 17px; line-height: 1.1; color: #fff;
  min-width: 0; max-width: 100%;
  white-space: pre; overflow: hidden; text-overflow: ellipsis;   /* pre : garde les espaces des bords */
  text-shadow: -1.5px -1.5px 0 #000, 1.5px -1.5px 0 #000, -1.5px 1.5px 0 #000, 1.5px 1.5px 0 #000,
               0 -1.5px 0 #000, 0 1.5px 0 #000, -1.5px 0 0 #000, 1.5px 0 0 #000;
}
.step1-actions { display: flex; justify-content: flex-end; margin-top: 20px; }

/* ---------- Étapes 2 et 3 ---------- */
.work {
  display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 20px;
  height: calc(100vh - var(--header-h) - 40px); min-height: 480px;
}
.stage {
  position: relative; overflow: hidden;
  background: var(--stage); border-radius: var(--radius);
}
.stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; outline: none; cursor: crosshair;
}
.stage canvas:focus-visible { box-shadow: inset 0 0 0 3px rgba(56, 225, 255, 0.55); }
.stage.result canvas {
  inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px);
  object-fit: contain; cursor: default;
}

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; overflow: auto;
  display: flex; flex-direction: column; gap: 16px;
}
.panel h2 { margin: 0; font-size: 17px; }
.help { margin: 0; padding-left: 20px; display: grid; gap: 7px; font-size: 13.5px; color: var(--muted); }
.help b { color: var(--text); }
.group { display: grid; gap: 8px; }
.row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
.row output { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.btns .btn { flex: 1 1 auto; }
.check { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 2px; flex: none; }
.info { margin: 0; font-size: 13px; color: var(--muted); }
.info.warn { color: var(--warn); font-weight: 600; }
.label { font-weight: 600; }
.sub { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 2px; }
.hints { display: flex; justify-content: space-between; margin-top: -6px; font-size: 12px; color: var(--muted); }
input[type="range"]:disabled { opacity: 0.4; }

.seg { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.seg.col { grid-template-columns: minmax(0, 1fr); }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--surface-2);
  font-weight: 600; font-size: 14px;
  transition: border-color 0.15s, background 0.15s;
}
.seg label:hover span { border-color: var(--muted); }
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.seg input:focus-visible + span { box-shadow: var(--ring); }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--muted); flex: none; }
.dot-black { background: #000; }
.dot-white { background: #fff; }
.sample {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 26px; border-radius: 6px; background: #8f969f;
  font-family: RobotoMeme, Roboto, Arial, sans-serif; font-weight: 700; font-size: 17px;
}
.sample-black {
  color: #000;
  text-shadow: -1.5px -1.5px 0 #fff, 1.5px -1.5px 0 #fff, -1.5px 1.5px 0 #fff, 1.5px 1.5px 0 #fff,
               0 -1.5px 0 #fff, 0 1.5px 0 #fff, -1.5px 0 0 #fff, 1.5px 0 0 #fff;
}
.sample-white {
  color: #fff;
  text-shadow: -1.5px -1.5px 0 #000, 1.5px -1.5px 0 #000, -1.5px 1.5px 0 #000, 1.5px 1.5px 0 #000,
               0 -1.5px 0 #000, 0 1.5px 0 #000, -1.5px 0 0 #000, 1.5px 0 0 #000;
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: auto; }
.actions .primary { flex: 1; }
.stack { display: grid; gap: 8px; }

/* ---------- Message ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  background: #1c1e22; color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3); font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Petits écrans ---------- */
@media (max-width: 860px) {
  /* Barre sur une seule ligne de 60 px, comme les autres outils Barbatools.
     Elle s'allege par etapes : sous-titre, puis nom, puis libelles des etapes. */
  header.top { gap: 12px; padding: 0 10px 0 12px; }
  .brand small { display: none; }
  .stepper { flex-wrap: nowrap; }
  .stepper button { padding-right: 8px; font-size: 13px; white-space: nowrap; }
  main { padding: 12px 16px; }
  .card { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 20px; }
  .drop { width: 100%; max-width: 340px; justify-self: center; }
  .work { grid-template-columns: minmax(0, 1fr); height: auto; }
  .stage { height: 62vh; min-height: 320px; }
}
@media (max-width: 620px) {
  /* Sous 620 px, l'icone Barbatools ferait deborder la barre : elle devient un chevron
     a cote du logo (mesure : debordement des 610 px avec les etapes) */
  .barba-desktop { display: none; }
  .brand .barba-mobile { display: inline-flex; }
}
/* Paliers 600 et 480 px (et non 560 et 440) : le chevron du menu Barbatools prend 25 px. */
@media (max-width: 600px) {
  .brand > span { display: none; }                 /* nom de l'appli : le logo suffit */
}
@media (max-width: 480px) {
  /* Etapes : seul le numero, sauf pour l'etape en cours ; les libelles masques
     restent lus par les lecteurs d'ecran. */
  .stepper button:not([aria-current="step"]) > span:not(.num) {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .stepper button:not([aria-current="step"]) { padding: 6px; }
}
@media (max-width: 420px) {
  .fields { grid-template-columns: minmax(0, 1fr); }
}
