@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&display=swap');

:root {
  --bg1: #2b1d6b; --bg2: #13104a; --ink: #fff; --muted: #b9b3e6;
  --yellow: #ffd84d; --pink: #ff5c8a; --green: #5be37a; --c: #8a5cff;
  font-family: 'Baloo 2', 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink);
  background: radial-gradient(circle at 20% 10%, #4a2fa8 0, transparent 45%), radial-gradient(circle at 90% 90%, #7a1f6f 0, transparent 40%), linear-gradient(160deg, var(--bg1), var(--bg2));
  user-select: none; -webkit-user-select: none; touch-action: manipulation; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom)); }
.screen.active { display: flex; }

button.ghost, a.btn { background: rgba(255,255,255,.12); padding: 10px 16px; border-radius: 14px; text-decoration: none; color: #fff; display: inline-block; }
button.small { padding: 6px 12px; }
button.big { background: var(--yellow); color: #3a2400; font-size: 1.6rem; font-weight: 800; padding: 14px 40px; border-radius: 999px; box-shadow: 0 6px 0 #c79a00; }
button.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #c79a00; }
button.danger { background: #b4234a; padding: 10px 16px; border-radius: 12px; }

/* ---------- accueil ---------- */
.home-head { text-align: center; margin-top: 2vh; }
.home-head h1 { font-size: clamp(2.4rem, 7vw, 4.2rem); margin: 0; line-height: 1; letter-spacing: 1px; text-shadow: 0 4px 0 rgba(0,0,0,.25); }
.home-head h1 span { color: var(--yellow); }
.tagline { color: var(--muted); font-size: 1.2rem; margin: 6px 0 0; }
.profiles { flex: 1; display: flex; gap: 20px; justify-content: center; align-items: center; flex-wrap: wrap; padding: 16px 0; overflow: auto; }
.profile { background: linear-gradient(180deg, color-mix(in srgb, var(--c) 85%, #fff 15%), color-mix(in srgb, var(--c) 70%, #000 30%));
  border-radius: 32px; padding: 18px 18px 14px; width: min(330px, 44vw); min-width: 260px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 10px 0 color-mix(in srgb, var(--c) 50%, #000 50%), 0 18px 40px rgba(0,0,0,.35); transition: transform .12s; }
.profile:active { transform: translateY(6px); box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 50%, #000 50%); }
.p-avatar { font-size: 4.6rem; line-height: 1; filter: drop-shadow(0 4px 0 rgba(0,0,0,.2)); animation: bob 2.4s ease-in-out infinite; }
.p-name { font-size: 1.8rem; font-weight: 800; }
.p-stats { display: flex; gap: 16px; font-size: 1.3rem; font-weight: 700; }
.p-badge { background: rgba(0,0,0,.22); border-radius: 999px; padding: 2px 12px; font-size: .95rem; }
.p-badge.muted { opacity: .75; }
.p-next { width: 80%; height: 8px; background: rgba(0,0,0,.25); border-radius: 9px; overflow: hidden; }
.p-next div { height: 100%; background: var(--yellow); border-radius: 9px; }
.p-week { display: flex; gap: 4px; margin-top: 4px; }
.p-week .d { display: flex; flex-direction: column; align-items: center; background: rgba(0,0,0,.18); border-radius: 10px; padding: 2px 4px; font-size: .85rem; }
.p-week .d.today { outline: 2px solid var(--yellow); }
.p-week i { font-style: normal; opacity: .8; }
.p-week b { filter: grayscale(1); opacity: .3; font-size: .9rem; line-height: 1.2; }
.p-week b.on { filter: none; opacity: 1; }
.p-go { margin-top: 6px; background: var(--yellow); color: #3a2400; font-weight: 800; font-size: 1.4rem; padding: 6px 26px; border-radius: 999px; }
.home-foot { display: flex; justify-content: flex-end; }
#btn-parent { opacity: .7; position: relative; overflow: hidden; }
#btn-parent small { font-size: .8rem; }
#btn-parent.pressing::after { content: ''; position: absolute; left: 0; bottom: 0; height: 4px; background: var(--yellow); animation: fill 1.5s linear forwards; }
@keyframes fill { from { width: 0 } to { width: 100% } }

/* ---------- préparation ---------- */
.ready-wrap { flex: 1; display: flex; align-items: center; justify-content: center; gap: 28px; flex-wrap: wrap; }
.ready-cam { position: relative; width: min(560px, 90vw); border-radius: 28px; overflow: hidden; background: #000; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.ready-cam canvas, .cam-box canvas, .test-wrap canvas { width: 100%; display: block; }
.cam-badge { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: rgba(0,0,0,.6); padding: 4px 14px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.cam-badge.ok { background: var(--green); color: #053; }
.ready-text { max-width: 420px; text-align: center; }
.ready-text h2 { font-size: 2.4rem; margin: 0; }
.ready-text p { font-size: 1.3rem; color: var(--muted); }
.big-count { font-size: 5rem; font-weight: 800; color: var(--yellow); min-height: 6rem; }
.row { display: flex; gap: 12px; justify-content: center; }

/* ---------- jeu ---------- */
.hud { display: flex; align-items: center; gap: 14px; }
.hud-player { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 1.3rem; }
#hud-avatar { font-size: 2rem; }
.hud-progress { flex: 1; position: relative; height: 34px; background: rgba(0,0,0,.3); border-radius: 999px; overflow: hidden; }
#hud-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--yellow)); border-radius: 999px; transition: width .2s; }
#hud-time { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.15rem; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.game-area { flex: 1; display: flex; gap: 14px; min-height: 0; padding-top: 10px; }
.mouth-wrap { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; }
.mouth-svg { width: 100%; height: 100%; max-height: 100%; overflow: visible; }
.side { width: min(30vw, 300px); display: flex; flex-direction: column; gap: 12px; }
.cam-box { position: relative; border-radius: 20px; overflow: hidden; background: #000; border: 4px solid var(--c); }
.hint { background: rgba(255,255,255,.12); border-radius: 18px; padding: 12px; font-size: 1.35rem; font-weight: 800; text-align: center; line-height: 1.2; }
.killed { text-align: center; font-size: 1.4rem; font-weight: 800; }
@media (orientation: portrait) {
  .game-area { flex-direction: column; }
  .side { width: 100%; flex-direction: row; align-items: center; }
  .cam-box { width: 38%; }
  .hint { flex: 1; }
  .killed { display: none; }
}

/* zones */
.zone-hl, .zone-next { fill: none; stroke-width: 6; opacity: 0; }
.zone.active .zone-hl { opacity: 1; stroke: var(--yellow); fill: rgba(255,216,77,.12); filter: url(#glow); }
.zone.next .zone-next { opacity: 1; stroke: #fff; stroke-dasharray: 14 10; animation: dash 1s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -48; } }
.dirt { transition: opacity .3s; }
.sparkle { opacity: 0; }
.zone.clean .sparkle { opacity: 1; animation: twinkle 1.2s ease-in-out infinite; }
.monster { transition: opacity .2s; }
.monster-inner { transform-box: fill-box; transform-origin: center; transition: transform .25s; }
.monster-body { transform-box: fill-box; transform-origin: center; animation: wobble 1.6s ease-in-out infinite; }
.zone.scrubbing .monster-body { animation: shake .18s linear infinite; }
.monster.dead { opacity: 0; transition: opacity .35s .15s; }
.monster.popping .monster-inner { transform: scale(1.6) !important; }
.brush-icon { transition: transform .25s ease-out, opacity .2s; }
.brush-icon.wiggle text { animation: wiggle .2s linear infinite; transform-box: fill-box; transform-origin: center; }
.particle { animation: burst .7s ease-out forwards; transform-box: fill-box; }
.pow { fill: var(--yellow); font-weight: 800; stroke: #6b2a00; stroke-width: 2; paint-order: stroke; animation: pow .9s ease-out forwards; transform-box: fill-box; transform-origin: center; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
@keyframes pow { 0% { transform: scale(.3); opacity: 0 } 25% { transform: scale(1.2); opacity: 1 } 100% { transform: translateY(-40px) scale(1); opacity: 0 } }
@keyframes wobble { 0%,100% { transform: rotate(-6deg) } 50% { transform: rotate(6deg) scale(1.05) } }
@keyframes shake { 0% { transform: translate(-3px, 0) rotate(-8deg) } 50% { transform: translate(3px, 1px) rotate(8deg) } 100% { transform: translate(-3px, 0) rotate(-8deg) } }
@keyframes wiggle { 0%,100% { transform: translateX(-6px) rotate(-10deg) } 50% { transform: translateX(6px) rotate(10deg) } }
@keyframes twinkle { 0%,100% { transform: scale(1) } 50% { transform: scale(1.25) } }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }

/* ---------- victoire ---------- */
#screen-win { align-items: center; justify-content: center; }
.win-card { background: rgba(255,255,255,.1); border-radius: 36px; padding: 28px 40px; text-align: center; max-width: 560px; z-index: 2; }
.win-card h2 { font-size: 2.6rem; margin: 0; }
.win-stars { font-size: 4.5rem; display: flex; justify-content: center; gap: 10px; margin: 10px 0; }
.star { filter: grayscale(1) brightness(.5); transform: scale(.6); }
.star.on { animation: starIn .5s cubic-bezier(.2, 2, .4, 1) forwards; }
@keyframes starIn { to { filter: none; transform: scale(1); } }
.win-card p { font-size: 1.35rem; }
.win-badge { background: rgba(0,0,0,.25); border-radius: 22px; padding: 10px; margin: 0 auto 18px; font-size: 1.3rem; font-weight: 800; }
.win-badge .nb { color: var(--yellow); }
.win-badge .bi { font-size: 3rem; animation: bob 1.5s infinite; }
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#confetti span { position: absolute; top: -10%; animation: fall 3s linear forwards; }
@keyframes fall { to { transform: translateY(120vh) rotate(540deg); } }

/* ---------- parents ---------- */
#screen-parent { background: rgba(10, 8, 40, .96); overflow: auto; }
.panel { max-width: 980px; width: 100%; margin: 0 auto; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 16px; }
.tab { background: rgba(255,255,255,.08); padding: 8px 14px; border-radius: 12px; }
.tab.active { background: var(--yellow); color: #3a2400; font-weight: 800; }
.tab-body { display: none; flex-direction: column; gap: 14px; }
.tab-body.active { display: flex; }
.tab-body label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; }
.tab-body label.check { flex-direction: row; align-items: center; gap: 10px; }
.tab-body input[type=range] { width: 100%; accent-color: var(--yellow); }
.tab-body input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--yellow); }
.tab-body select, .pp-name { font: inherit; padding: 8px; border-radius: 10px; border: 0; background: rgba(255,255,255,.12); color: #fff; }
.tab-body select option { color: #000; }
output { color: var(--yellow); }
.note { color: var(--muted); font-size: .9rem; }
.pp { background: rgba(255,255,255,.06); border-left: 6px solid var(--c); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.pp-name { font-size: 1.3rem; font-weight: 800; }
.pp-avatars, .pp-colors { display: flex; flex-wrap: wrap; gap: 6px; }
.av { font-size: 1.8rem; background: rgba(255,255,255,.06); border-radius: 12px; padding: 2px 6px; }
.av.sel { background: var(--yellow); }
.co { width: 34px; height: 34px; border-radius: 50%; }
.co.sel { outline: 3px solid #fff; outline-offset: 2px; }
.pp-stats { color: var(--muted); font-size: .95rem; }
.pp-del { align-self: flex-start; }
.test-wrap { display: flex; gap: 16px; flex-wrap: wrap; }
.test-wrap canvas { flex: 1 1 420px; max-width: 640px; border-radius: 16px; background: #000; min-height: 200px; }
.test-info { flex: 1 1 280px; display: flex; flex-direction: column; gap: 10px; }
.test-zone { font-size: 2rem; font-weight: 800; background: rgba(255,255,255,.08); border-radius: 14px; padding: 8px 14px; text-align: center; }
.test-zone.ok { background: var(--green); color: #053; }
#test-data { background: rgba(0,0,0,.35); padding: 10px; border-radius: 12px; font-size: .85rem; white-space: pre-wrap; margin: 0; }
#btn-test-calib { background: var(--yellow); color: #3a2400; font-weight: 800; padding: 10px; border-radius: 12px; }
.mini-mouth { max-width: 320px; }
@media (max-width: 520px) { #hud-name { display: none; } .hint { font-size: 1.1rem; } }

/* vue fer à cheval */
.horseshoe .zone-hl, .horseshoe .zone-next { fill: none; stroke-width: 92; stroke-linecap: round; opacity: 0; filter: none; }
.horseshoe .zone.active .zone-hl { opacity: 1; stroke: #ffe066; stroke-opacity: .6; fill: none; filter: none; }
.horseshoe .zone.next .zone-next { opacity: 1; stroke: rgba(255, 255, 255, .28); stroke-dasharray: none; animation: pulseBand 1.1s ease-in-out infinite; }
@keyframes pulseBand { 0%,100% { stroke-opacity: .25 } 50% { stroke-opacity: .7 } }
.arch-label { fill: rgba(255,255,255,.55); font-size: 22px; font-weight: 800; letter-spacing: 3px; }
