:root {
  --bg: #160d2b;
  --ink: #ffffff;
  --muted: #b9a9de;
  --yellow: #ffd23f;
  --yellow-d: #c79a00;
  --blue: #4cc9f0;
  --blue-d: #1f8fb3;
  --pink: #ff3d8b;
  --pink-d: #b81e5e;
  --orange: #ff9b3d;
  --violet: #7b3fe4;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(700px 500px at 100% -10%, rgba(255, 61, 139, .35), transparent 60%),
    radial-gradient(600px 500px at -10% 110%, rgba(76, 201, 240, .28), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  line-height: 1.4;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

[hidden] { display: none !important; }

/* ---------- En-tête ---------- */
.top { display: flex; align-items: center; justify-content: space-between; }

.logo {
  margin: 0;
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: .08em;
  background: linear-gradient(90deg, var(--yellow), var(--orange), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.counter {
  background: rgba(255, 255, 255, .1);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 700;
  font-size: .9rem;
  color: var(--muted);
}

.lead { text-align: center; font-size: 1.15rem; color: var(--muted); margin: 8px 0 20px; }

.screen { display: flex; flex-direction: column; gap: 16px; flex: 1; }

/* ---------- Carte ---------- */
.card-wrap {
  perspective: 1200px;
  display: grid;
  place-items: center;
  padding: 8px 0;
}

.card {
  width: min(86vw, 360px);
  aspect-ratio: 1;
  position: relative;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.2, .8, .2, 1);
}

.card.revealed .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  border-radius: 28px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 10px 0 rgba(0, 0, 0, .25), 0 24px 50px rgba(0, 0, 0, .45);
}

.front {
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .28), transparent 45%),
    linear-gradient(145deg, var(--pink), var(--orange));
  border: 6px solid rgba(255, 255, 255, .85);
}

.back {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, #2a1a57, var(--violet));
  border: 6px solid var(--yellow);
  padding: 20px;
  text-align: center;
  align-content: center;
  gap: 6px;
}

.note {
  position: absolute;
  top: 18px;
  left: 18px;
  color: rgba(255, 255, 255, .9);
}

/* Égaliseur animé */
.eq {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 46%;
}

.bar {
  width: 16px;
  height: 22%;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .2);
}

.card[data-state="playing"] .bar { animation: bounce .9s ease-in-out infinite; }
.card[data-state="playing"] .bar:nth-child(1) { animation-delay: -.1s; animation-duration: .8s; }
.card[data-state="playing"] .bar:nth-child(2) { animation-delay: -.5s; animation-duration: 1.1s; }
.card[data-state="playing"] .bar:nth-child(3) { animation-delay: -.3s; animation-duration: .7s; }
.card[data-state="playing"] .bar:nth-child(4) { animation-delay: -.7s; animation-duration: 1s; }
.card[data-state="playing"] .bar:nth-child(5) { animation-delay: -.2s; animation-duration: .9s; }

@keyframes bounce {
  0%, 100% { height: 18%; }
  50% { height: 100%; }
}

/* Halo qui pulse pendant l'écoute */
.card[data-state="playing"] .front { animation: glow 1.4s ease-in-out infinite; }

@keyframes glow {
  0%, 100% { box-shadow: 0 10px 0 rgba(0, 0, 0, .25), 0 0 0 0 rgba(255, 61, 139, .55), 0 24px 50px rgba(0, 0, 0, .45); }
  50% { box-shadow: 0 10px 0 rgba(0, 0, 0, .25), 0 0 0 22px rgba(255, 61, 139, 0), 0 24px 50px rgba(0, 0, 0, .45); }
}

/* La carte bat comme un rythme pendant l'écoute */
.card[data-state="playing"] { animation: beat 1.2s ease-in-out infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }

/* Anneau qui tourne (disque vinyle) */
.ring {
  position: absolute;
  width: 88%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(255,255,255,.0), rgba(255,255,255,.55), rgba(255,255,255,.0) 45%, rgba(255,255,255,.35) 60%, rgba(255,255,255,.0));
  -webkit-mask: radial-gradient(circle, transparent 62%, #000 63%, #000 68%, transparent 69%);
  mask: radial-gradient(circle, transparent 62%, #000 63%, #000 68%, transparent 69%);
  opacity: 0;
  transition: opacity .3s ease;
}
.card[data-state="playing"] .ring { opacity: 1; animation: spin 3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Notes qui montent */
.float-note {
  position: absolute;
  bottom: 14%;
  font-size: 1.8rem;
  color: rgba(255, 255, 255, .9);
  opacity: 0;
}
.float-note.n1 { left: 14%; }
.float-note.n2 { left: 46%; }
.float-note.n3 { right: 14%; }
.card[data-state="playing"] .float-note { animation: rise 2.4s ease-in infinite; }
.card[data-state="playing"] .float-note.n2 { animation-delay: .8s; }
.card[data-state="playing"] .float-note.n3 { animation-delay: 1.6s; }
@keyframes rise {
  0% { transform: translateY(0) rotate(-8deg); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(-190px) rotate(12deg); opacity: 0; }
}

/* Chargement : la carte respire */
.card[data-state="loading"] .front { animation: breathe 1s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.97); } }

/* Pause : voile + logo pause */
.pause-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(22, 13, 43, .62);
  color: #fff;
  opacity: 0;
  transform: scale(1.08);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.card[data-state="paused"] .pause-overlay { opacity: 1; transform: scale(1); }

/* Réponse */
.ans-year {
  margin: 0;
  font-size: clamp(3.5rem, 22vw, 5.5rem);
  font-weight: 900;
  line-height: 1;
  color: var(--yellow);
  text-shadow: 0 6px 0 rgba(0, 0, 0, .3);
}

.ans-title {
  margin: 10px 0 0;
  font-size: clamp(1.3rem, 6.5vw, 1.9rem);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.ans-artist {
  margin: 0;
  font-size: clamp(1.05rem, 5vw, 1.4rem);
  font-weight: 600;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.hint {
  text-align: center;
  min-height: 1.5em;
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Boutons ---------- */
.controls { display: grid; gap: 14px; margin-top: auto; padding-bottom: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.btn {
  font: inherit;
  font-weight: 800;
  font-size: 1.1rem;
  min-height: 60px;
  padding: 14px 18px;
  border: 0;
  border-radius: 20px;
  color: #1a1030;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease, opacity .2s ease;
  touch-action: manipulation;
}

.btn-big { min-height: 72px; font-size: 1.3rem; }

.btn-yellow { background: var(--yellow); box-shadow: 0 7px 0 var(--yellow-d); }
.btn-blue { background: var(--blue); box-shadow: 0 7px 0 var(--blue-d); }
.btn-pink { background: var(--pink); color: #fff; box-shadow: 0 7px 0 var(--pink-d); }

.btn:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 2px 0 rgba(0, 0, 0, .3); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible, summary:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.error {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 61, 139, .18);
  border: 2px solid var(--pink);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 2px solid rgba(255, 255, 255, .2);
  min-height: 48px;
  font-size: 1rem;
}

/* ---------- Choix de la playlist ---------- */
.screen-title {
  margin: 4px 0 0;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 900;
}

.pl-list { display: grid; gap: 12px; align-content: start; }

.pl-item {
  font: inherit;
  color: var(--ink);
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: center;
  width: 100%;
  padding: 16px 18px;
  border-radius: 20px;
  border: 3px solid rgba(255, 255, 255, .15);
  background: rgba(255, 255, 255, .07);
  box-shadow: 0 6px 0 rgba(0, 0, 0, .25);
  cursor: pointer;
  transition: transform .08s ease, border-color .15s ease, background .15s ease;
  touch-action: manipulation;
}
.pl-item:hover { background: rgba(255, 255, 255, .11); }
.pl-item:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }
.pl-item:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.pl-item[aria-checked="true"] {
  border-color: var(--yellow);
  background: rgba(255, 210, 63, .14);
}

.pl-name { font-weight: 800; font-size: 1.15rem; overflow-wrap: anywhere; }
.pl-desc { grid-column: 1; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.pl-count {
  grid-column: 2;
  grid-row: 1 / span 2;
  background: rgba(255, 255, 255, .12);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 700;
  font-size: .85rem;
  color: var(--muted);
  white-space: nowrap;
}
.pl-item[aria-checked="true"] .pl-count { background: var(--yellow); color: #1a1030; }

/* ---------- Infos techniques ---------- */
.tech { color: var(--muted); font-size: .85rem; }
.tech summary { cursor: pointer; padding: 6px 0; }
.tech pre {
  background: rgba(0, 0, 0, .35);
  border-radius: 12px;
  padding: 12px;
  white-space: pre-wrap;
  min-height: 3rem;
  margin: 8px 0 0;
}

/* ---------- Accessibilité ---------- */
/* Mouvements réduits : on coupe seulement les grands mouvements (rotation, rebond, notes, retournement).
   L'égaliseur et le halo restent, car ils indiquent que la musique joue. */
@media (prefers-reduced-motion: reduce) {
  .card, .ring, .float-note { animation: none !important; }
  .card-inner { transition-duration: .2s; }
}
