:root {
  --paper: #ECE8E1; --surface: #FBFAF8; --surface2: #F3F0EA;
  --ink: #201E1B; --muted: #6E685F; --line: #D8D2C7;
  --accent: #14532D; --accent-soft: #E3EEE6; --accent-text: #FFFFFF;
  --note-bg: #F5EBD3; --note-ink: #6B5313;
  --shadow: 0 10px 30px rgba(32,30,27,.18), 0 2px 6px rgba(32,30,27,.12);
  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --sans: 'Segoe UI', -apple-system, system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171614; --surface: #211F1C; --surface2: #2A2724;
    --ink: #EAE6DF; --muted: #9B948A; --line: #38342E;
    --accent: #3E8E62; --accent-soft: #23352B;
    --note-bg: #322A18; --note-ink: #D8BC6E;
    --shadow: 0 10px 30px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 15px; line-height: 1.5;
}
body.protected { -webkit-user-select: none; user-select: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
button { font-family: var(--sans); cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- header ---------- */
header.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 16px; padding: 14px 22px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.wordmark { font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: 13px; }
.wordmark span { font-weight: 300; }
.book-id { text-align: center; min-width: 0; }
.book-id .title { font-family: var(--serif); font-size: 17px; line-height: 1.25; text-wrap: balance; }
.book-id .author { color: var(--muted); font-size: 13px; margin-top: 1px; }
.topbar .right { text-align: right; }
.chip-version {
  display: inline-block; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; color: var(--muted);
}

/* ---------- meta band / segments ---------- */
.metaband {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 10px 18px; padding: 10px 22px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.specs { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--muted); }
.specs b { color: var(--ink); font-weight: 600; }
.specs .k { text-transform: uppercase; letter-spacing: .07em; font-size: 10.5px; margin-right: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface2); }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; font-size: 13px; }
.seg button.active { background: var(--ink); color: var(--paper); }

/* ---------- stage ---------- */
.toolstrip { display: flex; justify-content: center; gap: 10px; padding: 12px 22px 0; flex-wrap: wrap; }
.stage-wrap { position: relative; }
.stage { position: relative; display: flex; align-items: flex-start; justify-content: center; padding: 18px 64px 84px; min-height: 62vh; }
.scroller { overflow: auto; max-width: 100%; max-height: 74vh; padding: 6px; }
.spread { display: flex; justify-content: center; }
.page-card { position: relative; background: #fff; box-shadow: var(--shadow); min-width: 40px; min-height: 200px; }
.page-card img { display: block; height: min(66vh, 780px); width: auto; pointer-events: none; -webkit-user-drag: none; }
.zoomed .page-card img { height: auto; }
.spread.duo .page-card { box-shadow: none; }
.spread.duo { box-shadow: var(--shadow); background: #fff; position: relative; }
.spread.duo::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 56px;
  transform: translateX(-50%); pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.10) 46%, rgba(0,0,0,.16) 50%, rgba(0,0,0,.10) 54%, rgba(0,0,0,0) 100%);
}
.spread.duo .page-card img { height: min(62vh, 720px); }
.page-blank { background: var(--surface2); border: 1px dashed var(--line); box-shadow: none; }
.navbtn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 19px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.navbtn:hover { background: var(--surface2); }
.navbtn.prev { left: 14px; } .navbtn.next { right: 14px; }
.pagepill {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-size: 13px; padding: 7px 16px; border-radius: 999px;
  font-variant-numeric: tabular-nums; box-shadow: 0 3px 10px rgba(0,0,0,.2); white-space: nowrap;
}
.toolbtn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 6px 12px; font-size: 13px; }
.toolbtn[disabled] { opacity: .4; cursor: default; }

/* ---------- couverture ---------- */
.coverview { display: flex; gap: 40px; justify-content: center; align-items: flex-start; flex-wrap: wrap; padding: 30px 22px 90px; }
.cover-label { text-align: center; font-size: 12px; color: var(--muted); margin-top: 10px; letter-spacing: .06em; text-transform: uppercase; }

/* ---------- action bar ---------- */
.actionbar {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 22px; background: var(--surface); border-top: 1px solid var(--line); flex-wrap: wrap;
}
.secnote { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.cta-group { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { border-radius: 10px; padding: 11px 20px; font-size: 14.5px; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary[disabled] { opacity: .5; cursor: default; filter: none; }
.btn.ghost:hover { background: var(--surface2); }
.btn.small { padding: 6px 12px; font-size: 12.5px; font-weight: 500; }
.statusband { display: none; align-items: center; gap: 10px; font-weight: 600; font-size: 14.5px; }
.statusband.ok { color: var(--accent); }
.statusband.warn { color: var(--note-ink); }

/* ---------- modals / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,18,15,.55); z-index: 50; display: none; align-items: center; justify-content: center; padding: 18px; }
.overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 14px; max-width: 640px; width: 100%; max-height: 88vh; overflow: auto; box-shadow: var(--shadow); padding: 26px 28px; }
.modal.wide { max-width: 760px; }
.modal h2 { font-family: var(--serif); font-size: 21px; margin: 0 0 4px; }
.modal .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 18px; }
.checkline { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; font-size: 14px; }
.checkline input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; }
.checkgroup { border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin: 14px 0; background: var(--surface2); }
.checkgroup .gt { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 4px; }
.sig-zone { margin-top: 16px; }
.sig-zone .gt { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
#sigcanvas { width: 100%; height: 140px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface2); touch-action: none; display: block; }
.sig-tools { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.sig-tools button { border: 0; background: transparent; color: var(--muted); text-decoration: underline; font-size: 12.5px; }
.field { margin: 12px 0; }
.field label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font-size: 14px; font-family: var(--sans); background: var(--surface); color: var(--ink);
}
.field textarea { resize: vertical; min-height: 54px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.success { text-align: center; padding: 18px 6px; }
.success .big { font-size: 44px; color: var(--accent); }
.success h3 { font-family: var(--serif); font-size: 20px; margin: 8px 0 6px; }
.success p { color: var(--muted); font-size: 14px; }
.modtable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.modtable th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.modtable td { padding: 6px 6px; vertical-align: top; }
.modtable input, .modtable textarea { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; font-size: 13.5px; font-family: var(--sans); background: var(--surface); color: var(--ink); }
.modtable textarea { resize: vertical; min-height: 40px; }
.modtable .pgcol { width: 74px; }
.addrow { border: 1px dashed var(--line); background: transparent; color: var(--muted); border-radius: 8px; padding: 7px 14px; font-size: 13px; margin-top: 8px; }
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: var(--ink); color: var(--paper); font-size: 13.5px;
  padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  z-index: 90; max-width: min(92vw, 480px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- édito ---------- */
.tabs { display: flex; gap: 2px; padding: 0 22px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { border: 0; background: transparent; color: var(--muted); font-size: 14px; padding: 11px 16px; border-bottom: 2.5px solid transparent; white-space: nowrap; text-decoration: none; }
.tabs a.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.edito-grid { display: grid; grid-template-columns: minmax(300px, 430px) 1fr; gap: 22px; padding: 24px 22px 60px; align-items: start; }
@media (max-width: 900px) { .edito-grid { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; }
.card h3 { font-family: var(--serif); font-size: 18px; margin: 0 0 14px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row2, .row3 { grid-template-columns: 1fr; } }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge.wait { background: var(--surface2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.mod { background: var(--note-bg); color: var(--note-ink); }
.badge.err { background: #F8E1E1; color: #8A2020; }
.battable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.battable th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.battable td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.battable tr:last-child td { border-bottom: 0; }
.battable .bk { font-weight: 600; }
.battable .au { color: var(--muted); font-size: 12.5px; }
.tablewrap { overflow-x: auto; }
.linkline { font-family: Consolas, monospace; font-size: 12.5px; word-break: break-all; }
.login-card { max-width: 380px; margin: 10vh auto; }
.center-note { text-align: center; color: var(--muted); padding: 40px 20px; }

@media (max-width: 700px) {
  header.topbar { grid-template-columns: 1fr; text-align: center; gap: 4px; }
  .topbar .right, .wordmark { text-align: center; }
  .stage { padding: 14px 8px 84px; }
  .navbtn.prev { left: 4px; } .navbtn.next { right: 4px; }
  .actionbar { justify-content: center; }
  .cta-group { width: 100%; }
  .cta-group .btn { flex: 1; }
  .secnote { display: none; }
}
