/*
 * Bibliothèque — design « Moderne coloré »
 * Icônes : Lucide (Twig : ux_icon('lucide:nom')) ; police : Nunito
 */

:root {
    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-2: #eef0f8;
    --text: #1f2340;
    --muted: #8a90ad;
    --border: #e3e5f0;
    --primary: #7b5cff;
    --primary-2: #ff5c8a;
    --gradient: linear-gradient(135deg, var(--primary), var(--primary-2));
    --on-gradient: #ffffff;
    --success: #1f9d6b;
    --warning: #e08a00;
    --info: #3a86ff;
    --error: #e5484d;
    --shadow-sm: 0 2px 8px rgba(31, 35, 64, 0.06);
    --shadow: 0 8px 24px rgba(31, 35, 64, 0.1);
    --radius-sm: 10px;
    --radius: 16px;
    --radius-lg: 22px;
    --tabbar-height: 64px;

    /* Une couleur par type de livre */
    --type-bd: #ff9f1c;
    --type-manga: #ff5c8a;
    --type-comic: #3a86ff;
    --type-novel: #2ec4b6;
    --type-other: #8a90ad;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12131c;
        --surface: #1c1e2b;
        --surface-2: #262938;
        --text: #eceefa;
        --muted: #9096b4;
        --border: #2e3144;
        --primary: #9580ff;
        --primary-2: #ff7aa2;
        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
        --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    overflow-x: hidden;
}

a {
    color: var(--primary);
}

h1,
h2,
h3 {
    line-height: 1.2;
    font-weight: 800;
}

h1 {
    font-size: 1.75rem;
    margin: 0 0 1rem;
}

svg {
    flex: none;
    vertical-align: -0.2em;
}

.muted {
    color: var(--muted);
    font-size: 0.9em;
}

/* ---------- En-tête ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.65rem 1rem;
    padding-top: calc(0.65rem + env(safe-area-inset-top));
    color: var(--on-gradient);
    background: var(--gradient);
    box-shadow: 0 4px 18px color-mix(in srgb, var(--primary) 30%, transparent);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 1.15rem;
    font-weight: 800;
    color: inherit;
    text-decoration: none;
}

.logo {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    color: var(--on-gradient);
    background: var(--gradient);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 40%, transparent);
}

/* Dans l'en-tête coloré, le logo passe en blanc */
.site-header .logo {
    color: var(--primary);
    background: #fff;
    box-shadow: none;
}

.main-nav {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
}

.main-nav a {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
}

.main-nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
}

/* Page active : pastille blanche bien visible */
.main-nav a[aria-current="page"] {
    color: var(--primary);
    background: #fff;
    box-shadow: 0 2px 8px rgba(31, 35, 64, 0.15);
}

/* ---------- Avatar et menu du profil ---------- */

.avatar {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: 800;
    color: #fff;
    background: var(--avatar-color, var(--primary));
    flex: none;
}

.profile-menu {
    position: relative;
}

.profile-menu > summary {
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.2rem 0.6rem 0.2rem 0.2rem;
    font-weight: 800;
    font-size: 0.95rem;
    list-style: none;
    cursor: pointer;
    background: var(--surface);
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
}

.profile-menu > summary::-webkit-details-marker {
    display: none;
}

.profile-menu > summary .chevron {
    color: var(--muted);
    transition: transform 0.15s;
}

.profile-menu[open] > summary .chevron {
    transform: rotate(180deg);
}

.profile-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    z-index: 30;
    min-width: 230px;
    padding: 0.4rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.profile-menu-title {
    margin: 0.35rem 0.6rem 0.25rem;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.profile-menu-panel form {
    margin: 0;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    margin: 0;
    padding: 0.5rem 0.6rem;
    font: inherit;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    color: var(--text);
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.menu-item:hover {
    background: var(--surface-2);
}

.menu-item[aria-current="true"] {
    background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.menu-item .check {
    margin-left: auto;
    color: var(--primary);
}

.menu-separator {
    height: 1px;
    margin: 0.35rem 0.4rem;
    background: var(--border);
}

.acting-banner {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 1rem 0;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, var(--surface));
    border-radius: var(--radius);
}

/* ---------- Barre d'onglets du bas (téléphone) ---------- */

.tab-bar {
    display: none;
}

@media (max-width: 700px) {
    .main-nav {
        display: none;
    }

    .profile-menu {
        margin-left: auto;
    }

    .tab-bar {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 20;
        display: flex;
        justify-content: space-around;
        height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
        padding: 0.45rem 0 env(safe-area-inset-bottom);
        background: var(--surface);
        box-shadow: 0 -4px 20px rgba(31, 35, 64, 0.08);
    }

    .tab-bar a {
        display: flex;
        flex: 1;
        flex-direction: column;
        align-items: center;
        gap: 0.15rem;
        font-size: 0.72rem;
        font-weight: 800;
        color: var(--muted);
        text-decoration: none;
    }

    .tab-bar a svg {
        font-size: 1.15rem;
    }

    .tab-bar a {
        min-height: 44px;
    }

    /* Onglet actif : pastille colorée derrière l'icône, libellé coloré */
    .tab-bar a svg {
        box-sizing: content-box;
        padding: 0.28rem 1.1rem;
        border-radius: 999px;
        transition: background 0.15s;
    }

    .tab-bar a[aria-current="page"] {
        color: var(--primary);
    }

    .tab-bar a[aria-current="page"]:not(.tab-scan) svg {
        background: color-mix(in srgb, var(--primary) 16%, transparent);
    }

    /* Bouton central « Scanner » mis en avant */
    .tab-bar a.tab-scan svg {
        box-sizing: content-box;
        padding: 0.5rem;
        margin-top: -1.1rem;
        color: var(--on-gradient);
        background: var(--gradient);
        border-radius: 14px;
        box-shadow: 0 6px 14px color-mix(in srgb, var(--primary) 45%, transparent);
    }

    /* Scanner actif : anneau autour du bouton central */
    .tab-bar a.tab-scan[aria-current="page"] svg {
        outline: 3px solid color-mix(in srgb, var(--primary) 30%, transparent);
        outline-offset: 2px;
    }

    body.has-tab-bar {
        padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 0.5rem);
    }
}

/* ---------- Mise en page ---------- */

.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 1rem 1rem 2rem;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.flash {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.error {
    color: var(--error);
}

/* ---------- Boutons et formulaires ---------- */

.button,
button[type="submit"]:not(.menu-item):not(.icon-button):not(.button-secondary):not(.star):not(.follow) {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.2rem;
    font: inherit;
    font-weight: 800;
    color: var(--on-gradient);
    text-decoration: none;
    background: var(--gradient);
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 35%, transparent);
}

.button.button-light {
    color: var(--primary);
    background: #fff;
    box-shadow: none;
}

.button-secondary {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    font: inherit;
    font-weight: 800;
    color: var(--text);
    background: var(--surface-2);
    border: 0;
    border-radius: 14px;
    box-shadow: none;
    cursor: pointer;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    margin: 0;
    padding: 0;
    color: var(--muted);
    background: var(--surface);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.icon-button:hover {
    color: var(--error);
    background: color-mix(in srgb, var(--error) 12%, transparent);
}

label {
    display: block;
    margin: 0.9rem 0 0.35rem;
    font-weight: 800;
    font-size: 0.9rem;
}

input[type="email"],
input[type="password"],
input[type="text"] {
    width: 100%;
    padding: 0.75rem 0.9rem;
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 2px solid transparent;
    border-radius: 12px;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}

input:focus {
    background: var(--surface);
    border-color: var(--primary);
}

/* ---------- Connexion ---------- */

.login {
    max-width: 380px;
    margin: 8vh auto 2rem;
    padding: 2rem 1.5rem;
    text-align: center;
}

.login .logo {
    width: 56px;
    height: 56px;
    margin: 0 auto 0.75rem;
    border-radius: 18px;
    font-size: 1.6rem;
}

.login h1 {
    margin-bottom: 0.25rem;
}

.login form {
    text-align: left;
}

.login button[type="submit"] {
    width: 100%;
    margin-top: 1.5rem;
}

/* ---------- Accueil ---------- */

.hero {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.4rem;
    margin-bottom: 1.25rem;
    color: var(--on-gradient);
    background: var(--gradient);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 28px color-mix(in srgb, var(--primary) 35%, transparent);
}

.hero-greeting {
    margin: 0 0 0.35rem;
    font-weight: 700;
    opacity: 0.9;
}

.hero-count {
    display: block;
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
}

.hero-sub {
    font-weight: 700;
    opacity: 0.9;
}

.notice {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    padding: 0.8rem 1rem;
    font-weight: 700;
    color: var(--warning);
    background: color-mix(in srgb, var(--warning) 12%, var(--surface));
    border-radius: var(--radius);
}

.notice a {
    margin-left: auto;
    color: inherit;
}

/* ---------- Onglets par type ---------- */

.tabs {
    display: flex;
    gap: 0.5rem;
    margin: 0 -1rem 1.25rem;
    padding: 0.1rem 1rem 0.4rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tabs a {
    --tab-color: var(--text);
    flex: none;
    padding: 0.4rem 0.95rem;
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--tab-color);
    text-decoration: none;
    background: color-mix(in srgb, var(--tab-color) 13%, transparent);
    border-radius: 999px;
}

.tabs a[aria-current="page"] {
    color: var(--surface);
    background: var(--text);
}

.tabs a.type-bd { --tab-color: var(--type-bd); }
.tabs a.type-manga { --tab-color: var(--type-manga); }
.tabs a.type-comic { --tab-color: var(--type-comic); }
.tabs a.type-novel { --tab-color: var(--type-novel); }
.tabs a.type-other { --tab-color: var(--type-other); }

/* ---------- Étagères et couvertures ---------- */

.shelf {
    margin: 0 0 1.75rem;
}

.shelf-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.shelf-header h2,
.shelf-header h3 {
    margin: 0;
    font-size: 1.15rem;
}

.shelf-count {
    margin-left: auto;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--muted);
    white-space: nowrap;
}

.progress {
    width: 90px;
    height: 7px;
    overflow: hidden;
    background: var(--surface-2);
    border-radius: 999px;
}

.progress span {
    display: block;
    height: 100%;
    background: var(--gradient);
    border-radius: inherit;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 1.1rem 0.85rem;
}

@media (max-width: 700px) {
    .book-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.9rem 0.6rem;
    }
}

.book-card {
    min-width: 0;
}

.book-cover {
    position: relative;
    aspect-ratio: 2 / 3;
    overflow: hidden;
    background: var(--surface-2);
    border-radius: 12px;
    box-shadow: 0 6px 14px rgba(31, 35, 64, 0.15);
}

.book-cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-cover-placeholder {
    display: grid;
    place-items: center;
    height: 100%;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--muted);
    background: linear-gradient(160deg, var(--surface-2), var(--surface));
}

.book-badge {
    position: absolute;
    top: 0.4rem;
    left: 0.4rem;
    padding: 0.05rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 800;
    color: #1f2340;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 999px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.book-warning {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    display: grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    color: #fff;
    background: var(--warning);
    border-radius: 50%;
}

.book-title {
    margin-top: 0.45rem;
    font-size: 0.85rem;
    font-weight: 800;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-meta {
    font-size: 0.78rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Emplacement d'un tome manquant */
.book-missing .book-cover {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 0.3rem;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--muted);
    background: transparent;
    border: 2px dashed var(--border);
    box-shadow: none;
}

.book-missing .book-cover svg {
    font-size: 1.3rem;
}

/* ---------- Scan ---------- */

.scanner-camera {
    position: relative;
    margin-bottom: 0.75rem;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    background: #000;
    border-radius: var(--radius);
}

.scanner-camera video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-frame {
    position: absolute;
    inset: 30% 10%;
    border: 3px solid rgba(255, 255, 255, 0.9);
    border-radius: 14px;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

.basket-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.9rem;
}

.basket-header h2 {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    font-size: 1.15rem;
}

.basket-count {
    padding: 0.2rem 0.65rem;
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    border-radius: 999px;
}

.basket-empty {
    display: none;
    margin: 0.5rem 0;
    text-align: center;
}

.basket:not(:has(.scan-result)) .basket-empty {
    display: flex;
}

/* « Vider » n'apparaît que si le panier contient quelque chose */
.stage-sheet:not(:has(.scan-result)) .basket-clear {
    display: none;
}

/* Dernier livre scanné : mis en avant en tête du panier */
.scan-results > li:first-child {
    background: color-mix(in srgb, var(--primary) 9%, var(--surface));
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent);
}

.scan-results > li:first-child .cover {
    width: 58px;
    height: 86px;
}

.scan-results > li:first-child .scan-title {
    font-size: 1.05rem;
}

.scan-results {
    display: grid;
    align-content: start;
    gap: 0.6rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.scan-result {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.6rem;
    background: var(--surface-2);
    border-radius: 14px;
}

.scan-result .cover {
    flex: none;
    width: 46px;
    height: 68px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.scan-result .cover-placeholder {
    display: grid;
    place-items: center;
    color: var(--muted);
    background: var(--surface);
}

.scan-body {
    flex: 1;
    min-width: 0;
    font-size: 0.92rem;
}

.scan-title {
    font-weight: 700;
    overflow-wrap: anywhere;
}

.scan-status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.scan-added .scan-status { color: var(--success); }
.scan-added_to_review .scan-status { color: var(--warning); }
.scan-already_owned .scan-status { color: var(--info); }
.scan-not_found .scan-status,
.scan-invalid .scan-status { color: var(--error); }

/* ---------- Famille ---------- */

.member-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.9rem;
    margin: 1rem 0 0;
    padding: 0;
    list-style: none;
}

/* Grandes cartes faciles à toucher, pour les enfants */
.member-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 1.25rem 0.75rem;
    color: var(--text);
    text-decoration: none;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s, box-shadow 0.15s;
}

.member-card:hover,
.member-card:focus-visible {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.member-card .avatar {
    width: 72px;
    height: 72px;
    font-size: 1.9rem;
}

.member-name {
    font-size: 1.1rem;
    font-weight: 800;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
    font-weight: 800;
    text-decoration: none;
}

.member-header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 1.25rem;
}

.member-header .avatar {
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
}

.member-header h1 {
    margin: 0;
}

.member-header p {
    margin: 0.15rem 0 0;
}

/* Tome manquant qu'un proche possède : « Noé l'a » */
.book-missing.is-in-family .book-cover {
    border-color: color-mix(in srgb, var(--primary) 45%, transparent);
    background: color-mix(in srgb, var(--primary) 6%, transparent);
}

.family-owners {
    display: flex;
    justify-content: center;
    margin-top: 0.35rem;
}

.family-owners .avatar {
    width: 24px;
    height: 24px;
    margin-left: -6px;
    font-size: 0.7rem;
    border: 2px solid var(--surface);
}

.family-owners .avatar:first-child {
    margin-left: 0;
}

.family-owners-label {
    font-size: 0.75rem;
    color: var(--primary);
}

/* ---------- Mon profil ---------- */

.profile-layout {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (min-width: 860px) {
    .profile-layout {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }
}

.card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.5rem;
    font-size: 1.15rem;
}

.card form button[type="submit"]:not(.star):not(.follow) {
    margin-top: 1.1rem;
}

.card .muted {
    margin: 0.3rem 0 0;
}

.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.9rem 0 0;
    padding: 0;
    border: 0;
}

.color-picker legend {
    margin-bottom: 0.4rem;
    font-weight: 800;
    font-size: 0.9rem;
}

.color-swatch {
    margin: 0;
    cursor: pointer;
}

.color-swatch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.color-swatch .avatar {
    width: 42px;
    height: 42px;
    font-size: 1.1rem;
    outline: 3px solid transparent;
    outline-offset: 2px;
    transition: outline-color 0.15s;
}

.color-swatch input:checked + .avatar {
    outline-color: var(--swatch);
}

.color-swatch input:focus-visible + .avatar {
    outline-color: var(--text);
}

.series-list {
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
}

.series-list li + li {
    border-top: 1px solid var(--border);
}

.series-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    padding: 0.6rem 0;
}

.series-name {
    flex: 1 1 10rem;
    font-weight: 800;
}

.series-row form {
    margin: 0;
}

/* Étoiles : grands boutons faciles à toucher */
.stars {
    display: flex;
    gap: 0.1rem;
}

button.star {
    display: grid;
    place-items: center;
    width: 2.2rem;
    height: 2.2rem;
    margin: 0;
    padding: 0;
    font-size: 1.15rem;
    color: var(--border);
    background: none;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

button.star:hover {
    color: #ffc53d;
}

button.star.is-on {
    color: #ffb300;
}

button.star.is-on svg,
button.star.is-on svg path {
    fill: currentColor;
}

/* Survol : allume l'étoile survolée et celles d'avant */
.stars:hover button.star {
    color: #ffc53d;
}

.stars button.star:hover ~ button.star {
    color: var(--border);
}

.follow {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
    padding: 0.4rem 0.8rem;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--muted);
    background: var(--surface-2);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}

.follow.is-on {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, transparent);
}

/* ---------- Tri et préférences dans les étagères ---------- */

/* Choix du tri : « Préférées » / « A→Z » */
.order-switch {
    display: inline-flex;
    gap: 0.2rem;
    margin: -0.5rem 0 1.25rem;
    padding: 0.2rem;
    background: var(--surface-2);
    border-radius: 999px;
}

.order-switch a {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--muted);
    text-decoration: none;
    border-radius: 999px;
}

.order-switch a[aria-current="page"] {
    color: var(--primary);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

/* « En cours » / « Terminées ou non suivies » */
.shelf-group-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0 1rem;
    padding-bottom: 0.4rem;
    font-size: 1.35rem;
    border-bottom: 2px solid var(--border);
}

.shelf-group-title svg {
    color: var(--primary);
}

.shelf-group-others {
    margin-top: 2.25rem;
    color: var(--muted);
}

.shelf-group-others svg {
    color: inherit;
}

.shelf-group-count {
    padding: 0.1rem 0.6rem;
    font-size: 0.85rem;
    color: var(--muted);
    background: var(--surface-2);
    border-radius: 999px;
}

/* Cadre Turbo autour d'une étagère : se comporte comme un bloc normal */
.shelf-frame {
    display: block;
}

.shelf-prefs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
    margin: -0.4rem 0 0.75rem;
}

.shelf-prefs form {
    margin: 0;
}

/* Étoiles un peu plus petites que dans le profil, mais toujours faciles à toucher */
.shelf-prefs button.star {
    width: 1.9rem;
    height: 1.9rem;
    font-size: 1rem;
}

.shelf-prefs .follow {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

/* Étoiles en lecture seule (bibliothèque d'un autre membre) */
.stars-readonly {
    align-items: center;
    font-size: 1rem;
    color: var(--border);
}

.stars-readonly .star {
    display: grid;
}

.stars-readonly .star.is-on {
    color: #ffb300;
}

.stars-readonly .star.is-on svg,
.stars-readonly .star.is-on svg path {
    fill: currentColor;
}

/* Série non suivie : ses tomes manquants ne sont pas recherchés, on les estompe */
.is-unfollowed .book-missing:not(.is-reserved) .book-cover {
    opacity: 0.45;
}

/* ---------- Mode de scan et « en magasin » ---------- */

.segmented {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    padding: 0.3rem;
    background: var(--surface-2);
    border-radius: 16px;
}

.segmented a {
    display: flex;
    flex: 1;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    min-height: 44px;
    padding: 0.5rem;
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--muted);
    text-align: center;
    text-decoration: none;
    border-radius: 12px;
}

.segmented a[aria-current="page"] {
    color: var(--primary);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}



.store-book {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.store-cover {
    flex: none;
    width: 72px;
    height: 106px;
    object-fit: cover;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.store-cover.cover-placeholder {
    position: relative;
    overflow: hidden;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    color: var(--muted);
    background: var(--surface-2);
}

.store-series {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--primary);
}

.store-title {
    margin: 0.1rem 0 0.2rem;
    font-size: 1.15rem;
}

.store-book .muted {
    margin: 0;
}

.store-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0 0;
    padding: 0.65rem 0.9rem;
    font-weight: 800;
    border-radius: 12px;
}

.store-summary.is-gift {
    color: var(--on-gradient);
    background: var(--gradient);
}

.store-summary.is-owned {
    color: var(--success);
    background: color-mix(in srgb, var(--success) 12%, transparent);
}

.store-summary.is-error {
    margin: 0;
    color: var(--error);
    background: color-mix(in srgb, var(--error) 10%, transparent);
}

.store-members {
    display: grid;
    gap: 0.4rem;
    margin: 0.9rem 0 0;
    padding: 0;
    list-style: none;
}

.store-member {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.6rem;
    border-radius: 12px;
    background: var(--surface-2);
}

.store-member-name {
    font-weight: 800;
}

.store-state {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: auto;
    font-size: 0.85rem;
    font-weight: 800;
    text-align: right;
}

.store-member.is-owned .store-state { color: var(--success); }
.store-member.is-missing .store-state { color: var(--muted); }

.store-member.is-gift_idea {
    background: color-mix(in srgb, var(--primary) 12%, var(--surface));
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent);
}

.store-member.is-gift_idea .store-state { color: var(--primary); }

.store-cover img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ---------- Écran de scan « à la Yuka » (Ajouter et En magasin) ---------- */

:root {
    --header-height: 58px;
}

.site-header {
    min-height: calc(var(--header-height) + env(safe-area-inset-top));
}

.stage {
    display: grid;
    gap: 1rem;
}

.stage-camera {
    position: relative;
    overflow: hidden;
    display: grid;
    place-items: center;
    min-height: 320px;
    background: #15161f;
    border-radius: var(--radius-lg);
}

.stage-camera .scanner-camera {
    position: absolute;
    inset: 0;
    margin: 0;
    aspect-ratio: auto;
    border-radius: 0;
}

.stage-aim {
    position: absolute;
    top: 22%;
    left: 0;
    right: 0;
    margin: 0;
    text-align: center;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.stage-top {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
    z-index: 2;
}

.stage-top .segmented {
    margin: 0;
    background: rgba(20, 22, 35, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.stage-top .segmented a {
    color: rgba(255, 255, 255, 0.85);
    min-height: 38px;
}

.stage-top .segmented a[aria-current="page"] {
    color: var(--primary);
    background: #fff;
}

/* Bouton caméra : grand au centre tant qu'elle est éteinte, petit dans un coin ensuite */
.stage-camera-toggle {
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 1.3rem;
    font: inherit;
    font-weight: 800;
    color: var(--primary);
    background: #fff;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.stage-camera:has(.scanner-camera:not([hidden])) .stage-camera-toggle {
    position: absolute;
    top: 4.4rem;
    right: 0.75rem;
    padding: 0.55rem;
    color: #fff;
    background: rgba(20, 22, 35, 0.55);
    box-shadow: none;
}

.stage-camera .scanner-error {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    z-index: 2;
}

.stage-sheet {
    padding: 1rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.stage-grab {
    display: none;
}

.stage-empty {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    margin: 0;
    color: var(--muted);
}

.stage-manual {
    margin-top: 0.9rem;
}

.stage-manual-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.stage-manual-form[hidden] {
    display: none;
}

.stage-manual-form button[type="submit"] {
    flex: none;
}

.stage-actions {
    display: flex;
    gap: 0.5rem;
}

.stage-actions > * {
    flex: 1;
}

.stage-actions form {
    margin: 0;
}

.stage-actions .button-secondary {
    width: 100%;
}

/* Ordinateur : champ ISBN toujours visible (douchette), pas besoin du bouton */
@media (min-width: 860px) {
    .stage-manual-form[hidden] {
        display: flex;
    }

    .stage-manual-toggle {
        display: none;
    }
}

/* Ordinateur : caméra à gauche, fiche à droite */
@media (min-width: 860px) {
    .stage {
        grid-template-columns: minmax(0, 1fr) 400px;
        align-items: start;
    }

    .stage-camera {
        aspect-ratio: 4 / 3;
    }
}

/* Téléphone : caméra plein écran, fiche par-dessus en bas */
@media (max-width: 859px) {
    body.is-stage .container {
        padding: 0;
    }

    body.is-stage .flash {
        display: none;
    }

    .stage {
        position: relative;
        display: block;
        height: calc(100dvh - var(--header-height) - env(safe-area-inset-top) - var(--tabbar-height) - env(safe-area-inset-bottom));
    }

    .stage-camera {
        position: absolute;
        inset: 0;
        min-height: 0;
        border-radius: 0;
    }

    /* Cadre de visée et bouton dans la partie haute, visible au-dessus de la fiche */
    .stage-camera .scanner-frame {
        inset: 15% 10% auto;
        height: 18%;
    }

    .stage-aim {
        top: 35%;
    }

    .stage-camera-toggle {
        position: absolute;
        top: 20%;
        left: 50%;
        transform: translateX(-50%);
        white-space: nowrap;
    }

    .stage-sheet {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 3;
        max-height: 58%;
        overflow-y: auto;
        padding: 0.4rem 1rem 1rem;
        border-radius: 22px 22px 0 0;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25);
        transition: max-height 0.25s ease;
        overscroll-behavior: contain;
    }

    .stage-sheet.is-expanded {
        max-height: 92%;
    }

    .stage-grab {
        display: block;
        width: 100%;
        height: 22px;
        margin: 0 0 0.4rem;
        padding: 0;
        background: none;
        border: 0;
        cursor: pointer;
    }

    .stage-grab::before {
        content: "";
        display: block;
        width: 44px;
        height: 5px;
        margin: 8px auto;
        background: var(--border);
        border-radius: 9px;
    }

    /* La caméra active n'a plus besoin du gros bouton : le cadre reste au-dessus de la fiche */
    .stage-camera:has(.scanner-camera:not([hidden])) .stage-camera-toggle {
        top: 4.2rem;
        left: auto;
        transform: none;
    }
}

/* Message « panier vide » : masqué dès qu'il y a un scan (après .stage-empty qui l'affichait) */
.stage-empty.basket-empty {
    display: none;
}

.basket:not(:has(.scan-result)) .stage-empty.basket-empty {
    display: flex;
}

/* ---------- Cadeaux ---------- */

.store-flash {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.9rem;
    font-weight: 800;
}

.flash-success { color: var(--success); }
.flash-error { color: var(--error); }

.store-member {
    display: block;
}

.store-member-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.store-member.is-reserved {
    background: color-mix(in srgb, var(--warning) 12%, var(--surface));
}

.store-member.is-reserved .store-state {
    color: var(--warning);
}

.gift-form {
    margin-top: 0.5rem;
}

.gift-form > summary {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--primary);
    list-style: none;
    cursor: pointer;
    background: var(--surface);
    border-radius: 999px;
}

.gift-form > summary::-webkit-details-marker {
    display: none;
}

.gift-form form {
    display: grid;
    gap: 0.5rem;
    margin-top: 0.6rem;
    padding: 0.75rem;
    background: var(--surface);
    border-radius: 12px;
}

.gift-choice {
    display: grid;
    gap: 0.25rem;
}

.gift-form label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 0.9rem;
    font-weight: 700;
}

.gift-form input[type="radio"],
.gift-form input[type="checkbox"] {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--primary);
}

.gift-form button[type="submit"] {
    margin-top: 0.25rem;
}

/* Page « Cadeaux » */
.gift-group {
    margin-bottom: 1rem;
}

.gift-group-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.gift-list {
    display: grid;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.gift-card {
    display: flex;
    gap: 0.85rem;
    padding: 0.6rem;
    background: var(--surface-2);
    border-radius: 14px;
}

.gift-card-cover {
    display: grid;
    place-items: center;
    flex: none;
    width: 56px;
    height: 82px;
    overflow: hidden;
    color: var(--muted);
    background: var(--surface);
    border-radius: 8px;
}

.gift-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gift-card-body {
    flex: 1;
    min-width: 0;
}

.gift-card-title {
    margin: 0.1rem 0;
    font-weight: 800;
}

.gift-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.75rem;
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.gift-status {
    padding: 0 0.5rem;
    font-weight: 800;
    border-radius: 999px;
}

.gift-status.is-purchased {
    color: var(--success);
    background: color-mix(in srgb, var(--success) 12%, transparent);
}

.gift-status.is-planned {
    color: var(--warning);
    background: color-mix(in srgb, var(--warning) 12%, transparent);
}

.gift-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.gift-actions form {
    margin: 0;
}

.gift-actions button[type="submit"]:not(.icon-button) {
    padding: 0.5rem 0.9rem;
    font-size: 0.9rem;
}

.gift-other {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.gift-history {
    margin: 0;
    padding: 1rem 1.25rem;
    list-style: none;
}

.gift-history li + li {
    margin-top: 0.4rem;
}

/* Tome manquant déjà réservé en cadeau (vu par un adulte) */
.book-missing.is-reserved .book-cover {
    border-color: color-mix(in srgb, var(--warning) 55%, transparent);
    background: color-mix(in srgb, var(--warning) 8%, transparent);
}

.book-missing.is-reserved .family-owners-label {
    color: var(--warning);
}

/* Bouton secondaire sur fond gris (cartes de cadeaux) : fond blanc pour rester visible */
.gift-card .button-secondary {
    background: var(--surface);
}

/* ---------- Connexion : nos héros de BD ---------- */

body.is-login {
    background:
        radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 40%),
        radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--primary-2) 18%, transparent), transparent 40%),
        var(--bg);
    min-height: 100vh;
}

.login-scene {
    position: relative;
    max-width: 760px;
    margin: 0 auto;
    padding-top: 1rem;
}

.login-scene .login {
    position: relative;
    z-index: 1;
    margin-top: 1.25rem;
}

.login-heroes {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem 0.9rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.login-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    width: 76px;
    animation: hero-float 4.5s ease-in-out infinite;
    animation-delay: calc(var(--i) * -0.7s);
}

.login-hero img {
    width: 68px;
    height: 68px;
    object-fit: cover;
    border: 4px solid #fff;
    border-radius: 50%;
    box-shadow: 0 6px 18px rgba(31, 35, 64, 0.22);
    transform: rotate(calc((var(--i) - 2.5) * 3deg));
}

.login-hero span {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    white-space: nowrap;
}

@keyframes hero-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
    .login-hero {
        animation: none;
    }
}

/* Grand écran : les héros s'installent autour du formulaire */
@media (min-width: 760px) {
    .login-scene {
        min-height: 620px;
    }

    .login-heroes {
        position: absolute;
        inset: 0;
        display: block;
    }

    .login-hero {
        position: absolute;
        width: 112px;
    }

    .login-hero img {
        width: 100px;
        height: 100px;
    }

    .login-hero span {
        font-size: 0.8rem;
    }

    /* Trois à gauche, trois à droite, en quinconce */
    .login-hero:nth-child(1) { top: 9%; left: 2%; }
    .login-hero:nth-child(2) { top: 40%; left: -4%; }
    .login-hero:nth-child(3) { top: 71%; left: 5%; }
    .login-hero:nth-child(4) { top: 6%; right: 3%; }
    .login-hero:nth-child(5) { top: 37%; right: -3%; }
    .login-hero:nth-child(6) { top: 69%; right: 4%; }

    .login-scene .login {
        margin-top: 8vh;
    }
}

span.follow {
    cursor: default;
}
