/* Booky — fond crème commun, une couleur par personne.
   --pastel / --deep suivent le thème de l'élément : la racine prend celui de la personne connectée,
   et n'importe quel bloc peut porter data-theme pour signer ce qui vient de l'autre. */
:root {
  --bg: #faf6ee;
  --surface: #fffdf8;
  --line: #e6dfd2;
  --text: #2d2a26;
  --muted: #6f675d;
  --danger: #a3312f;
  --pastel: #ece5d8;
  --deep: #5a4d3c;
  --on-deep: #fffdf8;
  --radius: 18px;
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color-scheme: light;
}
[data-theme="green"] { --pastel: #dcebd9; --deep: #2f5d43; }
[data-theme="pink"] { --pastel: #f8dde4; --deep: #a8355a; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { font-family: var(--serif); color: var(--deep); letter-spacing: -.01em; margin: 0; }
h2 { font-size: 1.25rem; margin-bottom: 6px; }
p { margin: 0 0 10px; }
a { color: var(--deep); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2.5px solid var(--deep); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.i { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Boutons et champs */
.btn {
  min-height: var(--tap); padding: 10px 20px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--deep); border-color: var(--deep); color: var(--on-deep); width: 100%; }
.btn.link { border: 0; background: none; color: var(--deep); text-decoration: underline; font-weight: 500; width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
label { display: block; font-weight: 600; margin-bottom: 6px; }
input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: #fff;
}
input:focus { border-color: var(--deep); outline: none; box-shadow: 0 0 0 3px var(--pastel); }
.error { color: var(--danger); font-size: .9rem; min-height: 1.4em; margin: 6px 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

/* Connexion */
.login {
  min-height: 100dvh; max-width: 400px; margin: 0 auto;
  padding: calc(48px + var(--safe-t)) 20px calc(32px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.login-logo { border-radius: 22px; box-shadow: 0 6px 20px rgba(90, 77, 60, .14); }
.login h1 { font-size: 2.4rem; margin-top: 16px; }
.tagline { color: var(--muted); margin-bottom: 28px; }
.login .card { width: 100%; text-align: left; }
.login .card .small { margin: 12px 0 0; }
.login .card label[for="code"] { margin-top: 16px; }
.code-input { font-size: 1.6rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }

/* Coquille */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + var(--safe-t)) 16px 12px;
  background: linear-gradient(var(--bg) 75%, transparent);
}
.topbar h1 { font-size: 1.7rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-chip {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap);
  padding: 0 14px 0 10px; border-radius: 999px; background: var(--pastel);
  color: var(--deep); font-weight: 600; text-decoration: none; white-space: nowrap;
}
main#view { max-width: 720px; margin: 0 auto; padding: 4px 16px calc(96px + var(--safe-b)); }
section { margin-bottom: 28px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: rgba(250, 246, 238, .94); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px 7px; min-height: 56px;
  color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600;
}
.tabbar a[aria-current] { color: var(--deep); }
.tabbar a[aria-current] .i { background: var(--pastel); border-radius: 999px; box-shadow: 0 0 0 5px var(--pastel); }

/* États vides */
.empty { text-align: center; padding: 14vh 12px 0; }
.empty-mark {
  width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 50%;
  display: grid; place-items: center; background: var(--pastel); color: var(--deep);
}
.empty-mark .i { width: 36px; height: 36px; }
.empty p { max-width: 34ch; margin: 0 auto; }

/* Profil */
.people { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.person {
  display: flex; align-items: center; gap: 12px; padding: 16px;
  border-radius: var(--radius); background: var(--pastel); color: var(--deep);
}
.person.waiting { background: none; border: 1.5px dashed var(--line); }
.person-emoji {
  width: 52px; height: 52px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.7rem; background: var(--surface);
}
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; margin: 12px 0; }
.emoji-grid button {
  aspect-ratio: 1; min-height: 48px; font-size: 1.5rem; padding: 0;
  border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface);
}
.emoji-grid button[aria-pressed="true"] { border-color: var(--deep); background: var(--pastel); }
.inline-form { display: flex; align-items: center; gap: 10px; }
.inline-form label { margin: 0; white-space: nowrap; font-weight: 500; }
.inline-form input { width: 96px; text-align: center; font-size: 1.3rem; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); z-index: 40;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 22px; text-align: center;
  background: var(--text); color: var(--bg); font-size: .92rem;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Utilitaires */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.loading { text-align: center; padding: 48px 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.small { min-height: 40px; padding: 6px 16px; font-size: .9rem; }
.btn.inline { width: auto; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; margin-top: 16px; }
.btn.danger { color: var(--danger); }
.linklike { border: 0; background: none; padding: 0; color: var(--deep); text-decoration: underline; text-underline-offset: 3px; text-align: left; min-height: 28px; }
.back { display: inline-flex; align-items: center; gap: 2px; min-height: var(--tap); margin-left: -6px; font-weight: 600; text-decoration: none; }
.series { color: var(--deep); font-weight: 600; margin: 0 0 2px; }
h3 { font-family: var(--serif); font-size: 1.1rem; margin: 0 0 2px; line-height: 1.25; }

/* Couvertures : le titre sur fond pastel sert de couverture de secours */
.cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden;
  background: var(--pastel); box-shadow: 0 4px 14px rgba(90, 77, 60, .16);
}
.cover-title {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center;
  font-family: var(--serif); font-weight: 700; font-size: .85rem; line-height: 1.2; color: var(--deep);
  overflow: hidden; overflow-wrap: anywhere;
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.badges { position: absolute; top: 6px; right: 6px; display: flex; gap: 3px; }
.badges span {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: .95rem;
  background: var(--surface); box-shadow: 0 0 0 2px var(--deep);
}

/* Bibliothèque */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 16px; padding: 2px 16px 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button, .segmented button {
  flex: none; min-height: 40px; padding: 6px 14px; border-radius: 999px; white-space: nowrap;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; font-size: .9rem;
}
.chips button span { color: var(--muted); font-weight: 500; margin-left: 2px; }
.chips button[aria-pressed="true"], .segmented button[aria-pressed="true"] { background: var(--deep); border-color: var(--deep); color: var(--on-deep); }
.chips button[aria-pressed="true"] span { color: inherit; opacity: .8; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 20px 14px; }
.book { display: flex; flex-direction: column; gap: 2px; color: inherit; text-decoration: none; min-width: 0; }
.book .cover { margin-bottom: 6px; }
.book strong { font-size: .88rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fab {
  position: fixed; right: 18px; bottom: calc(76px + var(--safe-b)); z-index: 15;
  width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: var(--deep); color: var(--on-deep); box-shadow: 0 6px 18px rgba(45, 42, 38, .28);
}
.fab .i { width: 28px; height: 28px; }

/* Recherche */
.search { display: flex; gap: 8px; margin-bottom: 18px; }
.search .btn { width: 52px; padding: 0; display: grid; place-items: center; flex: none; }
.result { display: grid; grid-template-columns: 92px 1fr; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.result p { margin: 0 0 4px; }
.result .row { margin-top: 10px; }
.manual { margin-top: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 18px; }
.manual summary { min-height: var(--tap); display: flex; align-items: center; font-weight: 600; color: var(--deep); cursor: pointer; }
.manual form { padding-bottom: 16px; }
.manual label { margin-top: 12px; }
.manual input[type="file"] { padding: 9px; font-size: .9rem; }
.manual p { margin: 16px 0 8px; }

/* Fiche livre */
.book-head { display: grid; grid-template-columns: 128px 1fr; gap: 18px; align-items: end; margin: 6px 0 24px; }
.book-title { font-size: 1.5rem; line-height: 1.15; margin-bottom: 6px; }
.book-head p { margin: 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.pair .segmented button { flex: 1; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; text-align: center; margin: 4px 0 14px; }
.stepper p { margin: 0; min-width: 9ch; line-height: 1.2; }
.big { font-family: var(--serif); font-size: 2.6rem; font-weight: 700; color: var(--deep); font-variant-numeric: tabular-nums; }
.round {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; flex: none;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--deep);
}
.round.primary { background: var(--deep); border-color: var(--deep); color: var(--on-deep); }
.round:disabled { opacity: .35; cursor: default; }
.bar { height: 10px; border-radius: 999px; background: var(--pastel); overflow: hidden; margin-bottom: 14px; }
.bar span { display: block; height: 100%; border-radius: 999px; background: var(--deep); transition: width .25s; }
.inline-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 500; }
.inline-field input { width: 96px; text-align: center; }
.pair label { font-weight: 500; }
.pair input[type="date"] { margin-top: 4px; -webkit-appearance: none; appearance: none; }
.stars { display: flex; gap: 2px; margin-bottom: 12px; }
.stars button { width: 48px; height: 48px; border: 0; background: none; color: var(--line); display: grid; place-items: center; padding: 0; }
.stars .i { width: 34px; height: 34px; fill: currentColor; stroke: none; }
.stars button[aria-pressed="true"] { color: var(--deep); }
textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff;
  font: inherit; color: inherit; resize: vertical; margin-bottom: 8px;
}
textarea:focus { border-color: var(--deep); outline: none; box-shadow: 0 0 0 3px var(--pastel); }
.partner { background: var(--pastel); color: var(--deep); border-radius: var(--radius); padding: 16px 18px; }
.partner h2 { font-size: 1.1rem; }
.partner p { margin: 0; }
.stars-static { font-size: 1.3rem; letter-spacing: 2px; margin-top: 8px !important; }
.stars-static span { opacity: .25; }
.review-text { margin-top: 6px !important; white-space: pre-wrap; }
.sealed { display: flex; align-items: center; gap: 8px; margin-top: 8px !important; }
.sealed .i { width: 18px; height: 18px; }

/* Sagas */
.pill { display: inline-block; margin: 0 0 10px; padding: 3px 12px; border-radius: 999px; background: var(--pastel); color: var(--deep); font-size: .82rem; font-weight: 700; }
.pill[data-state="none"], .pill[data-state="wish"] { background: var(--line); color: var(--text); }
.pill[data-state="done"] { background: var(--deep); color: var(--on-deep); }
.duo { display: grid; gap: 6px; margin-bottom: 14px; }
.duo-line { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; color: var(--deep); }
.duo-line .bar { margin: 0; }
.duo-who { text-align: center; font-weight: 700; }
.duo-count { font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.saga-list { display: grid; gap: 14px; margin-bottom: 8px; }
.saga-card {
  display: grid; grid-template-columns: 112px 1fr; gap: 16px; align-items: center; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none;
}
.saga-card .duo { margin-bottom: 0; }
.saga-covers { display: flex; }
.saga-covers .cover { width: 64px; flex: none; }
.saga-covers .cover + .cover { margin-left: -40px; }
.saga-covers .cover:nth-child(1) { z-index: 3; } .saga-covers .cover:nth-child(2) { z-index: 2; transform: scale(.94); } .saga-covers .cover:nth-child(3) { z-index: 1; transform: scale(.88); }
.saga-covers .cover-title { font-size: .6rem; padding: 4px; }
.saga-info { min-width: 0; }
.tomes { display: grid; }
.tome { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; min-height: 72px; }
.tome .cover { width: 40px; flex: none; border-radius: 5px; box-shadow: 0 2px 6px rgba(90, 77, 60, .16); }
.tome .cover-title { font-size: 0; }
.tome-n { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--pastel); color: var(--deep); font-family: var(--serif); font-weight: 700; font-size: .95rem; }
.tome-n.side { background: none; border: 1.5px dashed var(--line-strong, #c9bfae); color: var(--muted); font-size: .8rem; }
.tome-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.tome-text strong { font-size: .95rem; }
.marks { display: flex; gap: 3px; flex: none; }
.marks span { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: .95rem; background: var(--surface); box-shadow: 0 0 0 2px var(--deep); }
.tome .row { flex: none; flex-wrap: nowrap; gap: 6px; }
.tome .btn.small { padding: 6px 12px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: var(--tap); margin-top: 8px; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--deep); }
.manual .row { margin-top: 12px; align-items: center; }
.manual .row .btn.link { width: auto; }
.series a { color: inherit; }

/* Scan du code-barres */
body.noscroll { overflow: hidden; }
.scan { position: fixed; inset: 0; z-index: 50; background: #000; display: grid; place-items: center; }
.scan video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: relative; width: min(86vw, 520px); height: 26vh; border-radius: 18px;
  border: 3px solid #fff; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5);
}
.scan-frame::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: var(--pastel); opacity: .9; }
.scan-hint {
  position: absolute; left: 0; right: 0; top: calc(50% + 13vh + 18px); margin: 0; padding: 0 24px;
  text-align: center; color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
}
.scan-close { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(32px + var(--safe-b)); }

/* Grand écran : la navigation passe sur le côté */
@media (min-width: 860px) {
  .tabbar {
    top: 0; right: auto; width: 96px; grid-template-columns: 1fr; align-content: center; gap: 6px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .topbar, main#view { margin-left: 96px; }
  main#view { max-width: none; padding-left: 32px; padding-right: 32px; }
  main#view > * { max-width: 720px; }
  .topbar { padding-left: 32px; padding-right: 32px; }
  #toast { bottom: 32px; }
  .fab { bottom: 28px; right: 28px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .chips { margin-left: 0; margin-right: 0; padding-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
