:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --text: #1c1b1a;
  --muted: #6b6762;
  --border: #e2dfda;
  /* Couleurs de texte et de fond choisies pour un contraste ≥ 4,5:1 (WCAG AA).
     L'orange de marque (#e8590c, icônes) est trop clair pour porter du texte blanc. */
  --accent: #c2410c;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --focus: #1971c2;
  --radius: 10px;
  --lvl-new: #2f7a3a;
  --lvl-started: #4d7c0f;
  --lvl-half: #b35c00;
  --lvl-low: #c2410c;
  --lvl-empty: #6c7178;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #211f1e;
    --text: #f1efec;
    --muted: #a39e98;
    --border: #36332f;
    --accent: #ff7a2e;
    --accent-text: #1c1b1a;
    --danger: #ff6b6b;
    --focus: #74c0fc;
    --lvl-new: #69db7c;
    --lvl-started: #94d82d;
    --lvl-half: #ffa94d;
    --lvl-low: #ff8a5b;
    --lvl-empty: #adb5bd;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
.card h2:first-child, .danger-zone h2:first-child { margin-top: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Structure ------------------------------------------------------------- */

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: .75rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; text-decoration: none; }
.nav { display: flex; gap: .25rem; overflow-x: auto; margin-left: auto; }
.nav a {
  padding: .35rem .6rem; border-radius: 6px; text-decoration: none; color: var(--muted); white-space: nowrap;
}
.nav a[aria-current="page"] { color: var(--text); background: var(--bg); font-weight: 600; }

/* Barre d'onglets mobile : remplace les liens du haut, seule la cloche y reste. */
.tabbar { display: none; }
@media (max-width: 720px) {
  .nav a:not(.bell) { display: none; }
  .tabbar {
    position: fixed; z-index: 10; left: 0; right: 0; bottom: 0;
    display: grid; grid-template-columns: repeat(5, 1fr);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  body:has(.tabbar) { padding-bottom: calc(3.75rem + env(safe-area-inset-bottom)); }
  body:has(.tabbar) .select-bar { bottom: calc(3.75rem + env(safe-area-inset-bottom)); }
}
.tabbar > a, .tabbar summary {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
  min-height: 3.75rem; padding: .35rem .2rem;
  font-size: .7rem; font-weight: 500; color: var(--muted); text-decoration: none;
  cursor: pointer; list-style: none; -webkit-tap-highlight-color: transparent;
}
.tabbar summary::-webkit-details-marker { display: none; }
.tabbar svg {
  width: 1.5rem; height: 1.5rem;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.tabbar > a[aria-current="page"], .tabbar summary.current, .tabbar-more[open] summary { color: var(--accent); font-weight: 600; }
.tabbar-more { position: relative; }
.tabbar-menu {
  position: absolute; right: .5rem; bottom: calc(100% + .5rem); min-width: 11rem;
  display: flex; flex-direction: column; padding: .35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / .18);
}
.tabbar-menu a { padding: .7rem .85rem; border-radius: 6px; text-decoration: none; }
.tabbar-menu a[aria-current="page"] { background: var(--bg); font-weight: 600; }

.container { max-width: 880px; margin: 0 auto; padding: 1rem 16px 3rem; }
.narrow { max-width: 440px; margin: 2rem auto 0; }
/* Formulaires courts (connexion, code, inscription) : champs et bouton espacés, bouton pleine largeur. */
.narrow .card, .narrow .card > form:not(.actions) { display: flex; flex-direction: column; gap: 1rem; }
.narrow .card { padding: 1.25rem; }
.narrow .card > *, .narrow .card > form > * { margin: 0; }
.narrow .card > .btn, .narrow .card > form:not(.actions) > .btn { width: 100%; }
.footer { text-align: center; padding: 1rem; font-size: .875rem; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.toolbar h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.card .actions, .danger-zone .actions { margin-top: 1rem; justify-content: flex-end; }

.card, .danger-zone {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.flash {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: 1rem;
}
.notice { background: var(--bg); border-radius: 6px; padding: .5rem .75rem; margin-top: 0; }

/* Formulaires ------------------------------------------------------------ */

label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: .45rem; font-weight: 400; }
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]):not([type=color]), select, textarea {
  width: 100%;
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  min-height: 2.6rem;
}
input[type=color] {
  width: 100%; height: 2.6rem; padding: .2rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
input[type=checkbox], input[type=radio] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.field-error { color: var(--danger); font-size: .85rem; font-weight: 400; }
.code-input { font-size: 1.6rem; letter-spacing: .3em; text-align: center; }

.grid { display: grid; gap: .85rem; grid-template-columns: 1fr; }
@media (min-width: 600px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .grid .full { grid-column: 1 / -1; }
}
[hidden] { display: none !important; }

.inline-form { display: flex; gap: .5rem; align-items: flex-end; }
.inline-form label { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 2.6rem; padding: .5rem 1rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  text-decoration: none; cursor: pointer; font-weight: 500;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 2rem; padding: .2rem .6rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Filtres ---------------------------------------------------------------- */

.filters { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.filters fieldset { border: 0; padding: 0; margin: 0; }
.families { display: flex; flex-wrap: wrap; gap: .4rem; }
.pill {
  flex-direction: row; align-items: center; gap: .35rem;
  padding: .25rem .6rem .25rem .3rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-weight: 400; font-size: .85rem;
}
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pill:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

.more { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.more summary { padding: .6rem .9rem; cursor: pointer; font-weight: 500; }
.filter-groups { display: grid; gap: 1rem; padding: 0 .9rem .9rem; grid-template-columns: 1fr; }
@media (min-width: 600px) { .filter-groups { grid-template-columns: repeat(3, 1fr); } }
.filter-groups legend { font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }
.near { display: flex; gap: .5rem; margin-top: .4rem; }
.near input[type=color] { width: 3.2rem; flex: none; }
.sort-row { display: flex; align-items: flex-end; gap: 1rem; }
.sort-row label { flex-direction: row; align-items: center; gap: .5rem; }
.sort-row select { width: auto; }

/* Listes ----------------------------------------------------------------- */

.count { color: var(--muted); font-size: .875rem; margin: 0 0 .5rem; }
.spools { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .4rem; }
.spool {
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem .7rem;
}
.spool.is-empty { opacity: .55; }
.spool-main { flex: 1; min-width: 0; display: flex; flex-direction: column; text-decoration: none; }
.spool-main strong, .spool-main .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spool-main .muted { font-size: .85rem; }
.swatch {
  display: inline-block; flex: none; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
}
.pill .swatch { width: 1.1rem; height: 1.1rem; }
.swatch.lg { width: 2.6rem; height: 2.6rem; }
.delta { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.count-badge { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.qty { width: 4.2rem !important; flex: none; }

select.level {
  width: auto; flex: none; min-height: 2.1rem; padding: .2rem 1.6rem .2rem .55rem;
  font-size: .85rem; font-weight: 600; border-radius: 999px;
  border: 1px solid currentColor; background: var(--surface);
}
.level-new { color: var(--lvl-new); }
.level-started { color: var(--lvl-started); }
.level-half { color: var(--lvl-half); }
.level-low { color: var(--lvl-low); }
.level-empty { color: var(--lvl-empty); }
select.level option { color: var(--text); }

span.level {
  flex: none; padding: .15rem .6rem; border: 1px solid currentColor; border-radius: 999px;
  font-size: .8rem; font-weight: 600; white-space: nowrap;
}
.tag {
  flex: none; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; white-space: nowrap;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
}
.tag.lent { color: var(--focus); border-color: color-mix(in srgb, var(--focus) 40%, var(--border)); }
.swatch.sm { width: .9rem; height: .9rem; vertical-align: -2px; }

.product-summary { display: flex; align-items: center; gap: .9rem; }

/* Amis, prêts, notifications ------------------------------------------------ */

.bell { position: relative; display: inline-flex; align-items: center; }
.badge-count {
  position: absolute; top: -.15rem; right: -.2rem; min-width: 1.05rem; height: 1.05rem; padding: 0 .25rem;
  border-radius: 999px; background: var(--accent); color: var(--accent-text);
  font-size: .7rem; font-weight: 700; line-height: 1.05rem; text-align: center;
}
.scope { flex-direction: row; align-items: center; gap: .5rem; }
.scope select { width: auto; flex: 1; max-width: 22rem; }
.select-form .spool input[type=checkbox] { flex: none; }
.select-bar {
  position: sticky; bottom: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  margin-top: .75rem; padding: .6rem .7rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.card.highlight { border-color: var(--accent); }
.plain-list, .history, .compact { list-style: none; padding: 0; margin: .75rem 0 0; }
.plain-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .4rem 0; border-top: 1px solid var(--border); }
.history li { padding: .45rem 0; border-top: 1px solid var(--border); }
.history li .muted { display: inline-block; min-width: 6.5rem; }
.notifications li.unread a { font-weight: 600; }
.compact li { padding: .15rem 0; font-size: .9rem; }
.message { margin: .5rem 0; padding: .5rem .75rem; border-left: 3px solid var(--border); color: var(--muted); font-style: italic; }
form.inline { display: inline; }
.loan-row { flex-wrap: wrap; }
.loan-action { display: flex; gap: .4rem; align-items: center; }
.loan-action select { width: auto; min-height: 2rem; padding: .2rem .4rem; }
.level-select { width: auto !important; min-height: 2rem !important; padding: .2rem .4rem !important; }
section > h2 { margin-top: 1.5rem; }

/* Passkeys ------------------------------------------------------------------------ */

.passkey-form { margin-top: .75rem; }
.passkey-login { text-align: center; margin-top: .5rem; }
.passkey-login .btn { width: 100%; }

/* Partages 3D ------------------------------------------------------------------ */

.share-head-link { display: flex; gap: .9rem; align-items: center; margin-bottom: .75rem; text-decoration: none; color: inherit; }
.share-head-link:hover .share-name { text-decoration: underline; }
.share-thumb {
  flex: none; width: 96px; height: 96px; border-radius: 8px; object-fit: contain;
  background: var(--bg); border: 1px solid var(--border);
}
.share-title { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.share-name { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }
.danger-tag { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.choice { display: flex; gap: .75rem; align-items: flex-start; padding: .6rem; background: var(--bg); border-radius: 8px; }
.share-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem; }
.compact-form input { min-height: 2rem !important; padding: .25rem .5rem !important; width: 13rem !important; }
.compact-form { align-items: center; }

.share-head h1 { margin-bottom: .25rem; }
.viewer {
  position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 70vh;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg);
}
.viewer canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewer-status {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  margin: 0; color: var(--muted); text-align: center; padding: 1rem;
}
.viewer-tools { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin: .6rem 0 .25rem; }
.swatches { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); margin-bottom: 1rem; }
.swatch-option {
  flex-direction: row; align-items: center; gap: .6rem; padding: .5rem .6rem; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-weight: 400;
}
.swatch-option input { position: absolute; opacity: 0; pointer-events: none; }
.swatch-option:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.swatch-option:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.swatch-text { display: flex; flex-direction: column; min-width: 0; }

.empty-state { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty-state strong { color: var(--text); }

/* Scanner ---------------------------------------------------------------- */

.scanner {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem; margin-bottom: 1rem;
}
.scanner video { width: 100%; max-height: 50vh; border-radius: 8px; background: #000; object-fit: cover; }
.scanner p { margin: 0; text-align: center; }

/* Pages de contenu ---------------------------------------------------------- */

.hero { max-width: 560px; margin: 2rem auto; text-align: center; }
.hero h1 { font-size: 1.9rem; }
.features { text-align: left; color: var(--muted); padding-left: 1.2rem; }
.prose { max-width: 680px; }
