:root {
  color-scheme: light;
  --bg: #faf6ef;
  --panel: #ffffff;
  --ink: #171310;
  --muted: #6b6156;
  --line: #e7ddc9;
  --accent: #a9631f;
  --danger: #8f2d2d;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

/* Grain de fond — même texture que le reste du site (assets/css/main.css),
   en CSS pur pour ne pas charger de JS sur les pages outil. Pas de curseur
   personnalisé ici : il gênerait la manipulation précise du viewer 3D. */
body::after {
  content: ''; position: fixed; inset: 0; z-index: 9998; pointer-events: none;
  opacity: .05; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}
@media (hover: none), (pointer: coarse) { body::after { display: none; } }

::selection { background: var(--accent); color: #fff; }
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1180px, calc(100% - 28px)); margin: 0 auto; padding: 24px 0 44px; }
.cfg-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 6px; font-size: 11px; letter-spacing: .18em; font-weight: 800; }
.back-link { color: var(--ink); text-decoration: none; }
.back-link:hover { color: var(--accent); }
h1 { margin: 0; font-family: 'Fraunces', Georgia, serif; font-size: clamp(30px, 5vw, 52px); font-weight: 500; line-height: .95; }


.tryon-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(290px, .75fr); gap: 18px; align-items: start; }
.viewer-card, .control-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.viewer-card { padding: 12px; }
.stage { position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden; background: #171717; }
/* Calque 3D : recouvre exactement la vidéo, fond transparent. Le miroir
   selfie est appliqué ICI en CSS (et nulle part ailleurs dans la scène 3D)
   pour éviter toute double inversion. */

.permission-panel, .loading-panel { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 28px; color: #fff; background: radial-gradient(circle at center, #34312e 0%, #151515 75%); }
.permission-panel h2 { margin: 8px 0; font-family: 'Fraunces', Georgia, serif; font-size: clamp(25px, 4vw, 38px); font-weight: 500; }
.permission-panel p { max-width: 510px; margin: 4px 0 20px; color: #d2d0cc; line-height: 1.5; }
.permission-icon { font-size: 54px; }
.microcopy { font-size: 12px; opacity: .72; }
.hidden { display: none !important; }

.secondary-btn { background: #f7f5f1; border-color: var(--line); color: var(--ink); }
.secondary-btn:disabled { cursor: not-allowed; opacity: .42; }
.secondary-btn.danger:not(:disabled) { color: var(--danger); }
.viewer-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 10px; }

.loading-panel { gap: 12px; background: rgba(18,18,18,.9); }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.24); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Panneau de calibration 3D — mode ?debug=1 uniquement, jamais visible
   pour un client. Volontairement minimal (outil de réglage, pas de
   l'UI produit). */

.control-panel { padding: 4px 18px; }
.control-section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.control-section:last-child { border-bottom: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.control-section h2 { margin: 0 0 12px; font-size: 15px; }
.section-heading h2 { margin: 0; }
.model-name { color: var(--muted); font-size: 12px; }
.hat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.hat-option { min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: #faf9f7; padding: 8px; text-align: left; transition: border-color .15s, background .15s, transform .15s; }
.hat-option:hover { transform: translateY(-1px); }
.hat-option.selected { border-color: var(--ink); background: #f0ede7; box-shadow: inset 0 0 0 1px var(--ink); }
.hat-option img { width: 100%; aspect-ratio: 1.8 / 1; object-fit: contain; display: block; }
.hat-option span { display: block; margin-top: 4px; font-size: 12px; font-weight: 700; }

/* Configurateur 3D */
.cfg-stage { background: #f3ece0; }
.cfg-stage canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.zoom-controls { position: absolute; left: 14px; top: 14px; display: flex; flex-direction: column; gap: 6px; z-index: 4; }
.zoom-controls button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.92); color: var(--ink); font-size: 17px; font-weight: 700; line-height: 1; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.zoom-controls button:hover { background: #fff; border-color: var(--accent); }
.swatch-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatch { width: 100%; aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; background: var(--swatch-color); cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); transition: transform .12s, border-color .12s; }
.swatch:hover { transform: scale(1.08); }
.swatch.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 0 0 2px #fff, 0 0 0 3px var(--accent); }
.disabled-section { opacity: .4; pointer-events: none; }

.toggle { position: relative; display: inline-flex; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle-track { width: 38px; height: 22px; background: var(--line); border-radius: 999px; display: block; position: relative; transition: background .15s; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }

input[type="range"] { width: 100%; accent-color: var(--accent); }
.text-btn { border: 0; background: transparent; padding: 7px 0; text-decoration: underline; color: var(--muted); font-size: 12px; }
.dev-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.dev-note strong { color: var(--ink); }
.dev-note p { margin: 5px 0 0; }

@media (max-width: 820px) {
  .app-shell { width: min(100% - 18px, 720px); padding-top: 14px; }
  .cfg-head { align-items: start; }
  .tryon-layout { grid-template-columns: 1fr; }
  .stage { aspect-ratio: 3 / 4; }
  .control-panel { padding: 2px 14px; }
  .viewer-actions .secondary-btn { flex: 1 1 30%; }
}

@media (max-width: 430px) {
  .cfg-head { flex-direction: column; }
  .viewer-card { padding: 7px; }
}

/* ---------------------------------------------------------------
   Habillage "atelier" de la page de personnalisation.
   La page charge main.css en premier (identité du site : header,
   footer, boutons, pastilles de taille) et ce fichier par-dessus
   pour ce qui est propre au configurateur.
   --------------------------------------------------------------- */
.app-shell { padding-top: 34px; }
.cfg-head { display: block; max-width: 620px; margin-bottom: 26px; }
.cfg-head h1 { font-size: clamp(30px, 4.4vw, 46px); font-weight: 600; margin-bottom: 12px; }
.cfg-intro { color: var(--muted); font-size: 15.5px; line-height: 1.6; margin: 0; }

.viewer-card { padding: 14px; box-shadow: 0 14px 40px rgba(23,19,16,.08); }
.stage { aspect-ratio: 5 / 4; }
.cfg-stage { background: linear-gradient(180deg, #efe6d8 0%, #e6d9c6 45%, #cbb9a0 100%); }

/* Indication de manipulation : discrète, et elle s'efface au survol
   pour ne pas rester en travers du produit pendant qu'on le tourne. */
.stage-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  margin: 0; padding: 7px 14px; border-radius: 999px;
  background: rgba(23,19,16,.55); color: #f6f1e8; font-size: 12px;
  backdrop-filter: blur(5px); pointer-events: none;
  transition: opacity .3s ease; z-index: 3;
}
.cfg-stage:hover .stage-hint { opacity: 0; }

.control-panel { box-shadow: 0 14px 40px rgba(23,19,16,.08); }
.control-section h2 {
  display: flex; align-items: center; gap: 9px;
  font-family: 'Fraunces', Georgia, serif; font-size: 16px; font-weight: 600;
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 21px; height: 21px; border-radius: 50%; flex-shrink: 0;
  background: var(--ink); color: #fff;
  font-family: Inter, sans-serif; font-size: 11px; font-weight: 700;
}
.swatch-name { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.swatch-name a { color: var(--accent); }

.hat-option img { aspect-ratio: 1 / 1; object-fit: cover; border-radius: 8px; }
.hat-option.selected { box-shadow: inset 0 0 0 2px var(--ink); }

.control-section .size-pills { margin-top: 4px; }

/* Récapitulatif + achat : la seule zone en fond plein du panneau, pour
   que l'œil y revienne naturellement après avoir composé le chapeau. */
.cfg-summary { background: #faf7f1; margin: 0 -18px -4px; padding: 18px; border-top: 1px solid var(--line); }
.cfg-summary-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.cfg-summary-row strong { display: block; font-family: 'Fraunces', Georgia, serif; font-size: 16px; }
.cfg-summary-row span { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.cfg-summary-price { font-family: 'Fraunces', Georgia, serif; font-size: 19px; color: var(--accent); white-space: nowrap; }
.cfg-note { margin: 10px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* ---- Photos du modèle (glissière) + bascule vers l'aperçu 3D ---- */
.cfg-mode { display: flex; gap: 6px; margin-bottom: 12px; padding: 4px; background: #f3ece0; border-radius: 999px; width: fit-content; max-width: 100%; }
.cfg-mode-btn { border: 0; background: none; font: inherit; font-size: 13.5px; font-weight: 600; padding: 8px 16px; border-radius: 999px; color: #6b5f52; cursor: pointer; transition: background .2s, color .2s; }
.cfg-mode-btn.is-active { background: #171310; color: #f4efe6; }
.cfg-photos[hidden], .cfg-stage[hidden] { display: none; }
.cfg-photos .product-gallery-main { aspect-ratio: 5 / 4; border-radius: 12px; box-shadow: none; }
.cfg-photos .slide img, .cfg-photos .product-gallery-main > img { width: 100%; height: 100%; object-fit: cover; }
.cfg-photos .product-gallery-main { background: #fff; }
.cfg-photos .slider-tabs { padding: 4px 2px 0; }
.cfg-3d-note { margin: 0 0 10px; font-size: 13px; color: #6b5f52; }
.viewer-card.is-photos #cfgResetView, .viewer-card.is-photos #cfgCapture { display: none; }
@media (max-width: 560px) { .cfg-mode-btn { padding: 8px 12px; font-size: 12.5px; } }

/* ---- Configurateur photo (offre fait main) ---- */
.cfg-photo { aspect-ratio: 4 / 5; max-height: 78vh; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #fff; }
.cfg-photo img { width: 100%; height: 100%; object-fit: contain; display: block; transition: opacity .25s ease; }
.cfg-photo img.is-changing { opacity: .35; }
.cfg-photo-caption { margin: 10px 2px 0; font-size: 13.5px; color: #6b5f52; text-align: center; }
.cfg-help { margin: -4px 0 10px; font-size: 13px; color: #6b5f52; }
