/* Ex-libris
   Mise en page : registre en une colonne. En-tête, onglets qui servent aussi de compteurs,
   barre d'outils, puis une ligne par livre avec son dos coloré et sa cote. */

@font-face { font-family: "Gloock"; src: url("fonts/gloock-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("fonts/figtree-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("fonts/figtree-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("fonts/figtree-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("fonts/figtree-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --paper: #eef1f4; --surface: #ffffff; --sunk: #e4e9ef; --ink: #16202e; --muted: #5a6575; --line: #d3dae3;
  --accent: #e2a813; --accent-ink: #2a1f00; --focus: #2f6fd6;
  --ok: #2c7a4c; --ok-bg: #e1f1e7; --info: #2f5f9e; --info-bg: #e2ebf7; --danger: #b23a3a;
  --s1: #2d4a6b; --s2: #7a2f3a; --s3: #2f6b5a; --s4: #6e5b26; --s5: #4b3b6e; --s6: #8a4b20; --spine-ink: #f7f4ec;
  --backdrop: rgba(10, 14, 20, .45);
  --f-display: "Gloock", Georgia, "Times New Roman", serif;
  --f-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10151c; --surface: #18202a; --sunk: #222c38; --ink: #e7ecf2; --muted: #9ba7b6; --line: #2b3644;
    --accent: #f0bd3a; --accent-ink: #1d1500; --focus: #86b4ff;
    --ok: #74c995; --ok-bg: #1b3326; --info: #8fb6ec; --info-bg: #1c2a3d; --danger: #ef7f7f;
    --s1: #3f6590; --s2: #9a4552; --s3: #3f8a74; --s4: #8f7836; --s5: #6a5794; --s6: #a8622f; --spine-ink: #fbf8f0;
    --backdrop: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--f-body); font-size: 15px; line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: calc(env(safe-area-inset-top, 0px) + 24px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 64px);
  min-height: 100vh; min-height: 100dvh;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

/* En-tête */
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.brand { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.eyebrow { font-family: var(--f-mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
h1 { font-family: var(--f-display); font-weight: 400; font-size: clamp(38px, 7vw, 54px); line-height: 1; margin: 0; letter-spacing: -.01em; text-wrap: balance; }
.tagline { margin: 0; color: var(--muted); }
.top-acts { display: flex; gap: 8px; }

/* Boutons */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); border-color: var(--line); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.icon { padding: 8px; width: 38px; height: 38px; }
.btn.block { width: 100%; padding: 11px 14px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: default; }

/* Onglets compteurs */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.tab {
  flex: 0 0 auto; border: 1px solid var(--line); background: transparent; border-radius: var(--r);
  padding: 8px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start;
  min-width: 92px; text-align: left; -webkit-tap-highlight-color: transparent;
}
.tab .n { font-family: var(--f-display); font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tab .l { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.tab[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.tab[aria-selected="true"] .l { color: var(--paper); opacity: .8; }

/* Barre d'outils */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { flex: 1 1 220px; min-width: 0; position: relative; }
.search input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 9px 14px 9px 36px; font-size: 16px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar select { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 9px 12px; font-size: 15px; }

.notice { border: 1px dashed var(--line); border-radius: var(--r); padding: 12px 14px; color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }

/* Liste */
.list { display: flex; flex-direction: column; gap: 8px; }
.book {
  display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; gap: 14px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px 10px 10px;
}
.spine {
  color: var(--spine-ink); border-radius: 4px 6px 6px 4px; min-height: 76px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px 0; position: relative;
  box-shadow: inset 3px 0 0 rgba(255, 255, 255, .12), inset -2px 0 0 rgba(0, 0, 0, .18);
}
.spine::before, .spine::after { content: ""; position: absolute; left: 5px; right: 5px; height: 1px; background: currentColor; opacity: .35; }
.spine::before { top: 6px; } .spine::after { bottom: 6px; }
.sp1 { --sp: var(--s1); } .sp2 { --sp: var(--s2); } .sp3 { --sp: var(--s3); }
.sp4 { --sp: var(--s4); } .sp5 { --sp: var(--s5); } .sp6 { --sp: var(--s6); }
.spine { background: var(--sp); }
.cote { background: var(--spine-ink); color: var(--sp); font-family: var(--f-mono); font-size: 10px; font-weight: 600; line-height: 1.15; text-align: center; padding: 3px 2px; border-radius: 2px; width: 38px; letter-spacing: .02em; }
.cover { width: 50px; aspect-ratio: 2 / 3; max-width: 100%; object-fit: cover; border-radius: 3px; background: var(--sunk); align-self: center; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.meta { min-width: 0; display: flex; flex-direction: column; gap: 5px; justify-content: center; }
.meta h3 { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.by { margin: 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 9px; border: 1px solid var(--line); color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.chip.owned { border-color: transparent; background: var(--sunk); color: var(--ink); }
.chip.wish { border-color: transparent; background: var(--accent); color: var(--accent-ink); }
.chip.read { border-color: transparent; background: var(--ok-bg); color: var(--ok); }
.chip.reading { border-color: transparent; background: var(--info-bg); color: var(--info); }
.stars { letter-spacing: 1px; }
.comment { margin: 0; font-size: 13.5px; color: var(--muted); font-style: italic; overflow-wrap: anywhere; }
.acts { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; justify-content: center; }
@media (max-width: 560px) {
  .book { grid-template-columns: 44px minmax(0, 1fr); }
  .cover { width: 44px; }
  .acts { grid-column: 2; flex-direction: row; flex-wrap: wrap; justify-content: flex-start; }
}

.empty { text-align: center; padding: 40px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--r); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.empty strong { font-family: var(--f-display); font-weight: 400; font-size: 22px; color: var(--ink); }

/* Connexion */
.gate { min-height: calc(100dvh - 120px); display: grid; place-items: center; }
.gate-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 22px; }
.gate-icon { border-radius: 14px; }
.gate-lead { margin: 0; color: var(--muted); }

/* Dialogues */
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink);
  padding: 0; width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overscroll-behavior: contain;
}
dialog::backdrop { background: var(--backdrop); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dlg h2 { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: 28px; line-height: 1.1; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label, .field legend, .lbl, .lookup > label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; padding: 0; }
.field input, .field select, .field textarea, .lookup input {
  border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 9px 11px; width: 100%; font-size: 16px;
}
.field textarea { min-height: 70px; resize: vertical; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.seg label { text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 500; color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; cursor: pointer; display: inline-flex; align-items: center; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 700; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.rate { display: flex; gap: 2px; margin-top: 2px; }
.rate button { border: 0; background: none; font-size: 28px; line-height: 1; cursor: pointer; color: var(--line); padding: 2px 3px; }
.rate button.on { color: var(--accent); }
.dlg-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; }
.dlg-foot .right { display: flex; gap: 8px; margin-left: auto; }
.err { color: var(--danger); font-size: 13.5px; margin: 0; }
.hint { color: var(--muted); font-size: 13.5px; margin: 0; }
@media (max-width: 480px) { .fields { grid-template-columns: 1fr; } }

/* Recherche automatique */
.lookup { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: var(--r); background: var(--sunk); }
.lookup input { background: var(--surface); }
.lookup-row { display: flex; gap: 8px; }
.lookup-row input { flex: 1; min-width: 0; }
.lk-results { display: flex; flex-direction: column; gap: 6px; }
.lk-item { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px; align-items: center; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px 6px 6px; cursor: pointer; }
.lk-item:hover { border-color: var(--muted); }
.lk-item img, .lk-item .ph { width: 36px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 2px; background: var(--line); }
.lk-item strong { display: block; font-size: 14px; overflow-wrap: anywhere; }
.lk-item span { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }

/* Réglages */
.menu-sec { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.menu-sec h3 { margin: 0; font-size: 15px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row.spread { justify-content: space-between; align-items: center; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--paper); padding: 9px 16px; border-radius: 999px;
  font-weight: 600; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: up .2s ease-out; }
  @keyframes up { from { transform: translate(-50%, 8px); opacity: 0; } }
}

/* ---------- Couvertures ---------- */
.viewsw { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); padding: 2px; }
.vbtn { border: 0; background: transparent; color: var(--muted); border-radius: 999px; width: 38px; height: 34px; display: grid; place-items: center; cursor: pointer; }
.vbtn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* Couverture générée quand le livre n'a pas d'image */
.fake {
  background: var(--sp); color: var(--spine-ink); width: 100%; height: 100%;
  display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  padding: 24% 10% 10%; position: relative; overflow: hidden;
  box-shadow: inset 4px 0 0 rgba(0, 0, 0, .18);
}
.fake::before { content: ""; position: absolute; inset: 6% 7%; border: 1px solid currentColor; opacity: .3; border-radius: 2px; pointer-events: none; }
.fake .ft { font-family: var(--f-display); font-size: 15px; line-height: 1.12; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.fake .fa { font-family: var(--f-mono); font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; opacity: .85; overflow-wrap: anywhere; }

/* Vue en grille */
.list.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 18px 12px; }
.tile { border: 0; background: none; padding: 0; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-width: 0; color: inherit; -webkit-tap-highlight-color: transparent; }
.tile .cv { position: relative; width: 100%; aspect-ratio: 2 / 3; max-width: 100%; border-radius: 3px 5px 5px 3px; overflow: hidden; background: var(--sunk); box-shadow: 0 1px 2px rgba(0, 0, 0, .18), 0 6px 14px -8px rgba(0, 0, 0, .35); }
.tile .cv img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile:hover .cv { box-shadow: 0 0 0 2px var(--accent), 0 6px 14px -8px rgba(0, 0, 0, .35); }
.tile .t { font-size: 13px; font-weight: 700; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tile .a { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { position: absolute; top: 6px; right: 6px; font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 2px 7px; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.badge.wish { background: var(--accent); color: var(--accent-ink); }
.badge.read { background: var(--ok-bg); color: var(--ok); }
.badge.reading { background: var(--info-bg); color: var(--info); }

/* Éditeur de couverture dans la fiche */
.cover-edit { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 14px; align-items: center; }
.cover-prev { width: 88px; aspect-ratio: 2 / 3; max-width: 100%; border-radius: 3px 5px 5px 3px; overflow: hidden; background: var(--sunk); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.cover-prev img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-prev .fake .ft { font-size: 12px; }
.cover-prev.busy { opacity: .5; }
.cover-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cover-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; }
.cover-results:empty { display: none; }
.cover-results button { border: 2px solid transparent; padding: 0; border-radius: 4px; overflow: hidden; aspect-ratio: 2 / 3; max-width: 100%; background: var(--sunk); cursor: pointer; }
.cover-results button:hover, .cover-results button:focus-visible { border-color: var(--accent); }
.cover-results img { width: 100%; height: 100%; object-fit: cover; display: block; }

.list.grid .empty { grid-column: 1 / -1; }
.cover-prev .fake { padding-top: 14%; }
