:root {
  --fond: #f4f7f6;
  --surface: #ffffff;
  --texte: #16302b;
  --texte-doux: #5b6f6a;
  --bord: #dbe5e2;
  --accent: #0f766e;
  --accent-doux: #ccebe6;
  --accent-texte: #ffffff;
  --alerte-fond: #fff6e5;
  --alerte-bord: #f0c36d;
  --alerte-texte: #6b4a00;
  --ombre: 0 1px 2px rgba(16, 40, 35, .06), 0 4px 16px rgba(16, 40, 35, .06);
  --rayon: 14px;
  --scene-fond: #e8efed;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #0f1715;
    --surface: #17221f;
    --texte: #e3eeeb;
    --texte-doux: #9db1ac;
    --bord: #273632;
    --accent: #2bb3a3;
    --accent-doux: #173e39;
    --accent-texte: #06231f;
    --alerte-fond: #2b2210;
    --alerte-bord: #7a5d1d;
    --alerte-texte: #f3d79a;
    --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --scene-fond: #14201d;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --fond: #0f1715;
  --surface: #17221f;
  --texte: #e3eeeb;
  --texte-doux: #9db1ac;
  --bord: #273632;
  --accent: #2bb3a3;
  --accent-doux: #173e39;
  --accent-texte: #06231f;
  --alerte-fond: #2b2210;
  --alerte-bord: #7a5d1d;
  --alerte-texte: #f3d79a;
  --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --scene-fond: #14201d;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.visuellement-cache {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* En-tête */
.entete {
  padding: 16px max(16px, env(safe-area-inset-left)) 8px;
  max-width: 1180px; width: 100%; margin: 0 auto;
}
.marque { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='9' r='4' fill='white'/%3E%3Cpath d='M16 14v8M10 17h12M16 22l-4 6M16 22l4 6' stroke='white' stroke-width='2.6' stroke-linecap='round' fill='none'/%3E%3C/svg%3E") center / 30px no-repeat;
}
.entete h1 { margin: 0; font-size: 1.35rem; line-height: 1.2; letter-spacing: -.01em; }
.entete p { margin: 0; color: var(--texte-doux); font-size: .92rem; }

/* Mise en page : téléphone d'abord (recherche, corps, fiches) */
.page {
  flex: 1;
  width: 100%; max-width: 1180px; margin: 0 auto;
  padding: 8px 16px 24px;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "recherche" "corps" "resultats";
}
.recherche { grid-area: recherche; }
.corps { grid-area: corps; min-width: 0; }
.resultats { grid-area: resultats; min-width: 0; }

@media (min-width: 860px) {
  .page {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "corps recherche" "corps resultats";
    column-gap: 28px;
    align-items: start;
  }
  .corps { position: sticky; top: 16px; }
}

/* Recherche */
.champ {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--bord);
  border-radius: 999px; padding: 0 8px 0 16px; box-shadow: var(--ombre);
}
.champ:focus-within { border-color: var(--accent); outline: 3px solid var(--accent-doux); }
.champ svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--texte-doux); stroke-width: 2; stroke-linecap: round; }
.champ input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: inherit;
  font: inherit; font-size: 1.05rem; padding: 13px 0; outline: none;
}
.champ input::-webkit-search-cancel-button { display: none; }
.effacer {
  border: 0; background: var(--accent-doux); color: var(--texte);
  width: 32px; height: 32px; border-radius: 50%; font-size: 1.2rem; line-height: 1; cursor: pointer;
}

/* Corps 3D */
.scene {
  position: relative;
  height: min(58vh, 520px);
  min-height: 340px;
  border-radius: var(--rayon);
  background: radial-gradient(ellipse at 50% 35%, var(--surface), var(--scene-fond) 75%);
  border: 1px solid var(--bord);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.scene:active { cursor: grabbing; }
.scene.survol { cursor: pointer; }
.scene canvas { display: block; width: 100%; height: 100%; }
@media (min-width: 860px) { .scene { height: min(72vh, 640px); } }

.aide {
  position: absolute; left: 0; right: 0; bottom: 10px; margin: 0;
  text-align: center; font-size: .85rem; color: var(--texte-doux); pointer-events: none;
}
.tourner { position: absolute; right: 10px; bottom: 34px; display: flex; flex-direction: column; gap: 8px; }
.tourner button {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--bord);
  background: var(--surface); color: var(--texte); font-size: 1.3rem; line-height: 1;
  cursor: pointer; box-shadow: var(--ombre);
}
.tourner button:hover { border-color: var(--accent); color: var(--accent); }
.tourner button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.infobulle {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--texte); color: var(--fond);
  padding: 4px 12px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  pointer-events: none; white-space: nowrap;
}
.scene-erreur {
  display: grid; place-items: center; height: 100%; padding: 24px;
  text-align: center; color: var(--texte-doux);
}

.zones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.puce {
  border: 1px solid var(--bord); background: var(--surface); color: var(--texte);
  border-radius: 999px; padding: 7px 13px; font: inherit; font-size: .9rem; cursor: pointer;
  min-height: 36px;
}
.puce:hover { border-color: var(--accent); }
.puce[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.puce .nb { opacity: .7; margin-left: 4px; font-size: .8rem; }

/* Liste des fiches */
.resultats-tete { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 4px 2px 10px; }
.resultats h2 { margin: 0; font-size: 1.1rem; }
.lien { border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 4px; }

.liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.carte {
  display: flex; gap: 14px; align-items: center; width: 100%; text-align: left;
  background: var(--surface); color: inherit; border: 1px solid var(--bord);
  border-radius: var(--rayon); padding: 10px; font: inherit; cursor: pointer; box-shadow: var(--ombre);
}
.carte:hover { border-color: var(--accent); }
.carte:focus-visible, .puce:focus-visible, .lien:focus-visible, .fermer:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.vignette {
  width: 76px; height: 76px; flex: none; border-radius: 10px; overflow: hidden;
  background: var(--accent-doux); display: grid; place-items: center;
}
.vignette img { width: 100%; height: 100%; object-fit: cover; }
.vignette svg, .photo-vide svg { width: 44%; height: 44%; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.carte h3 { margin: 0 0 2px; font-size: 1rem; line-height: 1.3; }
.carte p { margin: 0; color: var(--texte-doux); font-size: .9rem; line-height: 1.4; }
.vide { color: var(--texte-doux); padding: 20px 4px; }

/* Fiche détaillée */
.fiche { position: fixed; inset: 0; z-index: 10; display: flex; justify-content: center; align-items: flex-start; }
.fiche[hidden] { display: none; }
.fiche-fond { position: absolute; inset: 0; background: rgba(8, 20, 18, .45); }
.fiche-carte {
  position: relative; background: var(--surface); width: 100%; height: 100%;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 16px max(32px, env(safe-area-inset-bottom));
}
@media (min-width: 700px) {
  .fiche { align-items: center; padding: 24px; }
  .fiche-carte { max-width: 680px; height: auto; max-height: calc(100vh - 48px); border-radius: 18px; padding: 16px 28px 32px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
}
.fermer {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600;
  padding: 8px 4px; margin-bottom: 8px; cursor: pointer; font-size: 1rem;
}
.photo {
  width: 100%; aspect-ratio: 4 / 3; border-radius: var(--rayon); overflow: hidden;
  background: var(--accent-doux); margin-bottom: 16px;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-vide { display: grid; place-items: center; align-content: center; gap: 4px; color: var(--texte-doux); font-size: .9rem; }
.photo-vide svg { width: 64px; height: 64px; }
.fiche h2 { margin: 0 0 6px; font-size: 1.5rem; line-height: 1.2; letter-spacing: -.01em; }
.etiquettes { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.etiquette { background: var(--accent-doux); color: var(--texte); border-radius: 999px; padding: 2px 10px; font-size: .82rem; }
.objectif { font-size: 1.05rem; margin: 0 0 18px; }
.fiche h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--texte-doux); margin: 20px 0 6px; }
.fiche p { margin: 0; }
.etapes { margin: 0; padding: 0; list-style: none; counter-reset: etape; display: grid; gap: 10px; }
.etapes li { counter-increment: etape; display: flex; gap: 12px; align-items: flex-start; }
.etapes li::before {
  content: counter(etape); flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-texte); font-weight: 700; font-size: .9rem;
  display: grid; place-items: center; margin-top: -1px;
}
.dosage {
  margin-top: 20px; padding: 12px 14px; border-radius: 12px;
  background: var(--accent-doux); font-weight: 600;
}
.precautions {
  margin-top: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--alerte-fond); border: 1px solid var(--alerte-bord); color: var(--alerte-texte);
}

.pied {
  max-width: 1180px; margin: 0 auto; padding: 16px 16px max(24px, env(safe-area-inset-bottom));
  color: var(--texte-doux); font-size: .85rem; text-align: center;
}

body.fiche-ouverte { overflow: hidden; }
