/* =========================================================================
   Lele's Shop — thème atelier clair (papier / encre / fil rouge).
   Zéro glassmorphism : surfaces pleines, bordures fines, ombres douces.
   ========================================================================= */

:root {
  --paper: #f4f0e7;
  --paper-2: #ece5d8; /* = clear color de la scène 3D */
  --card: #fbf8f1;
  --ink: #1e1b17;
  --muted: #6e675c;
  --line: #d8d0bf;
  --accent: #9d5389; /* fil rose-violet doux */
  --accent-soft: #ecd8e8;

  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(30, 27, 23, 0.06), 0 2px 8px rgba(30, 27, 23, 0.06);
  --shadow-md: 0 6px 24px rgba(30, 27, 23, 0.12), 0 2px 6px rgba(30, 27, 23, 0.08);

  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --serif: 'Hoefler Text', Georgia, 'Times New Roman', serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---- Scène 3D (fond) ---------------------------------------------------- */
#shop-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* suit la zone visible réelle sur mobile (barre d'adresse) */
  display: block;
  z-index: 0;
  touch-action: none;
}

/* ---- Racine des overlays ----------------------------------------------- */
#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

/* ---- Boot loader -------------------------------------------------------- */
#boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--paper-2);
  transition: opacity 0.5s ease;
}
body.is-ready #boot {
  opacity: 0;
  pointer-events: none;
}
.boot__spinner {
  width: 34px;
  height: 34px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.boot__label {
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.02em;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- Sélecteur de langue (fixe, haut-droite, desktop + mobile) ---------- */
.lang-switch {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 60; /* au-dessus des overlays (10) et du boot (50) */
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
body.is-ready .lang-switch {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.lang-switch__btn {
  appearance: none;
  border: 0;
  background: transparent;
  font-family: var(--sans);
  font-size: 16px; /* taille du drapeau emoji (et du repli initiales sur OS sans emoji drapeau) */
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  padding: 5px 8px;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.5;
  filter: saturate(0.7);
  transition: opacity 0.16s ease, filter 0.16s ease, background 0.16s ease, transform 0.08s ease;
}
.lang-switch__btn:hover {
  opacity: 0.85;
}
.lang-switch__btn:active {
  transform: translateY(1px);
}
.lang-switch__btn.is-active {
  opacity: 1;
  filter: none;
  background: var(--accent-soft);
}
@media (max-width: 640px) {
  .lang-switch {
    gap: 1px;
    padding: 2px;
  }
  .lang-switch__btn {
    padding: 5px 7px;
  }
}

/* ---- Overlay générique -------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  opacity: 0;
  transition: opacity 0.32s ease;
  pointer-events: auto;
}
.overlay.is-open {
  opacity: 1;
}
.overlay.is-closing {
  opacity: 0;
}
.overlay--center,
.overlay--panel {
  background: rgba(244, 240, 231, 0.74); /* scrim plat, pas de blur */
}
.overlay--sketch {
  background: transparent;
  pointer-events: none;
}
.overlay--sketch > * {
  pointer-events: auto;
}

/* ---- Typo --------------------------------------------------------------- */
.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}
.display {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.05;
  margin: 0 0 14px;
}
.lede {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
  margin: 0 0 24px;
}

/* ---- Boutons ------------------------------------------------------------ */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 13px 30px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  transition: background 0.18s ease, transform 0.06s ease, opacity 0.18s ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn--primary {
  background: var(--ink);
  color: var(--paper);
}
.btn--primary:hover {
  background: var(--accent);
}
.btn--primary[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  background: var(--ink);
}
.btn--sm {
  padding: 10px 20px;
  font-size: 14px;
}

/* ---- Carte Welcome ------------------------------------------------------ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px;
  max-width: 460px;
  text-align: center;
  animation: rise 0.4s ease both;
}
.card--welcome {
  padding: 48px 44px;
}
/* Petite modale d'intro au croquis : plus compacte que la carte Welcome */
.card--intro {
  max-width: 380px;
  padding: 32px 34px;
}
.card--intro .display {
  font-size: clamp(24px, 4.6vw, 30px);
  margin-bottom: 8px;
}
.card--intro .lede {
  margin-bottom: 22px;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---- Panel générique (perso / tissus / récap) --------------------------- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 28px;
  animation: rise 0.4s ease both;
}
.panel--wide {
  width: min(880px, 100%);
}
.panel__head {
  text-align: center;
  margin-bottom: 20px;
}
.panel__title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 24px;
  margin: 0 0 6px;
}
.panel__sub {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}
.panel__foot {
  margin-top: 22px;
  display: flex;
  justify-content: center;
}

/* ---- Grille personnages ------------------------------------------------- */
.char-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.char-card {
  appearance: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 8px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.06s ease;
}
.char-card:hover {
  border-color: #c4baa6;
  box-shadow: var(--shadow-sm);
}
.char-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.char-card__viewer {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  background: linear-gradient(180deg, #f6f2e9, #eee7d9);
  overflow: hidden;
}
.char-card__viewer.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.6) 50%, transparent 80%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}
.char-card__canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.char-card__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.char-card__err {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--muted);
}

/* ---- Sketch ------------------------------------------------------------- */
.sketch-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* reste calé sur le canvas 3D en dessous */
  z-index: 5;
  cursor: crosshair;
  touch-action: none;
}
.sketch-frame {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(52vh, 78vw);
  width: min(52dvh, 78vw);
  height: min(74vh, 92vw);
  height: min(74dvh, 92vw);
  z-index: 4;
  pointer-events: none;
}
.sketch-frame__c {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 2px solid rgba(30, 27, 23, 0.28);
}
.sketch-frame__c.tl {
  top: 0;
  left: 0;
  border-right: 0;
  border-bottom: 0;
}
.sketch-frame__c.tr {
  top: 0;
  right: 0;
  border-left: 0;
  border-bottom: 0;
}
.sketch-frame__c.bl {
  bottom: 0;
  left: 0;
  border-right: 0;
  border-top: 0;
}
.sketch-frame__c.br {
  bottom: 0;
  right: 0;
  border-left: 0;
  border-top: 0;
}
.sketch-tools {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 6;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.sketch-hint {
  font-size: 12px;
  color: var(--muted);
}
.sketch-tools__row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tool {
  appearance: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 54px;
  transition: border-color 0.14s, background 0.14s;
}
.tool:hover {
  border-color: #c4baa6;
}
.tool.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.tool__glyph {
  font-size: 16px;
  line-height: 1;
}
.tool__label {
  font-size: 11px;
  color: var(--muted);
}

/* ---- Épaisseur du crayon (fin / moyen / épais) -------------------------- */
.sketch-sizes {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.size {
  appearance: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.14s;
}
.size:hover {
  background: var(--paper);
}
.size.is-active {
  background: var(--accent-soft);
}
.size__dot {
  display: block;
  border-radius: 50%;
  background: var(--ink);
}
.size.is-active .size__dot {
  background: var(--accent);
}

/* ---- Palette de couleurs (sketch) --------------------------------------- */
.sketch-swatches {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.swatch {
  appearance: none;
  position: relative;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--sw, #000);
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--line);
  transition: transform 0.1s, box-shadow 0.14s;
}
.swatch:hover {
  transform: scale(1.12);
}
.swatch.is-active {
  box-shadow: 0 0 0 2px var(--accent);
}
.swatch--custom {
  overflow: hidden;
  background: conic-gradient(
    from 0deg,
    #ff3b30,
    #ffcc00,
    #34c759,
    #00c7be,
    #007aff,
    #af52de,
    #ff3b30
  );
}
.swatch__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

/* ---- Grille tissus ------------------------------------------------------ */
.fabric-counter {
  font-weight: 600;
  color: var(--accent);
}
.fabric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.fabric-tile {
  appearance: none;
  position: relative;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.16s, box-shadow 0.16s, transform 0.06s;
}
.fabric-tile:hover {
  border-color: #c4baa6;
}
.fabric-tile.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.fabric-tile__img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background-size: cover;
  background-position: center;
}
.fabric-tile__check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.16s, transform 0.16s;
}
.fabric-tile.is-selected .fabric-tile__check {
  opacity: 1;
  transform: none;
}
.fabric-tile__name {
  display: block;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* ---- Récap -------------------------------------------------------------- */
.recap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.recap__hero {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #f6f2e9, #ece5d8);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.recap__sketch {
  max-width: 100%;
  max-height: 46vh;
  border-radius: 8px;
  background: #fff;
}
.recap__sketch--empty {
  display: grid;
  place-items: center;
  min-height: 200px;
  color: var(--muted);
}
.recap__badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 5px 12px;
  border-radius: 999px;
  margin: 0 0 10px;
}
.recap__side {
  display: flex;
  flex-direction: column;
}
.recap-list {
  margin: 4px 0 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 14px;
}
.recap-list dt {
  color: var(--muted);
}
.recap-list dd {
  margin: 0;
  font-weight: 600;
}
.recap-fabrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.recap-fabric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 60px;
}
.recap-fabric__img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background-size: cover;
  background-position: center;
}
.recap-fabric__name {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  line-height: 1.15;
}
.recap__ask {
  font-size: 14px;
  color: var(--muted);
  margin: 6px 0 8px;
}
.field {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  font-family: var(--sans);
  background: #fff;
  margin-bottom: 8px;
}
.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.field--area {
  resize: vertical;
  min-height: 72px;
  line-height: 1.4;
}
.field-count {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  margin: -4px 0 10px;
}
.field-err {
  color: var(--accent);
  font-size: 13px;
  min-height: 18px;
  margin: 0 0 8px;
}

/* ---- Écran merci -------------------------------------------------------- */
.thanks {
  text-align: center;
  padding: 20px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.thanks__mark {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
}
.thanks__sketch {
  margin-top: 18px;
  max-width: 320px;
  max-height: 40vh;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}

/* ---- Shake -------------------------------------------------------------- */
.shake {
  animation: shake 0.32s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* =========================================================================
   Responsive — tablette, téléphone, petit téléphone, paysage court.
   Base = desktop ; on resserre à mesure que l'écran rétrécit.
   ========================================================================= */

/* ---- Tablette (≤ 900px) : panneaux plus souples, moins de marge ---------- */
@media (max-width: 900px) {
  .panel {
    width: min(680px, 100%);
    padding: 24px;
  }
  .panel--wide {
    width: min(760px, 100%);
  }
  .recap {
    gap: 18px;
  }
}

/* ---- Téléphone (≤ 640px) ------------------------------------------------- */
@media (max-width: 640px) {
  .overlay {
    padding: 16px;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  }

  /* Cartes / typo un cran plus compacts */
  .card {
    padding: 30px 24px;
  }
  .card--welcome {
    padding: 34px 26px;
  }
  .display {
    font-size: clamp(26px, 8vw, 36px);
  }
  .lede {
    font-size: 15px;
    margin-bottom: 20px;
  }

  /* Panneaux : pleine largeur, hauteur qui suit la zone visible */
  .panel,
  .panel--wide {
    width: 100%;
    padding: 20px 16px;
    max-height: calc(100dvh - 32px);
  }
  .panel__title {
    font-size: 21px;
  }

  /* Grilles */
  .char-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .fabric-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Récap en une colonne */
  .recap {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .recap__sketch {
    max-height: 40vh;
    max-height: 40dvh;
  }
  /* La barre d'outils du sketch est gérée dans son bloc dédié plus bas
     (couleurs en haut, outils en bas) pour dégager le personnage. */
}

/* ---- Petit téléphone (≤ 380px) : 2 tissus par ligne, marges minimales ---- */
@media (max-width: 380px) {
  .fabric-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .char-grid {
    gap: 8px;
  }
  .swatch {
    width: 24px;
    height: 24px;
  }
}

/* ---- Paysage court (téléphone couché) : ancrage haut + scroll interne ----- */
@media (max-height: 480px) and (orientation: landscape) {
  .overlay {
    align-items: flex-start;
    padding: 10px;
    padding: 10px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left));
  }
  .panel,
  .panel--wide {
    max-height: calc(100dvh - 20px);
  }
  .card--welcome {
    padding: 22px 26px;
  }
  /* (barre du sketch : voir le bloc dédié plus bas) */
}

/* =========================================================================
   Sketch sur mobile — barre dégroupée : COULEURS en haut, OUTILS en bas.
   Deux fines pastilles sur les bords → le personnage (tête + torse) reste
   dégagé au centre pour dessiner. S'applique en portrait et en paysage.
   ========================================================================= */
@media (max-width: 640px), (max-height: 520px) and (orientation: landscape) {
  /* Le conteneur devient un simple passe-plat transparent ; ses deux barres
     (palette + rangée d'outils) se positionnent chacune sur un bord. */
  .sketch-tools {
    inset: 0;
    transform: none;
    width: auto;
    max-width: none;
    padding: 0;
    gap: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
    pointer-events: none;
  }
  .sketch-hint {
    display: none; /* on garde l'écran propre ; les libellés d'outils suffisent */
  }

  /* Pastilles flottantes : fond papier, centrées, jamais hors-écran */
  .sketch-swatches,
  .sketch-tools__row {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100vw - 16px);
    pointer-events: auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    padding: 7px 10px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .sketch-swatches {
    top: max(8px, env(safe-area-inset-top)); /* couleurs tout en haut */
  }
  .sketch-tools__row {
    bottom: max(10px, env(safe-area-inset-bottom)); /* outils tout en bas */
    gap: 8px;
  }
  /* Outils un peu plus compacts pour tenir sur une ligne */
  .tool {
    min-width: 44px;
    padding: 6px 9px;
  }
  .size {
    width: 27px;
    height: 27px;
  }
}

/* ---- Pointeur grossier (doigt) : cibles tactiles plus généreuses --------- */
@media (hover: none) and (pointer: coarse) {
  .char-card,
  .fabric-tile,
  .tool,
  .size,
  .swatch,
  .btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}
