/* =============================================================
   Anagnosis — feuille de style
   Applique docs/charte-visuelle.md. Les valeurs viennent de là ;
   ne pas en inventer ici.
   ============================================================= */

:root {
  /* Constantes — charte §2.1 */
  --papier: #F4EFE1;
  --encre-noire: #1B1A17;
  --jaune: #FFE800;
  --texte: #1B1A17;
  --texte-2: #5B5449;
  --texte-3: #8A8375;
  --filet: #D9CFB8;
  --voile: rgba(27, 26, 23, .045);

  /* Encre de discipline — posée par le JS sur <html> */
  --enc: #3D5588;
  --enc-clair: #5C7CBF;

  /* Mélange riso — charte §3 */
  --melange: multiply;
  --grain-opacite: .045;

  /* Espacement, base 4 — charte §5 */
  --e1: 4px;  --e2: 8px;  --e3: 12px; --e4: 16px;
  --e6: 24px; --e8: 32px; --e12: 48px; --e16: 64px;
  --marge: 20px;

  /* Typographie — charte §4 */
  --display: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  --corps: 'Newsreader', ui-serif, 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --mono: 'Martian Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --barre-h: 74px;
  --refuge: env(safe-area-inset-bottom, 0px);
}

html[data-theme='sombre'] {
  --papier: #241F1A;          /* noir chaud, jamais #000 — charte §2.1 */
  --texte: #EDE3D0;
  --texte-2: #B3A794;
  --texte-3: #7D7365;
  --filet: #3D362C;
  --voile: rgba(237, 227, 208, .06);
  --melange: screen;          /* la surimpression s'inverse sur fond sombre */
  --grain-opacite: .07;
}

* , *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--papier);
  color: var(--texte);
  font-family: var(--corps);
  font-size: 16.5px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
h1, h2, h3, h4, p, ul, ol { margin: 0; }
a { color: var(--enc); }

/* Rayon 0 partout — charte §5. Seule exception : 2 px sur une cible pleine. */
button, input, textarea, select { border-radius: 0; }

/* ---- grain, une seule fois sur la composition entière — charte §3 ---- */
.grain {
  position: fixed; inset: 0; z-index: 60; pointer-events: none;
  opacity: var(--grain-opacite);
  mix-blend-mode: var(--melange);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='90' height='90' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- structure ---- */
#app { min-height: 100%; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.ecran { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }
.defile {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--barre-h) + var(--refuge) + var(--e8));
}
.ecran.sans-barre .defile { padding-bottom: calc(var(--refuge) + var(--e8)); }
.bloc { padding: 0 var(--marge); }

/* ---- typographie ---- */
.sur-titre {
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--enc);
}
.titre-xl {
  font-family: var(--display); font-weight: 800; letter-spacing: -.032em;
  line-height: .96; font-size: clamp(30px, 8.6vw, 44px);
}
.titre-l {
  font-family: var(--display); font-weight: 800; letter-spacing: -.028em;
  line-height: 1.04; font-size: clamp(25px, 6.8vw, 34px);
}
.titre-m { font-family: var(--display); font-weight: 700; font-size: 19px; line-height: 1.15; letter-spacing: -.01em; }
.accroche { font-size: 17px; font-style: italic; color: var(--texte-2); line-height: 1.45; }
.mono { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.discret { color: var(--texte-2); font-size: 14px; }

/* ---- barre de titre (lecture) — écrans §3 ---- */
.barre-titre {
  position: sticky; top: 0; z-index: 5;
  background: var(--papier); border-bottom: 2px solid var(--encre-noire);
  padding: calc(env(safe-area-inset-top, 0px) + var(--e3)) var(--marge) var(--e2);
}
.barre-titre .ligne { display: flex; align-items: center; gap: var(--e2); }
.pastille { width: 12px; height: 12px; background: var(--enc); flex: 0 0 auto; }
.barre-titre .t {
  font-family: var(--display); font-weight: 700; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.progression { height: 3px; background: var(--filet); margin: var(--e2) calc(var(--marge) * -1) -2px; }
.progression i { display: block; height: 100%; background: var(--enc); }

/* ---- champ d'encre (illustration) — systeme-illustration.md ---- */
.champ { position: relative; overflow: hidden; isolation: isolate; height: 190px; }
.champ.haut { height: 240px; }
.aplat { position: absolute; mix-blend-mode: var(--melange); }
.champ figcaption { position: absolute; inset: auto 0 0; display: none; }

/* ---- boutons ---- */
.cta {
  display: block; width: 100%; min-height: 52px; padding: var(--e4);
  background: var(--encre-noire); color: var(--papier);
  font-family: var(--display); font-weight: 800; font-size: 16px; letter-spacing: -.01em;
  text-align: center;
}
html[data-theme='sombre'] .cta { background: var(--texte); color: var(--papier); }
.cta.encre { background: var(--enc); color: #F4EFE1; }
.cta.creux { background: none; color: var(--texte); border: 2px solid var(--texte); }
.cta:disabled { opacity: .32; cursor: not-allowed; }
.cta .app { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; opacity: .7; margin-left: var(--e2); }

/* ---- étiquettes ---- */
.etiq {
  display: inline-block; font-family: var(--mono); font-size: 9.5px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; padding: 4px 8px;
  border: 1.5px solid var(--filet); color: var(--texte-2);
}
.etiq.pleine { background: var(--enc); border-color: var(--enc); color: #F4EFE1; }
.etiq.noire { background: var(--encre-noire); border-color: var(--encre-noire); color: var(--jaune); }

/* ---- corps de fiche ---- */
.fiche-corps { font-family: var(--corps); font-size: 16.5px; line-height: 1.62; max-width: 45ch; }
.fiche-corps p { margin: 0 0 var(--e4); }
.fiche-corps h3 {
  font-family: var(--display); font-weight: 700; font-size: 19px; line-height: 1.15;
  letter-spacing: -.01em; margin: var(--e8) 0 var(--e3); padding-left: var(--e3);
  border-left: 4px solid var(--enc);
}
.encadre { margin: var(--e8) 0 0; padding: var(--e4); background: var(--voile); border-left: 4px solid var(--enc); }
.encadre p { font-size: 18px; line-height: 1.45; font-style: italic; }
.encadre cite { display: block; margin-top: var(--e2); font-family: var(--mono); font-size: 10px; letter-spacing: .06em; font-style: normal; color: var(--texte-2); }

.sources { margin-top: var(--e8); padding-top: var(--e4); border-top: 2px solid var(--encre-noire); }
html[data-theme='sombre'] .sources { border-top-color: var(--texte); }
.sources ol { padding-left: var(--e4); font-family: var(--display); font-weight: 400; font-size: 13px; line-height: 1.5; color: var(--texte-2); }
.sources li { margin-bottom: var(--e2); }
.sources b { color: var(--texte); font-weight: 600; }

/* ---- barre d'onglets — écrans §2 ---- */
.onglets {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  display: flex; max-width: 560px; margin: 0 auto;
  padding-bottom: var(--refuge);
  background: var(--papier); border-top: 2px solid var(--encre-noire);
}
html[data-theme='sombre'] .onglets { border-top-color: var(--texte); }
/* Liquid Glass — préférence utilisateur, cantonnée à cette barre (charte §6) */
.onglets.verre {
  background: rgba(244, 239, 225, .60);
  -webkit-backdrop-filter: blur(20px) saturate(185%);
  backdrop-filter: blur(20px) saturate(185%);
  border-top: 1px solid rgba(27, 26, 23, .16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
}
html[data-theme='sombre'] .onglets.verre {
  background: rgba(36, 31, 26, .52);
  border-top-color: rgba(237, 227, 208, .16);
}
.onglets button {
  flex: 1; min-height: 52px; padding: var(--e3) 2px calc(var(--e3) - 2px);
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  position: relative; color: var(--texte); opacity: .4;
}
.onglets button[aria-current='page'] { opacity: 1; }
.onglets button[aria-current='page']::before {
  content: ''; position: absolute; top: -2px; left: 0; right: 0; height: 3px; background: var(--enc);
}
.onglets .glyphe { width: 15px; height: 15px; }
.onglets .lib { font-family: var(--mono); font-size: 8.5px; font-weight: 400; letter-spacing: .06em; text-transform: uppercase; }
.onglets button[aria-current='page'] .lib { font-weight: 600; }

/* ---- listes ---- */
.rangee {
  display: flex; align-items: stretch; gap: var(--e3); width: 100%; text-align: left;
  padding: var(--e3) 0; border-bottom: 1px solid var(--filet);
}
.rangee .barre { width: 4px; background: var(--enc); flex: 0 0 auto; }
.rangee .t { font-family: var(--display); font-weight: 700; font-size: 15.5px; line-height: 1.25; }
.rangee .d { font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--texte-3); margin-top: 3px; }
.rangee.bloque { opacity: .45; }

/* ---- calendrier ---- */
.calendrier { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--e1); margin-top: var(--e4); }
.jour {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 10px; border: 1.5px solid var(--filet); color: var(--texte-3);
}
.jour.lu { background: var(--jour-enc, var(--enc)); border-color: var(--jour-enc, var(--enc)); color: #F4EFE1; }
.jour.aujourdhui { border: 2px solid var(--texte); color: var(--texte); font-weight: 600; }
.jour.verrou { border-style: dashed; }
.jour.futur { opacity: .3; }

/* ---- quiz ---- */
.choix { display: block; width: 100%; text-align: left; padding: var(--e3) var(--e4); border: 2px solid var(--texte); margin-bottom: var(--e2); font-family: var(--display); font-size: 14.5px; line-height: 1.35; }
.choix[data-etat='bon'] { background: var(--enc); border-color: var(--enc); color: #F4EFE1; }
.choix[data-etat='rate'] { text-decoration: line-through; opacity: .45; }
.explication { margin-top: var(--e4); padding: var(--e4); border: 2px solid var(--texte); font-family: var(--display); font-size: 13.5px; line-height: 1.55; }
.explication h4 { font-family: var(--mono); font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--texte-3); margin-bottom: var(--e2); }

/* ---- statistiques ---- */
.stat { display: flex; justify-content: space-between; align-items: baseline; padding: var(--e3) 0; border-bottom: 1px solid var(--filet); }
.stat b { font-family: var(--display); font-weight: 800; font-size: 30px; letter-spacing: -.03em; }
.jauge { height: 10px; background: var(--filet); margin-top: 5px; }
.jauge i { display: block; height: 100%; background: var(--jauge-enc, var(--enc)); }

/* ---- verrou ---- */
.compte { font-family: var(--display); font-weight: 800; font-size: clamp(46px, 15vw, 74px); letter-spacing: -.04em; font-variant-numeric: tabular-nums; }

/* ---- réglages ---- */
.tuiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--e2); margin-top: var(--e4); }
.tuile { display: flex; align-items: center; gap: var(--e2); padding: var(--e3); border: 2px solid var(--texte); font-family: var(--display); font-weight: 700; font-size: 14px; text-align: left; }
.tuile .puce { width: 14px; height: 14px; background: var(--t-enc); flex: 0 0 auto; }
.tuile[aria-pressed='true'] { background: var(--t-enc); border-color: var(--t-enc); color: #F4EFE1; }
.tuile[aria-pressed='true'] .puce { background: #F4EFE1; }
.segment { display: flex; border: 2px solid var(--texte); margin-top: var(--e2); }
.segment button { flex: 1; padding: var(--e3) var(--e2); font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; min-height: 44px; }
.segment button[aria-pressed='true'] { background: var(--texte); color: var(--papier); }
.champ-heure { font-family: var(--mono); font-size: 15px; padding: var(--e3); border: 2px solid var(--texte); background: none; color: var(--texte); width: 100%; min-height: 44px; }

/* ---- feuille de partage ---- */
.apercu-carte { width: 100%; max-width: 300px; margin: 0 auto; display: block; box-shadow: 0 10px 40px rgba(0,0,0,.18); }

/* ---- notification ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--barre-h) + var(--refuge) + var(--e4));
  transform: translateX(-50%); z-index: 70;
  background: var(--encre-noire); color: var(--papier);
  padding: var(--e3) var(--e4); font-family: var(--display); font-weight: 700; font-size: 13.5px;
  max-width: calc(100% - var(--e8)); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
html[data-theme='sombre'] .toast { background: var(--texte); color: var(--papier); }
.toast.on { opacity: 1; }

:focus-visible { outline: 3px solid var(--enc); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
