/* ==================================================================== */
/* Nidoo — styles (thème ludique pour les enfants)                      */
/* Les couleurs et dimensions principales sont réglables ci-dessous.    */
/* Les couleurs des widgets sont dans js/widgets.js (Nidoo.COULEURS).   */
/* ==================================================================== */

:root {
  --fond: #fff6e5;            /* fond de la page */
  --pois: #ffe2b8;            /* petits pois décoratifs du fond */
  --texte: #3b2a5c;
  --texte-doux: #8a7aa8;
  --bouton: #ffffff;
  --bouton-ombre: #e6d3b3;

  --marge: 20px;              /* espace autour de la grille */
  --ecart: 16px;              /* espace entre les widgets */
  --colonnes: 4;              /* nombre de colonnes (adapté à l'écran plus bas) */
  --lignes: 6;                /* nombre de lignes qui doivent tenir dans la hauteur de l'écran */
  --arrondi: 26px;            /* coins arrondis des widgets */
  --relief: 6px;              /* épaisseur de l'effet "relief" sous les widgets */
  --hauteur-barre: 64px;      /* hauteur de la barre du haut */

  /* Taille d'une case : selon la largeur ET la hauteur de l'écran (la plus petite des deux), */
  /* pour que toute la grille tienne sur un iPad sans faire défiler.                          */
  --case-largeur: calc((100vw - 2 * var(--marge) - (var(--colonnes) - 1) * var(--ecart)) / var(--colonnes));
  --case-hauteur: calc((100dvh - var(--hauteur-barre) - var(--marge) - var(--relief) - 12px
                        - (var(--lignes) - 1) * (var(--ecart) + var(--relief))) / var(--lignes));
  --case: min(var(--case-largeur), var(--case-hauteur));

  --police: "Fredoka", ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
}

/* Mode sombre automatique : un ciel de nuit étoilé. */
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #1f1b3d;
    --pois: #2c2756;
    --texte: #f4f0ff;
    --texte-doux: #a9a2d0;
    --bouton: #34306a;
    --bouton-ombre: #16132e;
  }
}

/* Nombre de colonnes et de lignes selon l'écran :                                  */
/*   iPad à l'horizontale : 6 colonnes × 4 lignes                                     */
/*   iPad à la verticale  : 4 colonnes × 6 lignes                                     */
/*   petit écran          : 2 colonnes, on fait défiler                               */
@media (orientation: landscape) and (min-width: 900px) { :root { --colonnes: 6; --lignes: 4; } }
@media (max-width: 600px) { :root { --colonnes: 2; --case: var(--case-largeur); } }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--texte);
  font-family: var(--police);
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}

body {
  /* Fond à pois */
  background-color: var(--fond);
  background-image: radial-gradient(var(--pois) 3px, transparent 3.5px);
  background-size: 34px 34px;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* -------------------------------------------------------------------- */
/* Barre du haut                                                        */
/* -------------------------------------------------------------------- */

.barre {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: calc(env(safe-area-inset-top) + var(--hauteur-barre));
  padding: env(safe-area-inset-top) var(--marge) 0;
}

/* Le titre : chaque lettre a sa couleur et sautille. */
.titre {
  margin: 0;
  display: flex;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 1px;
}
.titre span {
  display: inline-block;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  animation: sautiller 2.4s ease-in-out infinite;
}
.titre span:nth-child(1) { color: #ef476f; animation-delay: 0s; }
.titre span:nth-child(2) { color: #ff9f1c; animation-delay: 0.15s; }
.titre span:nth-child(3) { color: #8ac926; animation-delay: 0.3s; }
.titre span:nth-child(4) { color: #3a86ff; animation-delay: 0.45s; }
.titre span:nth-child(5) { color: #8338ec; animation-delay: 0.6s; }

@keyframes sautiller {
  0%, 60%, 100% { transform: translateY(0) rotate(0); }
  30%           { transform: translateY(-6px) rotate(-4deg); }
}

.actions { display: flex; gap: 12px; }

/* Bouton "bonbon" avec relief qui s'enfonce quand on appuie. */
.bouton {
  border: 0;
  border-radius: 999px;
  padding: 9px 20px;
  background: var(--bouton);
  box-shadow: 0 5px 0 var(--bouton-ombre);
  font-size: 1.1rem;
  font-weight: 600;
  transition: transform 0.08s, box-shadow 0.08s;
}
.bouton:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--bouton-ombre);
}

#bouton-ajouter {
  background: #8ac926;
  color: #1f3300;
  box-shadow: 0 5px 0 #64a000;
}
.edition #bouton-modifier {
  background: #3a86ff;
  color: #fff;
  box-shadow: 0 5px 0 #1d63d6;
}

/* -------------------------------------------------------------------- */
/* La grille                                                            */
/* -------------------------------------------------------------------- */

.grille {
  display: grid;
  grid-template-columns: repeat(var(--colonnes), minmax(0, 1fr));
  grid-auto-rows: var(--case);
  grid-auto-flow: dense;          /* bouche les trous automatiquement */
  gap: calc(var(--ecart) + var(--relief)) var(--ecart);
  padding: 12px var(--marge) calc(env(safe-area-inset-bottom) + var(--marge) + var(--relief));
  max-width: calc(var(--colonnes) * var(--case) + (var(--colonnes) - 1) * var(--ecart) + 2 * var(--marge));
  margin: 0 auto;
}

.vide {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--texte-doux);
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.6;
  margin-top: 12vh;
}
.vide::before {
  content: "🧸";
  display: block;
  font-size: 4rem;
  margin-bottom: 8px;
  animation: sautiller 2.4s ease-in-out infinite;
}

/* -------------------------------------------------------------------- */
/* Un widget                                                            */
/* Ses couleurs viennent de --w-fond, --w-ombre et --w-texte,           */
/* posées par js/app.js selon la couleur choisie.                       */
/* -------------------------------------------------------------------- */

.widget {
  --w-fond: #3a86ff;
  --w-ombre: #1d63d6;
  --w-texte: #ffffff;

  position: relative;
  background: var(--w-fond);
  color: var(--w-texte);
  border-radius: var(--arrondi);
  box-shadow:
    0 var(--relief) 0 var(--w-ombre),
    0 calc(var(--relief) + 10px) 24px rgba(0, 0, 0, 0.12);
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.12s ease-out;
  animation: apparaitre 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Un petit "rebond" quand on appuie sur un widget. */
body:not(.edition) .widget:active { transform: scale(0.97); }

@keyframes apparaitre {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.taille-petit { grid-column: span 1; grid-row: span 1; }
.taille-moyen { grid-column: span 2; grid-row: span 1; }
.taille-grand { grid-column: span 2; grid-row: span 2; }

/* Le contenu prend toute la place ; "container-type" permet aux widgets */
/* d'adapter la taille du texte à leur case (unités cqmin, cqw...).     */
.contenu {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  container-type: size;
}

/* Décor : deux bulles claires dans les coins de chaque widget. */
.contenu::before,
.contenu::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  pointer-events: none;
}
.contenu::before { width: 60cqmin; height: 60cqmin; top: -22cqmin; right: -18cqmin; }
.contenu::after  { width: 26cqmin; height: 26cqmin; bottom: -8cqmin; left: 10cqmin; }

.contenu > * { position: relative; z-index: 1; }

.widget-inconnu {
  margin: 0;
  padding: 16px;
  font-weight: 600;
}

/* -------------------------------------------------------------------- */
/* Mode "Modifier"                                                      */
/* -------------------------------------------------------------------- */

.bouton-widget {
  display: none;
  position: absolute;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #ffffff;
  color: #3b2a5c;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.bouton-supprimer { top: -12px; left: -12px; background: #ef476f; color: #fff; font-size: 1.6rem; }
.bouton-taille    { bottom: -12px; right: -12px; }
.bouton-couleur   { bottom: -12px; left: -12px; }
.bouton-reglages  { top: -12px; right: -12px; }

.edition .bouton-widget { display: grid; place-items: center; }

.edition .widget {
  cursor: grab;
  touch-action: none;             /* le doigt déplace le widget au lieu de faire défiler */
  animation: trembler 0.28s ease-in-out infinite alternate;
}
.edition .widget:nth-child(2n) { animation-delay: -0.14s; }

/* En mode "Modifier", on ne peut pas utiliser le contenu des widgets. */
.edition .contenu { pointer-events: none; }

@keyframes trembler {
  from { transform: rotate(-1.2deg); }
  to   { transform: rotate(1.2deg); }
}

/* Moins d'animations si l'appareil le demande. */
@media (prefers-reduced-motion: reduce) {
  .titre span, .vide::before, .widget { animation: none; }
  .edition .widget { animation: none; outline: 3px dashed var(--texte-doux); outline-offset: 4px; }
}

/* Pendant un glisser-déposer */
.widget.en-deplacement { opacity: 0.3; animation: none; }

.fantome {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  animation: none !important;
  transform: scale(1.06) rotate(3deg);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

/* -------------------------------------------------------------------- */
/* Fenêtre "Ajouter un widget"                                          */
/* -------------------------------------------------------------------- */

.galerie {
  border: 0;
  border-radius: 32px;
  padding: 28px;
  width: min(560px, calc(100vw - 32px));
  background: var(--fond);
  color: var(--texte);
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.15), 0 30px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
}
.galerie[open] { animation: apparaitre 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.galerie::backdrop { background: rgba(40, 20, 80, 0.45); }
.galerie h2 { margin: 0 0 22px; font-size: 1.8rem; font-weight: 700; }

/* Fenêtre "Réglages" */
.champs { display: grid; gap: 16px; text-align: left; margin-bottom: 24px; }
.champ { display: grid; gap: 6px; font-weight: 600; }
.champ input,
.champ textarea {
  width: 100%;
  padding: 12px 14px;
  border: 3px solid var(--bouton-ombre);
  border-radius: 16px;
  background: var(--bouton);
  color: var(--texte);
  font: inherit;
  font-weight: 500;
}
.champ textarea { resize: vertical; line-height: 1.4; }
.champ input:focus,
.champ textarea:focus { outline: none; border-color: #3a86ff; }
.champ small { color: var(--texte-doux); font-weight: 500; line-height: 1.35; }
.boutons-fenetre { display: flex; gap: 12px; justify-content: center; }
.bouton-principal { background: #3a86ff; color: #fff; box-shadow: 0 5px 0 #1d63d6; }

.liste-widgets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.choix-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 8px;
  border: 0;
  border-radius: 24px;
  background: var(--w-fond);
  color: var(--w-texte);
  box-shadow: 0 6px 0 var(--w-ombre);
  font-size: 1.2rem;
  font-weight: 600;
  transition: transform 0.08s, box-shadow 0.08s;
}
.choix-widget:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--w-ombre); }
.choix-widget .icone { font-size: 2.6rem; }

/* ==================================================================== */
/* Styles des widgets (un bloc par widget)                              */
/* Utiliser var(--w-texte) pour la couleur du texte.                    */
/* ==================================================================== */

/* --- Horloge --- */
.horloge {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4cqmin;
  padding: 8cqmin;
}
.horloge-heure {
  font-size: 36cqmin;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1.2cqmin 0 rgba(0, 0, 0, 0.15);
}
.horloge-date {
  font-size: 11cqmin;
  font-weight: 600;
  text-align: center;
  opacity: 0.9;
}
.taille-petit .horloge-heure { font-size: 30cqmin; }
.taille-petit .horloge-date  { font-size: 12cqmin; }

/* --- Note --- */
.note {
  width: 100%;
  height: 100%;
  border: 0;
  resize: none;
  padding: 22px 24px;
  background: transparent;
  color: var(--w-texte);
  font: inherit;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.4;
  outline: none;
}
.note::placeholder { color: var(--w-texte); opacity: 0.65; }

/* --- Éléments communs aux widgets --- */
.widget-message {
  margin: 0;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 12px;
  text-align: center;
  font-weight: 600;
}

.widget-entete {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 14px 18px 8px;
  font-size: 1.3rem;
  font-weight: 700;
}
.compteur {
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.3);
  font-size: 1rem;
}

/* Liste dans un widget (courses, routine, agenda) : la liste défile si elle est longue. */
.liste-widget { height: 100%; display: flex; flex-direction: column; }
.liste-widget ul {
  flex: 1;
  margin: 0 6px 10px 0;       /* laisse un peu d'air à droite de la barre de défilement */
  padding: 0 8px 0 14px;
  list-style: none;
  overflow-y: auto;

  /* Barre de défilement discrète : fine, un peu transparente, sans fond. */
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--w-texte) 40%, transparent) transparent;
}

/* Même chose pour les navigateurs qui utilisent l'ancienne méthode (Safari plus ancien). */
.liste-widget ul::-webkit-scrollbar { width: 6px; }
.liste-widget ul::-webkit-scrollbar-track { background: transparent; }
.liste-widget ul::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--w-texte) 40%, transparent);
  border-radius: 999px;
}
.liste-vide { padding: 10px 4px; opacity: 0.85; font-weight: 600; }

/* Cases à cocher rondes */
.cases li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 4px;
  font-size: 1.15rem;
  font-weight: 600;
  transition: opacity 0.3s, transform 0.3s;
}
.case {
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 3px solid currentColor;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  font-weight: 700;
}
.cases li.fait .case,
.cases li.coche .case { background: var(--w-texte); color: var(--w-fond); }
.cases li.fait .case::after,
.cases li.coche .case::after { content: "✓"; }
.cases li.fait span { text-decoration: line-through; opacity: 0.7; }
.cases li.coche { opacity: 0; transform: translateX(30px); }

.bravo {
  margin: 0 14px 6px;
  padding: 6px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.3);
  text-align: center;
  font-weight: 700;
}

/* Ligne d'ajout (courses) */
.ajout { display: flex; gap: 8px; padding: 8px 14px 14px; }
.ajout input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  color: #3b2a5c;
  font: inherit;
  font-weight: 600;
}
.ajout input:focus { outline: 3px solid rgba(255, 255, 255, 0.8); }
.ajout button {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--w-texte);
  color: var(--w-fond);
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}

/* --- Météo et Tempo (même mise en page : une colonne par jour) --- */
.meteo,
.tempo {
  height: 100%;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: center;
  padding: 4cqh 3cqw;
}
.meteo-jour,
.tempo-jour {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-weight: 600;
}
.meteo-titre,
.tempo-titre { font-size: max(13px, 10cqh); font-weight: 700; }
.meteo-icone { font-size: 30cqh; line-height: 1.1; }
.meteo-temp  { font-size: 22cqh; font-weight: 700; line-height: 1; }
.meteo-minmax { font-size: max(12px, 8cqh); opacity: 0.9; }

.tempo-pastille {
  width: 42cqh;
  height: 42cqh;
  margin: 4cqh 0;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 1.5cqh 0 rgba(0, 0, 0, 0.15);
  display: grid;
  place-items: center;
  font-size: 22cqh;
  font-weight: 700;
}
.tempo-nom    { font-size: max(13px, 11cqh); font-weight: 700; }
.tempo-detail { font-size: max(11px, 8cqh); opacity: 0.85; }

/* --- Agenda --- */
.agenda li { padding: 3px 4px; }
.agenda-jour {
  margin-top: 6px;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.85;
}
.agenda-evt {
  display: flex;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
}
.agenda-heure {
  flex: none;
  min-width: 4.2em;
  padding: 1px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.28);
  text-align: center;
  font-size: 0.9rem;
}
.agenda-exemple {
  margin-bottom: 4px;
  padding: 4px 10px !important;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.15);
  font-size: 0.85rem;
  font-weight: 600;
}
