:root {
  --bg1: #6d5cff; --bg2: #2bb7ff;
  --ink: #1f1d3a; --muted: #6b6a85; --card: #fff;
  --ok: #22c55e; --bad: #ef4444; --warn: #f59e0b;
  --accent: #ff7a3d;
  --c0: #e6e6f0; --c1: #f87171; --c2: #fb923c; --c3: #facc15; --c4: #86efac; --c5: #22c55e;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif;
}
body.melvil { --bg1: #ff8a3d; --bg2: #ffcc33; --accent: #ff5e3a; }
body.raphael { --bg1: #4f6bff; --bg2: #38d1c6; --accent: #4f6bff; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; }
.screen {
  display: none; flex-direction: column; align-items: center; gap: 14px;
  padding: calc(env(safe-area-inset-top) + 16px) 18px calc(env(safe-area-inset-bottom) + 18px);
  min-height: 100dvh; position: relative;
}
.screen.on { display: flex; animation: pop .25s ease-out; }
@keyframes pop { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }

h1, h2 { margin: 0; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.15); text-align: center; }
.logo { font-size: 44px; line-height: 1; margin-top: 6vh; letter-spacing: -1px; }
.logo span { color: #fff6a8; }
.spark { display: inline-block; animation: wiggle 2s infinite; }
@keyframes wiggle { 50% { transform: rotate(20deg) scale(1.2); } }
.sub { color: #fff; opacity: .95; font-size: 19px; margin: 0; text-align: center; font-weight: 600; }
.sub.small { font-size: 15px; }

.who { display: flex; gap: 16px; width: 100%; margin-top: 4vh; }
.kid {
  flex: 1; background: #fff; border-radius: 28px; padding: 22px 8px 18px; font-size: 24px; font-weight: 800;
  display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: 0 8px 0 rgba(0,0,0,.15);
  transition: transform .1s;
}
.kid:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.kid .ava { font-size: 72px; }
.kid-melvil { color: #e8590c; } .kid-raphael { color: #3b5bdb; }
.link { background: none; color: #fff; text-decoration: underline; font-size: 15px; opacity: .9; margin-top: auto; padding: 10px; }

.back {
  position: absolute; left: 14px; top: calc(env(safe-area-inset-top) + 12px);
  width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.3); color: #fff; font-size: 22px; font-weight: 800;
}
.topbar { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 44px; }
.topbar .back { position: static; flex: none; }
.topbar h2 { flex: 1; font-size: 24px; }
.stars-total { margin-left: auto; background: rgba(255,255,255,.3); color: #fff; padding: 8px 14px; border-radius: 99px; font-size: 18px; }

.pin-ava { font-size: 80px; margin-top: 7vh; }
.dots { display: flex; gap: 16px; margin: 6px 0; }
.dots i { width: 20px; height: 20px; border-radius: 50%; background: rgba(255,255,255,.35); display: block; transition: .15s; }
.dots i.f { background: #fff; transform: scale(1.15); }
.dots.shake, .card.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.err { color: #fff; background: rgba(239,68,68,.85); border-radius: 12px; padding: 0 12px; min-height: 0; margin: 0; font-weight: 700; }
.err:empty { display: none; }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 360px; }
.pad button {
  height: 62px; border-radius: 18px; background: #fff; font-size: 30px; font-weight: 800;
  box-shadow: 0 5px 0 rgba(0,0,0,.14); transition: transform .06s;
}
.pad button:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.14); }
.pad .k-ok { background: var(--ok); color: #fff; }
.pad .k-del { background: #ffe4e4; color: var(--bad); }

.hello { font-size: 30px; margin-top: 2px; }
.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; width: 100%; }
.chip {
  aspect-ratio: 1; border-radius: 20px; background: rgba(255,255,255,.35); color: #fff; font-size: 28px; font-weight: 900;
  position: relative; box-shadow: 0 4px 0 rgba(0,0,0,.1); transition: .12s;
}
.chip.on { background: #fff; color: var(--accent); transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,.15); }
.chip .badge { position: absolute; top: -8px; right: -6px; font-size: 20px; }
.chip .bar { position: absolute; left: 10%; right: 10%; bottom: 7px; height: 5px; border-radius: 3px; background: rgba(0,0,0,.12); overflow: hidden; }
.chip .bar i { display: block; height: 100%; background: var(--ok); }
.row-btns { display: flex; gap: 10px; }
.pill { background: rgba(255,255,255,.3); color: #fff; border-radius: 99px; padding: 10px 18px; font-size: 16px; font-weight: 700; }
.opts { display: flex; flex-direction: column; gap: 10px; align-items: center; width: 100%; }
.seg { display: flex; background: rgba(255,255,255,.25); border-radius: 99px; padding: 4px; }
.seg button { background: none; color: #fff; padding: 9px 16px; border-radius: 99px; font-size: 16px; font-weight: 700; }
.seg button.on { background: #fff; color: var(--accent); }
.toggle { background: rgba(255,255,255,.25); color: #fff; border-radius: 99px; padding: 11px 18px; font-size: 16px; font-weight: 700; }
.toggle.on { background: #fff; color: var(--accent); }
.go {
  width: 100%; max-width: 360px; background: var(--ink); color: #fff; font-size: 24px; font-weight: 900;
  padding: 18px; border-radius: 22px; box-shadow: 0 6px 0 rgba(0,0,0,.25);
}
.go:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.25); }
.go:disabled { opacity: .5; }

.mini-wrap { width: 100%; background: rgba(255,255,255,.18); border-radius: 22px; padding: 12px; margin-top: 6px; }
.grid { display: grid; grid-template-columns: repeat(11, 1fr); gap: 3px; width: 100%; }
.grid div { aspect-ratio: 1; border-radius: 4px; background: var(--c0); font-size: 10px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: rgba(0,0,0,.55); }
.grid .h { background: none; color: #fff; font-size: 12px; }
.grid .b0 { background: var(--c1); } .grid .b1 { background: var(--c2); }
.grid .b2, .grid .b3 { background: var(--c3); } .grid .b4 { background: var(--c4); } .grid .b5 { background: var(--c5); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; color: #fff; font-size: 12px; margin-top: 8px; align-items: center; }
.legend span { width: 12px; height: 12px; border-radius: 3px; display: inline-block; margin-right: -6px; }
.l0 { background: var(--c0); } .l1 { background: var(--c1); } .l2 { background: var(--c2); } .l3 { background: var(--c3); } .l5 { background: var(--c5); }

.progress { flex: 1; height: 14px; background: rgba(255,255,255,.3); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: #fff; border-radius: 99px; transition: width .3s; }
.streak { color: #fff; font-weight: 900; font-size: 20px; min-width: 60px; text-align: right; }
.streak.hot { animation: pulse .5s; }
@keyframes pulse { 50% { transform: scale(1.4); } }

.card-zone { width: 100%; perspective: 800px; margin-top: 4px; }
.card {
  background: #fff; border-radius: 30px; padding: 22px 16px 16px; text-align: center;
  box-shadow: 0 10px 0 rgba(0,0,0,.15); transition: background .2s;
}
.card.enter { animation: flip .35s ease-out; }
@keyframes flip { from { transform: rotateY(80deg) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.card .q { font-size: 64px; font-weight: 900; letter-spacing: 2px; }
.card .ans {
  font-size: 54px; font-weight: 900; color: var(--accent); min-height: 70px;
  border-bottom: 4px dashed #e2e2ee; margin: 0 auto; width: 60%;
}
.card .fb { min-height: 34px; font-size: 22px; font-weight: 800; margin-top: 8px; }
.card.ok { background: #dcfce7; } .card.ok .ans { color: var(--ok); border-color: transparent; }
.card.bad { background: #fee2e2; } .card.bad .ans { color: var(--bad); text-decoration: line-through; border-color: transparent; }
.card .fb .correct { display: block; font-size: 36px; color: var(--ink); margin-top: 4px; }

.mic-row { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.mic {
  width: 64px; height: 64px; border-radius: 50%; background: #fff; font-size: 30px;
  box-shadow: 0 5px 0 rgba(0,0,0,.14); position: relative;
}
.mic.listening { background: var(--bad); }
.mic.listening::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 4px solid #fff;
  animation: ring 1s infinite;
}
.mic.speaking::after { border-color: #fff6a8; animation-duration: .4s; }
.mic.busy { background: var(--warn); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ring { from { transform: scale(.9); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }
.mic-status { color: #fff; font-weight: 700; font-size: 16px; max-width: 220px; }

.trophy { font-size: 100px; margin-top: 5vh; animation: bounce 1s ease-in-out infinite; }
@keyframes bounce { 50% { transform: translateY(-14px) rotate(-6deg); } }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.end-stats { display: flex; gap: 10px; width: 100%; }
.end-stats div { flex: 1; background: #fff; border-radius: 20px; padding: 12px 4px; text-align: center; }
.end-stats b { display: block; font-size: 32px; color: var(--accent); }
.end-stats span { font-size: 13px; color: var(--muted); font-weight: 700; }
#end-badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.badge-new { background: #fff6a8; border-radius: 16px; padding: 10px 16px; font-weight: 800; animation: pop .5s; }
#end-missed { background: rgba(255,255,255,.9); border-radius: 18px; padding: 10px 16px; width: 100%; text-align: center; }
#end-missed:empty { display: none; }
#end-missed h3 { margin: 0 0 6px; font-size: 16px; color: var(--muted); }
#end-missed span { display: inline-block; margin: 3px 8px; font-size: 20px; font-weight: 800; }

.toast {
  position: fixed; left: 50%; top: 18%; transform: translate(-50%, 0) scale(0); background: #fff; color: var(--ink);
  font-size: 26px; font-weight: 900; padding: 14px 24px; border-radius: 99px; box-shadow: 0 8px 30px rgba(0,0,0,.25);
  transition: transform .25s cubic-bezier(.3,1.6,.6,1); z-index: 10; white-space: nowrap;
}
.toast.on { transform: translate(-50%, 0) scale(1); }

/* espace parent */
.parent { background: #f4f4fb; color: var(--ink); }
.parent .topbar h2 { color: var(--ink); text-shadow: none; }
.parent .back { background: #e4e4f0; color: var(--ink); }
.parent .link { color: var(--muted); margin: 0; }
.parent .seg { background: #e4e4f0; }
.parent .seg button { color: var(--ink); }
.parent .seg button.on { background: var(--ink); color: #fff; }
.pcard { background: #fff; border-radius: 18px; padding: 14px; width: 100%; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.pcard h3 { margin: 0 0 10px; font-size: 16px; }
.parent .grid .h { color: var(--muted); }
.parent .grid div.cell { cursor: pointer; font-size: 9px; }
.parent .legend { color: var(--muted); }
.kpis { display: flex; gap: 8px; }
.kpis div { flex: 1; text-align: center; background: #f4f4fb; border-radius: 12px; padding: 8px 2px; }
.kpis b { display: block; font-size: 22px; }
.kpis span { font-size: 12px; color: var(--muted); }
.hard { display: flex; flex-wrap: wrap; gap: 6px; }
.hard span { background: #fee2e2; border-radius: 10px; padding: 5px 9px; font-weight: 800; font-size: 14px; }
.hard small { color: var(--muted); font-weight: 600; }
.ptable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ptable td, .ptable th { padding: 5px 3px; border-bottom: 1px solid #eee; text-align: left; }
.ptable th { color: var(--muted); font-weight: 700; }
.detail { font-size: 14px; color: var(--muted); min-height: 20px; margin-top: 8px; }
.target-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.target-row input { flex: 1; }
