/* Calendrier de l'Avent — maquette, style générique de départ (à affiner). */
:root {
  --bg: #f4f4f5;
  --surface: #fff;
  --text: #18181b;
  --muted: #71717a;
  --faint: #a1a1aa;
  --border: #e4e4e7;
  --locked: #e9e9ec;
  --accent: #dc2626;
  --dark: #18181b;
  --font: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", "Noto Sans", sans-serif;
  --safe-top: max(env(safe-area-inset-top), 16px);
  --safe-bottom: max(env(safe-area-inset-bottom), 16px);
  --seek-zone: calc(env(safe-area-inset-bottom, 0px) + 30px); /* hauteur réservée à la barre de lecture */
  --ease: cubic-bezier(.32, .72, 0, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
svg { display: block; }
h1, h2, p { margin: 0; }

.screen { min-height: 100dvh; padding: var(--safe-top) 16px calc(var(--safe-bottom) + 32px); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 46px; padding: 0 18px;
  border-radius: 10px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-block { width: 100%; }
.btn-dark { background: var(--dark); color: #fff; }
.btn-outline { background: var(--surface); border: 1px solid var(--border); }
.btn-light { background: #fff; color: var(--text); }
.btn-ghost { background: rgba(255, 255, 255, .2); color: #fff; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }

/* ---------- Connexion ---------- */
#login { display: grid; place-items: center; }
.login-card { width: 100%; max-width: 360px; padding: 28px 22px 22px; }
.login-card h1 { margin-bottom: 24px; font-size: 24px; font-weight: 700; text-align: center; }
.login-card label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.login-card input {
  display: block; width: 100%; height: 48px; padding: 0 14px; margin-bottom: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; font: inherit; font-size: 17px; color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--dark); }
.error { margin: -6px 0 14px; font-size: 14px; color: var(--accent); }

/* ---------- Calendrier ---------- */
.page-head { padding: 12px 2px 18px; }
.page-head h1 { font-size: 26px; font-weight: 700; line-height: 1.2; }
.page-head p { margin-top: 4px; font-size: 15px; line-height: 1.4; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  display: grid; place-items: center; user-select: none; -webkit-user-select: none;
  background: var(--locked); color: var(--faint); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums;
  transition: transform .2s var(--ease);
}
.tile:active { transform: scale(.95); }
.tile .lock { position: absolute; top: 7px; right: 7px; width: 13px; height: 13px; fill: var(--faint); }
.tile.is-ready { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1), 0 0 0 1.5px var(--accent); }
.tile .badge { position: absolute; top: 8px; right: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.tile.is-open { color: #fff; }
.tile.is-open img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile.is-open::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0, 0, 0, .5), transparent 55%); }
.tile.is-open .num { position: absolute; z-index: 1; left: 8px; bottom: 5px; font-size: 16px; }
.tile.reveal img { animation: reveal 1.1s var(--ease) both; }
@keyframes reveal { from { opacity: 0; transform: scale(1.35); filter: blur(14px); } to { opacity: 1; transform: none; filter: none; } }

.shake { animation: shake .42s; }
@keyframes shake {
  0%, 100% { translate: 0; } 20% { translate: -6px; } 40% { translate: 5px; } 60% { translate: -3px; } 80% { translate: 2px; }
}

/* ---------- Lecteur ---------- */
.player { position: fixed; inset: 0; z-index: 10; background: #000; color: #fff; overflow: hidden; touch-action: none; }
.photo { position: absolute; inset: 0; opacity: 0; overflow: hidden; }
.photo-bg { position: absolute; inset: -12%; width: 124%; height: 124%; object-fit: cover; filter: blur(40px) brightness(.5) saturate(1.3); }
.photo-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }

.cam { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; transform-origin: 0 0; will-change: transform; z-index: 1; }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; border-radius: inherit; }
.cam.is-pip { box-shadow: 0 12px 40px rgba(0, 0, 0, .5); cursor: grab; }

.player-top {
  position: absolute; z-index: 4; top: var(--safe-top); left: 16px; right: 12px;
  display: flex; justify-content: space-between; align-items: center; pointer-events: none;
}
.player-day { font-size: 16px; font-weight: 600; text-shadow: 0 1px 8px rgba(0, 0, 0, .6); }
.icon-btn { pointer-events: auto; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, .4); }
.icon-btn svg { width: 22px; height: 22px; fill: #fff; }

.big-play {
  position: absolute; z-index: 4; inset: 0; margin: auto; width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, .45); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.big-play svg { width: 38px; height: 38px; fill: #fff; margin-left: 4px; }

.end-actions {
  position: absolute; z-index: 5; left: 0; right: 0; bottom: calc(var(--seek-zone) + 14px);
  display: flex; justify-content: center; gap: 12px;
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .35s, transform .5s var(--ease);
}
.end-actions.is-on { opacity: 1; transform: none; pointer-events: auto; }
.player.is-scrubbing .end-actions { opacity: 0; pointer-events: none; }
.end-actions .btn { min-width: 120px; height: 50px; border-radius: 25px; }

/* Barre de lecture tout en bas, façon Reels : fine, elle s'épaissit quand on la fait glisser */
.seek {
  position: absolute; z-index: 6; left: 0; right: 0; bottom: env(safe-area-inset-bottom, 0px);
  height: 30px; display: flex; align-items: flex-end; cursor: pointer; touch-action: none;
}
.seek:focus-visible { outline: none; }
.seek-track { position: relative; width: 100%; height: 3px; background: rgba(255, 255, 255, .3); transition: height .2s var(--ease), margin .2s var(--ease); }
.seek-fill { position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--p, 0) * 100%); background: #fff; }
.seek-thumb {
  position: absolute; top: 50%; left: calc(var(--p, 0) * 100%); width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .4); transform: scale(0); transition: transform .2s var(--ease);
}
.seek.is-scrubbing .seek-track, .seek:focus-visible .seek-track { height: 6px; margin-bottom: 5px; } /* remonte pour que le rond reste visible */
.seek.is-scrubbing .seek-thumb, .seek:focus-visible .seek-thumb { transform: scale(1); }
.seek-time {
  position: absolute; z-index: 6; left: 50%; bottom: calc(var(--seek-zone) + 16px); transform: translateX(-50%);
  font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
  text-shadow: 0 1px 10px rgba(0, 0, 0, .7); opacity: 0; transition: opacity .2s; pointer-events: none;
}
.seek-time.is-on { opacity: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 60; left: 50%; top: calc(var(--safe-top) + 6px);
  padding: 10px 16px; border-radius: 10px; background: var(--dark); color: #fff;
  font-size: 15px; font-weight: 500; white-space: nowrap; box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
  opacity: 0; transform: translate(-50%, -16px); pointer-events: none;
  transition: opacity .25s, transform .4s var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Admin ---------- */
.day-list { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.day-list li + li { border-top: 1px solid var(--border); }
.day-row { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; color: inherit; text-decoration: none; }
.day-row:active { background: var(--bg); }
.thumb { flex: none; width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--locked); }
.thumb-empty { display: grid; place-items: center; font-size: 15px; font-weight: 700; color: var(--faint); }
.day-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.day-name { display: flex; align-items: center; gap: 6px; font-size: 16px; font-weight: 600; }
.day-status { font-size: 14px; color: var(--muted); }
.day-status.is-missing { color: var(--faint); }
.day-row > svg { flex: none; width: 22px; height: 22px; fill: var(--faint); }
.tag { font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--locked); color: var(--muted); }
.tag-today { background: #fee2e2; color: var(--accent); }

.back { display: inline-flex; align-items: center; margin: 8px 0 4px -6px; font-size: 16px; font-weight: 500; color: var(--muted); text-decoration: none; }
.back svg { width: 26px; height: 26px; fill: currentColor; }
.day-title { margin: 4px 2px 18px; font-size: 26px; font-weight: 700; }
.section { padding: 16px; margin-bottom: 14px; }
.section h2 { margin-bottom: 12px; font-size: 17px; font-weight: 700; }
.photo-preview { aspect-ratio: 4 / 3; margin-bottom: 12px; border-radius: 10px; overflow: hidden; background: var(--locked); display: grid; place-items: center; }
.photo-preview img { width: 100%; height: 100%; object-fit: contain; background: #000; }
.photo-preview p { color: var(--faint); }
.section .btn-outline { width: 100%; }
.upload { margin-top: 12px; }
.bar { height: 6px; border-radius: 3px; background: var(--locked); overflow: hidden; }
.bar span { display: block; width: 0; height: 100%; background: var(--dark); transition: width .1s linear; }
.upload p { margin-top: 8px; font-size: 14px; color: var(--muted); }
.hint { margin-bottom: 12px; font-size: 14px; color: var(--muted); }

.edit-cam { position: relative; display: block; width: 56%; margin: 0 auto; aspect-ratio: 9 / 16; border-radius: 12px; overflow: hidden; background: #000; }
.edit-cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.edit-play { position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, .45); }
.edit-play svg { width: 30px; height: 30px; fill: #fff; margin-left: 3px; }
.scrub { position: relative; margin-top: 16px; }
.scrub input { position: relative; z-index: 1; -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 28px; margin: 0; background: transparent; }
.scrub input::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--locked); }
.scrub input::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: var(--dark); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.scrub input::-moz-range-track { height: 6px; border-radius: 3px; background: var(--locked); }
.scrub input::-moz-range-thumb { width: 18px; height: 18px; border: 3px solid #fff; border-radius: 50%; background: var(--dark); }
.marker {
  position: absolute; z-index: 0; top: 3px; width: 4px; height: 22px; border-radius: 2px; background: var(--accent);
  left: calc(11px + (100% - 22px) * var(--r, 0)); transform: translateX(-50%); pointer-events: none;
}
.times { display: flex; justify-content: space-between; margin-top: 2px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn-row { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 8px; margin-top: 12px; }
.btn-row .btn { padding: 0 8px; }
.editor-note { margin-top: 12px; font-size: 14px; line-height: 1.45; color: var(--muted); }
.editor-note strong { color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .tile.reveal img, .shake { animation: none !important; }
}

/* ---------- Fond de nuit (connexion + calendrier) ---------- */
.scene, .snow { display: none; }
body[data-screen="login"], body[data-screen="calendar"] { background: #0b1530; }
body[data-screen="login"] .scene, body[data-screen="calendar"] .scene { display: block; }
body[data-screen="calendar"] .snow { display: block; }
/* Le fond ne bouge jamais : il fait la taille du grand écran (barre de Safari réduite) et tout y est
   placé par rapport au haut. --bar = hauteur que prend la barre de Safari quand elle est grande :
   le sol et les Pères Noël sont posés juste au-dessus, et le sol continue dessous jusqu'en bas.
   Dans l'app installée il n'y a pas de barre : zone visible (dvh) et --bar à 0. */
:root { --bar: 0px; }
@supports (height: 100svh) { :root { --bar: calc(100lvh - 100svh); } }
.scene { position: fixed; left: 0; right: 0; top: 0; height: 100vh; height: 100lvh; z-index: 0; overflow: hidden; background: linear-gradient(#0b1530 0%, #142650 55%, #24407a 100%); }
@media (display-mode: standalone) {
  :root { --bar: 0px; }
  .scene { height: 100dvh; }
}
.scene-inner { position: relative; height: 100%; max-width: 440px; margin: 0 auto; }
.stars { position: absolute; left: 0; top: 0; width: 100%; height: 60%; }
.garland { position: absolute; left: 0; top: calc(var(--safe-top) - 26px); width: 100%; height: 70px; overflow: visible; }
.hill { position: absolute; left: 0; bottom: var(--bar); width: 100%; }
.ground { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--bar) + 1px); background: #f3f7fd; }
.hill-back { height: 96px; fill: #cfdcf1; }
.hill-front { height: 62px; fill: #f3f7fd; }
.santa { position: absolute; height: 150px; width: auto; }
.santa-suspendu { height: 140px; }
.santa-bisou { left: 6%; bottom: calc(var(--bar) + 14px); }
.santa-hotte { left: 34%; bottom: calc(var(--bar) + 10px); }
body[data-screen="login"] .santa { display: none; } /* ils n'apparaissent qu'une fois connectée */
body[data-screen="login"] .hill, body[data-screen="login"] .ground { display: none; } /* pas de collines enneigées sur la connexion */

/* Neige : toujours à la taille du grand écran (barre de Safari réduite), pour ne pas changer de taille
   pendant que la barre se réduit ou s'agrandit ; dans l'app installée, la zone visible (dvh). */
.snow { position: fixed; left: 0; top: 0; z-index: 5; width: 100%; height: 100vh; height: 100lvh; pointer-events: none; }
@media (display-mode: standalone) { .snow { height: 100dvh; } }

/* Calendrier sur le ciel de nuit */
#login, #calendar { position: relative; z-index: 1; }
#calendar .page-head { padding-top: 24px; color: #fff; }
#calendar .page-head p { color: rgba(255, 255, 255, .72); }
#calendar .grid { max-width: 352px; margin: 0 auto; gap: 8px; }
#calendar .tile:not(.is-ready):not(.is-open) { background: rgba(255, 255, 255, .13); color: rgba(255, 255, 255, .6); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); }
#calendar .tile .lock { fill: rgba(255, 255, 255, .45); }
#calendar .tile.is-ready { box-shadow: 0 0 0 2px var(--accent), 0 4px 18px rgba(0, 0, 0, .35); }

/* Père Noël pendu à l'envers sous la case 24 : ses jambes passent derrière la case */
#calendar .grid { position: relative; }
.santa-24 {
  position: absolute; z-index: -1; top: calc(100% - 24px); right: calc((100% - 24px) / 8 - 45px);
  width: 90px; height: auto; pointer-events: none;
  transform-origin: 50% 5%; /* il se balance depuis ses pieds */
  animation: swing 3.6s ease-in-out infinite alternate;
}
@keyframes swing { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@media (prefers-reduced-motion: reduce) { .santa-24 { animation: none; } }

/* Cheminée qui surgit au-dessus d'une case : le Père Noël sort du conduit puis y rentre */
.chimney { position: absolute; z-index: 2; pointer-events: none; transform-origin: 50% 100%; }
.chimney-clip { position: absolute; left: -20%; right: -20%; top: -10%; height: calc(10% + 81.6%); overflow: hidden; }
.chimney-santa { position: absolute; left: 14.286%; top: 10.917%; width: 71.429%; transform-origin: 50% 85%; } /* = la boîte de la cheminée */
.chimney-bricks { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- Ajouts du site ---------- */
.btn:disabled { opacity: .6; cursor: default; }
label.btn:has(input:disabled) { opacity: .5; pointer-events: none; }
.link { color: #2563eb; font-weight: 500; text-decoration: none; white-space: nowrap; }
.hint.is-error { color: var(--accent); }
.section .hint + .btn { margin-top: 2px; }

/* Connexion : pas de guirlande, carte translucide bleutée sur le ciel de nuit */
body[data-screen="login"] .garland { display: none; }
#login .login-card {
  background: rgba(110, 145, 225, .16); border: 1px solid rgba(255, 255, 255, .18); color: #fff;
  -webkit-backdrop-filter: blur(18px) saturate(140%); backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
#login .login-card label { color: rgba(255, 255, 255, .75); }
#login .login-card input { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .25); color: #fff; }
#login .login-card input:focus { border-color: rgba(255, 255, 255, .6); }
#login .btn-dark { background: #fff; color: #0b1530; }
#login .error { color: #ff9b9b; }
