/* Mon violon — scène de concert de nuit : violet profond, or des pièces, velours rose de l'étui. */
:root {
  color-scheme: dark;
  --nuit: #2a1b5c;
  --nuit-2: #4a2c8a;
  --or: #ffcb3d;
  --or-fonce: #c98012;
  --rose: #ff8fb8;
  --menthe: #63e2bd;
  --menthe-fonce: #1f9c7c;
  --ambre: #ffb547;
  --creme: #fff6e6;
  --lilas: #c9b8ff;
  --ombre: rgba(10, 4, 30, .45);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  color: var(--creme);
  background: radial-gradient(120% 70% at 50% 0%, #5d3aa6 0%, var(--nuit-2) 35%, var(--nuit) 75%) fixed, var(--nuit);
  background-color: var(--nuit);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:focus-visible, label:focus-within { outline: 4px solid var(--or); outline-offset: 3px; }
svg { display: block; }

/* Ciel étoilé discret */
#ciel { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#ciel i { position: absolute; width: calc(var(--t) / 3); height: calc(var(--t) / 3); border-radius: 50%; background: #fff;
  opacity: .35; animation: scintille 3.2s ease-in-out var(--d) infinite alternate; }
@keyframes scintille { to { opacity: .9; transform: scale(1.3); } }

#app {
  position: relative; min-height: 100%; max-width: 560px; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}

/* ---------- En-tête ---------- */
.haut { display: flex; align-items: center; justify-content: space-between; }
.haut h1 { margin: 0; font-size: 26px; letter-spacing: .5px; color: var(--or); text-shadow: 0 3px 0 rgba(0,0,0,.25); }
.rond { width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.12); color: var(--creme);
  display: grid; place-items: center; box-shadow: inset 0 0 0 2px rgba(255,255,255,.18); }
.rond svg { width: 28px; height: 28px; }
.rond:active { transform: scale(.94); }

.bandeau { display: flex; align-items: center; gap: 10px; justify-content: center; width: 100%;
  background: var(--or); color: var(--nuit); font-weight: 800; font-size: 17px; padding: 12px 14px; border-radius: 18px;
  box-shadow: 0 5px 0 var(--or-fonce); animation: appel 1.6s ease-in-out infinite alternate; }
.bandeau svg { width: 24px; height: 24px; }
@keyframes appel { to { transform: translateY(-2px) scale(1.015); } }
.alerte { margin: 0; background: #ff6b6b; color: #fff; padding: 10px 14px; border-radius: 14px; font-weight: 700; }

/* ---------- Scène : violon + chrono ---------- */
.scene { display: grid; grid-template-columns: 38% 1fr; align-items: center; gap: 6px; }
.violon-img { display: block; width: 100%; height: auto; max-height: 30vh; object-fit: contain; filter: drop-shadow(0 10px 14px var(--ombre)); }
.etat-marche .violon-img { animation: balance 2.4s ease-in-out infinite; transform-origin: 50% 80%; }
@keyframes balance { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.chrono { display: flex; flex-direction: column; align-items: center; text-align: center; }
.temps { font-size: clamp(54px, 17vw, 84px); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1;
  color: var(--creme); text-shadow: 0 4px 0 rgba(0,0,0,.25); }
.sous { margin-top: 8px; font-size: 22px; font-weight: 800; color: var(--lilas); }
.etat-marche .sous { color: var(--menthe); }

/* ---------- Portée de progression ---------- */
.progres { background: rgba(255,255,255,.07); border-radius: 22px; padding: 8px 10px 10px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.1); }
.portee-svg { width: 100%; height: auto; }
.n-cur { animation: pulse 1s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { to { opacity: .55; } }
.reste { margin: 2px 0 0; text-align: center; font-size: 19px; font-weight: 700; }
.reste b { color: var(--or); font-size: 26px; }

/* ---------- Gros boutons ---------- */
.commandes { display: flex; gap: 14px; justify-content: center; }
.gros, .moyen { display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 900; border-radius: 999px;
  transition: transform .08s; }
.gros { width: 100%; min-height: 92px; font-size: 32px; }
.moyen { flex: 1; min-height: 68px; font-size: 22px; padding: 0 18px; }
.gros svg { width: 44px; height: 44px; }
.moyen svg { width: 32px; height: 32px; }
.b-jouer { background: var(--menthe); color: #0f3d31; box-shadow: 0 8px 0 var(--menthe-fonce), 0 14px 24px var(--ombre); }
.b-pause { background: var(--ambre); color: #4a2a00; box-shadow: 0 8px 0 #c97f12, 0 14px 24px var(--ombre); }
.b-stop { background: var(--rose); color: #4d0f2a; box-shadow: 0 8px 0 #c44f7d, 0 14px 24px var(--ombre); }
.b-report { background: var(--lilas); color: var(--nuit); box-shadow: 0 8px 0 #8f7fd6, 0 14px 24px var(--ombre); }
.gros:active, .moyen:active { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.moyen:disabled { opacity: .45; }

/* ---------- Tirelire (étui à violon) ---------- */
.tirelire { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; }
.etui-svg { width: 100%; height: auto; filter: drop-shadow(0 8px 10px var(--ombre)); }
.etui.hop { animation: hop .5s ease; }
@keyframes hop { 40% { transform: translateY(-8px) scale(1.04); } }
.somme { display: flex; flex-direction: column; align-items: center; min-width: 96px; }
.somme b { font-size: 46px; font-weight: 900; color: var(--or); line-height: 1; text-shadow: 0 4px 0 rgba(0,0,0,.25); }
.somme span { font-size: 15px; font-weight: 700; color: var(--lilas); }
.somme small { font-size: 13px; color: var(--creme); opacity: .8; text-align: center; max-width: 110px; }

.b-semaine { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 58px; border-radius: 20px;
  background: rgba(255,255,255,.12); font-size: 20px; font-weight: 800; box-shadow: inset 0 0 0 2px rgba(255,255,255,.18); }
.b-semaine svg { width: 28px; height: 28px; color: var(--or); }

/* ---------- Pièce qui tombe + confettis ---------- */
.piece-tombe { position: fixed; left: 0; top: 0; width: 80px; height: 80px; z-index: 50; pointer-events: none; }
.piece-img { display: block; width: 100%; height: 100%; filter: drop-shadow(0 6px 8px var(--ombre)); }
.piece-tombe .piece-img { animation: pivote 1.3s ease-in; }
@keyframes pivote { from { transform: rotateY(0) rotate(-30deg); } to { transform: rotateY(720deg) rotate(0); } }
.piece-tombe span { position: absolute; left: 50%; top: -26px; transform: translateX(-50%); font-weight: 900; color: var(--or); font-size: 20px; white-space: nowrap; }
.confettis { position: fixed; inset: 0; pointer-events: none; z-index: 49; }
.confettis i { position: absolute; width: 10px; height: 14px; border-radius: 3px; animation: eclat 1.5s cubic-bezier(.2,.7,.4,1) forwards; }
.confettis i.etoile { width: 14px; height: 14px; clip-path: polygon(50% 0, 62% 36%, 100% 38%, 70% 60%, 80% 100%, 50% 76%, 20% 100%, 30% 60%, 0 38%, 38% 36%); }
@keyframes eclat { to { transform: translate(var(--dx), calc(var(--dy) + 160px)) rotate(var(--rot)); opacity: 0; } }

/* ---------- Fenêtres ---------- */
#couche { position: fixed; inset: 0; z-index: 40; display: none; background: rgba(18, 8, 45, .72);
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
#couche.ouverte { display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; }
.fenetre { width: 100%; min-width: 0; max-width: 480px; background: linear-gradient(180deg, #4b2f93, #33206e); border-radius: 30px;
  padding: 22px 18px; text-align: center; box-shadow: 0 20px 50px var(--ombre), inset 0 0 0 2px rgba(255,255,255,.15);
  animation: monte .25s ease-out; }
@keyframes monte { from { transform: translateY(24px) scale(.97); opacity: 0; } }
.fenetre h2 { margin: 6px 0 6px; font-size: 30px; color: var(--or); }
.fenetre p { margin: 8px 0; font-size: 18px; }
.fenetre .moyen { width: 100%; margin-top: 14px; }
.grand-ico { width: 74px; height: 74px; margin: 0 auto; color: var(--or); animation: tourne 6s linear infinite; }
.clavier .grand-ico { width: 50px; height: 50px; animation: none; color: var(--lilas); }
@keyframes tourne { to { transform: rotate(360deg); } }
.gros-chiffre { font-size: 48px !important; font-weight: 900; color: var(--creme); margin: 4px 0 !important; }
.petit { font-size: 15px !important; color: var(--lilas); }
.duo { display: flex; gap: 12px; }
.duo .moyen { margin-top: 10px; }

/* Bilan */
.tuiles-bilan { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.tb { background: rgba(255,255,255,.1); border-radius: 20px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tb b { font-size: 26px; font-weight: 900; color: var(--creme); }
.tb span { font-size: 14px; color: var(--lilas); font-weight: 700; }
.tb-img { width: 36px; height: 36px; }
.tb-euros b { color: var(--or); }
.report-bilan { font-weight: 700; }
.report-bilan b { color: var(--or); font-size: 22px; }
.jours { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 140px; align-items: end; margin-top: 10px; }
.jour { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 4px; }
.jour .barre { width: 70%; height: var(--h); min-height: 4px; background: linear-gradient(180deg, var(--or), var(--rose)); border-radius: 10px 10px 4px 4px; position: relative; }
.jour .barre i { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-style: normal; font-size: 13px; font-weight: 800; }
.jour span { font-weight: 800; color: var(--lilas); }
.jour.auj span { color: var(--or); }

/* Clavier du code */
.points { display: flex; gap: 16px; justify-content: center; margin: 16px 0; }
.points i { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 3px var(--lilas); }
.points i.plein { background: var(--or); box-shadow: none; }
.points.secoue { animation: secoue .4s; }
@keyframes secoue { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.touches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 300px; margin: 0 auto; }
.touches button { height: 66px; border-radius: 20px; background: rgba(255,255,255,.14); font-size: 30px; font-weight: 800; }
.touches button:active { background: rgba(255,255,255,.3); }
.touches .t-annuler { color: var(--rose); }

/* Espace parent : sobre, pour adulte */
.parent { text-align: left; max-width: 520px; }
.parent .moyen { font-size: 18px; padding: 0 12px; min-height: 58px; }
.parent .duo { flex-wrap: wrap; }
.parent .duo .moyen { flex: 1 1 130px; }
.parent-haut { display: flex; align-items: center; justify-content: space-between; }
.parent-haut h2 { margin: 0; font-size: 24px; }
.fermer { font-size: 22px; font-weight: 900; }
.onglets { display: flex; gap: 6px; overflow-x: auto; margin: 14px -4px 10px; padding: 4px; }
.onglets button { flex: none; padding: 10px 14px; border-radius: 14px; background: rgba(255,255,255,.1); font-size: 15px; font-weight: 700; }
.onglets button.actif { background: var(--or); color: var(--nuit); }
.pastille { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 10px; background: var(--rose); color: #4d0f2a; font-style: normal; font-size: 12px; }
.contenu-parent p { font-size: 16px; }
.carte-parent { background: rgba(255,255,255,.08); border-radius: 18px; padding: 12px 14px; margin-bottom: 12px; text-align: center; }
.carte-parent.confirme { box-shadow: inset 0 0 0 2px var(--rose); }
.aide { font-size: 14px !important; color: var(--lilas); }
.vide { font-size: 18px !important; font-weight: 700; }
.choix-semaine { display: flex; gap: 8px; }
.choix-semaine button { flex: 1; padding: 10px; border-radius: 14px; background: rgba(255,255,255,.1); font-weight: 700; }
.choix-semaine button.actif { background: var(--lilas); color: var(--nuit); }
.reglage { display: flex; align-items: center; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.reglage button { min-width: 50px; height: 50px; border-radius: 14px; background: rgba(255,255,255,.14); font-size: 18px; font-weight: 800; }
.delta { min-width: 84px; text-align: center; font-size: 20px; font-weight: 900; color: var(--or); }
.histo { width: 100%; border-collapse: collapse; font-size: 15px; }
.histo th { text-align: left; color: var(--lilas); font-size: 13px; padding: 6px 4px; }
.histo td { padding: 8px 4px; border-top: 1px solid rgba(255,255,255,.12); vertical-align: top; }
.histo small { color: var(--lilas); }
.st-payee { color: var(--menthe); font-weight: 800; }
.st-reportee { color: var(--ambre); font-weight: 800; }
.st-attente { color: var(--rose); font-weight: 800; }
.credits { margin: 16px 0 0 !important; font-size: 12px !important; color: var(--lilas); opacity: .75; text-align: center; }
.import { display: flex; cursor: pointer; margin-top: 14px; }

/* Premier lancement */
.accueil-vide { justify-content: center; }
.bienvenue { text-align: center; }
.bienvenue .violon-img { max-height: 40vh; margin: 0 auto; width: 50%; }
.bienvenue h1 { color: var(--or); font-size: 36px; }

/* Images Fluent */
.mini { width: 30px; height: 30px; flex: none; }
.grande-img { width: 84px; height: 84px; display: block; margin: 0 auto; animation: flotte 2.4s ease-in-out infinite alternate; }
.titre-img { width: 64px; height: 64px; display: block; margin: 0 auto; }
@keyframes flotte { to { transform: translateY(-6px) rotate(6deg); } }
.haut h1 { display: flex; align-items: center; gap: 8px; }
.indic-sync { display: inline-grid; width: 22px; height: 22px; }
.indic-sync svg { width: 22px; height: 22px; }
.indic-sync.ok { color: var(--menthe); }
.indic-sync.non { color: var(--lilas); opacity: .7; }
.b-semaine .mini { width: 32px; height: 32px; }

/* Chrono qui tourne sur l'autre téléphone */
.distant { background: rgba(255, 203, 61, .14); border-radius: 22px; padding: 12px 14px; box-shadow: inset 0 0 0 2px rgba(255, 203, 61, .5); }
.distant p { margin: 0 0 4px; display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; line-height: 1.2; }
.distant p span { flex: 1; }
.distant .t-distant { font-size: 26px; color: var(--or); font-variant-numeric: tabular-nums; }
.distant .moyen { min-height: 56px; font-size: 18px; }
.distant .moyen svg { width: 24px; height: 24px; }
.distant.secoue { animation: secoue .4s; }
.etat-distant .b-jouer.gros { opacity: .5; }

/* Choix du rôle */
.roles { display: grid; gap: 14px; margin: 16px 0 6px; }
.role-btn { display: grid; grid-template-columns: 64px 1fr; grid-template-rows: auto auto; align-items: center; column-gap: 14px; text-align: left;
  background: rgba(255,255,255,.12); border-radius: 24px; padding: 14px 16px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.18); }
.role-btn:active { background: rgba(255,255,255,.22); }
.role-img { grid-row: span 2; width: 64px; height: 64px; }
.role-btn b { font-size: 21px; color: var(--or); }
.role-btn span { font-size: 15px; color: var(--lilas); }

/* Synchro */
.parent h3 { margin: 16px 0 4px; font-size: 18px; color: var(--or); }
.champ { display: grid; gap: 6px; font-weight: 700; margin: 12px 0 0; }
.champ input { font: inherit; font-size: 18px; letter-spacing: 1px; padding: 14px; border-radius: 14px; border: 0; background: var(--creme); color: var(--nuit);
  -webkit-user-select: text; user-select: text; width: 100%; }
.champ input:focus-visible { outline: 4px solid var(--or); }
.qr { width: min(220px, 70%); margin: 8px auto; border-radius: 12px; overflow: hidden; }
.qr-svg { width: 100%; height: auto; }
.cle { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 17px !important; font-weight: 800; letter-spacing: 1px; word-break: break-all;
  -webkit-user-select: all; user-select: all; }
.sync-ok { color: var(--menthe); }
.sync-horsligne, .sync-aucun { color: var(--ambre); }
.sync-refusee, .sync-erreur { color: var(--rose); }
.moyen svg { flex: none; }

h1, h2, h3 { text-wrap: balance; }
@media (hover: hover) {
  .gros:hover, .moyen:hover, .rond:hover, .b-semaine:hover, .role-btn:hover, .touches button:hover, .onglets button:hover, .reglage button:hover { filter: brightness(1.08); }
}

/* Petits écrans (iPhone SE) */
@media (max-height: 700px) {
  #app { gap: 8px; }
  .violon-img { max-height: 22vh; }
  .gros { min-height: 76px; font-size: 28px; }
  .moyen { min-height: 60px; }
  .somme b { font-size: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
