@font-face { font-family: "OpenDyslexic"; src: url("fonts/opendyslexic.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "OpenDyslexic"; src: url("fonts/opendyslexic-bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Lexend"; src: url("fonts/lexend.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Lexend"; src: url("fonts/lexend-bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-hyperlegible.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-hyperlegible-bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Andika"; src: url("fonts/andika.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Andika"; src: url("fonts/andika-bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Comic Neue"; src: url("fonts/comic-neue.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Comic Neue"; src: url("fonts/comic-neue-bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --ui-bg: #f4f1ea;
  --ui-panel: #ffffff;
  --ui-ink: #1f2430;
  --ui-muted: #6b7080;
  --ui-line: #e2ddd2;
  --accent: #2f6fd6;
  --accent-soft: #e8f0fd;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --hl: #ffe066;
  --page-bg: #fdf6e3;
  --page-ink: #1f2430;
  --page-soft: rgba(31, 36, 48, .06);
  --page-accent: #2f6fd6;
  --font: "OpenDyslexic";
  --size: 22px;
  --letter: 0.05em;
  --word: 0.2em;
  --line: 1.8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--ui-bg); color: var(--ui-ink);
  font: 16px/1.45 "Atkinson Hyperlegible", system-ui, sans-serif;
  min-height: 100dvh;
}
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--ui-muted); }
.spacer { flex: 1; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px; border-radius: 12px;
  border: 1px solid var(--ui-line); background: var(--ui-panel); cursor: pointer; font-size: 16px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { width: 100%; min-height: 52px; font-size: 18px; }
.btn.icon { padding: 8px 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; }
.aa { font-family: "OpenDyslexic"; font-weight: 700; }

/* ---------- Barre du haut ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--ui-panel); border-bottom: 1px solid var(--ui-line);
}
.logo { font-family: "OpenDyslexic"; font-weight: 700; font-size: 20px; color: var(--ui-ink); }
.offline { font-size: 13px; background: #fff1d6; color: #7a5200; padding: 4px 10px; border-radius: 99px; }

.view { max-width: 980px; margin: 0 auto; padding: 20px 16px calc(40px + var(--safe-bottom)); }

/* ---------- Accueil ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 2px dashed #c9c2b2; border-radius: 20px; padding: 36px 20px; text-align: center;
  background: var(--ui-panel); cursor: pointer; transition: .15s;
}
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { font-size: 40px; }
.drop strong { font-size: 22px; font-family: "OpenDyslexic"; }
.drop span:last-child { color: var(--ui-muted); }

.progress { margin-top: 16px; background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 16px; padding: 16px; }
.progress-text { font-weight: 700; }
.progress-note { color: var(--ui-muted); font-size: 14px; margin-top: 6px; }
.bar { height: 10px; background: var(--ui-line); border-radius: 5px; overflow: hidden; margin-top: 10px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.library h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--ui-muted); margin: 28px 0 10px; }
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.doc-list li { display: flex; align-items: center; gap: 12px; background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 14px; padding: 10px 12px; }
.doc-list .thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--ui-bg); flex: none; display: grid; place-items: center; font-size: 24px; }
.doc-list .open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; cursor: pointer; padding: 4px 0; }
.doc-list .name { font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-list .meta { color: var(--ui-muted); font-size: 14px; }
.doc-list .del { color: var(--ui-muted); }

/* ---------- Lecteur ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.tabs { display: inline-flex; background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 12px; padding: 3px; }
.tabs button { border: 0; background: transparent; min-height: 38px; padding: 6px 14px; border-radius: 9px; cursor: pointer; }
.tabs button[aria-selected=true] { background: var(--accent); color: var(--accent-ink); }
.edit-hint { background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; margin: 0 0 12px; }

.page, .preview {
  background: var(--page-bg); color: var(--page-ink);
  font-family: var(--font), sans-serif; font-size: var(--size);
  letter-spacing: var(--letter); word-spacing: var(--word); line-height: var(--line);
}
.page {
  border-radius: 18px; border: 1px solid var(--ui-line);
  padding: clamp(20px, 5vw, 48px) clamp(18px, 6vw, 56px);
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
  overflow-wrap: break-word;
}
.page > * { margin: 0 0 1em; }
.page .b-kicker { font-size: .8em; font-weight: 700; color: var(--page-accent); margin-bottom: .4em; }
.page h1 { font-size: 1.7em; line-height: 1.3; font-weight: 700; margin-bottom: .5em; }
.page .b-sub { font-size: 1.1em; font-weight: 700; }
.page .b-byline { font-size: .8em; opacity: .75; }
.page h2 { font-size: 1.25em; line-height: 1.4; font-weight: 700; margin-top: 1.4em; margin-bottom: .5em; }
.page ul { padding-left: 1.4em; }
.page li { margin-bottom: .5em; }
.page blockquote { border-left: 6px solid var(--page-accent); background: var(--page-soft); border-radius: 0 12px 12px 0; padding: .6em 1em; font-weight: 700; }
.page blockquote cite { display: block; font-style: normal; font-weight: 400; font-size: .8em; opacity: .75; margin-top: .3em; }
.page .b-note { border: 2px solid var(--page-accent); border-radius: 12px; padding: .6em 1em; }
.page figure { margin: 1.2em 0; }
.page figure img { display: block; max-width: 100%; max-height: 55vh; border-radius: 12px; margin: 0 auto; }
.page figcaption, .page .b-caption { font-size: .75em; opacity: .8; margin-top: .4em; }
.page.no-images figure img { display: none; }
.page .pagebreak { border: 0; border-top: 2px dashed var(--page-soft); margin: 2em 0; }
.page .w { border-radius: 4px; cursor: pointer; }
.page .w.on { background: var(--hl); color: #1f2430; box-shadow: 0 0 0 3px var(--hl); }
.page .blk { position: relative; }
.page.editing [contenteditable] { outline: 2px dashed transparent; border-radius: 8px; cursor: text; }
.page.editing [contenteditable]:hover { outline-color: var(--ui-line); }
.page.editing [contenteditable]:focus { outline-color: var(--accent); background: rgba(47,111,214,.05); }
.page .del-blk { position: absolute; right: -8px; top: -8px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--ui-line); background: #fff; font-size: 15px; cursor: pointer; letter-spacing: 0; line-height: 1; font-family: system-ui; display: none; }
.page.editing .del-blk { display: block; }

/* ---------- Réglages ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(20,22,30,.35); z-index: 30; }
.settings {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(380px, 100vw); background: var(--ui-panel); overflow-y: auto;
  padding: calc(16px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  box-shadow: -8px 0 30px rgba(0,0,0,.15);
}
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.settings-head h2 { margin: 0; font-size: 20px; }
.preview { border-radius: 14px; border: 1px solid var(--ui-line); padding: 14px 16px; margin-bottom: 18px; max-height: 180px; overflow: hidden; }
.field { margin-bottom: 18px; }
.field > label { display: flex; justify-content: space-between; font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.field output { color: var(--ui-muted); font-weight: 400; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }
.font-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.font-grid button { min-height: 48px; border: 1px solid var(--ui-line); border-radius: 12px; background: #fff; cursor: pointer; font-size: 16px; padding: 6px; }
.font-grid button[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); background: var(--accent-soft); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--ui-line); cursor: pointer; }
.swatch[aria-pressed=true] { box-shadow: 0 0 0 3px var(--accent); border-color: #fff; }
.check { display: flex !important; justify-content: flex-start !important; align-items: center; gap: 10px; font-weight: 400 !important; min-height: 40px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- Divers ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: var(--ui-bg); display: grid; place-items: center; padding: 16px; }
.card { width: min(420px, 100%); background: var(--ui-panel); border-radius: 20px; padding: 28px; box-shadow: 0 10px 40px rgba(0,0,0,.08); text-align: center; }
.card .logo { font-size: 28px; margin-bottom: 8px; }
.card input { width: 100%; min-height: 52px; font-size: 20px; text-align: center; border: 2px solid var(--ui-line); border-radius: 12px; margin: 8px 0; }
.card input:focus { outline: none; border-color: var(--accent); }
.err { color: var(--danger); min-height: 1.4em; margin: 4px 0 10px; }

.ruler {
  position: fixed; left: 0; right: 0; z-index: 5; pointer-events: none;
  height: calc(var(--size) * var(--line) + 10px); transform: translateY(-50%);
  background: rgba(255, 224, 102, .25); border-top: 2px solid rgba(214,170,0,.6); border-bottom: 2px solid rgba(214,170,0,.6);
  box-shadow: 0 0 0 100vmax rgba(20,22,30,.18);
}
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60; background: #1f2430; color: #fff; padding: 12px 18px; border-radius: 12px; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }

@media (max-width: 700px) {
  .toolbar .btn { padding: 8px 10px; }
  #back { font-size: 0; } #back::before { content: "←"; font-size: 18px; }
}

/* ---------- v2.1 : réglages au doigt, URL, aide ---------- */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper input[type=range] { flex: 1; }
.step { flex: none; width: 52px; height: 52px; border-radius: 14px; border: 1px solid var(--ui-line); background: #fff; font-size: 26px; font-weight: 700; line-height: 1; cursor: pointer; touch-action: manipulation; }
.step:active { background: var(--accent-soft); border-color: var(--accent); }
.url-form { display: flex; gap: 8px; margin-top: 14px; }
.url-form input { flex: 1; min-width: 0; min-height: 52px; font-size: 17px; padding: 0 14px; border: 2px solid var(--ui-line); border-radius: 14px; background: var(--ui-panel); }
.url-form input:focus { outline: none; border-color: var(--accent); }
.url-form .btn { min-height: 52px; }
.home-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.home-actions .btn { flex: 1; }
.help { background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 18px; padding: 24px clamp(18px, 4vw, 36px); line-height: 1.6; }
.help h1 { font-family: "OpenDyslexic"; font-size: 24px; margin-top: 0; }
.help h2 { font-size: 19px; margin: 28px 0 8px; }
.help ol { padding-left: 1.3em; } .help li { margin-bottom: 10px; }
.help code { background: var(--ui-bg); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.help .btn { margin: 4px 0; white-space: normal; }
.source-link { display: inline-block; font-size: 14px; color: var(--ui-muted); margin: -4px 0 12px; word-break: break-all; }
