:root {
  color-scheme: light dark;
  --nuit: #241B4F;
  --nuit-2: #352A6E;
  --etoile: #FFD66B;
  --rose: #D93A6B;
  --lagon: #12877A;
  --fond: #EEEBFA;
  --surface: #FFFFFF;
  --surface-2: #E3DFF6;
  --encre: #1D1838;
  --doux: #5B5480;
  --trait: #D3CDEE;
  --bulle-eux: #FFFFFF;
  --bulle-nous: #352A6E;
  --bulle-nous-txt: #FFFFFF;
  --brouillon: #FFF5D6;
  --brouillon-trait: #B98900;
  --police: ui-rounded, "SF Pro Rounded", Nunito, "Segoe UI Variable Text", Roboto, system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #16112F;
    --surface: #221A47;
    --surface-2: #2E2560;
    --encre: #F1EEFF;
    --doux: #B5AEDB;
    --trait: #3B3170;
    --bulle-eux: #2E2560;
    --bulle-nous: #5546A8;
    --brouillon: #3A3214;
    --brouillon-trait: #FFD66B;
    --rose: #FF7EA6;
    --lagon: #4BD8C5;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--fond); color: var(--encre); font: 16px/1.5 var(--police); -webkit-text-size-adjust: 100%; overflow-wrap: anywhere; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; font-weight: 800; }
h2 { font-size: 1.1rem; line-height: 1.3; margin: 0; font-weight: 800; }
p { margin: 0; }
a { color: inherit; }
.doux { color: var(--doux); }
.petit { font-size: .875rem; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--etoile); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Structure */
#app { min-height: 100%; }
.cadre { display: grid; grid-template-rows: 1fr; min-height: 100dvh; padding-bottom: calc(64px + var(--safe-b)); }
.page { width: 100%; max-width: 44rem; margin: 0 auto; padding: calc(16px + var(--safe-t)) 16px 24px; display: grid; gap: 16px; align-content: start; }
.onglets { position: fixed; z-index: 10; inset: auto 0 0 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--trait); padding-bottom: var(--safe-b); }
.onglet { display: grid; justify-items: center; gap: 2px; padding: 8px 0 7px; font-size: .72rem; font-weight: 700; text-decoration: none; color: var(--doux); position: relative; }
.onglet[aria-current="page"] { color: var(--encre); }
.onglet svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.onglet[aria-current="page"] svg { fill: var(--etoile); }
.pastille { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--rose); color: #fff; font-size: .7rem; line-height: 18px; text-align: center; }
@media (prefers-color-scheme: dark) { .pastille { color: #16112F; } }
@media (min-width: 900px) {
  .cadre { grid-template-columns: 200px 1fr; padding-bottom: 0; }
  .onglets { position: sticky; top: 0; height: 100dvh; grid-template-columns: 1fr; grid-auto-rows: min-content; border-top: 0; border-right: 1px solid var(--trait); padding: 16px 8px; gap: 4px; }
  .onglet { display: flex; align-items: center; gap: 12px; padding: 10px 12px; font-size: .95rem; border-radius: 12px; }
  .onglet[aria-current="page"] { background: var(--surface-2); }
  .pastille { position: static; margin-left: auto; }
  .page { padding-top: 24px; }
}

/* Éléments communs */
.bouton { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 16px; border-radius: 14px; border: 1px solid var(--trait); background: var(--surface); font-weight: 700; text-decoration: none; cursor: pointer; }
.bouton.fort { background: var(--nuit); border-color: var(--nuit); color: #fff; }
@media (prefers-color-scheme: dark) { .bouton.fort { background: var(--etoile); border-color: var(--etoile); color: #1D1838; } }
.bouton.danger { color: var(--rose); border-color: currentColor; background: transparent; }
.bouton.plat { background: transparent; border-color: transparent; padding-inline: 8px; }
.bouton:disabled { opacity: .55; cursor: default; }
.rang { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.entre { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pile { display: grid; gap: 8px; }
label.champ { display: grid; gap: 4px; font-weight: 700; font-size: .92rem; }
label.champ small { font-weight: 400; color: var(--doux); }
input[type=text], input[type=url], input[type=email], input[type=password], input[type=number], input[type=date], input:not([type]), textarea, select {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--trait); background: var(--surface); font-weight: 400;
}
textarea { min-height: 96px; resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; }
label.case { display: flex; gap: 10px; align-items: flex-start; min-height: 32px; }
label.case input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--nuit-2); }
.bloc { background: var(--surface); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.alerte { background: var(--brouillon); border-left: 4px solid var(--brouillon-trait); border-radius: 12px; padding: 12px; display: grid; gap: 6px; }
.alerte.rouge { border-left-color: var(--rose); }
.vide { padding: 24px 16px; text-align: center; color: var(--doux); display: grid; gap: 12px; justify-items: center; }
.puces { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; margin-inline: -16px; padding-inline: 16px; }
.puce { flex: none; min-height: 36px; display: inline-flex; align-items: center; padding: 4px 14px; border-radius: 18px; background: var(--surface); text-decoration: none; font-weight: 700; font-size: .9rem; color: var(--doux); }
.puce[aria-current="true"] { background: var(--nuit); color: #fff; }
@media (prefers-color-scheme: dark) { .puce[aria-current="true"] { background: var(--etoile); color: #1D1838; } }
.etat { display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--doux); white-space: nowrap; }
.etat.chaud { background: var(--etoile); color: #1D1838; }
.etat.alerte-e { background: var(--rose); color: #fff; }
@media (prefers-color-scheme: dark) { .etat.alerte-e { color: #16112F; } }
.etat.bon { background: var(--lagon); color: #fff; }
@media (prefers-color-scheme: dark) { .etat.bon { color: #16112F; } }
#toast { position: fixed; z-index: 30; left: 16px; right: 16px; bottom: calc(76px + var(--safe-b)); max-width: 28rem; margin: 0 auto; padding: 12px 16px; border-radius: 14px; background: var(--encre); color: var(--fond); font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .15s; }
#toast.visible { opacity: 1; }

/* Listes */
.liste { display: grid; gap: 1px; background: var(--trait); border-radius: 16px; overflow: hidden; }
.ligne { display: grid; gap: 2px; padding: 12px 16px; background: var(--surface); text-decoration: none; }
.ligne:focus-visible { outline-offset: -3px; }
.ligne .titre { font-weight: 800; }
.non-lu .titre::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--rose); margin-right: 8px; vertical-align: 2px; }
.chiffres { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .875rem; color: var(--doux); font-variant-numeric: tabular-nums; }
.apercu { color: var(--doux); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Le ciel de l'accueil */
.ciel { background: var(--nuit); color: #fff; margin: calc(-16px - var(--safe-t)) -16px 0; padding: calc(16px + var(--safe-t)) 16px 16px; border-radius: 0 0 28px 28px; display: grid; gap: 4px; }
@media (min-width: 720px) { .ciel { margin: 0; border-radius: 24px; padding: 20px; } }
.ciel h1 { font-size: 1.25rem; }
.ciel .doux { color: #C9C2F0; }
.ciel svg { width: 100%; max-width: 620px; height: auto; display: block; overflow: visible; margin: 0 auto; }
.ciel .fond-etoile { fill: #fff; opacity: .28; }
.ciel .chemin { fill: none; stroke: #8E82DA; stroke-width: 1.2; stroke-dasharray: 4 5; }
.ciel a { text-decoration: none; }
.ciel .astre { fill: var(--etoile); filter: drop-shadow(0 0 6px rgba(255, 214, 107, .75)); }
.ciel .astre.eteint { fill: none; stroke: #8E82DA; stroke-width: 1.2; filter: none; }
.ciel .nb { fill: #fff; font: 800 17px var(--police); text-anchor: middle; font-variant-numeric: tabular-nums; }
.ciel .nom { fill: #C9C2F0; font: 600 10.5px var(--police); text-anchor: middle; }
.ciel a:focus-visible .nom, .ciel a:hover .nom { fill: #fff; text-decoration: underline; }
.ciel a:focus { outline: none; }
@media (prefers-reduced-motion: no-preference) {
  .ciel.arrivee .chemin { animation: trace 1.1s ease-out both; stroke-dasharray: 600; }
  .ciel.arrivee .groupe-astre { animation: eclot .45s ease-out both; animation-delay: calc(var(--i) * 140ms + 120ms); transform-box: fill-box; transform-origin: center; }
  @keyframes trace { from { stroke-dashoffset: 600; } to { stroke-dashoffset: 0; } }
  @keyframes eclot { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: scale(1); } }
}

/* Connexion */
.connexion { min-height: 100dvh; display: grid; align-content: center; padding: 16px; background: var(--nuit); }
.connexion form { width: 100%; max-width: 24rem; margin: 0 auto; background: var(--surface); border-radius: 20px; padding: 20px; display: grid; gap: 14px; }

/* Conversation */
.conv-tete { position: sticky; top: 0; z-index: 5; background: var(--fond); padding: calc(8px + var(--safe-t)) 16px 8px; margin: calc(-16px - var(--safe-t)) -16px 0; display: grid; gap: 8px; border-bottom: 1px solid var(--trait); }
.segment { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 14px; }
.segment button { min-height: 40px; border: 0; background: transparent; border-radius: 11px; font-weight: 700; font-size: .875rem; cursor: pointer; color: var(--doux); }
.segment button[aria-pressed="true"] { background: var(--surface); color: var(--encre); box-shadow: 0 1px 2px rgba(29, 24, 56, .2); }
.segment button:disabled { opacity: .5; cursor: default; }
.fil { display: grid; gap: 10px; align-content: start; }
.bulle { max-width: 88%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; display: grid; gap: 4px; }
.bulle.eux { justify-self: start; background: var(--bulle-eux); border-bottom-left-radius: 6px; }
.bulle.nous { justify-self: end; background: var(--bulle-nous); color: var(--bulle-nous-txt); border-bottom-right-radius: 6px; }
.bulle .meta { font-size: .75rem; opacity: .75; white-space: normal; }
.bulle.annule { opacity: .55; text-decoration: line-through; background: transparent; color: var(--doux); border: 1px solid var(--trait); }
.brouillon { justify-self: stretch; background: var(--brouillon); border: 2px dashed var(--brouillon-trait); border-radius: 18px; padding: 12px; display: grid; gap: 10px; }
.brouillon textarea { background: var(--surface); min-height: 160px; }
.composer { display: grid; gap: 8px; }

/* Fiche */
.fiche-chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.fiche-chiffres strong { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.bouton.plat { font-size: 1.5rem; }
.score { display: flex; align-items: baseline; gap: 8px; }
.score strong { font-size: 1.6rem; }
details > summary { cursor: pointer; font-weight: 700; min-height: 32px; }
.journal { display: grid; gap: 6px; font-size: .9rem; }
.journal div { display: grid; gap: 0; border-bottom: 1px solid var(--trait); padding-bottom: 6px; }
