:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #667085;
  --navy: #0f1623;
  --cream: #e8e2d0;
  --slate: #8b93a1;
  --tile: #182234;
  --primary: #1b2740;
  --primary-text: #ffffff;
  --accent: #f5b800;
  --st-reading: #1d63c9;
  --st-reading-text: #ffffff;
  --ok-text: #ffffff;
  --danger: #b42318;
  --ok: #1a7f4b;
  --border: #e3ddd0;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161f;
    --surface: #1b2230;
    --text: #e8eaf0;
    --muted: #98a2b3;
    --primary: #f5b800;
    --primary-text: #1a1400;
    --st-reading: #6ea8ff;
    --st-reading-text: #071a33;
    --ok-text: #07230f;
    --border: #2b3447;
    --danger: #f97066;
    --ok: #47cd89;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.25rem; }
.muted { color: var(--muted); font-size: .9rem; }
.book .meta .muted { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hidden { display: none !important; }

header.bar {
  position: sticky; top: 0; z-index: 5;
  background: var(--navy); color: var(--cream);
  padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem;
  display: flex; align-items: center; gap: .75rem;
}
.brand { display: inline-flex; align-items: center; gap: .45rem; text-decoration: none; color: inherit; }
.brand-mark svg { display: block; height: 1.9rem; width: auto; }
.brand-word { font-weight: 700; font-size: 1.3rem; letter-spacing: -.01em; line-height: 1; }
.brand-word .w-my { color: var(--slate); font-weight: 400; }
.brand-word .w-bi { color: var(--cream); }
.brand-word .w-bli { color: var(--accent); }
header.bar .brand { margin-right: auto; }
h1.auth-logo { display: flex; justify-content: center; padding: .9rem; margin: 0 0 .75rem; background: var(--navy); border-radius: var(--radius); }
h1.auth-logo .brand-mark svg { height: 3rem; }
h1.auth-logo .brand-word { font-size: 2.2rem; }
header.bar button { background: transparent; color: inherit; border: 1px solid currentColor; }
nav.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  flex: 1 0 auto; text-align: center; padding: .7rem .6rem; text-decoration: none; white-space: nowrap;
  color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600;
}
@media (max-width: 480px) { nav.tabs a { padding: .7rem .45rem; font-size: .85rem; } }
nav.tabs a.active { color: var(--primary); border-bottom-color: var(--accent); }

main { max-width: 960px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
}
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 10rem; }
.stack > * + * { margin-top: .75rem; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; padding: .65rem .75rem; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 5rem; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; }
/* Même contour de focus partout (marque : ambre) */
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
button:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, .btn {
  font: inherit; font-weight: 600; padding: .65rem 1rem; border-radius: 8px; cursor: pointer;
  background: var(--primary); color: var(--primary-text); border: 1px solid var(--primary);
  text-decoration: none; display: inline-block; text-align: center;
}
button.secondary, .btn.secondary { background: transparent; color: var(--primary); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
button.block, .btn.block { display: block; width: 100%; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); text-decoration: underline; font-weight: 400; }

.error { color: var(--danger); font-weight: 600; }
.notice { color: var(--ok); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.book {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column;
}
.cover {
  aspect-ratio: 2 / 3; background: linear-gradient(90deg, var(--accent) 0 6px, var(--tile) 6px);
  display: flex; align-items: center; justify-content: center; text-align: center; box-shadow: inset 0 0 0 1px rgba(232, 226, 208, .12);
  color: var(--cream); padding: .5rem .5rem .5rem calc(.5rem + 6px); font-weight: 700; font-size: .9rem; overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book .meta { padding: .5rem .6rem .7rem; }
.book .title { font-weight: 700; font-size: .92rem; overflow-wrap: anywhere; }
.badge {
  display: inline-block; font-size: .75rem; font-weight: 700; padding: .1rem .5rem;
  border-radius: 999px; background: var(--accent); color: #2b2100; margin-top: .3rem;
}
.badge.late { background: var(--danger); color: #fff; }
.badge.read { background: var(--ok); color: var(--ok-text); }

.detail { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 600px) { .detail { grid-template-columns: 180px 1fr; } }

.fab {
  position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom));
  border-radius: 999px; padding: .9rem 1.2rem; box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
/* Mobile : la barre du navigateur apparaît quand on remonte et recouvrait le bouton. 100dvh suit la zone
   réellement visible, donc le bouton reste au-dessus de la barre dans les deux cas. */
@supports (height: 100dvh) {
  .fab { bottom: auto; top: calc(100dvh - 1rem - env(safe-area-inset-bottom)); transform: translateY(-100%); }
}

.scanner {
  position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column;
}
.scanner video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.scanner .frame {
  position: absolute; left: 10%; right: 10%; top: 30%; height: 22%;
  border: 3px solid var(--accent); border-radius: 12px; pointer-events: none;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.45);
}
.scanner .bottom { padding: 1rem; background: #000; color: #fff; text-align: center; }

.list-item { display: flex; gap: .75rem; align-items: center; justify-content: space-between; padding: .6rem 0; border-top: 1px solid var(--border); }
.list-item:first-child { border-top: 0; }
.tabs-inline { display: flex; gap: .5rem; margin-bottom: 1rem; }
.tabs-inline button { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.detail .cover { max-width: 180px; width: 100%; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: transparent; color: var(--text); padding: .6rem 1rem; white-space: nowrap; }
.segmented.block { display: flex; }
.segmented.block button { flex: 1; }
.segmented button[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); }
.progress { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: .4rem; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.book.missing { opacity: .55; border-style: dashed; background: transparent; filter: grayscale(1); }
.book.missing .cover { background: var(--border); color: var(--muted); }
.badge.missing-badge { background: var(--border); color: var(--muted); }
.book.missing.selectable { cursor: pointer; text-align: left; font: inherit; color: inherit; padding: 0; }
.book.missing.selected { opacity: 1; filter: none; border: 2px solid var(--accent); background: var(--surface); }
.book.missing.selected .cover { background: var(--accent); color: #2b2100; }
.book.missing.selected .badge.missing-badge { background: var(--accent); color: #2b2100; }
.selection-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom));
  display: flex; gap: .75rem; align-items: center; padding: .7rem 1rem; z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
.badge.notowned { background: transparent; color: var(--muted); border: 1px dashed var(--muted); margin-right: .25rem; }
.badge.reading { background: var(--st-reading); color: var(--st-reading-text); }

/* Gros bouton d'activation : ambre pour activer, ardoise pour désactiver */
button.big { width: 100%; padding: 1rem 1.25rem; font-size: 1.1rem; font-weight: 700; border-radius: var(--radius); border: 0; cursor: pointer; }
button.big.on { background: var(--accent); color: #1a1400; }
button.big.off { background: var(--slate); color: var(--navy); }
button.big:disabled { opacity: .6; cursor: default; }
button.big:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

.badge.notread { background: transparent; color: var(--muted); border: 1px solid var(--border); margin-right: .25rem; }

/* Boutons Non lu / En cours / Lu : une couleur par état */
.segmented.status button[aria-pressed="true"][data-s="unread"] { background: var(--slate); color: var(--navy); }
.segmented.status button[aria-pressed="true"][data-s="reading"] { background: var(--st-reading); color: var(--st-reading-text); }
.segmented.status button[aria-pressed="true"][data-s="read"] { background: var(--ok); color: var(--ok-text); }
.segmented.status { display: flex; }
.segmented.status button { flex: 1; }
.segmented.mini button { padding: .35rem .1rem; font-size: .75rem; }
.tile { display: flex; flex-direction: column; gap: .4rem; }
.tile > a.book { flex: 1; }
