/* =========================================================================
 * calendar.css — Calendrier interactif & suivi du temps
 *   Panneau latéral (Flexbox), jauge du dodo, voile du coucher,
 *   grille mensuelle (CSS Grid), icônes animées, bulle ludique.
 * ========================================================================= */

/* ---------- Tableau de bord : 3 cartes (devoirs, calendrier, boutique) ---------- */
.kid-top { grid-template-columns: 1.6fr 1fr 1fr; }

/* ---------- Icônes du ciel (soleil levant, grand soleil, lune) ---------- */
.sky { display: inline-block; vertical-align: middle; overflow: visible; }
.sky-lg { width: 96px; height: 96px; }
.sky-md { width: 54px; height: 54px; flex: none; }
.sky-xs { width: 22px; height: 22px; }
.sky-sunrise .rise { animation: sunRise 3.2s ease-in-out infinite alternate; }
.sky-sunrise .rays { animation: raysGlow 1.6s ease-in-out infinite alternate; }
.sky-sun .spin { transform-origin: 50px 50px; animation: spin 12s linear infinite; }
.sky-moon { animation: moonFloat 4s ease-in-out infinite; }
.sky-moon .twinkle { animation: twinkle 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.sky-moon .t2 { animation-delay: .6s; }
.sky-moon .t3 { animation-delay: 1.1s; }
@keyframes sunRise { from { transform: translateY(14px); } to { transform: translateY(-2px); } }
@keyframes raysGlow { from { opacity: .35; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes moonFloat { 50% { transform: translateY(-5px) rotate(-4deg); } }
@keyframes twinkle { 50% { opacity: .2; transform: scale(.6); } }

/* ---------- Panneau latéral « Ma journée » (fixé à gauche) ---------- */
:root { --panel-w: 172px; }
body.with-daypanel #app { padding-left: calc(var(--panel-w) + 28px); }
.day-panel {
  position: fixed; left: 12px; top: 12px; bottom: 12px; width: var(--panel-w); z-index: 40;
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 10px;
  border-radius: 28px; box-shadow: var(--shadow); color: var(--ink); overflow: hidden;
  background: linear-gradient(180deg, #fff3d6, #ffffff 55%);
  transition: background 1.5s;
}
.day-panel[data-period="midi"] { background: linear-gradient(180deg, #cdeeff, #ffffff 60%); }
.day-panel[data-period="soir"] { background: linear-gradient(180deg, #2b2d6e, #5a4fa8 55%, #8e7cc3); color: #fff; }
.dp-date { margin: 0; font-size: .8rem; text-transform: capitalize; text-align: center; opacity: .8; }
.dp-period { margin: -4px 0 0; font-weight: 700; font-size: 1.05rem; }
.dp-clock { margin: 0; font-size: 2rem; font-weight: 700; letter-spacing: .03em; font-variant-numeric: tabular-nums; }
.dodo-gauge { flex: 1; min-height: 160px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 4px; }
.dg-end { display: flex; flex-direction: column; align-items: center; line-height: 1; font-size: 1.6rem; }
.dg-end small { font-size: .75rem; font-weight: 600; opacity: .8; }
.dg-tube {
  position: relative; flex: 1; width: 46px; border-radius: 999px; background: rgba(139, 92, 246, .12);
  border: 3px solid rgba(139, 92, 246, .35);
}
.dg-fill {
  position: absolute; left: 3px; right: 3px; bottom: 3px; max-height: calc(100% - 6px); border-radius: 999px;
  background: linear-gradient(0deg, #ffd166 0%, #ff9e6d 45%, #8b5cf6 80%, #3a2f8f 100%);
  transition: height 1.2s ease, width 1.2s ease;
}
.dg-bear { position: absolute; left: 50%; transform: translateX(-50%); font-size: 1.5rem; transition: bottom 1.2s ease; animation: bearBob 2.4s ease-in-out infinite; }
.dg-star { position: absolute; font-size: .7rem; color: #c4b5fd; animation: twinkle 2s infinite; }
.dg-star.s1 { left: -14px; top: 12%; }
.dg-star.s2 { right: -14px; top: 28%; animation-delay: .7s; }
.dg-star.s3 { left: -12px; top: 46%; animation-delay: 1.3s; }
.dodo-gauge[data-stage="bientot"] .dg-tube { border-color: #8b5cf6; animation: pulseGauge 1.6s infinite; }
.dodo-gauge[data-stage="dodo"] .dg-bear { animation: none; }
.dg-left { margin: 0; text-align: center; font-size: .95rem; line-height: 1.25; }
.dp-cal {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; background: rgba(255, 255, 255, .85);
  color: var(--ink); text-decoration: none; font-weight: 600; box-shadow: 0 3px 0 rgba(0, 0, 0, .08);
}
@keyframes bearBob { 50% { transform: translateX(-50%) translateY(-4px) rotate(6deg); } }
@keyframes pulseGauge { 0%, 100% { box-shadow: 0 0 0 4px rgba(139, 92, 246, .25); } 50% { box-shadow: 0 0 0 12px rgba(139, 92, 246, .08); } }

/* ---------- Coucher : voile sombre + message ---------- */
.bedtime-dim { position: fixed; inset: 0; background: #120d3a; opacity: 0; pointer-events: none; z-index: 90; transition: opacity 2s ease; }
.bedtime-banner {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 95; width: min(640px, calc(100% - 32px));
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 22px; color: #fff;
  background: linear-gradient(135deg, #4c3fb4, #2b2d6e); box-shadow: 0 10px 30px rgba(0, 0, 0, .3); animation: slideUp .4s;
}
body.with-daypanel .bedtime-banner { left: calc(50% + var(--panel-w) / 2 + 6px); width: min(640px, calc(100% - var(--panel-w) - 60px)); }
.bb-icon { font-size: 2rem; animation: moonFloat 3s infinite; }
.bb-text { flex: 1; font-weight: 600; font-size: 1.05rem; }
.bedtime-banner .btn { flex: none; }

/* ---------- Icônes d'événements animées ---------- */
.ev-icon { --s: 30px; width: var(--s); height: var(--s); display: inline-grid; place-items: center; flex: none; }
.ev-icon .ev-svg { width: 100%; height: 100%; overflow: visible; }
.ev-emoji { font-size: calc(var(--s) * .82); line-height: 1; }
.ev-sm { --s: 24px; }
.ev-md { --s: 46px; }
.ev-lg { --s: 72px; }
.anim-bob { animation: evBob 2.2s ease-in-out infinite; }
.anim-swing { animation: evSwing 2s ease-in-out infinite; transform-origin: 50% 10%; }
.anim-pulse { animation: evPulse 1.8s ease-in-out infinite; }
.anim-wiggle { animation: evWiggle 2.6s ease-in-out infinite; }
.ev-svg .smoke { animation: smoke 2.4s ease-out infinite; }
.ev-cont { opacity: .55; }
@keyframes evBob { 50% { transform: translateY(-3px); } }
@keyframes evSwing { 25% { transform: rotate(10deg); } 75% { transform: rotate(-10deg); } }
@keyframes evPulse { 50% { transform: scale(1.15); } }
@keyframes evWiggle { 0%, 70%, 100% { transform: rotate(0); } 80% { transform: rotate(-10deg); } 90% { transform: rotate(10deg); } }
@keyframes smoke { 0% { opacity: 0; transform: translateY(4px); } 40% { opacity: .9; } 100% { opacity: 0; transform: translateY(-8px); } }

/* ---------- Grille du mois ---------- */
.cal-card { background: #fff; border-radius: 28px; padding: 16px; box-shadow: var(--shadow); }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.cal-title { margin: 0; font-size: 1.8rem; text-transform: capitalize; }
.cal-title small { color: var(--muted); font-size: .7em; }
.cal-nav { width: 60px; height: 60px; border-radius: 50%; border: 0; background: #f3effd; font-size: 1.4rem; cursor: pointer; box-shadow: 0 4px 0 rgba(42, 35, 80, .12); }
.cal-nav:active { transform: translateY(3px); box-shadow: none; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; touch-action: pan-y; }
.cal-wd { text-align: center; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-wd.weekend { color: var(--pink); }
.cal-day {
  position: relative; min-height: clamp(64px, 11vh, 104px); border: 0; border-radius: 16px; background: #faf8ff;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px; padding: 6px 2px;
  cursor: pointer; overflow: hidden; color: var(--ink); font-family: inherit;
}
.cal-day.weekend { background: #fff4f8; }
.cal-day.past { opacity: .45; }
.cal-day.cal-out { background: transparent; cursor: default; }
.cal-day.has-ev { background: #fff; box-shadow: 0 3px 0 rgba(42, 35, 80, .08); }
.cal-day:active:not(.cal-out) { transform: scale(.95); }
.cal-num { font-weight: 700; font-size: 1.15rem; position: relative; }
.cal-evs { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; position: relative; }
.cal-more { font-size: .75rem; font-weight: 700; color: var(--muted); align-self: center; }
.cal-band { position: absolute; inset: 0; background: var(--band); opacity: .13; }
.cal-day.today { outline: 4px solid var(--primary); background: #f1ebff; animation: todayGlow 2s ease-in-out infinite; opacity: 1; }
.cal-day.today .cal-num { color: #fff; background: var(--primary); border-radius: 999px; padding: 0 9px; }
.cal-today-tag { font-size: .62rem; font-weight: 700; color: var(--primary-d); text-transform: uppercase; position: relative; }
.cal-day.selected { outline: 3px dashed var(--orange); }
@keyframes todayGlow { 50% { box-shadow: 0 0 0 8px rgba(139, 92, 246, .18); } }
.cal-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 18px; margin: 14px 0; }
.cal-leg { display: inline-flex; align-items: center; gap: 6px; background: #fff; padding: 6px 12px; border-radius: 999px; box-shadow: 0 3px 0 rgba(0, 0, 0, .05); font-weight: 600; }
.next-event {
  display: flex; align-items: center; gap: 14px; width: 100%; border: 0; cursor: pointer; margin-bottom: 14px; padding: 12px 18px;
  border-radius: 22px; background: #fff; box-shadow: var(--shadow); border-left: 10px solid var(--ec); text-align: left; font-family: inherit; color: var(--ink);
}
.next-event span { display: flex; flex-direction: column; flex: 1; font-size: 1.3rem; }
.next-event small { color: var(--muted); font-size: .8rem; text-transform: uppercase; font-weight: 700; }
.next-event .ne-dodos { flex: none; font-size: 1.6rem; font-weight: 700; color: var(--ec); }

/* ---------- Bulle ludique ---------- */
.cal-bubble-backdrop { position: fixed; inset: 0; z-index: 110; display: grid; place-items: center; padding: 16px; background: rgba(30, 20, 60, .35); animation: fadeIn .15s; }
.cal-bubble-backdrop.closing { opacity: 0; transition: opacity .18s; }
.cal-bubble {
  position: relative; width: min(460px, 100%); max-height: 88vh; overflow: auto; background: #fff; border-radius: 34px; padding: 22px 20px 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .25); animation: bubbleIn .35s cubic-bezier(.3, 1.6, .5, 1);
  display: flex; flex-direction: column; gap: 12px;
}
.cal-close { position: absolute; top: 10px; right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: #f3effd; font-size: 1.1rem; cursor: pointer; z-index: 2; }
.cb-date { margin: 0; text-align: center; font-weight: 700; color: var(--muted); text-transform: capitalize; padding: 0 40px; }
.cb-card {
  position: relative; border-radius: 24px; padding: 14px 16px; text-align: center;
  background: color-mix(in srgb, var(--ec, var(--primary)) 10%, white);
  border: 3px solid color-mix(in srgb, var(--ec, var(--primary)) 35%, white);
}
.cb-card.is-past { opacity: .6; }
.cb-top { display: flex; align-items: center; justify-content: center; gap: 12px; text-align: left; padding-right: 40px; }
.cb-top b { display: block; font-size: 1.6rem; }
.cb-top small { color: var(--muted); }
.cb-dodos { font-size: 1.7rem; font-weight: 700; margin: 10px 0 4px; color: color-mix(in srgb, var(--ec, var(--primary)) 70%, black); }
.dodo-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px; font-size: 1.8rem; }
.dodo-row span { animation: pop .4s backwards; }
.dodo-big { font-size: 2.6rem; font-weight: 700; }
.cb-moment { display: inline-flex; align-items: center; gap: 10px; margin-top: 10px; padding: 6px 16px 6px 8px; border-radius: 999px; background: #fff; font-size: 1.25rem; font-weight: 700; }
.cb-moment span { display: flex; flex-direction: column; text-align: left; line-height: 1.15; }
.cb-moment small { font-size: .85rem; color: var(--muted); font-weight: 600; }
.cb-note { margin: 10px 0 0; font-size: 1.05rem; }
.cb-say { position: absolute; top: 10px; right: 10px; }
.cb-empty { --ec: #8b5cf6; }
@keyframes bubbleIn { from { transform: scale(.3) translateY(40px); opacity: 0; } }

/* ---------- Espace parent : création des événements ---------- */
.cal-parent { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; margin-bottom: 18px; }
.cal-parent .card { margin: 0; }
.cal-parent .cal-day { min-height: 58px; }
.cal-parent .cal-title { font-size: 1.3rem; }
.cal-parent .cal-nav { width: 46px; height: 46px; }
.ev-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.form .ev-type { position: relative; }
.ev-type input { position: absolute; opacity: 0; pointer-events: none; }
.ev-type span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 12px 8px; min-height: 100px;
  border-radius: 18px; border: 3px solid var(--line); background: #fff; cursor: pointer; text-align: center; font-size: .9rem;
}
.ev-type input:checked + span { border-color: var(--ec); background: color-mix(in srgb, var(--ec) 12%, white); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ec) 25%, transparent); }
.ev-type input:focus-visible + span { outline: 3px solid var(--primary); }
.ev-cell { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Tablette portrait ---------- */
@media (max-width: 1000px) {
  .cal-parent { grid-template-columns: 1fr; }
  .kid-top { grid-template-columns: 1fr 1fr; }
  .kid-top .progress-card { grid-column: 1 / -1; }
}

/* ---------- Téléphone : le panneau devient une barre en haut ---------- */
@media (max-width: 700px) {
  :root { --panel-w: 0px; }
  body.with-daypanel #app { padding-left: 16px; padding-top: 100px; }
  .day-panel { left: 8px; right: 8px; top: 8px; bottom: auto; width: auto; height: 82px; flex-direction: row; padding: 8px 14px; border-radius: 22px; }
  .day-panel .sky-lg { width: 54px; height: 54px; }
  .dp-date, .dg-star, .dg-bear, .dg-left, .dp-cal span { display: none; }
  .dp-clock { font-size: 1.5rem; }
  .dodo-gauge { flex-direction: row; min-height: 0; height: 100%; }
  .dg-tube { height: 22px; width: auto; flex: 1; align-self: center; }
  .dg-fill { top: 3px; bottom: 3px; right: auto; height: auto !important; width: var(--fill, 0); max-width: calc(100% - 6px); }
  .dg-end { font-size: 1.1rem; }
  .kid-top { grid-template-columns: 1fr; }
  body.with-daypanel .bedtime-banner { left: 50%; width: calc(100% - 32px); top: 100px; }
}
