:root {
  --gold: #e8b85a;
  --gold-light: #fff1c9;
  --gold-dark: #9a6b1f;
  --ink: #1a1208;
  --glass: rgba(26, 18, 8, .62);
  --bg: #000;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Inter', system-ui, sans-serif;
  color: #fff;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* ---------- Scène 3D ---------- */
#stage {
  position: fixed;
  inset: 0;
  perspective: 1400px;
  perspective-origin: 50% 50%;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #1c1307 0%, #000 70%);
}

/* ---------- Écrans ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  visibility: hidden;
  backface-visibility: hidden;
}
.screen.active { visibility: visible; }

.bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center 30%;
  z-index: -2;
}
.bg-defi    { background-image: url('img/defi.jpg'); animation: breathe 12s ease-in-out infinite; }
.bg-accueil { background-image: url('img/accueil.jpg'); }

@keyframes breathe {
  0%, 100% { transform: scale(1.02); }
  50%      { transform: scale(1.07); }
}

/* ---------- Bienvenue ---------- */
.vignette {
  position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse at center 35%, transparent 25%, rgba(0,0,0,.75) 100%),
    linear-gradient(to top, rgba(0,0,0,.85) 0%, transparent 45%);
}

.welcome-content {
  position: absolute;
  bottom: 9vh;
  left: 0; right: 0;
  text-align: center;
  padding: 0 16px;
  animation: rise 1.4s cubic-bezier(.2,.8,.2,1) both .3s;
}

.kicker {
  font-family: 'Cinzel', serif;
  letter-spacing: .5em;
  text-transform: uppercase;
  font-size: clamp(.7rem, 1.6vw, .95rem);
  color: var(--gold-light);
  opacity: .8;
  margin-bottom: .6rem;
}

.title {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: clamp(2.2rem, 7vw, 5.5rem);
  line-height: 1.02;
  text-transform: uppercase;
  background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 50%, var(--gold-dark) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 20px rgba(0,0,0,.6));
}
.title span { letter-spacing: .08em; }

.btn-enter {
  margin-top: 2.2rem;
  padding: 1rem 3.4rem;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: .35em;
  text-transform: uppercase;
  color: var(--ink);
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 55%, var(--gold-dark));
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(255,241,201,.5), 0 10px 40px rgba(232,184,90,.35);
  transition: transform .25s, box-shadow .25s;
  animation: pulse 2.6s ease-in-out infinite 2s;
}
.btn-enter:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 0 0 1px rgba(255,241,201,.8), 0 14px 60px rgba(232,184,90,.6);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255,241,201,.5), 0 10px 40px rgba(232,184,90,.35); }
  50%      { box-shadow: 0 0 0 1px rgba(255,241,201,.9), 0 10px 70px rgba(232,184,90,.7); }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: none; }
}

/* Petites braises qui montent */
.embers { position: absolute; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.ember {
  position: absolute;
  bottom: -10px;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px 2px rgba(255,170,60,.8);
  animation: float linear infinite;
}
@keyframes float {
  from { transform: translateY(0) translateX(0); opacity: 0; }
  10%  { opacity: 1; }
  to   { transform: translateY(-105vh) translateX(var(--drift)); opacity: 0; }
}

/* ---------- Transition 3D : rotation de cube (3,6 s) ---------- */
#stage.turning { animation: stageDip 3.6s cubic-bezier(.65,0,.35,1) forwards; }
@keyframes stageDip {
  0%   { transform: scale(1); }
  50%  { transform: scale(.72); }
  100% { transform: scale(1); }
}

#welcome.cube-out {
  transform-origin: 100% 50%;
  animation: cubeOut 3.6s cubic-bezier(.65,0,.35,1) forwards;
}
#home.cube-in {
  visibility: visible;
  transform-origin: 0% 50%;
  animation: cubeIn 3.6s cubic-bezier(.65,0,.35,1) forwards;
}
@keyframes cubeOut {
  0%   { transform: translateX(0) rotateY(0); filter: brightness(1); }
  15%  { transform: translateX(0) rotateY(0); filter: brightness(1); }
  100% { transform: translateX(-100%) rotateY(-90deg); filter: brightness(.25); }
}
@keyframes cubeIn {
  0%   { transform: translateX(100%) rotateY(90deg); filter: brightness(.25); }
  15%  { transform: translateX(100%) rotateY(90deg); filter: brightness(.25); }
  100% { transform: translateX(0) rotateY(0); filter: brightness(1); }
}
#welcome.cube-out .welcome-content { animation: fadeDown .7s ease forwards; }
@keyframes fadeDown { to { opacity: 0; transform: translateY(30px); } }

/* Apparition du contenu de l'accueil après la rotation */
#home .home-header,
#home .game-card { opacity: 0; }
#home.ready .home-header { animation: rise 1s cubic-bezier(.2,.8,.2,1) both; }
#home.ready .game-card   { animation: rise .9s cubic-bezier(.2,.8,.2,1) both; }
#home.ready .game-card:nth-child(1) { animation-delay: .25s; }
#home.ready .game-card:nth-child(2) { animation-delay: .35s; }
#home.ready .game-card:nth-child(3) { animation-delay: .45s; }
#home.ready .game-card:nth-child(4) { animation-delay: .55s; }

/* ---------- Accueil ---------- */
#home {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 0 16px 40px;
}

.home-overlay {
  position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(to bottom, rgba(30,20,5,.15) 0%, rgba(30,20,5,.1) 40%, rgba(25,16,4,.82) 100%);
}

.home-header {
  text-align: center;
  margin-top: max(5vh, 90px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .7rem;
}
.home-title {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: clamp(1.5rem, 4vw, 2.8rem);
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.home-title span { color: var(--gold-dark); }

/* "Choisis ton défi" : texte clair sur pastille sombre, lisible sur la couronne */
.home-sub {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: .35em;
  text-transform: uppercase;
  font-size: .8rem;
  color: var(--gold-light);
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(232,184,90,.45);
  padding: .5rem 1.1rem .5rem 1.45rem;
  border-radius: 999px;
}

.games {
  margin-top: auto;
  width: 100%;
  max-width: 1180px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 16px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .8rem;
  padding: 1.6rem 1rem;
  border-radius: 18px;
  background: rgba(255, 248, 230, .12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,241,201,.35);
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  transition: transform .25s, background .25s, border-color .25s, box-shadow .25s;
}
.game-card:hover {
  transform: translateY(-6px);
  background: rgba(255, 248, 230, .22);
  border-color: var(--gold);
  box-shadow: 0 16px 40px rgba(0,0,0,.4), 0 0 30px rgba(232,184,90,.35);
}
.game-icon { font-size: 2.6rem; filter: drop-shadow(0 4px 8px rgba(0,0,0,.4)); }
.game-name {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .05em;
  color: var(--gold-light);
  text-align: center;
}

/* ---------- Lecteur de musique ---------- */
#player {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: calc(14px + env(safe-area-inset-right, 0px));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px 8px 12px;
  border-radius: 16px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(232,184,90,.4);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  color: var(--gold-light);
  animation: playerIn .8s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes playerIn { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }

.pl-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pl-text { display: flex; flex-direction: column; min-width: 0; width: 128px; }
.pl-title {
  font-family: 'Cinzel', serif; font-weight: 700; font-size: .82rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pl-artist {
  font-size: .7rem; opacity: .7;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Petit égaliseur animé */
.pl-eq { display: flex; align-items: flex-end; gap: 2px; height: 16px; width: 14px; }
.pl-eq i { width: 3px; height: 30%; background: var(--gold); border-radius: 1px; }
#player.playing .pl-eq i { animation: eq .9s ease-in-out infinite; }
#player.playing .pl-eq i:nth-child(2) { animation-delay: -.3s; }
#player.playing .pl-eq i:nth-child(3) { animation-delay: -.6s; }
@keyframes eq { 0%, 100% { height: 25%; } 50% { height: 100%; } }

.pl-controls { display: flex; align-items: center; gap: 4px; }
.pl-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 50%;
  transition: background .2s, transform .2s;
}
.pl-btn svg { width: 16px; height: 16px; fill: var(--gold-light); }
.pl-btn:hover { background: rgba(232,184,90,.18); }
.pl-main {
  width: 38px; height: 38px;
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 60%, var(--gold-dark));
}
.pl-main:hover { background: linear-gradient(180deg, #fff, var(--gold-light) 40%, var(--gold)); transform: scale(1.06); }
.pl-main svg { fill: var(--ink); width: 18px; height: 18px; }
.pl-main .ic-pause { display: none; }
#player.playing .pl-main .ic-play { display: none; }
#player.playing .pl-main .ic-pause { display: block; }

.pl-vol { display: flex; align-items: center; gap: 6px; margin-left: 6px; }
.pl-vol svg { width: 16px; height: 16px; fill: var(--gold-light); stroke: var(--gold-light); stroke-width: 1.6; }
.pl-vol svg path:last-child { fill: none; }

#plVol {
  -webkit-appearance: none; appearance: none;
  width: 84px; height: 4px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--gold) var(--fill, 60%), rgba(255,241,201,.25) var(--fill, 60%));
  cursor: pointer;
}
#plVol::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--gold-light);
  border: 2px solid var(--gold-dark);
}
#plVol::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--gold-light);
  border: 2px solid var(--gold-dark);
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  padding: .8rem 1.4rem;
  border-radius: 999px;
  background: rgba(26,18,8,.92);
  border: 1px solid var(--gold);
  color: var(--gold-light);
  font-size: .95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  z-index: 100;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .games { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .game-card { padding: 1.2rem .6rem; }
  .game-icon { font-size: 2rem; }
  .game-name { font-size: .85rem; }
  .bg { background-position: center top; }

  /* Lecteur pleine largeur en haut, l'accueil descend en dessous */
  #player {
    left: calc(12px + env(safe-area-inset-left, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    top: calc(10px + env(safe-area-inset-top, 0px));
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
  }
  .pl-text { width: auto; flex: 1; }
  .pl-info { flex: 1; }
  #plVol { width: 56px; }
  .home-header { margin-top: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
