:root {
  --brand: #5b6ccf;
  --brand-dark: #3f4fa0;
  --bg: #11131a;
  --panel: rgba(20, 22, 30, 0.78);
  --btn: rgba(255, 255, 255, 0.14);
  --btn-active: #5b6ccf;
  --text: #f4f5fb;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  overflow: hidden; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none;
}

/* Camera plein ecran */
#cam {
  position: fixed; inset: 0; width: 100%; height: 100%;
  object-fit: cover; background: #000; z-index: 0;
}

/* Calque modele */
#overlayWrap {
  position: fixed; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
#overlay {
  width: 78vmin; height: 78vmin;
  opacity: 0.55;
  transform: translate(0px, 0px) scale(1) rotate(0deg);
  transition: opacity 0.08s linear;
  pointer-events: none;
  filter: drop-shadow(0 0 1px rgba(0,0,0,0.25));
}
#overlay > svg, #overlay > img {
  width: 100%; height: 100%; display: block; object-fit: contain;
}

/* Ecrans plein (start / erreur) */
.screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 0%, #2a2f4a 0%, #11131a 70%);
  padding: 24px;
}
.start-card { text-align: center; max-width: 420px; }
.logo { font-size: 2.4rem; font-weight: 800; letter-spacing: 1px; margin-bottom: 10px; }
.tagline { font-size: 1.05rem; line-height: 1.5; opacity: 0.92; margin: 0 0 24px; }
.hint { font-size: 0.85rem; opacity: 0.65; margin-top: 16px; min-height: 1.2em; }

.big-btn {
  font-size: 1.25rem; font-weight: 700; color: var(--text);
  background: var(--btn); border: none; border-radius: var(--radius);
  padding: 18px 28px; min-height: 60px; cursor: pointer;
}
.big-btn.primary { background: var(--brand); }
.big-btn:active { transform: scale(0.97); }

.tip { display: block; margin-top: 12px; font-size: 0.88rem; opacity: 0.7; }

#maintForm { display: flex; flex-direction: column; gap: 12px; align-items: stretch; max-width: 320px; margin: 0 auto; }
.pass-input {
  font-size: 1.15rem; text-align: center; color: var(--text);
  background: var(--btn); border: 2px solid transparent; border-radius: var(--radius);
  padding: 16px; min-height: 56px; outline: none;
}
.pass-input:focus { border-color: var(--brand); }
.pass-input::placeholder { color: rgba(255,255,255,0.5); }
#photoBtn[data-mode="contour"] { background: var(--brand); }

/* Barre du haut */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(env(safe-area-inset-top), 10px) 14px 10px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.45), transparent);
}
.brand { font-weight: 800; letter-spacing: 1px; font-size: 1.05rem; text-shadow: 0 1px 3px rgba(0,0,0,0.6); }
.top-actions { display: flex; gap: 10px; }

.icon-btn {
  font-size: 1.4rem; width: 52px; height: 52px; line-height: 1;
  border: none; border-radius: 50%; background: var(--panel);
  color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.icon-btn:active { transform: scale(0.92); }

/* Controles du bas */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 14px max(env(safe-area-inset-bottom), 14px);
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
  display: flex; flex-direction: column; gap: 12px;
}
.opacity-row { display: flex; align-items: center; gap: 12px; }
.op-label { font-size: 0.9rem; opacity: 0.9; min-width: 96px; }
#opacity { flex: 1; height: 36px; accent-color: var(--brand); }

/* Mode etape par etape */
.step-bar { display: flex; align-items: center; gap: 10px; }
.step-bar .ctrl-btn { flex: 1; }
.step-count {
  flex: 0 0 auto; min-width: 88px; text-align: center;
  font-size: 1.2rem; font-weight: 800; text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
#stepBtn[data-on="true"] { background: var(--brand); }
.icon-btn:disabled, .ctrl-btn:disabled { opacity: 0.35; pointer-events: none; }

.btn-row { display: flex; gap: 8px; justify-content: space-between; }
.ctrl-btn {
  flex: 1; font-size: 1.5rem; height: 58px; line-height: 1;
  border: none; border-radius: 14px; background: var(--btn);
  color: var(--text); cursor: pointer;
}
.ctrl-btn:active { transform: scale(0.94); background: var(--btn-active); }
#lock[data-locked="true"] { background: var(--brand); }

/* Tiroir bibliotheque */
.drawer {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10, 11, 16, 0.96);
  display: flex; flex-direction: column;
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(env(safe-area-inset-top), 14px) 16px 12px;
  font-size: 1.15rem; font-weight: 700;
}
.grid {
  flex: 1; overflow-y: auto; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px; padding: 12px 16px 28px;
}
.model-card {
  background: #fff; border-radius: 16px; aspect-ratio: 1;
  display: grid; place-items: center; padding: 10px; cursor: pointer;
  border: 3px solid transparent;
}
.model-card:active { border-color: var(--brand); transform: scale(0.96); }
.model-card img { width: 100%; height: 100%; object-fit: contain; }
.model-card span { display: none; }

.hidden { display: none !important; }

/* Paysage : controles plus compacts */
@media (orientation: landscape) and (max-height: 480px) {
  #overlay { width: 70vmin; height: 70vmin; }
  .ctrl-btn { height: 48px; font-size: 1.3rem; }
}
