/* ============================================================
   Bubble Pop ! – feuille de style
   Jeu pour enfant de 3 ans : gros boutons, contrastes doux,
   aucune dépendance externe (polices système uniquement).
   ============================================================ */

:root {
  --bg-0: #0b0a1a;
  --bg-1: #171334;
  --bg-2: #241a4d;
  --ink: #ffffff;
  --ink-soft: #cfc9ee;
  --mint: #5ff2cf;
  --mint-deep: #23b79a;
  --violet: #b79bff;
  --pink: #ff7bc4;
  --sun: #ffd45e;
  --radius: 26px;
  --shadow: 0 10px 0 rgba(0,0,0,.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
}

body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% -10%, #2b1c5c 0%, transparent 60%),
    radial-gradient(90% 60% at 10% 110%, #1d3a52 0%, transparent 55%),
    radial-gradient(90% 60% at 95% 100%, #3a1d4f 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
}

/* ---------------- Écrans ---------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(18px + var(--safe-top)) calc(18px + var(--safe-right))
           calc(18px + var(--safe-bottom)) calc(18px + var(--safe-left));
  text-align: center;
  transition: opacity .25s ease;
}
.screen.hidden { display: none; }

/* ---------------- Décor bulles ---------------- */
.deco {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.deco span {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,.85), rgba(255,255,255,.06) 42%, rgba(255,255,255,0) 60%);
  opacity: .5;
  filter: blur(.4px);
  animation: floaty 9s ease-in-out infinite;
}
.deco span:nth-child(1) { width: 120px; height: 120px; left: -30px; top: 8%;  background-color: #3f7ce0; animation-delay: 0s; }
.deco span:nth-child(2) { width: 70px;  height: 70px;  left: 12%;  top: 30%; background-color: #e04f9a; animation-delay: .8s; }
.deco span:nth-child(3) { width: 160px; height: 160px; right: -50px; top: 4%;  background-color: #7a4fe0; animation-delay: 1.6s; }
.deco span:nth-child(4) { width: 90px;  height: 90px;  right: 8%;  bottom: 22%; background-color: #ffb547; animation-delay: .4s; }
.deco span:nth-child(5) { width: 150px; height: 150px; left: -40px; bottom: -30px; background-color: #2bb7a0; animation-delay: 1.2s; }
.deco span:nth-child(6) { width: 60px;  height: 60px;  right: 26%; bottom: 6%; background-color: #ff7bc4; animation-delay: 2s; }
@keyframes floaty {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-18px) scale(1.04); }
}

/* ---------------- Accueil ---------------- */
.logo {
  position: relative;
  margin: 0 0 6px;
  font-size: clamp(46px, 13vw, 92px);
  font-weight: 900;
  letter-spacing: -2px;
  line-height: 1;
  color: var(--mint);
  text-shadow: 0 0 18px rgba(95,242,207,.55), 0 6px 0 rgba(0,0,0,.25);
}
.logo span { color: var(--violet); text-shadow: 0 0 18px rgba(183,155,255,.55), 0 6px 0 rgba(0,0,0,.25); }

.tagline {
  position: relative;
  margin: 0 0 clamp(20px, 6vh, 46px);
  font-size: clamp(16px, 4.4vw, 22px);
  font-weight: 700;
  color: var(--ink-soft);
}

.home-actions {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(420px, 84vw);
}

.home-sound { position: absolute; top: calc(14px + var(--safe-top)); right: calc(14px + var(--safe-right)); }

/* ---------------- Boutons ---------------- */
.btn {
  position: relative;
  border: 0;
  border-radius: var(--radius);
  padding: 22px 28px;
  font-family: inherit;
  font-size: clamp(22px, 5.6vw, 30px);
  font-weight: 900;
  letter-spacing: .5px;
  color: #08131a;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, filter .15s ease;
  touch-action: manipulation;
}
.btn:active { transform: translateY(6px); box-shadow: 0 4px 0 rgba(0,0,0,.28); }
.btn-primary  { background: linear-gradient(180deg, #8bffe4, var(--mint)); }
.btn-secondary{ background: linear-gradient(180deg, #d3c2ff, var(--violet)); }
.btn-link {
  margin-top: 4px;
  padding: 12px;
  background: transparent;
  color: var(--ink-soft);
  font-size: clamp(16px, 4vw, 20px);
  box-shadow: none;
  text-decoration: underline;
  text-underline-offset: 5px;
}
.btn-link:active { transform: none; box-shadow: none; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  min-width: 56px;
  border: 0;
  border-radius: 18px;
  background: rgba(255,255,255,.12);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: transform .12s ease, background .15s ease;
  touch-action: manipulation;
}
.btn-icon:active { transform: scale(.93); background: rgba(255,255,255,.22); }

/* ---------------- Choix des niveaux ---------------- */
.subhud {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 860px;
  margin-bottom: 14px;
}
.subhud h2 {
  margin: 0;
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 900;
  color: var(--mint);
}

.level-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: clamp(12px, 3vw, 20px);
  width: 100%;
  max-width: 860px;
  overflow-y: auto;
  padding: 6px;
  -webkit-overflow-scrolling: touch;
}

.level-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 24px;
  padding: 6px;
  font-family: inherit;
  font-weight: 900;
  color: #08131a;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(0,0,0,.3);
  transition: transform .12s ease, box-shadow .12s ease;
  touch-action: manipulation;
}
.level-tile:active { transform: translateY(5px); box-shadow: 0 3px 0 rgba(0,0,0,.3); }
.level-tile .lv-num { font-size: clamp(26px, 7vw, 36px); line-height: 1; }
.level-tile .lv-stars { font-size: clamp(12px, 3vw, 16px); letter-spacing: 1px; opacity: .95; }
.level-tile.is-done::after {
  content: "✔";
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 18px;
  color: #063b30;
}

/* ---------------- HUD de jeu ---------------- */
/* Le canvas occupe tout l'écran ; le HUD et l'astuce flottent par-dessus. */
.screen#screen-game {
  display: block;
  padding: 0;
}
/* L'ID ci-dessus est plus spécifique que .hidden : on rétablit le masquage. */
.screen#screen-game.hidden { display: none; }

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 8px calc(10px + var(--safe-left));
  background: linear-gradient(180deg, rgba(11,10,26,.72), rgba(11,10,26,0));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-center { flex: 1 1 auto; min-width: 0; padding: 0 4px; }
.hud-name {
  font-size: clamp(13px, 3.4vw, 17px);
  font-weight: 800;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress {
  margin-top: 6px;
  height: 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint), var(--violet));
  transition: width .25s ease;
}

.hud-count {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 44px;
  padding: 0 10px;
  border-radius: 16px;
  background: rgba(255,255,255,.12);
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 900;
  color: var(--mint);
}

/* ---------------- Canvas ---------------- */
#game {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(6px + var(--safe-bottom));
  z-index: 3;
  margin: 0;
  padding: 0 12px;
  font-size: clamp(13px, 3.6vw, 17px);
  font-weight: 700;
  color: var(--ink-soft);
  opacity: .75;
  pointer-events: none;
}

.game-bg {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(80% 50% at 50% 0%, rgba(95,242,207,.12) 0%, transparent 70%),
    radial-gradient(60% 40% at 20% 100%, rgba(183,155,255,.14) 0%, transparent 70%),
    radial-gradient(60% 40% at 90% 90%, rgba(255,123,196,.12) 0%, transparent 70%);
}

/* ---------------- Victoire ---------------- */
.celebrate {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7,6,20,.72);
  backdrop-filter: blur(6px);
}
.celebrate.show { display: flex; animation: fadeIn .2s ease; }

.celebrate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(420px, 88vw);
  padding: 26px 24px 20px;
  border-radius: 32px;
  background: linear-gradient(180deg, #241a4d, #15112e);
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  animation: popIn .35s cubic-bezier(.2,1.4,.5,1);
}

.celebrate-stars { display: flex; gap: 10px; font-size: clamp(38px, 11vw, 56px); line-height: 1; }
.celebrate-stars span { display: inline-block; animation: starBounce .7s ease infinite alternate; }
.celebrate-stars span:nth-child(2) { animation-delay: .15s; }
.celebrate-stars span:nth-child(3) { animation-delay: .3s; }

.celebrate-title {
  font-size: clamp(24px, 6.6vw, 34px);
  font-weight: 900;
  color: var(--mint);
  text-shadow: 0 0 16px rgba(95,242,207,.5);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn  { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes starBounce { from { transform: translateY(0) scale(1); } to { transform: translateY(-10px) scale(1.08); } }

/* ---------------- Accessibilité ---------------- */
@media (prefers-reduced-motion: reduce) {
  .deco span, .celebrate-stars span, .celebrate-card { animation: none !important; }
  * { transition-duration: .01ms !important; }
}

/* ---------------- Paysage court ---------------- */
@media (max-height: 480px) and (orientation: landscape) {
  .logo { font-size: clamp(34px, 9vh, 56px); }
  .tagline { margin-bottom: 14px; }
  .btn { padding: 14px 22px; }
  .hint { display: none; }
}
