:root {
  --bg: #0b0c16;
  --panel: rgba(22, 24, 40, 0.72);
  --panel-2: rgba(40, 44, 70, 0.8);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f5fb;
  --muted: #a3a8c3;
  --red: #ff3b5c;
  --orange: #ff8a1f;
  --yellow: #ffd60a;
  --green: #2fd36b;
  --blue: #2f7bff;
  --white: #f5f5f0;
  --accent: #7b5cff;
  --grad: linear-gradient(120deg, #ff3b5c 0%, #ff8a1f 25%, #ffd60a 45%, #2fd36b 65%, #2f7bff 85%, #7b5cff 100%);
  --cta: linear-gradient(120deg, #7b5cff, #2f7bff 55%, #2fd3c8);
  --ok: #2fd36b;
  --warn: #ffb020;
  --err: #ff5470;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
html, body { margin: 0; height: 100%; color: var(--text); overflow: hidden; }
body { font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; overscroll-behavior: none; }
h1, h2 { margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1.3rem; font-weight: 700; }
p { line-height: 1.45; margin: 0; }
.small { font-size: 0.88rem; color: var(--muted); }

/* Fond animé : taches de couleur floues aux couleurs du cube. */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: radial-gradient(ellipse at 50% 0%, #1a1740 0%, var(--bg) 60%); }
.bg i { position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%; filter: blur(70px); opacity: 0.35; animation: float 18s ease-in-out infinite alternate; }
.bg i:nth-child(1) { background: var(--red); left: -20vmax; top: -15vmax; }
.bg i:nth-child(2) { background: var(--blue); right: -25vmax; top: 10vmax; animation-delay: -6s; }
.bg i:nth-child(3) { background: var(--green); left: -10vmax; bottom: -30vmax; animation-delay: -12s; opacity: 0.25; }
.bg i:nth-child(4) { background: var(--accent); right: -15vmax; bottom: -25vmax; animation-delay: -3s; opacity: 0.3; }
@keyframes float { to { transform: translate(8vmax, 6vmax) scale(1.15); } }

/* Couches : caméra < scène 3D < écrans */
#camera-layer { position: fixed; inset: 0; z-index: 0; background: #000; opacity: 0; visibility: hidden; transition: opacity 0.6s, visibility 0.6s; }
#camera-layer.on { opacity: 1; visibility: visible; }
#camera-layer video, #camera-layer canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }

.screen {
  position: fixed; inset: 0; z-index: 2; display: flex; flex-direction: column;
  padding: calc(14px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  opacity: 0; visibility: hidden; transform: translateY(14px); pointer-events: none;
  transition: opacity 0.5s, transform 0.5s, visibility 0.5s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; }
.screen.active > * { pointer-events: auto; }
.anchor { pointer-events: auto; }

/* Boutons */
button { font: inherit; color: inherit; border: 0; border-radius: var(--radius); padding: 0.85em 1.2em; cursor: pointer; background: var(--panel-2); transition: transform 0.12s, opacity 0.2s, box-shadow 0.2s; }
button:active { transform: scale(0.96); }
button:disabled { opacity: 0.4; }
.cta {
  background: var(--cta); color: white; font-weight: 700; font-size: 1.08rem; padding: 1em 1.4em;
  box-shadow: 0 10px 30px -8px rgba(123, 92, 255, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  position: relative; overflow: hidden;
}
.cta::after { content: ''; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,0.35) 50%, transparent 70%); transform: translateX(-100%); animation: shine 3.5s infinite; }
@keyframes shine { 60%, 100% { transform: translateX(100%); } }
.cta-icon { margin-right: 6px; }
.ghost { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); }
.glass { background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); }
button.icon { width: 44px; height: 44px; padding: 0; border-radius: 50%; display: grid; place-items: center; font-size: 1.1rem; flex: none; }
.small-btn { font-size: 0.85rem; padding: 0.6em 0.95em; border-radius: 14px; }

/* Accueil */
#home { align-items: center; justify-content: space-between; text-align: center; }
.pill { font-size: 0.82rem; padding: 6px 14px; border-radius: 999px; background: rgba(255,255,255,0.07); border: 1px solid var(--line); color: var(--muted); }
.hero-anchor { width: min(78vw, 340px); aspect-ratio: 1; flex: 1 1 auto; max-height: 40vh; }
.title { font-size: clamp(2.3rem, 10vw, 3.4rem); font-weight: 800; line-height: 1; }
.rainbow { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; background-size: 200% 100%; animation: hue 6s linear infinite; }
@keyframes hue { to { background-position: 200% 0; } }
.tagline { color: var(--muted); margin-top: 10px; font-size: 1.02rem; }
.home-actions { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.home-actions .cta { width: 100%; }
/* Choix du cube */
.puzzles { display: flex; gap: 6px; padding: 5px; border-radius: 999px; background: rgba(255,255,255,0.06); border: 1px solid var(--line); }
.puzzles button { flex: 1; padding: 9px 0; border-radius: 999px; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 700; font-size: 0.98rem; cursor: pointer; transition: background .25s, color .25s, transform .2s; }
.puzzles button.on { background: var(--grad); color: #111; transform: scale(1.03); }
.how { display: flex; justify-content: center; gap: 18px; font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.how b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; margin-right: 6px; background: var(--grad); color: #111; font-size: 0.75rem; }

/* Scan */
#scan { padding: 0; }
.scan-top { position: absolute; top: 0; left: 0; right: 0; padding: calc(12px + var(--safe-top)) 12px 10px; display: flex; align-items: center; gap: 10px; }
.steps { flex: 1; display: flex; justify-content: center; gap: 6px; padding-right: 150px; }
.step { --n: 3; width: 30px; height: 30px; border-radius: 8px; border: 2px solid rgba(255,255,255,0.35); display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr); gap: 1px; padding: 2px; background: rgba(0,0,0,0.35); }
.step.current { border-color: white; box-shadow: 0 0 0 3px rgba(123,92,255,0.7); }
.step span { border-radius: 1.5px; }
.instruction { position: absolute; top: calc(66px + var(--safe-top)); left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; }
.instr-text { flex: 1; border-radius: var(--radius); padding: 10px 14px; }
.guide { width: 86px; height: 86px; flex: none; }
.instr-main { font-size: 1.12rem; font-weight: 700; line-height: 1.25; }
.instr-sub { font-size: 0.9rem; color: var(--muted); margin-top: 4px; line-height: 1.3; }
.chip { display: inline-block; padding: 0 0.45em; border-radius: 7px; color: #111; font-weight: 700; }
.mini-backdrop { position: absolute; top: calc(12px + var(--safe-top)); right: 12px; width: 138px; height: 168px; border-radius: 22px; background: rgba(14, 16, 32, 0.55); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); transition: opacity 0.4s; }
#camera-layer.guided .mini-backdrop { opacity: 0; }
.mini { height: 168px; position: absolute; top: calc(12px + var(--safe-top)); right: 12px; width: 138px; border-radius: 22px; padding: 6px 10px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; transition: opacity 0.5s; }
.mini-cube { width: 118px; height: 118px; }
.mini-progress { width: 100%; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
#mini-bar { height: 100%; width: 0; background: var(--grad); transition: width 0.3s; }
.mini-count { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { position: absolute; left: 50%; bottom: calc(86px + var(--safe-bottom)); transform: translateX(-50%); padding: 12px 20px; border-radius: 20px; font-size: 1.05rem; font-weight: 600; text-align: center; width: max-content; max-width: 90vw; transition: opacity 0.3s; }
.hint:empty { display: none; }
.hint.pop { animation: hintpop 0.35s ease-out; }
@keyframes hintpop { from { transform: translateX(-50%) scale(0.92); opacity: 0.4; } }
.hint-icon { display: inline-block; font-size: 1.3em; color: var(--yellow); }
.i-0 { animation: spinl 1.6s ease-in-out infinite; }
.i-1 { animation: spinr 1.6s ease-in-out infinite; }
.i-2, .i-3 { animation: bob 1.2s ease-in-out infinite; }
.i-4 { animation: spinl 2.2s linear infinite; }
@keyframes spinl { 50% { transform: rotate(-200deg); } }
@keyframes spinr { 50% { transform: rotate(200deg); } }
@keyframes bob { 50% { transform: translateY(-5px); } }
.stability { position: absolute; left: 22%; right: 22%; bottom: calc(76px + var(--safe-bottom)); height: 5px; border-radius: 3px; background: rgba(255,255,255,0.15); overflow: hidden; }
#stability-bar { height: 100%; width: 0; background: var(--ok); transition: width 0.12s linear; }
.scan-bottom { position: absolute; bottom: 0; left: 0; right: 0; padding: 12px 12px calc(16px + var(--safe-bottom)); display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.flash { position: absolute; inset: 0; background: white; opacity: 0; pointer-events: none; transition: opacity 0.35s; }
.flash.on { opacity: 0.55; transition: none; }
.scan-error { position: absolute; inset: 0; background: var(--bg); padding: 40px 24px; display: flex; flex-direction: column; justify-content: center; gap: 16px; text-align: center; }
#scan.free .guided-only, #scan:not(.free) .free-only { display: none !important; }
.done-banner { position: absolute; left: 0; right: 0; top: calc(14% + var(--safe-top)); text-align: center; font-size: 2rem; font-weight: 800; opacity: 0; transform: translateY(16px) scale(0.95); transition: all 0.6s 0.2s; pointer-events: none; }
.done-banner span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
#scan.complete .mini, #scan.complete .hint, #scan.complete .scan-bottom, #scan.complete .scan-top { opacity: 0; pointer-events: none; transition: opacity 0.4s; }
#scan.complete .done-banner { opacity: 1; transform: none; }

/* Vérification */
#review { gap: 10px; max-width: 640px; margin: 0 auto; }
.bar { display: flex; align-items: center; gap: 12px; min-height: 56px; }
#solve-sub { color: var(--muted); font-size: 0.85rem; }
.net-anchor { flex: 1 1 auto; min-height: 220px; width: 100%; cursor: pointer; }
.palette { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.palette button { width: 46px; height: 46px; border-radius: 50%; padding: 0; border: 3px solid rgba(255,255,255,0.15); box-shadow: 0 4px 14px -4px rgba(0,0,0,0.6); }
.palette button.on { border-color: white; transform: scale(1.12); }
.palette.disabled button { opacity: 0.55; transform: scale(0.88); }
.msg { min-height: 2.6em; font-size: 0.95rem; text-align: center; display: grid; place-items: center; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Solution */
#solve { gap: 10px; max-width: 680px; margin: 0 auto; }
.viewer { flex: 1 1 auto; min-height: 220px; }
.move-card { display: flex; align-items: center; gap: 14px; justify-content: center; border-radius: var(--radius); padding: 10px 16px; min-height: 64px; }
.move-big { font-size: 2.4rem; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: center; }
.move-desc { color: var(--muted); }
.moves { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-height: 96px; overflow-y: auto; }
.moves span { padding: 5px 10px; border-radius: 10px; background: rgba(255,255,255,0.07); font-weight: 700; font-size: 0.95rem; cursor: pointer; border-bottom: 3px solid var(--c, transparent); transition: all 0.25s; }
.moves span.done { opacity: 0.35; }
.moves span.now { background: var(--cta); color: white; transform: scale(1.1); }
.controls { display: flex; justify-content: center; gap: 12px; align-items: center; }
.controls .play { background: var(--cta); width: 62px; height: 62px; font-size: 1.3rem; box-shadow: 0 10px 30px -8px rgba(123, 92, 255, 0.8); }
.solve-foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.speed { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.85rem; }
.notation { color: var(--muted); font-size: 0.85rem; max-width: 60%; text-align: right; }
.notation summary { cursor: pointer; }
.notation p { text-align: left; margin-top: 6px; }
.celebrate { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 18px; padding: 0 24px calc(40px + var(--safe-bottom)); pointer-events: none; }
.celebrate > * { pointer-events: auto; }
.celebrate-text { font-size: 2.6rem; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; animation: pop 0.6s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }
#solve.celebrating > :not(.celebrate):not(.viewer) { opacity: 0; pointer-events: none; transition: opacity 0.4s; }

@media (min-width: 760px) {
  .instruction { left: 50%; right: auto; transform: translateX(-50%); width: 560px; }
}

/* Calques décoratifs : ne bloquent jamais les appuis. */
.screen.active > .flash, .screen.active > .done-banner, .screen.active > .celebrate { pointer-events: none; }
.screen.active > .celebrate > * { pointer-events: auto; }

/* Pastilles : à gauche en mode libre (le mini-cube occupe la droite). */
#scan.free .steps { justify-content: flex-start; padding-right: 150px; gap: 5px; }
#scan:not(.free) .steps { padding-right: 0; }
#scan.free .step { width: 26px; height: 26px; border-radius: 7px; }
.step.done { border-color: var(--ok); }

/* Lampe : mise en avant quand l'image est sombre. */
#torch.suggest { animation: glow 1.2s ease-in-out infinite; }
#torch.on { background: var(--yellow); color: #111; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px rgba(255, 214, 10, 0.45); } }

/* Batterie : les animations décoratives ne tournent que sur l'accueil ; sous
   la caméra, le fond est masqué et les panneaux ne floutent plus la vidéo
   (un flou recalculé 30 fois par seconde coûte cher). */
body:not([data-screen="home"]) .bg i,
body:not([data-screen="home"]) .rainbow,
body:not([data-screen="home"]) .cta::after { animation-play-state: paused; }
body[data-screen="scan"] .bg { display: none; }
#scan .glass, .mini-backdrop { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(14, 16, 32, 0.78); }
@media (prefers-reduced-motion: reduce) {
  .bg i, .rainbow, .cta::after { animation: none; }
}
