:root {
  --fond: #f7f5ef;
  --carte: #ffffff;
  --texte: #24221d;
  --doux: #6f6a5f;
  --ligne: #ebe6da;
  --accent: #6aa84f; /* remplacé par la couleur de la mascotte */
  --accent-2: #ff8a65;
  --accent-fond: #f1f8e9;
  --prot: #e57373;
  --gluc: #f6b93b;
  --lip: #64b5f6;
  --danger: #d9534f;
  --rayon: 22px;
  --ombre: 0 1px 2px rgba(40, 30, 10, 0.05), 0 6px 20px rgba(40, 30, 10, 0.06);
  --police: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #171612;
    --carte: #22211c;
    --texte: #f2efe6;
    --doux: #a8a294;
    --ligne: #34322b;
    --ombre: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
  /* les illustrations ont une ombre claire au sol : on garde un fond pastel derrière elles */
  .mascotte-scene { background: var(--accent-fond); }
  .mascotte-scene > .doux, .mascotte-scene > h1 { color: #2b2820; }
  .carte .mascotte, .choix .mascotte, .celebration .mascotte { background: radial-gradient(circle at 50% 55%, var(--accent-fond) 62%, transparent 63%); }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--fond); color: var(--texte); font-family: var(--police); font-size: 16px; }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.1rem; font-weight: 800; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
[hidden] { display: none !important; }

#app { max-width: 560px; margin: 0 auto; }
#vue { padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 110px); display: flex; flex-direction: column; gap: 14px; }

.carte { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 16px; }
.ligne-titre { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.doux { color: var(--doux); }
.petit { font-size: 0.85rem; }
.centre { text-align: center; }

/* ---------- En-tête date ---------- */
.entete { display: flex; align-items: center; justify-content: space-between; }
.entete .date-nav { display: flex; align-items: center; gap: 4px; }
.rond { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--carte); box-shadow: var(--ombre); font-size: 1.1rem; }
.rond:disabled { opacity: 0.35; }
.titre-jour small { display: block; color: var(--doux); font-size: 0.85rem; font-weight: 600; }

/* ---------- Scène mascotte ---------- */
.mascotte-scene { background: var(--accent-fond); border-radius: var(--rayon); padding: 14px; display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; position: relative; overflow: hidden; }
.mascotte-scene .infos { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.bulle { background: var(--carte); border-radius: 18px; padding: 10px 12px; font-size: 0.92rem; line-height: 1.35; position: relative; box-shadow: var(--ombre); }
.bulle::before { content: ''; position: absolute; left: -7px; top: 18px; border: 8px solid transparent; border-right-color: var(--carte); border-left: 0; }
.pastilles { display: flex; gap: 6px; flex-wrap: wrap; }
.pastille { background: var(--carte); border-radius: 999px; padding: 3px 9px; font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.xp-barre { height: 8px; background: color-mix(in srgb, var(--accent) 18%, transparent); border-radius: 99px; overflow: hidden; }
.xp-barre > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.6s ease; }

.mascotte { width: var(--taille); height: var(--taille); position: relative; flex: none; }
.mascotte img, .mascotte-svg, .mascotte-svg svg { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; }
.mascotte img, .mascotte-svg { transform-origin: 50% 95%; }
.mascotte.verrouille img, .mascotte.verrouille .mascotte-svg { filter: grayscale(1) brightness(0.6) opacity(0.35); }
.humeur-radieux img, .humeur-radieux .mascotte-svg { animation: sautille 1.1s ease-in-out infinite; }
.humeur-content img, .humeur-content .mascotte-svg { animation: respire 3s ease-in-out infinite; }
.humeur-neutre img, .humeur-neutre .mascotte-svg { animation: respire 4.5s ease-in-out infinite; }
.humeur-affame img, .humeur-affame .mascotte-svg { animation: penche 2.6s ease-in-out infinite; filter: saturate(0.85); }
.humeur-inquiet img, .humeur-inquiet .mascotte-svg { animation: tremble 2.2s ease-in-out infinite; }
.humeur-endormi img, .humeur-endormi .mascotte-svg { animation: respire 5s ease-in-out infinite; filter: saturate(0.6) brightness(0.95); }
.verrouille img, .verrouille .mascotte-svg { animation: none !important; }
.zzz { position: absolute; right: 4%; top: 6%; font-weight: 800; color: var(--doux); font-size: calc(var(--taille) * 0.12); animation: flotte 2.4s ease-in-out infinite; }
.zzz span { font-size: 0.8em; margin-left: 2px; }
@keyframes sautille { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-9%) scale(1.02, 0.98); } 60% { transform: translateY(0) scale(1.04, 0.96); } }
@keyframes respire { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03, 0.98); } }
@keyframes penche { 0%, 100% { transform: rotate(-3deg) translateY(2%); } 50% { transform: rotate(3deg) translateY(2%); } }
@keyframes tremble { 0%, 80%, 100% { transform: translateX(0); } 84% { transform: translateX(-2%); } 88% { transform: translateX(2%); } 92% { transform: translateX(-2%); } 96% { transform: translateX(1%); } }
@keyframes flotte { 0%, 100% { transform: translateY(0); opacity: 0.6; } 50% { transform: translateY(-8px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .mascotte * { animation: none !important; } }

/* ---------- Résumé calories ---------- */
.resume { display: grid; grid-template-columns: 128px 1fr; gap: 16px; align-items: center; }
.anneau { position: relative; width: 128px; height: 128px; }
.anneau svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.anneau .val { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.anneau .val b { font-size: 1.55rem; font-weight: 800; line-height: 1; }
.anneau .val span { font-size: 0.75rem; color: var(--doux); font-weight: 600; }
.macros { display: flex; flex-direction: column; gap: 10px; }
.macro .tete { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: 700; margin-bottom: 4px; }
.macro .tete span:last-child { color: var(--doux); font-weight: 600; }
.jauge { height: 9px; background: var(--ligne); border-radius: 99px; overflow: hidden; }
.jauge > i { display: block; height: 100%; border-radius: 99px; transition: width 0.5s ease; }

/* ---------- Repas ---------- */
.repas .ligne-titre h3 { display: flex; align-items: center; gap: 8px; }
.repas .kcal-repas { color: var(--doux); font-weight: 700; font-size: 0.9rem; }
.items { list-style: none; margin: 8px 0 0; padding: 0; }
.items li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--ligne); }
.items li:first-child { border-top: 0; }
.items .nom { flex: 1; min-width: 0; }
.items .nom b { font-weight: 650; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items .nom small { color: var(--doux); font-size: 0.78rem; }
.items .kc { font-weight: 800; font-size: 0.95rem; white-space: nowrap; }
.suppr { width: 30px; height: 30px; border-radius: 50%; color: var(--doux); font-size: 1rem; }
.suppr:active { background: var(--ligne); }
.ajout-repas { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Boutons ---------- */
.btn { border-radius: 14px; padding: 11px 16px; font-weight: 750; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; transition: transform 0.1s; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; }
.btn.second { background: color-mix(in srgb, var(--accent) 14%, var(--carte)); color: var(--texte); }
.btn.fantome { background: transparent; color: var(--accent); padding: 8px 10px; min-height: 36px; }
.btn.plein { width: 100%; }
.btn.danger { background: transparent; color: var(--danger); }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Analyses IA ---------- */
.analyse h2 { margin-bottom: 4px; }
.analyse .bloc { margin-top: 12px; }
.analyse .bloc h3 { font-size: 0.88rem; color: var(--doux); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.analyse ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.analyse .conseil { margin-top: 12px; background: var(--accent-fond); border-radius: 14px; padding: 10px 12px; font-weight: 600; }
.sugg { border: 1px solid var(--ligne); border-radius: 16px; padding: 12px; margin-top: 10px; }
.sugg .ligne-titre b { font-size: 1rem; }
.chargement { display: flex; align-items: center; gap: 10px; color: var(--doux); font-weight: 600; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--ligne); border-top-color: var(--accent); animation: tourne 0.8s linear infinite; flex: none; }
@keyframes tourne { to { transform: rotate(360deg); } }
.erreur { color: var(--danger); font-weight: 600; font-size: 0.92rem; }

/* ---------- Tab bar ---------- */
.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 560px; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px); background: color-mix(in srgb, var(--fond) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--ligne); z-index: 10; }
.tabbar button[data-tab] { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.7rem; font-weight: 700; color: var(--doux); padding: 4px 0; }
.tabbar .ico { font-size: 1.3rem; filter: grayscale(1); opacity: 0.7; }
.tabbar button.actif { color: var(--texte); }
.tabbar button.actif .ico { filter: none; opacity: 1; }
#fab { justify-self: center; width: 60px; height: 60px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 2rem; font-weight: 400; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent); margin-top: -26px; display: grid; place-items: center; }
#fab:active { transform: scale(0.94); }

/* ---------- Bottom sheet ---------- */
.sheet-fond { position: fixed; inset: 0; background: rgba(20, 15, 5, 0.35); z-index: 20; animation: apparait 0.2s; }
.sheet { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--fond); border-radius: 26px 26px 0 0; padding: 10px 16px calc(env(safe-area-inset-bottom) + 18px); z-index: 21; animation: monte 0.25s ease-out; display: flex; flex-direction: column; gap: 14px; }
.sheet .poignee { width: 42px; height: 5px; border-radius: 9px; background: var(--ligne); margin: 0 auto 2px; }
@keyframes monte { from { transform: translate(-50%, 40%); opacity: 0; } }
@keyframes apparait { from { opacity: 0; } }

.segments { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--ligne); border-radius: 14px; padding: 3px; gap: 3px; }
.segments button { border-radius: 11px; padding: 8px 4px; font-weight: 700; font-size: 0.88rem; color: var(--doux); }
.segments button.actif { background: var(--carte); color: var(--texte); box-shadow: var(--ombre); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 9px 13px; background: var(--carte); box-shadow: var(--ombre); font-weight: 650; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 6px; }
.chip small { color: var(--doux); font-weight: 600; }
.chip.actif { background: var(--accent); color: #fff; }
.chip.actif small { color: rgba(255, 255, 255, 0.85); }
.chip:active { transform: scale(0.96); }

label.champ { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 0.88rem; }
.champ input, .champ textarea, .champ select, input.champ-in { background: var(--carte); border: 1.5px solid var(--ligne); border-radius: 14px; padding: 12px 13px; font-size: 1rem; width: 100%; font-weight: 500; }
.champ input:focus, .champ textarea:focus, input.champ-in:focus { outline: none; border-color: var(--accent); }
textarea { resize: none; min-height: 86px; }
.grille-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grille-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.photo-zone { border: 2px dashed var(--ligne); border-radius: var(--rayon); padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; color: var(--doux); font-weight: 600; }
.photo-zone img { max-width: 100%; max-height: 220px; border-radius: 14px; }

.resultat-item { display: grid; grid-template-columns: 1fr 76px 30px; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--ligne); }
.resultat-item:first-child { border-top: 0; }
.resultat-item input { background: var(--carte); border: 1.5px solid var(--ligne); border-radius: 10px; padding: 7px 8px; width: 100%; font-weight: 700; text-align: right; }
.resultat-item small { color: var(--doux); display: block; font-size: 0.78rem; }

/* ---------- Historique ---------- */
.histo { list-style: none; padding: 0; margin: 0; }
.histo li { display: grid; grid-template-columns: 82px 1fr 64px; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--ligne); cursor: pointer; }
.histo li:first-child { border-top: 0; }
.histo .j { font-weight: 700; font-size: 0.88rem; }
.histo .j small { display: block; color: var(--doux); font-weight: 600; }
.histo .barre { height: 12px; background: var(--ligne); border-radius: 99px; position: relative; overflow: visible; }
.histo .barre i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.histo .barre .cible { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--texte); opacity: 0.35; }
.histo .v { text-align: right; font-weight: 800; font-size: 0.9rem; }
.histo li.vide .v { color: var(--doux); font-weight: 600; }
.semaine-graph { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 120px; margin-top: 12px; position: relative; }
.semaine-graph .col { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.semaine-graph .col i { width: 100%; max-width: 30px; border-radius: 8px 8px 4px 4px; background: var(--accent); min-height: 3px; }
.semaine-graph .col span { line-height: 18px; height: 18px; font-size: 0.72rem; color: var(--doux); font-weight: 700; }
.semaine-graph .ligne-cible { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--doux); opacity: 0.4; }

/* ---------- Page mascotte ---------- */
.hero { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 20px 16px; }
.hero .bulle::before { display: none; }
.stades { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.stades .st { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.7rem; font-weight: 700; text-align: center; color: var(--doux); }
.stades .st.ok { color: var(--texte); }
.choix-mascottes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choix { background: var(--carte); border-radius: 18px; padding: 10px; box-shadow: var(--ombre); display: flex; flex-direction: column; align-items: center; gap: 4px; border: 2px solid transparent; text-align: center; }
.choix.actif { border-color: var(--accent); }
.choix b { font-size: 0.95rem; }
.choix small { color: var(--doux); font-size: 0.75rem; line-height: 1.3; }
.xp-detail { list-style: none; padding: 0; margin: 8px 0 0; font-size: 0.88rem; }
.xp-detail li { display: flex; justify-content: space-between; padding: 4px 0; }
.xp-detail li b { color: var(--accent); }

/* ---------- Toast & célébration ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 92px); background: var(--texte); color: var(--fond); padding: 11px 16px; border-radius: 16px; font-weight: 700; z-index: 30; display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); animation: apparait 0.2s; }
.toast button { color: var(--accent-2); font-weight: 800; }
.celebration { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(20, 15, 5, 0.55); animation: apparait 0.3s; }
.celebration .carte { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 320px; animation: monte-centre 0.4s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes monte-centre { from { transform: scale(0.6); opacity: 0; } }
