:root {
  --nuit: #1b1530;
  --nuit-transparente: rgba(20, 14, 40, 0.55);
  --or: #f6c75a;
  --creme: #fff8ec;
  --rouge: #c0392b;
  --vert: #2e7d4f;
  --texte: #2b2233;
  --gris: #6d6478;
  --bord: #e3dce9;
  --twitch: #9146ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Montserrat', system-ui, sans-serif;
  color: var(--creme);
  background: var(--nuit) var(--fond, none) center / cover fixed no-repeat;
}

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 16px; }

a { color: var(--or); }

/* === En-tête et pied === */

.entete, .pied {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--nuit-transparente);
  backdrop-filter: blur(4px);
}

.entete-titre {
  font-family: 'BioRhyme', serif;
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--creme);
  text-decoration: none;
}

.entete-compte { display: flex; align-items: center; gap: 14px; }
.entete-compte form { margin: 0; }
.pseudo { font-weight: 600; }

.lien {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--or);
  text-decoration: underline;
  cursor: pointer;
}

.bouton-twitch {
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--twitch);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.pied { margin-top: 24px; font-size: 0.9rem; }
.pied p { margin: 0; }
.reseaux { display: flex; flex-wrap: wrap; gap: 14px; }

.annonce {
  margin: 16px auto 0;
  max-width: 640px;
  padding: 10px 16px;
  border-radius: 8px;
  text-align: center;
  background: var(--nuit-transparente);
  backdrop-filter: blur(4px);
}

/* === Grille du calendrier === */

.grille {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(84px, 1fr);
  grid-template-areas: var(--zones-etroite);
  gap: 12px;
  margin: 16px auto;
}

@media (min-width: 640px) {
  .grille {
    grid-template-columns: repeat(5, 1fr);
    grid-auto-rows: minmax(110px, 15vh);
    grid-template-areas: var(--zones-large);
    gap: 15px;
  }
}

.porte {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-decoration: none;
  perspective: 1000px;
}

.porte .face, .porte .dos {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  backface-visibility: hidden;
  transition: transform 0.7s ease;
}

.porte .face {
  border: 2px dashed rgba(255, 248, 236, 0.75);
  background: rgba(20, 14, 40, 0.25);
  font-family: 'BioRhyme', serif;
  font-size: clamp(2rem, 6vw, 3.4rem);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

.porte .dos {
  transform: rotateY(180deg);
  padding: 8px;
  background: var(--creme);
  color: var(--texte);
  border: 2px solid var(--or);
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
  font-size: clamp(0.75rem, 1.6vw, 1rem);
  overflow: hidden;
}

.porte .dos img { max-width: 100%; max-height: 100%; object-fit: contain; }

.porte.ouverte .face { transform: rotateY(-180deg); }
.porte.ouverte .dos { transform: rotateY(0); }
.porte.ouverte:not(.gagnee) .dos { opacity: 0.8; }

.porte.du-jour { cursor: pointer; }
.porte.du-jour .face {
  border: 3px solid var(--or);
  color: var(--or);
  background: rgba(20, 14, 40, 0.45);
  animation: lueur 1.8s ease-in-out infinite;
}
.porte.du-jour:hover .face, .porte.du-jour:focus-visible .face { background: rgba(20, 14, 40, 0.65); }
.porte.du-jour:disabled { cursor: wait; }

.porte.fermee .face { cursor: not-allowed; }
.porte.passee .face { opacity: 0.45; }
.porte.secoue { animation: secoue 0.4s; }

@keyframes lueur {
  50% { box-shadow: 0 0 22px 4px rgba(246, 199, 90, 0.7); }
}

@keyframes secoue {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  .porte .face, .porte .dos { transition: none; }
  .porte.du-jour .face, .porte.secoue { animation: none; }
}

/* === Fenêtre de résultat === */

.resultat {
  max-width: min(420px, calc(100vw - 32px));
  border: 3px solid var(--or);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  background: var(--creme);
  color: var(--texte);
}
.resultat::backdrop { background: rgba(0, 0, 0, 0.6); }
.resultat-titre { font-weight: 700; font-size: 1.15rem; }
.resultat-gain { margin: 12px 0 18px; font-family: 'BioRhyme', serif; font-size: 1.5rem; font-weight: 700; color: var(--rouge); }
.resultat-gain img { max-width: 220px; max-height: 220px; }

/* === Admin === */

body.page-admin { background: #f5f2f8; color: var(--texte); }
.page-admin .entete, .page-admin .pied { background: var(--nuit); color: var(--creme); }
.page-admin main a { color: #6b3fd1; }
.page-admin h1 { font-family: 'BioRhyme', serif; }

.admin-nav { display: flex; flex-wrap: wrap; gap: 18px; padding: 16px 0 4px; font-weight: 600; }
.admin-message { padding: 10px 14px; border-radius: 6px; background: #e3f4e8; color: var(--vert); }
.admin-message.erreur { background: #fbe4e1; color: var(--rouge); }
.aide { color: var(--gris); font-size: 0.92rem; }
.badge { margin-left: 6px; padding: 2px 8px; border-radius: 10px; background: var(--vert); color: #fff; font-size: 0.75rem; }

.panneau { margin: 20px 0; padding: 16px 20px; border-radius: 10px; background: #fff; border: 1px solid var(--bord); }
.panneau h2 { margin-top: 0; }

.tableau { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--bord); }
.tableau th, .tableau td { padding: 8px 10px; border-bottom: 1px solid var(--bord); text-align: left; vertical-align: middle; }
.tableau form { margin: 0; }
.tableau tr.remis { color: var(--gris); }
@media (max-width: 640px) { .tableau { display: block; overflow-x: auto; } }

.formulaire { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.formulaire.en-ligne { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.formulaire label, .carte-gain label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; font-weight: 600; }
.formulaire input:not([type=file]), .formulaire select, .carte-gain input:not([type=file]):not([type=checkbox]) {
  padding: 6px 8px;
  border: 1px solid var(--bord);
  border-radius: 5px;
  font: inherit;
  font-weight: 400;
  min-width: 0;
}
.formulaire input[name=titre] { width: min(420px, 80vw); }
.formulaire label.case-ligne { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.essai { display: flex; align-items: center; gap: 16px; margin-top: 14px; padding: 10px; border-radius: 8px; background: #faf7fc; }
.essai p { margin: 0; }
.apercus { display: flex; flex-wrap: wrap; gap: 24px; }
.apercu { max-width: 110px; max-height: 110px; object-fit: contain; border: 1px solid var(--bord); border-radius: 6px; background: #faf7fc; }
.apercu.large { max-width: 280px; }

.carte-gain {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 20px;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--bord);
  border-radius: 8px;
}
.carte-gain.nouveau { border-style: dashed; }
.carte-gain .champs { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); align-content: start; gap: 10px; }
.carte-gain .champs .libelle { grid-column: 1 / -1; }
.carte-gain label.case { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.carte-gain .image-gain { display: flex; flex-direction: column; gap: 6px; max-width: 220px; }
.carte-gain .sortis { margin: 0; color: var(--gris); font-size: 0.9rem; }
.carte-gain .actions { grid-column: 1 / -1; display: flex; gap: 10px; }
@media (max-width: 640px) { .carte-gain { grid-template-columns: 1fr; } }

.bouton {
  padding: 8px 16px;
  border: 0;
  border-radius: 6px;
  background: var(--vert);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.bouton.petit { padding: 4px 10px; font-size: 0.85rem; }
.bouton.danger { background: var(--rouge); }
.bouton.secondaire { background: var(--gris); }
