/* =====================================================================
   Bricks Wargame — thème « Holo tactique »
   Sombre, accents cyan (action) et ambre (points). Conçu d'abord pour le téléphone.
   Thème clair en option (voir « Thème clair ») : n'écrire les couleurs qu'avec les variables.
   ===================================================================== */

:root {
    color-scheme: dark;

    --bg: #05080f;
    --bg-raise: #09101c;
    --panel: #0d1727;
    --panel-2: #122035;
    --panel-3: #182a45;
    --line: #1d3050;
    --line-strong: #2b4670;
    --text: #e3edfa;
    --muted: #94a8c4;
    --faint: #63799b;

    /* Accents : --cyan, --amber… pour les textes, icônes et contours ; --cyan-fill et --amber-fill
       pour les aplats portant un texte foncé (--cyan-ink, --amber-ink). Mêmes teintes en sombre,
       distinctes en clair où le texte coloré doit être plus soutenu pour rester lisible. */
    --cyan: #4fd8ff;
    --cyan-fill: #4fd8ff;
    --cyan-2: #a3ecff;
    --cyan-ink: #03131d;
    --cyan-soft: rgba(79, 216, 255, 0.12);
    --cyan-line: rgba(79, 216, 255, 0.45);
    --amber: #ffb547;
    --amber-fill: #ffb547;
    --amber-2: #ffc978;
    --amber-ink: #1d1200;
    --amber-soft: rgba(255, 181, 71, 0.13);
    --amber-line: rgba(255, 181, 71, 0.45);
    --red: #ff6473;
    --red-text: #ffd3d8;
    --red-soft: rgba(255, 100, 115, 0.13);
    --red-line: rgba(255, 100, 115, 0.45);
    --green: #4be3a5;
    --green-soft: rgba(75, 227, 165, 0.12);
    --green-line: rgba(75, 227, 165, 0.45);

    --faction: var(--cyan);

    /* Surfaces translucides (barres, fenêtres flottantes) et voile derrière les fenêtres. */
    --bg-glow: rgba(79, 216, 255, 0.09);
    --bar-bg: rgba(5, 8, 15, 0.82);
    --bar-bg-strong: rgba(5, 8, 15, 0.9);
    --tabbar-bg: rgba(9, 16, 28, 0.94);
    --float-bg: rgba(13, 23, 39, 0.96);
    --backdrop: rgba(2, 5, 10, 0.72);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a8c4' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

    --font-ui: "Oxanium", "Bahnschrift", "Segoe UI", sans-serif;
    --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;

    --radius-sm: 7px;
    --radius: 12px;
    --radius-lg: 18px;
    --tabbar-h: 64px;
    --topbar-h: 58px;
    --sidebar-w: 248px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    /* Marges latérales du contenu : 16px, davantage sous l'encoche d'un téléphone tenu en paysage
       (viewport-fit=cover). Redéfinies par les panneaux coulissants : les rangées « bord à bord »
       (onglets, puces, barre de partie) s'alignent sur la marge de leur conteneur. */
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --gutter-l: max(16px, var(--safe-l));
    --gutter-r: max(16px, var(--safe-r));
    --glow: 0 0 0 1px var(--cyan-line), 0 0 22px rgba(79, 216, 255, 0.16);
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
    /* Halos « néon » : remplacés par des ombres discrètes, ou retirés, en thème clair. */
    --glow-primary: 0 0 20px rgba(79, 216, 255, 0.25);
    --glow-fab: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 24px rgba(79, 216, 255, 0.3);
    --glow-selected: 0 0 14px rgba(79, 216, 255, 0.18);
    --glow-tab: 0 0 12px var(--cyan);
    --glow-points: 0 0 22px rgba(255, 181, 71, 0.35);
    --glow-pip: 0 0 6px rgba(75, 227, 165, 0.5);
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* Couleurs des factions (choisies dans l'admin). */
[data-faction="cyan"] { --faction: #4fd8ff; }
[data-faction="ambre"] { --faction: #ffb547; }
[data-faction="rouge"] { --faction: #ff7466; }
[data-faction="vert"] { --faction: #4be3a5; }
[data-faction="bleu"] { --faction: #7da6ff; }
[data-faction="violet"] { --faction: #b896ff; }
[data-faction="acier"] { --faction: #b9c7da; }

/* ---------- Thème clair ----------
   Posé par js/theme.js (data-theme="light" sur <html>, avant l'affichage) : choix fait dans
   « Compte » ou la barre latérale, ou réglage clair de l'appareil en mode automatique.
   Seules les variables changent. Textes colorés plus soutenus : contraste d'au moins 4,5:1. */

:root[data-theme="light"] {
    color-scheme: light;

    --bg: #eef2f8;
    --bg-raise: #f6f8fc;
    --panel: #ffffff;
    --panel-2: #f8fafd;
    --panel-3: #e9eff7;
    --line: #d5dee9;
    --line-strong: #9fb0c5;
    --text: #0e1a2c;
    --muted: #45576f;
    --faint: #56698a;

    --cyan: #00668f;
    --cyan-fill: #1fb0e0;
    --cyan-2: #12a2d2;
    --cyan-soft: rgba(0, 102, 143, 0.1);
    --cyan-line: rgba(0, 102, 143, 0.4);
    --amber: #9c4d00;
    --amber-fill: #f0a01e;
    --amber-2: #e39414;
    --amber-soft: rgba(156, 77, 0, 0.1);
    --amber-line: rgba(156, 77, 0, 0.4);
    --red: #b42235;
    --red-text: #8f1d2c;
    --red-soft: rgba(180, 34, 53, 0.1);
    --red-line: rgba(180, 34, 53, 0.45);
    --green: #036c4c;
    --green-soft: rgba(3, 108, 76, 0.1);
    --green-line: rgba(3, 108, 76, 0.4);

    --bg-glow: rgba(31, 176, 224, 0.1);
    --bar-bg: rgba(238, 242, 248, 0.86);
    --bar-bg-strong: rgba(238, 242, 248, 0.92);
    --tabbar-bg: rgba(255, 255, 255, 0.94);
    --float-bg: rgba(255, 255, 255, 0.97);
    --backdrop: rgba(14, 26, 44, 0.42);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2345576f' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

    --glow: 0 0 0 1px var(--cyan-line), 0 6px 18px rgba(0, 80, 120, 0.12);
    --shadow: 0 18px 48px rgba(16, 34, 60, 0.18);
    --glow-primary: 0 2px 8px rgba(0, 120, 170, 0.22);
    --glow-fab: 0 10px 26px rgba(16, 34, 60, 0.28);
    --glow-selected: none;
    --glow-tab: none;
    --glow-points: none;
    --glow-pip: none;
}

:root[data-theme="light"] [data-faction="cyan"] { --faction: #00668f; }
:root[data-theme="light"] [data-faction="ambre"] { --faction: #9c4d00; }
:root[data-theme="light"] [data-faction="rouge"] { --faction: #b3342a; }
:root[data-theme="light"] [data-faction="vert"] { --faction: #036c4c; }
:root[data-theme="light"] [data-faction="bleu"] { --faction: #2d5bd0; }
:root[data-theme="light"] [data-faction="violet"] { --faction: #7347d1; }
:root[data-theme="light"] [data-faction="acier"] { --faction: #4f6079; }

:root[data-theme="light"] .faction-dot {
    box-shadow: none;
}

/* Jauge de budget : aplats vifs, sans halo. */
:root[data-theme="light"] .meter-fill {
    background: linear-gradient(90deg, var(--cyan-fill), var(--cyan-2));
    box-shadow: none;
}

:root[data-theme="light"] .meter.is-near .meter-fill {
    background: linear-gradient(90deg, var(--amber-fill), var(--amber-2));
    box-shadow: none;
}

:root[data-theme="light"] .meter.is-over .meter-fill {
    background: repeating-linear-gradient(135deg, var(--amber-fill) 0 10px, color-mix(in srgb, var(--amber-fill) 55%, #fff) 10px 20px);
    box-shadow: none;
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    /* Champ atteint au clavier ou ancre : visible entre la barre du haut et les onglets. */
    scroll-padding-top: calc(var(--topbar-h) + 12px);
    scroll-padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
}

/* Barre d'enregistrement collée en bas (règles, unités) : le champ suivi reste au-dessus. */
html:has(.save-bar) {
    scroll-padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 96px);
}

@media (min-width: 1024px) {
    html {
        scroll-padding-bottom: 12px;
    }

    html:has(.save-bar) {
        scroll-padding-bottom: 96px;
    }
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100svh; /* hauteur visible avec les barres du navigateur mobile */
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text);
    background:
        radial-gradient(900px 480px at 50% -220px, var(--bg-glow), transparent 70%),
        var(--bg);
    -webkit-tap-highlight-color: transparent;
    /* Un mot plus large que l'écran (nom sans espace, e-mail, lien) passe à la ligne. */
    overflow-wrap: break-word;
}

h1,
h2,
h3,
h4 {
    margin: 0;
    font-family: var(--font-ui);
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: 0.01em;
}

p {
    margin: 0;
}

a {
    color: var(--cyan);
    text-underline-offset: 3px;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

/* Pas de zoom au double toucher sur les commandes : les touches rapides (PV, tours,
   compteurs) restent des touches. Le zoom à deux doigts reste possible. */
a,
button,
input,
select,
textarea,
label,
summary {
    touch-action: manipulation;
}

/* Touches répétées ou appui long sur un bouton : pas de sélection de texte. */
.btn,
.chip,
.seg label,
.stepper button,
.tabbar a,
.tabs button,
.tabs a,
.game-dots button {
    -webkit-user-select: none;
    user-select: none;
}

/* Rangées qui défilent de côté : arrivé au bout, le geste ne fait pas « Retour » dans le navigateur. */
.tabs,
.chips-scroll,
.game-track,
.table-wrap {
    overscroll-behavior-x: contain;
}

img {
    max-width: 100%;
}

:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: 12px;
    top: -60px;
    z-index: 100;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    background: var(--cyan-fill);
    color: var(--cyan-ink);
    font-weight: 700;
}

.skip-link:focus {
    top: 12px;
}

.icon {
    width: 1.25em;
    height: 1.25em;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}

.num {
    font-family: var(--font-ui);
    font-variant-numeric: tabular-nums;
}

.label {
    font-family: var(--font-ui);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

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

.small {
    font-size: 0.875rem;
}

.text-amber { color: var(--amber); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-cyan { color: var(--cyan); }

/* ---------- Structure : barre latérale, barre du haut, onglets ---------- */

.sidebar {
    display: none;
}

.shell {
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: var(--topbar-h);
    padding: 6px max(10px, var(--safe-r)) 6px var(--gutter-l);
    background: var(--bar-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}

.topbar-back {
    margin-left: -8px;
}

.topbar-title {
    flex: 1;
    min-width: 0;
    font-size: 1.15rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
    font-family: var(--font-ui);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.main {
    flex: 1;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 16px var(--gutter-r) calc(var(--tabbar-h) + var(--safe-b) + 32px) var(--gutter-l);
    display: grid;
    gap: 20px;
    align-content: start;
}

.main-narrow {
    max-width: 720px;
}

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    padding: 0 max(4px, var(--safe-r)) var(--safe-b) max(4px, var(--safe-l));
    background: var(--tabbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
}

.tabbar a {
    flex: 1;
    min-width: 0;
    height: var(--tabbar-h);
    display: grid;
    place-items: center;
    align-content: center;
    gap: 3px;
    color: var(--faint);
    text-decoration: none;
    font-family: var(--font-ui);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    position: relative;
}

.tabbar a .icon {
    width: 24px;
    height: 24px;
}

.tabbar a[aria-current="page"] {
    color: var(--cyan);
}

.tabbar a[aria-current="page"]::before {
    content: "";
    position: absolute;
    top: 0;
    left: 28%;
    right: 28%;
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--cyan);
    box-shadow: var(--glow-tab);
}

.site-footer {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 var(--gutter-r) calc(var(--tabbar-h) + var(--safe-b) + 20px) var(--gutter-l);
    color: var(--faint);
    font-size: 0.8rem;
}

.site-footer a {
    color: inherit;
}

.main + .site-footer {
    margin-top: calc(-1 * (var(--tabbar-h) + var(--safe-b)));
}

/* Page avec bouton flottant : le bas du pied de page passe au-dessus du bouton. */
.shell:has(.fab) .site-footer {
    padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 92px);
}

@media (min-width: 1024px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        width: var(--sidebar-w);
        display: flex;
        flex-direction: column;
        gap: 24px;
        padding: 20px 14px;
        background: var(--bg-raise);
        border-right: 1px solid var(--line);
        /* Tablette en paysage (768px de haut) : menu admin et thème défilent au lieu d'être coupés. */
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .sidebar-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 4px 10px;
        color: var(--text);
        text-decoration: none;
        font-family: var(--font-ui);
        font-size: 1.05rem;
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .sidebar-nav {
        display: grid;
        gap: 4px;
    }

    .sidebar-nav a {
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 44px;
        padding: 0 12px;
        border-radius: var(--radius-sm);
        color: var(--muted);
        text-decoration: none;
        font-family: var(--font-ui);
        font-weight: 600;
        letter-spacing: 0.03em;
    }

    @media (hover: hover) {
        .sidebar-nav a:hover {
            background: var(--panel);
            color: var(--text);
        }
    }

    .sidebar-nav a[aria-current="page"] {
        background: var(--cyan-soft);
        color: var(--cyan);
        box-shadow: inset 2px 0 0 var(--cyan);
    }

    .sidebar-user {
        margin-top: auto;
        display: grid;
        gap: 6px;
        padding: 12px;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: var(--panel);
        font-size: 0.9rem;
    }

    .sidebar-user a {
        color: var(--muted);
    }

    .shell {
        margin-left: var(--sidebar-w);
    }

    .topbar {
        padding: 10px 24px;
    }

    .topbar-brand {
        display: none;
    }

    .tabbar {
        display: none;
    }

    .main {
        padding: 28px 32px 48px;
        gap: 24px;
    }

    .site-footer,
    .main + .site-footer {
        margin-top: 0;
        padding: 0 32px 28px;
    }

    .shell:has(.fab) .site-footer {
        padding-bottom: 100px;
    }
}

/* ---------- Brique-logo ---------- */

.logo {
    width: 30px;
    height: 22px;
    flex: none;
}

.logo rect {
    fill: var(--cyan-fill);
}

.logo .logo-dim {
    fill: var(--amber-fill);
}

/* ---------- Boutons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 18px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--panel-2);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

/* Survols réservés aux souris : au doigt, un survol reste « collé » après la touche
   et fait passer un bouton ou une puce pour sélectionné. */
@media (hover: hover) {
    .btn:hover {
        border-color: var(--cyan-line);
        background: var(--panel-3);
    }
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.45;
    pointer-events: none;
}

.btn-primary {
    background: var(--cyan-fill);
    border-color: var(--cyan-fill);
    color: var(--cyan-ink);
    box-shadow: var(--glow-primary);
}

@media (hover: hover) {
    .btn-primary:hover {
        background: var(--cyan-2);
        border-color: var(--cyan-2);
    }
}

.btn-amber {
    background: var(--amber-fill);
    border-color: var(--amber-fill);
    color: var(--amber-ink);
}

@media (hover: hover) {
    .btn-amber:hover {
        background: var(--amber-2);
        border-color: var(--amber-2);
    }
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--cyan);
}

@media (hover: hover) {
    .btn-ghost:hover {
        background: var(--cyan-soft);
        border-color: transparent;
    }
}

.btn-danger {
    background: transparent;
    border-color: var(--red-line);
    color: var(--red);
}

@media (hover: hover) {
    .btn-danger:hover {
        background: var(--red-soft);
        border-color: var(--red);
    }
}

.btn-icon {
    width: 46px;
    padding: 0;
}

.btn-icon.btn-ghost {
    color: var(--muted);
}

@media (hover: hover) {
    .btn-icon.btn-ghost:hover {
        color: var(--text);
    }
}

.btn-sm {
    min-height: 36px;
    padding: 0 12px;
    font-size: 0.85rem;
    border-radius: 8px;
}

.btn-sm.btn-icon {
    width: 36px;
}

.btn-block {
    width: 100%;
}

.btn .icon {
    width: 20px;
    height: 20px;
}

/* Place sous le bouton flottant pour voir le bas de la page. */
.main:has(.fab) {
    padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 104px);
}

.fab {
    position: fixed;
    right: var(--gutter-r);
    bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
    z-index: 35;
    min-height: 56px;
    padding: 0 22px;
    border-radius: 999px;
    box-shadow: var(--glow-fab);
}

@media (min-width: 1024px) {
    .fab {
        bottom: 28px;
        right: 32px;
    }
}

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

.field {
    display: grid;
    gap: 6px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.field > .label,
.field > legend {
    padding: 0;
}

.hint {
    color: var(--muted);
    font-size: 0.85rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    min-width: 0; /* dans une rangée, un long choix de liste ne pousse pas la page en largeur */
    min-height: 48px;
    padding: 10px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--bg-raise);
    color: var(--text);
    font-size: 16px; /* évite le zoom automatique sur iPhone */
    transition: border-color 0.15s, box-shadow 0.15s;
}

/* iPhone : sans le style natif (ombre intérieure, coins imposés), les champs suivent le thème. */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"] {
    -webkit-appearance: none;
    appearance: none;
}

input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
}

textarea {
    min-height: 96px;
    resize: vertical;
}

input::placeholder,
textarea::placeholder {
    color: var(--faint);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px var(--cyan-soft);
}

select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 42px;
    background-image: var(--select-arrow);
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 18px;
}

input[aria-invalid="true"] {
    border-color: var(--red);
}

.check {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    cursor: pointer;
}

.check input {
    flex: none; /* à côté d'un long texte, la case ne s'écrase pas */
    width: 22px;
    height: 22px;
    accent-color: var(--cyan);
}

/* Interrupteur */
.switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 48px;
    cursor: pointer;
}

.switch input {
    appearance: none;
    flex: none;
    width: 50px;
    height: 30px;
    margin: 0;
    border-radius: 999px;
    background: var(--panel-3);
    border: 1px solid var(--line-strong);
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.switch input::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--muted);
    transition: transform 0.2s var(--ease), background 0.2s;
}

.switch input:checked {
    background: var(--cyan-soft);
    border-color: var(--cyan);
}

.switch input:checked::after {
    transform: translateX(20px);
    background: var(--cyan);
}

/* Choix segmentés (dés, statut) */
.seg {
    position: relative; /* repère des boutons radio masqués */
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.seg input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.seg label {
    min-width: 52px;
    min-height: 44px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--bg-raise);
    color: var(--muted);
    font-family: var(--font-ui);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.seg input:checked + label {
    border-color: var(--cyan);
    background: var(--cyan-soft);
    color: var(--cyan);
    box-shadow: var(--glow-selected);
}

.seg input:focus-visible + label {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
}

.seg input:disabled + label {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Compteur − / + */
.stepper {
    display: inline-flex;
    justify-self: start;
    align-items: stretch;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--bg-raise);
    overflow: hidden;
}

.stepper button {
    width: 46px;
    min-height: 46px;
    border: 0;
    background: transparent;
    color: var(--cyan);
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
}

@media (hover: hover) {
    .stepper button:hover {
        background: var(--cyan-soft);
    }
}

.stepper button:active {
    background: var(--cyan-soft);
}

.stepper button:disabled {
    color: var(--faint);
    background: transparent;
    cursor: not-allowed;
}

.stepper input {
    width: 56px;
    min-height: 46px;
    border: 0;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    text-align: center;
    font-family: var(--font-ui);
    font-weight: 700;
    -moz-appearance: textfield;
    appearance: textfield;
    padding: 0;
}

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.stepper input:focus {
    box-shadow: none;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.chips-scroll {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
    padding: 2px var(--gutter-r) 2px var(--gutter-l);
}

.chips-scroll::-webkit-scrollbar {
    display: none;
}

.chip {
    /* Repère de la case masquée : sans lui, dans une rangée qui défile, elle se place
       par rapport à la page et l'élargit (page qui glisse de côté sur téléphone). */
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: var(--bg-raise);
    color: var(--muted);
    font-family: var(--font-ui);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

@media (hover: hover) {
    .chip:hover {
        color: var(--text);
        border-color: var(--cyan-line);
    }
}

.chip[aria-pressed="true"],
.chip[aria-current="true"],
.chip.is-on {
    border-color: var(--cyan);
    background: var(--cyan-soft);
    color: var(--cyan);
}

.chip input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

label.chip:has(input:checked) {
    border-color: var(--cyan);
    background: var(--cyan-soft);
    color: var(--cyan);
}

label.chip:has(input:focus-visible) {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
}

/* Cases à cocher en forme de boutons (provenance des unités : génériques, les miennes, la communauté).
   La petite case indique qu'on peut en cocher plusieurs, contrairement aux filtres de rôle. */
.chip-box {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    flex: none;
    border: 1.5px solid currentColor;
    border-radius: 4px;
}

.chip-box .icon {
    width: 12px;
    height: 12px;
    stroke-width: 3;
    opacity: 0;
}

label.chip:has(input:checked) .chip-box {
    border-color: var(--cyan);
    background: var(--cyan);
    color: var(--cyan-ink);
}

label.chip:has(input:checked) .chip-box .icon {
    opacity: 1;
}

.chip-count {
    min-width: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 20px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.chip-count:empty {
    display: none;
}

label.chip:has(input:checked) .chip-count {
    background: color-mix(in srgb, var(--cyan) 18%, transparent);
    color: var(--cyan);
}

/* Auteur d'une unité de joueur : pseudo raccourci s'il est long. */
.badge-owner {
    max-width: 13rem;
}

.badge-owner > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
    align-items: start;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

/* ---------- Panneaux ---------- */

.panel {
    position: relative;
    display: grid;
    gap: 16px;
    padding: 18px;
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.panel-flush {
    padding: 0;
    gap: 0;
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.panel-head h2 {
    font-size: 1.1rem;
}

/* Coins de visée « HUD » */
.hud::before,
.hud::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid var(--cyan);
    pointer-events: none;
    opacity: 0.85;
}

.hud::before {
    top: -1px;
    left: -1px;
    border-right: 0;
    border-bottom: 0;
    border-top-left-radius: var(--radius);
}

.hud::after {
    right: -1px;
    bottom: -1px;
    border-left: 0;
    border-top: 0;
    border-bottom-right-radius: var(--radius);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
}

.section-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--line-strong), transparent);
}

.page-intro {
    color: var(--muted);
    max-width: 62ch;
}

.stack {
    display: grid;
    gap: 16px;
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

/* ---------- Badges ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 24px;
    padding: 0 9px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    color: var(--muted);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

/* Badge seul dans une colonne (carte d'armée, page des règles) : à la taille de son texte,
   pas étiré sur toute la largeur. */
:where(.stack, .panel, .field) > .badge {
    justify-self: start;
}

.badge .icon {
    width: 14px;
    height: 14px;
}

.badge-cyan { border-color: var(--cyan-line); color: var(--cyan); background: var(--cyan-soft); }
.badge-amber { border-color: var(--amber-line); color: var(--amber); background: var(--amber-soft); }
.badge-red { border-color: var(--red-line); color: var(--red); background: var(--red-soft); }
.badge-green { border-color: var(--green-line); color: var(--green); background: var(--green-soft); }

.badge-faction {
    border-color: color-mix(in srgb, var(--faction) 55%, transparent);
    color: var(--faction);
    background: color-mix(in srgb, var(--faction) 12%, transparent);
}

.faction-dot {
    width: 10px;
    height: 10px;
    flex: none;
    border-radius: 3px;
    background: var(--faction);
    box-shadow: 0 0 10px var(--faction);
    transform: rotate(45deg);
}

/* ---------- Messages ---------- */

.alert {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border: 1px solid var(--line-strong);
    border-left-width: 3px;
    border-radius: var(--radius-sm);
    background: var(--panel);
    font-size: 0.95rem;
}

.alert .icon {
    margin-top: 2px;
}

.alert-error { border-color: color-mix(in srgb, var(--red) 50%, transparent); border-left-color: var(--red); color: var(--red-text); }
.alert-error .icon { color: var(--red); }
.alert-warn { border-color: color-mix(in srgb, var(--amber) 40%, transparent); border-left-color: var(--amber); }
.alert-warn .icon { color: var(--amber); }
.alert-ok { border-color: color-mix(in srgb, var(--green) 40%, transparent); border-left-color: var(--green); }
.alert-ok .icon { color: var(--green); }
.alert-info { border-left-color: var(--cyan); }
.alert-info .icon { color: var(--cyan); }

.alert ul {
    margin: 4px 0 0;
    padding-left: 18px;
}

/* Notifications : en haut sur téléphone (elles ne cachent ni le bouton d'ajout ni les onglets),
   dans la couche supérieure (popover) pour rester visibles au-dessus des panneaux ouverts. */
.toasts {
    position: fixed;
    inset: calc(env(safe-area-inset-top, 0px) + 10px) max(12px, var(--safe-r)) auto max(12px, var(--safe-l));
    z-index: 90;
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    overflow: visible;
    display: grid;
    gap: 8px;
    justify-items: center;
    pointer-events: none;
}

.toasts[popover]:not(:popover-open) {
    display: none;
}

.toast {
    max-width: 520px;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: 1px solid var(--cyan-line);
    border-radius: var(--radius);
    background: var(--float-bg);
    box-shadow: var(--shadow);
    /* Les touches traversent la notification (sauf son lien) : rien n'est bloqué dessous. */
    pointer-events: none;
    animation: toast-in 0.25s var(--ease);
}

.toast .icon {
    color: var(--green);
}

.toast-error {
    border-color: color-mix(in srgb, var(--red) 60%, transparent);
}

.toast-error .icon {
    color: var(--red);
}

.toast a {
    pointer-events: auto;
    margin-left: auto;
    font-weight: 700;
    white-space: nowrap;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-12px); }
}

@media (min-width: 1024px) {
    .toasts {
        inset: calc(var(--topbar-h) + 12px) 32px auto auto;
        width: 420px;
    }
}

.empty {
    display: grid;
    justify-items: center;
    gap: 12px;
    padding: 36px 20px;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
}

.empty .icon {
    width: 40px;
    height: 40px;
    color: var(--faint);
}

.empty h2,
.empty h3 {
    color: var(--text);
    font-size: 1.1rem;
}

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

.list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

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

.list-item {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 64px;
    padding: 10px 16px;
    color: var(--text);
    text-decoration: none;
}

@media (hover: hover) {
    a.list-item:hover,
    button.list-item:hover {
        background: var(--panel-3);
    }
}

a.list-item:active,
button.list-item:active {
    background: var(--panel-3);
}

button.list-item {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.list-main {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr); /* une ligne trop longue ne l'élargit pas */
    gap: 2px;
}

.list-main strong {
    font-family: var(--font-ui);
    font-weight: 600;
    overflow-wrap: anywhere;
}

.list-meta {
    color: var(--muted);
    font-size: 0.85rem;
    overflow-wrap: anywhere; /* adresses e-mail */
}

.list-item.text-red {
    color: var(--red);
}

.list-end {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.list-end .icon {
    color: var(--faint);
}

/* Cadre photo d'une figurine */
.thumb {
    flex: none;
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--bg-raise);
    overflow: hidden;
}

.thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.thumb-lg {
    width: 84px;
    height: 84px;
    border-radius: 14px;
}

/* Photos prises au téléphone : leur propre fond, cadre sombre plutôt que blanc. */
.thumb img.is-photo,
.fig-photo img.is-photo,
.datacard-photo img.is-photo {
    background: var(--bg-raise);
}

.fig-placeholder {
    width: 46%;
    height: auto;
    fill: var(--line-strong);
}

/* ---------- Barre de budget ---------- */

.meter {
    display: grid;
    gap: 6px;
}

.meter-track {
    height: 10px;
    border-radius: 999px;
    background: var(--bg-raise);
    border: 1px solid var(--line);
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--cyan), var(--cyan-2));
    box-shadow: 0 0 14px rgba(79, 216, 255, 0.5);
    transition: width 0.35s var(--ease);
}

.meter.is-near .meter-fill {
    background: linear-gradient(90deg, var(--amber), #ffd28a);
    box-shadow: 0 0 14px rgba(255, 181, 71, 0.5);
}

/* Au-delà du budget (indicatif) : ambre rayé, une information et non une erreur. */
.meter.is-over .meter-fill {
    background: repeating-linear-gradient(135deg, var(--amber) 0 10px, #ffd28a 10px 20px);
    box-shadow: 0 0 14px rgba(255, 181, 71, 0.55);
}

.meter-text {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.9rem;
    color: var(--muted);
}

.meter-text strong {
    color: var(--text);
    font-family: var(--font-ui);
}

/* ---------- Grands chiffres (points) ---------- */

.readout {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-family: var(--font-ui);
}

.readout-value {
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1;
    color: var(--amber);
    text-shadow: var(--glow-points);
    font-variant-numeric: tabular-nums;
}

.readout-unit {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.pts {
    font-family: var(--font-ui);
    font-weight: 700;
    color: var(--amber);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------- Onglets ---------- */

.tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    border-bottom: 1px solid var(--line);
    margin: 0 calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
    padding: 0 var(--gutter-r) 0 var(--gutter-l);
}

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

.tabs button,
.tabs a {
    flex: none;
    min-height: 46px;
    padding: 0 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    font-family: var(--font-ui);
    font-weight: 600;
    letter-spacing: 0.03em;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.tabs [aria-selected="true"],
.tabs [aria-current="page"] {
    color: var(--cyan);
    border-bottom-color: var(--cyan);
}

@media (min-width: 1024px) {
    .tabs,
    .chips-scroll {
        margin: 0;
        padding-left: 0;
        padding-right: 0;
    }
}

/* ---------- Panneau coulissant (fenêtre) ---------- */

.sheet {
    /* Marges du panneau, reprises par les rangées bord à bord qu'il contient. */
    --gutter-l: max(18px, var(--safe-l));
    --gutter-r: max(18px, var(--safe-r));
    width: 100%;
    max-width: 100%;
    max-height: 94vh;
    /* Hauteur visible réelle : sur iPhone, 94vh dépasse quand la barre de Safari est affichée
       et le haut du panneau (titre, bouton Fermer) sortirait de l'écran. */
    max-height: 94dvh;
    margin: auto 0 0;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-bottom: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: var(--panel);
    color: var(--text);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.sheet[open] {
    display: flex;
    flex-direction: column;
    animation: sheet-up 0.28s var(--ease);
}

/* Repli : avant 2024 (iOS < 17.4…), ::backdrop n'hérite pas des variables. */
.sheet::backdrop {
    background: var(--backdrop, rgba(2, 5, 10, 0.72));
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

@keyframes sheet-up {
    from { transform: translateY(40px); opacity: 0; }
}

.sheet-head {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 60px;
    padding: 8px max(8px, var(--safe-r)) 8px var(--gutter-l);
    border-bottom: 1px solid var(--line);
    position: relative;
}

.sheet-head::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 2px;
    background: var(--line-strong);
}

.sheet-head h2 {
    flex: 1;
    min-width: 0;
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sheet-head .btn-icon:first-child {
    margin-left: -10px;
}

.sheet-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px var(--gutter-r) calc(24px + var(--safe-b)) var(--gutter-l);
    display: grid;
    /* Lignes à la hauteur de leur contenu : quand la liste dépasse, une rangée défilante
       (puces, onglets) ne doit pas être écrasée à sa taille minimale (0). */
    grid-auto-rows: max-content;
    gap: 18px;
    align-content: start;
}

/* Avec un pied de panneau, c'est lui qui longe le bas de l'écran (barre d'accueil de l'iPhone). */
.sheet-body:has(+ .sheet-foot:not([hidden])) {
    padding-bottom: 24px;
}

.sheet-foot {
    display: flex;
    flex-wrap: wrap; /* deux boutons trop longs pour un petit écran : l'un sous l'autre */
    gap: 10px;
    padding: 12px var(--gutter-r) calc(12px + var(--safe-b)) var(--gutter-l);
    border-top: 1px solid var(--line);
    background: var(--bg-raise);
}

.sheet-foot .btn {
    flex: 1;
}

@media (min-width: 760px) {
    .sheet {
        --gutter-l: 18px;
        width: min(560px, 100vw);
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        margin: 0 0 0 auto;
        border: 0;
        border-left: 1px solid var(--line-strong);
        border-radius: 0;
    }

    .sheet[open] {
        animation-name: sheet-side;
    }

    .sheet-head::before {
        display: none;
    }

    @keyframes sheet-side {
        from { transform: translateX(40px); opacity: 0; }
    }
}

/* Fenêtre centrée (confirmation) */
.modal {
    width: min(440px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    background: var(--panel);
    color: var(--text);
    box-shadow: var(--shadow);
}

.modal::backdrop {
    background: var(--backdrop, rgba(2, 5, 10, 0.72));
}

.modal-body {
    display: grid;
    gap: 16px;
    padding: 22px;
}

.modal-body h2 {
    font-size: 1.15rem;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

/* ---------- Fiche de jeu ---------- */

.datacard {
    position: relative;
    display: grid;
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    overflow: hidden;
}

.datacard-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background:
        linear-gradient(90deg, color-mix(in srgb, var(--faction) 16%, transparent), transparent 70%),
        var(--panel-2);
    border-bottom: 1px solid var(--line);
}

.datacard-title {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr); /* le nom et les badges restent dans la carte */
    gap: 4px;
}

.datacard-title h3 {
    font-size: 1.2rem;
    overflow-wrap: anywhere;
}

.datacard-photo {
    flex: none;
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    border: 1px solid var(--line-strong);
    background: var(--bg-raise);
    overflow: hidden;
}

.datacard-photo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.datacard-body {
    display: grid;
    gap: 14px;
    padding: 14px;
}

.statline {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
    gap: 6px;
    container-type: inline-size; /* voir « Rangée étroite » plus bas */
}

.stat {
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 8px 4px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--bg-raise);
}

.stat span {
    /* Abréviation choisie dans les règles : si elle est trop longue pour la case (6 caractéristiques
       sur un petit écran), elle est coupée par « … » au lieu de déborder. */
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-ui);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.stat strong {
    font-family: var(--font-ui);
    font-size: 1.2rem;
    color: var(--cyan);
    font-variant-numeric: tabular-nums;
}

/* Rangée étroite (téléphone, deux fiches côte à côte en paysage, panneau) : intitulés resserrés
   pour que « ARMURE » tienne en entier dans sa case. */
@container (max-width: 330px) {
    .stat {
        padding-left: 0;
        padding-right: 0;
    }

    .stat span {
        letter-spacing: 0;
    }
}

.weapons {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.weapon-row {
    display: grid;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--bg-raise);
}

.weapon-row-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-family: var(--font-ui);
    font-weight: 600;
}

.weapon-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    color: var(--muted);
    font-size: 0.85rem;
}

.weapon-stats b {
    color: var(--text);
    font-family: var(--font-ui);
}

.card-traits {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ---------- Composition par rôle ---------- */

.roster {
    display: grid;
    gap: 14px;
}

.roster-group {
    display: grid;
    gap: 12px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    border-left: 3px solid var(--green);
}

.roster-group.is-missing,
.roster-group.is-excess {
    border-left-color: var(--red);
}

.roster-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 12px;
}

.roster-head h3 {
    font-size: 1.05rem;
    letter-spacing: 0.04em;
}

.quota-state {
    font-family: var(--font-ui);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--green);
}

.is-missing .quota-state,
.is-excess .quota-state {
    color: var(--red);
}

.fig-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

@media (max-width: 420px) {
    .fig-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.fig-card {
    position: relative;
    display: grid;
    grid-template-rows: auto 1fr;
    width: 100%;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--panel-2);
    color: var(--text);
    text-align: left;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

a.fig-card {
    text-decoration: none;
}

@media (hover: hover) {
    .fig-card:hover {
        border-color: var(--cyan-line);
        box-shadow: var(--glow);
    }
}

/* Au doigt : la carte s'allume le temps de la touche. */
.fig-card:active {
    border-color: var(--cyan-line);
    box-shadow: var(--glow);
}

.fig-card.is-invalid {
    border-color: var(--red);
}

.fig-photo {
    position: relative;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    background: var(--bg-raise);
    border-bottom: 1px solid var(--line);
}

.fig-photo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.fig-count {
    position: absolute;
    top: 6px;
    right: 6px;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--amber-fill);
    color: var(--amber-ink);
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 700;
}

.fig-flag {
    position: absolute;
    left: 6px;
    top: 6px;
}

.fig-body {
    display: grid;
    gap: 2px;
    align-content: start;
    padding: 9px 10px 11px;
}

.fig-name {
    font-family: var(--font-ui);
    font-weight: 600;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.fig-meta {
    color: var(--muted);
    font-size: 0.8rem;
}

.fig-note {
    color: var(--red);
    font-size: 0.8rem;
    font-weight: 700;
}

.fig-card.is-slot {
    border: 1px dashed var(--line-strong);
    background: transparent;
    color: var(--muted);
}

.fig-card.is-slot .fig-photo {
    background: transparent;
    border-bottom: 1px dashed var(--line);
}

.fig-card.is-slot .fig-placeholder {
    opacity: 0.5;
}

@media (hover: hover) {
    .fig-card.is-slot:hover {
        color: var(--cyan);
    }
}

.fig-card.is-slot:active {
    color: var(--cyan);
}

.slot-plus {
    position: absolute;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--cyan-line);
    background: var(--cyan-soft);
    color: var(--cyan);
}

.roster-optional {
    color: var(--muted);
    font-size: 0.9rem;
}

/* ---------- Cartes d'armées et de catalogue ---------- */

.card-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
}

.army-card {
    position: relative;
    display: grid;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--faction) 12%, transparent), transparent 55%),
        var(--panel);
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

@media (hover: hover) {
    .army-card:hover {
        border-color: color-mix(in srgb, var(--faction) 60%, transparent);
        box-shadow: 0 0 0 1px color-mix(in srgb, var(--faction) 35%, transparent), 0 0 26px color-mix(in srgb, var(--faction) 15%, transparent);
    }
}

.army-card:active {
    border-color: color-mix(in srgb, var(--faction) 60%, transparent);
}

.army-card h2 {
    font-size: 1.2rem;
}

.army-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.army-thumbs {
    display: flex;
    gap: 6px;
}

.army-thumbs .thumb {
    width: 40px;
    height: 40px;
    border-radius: 8px;
}

.army-thumbs .more {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--line);
    color: var(--muted);
    font-family: var(--font-ui);
    font-size: 0.8rem;
}

.unit-tile {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

@media (hover: hover) {
    .unit-tile:hover {
        border-color: var(--cyan-line);
        box-shadow: var(--glow);
    }
}

.unit-tile:active {
    border-color: var(--cyan-line);
    box-shadow: var(--glow);
}

.unit-tile .list-main {
    gap: 4px;
}

/* ---------- Éditeur d'unité ---------- */

.ed-readout {
    position: sticky;
    top: -16px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -16px calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
    padding: 12px var(--gutter-r) 12px var(--gutter-l);
    background: var(--float-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.ed-readout.is-busy .readout-value {
    opacity: 0.5;
}

.ed-total {
    text-align: right;
    font-size: 0.9rem;
    color: var(--muted);
}

.ed-total strong {
    display: block;
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 1.1rem;
}

.ed-section {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-2);
}

.ed-section > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 54px;
    padding: 0 16px;
    cursor: pointer;
    list-style: none;
}

.ed-section > summary::-webkit-details-marker {
    display: none;
}

.ed-section > summary h3 {
    font-size: 1rem;
}

.ed-section > summary .ed-sum {
    flex: 1;
    min-width: 0;
    text-align: right;
    color: var(--muted);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ed-section > summary::after {
    content: "";
    width: 9px;
    height: 9px;
    flex: none;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg) translate(-2px, -2px);
    transition: transform 0.2s;
}

.ed-section[open] > summary::after {
    transform: rotate(-135deg) translate(-2px, -2px);
}

.ed-section-body {
    display: grid;
    gap: 16px;
    padding: 4px 16px 18px;
}

.ed-row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-end;
}

.ed-row > .field {
    flex: 1 1 10rem;
}

.ed-weapon {
    display: grid;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--cyan);
    border-radius: 10px;
    background: var(--bg-raise);
}

.ed-weapon-head {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ed-weapon-head .field {
    flex: 1;
}

.ed-weapon-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
    gap: 12px;
}

.ed-value {
    font-family: var(--font-ui);
    color: var(--amber);
    font-size: 0.85rem;
    white-space: nowrap;
    padding-bottom: 14px;
}

.trait-list {
    display: grid;
    gap: 8px;
}

.trait-option {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 4px 12px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-raise);
    cursor: pointer;
}

.trait-option:has(input[type="checkbox"]:checked) {
    border-color: var(--cyan-line);
    background: var(--cyan-soft);
}

.trait-option input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--cyan);
}

.trait-option small {
    grid-column: 2 / -1;
    color: var(--muted);
    font-size: 0.82rem;
}

.trait-option .stepper button {
    width: 38px;
    min-height: 38px;
}

.trait-option .stepper input {
    width: 40px;
    min-height: 38px;
}

.breakdown {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-2);
}

.breakdown > summary {
    min-height: 50px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    cursor: pointer;
    font-family: var(--font-ui);
    font-weight: 600;
    color: var(--muted);
}

.breakdown dl {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 16px;
    margin: 0;
    padding: 0 16px 16px;
    font-size: 0.88rem;
}

.breakdown dt {
    color: var(--muted);
}

.breakdown dd {
    margin: 0;
    text-align: right;
    font-family: var(--font-ui);
    font-variant-numeric: tabular-nums;
}

.warnings {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* ---------- Mode partie ---------- */

.game-bar {
    position: sticky;
    top: var(--topbar-h);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: -16px calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
    padding: 10px var(--gutter-r) 10px var(--gutter-l);
    background: var(--bar-bg-strong);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.game-turn {
    display: flex;
    align-items: center;
    gap: 8px;
}

.game-summary {
    flex: 1;
    text-align: center;
}

/* Téléphone en portrait : le compteur et « Tour suivant » sur une ligne, le résumé dessous
   (sur une seule ligne, l'ensemble demande environ 400px). */
@media (max-width: 439px) {
    .game-bar {
        flex-wrap: wrap;
        justify-content: space-between;
        row-gap: 4px;
    }

    .game-summary {
        order: 3;
        flex-basis: 100%;
    }
}

@media (max-width: 359px) {
    .game-bar {
        gap: 8px;
    }

    .game-turn {
        gap: 6px;
    }

    .game-bar > .btn .icon {
        display: none;
    }
}

.game-turn strong {
    font-family: var(--font-ui);
    font-size: 1.6rem;
    color: var(--amber);
    min-width: 2ch;
    text-align: center;
}

.game-track {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 100%;
    gap: 16px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    margin: 0 calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
    padding: 4px var(--gutter-r) 8px var(--gutter-l);
    scroll-padding: 0 var(--gutter-r) 0 var(--gutter-l);
}

/* Téléphone en paysage, petite tablette : deux fiches côte à côte au lieu d'une très large. */
@media (min-width: 640px) and (max-width: 1023px) {
    .game-track {
        grid-auto-columns: calc((100% - 16px) / 2);
    }
}

.game-track::-webkit-scrollbar {
    display: none;
}

.game-card {
    scroll-snap-align: start;
    display: grid;
    gap: 14px;
    align-content: start;
    padding: 14px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    background: var(--panel);
    min-width: 0;
}

.game-card.is-activated {
    border-color: color-mix(in srgb, var(--amber) 50%, transparent);
}

.game-card.is-destroyed {
    opacity: 0.55;
    filter: grayscale(0.6);
}

.game-card-head {
    display: flex;
    align-items: center;
    gap: 14px;
}

.game-card-head h2 {
    font-size: 1.25rem;
    overflow-wrap: anywhere;
}

.wound-box {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raise);
}

.wound-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.wound-controls .btn {
    min-width: 64px;
    min-height: 56px;
    font-size: 1.15rem;
}

.wound-count {
    text-align: center;
    display: grid;
}

.wound-count strong {
    font-family: var(--font-ui);
    font-size: 1.8rem;
    line-height: 1;
}

.figures {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.figure {
    display: flex;
    gap: 3px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 7px;
}

.figure.is-dead {
    opacity: 0.4;
}

.pip {
    width: 12px;
    height: 18px;
    border-radius: 3px;
    background: var(--green);
    box-shadow: var(--glow-pip);
}

.pip.is-lost {
    background: var(--panel-3);
    box-shadow: none;
}

.game-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.game-dots button {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

.game-dots button::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--line-strong);
}

.game-dots button.is-activated::before {
    background: var(--amber);
}

.game-dots button.is-destroyed::before {
    background: var(--red);
    opacity: 0.6;
}

.game-dots button[aria-current="true"]::before {
    width: 22px;
    border-radius: 5px;
    background: var(--cyan);
}

@media (min-width: 1024px) {
    .game-bar {
        margin: -28px -32px 0;
        padding: 12px 32px;
    }

    .game-track {
        grid-auto-flow: row;
        grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
        overflow: visible;
        margin: 0;
        padding: 0;
    }

    .game-dots {
        display: none;
    }
}

/* ---------- Connexion, inscription ---------- */

.auth {
    min-height: 100vh;
    min-height: 100svh; /* centré dans la partie visible, barres du navigateur affichées */
    display: grid;
    place-items: center;
    padding: 24px var(--gutter-r) calc(24px + var(--safe-b)) var(--gutter-l);
}

.auth-box {
    width: min(440px, 100%);
    display: grid;
    gap: 22px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-ui);
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.auth-brand .logo {
    width: 40px;
    height: 30px;
}

.auth .panel {
    padding: 24px 20px;
    gap: 18px;
}

.auth h1 {
    font-size: 1.6rem;
}

.auth-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0 10px;
    font-size: 0.95rem;
}

/* Liens seuls sur leur ligne : une vraie cible pour le doigt. */
.auth-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

/* ---------- Admin ---------- */

.stat-tiles {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 10rem), 1fr));
}

.stat-tile {
    display: grid;
    gap: 6px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    text-decoration: none;
}

@media (hover: hover) {
    a.stat-tile:hover {
        border-color: var(--cyan-line);
        box-shadow: var(--glow);
    }
}

a.stat-tile:active {
    border-color: var(--cyan-line);
}

.stat-tile strong {
    font-family: var(--font-ui);
    font-size: 2rem;
    line-height: 1;
    color: var(--cyan);
}

.kv {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px 16px;
    margin: 0;
}

.kv dt {
    color: var(--muted);
}

.kv dd {
    margin: 0;
    overflow-wrap: anywhere; /* e-mail ou nom sans espace : à la ligne plutôt que hors de l'écran */
}

/* Téléphone étroit : l'intitulé au-dessus de sa valeur, la valeur garde toute la largeur. */
@media (max-width: 380px) {
    .kv {
        grid-template-columns: minmax(0, 1fr);
        gap: 2px;
    }

    .kv dd + dt {
        margin-top: 10px;
    }
}

.rule-item {
    display: grid;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--cyan);
    border-radius: 10px;
    background: var(--bg-raise);
}

.rule-item.is-disabled {
    border-left-color: var(--line-strong);
    opacity: 0.75;
}

.rule-item-head {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.rule-item-head > .field {
    flex: 1 1 11rem;
}

.rule-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr));
    gap: 12px;
    align-items: end;
}

.rule-list {
    display: grid;
    gap: 12px;
}

.save-bar {
    position: sticky;
    bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px);
    z-index: 25;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--cyan-line);
    border-radius: var(--radius);
    background: var(--float-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
}

@media (min-width: 1024px) {
    .save-bar {
        bottom: 16px;
    }
}

.status-line {
    min-height: 1.5em;
    color: var(--green);
    font-weight: 700;
    font-size: 0.92rem;
}

.status-line.is-error {
    color: var(--red);
}

.color-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.color-options label {
    position: relative;
    cursor: pointer;
}

.color-options input {
    position: absolute;
    opacity: 0;
}

.color-options input + span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.875rem;
}

.color-options input:checked + span {
    border-color: var(--faction);
    color: var(--text);
    box-shadow: 0 0 0 1px var(--faction);
}

.color-options input:focus-visible + span {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
}

/* Résultats de recherche de photo (Rebrickable) */
.photo-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.5rem), 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.photo-result {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-raise);
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

@media (hover: hover) {
    .photo-result:hover {
        border-color: var(--cyan-line);
        box-shadow: var(--glow);
    }
}

.photo-result:active {
    border-color: var(--cyan-line);
}

.photo-result:disabled {
    opacity: 0.5;
    cursor: wait;
}

.photo-result img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    border-radius: 7px;
    background: #fff;
}

.photo-result span {
    font-size: 0.82rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.photo-result .meta {
    color: var(--muted);
    font-size: 0.75rem;
}

.photo-current {
    display: flex;
    flex-wrap: wrap; /* petit écran : les boutons passent sous la photo */
    align-items: center;
    gap: 14px;
}

.photo-current > :last-child {
    flex: 1 1 12rem;
    min-width: 0;
}

code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.88em;
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--bg-raise);
    border: 1px solid var(--line);
}

/* Tableau trop large : il défile seul, la page ne déborde pas */
.table-wrap {
    overflow-x: auto;
    min-width: 0;
}

.table caption {
    padding: 8px 0;
}

/* Page « Règles » : caractéristiques, armes et rôles en cartes (une colonne sur téléphone). */
.rules-cards {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
}

/* Tableaux d'admin : en cartes sur téléphone */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.table th {
    font-family: var(--font-ui);
    font-size: 0.74rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

/* Grilles empilées : une colonne qui ne dépasse jamais l'écran, même si un texte
   sur une ligne (résumé, nom long) est plus large. Évite le défilement horizontal. */
.main,
.stack,
.panel,
.sheet-body,
.ed-section-body,
.roster,
.roster-group,
.datacard,
.datacard-body,
.modal-body,
.auth-box,
.game-card,
.wound-box,
.rule-item,
.rule-list,
.band-list {
    grid-template-columns: minmax(0, 1fr);
}

.panel-flush {
    grid-template-columns: minmax(0, 1fr);
}

.dice-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 5.5rem), 1fr));
}

.band-list {
    display: grid;
    gap: 10px;
}

.band,
.add-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}

.band > .field {
    flex: 1 1 9rem;
}

.add-row input,
.add-row select {
    flex: 1 1 12rem;
    width: auto;
}

/* Listes dépliantes : pas de triangle du navigateur. */
details > summary {
    list-style: none;
}

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

/* Éditeur d'unité dans une page (et non dans un panneau coulissant). */
.main .ed-readout {
    top: calc(var(--topbar-h) + 8px);
    margin: 0;
    padding: 12px 18px;
    border: 1px solid var(--cyan-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

form > button.list-item {
    font: inherit;
}

/* ---------- Partage ---------- */

.share-head {
    display: grid;
    gap: 10px;
}

.share-head h1 {
    font-size: clamp(1.8rem, 6vw, 2.6rem);
}

.share-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
    align-items: start;
}

/* ---------- Équipement : photos des armes et des accessoires ---------- */

/* Bouton « Prendre ou choisir » : le champ fichier caché reste dans le bouton. */
.photo-pick {
    position: relative;
}

/* Texte masqué sur petit écran (le bouton garde son icône et son aria-label). */
@media (max-width: 480px) {
    .hide-narrow {
        display: none;
    }
}

.thumb .equip-placeholder {
    width: 46%;
    height: 46%;
    color: var(--faint);
}

/* Bouton dans un état vide : icône à la taille du bouton, pas à celle de l'illustration. */
.empty .btn .icon {
    width: 20px;
    height: 20px;
    color: inherit;
}

/* Fiches : photo de l'arme à gauche de sa ligne. */
.weapon-row.has-photo {
    grid-template-columns: 52px minmax(0, 1fr);
    align-items: center;
    column-gap: 12px;
}

.weapon-row-main {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.weapon-photo {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.weapon-photo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Fiches : accessoires portés, avec leur photo en pastille. */
.equip-chip img {
    width: 22px;
    height: 22px;
    margin-left: -6px;
    border-radius: 50%;
    border: 1px solid var(--cyan-line);
    background: #fff;
    object-fit: contain;
}

/* Éditeur d'unité et règles : photo d'une arme ou d'un accessoire. */
.ed-photo {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
}

.ed-photo .thumb,
.rule-photo .thumb {
    width: 52px;
    height: 52px;
}

.ed-photo.is-busy {
    opacity: 0.55;
    pointer-events: none;
}

.trait-photo {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    margin-right: 8px;
    vertical-align: middle;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
}

.trait-photo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Page « Équipement » : cartes des armes et des accessoires. */
.equip-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 21rem), 1fr));
    margin: 0;
    padding: 0;
    list-style: none;
}

.equip-grid > li {
    display: grid;
    min-width: 0;
}

.equip-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px 14px;
    align-content: start;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.equip-card.is-hidden {
    border-style: dashed;
    opacity: 0.75;
}

.equip-card.is-invalid {
    border-color: var(--red-line);
}

.equip-main {
    display: grid;
    gap: 3px;
    align-content: start;
    min-width: 0;
}

.equip-name {
    font-family: var(--font-ui);
    font-weight: 600;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.equip-stats {
    font-size: 0.88rem;
}

.equip-desc {
    color: var(--muted);
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}

.equip-badges {
    gap: 6px;
    margin-top: 4px;
}

.equip-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

/* ---------- Choix du thème (Compte, barre latérale) ---------- */

.theme-switch {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.theme-switch .seg {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.theme-switch .seg label {
    gap: 8px;
    min-width: 0;
}

/* Version compacte : intitulé et trois icônes sur une ligne. */
.theme-switch-compact {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.theme-switch-compact .seg {
    gap: 4px;
}

.theme-switch-compact .seg label {
    min-width: 36px;
    min-height: 32px;
    padding: 0;
    border-radius: 8px;
}

.theme-switch-compact .icon {
    width: 18px;
    height: 18px;
}

.sidebar-user .theme-switch {
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

/* Pendant la bascule, pas de transitions : tout change de couleur en même temps. */
.theme-switching *,
.theme-switching *::before,
.theme-switching *::after {
    transition: none !important;
}

/* ---------- Téléphones : petits écrans et paysage ----------
   Vérifié à 320, 360, 390 et 768px de large, et en paysage (740 × 360). */

/* Petit téléphone : rangées resserrées, le texte garde de la place. */
@media (max-width: 400px) {
    /* Un intitulé de bouton plus long que l'écran passe à la ligne au lieu de déborder… */
    .btn:not(.btn-icon) {
        max-width: 100%;
        white-space: normal;
        text-align: center;
        line-height: 1.2;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    /* … sauf là où ce sont les boutons qui passent à la ligne suivante. */
    .sheet-foot .btn,
    .game-bar .btn {
        white-space: nowrap;
    }

    .list-item {
        gap: 10px;
        padding: 10px 12px;
    }

    .list-end .btn-icon {
        width: 40px;
        min-height: 40px;
    }

    /* Fiche de jeu : photo plus petite pour laisser la place au nom et aux badges. */
    .datacard-head {
        gap: 10px;
        padding: 12px;
    }

    .datacard-photo {
        width: 52px;
        height: 52px;
    }

    .datacard-title h3 {
        font-size: 1.08rem;
    }

    .datacard-body {
        padding: 12px;
    }

    /* Noms longs dans une colonne étroite : coupés avec un tiret plutôt qu'au milieu d'un mot. */
    .datacard-title h3,
    .fig-name,
    .game-card-head h2 {
        -webkit-hyphens: auto;
        hyphens: auto;
    }

    /* Caractéristiques sur une rangée : cases un peu plus larges (voir aussi « Rangée étroite »). */
    .statline {
        gap: 4px;
    }

    /* Badge plus large que sa colonne (rôle ou faction au nom long) : à la ligne dans le badge
       plutôt que hors de la carte. Le badge d'auteur garde sa coupure « … ». */
    .badge:not(.badge-owner) {
        flex-shrink: 0;
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .unit-tile {
        gap: 10px;
    }

    /* Boutons d'action d'une ligne de liste (admin) : l'un sous l'autre, le nom garde la largeur. */
    .list-end:has(.btn-icon) {
        flex-direction: column;
        gap: 2px;
    }

    /* Trait à niveaux (Ordres, Transport) : le compteur passe sous le nom. */
    .trait-option {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .trait-option > .stepper {
        grid-column: 2;
        grid-row: 2;
    }
}

/* Six onglets (joueur admin : Armées, Catalogue, Partie, Règles, Admin, Compte) : chaque onglet
   prend la largeur de son intitulé plus une part égale du reste, pour que « CATALOGUE » tienne. */
@media (max-width: 440px) {
    .tabbar:has(> a:nth-child(6)) a {
        flex: 1 1 auto;
    }
}

@media (max-width: 360px) {
    /* Choix du thème en pleine largeur : icône et mot tiennent dans chaque case. */
    .theme-switch:not(.theme-switch-compact) .seg {
        gap: 4px;
    }

    .theme-switch:not(.theme-switch-compact) .seg label {
        gap: 4px;
        padding: 0 4px;
    }

    /* Cinq onglets ou plus : intitulés resserrés, « CATALOGUE » tient dans sa case. */
    .tabbar:has(> a:nth-child(5)) a {
        font-size: 0.64rem;
        letter-spacing: 0.02em;
    }

    /* Barre du haut : « Jouer », « Imprimer », « Nouvelle »… réduits à leur icône pour laisser
       le titre lisible. L'intitulé reste dans le bouton pour les lecteurs d'écran. */
    .topbar-actions .btn-sm:not(.btn-icon):has(> .icon) {
        width: 36px;
        padding: 0;
        gap: 0;
        font-size: 0;
        letter-spacing: 0;
    }
}

/* Téléphone en paysage : barres plus basses (icône et intitulé côte à côte dans les onglets),
   le contenu garde de la hauteur. Les décalages qui dépendent des barres suivent les variables. */
@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --tabbar-h: 50px;
        --topbar-h: 50px;
    }

    .topbar {
        padding-top: 2px;
        padding-bottom: 2px;
    }

    .topbar .btn-icon {
        width: 44px;
        min-height: 44px;
    }

    .tabbar a {
        grid-auto-flow: column;
        justify-content: center;
        gap: 8px;
    }

    .sheet-head {
        min-height: 52px;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .save-bar {
        padding: 6px 12px;
    }

    .save-bar .btn {
        min-height: 40px;
    }

    .game-bar {
        padding-top: 6px;
        padding-bottom: 6px;
    }

    /* Coût en direct de l'éditeur d'unité : collé en haut, mais sur une ligne basse. */
    .ed-readout {
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .ed-readout .readout-value {
        font-size: 1.6rem;
    }

    .main .ed-readout {
        top: calc(var(--topbar-h) + 4px);
        padding-top: 6px;
        padding-bottom: 6px;
    }
}

/* Éditeur d'unité : un champ atteint au clavier ne passe pas sous le coût collé en haut. */
html:has(.main .ed-readout) {
    scroll-padding-top: calc(var(--topbar-h) + 88px);
}

.sheet-body:has(> .stack > .ed-readout) {
    scroll-padding-top: 72px;
}

/* ---------- Impression : clair et sobre ---------- */

@media print {
    :root,
    :root[data-theme] {
        color-scheme: light;
        --bg: #fff;
        --bg-raise: #fff;
        --panel: #fff;
        --panel-2: #f3f5f8;
        --panel-3: #e9edf2;
        --line: #c8d0da;
        --line-strong: #9aa7b6;
        --text: #000;
        --muted: #444;
        --faint: #666;
        --cyan: #005f86;
        --amber: #8a5300;
    }

    body {
        background: #fff;
    }

    .sidebar,
    .tabbar,
    .topbar,
    .toasts,
    .no-print,
    .site-footer,
    .fab {
        display: none !important;
    }

    .shell {
        margin: 0;
    }

    .main {
        padding: 0;
        max-width: none;
    }

    .datacard,
    .roster-group {
        break-inside: avoid;
    }

    .readout-value,
    .stat strong {
        text-shadow: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

/* =====================================================================
   Alignement des champs dans les grilles (règles, éditeur d'unité, réglages)
   Chaque champ occupe trois rangées partagées avec ses voisins : libellé, saisie,
   aide. Les saisies d'une même rangée restent sur une même ligne, même quand un
   libellé passe sur deux lignes ou qu'une aide est plus longue que les autres.
   ===================================================================== */
.rule-grid,
.form-grid,
.ed-row,
.ed-weapon-stats {
    display: grid;
    align-items: start;
    row-gap: 0;
    column-gap: 14px;
}

.ed-row {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 12rem), 1fr));
}

/* Assez large pour un compteur − / + sans qu'il déborde de sa colonne. */
.ed-weapon-stats {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr));
}

.rule-grid > .field,
.form-grid > .field,
.ed-row > .field,
.ed-weapon-stats > .field {
    grid-row: span 3;
    grid-template-rows: subgrid;
    row-gap: 6px;
    align-content: start;
    margin-bottom: 12px;
}

/* Libellé sur une ligne quand ses voisins en ont deux : il reste collé à sa saisie. */
.rule-grid > .field > .label,
.form-grid > .field > .label,
.ed-row > .field > .label,
.ed-weapon-stats > .field > .label {
    align-self: end;
}

/* Interrupteur ou case à cocher placé dans une grille de champs : centré sur la rangée. */
.rule-grid > :not(.field),
.form-grid > :not(.field) {
    grid-row: span 3;
    align-self: center;
    margin-bottom: 12px;
}

/* Case à cocher à la place d'une saisie (libellé vide au-dessus) : alignée sur les saisies. */
.field > .check {
    align-self: center;
}

/* Rangées « champ + bouton » : le bouton s'aligne sur la saisie, pas sur l'aide. */
.add-row > .field {
    flex: 1 1 12rem;
}

/* Titres des panneaux : même taille partout, qu'ils aient un bouton à côté ou non. */
.panel > h2,
.panel-head > h2 {
    font-size: 1.2rem;
}
