/* ---------- thèmes ---------- */
:root {
  --serif: "Noto Serif", "Source Serif Pro", Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Roboto", "Segoe UI", Helvetica, Arial, sans-serif;

  --fs: 19px;
  --lh: 1.62;
  --ff: var(--serif);

  --bg: #faf7f0;
  --fg: #23201c;
  --dim: #97907f;
  --rule: #e2d9c8;
  --ui: #efe9dd;
  --ui-on: #23201c;
  --ui-on-fg: #faf7f0;
}
:root[data-theme="sepia"] {
  --bg: #f3e8d0;
  --fg: #3a3226;
  --dim: #93836a;
  --rule: #ded0b1;
  --ui: #e9dcbe;
  --ui-on: #3a3226;
  --ui-on-fg: #f3e8d0;
}
:root[data-theme="night"] {
  --bg: #101012;
  --fg: #d3cec6;
  --dim: #6f6a64;
  --rule: #29292e;
  --ui: #1e1e22;
  --ui-on: #d3cec6;
  --ui-on-fg: #101012;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
}
body {
  font-family: var(--ff);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ---------- écran de démarrage ---------- */
#boot {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: var(--bg); color: var(--fg);
  transition: opacity .4s ease;
}
#boot.gone { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; padding: 0 2rem; }
.boot-title { font-family: var(--serif); font-size: 1.6rem; line-height: 1.35; }
.boot-sub { margin-top: .9rem; font-size: .8rem; color: var(--dim); letter-spacing: .02em; }
.boot-dots { margin-top: 2.4rem; display: flex; gap: .4rem; justify-content: center; }
.boot-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--dim); animation: pulse 1.1s infinite; }
.boot-dots i:nth-child(2) { animation-delay: .16s; }
.boot-dots i:nth-child(3) { animation-delay: .32s; }
@keyframes pulse { 0%,100% { opacity:.2 } 50% { opacity:.9 } }

/* ---------- structure ---------- */
#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#bar {
  display: flex; align-items: center; gap: .5rem;
  height: 40px; padding: 0 .6rem;
  transition: opacity .25s ease;
}
#menuBtn {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 8px;
  color: var(--dim); opacity: .75;
}
#menuBtn:active { background: var(--ui); }
#barTitle { font-size: .7rem; color: var(--dim); opacity: .6; letter-spacing: .04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#stage {
  position: relative;
  overflow: hidden;
  padding: 4px 22px 6px;
}

#foot {
  display: flex; justify-content: space-between; align-items: center;
  height: 26px; padding: 0 24px 2px;
  font-family: var(--sans);
  font-size: .62rem; letter-spacing: .04em;
  color: var(--dim); opacity: .7;
  transition: opacity .25s ease;
}

#app.bare #bar, #app.bare #foot { opacity: 0; pointer-events: none; }

#measure {
  position: absolute; left: -99999px; top: 0;
  visibility: hidden; pointer-events: none;
}

/* ---------- corps du texte ---------- */
.doc {
  position: relative;
  column-fill: auto;
  font-family: var(--ff);
  font-size: var(--fs);
  line-height: var(--lh);
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  will-change: transform;
}
.doc p { margin: 0; text-indent: 1.25em; orphans: 2; widows: 2; }
.doc h1 + p, .doc h2 + p, .doc h3 + p, .doc blockquote + p, .doc ul + p, .doc hr + p { text-indent: 0; }

.doc h1 {
  font-size: 1.42em; line-height: 1.24; font-weight: 600;
  margin: .4em 0 1.5em; padding-bottom: .7em;
  border-bottom: 1px solid var(--rule);
  text-align: left; hyphens: none; text-wrap: balance;
  break-after: avoid;
}
.doc h2 {
  font-size: .8em; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase;
  color: var(--dim);
  margin: 1.9em 0 .8em; text-align: left; hyphens: none;
  break-after: avoid;
}
.doc h3 {
  font-size: 1em; font-weight: 600; font-style: italic;
  margin: 1.5em 0 .5em; text-align: left; hyphens: none;
  break-after: avoid;
}

.doc blockquote {
  margin: 0 0 1.6em; padding: .1em 0 .1em 1em;
  border-left: 2px solid var(--rule);
  font-size: .93em; color: var(--fg); opacity: .88;
  text-align: left; hyphens: none;
}
.doc blockquote p { text-indent: 0; margin: 0 0 .7em; }
.doc blockquote p:last-child { margin-bottom: 0; }

.doc ul { margin: .3em 0 1.1em; padding-left: 1.2em; }
.doc li { margin: 0 0 .5em; text-align: left; }

.doc em { font-style: italic; }
.doc strong { font-weight: 700; }
.doc hr { border: 0; border-top: 1px solid var(--rule); margin: 1.6em 20% ; }

/* ---------- panneau ---------- */
#scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.35); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0 } }

#panel {
  position: fixed; z-index: 30; top: 0; left: 0; right: 0;
  max-height: 88vh;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  box-shadow: 0 12px 40px rgba(0,0,0,.22);
  animation: drop .24s cubic-bezier(.2,.7,.3,1);
  padding-top: env(safe-area-inset-top);
}
@keyframes drop { from { transform: translateY(-101%) } }
.panel-scroll {
  max-height: calc(88vh - env(safe-area-inset-top));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: .3rem 1.1rem 1.4rem;
  font-family: var(--sans);
}
.grip { display: block; width: 36px; height: 4px; border-radius: 3px;
  background: var(--rule); margin: .45rem auto .7rem; }

#installBlock {
  margin: .2rem 0 .9rem; padding: .8rem .9rem;
  background: var(--ui); border-radius: 11px;
}
#installBtn {
  display: flex; align-items: center; gap: .5rem; width: 100%;
  padding: .6rem .8rem; border-radius: 8px;
  background: var(--ui-on); color: var(--ui-on-fg);
  font-size: .82rem; font-weight: 600;
}
#installBtn:active { opacity: .8; }
/* `display: flex` ci-dessus l'emporte sur le `display: none` de [hidden] : à réaffirmer. */
#installBtn[hidden] { display: none; }
#installBlock[hidden] { display: none; }
#installHint { margin: .55rem .2rem 0; font-size: .68rem; line-height: 1.5; color: var(--dim); }
#installBtn[hidden] + #installHint { margin-top: 0; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem 0; }
.lab { font-size: .78rem; color: var(--dim); letter-spacing: .04em; }

.seg { display: flex; background: var(--ui); border-radius: 9px; padding: 3px; }
.seg button {
  padding: .38rem .72rem; border-radius: 7px;
  font-size: .78rem; color: var(--fg); opacity: .65;
}
.seg button[aria-pressed="true"] { background: var(--ui-on); color: var(--ui-on-fg); opacity: 1; }

.stepper { display: flex; align-items: center; background: var(--ui); border-radius: 9px; padding: 3px; }
.stepper button { width: 40px; height: 30px; border-radius: 7px; font-size: .85rem; }
.stepper button:active { background: var(--ui-on); color: var(--ui-on-fg); }
.stepper button small { font-size: .7em; }
.stepper span { min-width: 44px; text-align: center; font-size: .74rem; color: var(--dim); font-variant-numeric: tabular-nums; }

.sep { height: 1px; background: var(--rule); margin: .9rem 0 .5rem; }

#toc { display: flex; flex-direction: column; }
#toc button {
  display: flex; justify-content: space-between; align-items: baseline; gap: .8rem;
  text-align: left; padding: .58rem .4rem; border-radius: 7px;
  font-size: .84rem; line-height: 1.3;
}
#toc button:active { background: var(--ui); }
#toc button[aria-current="true"] { font-weight: 650; }
#toc button[aria-current="true"] .pg { color: var(--fg); opacity: .75; }
#toc .pg { font-size: .68rem; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

.foot-note { margin-top: 1rem; font-size: .66rem; color: var(--dim); line-height: 1.5; }
