/* Jinglebox V1 — styles (mobile-first) */

:root {
  --night: #0b1428;
  --night-2: #13213d;
  --ink: #fdf8ef;
  --ink-soft: #d9d2c5;
  --gold: #f4c95d;
  --gold-strong: #ffd978;
  --red: #c0392b;
  --red-dark: #8e2318;
  --green: #1f7a4d;
  --green-dark: #135235;
  --blue: #2c5d9e;
  --blue-dark: #1b3d6b;
  --gold-box: #c9962c;
  --gold-box-dark: #8f6a1c;
  --grey: #5d6470;
  --radius: 14px;
  --shadow: 0 10px 24px rgba(0, 0, 0, .35);
  --font-title: "Georgia", "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--night);
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Fond du calendrier : image + voile sombre pour la lisibilité */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(6, 10, 22, .55) 0%, rgba(6, 10, 22, .72) 100%),
    var(--bg-image, none) center / cover no-repeat,
    var(--night);
}

body.is-error::before,
body.is-loading::before { background: var(--night); }

[hidden] { display: none !important; }

a { color: var(--gold-strong); }

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

/* ---------- En-tête ---------- */

.site-header {
  width: 100%;
  padding: 18px 16px 8px;
  text-align: center;
}

.site-title {
  margin: 0;
  font-family: var(--font-title);
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  letter-spacing: .02em;
  color: var(--gold-strong);
  text-shadow: 0 2px 12px rgba(244, 201, 93, .35);
}

.site-meta {
  margin: 2px 0 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--ink-soft);
  font-size: .95rem;
}

.site-progress::before {
  content: "·";
  margin-right: 10px;
}

/* ---------- Calendrier ---------- */

.calendar {
  width: 100%;
  max-width: 1120px;
  padding: 8px 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.calendar-notice {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(11, 20, 40, .7);
  color: var(--ink);
  text-align: center;
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.slot {
  transform: translate(var(--dx, 0), var(--dy, 0)) rotate(var(--rot, 0deg));
}

/* ---------- Cases ---------- */

.box {
  --box: var(--red);
  --box-dark: var(--red-dark);
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .18s ease;
}

.box--green { --box: var(--green); --box-dark: var(--green-dark); }
.box--gold { --box: var(--gold-box); --box-dark: var(--gold-box-dark); }
.box--blue { --box: var(--blue); --box-dark: var(--blue-dark); }

.box:hover { transform: translateY(-3px); }
.box:active { transform: translateY(0) scale(.97); }

/* Paquet cadeau dessiné en CSS */
.box-gift {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .18), transparent 55%),
    linear-gradient(160deg, var(--box), var(--box-dark));
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, .12);
  overflow: hidden;
}

.box-ribbon,
.box-ribbon::after {
  position: absolute;
  background: linear-gradient(90deg, #e9b949, #fbe29a, #e9b949);
}

.box-ribbon {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 14%;
  transform: translateX(-50%);
}

.box-ribbon::after {
  content: "";
  left: -300%;
  right: -300%;
  top: 34%;
  height: 100%;
  max-height: 14%;
  transform: translateY(-50%);
  background: linear-gradient(180deg, #e9b949, #fbe29a, #e9b949);
}

.box-lid {
  position: absolute;
  left: -2%;
  right: -2%;
  top: 0;
  height: 34%;
  background: linear-gradient(180deg, rgba(255, 255, 255, .12), rgba(0, 0, 0, .18));
  border-bottom: 2px solid rgba(0, 0, 0, .2);
  transform-origin: 0 100%;
}

.box-bow {
  position: absolute;
  left: 50%;
  top: 34%;
  width: 34%;
  height: 20%;
  transform: translate(-50%, -78%);
}

.box-bow::before,
.box-bow::after {
  content: "";
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  border: 4px solid #fbe29a;
  border-radius: 50% 50% 10% 50%;
}

.box-bow::before { left: 0; transform: rotate(-12deg); }
.box-bow::after { right: 0; transform: scaleX(-1) rotate(-12deg); }

.box-day {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  min-width: 2.2em;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(11, 20, 40, .82);
  color: var(--ink);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: clamp(1rem, 4.5vw, 1.5rem);
  line-height: 1.3;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}

/* Case fermée : petit cadenas */
.box.is-closed .box-gift::after {
  content: "";
  position: absolute;
  right: 8%;
  top: 8%;
  width: 14%;
  aspect-ratio: 1;
  border-radius: 3px;
  background: rgba(11, 20, 40, .55);
  box-shadow: 0 -5px 0 -2px rgba(11, 20, 40, .55);
}

.box.is-closed { cursor: not-allowed; }
.box.is-closed .box-gift { filter: saturate(.75) brightness(.9); }

/* Case ouverte avec pochette */
.box-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 0 0 2px rgba(255, 255, 255, .25);
  background: var(--night-2);
  z-index: 1;
}

.box.has-cover .box-gift { visibility: hidden; }

.box.has-cover .box-day {
  left: 6%;
  top: 6%;
  bottom: auto;
  transform: none;
  z-index: 2;
  font-size: clamp(.85rem, 3.6vw, 1.1rem);
}

.box.is-open:not(.has-cover) .box-lid,
.box.is-today.was-opened:not(.has-cover) .box-lid { transform: rotate(-14deg) translateY(-6%); }

.box.is-broken .box-gift {
  background: repeating-linear-gradient(135deg, #6b717c 0 10px, #5d6470 10px 20px);
}

/* Case du jour */
.box.is-today {
  z-index: 2;
}

.box.is-today .box-gift,
.box.is-today .box-cover {
  box-shadow: 0 0 0 3px var(--gold-strong), 0 0 22px 6px rgba(255, 217, 120, .55);
}

.box.is-today:not(.was-opened) .box-gift {
  animation: glow 2.4s ease-in-out infinite;
}

.box-tag {
  position: absolute;
  left: 50%;
  top: -10px;
  transform: translateX(-50%);
  z-index: 3;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gold-strong);
  color: #2b1d00;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 3px var(--gold-strong), 0 0 14px 3px rgba(255, 217, 120, .4); }
  50% { box-shadow: 0 0 0 3px var(--gold-strong), 0 0 28px 10px rgba(255, 217, 120, .7); }
}

/* Animation d’ouverture de la case du jour (600 ms) */
.box.is-opening { animation: shake .6s ease-in-out; }
.box.is-opening .box-lid { animation: lid-open .6s ease-in forwards; }
.box.is-opening .box-bow { animation: bow-pop .6s ease-in forwards; }

@keyframes shake {
  0% { transform: scale(1); }
  20% { transform: scale(1.06) rotate(-4deg); }
  40% { transform: scale(1.08) rotate(4deg); }
  60% { transform: scale(1.1) rotate(-2deg); }
  100% { transform: scale(1.12); }
}

@keyframes lid-open {
  0%, 35% { transform: none; }
  100% { transform: translateY(-60%) rotate(-28deg); opacity: .2; }
}

@keyframes bow-pop {
  0%, 35% { transform: translate(-50%, -78%); }
  100% { transform: translate(-50%, -260%) scale(1.3); opacity: 0; }
}

/* ---------- Bandeau playlist ---------- */

.banner {
  width: 100%;
  max-width: 720px;
  margin-bottom: 8px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(31, 122, 77, .92), rgba(19, 82, 53, .92));
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, .15);
  text-align: center;
}

.banner-text {
  margin: 0;
  font-size: 1.05rem;
}

.banner-text a {
  display: inline-block;
  margin: 2px 0;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--gold-strong);
  color: #2b1d00;
  font-weight: 700;
  text-decoration: none;
}

.banner-text a:hover { background: #fff0c2; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(11, 20, 40, .95);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, .15);
  color: var(--ink);
  text-align: center;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast:empty { display: none; }

/* ---------- Erreur globale ---------- */

.global-error {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 24px 16px;
}

.global-error-card {
  max-width: 420px;
  padding: 28px 24px;
  border-radius: var(--radius);
  background: var(--night-2);
  box-shadow: var(--shadow);
  text-align: center;
}

.global-error-title {
  margin: 0 0 6px;
  font-family: var(--font-title);
  font-size: 1.35rem;
  color: var(--gold-strong);
}

.global-error-text { margin: 0; color: var(--ink-soft); }

/* ---------- Popup ---------- */

.modal {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: auto;
}

.modal::backdrop {
  background: rgba(4, 8, 18, .78);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  min-height: 100%;
  padding: 56px 20px 28px;
  background: linear-gradient(180deg, var(--night-2), var(--night));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: var(--ink);
  cursor: pointer;
}

.modal-close:hover { background: rgba(255, 255, 255, .2); }

.modal-close svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  fill: none;
}

.modal-media {
  width: min(100%, 280px);
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--night);
  box-shadow: var(--shadow);
}

.modal-cover {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.track-broken {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: #4a4f58;
  cursor: not-allowed;
}

.track-broken svg { width: 45%; height: 45%; }
.track-broken-note { fill: #9aa0aa; }
.track-broken-slash { stroke: #c9cdd3; stroke-width: 5; stroke-linecap: round; }

.modal-title {
  margin: 0;
  min-height: 1.4em;
  font-size: 1.2rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.modal.is-broken .modal-title { display: none; }

.modal-error {
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(192, 57, 43, .18);
  border: 1px solid rgba(232, 110, 96, .6);
  color: #ffd9d4;
}

.player {
  width: 100%;
  max-width: 420px;
  min-height: 152px;
  border-radius: 12px;
  overflow: hidden;
}

.player iframe { display: block; border: 0; }

.modal-open {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 999px;
  background: #1db954;
  color: #04170b;
  font-weight: 700;
  text-decoration: none;
}

.modal-open:hover { background: #2fd567; }

/* ---------- Tablette ---------- */

@media (min-width: 600px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
  }

  .modal {
    width: min(440px, calc(100% - 32px));
    height: fit-content;
    max-height: calc(100% - 32px);
    margin: auto;
    border-radius: 20px;
  }

  .modal-card {
    min-height: 0;
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255, 255, 255, .1);
  }
}

/* ---------- Desktop : 6 × 4, tient sans défilement ---------- */

@media (min-width: 960px) {
  .calendar { gap: 14px; }

  .grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 22px;
    width: min(100%, calc((100vh - 170px) * 1.5));
    width: min(100%, calc((100dvh - 170px) * 1.5));
  }

  body[data-state="finished"] .grid {
    width: min(100%, calc((100vh - 270px) * 1.5));
    width: min(100%, calc((100dvh - 270px) * 1.5));
  }

  .box-day { font-size: 1.35rem; }
}

/* ---------- Très petit écran : grille régulière ---------- */

@media (max-width: 359px) {
  .grid { gap: 10px; }
  .slot { transform: none; }
}

/* ---------- Mouvement réduit ---------- */

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