@font-face {
  font-family: 'Nunito';
  src: url('fonts/Nunito-ExtraBold.ttf') format('truetype');
  font-weight: 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Nunito';
  src: url('fonts/Nunito-Black.ttf') format('truetype');
  font-weight: 900; font-style: normal; font-display: swap;
}

:root {
  --red: #AF1918; --red-d: #7E1010; --navy: #313F58; --yellow: #FAD200; --gold: #D5B374;
  --ice: #E3F6FF; --ice-2: #9fd0ee;
  --font: 'Nunito', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0d2340;
  font-family: var(--font); font-weight: 800; color: #fff;
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}
#safe-probe {
  position: fixed; visibility: hidden; pointer-events: none; inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#backdrop {
  position: fixed; inset: -40px; z-index: 0;
  background:
    url('../assets/decor/fond.jpg') center / cover no-repeat,
    radial-gradient(ellipse at 50% 30%, #3a76ab 0%, #163a63 55%, #0b1c33 100%);
  filter: blur(22px) brightness(.55) saturate(1.1);
  transform: scale(1.08);
}
#stage {
  position: fixed; z-index: 1; overflow: hidden;
  box-shadow: 0 0 60px rgba(0,0,0,.55);
  touch-action: none;
}
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
/* logos de marque : éléments SVG natifs au-dessus du canvas, sous les écrans DOM */
.stage-logo { position: absolute; left: 0; top: 0; z-index: 1; pointer-events: none; user-select: none; opacity: 0; transition: opacity .3s ease; image-rendering: auto; }
.stage-logo.show { opacity: 1; }
#start-logo { filter: drop-shadow(0 4px 8px rgba(0,0,0,.3)); }
#start-logo.float.show { animation: float 3s ease-in-out infinite; }
#ui { position: absolute; left: 0; top: 0; z-index: 2; transform-origin: 0 0; pointer-events: none; }
#ui > * { pointer-events: auto; }

/* ---------- boutons ---------- */
button { font-family: inherit; }
.btn {
  display: block; width: 100%; margin: 14px auto 0; padding: 22px 24px;
  font-size: 34px; font-weight: 900; letter-spacing: .5px; color: var(--navy);
  background: #fff; border: 0; border-radius: 999px; cursor: pointer;
  box-shadow: 0 6px 0 #c3ccd8, 0 12px 24px rgba(0,0,0,.25);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:active { transform: translateY(5px) scale(.98); box-shadow: 0 1px 0 #c3ccd8, 0 4px 10px rgba(0,0,0,.25); }
.btn-primary {
  color: #fff; background: linear-gradient(180deg, #D82D29 0%, var(--red) 55%, #921414 100%);
  box-shadow: 0 7px 0 var(--red-d), 0 14px 28px rgba(120,0,0,.35);
  text-shadow: 0 2px 0 rgba(0,0,0,.2);
}
.btn-primary:active { box-shadow: 0 2px 0 var(--red-d), 0 4px 10px rgba(120,0,0,.35); }
.btn-big { font-size: 46px; padding: 26px 24px; animation: breathe 1.8s ease-in-out infinite; }
.btn:focus-visible, .icon-btn:focus-visible, .hud-btn:focus-visible, .link-btn:focus-visible { outline: 5px solid var(--yellow); outline-offset: 4px; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.035); } }

.icon-btn {
  width: 76px; height: 76px; border-radius: 50%; border: 0; cursor: pointer;
  color: var(--navy); background: #fff; display: grid; place-items: center;
  box-shadow: 0 5px 0 #c3ccd8, 0 10px 20px rgba(0,0,0,.25);
}
.icon-btn svg { width: 40px; height: 40px; }
.corner-tools { position: absolute; right: 24px; top: 24px; display: flex; align-items: center; gap: 14px; }
.pause-tools { display: flex; justify-content: center; align-items: center; gap: 18px; margin-top: 22px; }
.lang-toggle {
  display: flex; padding: 5px; border-radius: 999px; background: #fff;
  box-shadow: 0 5px 0 #c3ccd8, 0 10px 20px rgba(0,0,0,.25);
}
.lang-btn {
  min-width: 64px; height: 56px; padding: 0 12px; border: 0; border-radius: 999px; cursor: pointer;
  font-size: 24px; font-weight: 900; letter-spacing: 1px; color: #6c7a90; background: transparent;
  transition: background .2s, color .2s;
}
.lang-btn.on { color: #fff; background: var(--navy); }
.lang-btn:focus-visible { outline: 4px solid var(--yellow); outline-offset: 2px; }

.hud-btn {
  position: absolute; right: 22px; top: 18px; width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.6); background: rgba(255,255,255,.18); color: #fff;
  display: grid; place-items: center; cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.hud-btn.show { opacity: 1; pointer-events: auto; }
.hud-btn svg { width: 34px; height: 34px; }
.hud-btn:active { transform: scale(.92); }

.link-btn {
  display: inline-block; margin-top: 22px; padding: 10px 18px; font-size: 26px; font-weight: 800;
  color: var(--navy); text-decoration: underline; text-underline-offset: 5px; text-decoration-thickness: 3px;
}

/* ---------- écrans ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 48px; opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .35s ease, visibility 0s linear .35s;
}
.screen { padding-bottom: calc(40px + var(--safe-b, 0px)); }
.screen.show { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .35s ease; }
.screen.dim { background: rgba(10,22,42,.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.card {
  width: 100%; max-width: 600px; padding: 40px 40px 34px; text-align: center;
  background: linear-gradient(180deg, rgba(255,255,255,.97), rgba(231,244,253,.97));
  color: var(--navy); border-radius: 44px; border: 5px solid #fff;
  box-shadow: 0 24px 60px rgba(4,16,36,.45), inset 0 -8px 0 rgba(49,63,88,.08);
  transform: translateY(40px) scale(.94); transition: transform .45s cubic-bezier(.2,1.5,.4,1);
}
.screen.show .card { transform: none; }
.card h2 { margin: 0 0 10px; font-size: 64px; font-weight: 900; color: var(--red); }

/* chargement */
#scr-loading { background: radial-gradient(ellipse at 50% 35%, #3a76ab 0%, #163a63 60%, #0b1c33 100%); }
.load-box { width: 80%; text-align: center; }
.load-title { font-size: 34px; margin-bottom: 26px; }
.load-track { height: 26px; border-radius: 13px; background: rgba(255,255,255,.2); overflow: hidden; border: 3px solid rgba(255,255,255,.5); }
#load-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--yellow), #fff3a0); transform-origin: 0 50%; transform: scaleX(.02); transition: transform .2s ease; }
#load-pc { margin-top: 14px; font-size: 26px; opacity: .85; }

/* accueil */
#scr-start { justify-content: flex-start; padding-top: 24px; }
.start-logo { align-self: flex-start; width: 210px; height: 133px; flex: 0 0 auto; } /* emplacement : le logo réel est #start-logo */
@keyframes float { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-8px) rotate(1deg); } }
.start-spacer { flex: 0 0 316px; }
.start-card { padding-top: 24px; padding-bottom: 28px; } /* compacte : les anses du panier restent visibles sous la carte */
.start-card .btn-big { padding: 20px 24px; }
.title { margin: 0 0 10px; font-size: 62px; line-height: 1.02; font-weight: 900; color: var(--navy); letter-spacing: -.5px; }
.title span { color: var(--red); font-size: 84px; display: inline-block; transform: rotate(-3deg); text-shadow: 0 4px 0 rgba(175,25,24,.15); }
.legend { list-style: none; margin: 0 -22px 18px; padding: 0; display: flex; justify-content: space-between; gap: 8px; }
.legend li { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 18px; line-height: 1.12; letter-spacing: -.2px; }
.legend canvas { width: 86px; height: 86px; background: #fff; border-radius: 26px; box-shadow: 0 4px 0 #d3dde8; }
.best { margin: 20px 0 0; font-size: 28px; }
.best b { color: var(--red); font-weight: 900; }

/* fin de partie */
.over-card { padding-top: 30px; }
.cause { margin: 0; font-size: 28px; color: #6c7a90; }
.score-label { margin-top: 10px; font-size: 26px; letter-spacing: 3px; color: #6c7a90; }
.big-score { font-size: 120px; line-height: 1; font-weight: 900; color: var(--red); font-variant-numeric: tabular-nums; }
.big-score.pop { animation: pop .5s cubic-bezier(.2,1.8,.4,1); }
@keyframes pop { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
.record {
  display: inline-block; margin-top: 8px; padding: 8px 22px; border-radius: 999px; font-size: 30px; font-weight: 900;
  color: var(--navy); background: linear-gradient(180deg, #FFE680, var(--yellow)); box-shadow: 0 4px 0 #c9a400;
  transform: scale(0); transition: transform .5s cubic-bezier(.2,1.8,.4,1);
}
.record.show { transform: scale(1) rotate(-3deg); animation: wiggle 1.2s ease-in-out .5s infinite; }
@keyframes wiggle { 0%,100% { transform: scale(1) rotate(-3deg); } 50% { transform: scale(1.06) rotate(2deg); } }
.over-card .best { margin-top: 10px; }
.rank { margin: 18px auto 0; padding: 14px 20px; border-radius: 24px; background: var(--navy); color: #fff; display: flex; flex-direction: column; gap: 2px; }
.rank span { font-size: 20px; letter-spacing: 2px; color: var(--gold); }
.rank b { overflow-wrap: anywhere; }
.legend span, .stats dt, .cause { overflow-wrap: break-word; }
.rank b { font-size: 40px; font-weight: 900; color: var(--yellow); }
.stats { display: flex; gap: 10px; margin: 18px 0 6px; }
.stats div { flex: 1; background: #fff; border-radius: 20px; padding: 12px 6px; box-shadow: 0 4px 0 #d3dde8; }
.stats dt { font-size: 18px; color: #6c7a90; line-height: 1.1; }
.stats dd { margin: 4px 0 0; font-size: 40px; font-weight: 900; color: var(--navy); }

#toast {
  position: absolute; left: 50%; bottom: 140px; transform: translate(-50%, 30px); opacity: 0;
  padding: 16px 28px; border-radius: 999px; background: var(--navy); color: #fff; font-size: 28px;
  pointer-events: none; transition: opacity .3s, transform .3s; white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#debug {
  position: fixed; left: 6px; bottom: 6px; z-index: 50; display: flex; flex-wrap: wrap; gap: 4px; max-width: 260px; opacity: .85;
  font: 600 12px/1.2 system-ui, sans-serif; touch-action: manipulation;
}
#debug button { padding: 6px 8px; border: 0; border-radius: 6px; background: rgba(255,255,255,.9); color: #222; cursor: pointer; font: inherit; }
#dbg-audio { width: 100%; padding: 4px 6px; background: rgba(0,40,90,.75); border-radius: 6px; color: #cfe8ff; }
#dbg-info { width: 100%; padding: 4px 6px; background: rgba(0,0,0,.6); border-radius: 6px; color: #fff; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; z-index: 99; }

@media (prefers-reduced-motion: reduce) {
  .btn-big, #start-logo.float.show, .record.show { animation: none; }
}
