:root {
  --nuit: #0b1f3a;
  --nuit-2: #10294b;
  --marque: #20589a;
  --marque-fonce: #034c96;
  --glace: #b3dde9;
  --glace-clair: #d2eaf2;
  --or: #f2b84b;
  --texte: #eef4fa;
  --texte-doux: #a9bfd6;
  --papier: #fbfcfd;
  --encre: #13263f;
  --rayon: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* L'attribut hidden doit l'emporter sur les display: flex des composants. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--texte);
  background-color: var(--nuit);
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255, 255, 255, 0.6), transparent),
    radial-gradient(1px 1px at 68% 9%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1.5px 1.5px at 85% 32%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 35% 45%, rgba(255, 255, 255, 0.4), transparent),
    radial-gradient(1px 1px at 52% 72%, rgba(255, 255, 255, 0.35), transparent),
    linear-gradient(180deg, var(--nuit) 0%, var(--nuit-2) 60%, #16345c 100%);
  background-attachment: fixed;
  line-height: 1.5;
}

button {
  font: inherit;
}

:focus-visible {
  outline: 3px solid var(--or);
  outline-offset: 3px;
}

/* Bandeau du mode aperçu */
.bandeau-apercu {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  background: var(--or);
  color: #2b1d05;
  font-size: 14px;
  font-weight: 600;
}

.bandeau-apercu a {
  color: inherit;
}

.bandeau-apercu button {
  border: 1px solid #2b1d05;
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 2px 12px;
  cursor: pointer;
}

/* En-tête */
.entete {
  display: flex;
  gap: 20px;
  align-items: center;
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 16px 8px;
}

.logo {
  width: 76px;
  height: auto;
  flex: none;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.35));
}

.surtitre {
  margin: 0;
  color: var(--glace);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 4px;
  font-size: clamp(28px, 6vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.accroche {
  margin: 0;
  color: var(--texte-doux);
  max-width: 52ch;
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

.statut {
  margin: 16px 0 20px;
  min-height: 1.5em;
  color: var(--glace-clair);
  font-weight: 600;
}

/* Grille des cases */
.grille {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(84px, auto);
  grid-auto-flow: dense;
  gap: 10px;
}

@media (min-width: 640px) {
  .grille {
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: 110px;
    gap: 14px;
  }
}

.grille li {
  display: flex;
}

.grille li.large {
  grid-column: span 2;
}

@media (min-width: 640px) {
  .grille li.haute {
    grid-row: span 2;
  }
}

.case {
  position: relative;
  flex: 1;
  min-height: 84px;
  padding: 0;
  border: 0;
  border-radius: var(--rayon);
  background: #081629;
  perspective: 700px;
  cursor: pointer;
  color: inherit;
}

.case .interieur {
  position: absolute;
  inset: 0;
  border-radius: var(--rayon);
  overflow: hidden;
  box-shadow: inset 0 0 0 2px rgba(179, 221, 233, 0.25);
}

.case .interieur canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.case .battant {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--rayon);
  background-color: var(--porte, var(--marque));
  background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 55%);
  box-shadow:
    inset 0 0 0 2px rgba(210, 234, 242, 0.35),
    0 6px 16px rgba(0, 0, 0, 0.35);
  transform-origin: left center;
  transition: transform 0.9s cubic-bezier(0.3, 1.45, 0.45, 1), box-shadow 0.3s;
  backface-visibility: hidden;
  overflow: hidden;
}

/* Teinte des portes : seule la couleur varie, les couches d'image (reflet, balayage) restent libres. */
.grille li:nth-child(3n) {
  --porte: var(--marque-fonce);
}

.grille li:nth-child(4n + 1) {
  --porte: #2f6db0;
}

.case .numero {
  font-size: clamp(26px, 6vw, 38px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.case .cadenas {
  position: absolute;
  right: 8px;
  bottom: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.case.verrouillee .battant {
  filter: saturate(0.5) brightness(0.8);
}

.case.disponible .battant::after {
  content: "Aujourd'hui";
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  color: #2b1d05;
  background: var(--or);
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.case.ouverte .battant {
  transform: rotateY(-105deg);
  box-shadow: none;
}

.case.ouverte .interieur::after {
  content: attr(data-jour);
  position: absolute;
  left: 8px;
  top: 6px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: rgba(11, 31, 58, 0.7);
  padding: 0 7px;
  border-radius: 999px;
}

.case.secoue {
  animation: secousse 0.4s;
}

@keyframes appel {
  0%,
  100% {
    box-shadow:
      inset 0 0 0 2px rgba(242, 184, 75, 0.9),
      0 0 0 0 rgba(242, 184, 75, 0.5);
  }
  50% {
    box-shadow:
      inset 0 0 0 2px rgba(242, 184, 75, 0.9),
      0 0 0 8px rgba(242, 184, 75, 0);
  }
}

@keyframes secousse {
  20%,
  60% {
    transform: translateX(-4px);
  }
  40%,
  80% {
    transform: translateX(4px);
  }
}

/* Fenêtre du jour */
.fenetre {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--papier);
  color: var(--encre);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  overflow: auto;
}

.fenetre::backdrop {
  background: rgba(4, 12, 26, 0.72);
  backdrop-filter: blur(3px);
}

.fenetre-corps {
  position: relative;
  padding: 16px 20px 20px;
}

.fermer {
  position: absolute;
  top: 22px;
  right: 26px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(11, 31, 58, 0.65);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.scene {
  position: relative;
  margin: 0 0 14px;
}

.scene canvas {
  display: block;
  width: 100%;
  aspect-ratio: 20 / 13;
  border-radius: 12px;
  background: var(--nuit);
  touch-action: manipulation;
}

.astuce {
  margin: 6px 0 0;
  font-size: 13px;
  color: #50657d;
}

.jour-etiquette {
  margin: 0;
  color: var(--marque);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.fenetre h2 {
  margin: 2px 0 8px;
  font-size: 24px;
  line-height: 1.2;
}

.message {
  margin: 0 0 10px;
  font-size: 17px;
}

.signature {
  margin: 0 0 16px;
  color: var(--marque);
  font-weight: 700;
  font-style: italic;
}

.fenetre-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid #e1e8ef;
  padding-top: 12px;
}

.fenetre-nav button {
  border: 1px solid #c9d6e3;
  background: #fff;
  color: var(--marque);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.fenetre-nav button:disabled {
  visibility: hidden;
}

/* Bulle d'information (case pas encore ouvrable) */
.bulle {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--papier);
  color: var(--encre);
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.pied {
  padding: 8px 16px 32px;
  text-align: center;
  color: var(--texte-doux);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
