/* ==========================================================================
   Test mémoire — feuille de style
   Couleurs et rayons en variables (:root), redéfinies pour le mode sombre.
   ========================================================================== */

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

:root {
    --primary: #1aa7a7;
    --primary-strong: #12807f;
    --primary-soft: #e3f6f5;
    --accent: #b93fd9;
    --accent-soft: #f6e6fb;
    --success: #23a566;
    --danger: #e0303a;
    --warning: #f5b700;
    --card-back-1: #ff6a3d;
    --card-back-2: #f0414f;

    --bg: #eef3f4;
    --surface: #ffffff;
    --surface-2: #f6f9fa;
    --border: #dfe7e9;
    --text: #1f2a33;
    --muted: #66737d;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 40, 48, .06), 0 4px 14px rgba(16, 40, 48, .06);
    --shadow-strong: 0 12px 40px rgba(16, 40, 48, .25);
    --focus: 0 0 0 3px rgba(185, 63, 217, .45);
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #2cc4c3;
        --primary-strong: #5fdcdb;
        --primary-soft: #143536;
        --accent: #d07aea;
        --accent-soft: #3a2242;
        --card-back-1: #e2552c;
        --card-back-2: #c9303e;

        --bg: #10171c;
        --surface: #182229;
        --surface-2: #1e2a32;
        --border: #2b3a44;
        --text: #e6edf1;
        --muted: #93a3ad;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
        --shadow-strong: 0 12px 40px rgba(0, 0, 0, .6);
    }
}

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

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

button {
    font: inherit;
    color: inherit;
    border: 0;
    background: none;
    cursor: pointer;
}

button:disabled {
    cursor: default;
}

input,
select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

kbd {
    display: inline-block;
    min-width: 1.5em;
    padding: 0 .35em;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface-2);
    font: .8em/1.6 ui-monospace, monospace;
    text-align: center;
}

.hide {
    display: none !important;
}

/* ---------- Barre du haut ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: 1200px;
    margin: 0 auto;
    padding: .6rem 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--text);
    text-decoration: none;
}

.brand-logo {
    font-size: 1.6rem;
    line-height: 1;
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -.01em;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: .35rem;
}

.icon-btn {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    font-size: 1.05rem;
    transition: background .15s, opacity .15s;
}

.icon-btn:hover {
    background: var(--surface-2);
}

.icon-btn[aria-pressed="false"] {
    opacity: .35;
    filter: grayscale(1);
}

.memo-account {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-left: .5rem;
    padding-left: .75rem;
    border-left: 1px solid var(--border);
    font-size: .9rem;
}

.account-name {
    font-weight: 700;
    white-space: nowrap;
}

.link-btn {
    color: var(--primary-strong);
    font-size: .9rem;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.link-btn:hover {
    color: var(--accent);
}

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

.layout {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 1.25rem;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.25rem 1rem 2rem;
    align-items: start;
}

.game-column,
.side-column {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.side-column {
    position: sticky;
    top: 4.5rem;
}

.footer {
    padding: 1rem;
    text-align: center;
    font-size: .8rem;
    color: var(--muted);
}

/* ---------- Cartes (panneaux) ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 1rem;
    font-weight: 800;
}

section.card,
.card > .card-title {
    padding: 1rem;
}

section.card > .card-title {
    padding: 0 0 .5rem;
}

details.card > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

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

details.card > summary::after {
    content: "";
    width: .55rem;
    height: .55rem;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform .2s;
    flex-shrink: 0;
}

details.card[open] > summary::after {
    transform: rotate(-135deg);
}

/* ---------- Nouvelle partie (étapes) ---------- */

.setup-body {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    padding: 0 1rem 1.1rem;
}

.step-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .6rem;
    font-size: .8rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.step-num {
    display: inline-grid;
    place-items: center;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: .75rem;
    letter-spacing: 0;
}

.level-tabs {
    display: inline-flex;
    gap: .25rem;
    padding: .25rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.level-tab {
    padding: .45rem 1.1rem;
    border-radius: 999px;
    font-weight: 600;
    color: var(--muted);
    transition: background .15s, color .15s;
}

.level-tab:hover {
    color: var(--text);
}

.level-tab.level-active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(26, 167, 167, .35);
}

.memo-choix {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: .6rem;
}

.memo-choix:empty::before {
    content: "Choisissez d'abord un niveau.";
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: .9rem;
}

.item-choix {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .05rem;
    padding: .7rem .5rem;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    transition: border-color .15s, transform .15s, background .15s;
}

.item-choix strong {
    font-size: 1.5rem;
    line-height: 1.1;
}

.item-choix small {
    font-size: .75rem;
    color: var(--muted);
}

.item-choix:not(:disabled):hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.item-choix.choix-active {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.item-choix:disabled {
    opacity: .4;
}

.stars {
    display: block;
    margin-top: .15rem;
    color: var(--warning);
    font-size: .8rem;
    letter-spacing: 1px;
}

.mode-groups {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.mode-group-title {
    margin-bottom: .4rem;
    font-size: .85rem;
    font-weight: 700;
}

.memo-modes {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.item-mode,
.item-duel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    width: 100%;
    padding: .55rem .8rem;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    background: var(--surface-2);
    text-align: left;
    font-weight: 600;
    transition: border-color .15s, background .15s;
}

.item-mode .stars {
    margin: 0;
    flex-shrink: 0;
}

.item-mode:hover,
.item-mode.mode-active {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.item-duel:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* ---------- Variantes ---------- */

.variant-picker {
    margin-bottom: 1rem;
}

.variant-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.variant-chip {
    padding: .35rem .8rem;
    border-radius: 999px;
    border: 2px solid var(--border);
    background: var(--surface-2);
    font-size: .9rem;
    font-weight: 600;
    transition: border-color .15s, background .15s;
}

.variant-chip:hover {
    border-color: var(--primary);
}

.variant-chip.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.variant-help {
    margin-top: .4rem;
    font-size: .85rem;
    color: var(--muted);
}

.stars.is-expert {
    color: var(--danger);
}

.choix-large {
    display: none;
    margin-top: .2rem;
    font-size: .7rem;
    color: var(--muted);
}

@media (max-width: 700px) {
    .choix-large {
        display: block;
    }
}

/* Piège déjà déclenché : signalé sur les deux faces */
.case.is-trap .case-front::after,
.case.is-trap .case-back::after {
    content: "💣";
    position: absolute;
    top: 4%;
    right: 6%;
    inset-inline-start: auto;
    display: block;
    font-size: 28cqi;
    line-height: 1;
    color: initial;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .4));
}

.case.is-trap .case-back::after {
    inset: auto;
    top: 4%;
    right: 6%;
}

/* Mélange : les deux cartes échangées tournoient */
.case.is-swapped {
    animation: swap .8s ease-in-out;
}

/* Lampe torche : seul un cercle autour du pointeur est visible */
.memo-board.is-torch .memo-plateau {
    -webkit-mask-image: radial-gradient(circle clamp(90px, 18vmin, 170px) at var(--tx, 50%) var(--ty, 50%), #000 55%, transparent 100%);
    mask-image: radial-gradient(circle clamp(90px, 18vmin, 170px) at var(--tx, 50%) var(--ty, 50%), #000 55%, transparent 100%);
}

.memo-board.is-torch {
    cursor: crosshair;
    touch-action: manipulation;
}

/*
 * Partie en cours sur grand écran : « Nouvelle partie », message, tableau de
 * bord et barre de duel passent dans une colonne étroite à gauche, la grille
 * prend tout le centre.
 */
@media (min-width: 961px) {
    .layout:has(.memo-plateau:not(:empty)):has(.setup:not([open])) {
        max-width: 1440px;
        grid-template-columns: minmax(0, 1fr) 300px;
    }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) {
        display: grid;
        grid-template-columns: 240px minmax(0, 1fr);
        grid-template-rows: auto auto auto auto minmax(0, 1fr);
        align-content: start;
        column-gap: 1.25rem;
        row-gap: .75rem;
    }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) > .setup { grid-area: 1 / 1; }
    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) > .memo-hint { grid-area: 2 / 1; }
    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) > .hud { grid-area: 3 / 1; }
    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) > .duel-bar { grid-area: 4 / 1; }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) > .memo-board {
        grid-column: 2;
        grid-row: 1 / -1;
        height: 100%;
    }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .memo-hint {
        text-align: left;
    }

    /* Tableau de bord vertical : statistiques en 2 × 2, boutons empilés */
    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .hud {
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        align-self: start;
        padding: 1rem 1rem 1.2rem;
    }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .hud-stats {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: .75rem;
    }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .hud-actions {
        flex-direction: column;
    }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .hud-actions .btn {
        width: 100%;
    }

    /* En duel, Classement / Pause / Rejouer sont désactivés : on les masque pour gagner de la place */
    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])):has(.duel-bar:not(.hide)) .hud-actions {
        display: none;
    }

    /* Barre de duel verticale : vous, le tour, l'adversaire */
    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .duel-bar {
        grid-template-columns: 1fr;
        gap: .5rem;
    }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .duel-turn {
        order: -1;
        text-align: left;
    }

    .game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .duel-them {
        text-align: left;
        border-right: 1px solid var(--border);
        border-left: 6px solid var(--accent);
    }
}

/* ---------- Message d'état ---------- */

.memo-hint {
    min-height: 1.45em;
    text-align: center;
    font-weight: 600;
    color: var(--muted);
}

.memo-hint.is-error {
    color: var(--danger);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    padding: .5rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    transition: background .15s, opacity .15s, transform .1s;
}

.btn:not(:disabled):hover {
    background: var(--primary-strong);
}

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

.btn:disabled {
    opacity: .45;
}

.btn.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.btn-ghost:not(:disabled):hover {
    background: var(--surface-2);
}

.btn.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.btn-secondary:not(:disabled):hover {
    background: var(--border);
}

.btn.btn-small {
    padding: .25rem .65rem;
    font-size: .85rem;
}

.btn-share {
    margin-top: .5rem;
}

/* ---------- Tableau de bord ---------- */

.hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem 1rem;
    position: relative;
    overflow: hidden;
}

.hud-stats {
    display: flex;
    gap: 1.5rem;
}

.hud-goal {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .4rem .75rem;
    width: 100%;
    padding: .45rem .7rem;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary-strong);
    font-weight: 700;
    font-size: .9rem;
}

.goal-dots {
    display: inline-flex;
    gap: .3rem;
}

.goal-dots .dot {
    width: .7rem;
    height: .7rem;
    border-radius: 50%;
    border: 2px solid var(--primary);
    transition: background .15s, transform .15s;
}

.goal-dots .dot.is-on {
    background: var(--primary);
    transform: scale(1.15);
}

.hud-stat dt {
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.hud-stat dd {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.hud-stat dd small {
    font-size: .8rem;
    font-weight: 600;
    color: var(--muted);
}

.hud-best dd {
    font-size: .95rem;
    padding-top: .25rem;
}

.hud-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.time-low {
    color: var(--danger);
    animation: pulse 1s infinite;
}

.memo-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: var(--surface-2);
}

.memo-progress-bar {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    transition: width .3s;
}

/* ---------- Plateau ---------- */

.memo-board {
    position: relative;
}

/*
 * Partie en cours (plateau rempli et « Nouvelle partie » repliée) : la colonne
 * du jeu prend toute la hauteur de l'écran et le plateau occupe la place
 * restante. Les cartes sont calculées pour tenir en largeur ET en hauteur
 * (unités de conteneur cqw/cqh), plateau centré : aucun défilement.
 */
.game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) {
    height: calc(100dvh - var(--topbar-h, 3.5rem) - 2rem);
    min-height: 380px;
    gap: .6rem;
}

.game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .memo-board {
    flex: 1;
    min-height: 0;
    container-type: size;
    display: grid;
    place-items: center;
}

.game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .memo-plateau {
    width: min(100cqw, calc((100cqh - .5rem) * var(--cols, 4) / var(--rows, 4)), calc(var(--cols, 4) * 150px));
    max-width: none;
    margin: 0;
}

.game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .memo-hint {
    min-height: 0;
    font-size: .9rem;
}

.game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .hud {
    padding: .6rem 1rem;
}

.game-column:has(.memo-plateau:not(:empty)):has(.setup:not([open])) .setup > summary {
    padding: .6rem 1rem;
}

.memo-plateau {
    display: grid;
    grid-template-columns: repeat(var(--cols, 4), 1fr);
    gap: clamp(.25rem, 1vw, .5rem);
    /* Cartes de 130 px au plus, et plateau entier visible en hauteur */
    max-width: min(100%, calc(var(--cols, 4) * 130px), calc((100vh - 12rem) * var(--cols, 4) / var(--rows, 4)));
    margin: 0 auto;
    transition: filter .2s;
}

.memo-plateau:empty {
    display: grid;
    max-width: none;
    place-items: center;
    min-height: 220px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
}

.memo-plateau:empty::before {
    content: attr(data-empty);
    max-width: 22rem;
    padding: 1rem;
    text-align: center;
    color: var(--muted);
}

.memo-plateau.is-paused {
    filter: blur(14px);
    pointer-events: none;
}

.case {
    aspect-ratio: 1;
    perspective: 700px;
    border-radius: var(--radius-sm);
    container-type: inline-size; /* le « ? » et la 💣 suivent la taille de la carte */
}

.case-inner {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform .4s cubic-bezier(.4, .2, .2, 1);
}

.case.is-revealed .case-inner,
.case.is-matched .case-inner {
    transform: rotateY(180deg);
}

.case-face {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-sm);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.case-back {
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .09) 0 6px, transparent 6px 12px),
        linear-gradient(135deg, var(--card-back-1), var(--card-back-2));
    border: 3px solid rgba(255, 255, 255, .85);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}

.case-back::after {
    content: "?";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: rgba(255, 255, 255, .55);
    font-weight: 800;
    font-size: 40cqi;
    line-height: 1;
}

.case:not(:disabled):hover .case-back {
    filter: brightness(1.08);
}

.case-front {
    transform: rotateY(180deg);
    background-color: var(--surface);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    box-shadow: 0 0 0 1px var(--border);
}

.case.is-wrong .case-front {
    box-shadow: 0 0 0 3px var(--danger);
    animation: shake .35s;
}

.case.is-matched .case-front {
    box-shadow: 0 0 0 3px var(--success);
    opacity: .6;
    transition: opacity .4s .3s;
}

.case.is-matched.is-mine .case-front {
    box-shadow: 0 0 0 3px var(--success);
}

.case.is-matched.is-theirs .case-front {
    box-shadow: 0 0 0 3px var(--accent);
}

/* ---------- Duels ---------- */

.duel-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .75rem;
}

.duel-player {
    display: flex;
    flex-direction: column;
    padding: .55rem .8rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: box-shadow .2s;
}

.duel-me {
    border-left: 6px solid var(--success);
}

.duel-them {
    border-right: 6px solid var(--accent);
    text-align: right;
}

.duel-player.is-current {
    box-shadow: 0 0 0 3px var(--primary), var(--shadow);
}

.duel-name {
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.duel-score {
    font-size: .85rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.duel-player.is-away .duel-score {
    color: var(--danger);
}

.duel-turn {
    font-weight: 800;
    text-align: center;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.duel-turn.is-mine {
    color: var(--success);
}

.duel-countdown {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    color: var(--primary-strong);
    font-size: clamp(4rem, 15vw, 7rem);
    font-weight: 900;
    animation: pop 1s infinite;
}

.duel-link {
    flex: 1;
    min-width: 0;
    padding: .45rem .6rem;
    font-size: .85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.duel-code {
    margin-top: .75rem;
}

.duel-code strong {
    font-size: 1.5rem;
    letter-spacing: .2em;
    color: var(--primary-strong);
}

.duel-code-input {
    text-transform: uppercase;
    letter-spacing: .2em;
}

.duel-waiting {
    margin-top: .75rem;
    color: var(--muted);
    animation: pulse 1.6s infinite;
}

/* ---------- Colonne de droite : invité, salon, aide ---------- */

.lobby-guest p,
.help-list {
    font-size: .9rem;
    color: var(--muted);
}

.guest-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: .75rem;
}

.help-list {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    padding-left: 1.1rem;
}

.lobby-count {
    margin-left: auto;
    padding: .1rem .55rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-strong);
    font-size: .75rem;
    font-weight: 700;
}

.lobby-body {
    display: flex;
    flex-direction: column;
    gap: .9rem;
    padding: 0 1rem 1rem;
}

.lobby-section h3 {
    margin-bottom: .3rem;
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.lobby-incoming {
    padding: .6rem .7rem;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

.lobby-incoming h3 {
    color: var(--accent);
}

.lobby-list {
    list-style: none;
}

.lobby-list li {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .35rem 0;
    border-bottom: 1px solid var(--border);
    font-size: .88rem;
}

.lobby-list li:last-child {
    border-bottom: 0;
}

.lobby-players .lobby-label strong::before {
    content: "";
    display: inline-block;
    width: .5rem;
    height: .5rem;
    margin-right: .4rem;
    border-radius: 50%;
    background: var(--success);
    vertical-align: middle;
}

.lobby-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lobby-label em {
    color: var(--muted);
}

.lobby-label small {
    color: var(--muted);
    font-size: .78rem;
}

.badge {
    display: inline-block;
    margin-left: .35rem;
    padding: 0 .45rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-strong);
    font-size: .7rem;
    font-weight: 700;
    vertical-align: middle;
}

.badge-accent {
    background: var(--accent-soft);
    color: var(--accent);
}

.tournament-meta {
    margin-top: .5rem;
    font-size: .9rem;
    color: var(--muted);
}

.lobby-empty {
    color: var(--muted);
    font-style: italic;
}

.lobby-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    padding-top: .25rem;
}

.lobby-create {
    background: var(--accent);
}

.lobby-create:not(:disabled):hover {
    background: color-mix(in srgb, var(--accent) 85%, #000);
}

/* ---------- Fenêtre modale ---------- */

.memo-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(8, 18, 24, .55);
    backdrop-filter: blur(3px);
    animation: fade .15s;
}

.memo-modal-box {
    width: 100%;
    max-width: 28rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: 1.5rem;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-strong);
    text-align: center;
    animation: rise .2s;
}

.modal-title {
    margin-bottom: .75rem;
    font-size: 1.3rem;
}

.modal-body p + p {
    margin-top: .3rem;
}

.modal-body .record {
    margin-top: .5rem;
    color: var(--accent);
    font-weight: 700;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .5rem;
    margin-top: 1.25rem;
}

.modal-actions:empty {
    display: none;
}

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

.auth-form,
.create-form {
    display: flex;
    flex-direction: column;
    gap: .55rem;
    margin: .75rem 0;
    text-align: left;
}

.auth-form input,
.create-form select,
.create-form input:not([type="radio"]),
.score-row input {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.auth-form input:focus,
.create-form select:focus,
.create-form input:focus,
.score-row input:focus {
    border-color: var(--primary);
}

.auth-help {
    font-size: .85rem;
    color: var(--muted);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
}

.form-row label {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    font-weight: 700;
}

.create-form fieldset {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    border: 0;
}

.create-form legend,
.create-form > label {
    margin-bottom: .2rem;
    font-weight: 700;
}

.radio {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .35rem .5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

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

.radio input {
    accent-color: var(--primary);
}

.score-form {
    margin-top: 1rem;
    text-align: left;
}

.score-form > .btn {
    width: 100%;
}

.score-form label {
    display: block;
    margin-bottom: .35rem;
    font-weight: 700;
}

.score-row {
    display: flex;
    gap: .4rem;
}

.form-error {
    margin-top: .4rem;
    color: var(--danger);
    font-size: .9rem;
}

.form-error:empty {
    display: none;
}

/* ---------- Tableaux de classement ---------- */

.board-mode {
    margin-bottom: .75rem;
    color: var(--muted);
}

.board {
    width: 100%;
    margin-top: .75rem;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    text-align: left;
}

.board th,
.board td {
    padding: .4rem .5rem;
    border-bottom: 1px solid var(--border);
}

.board th {
    font-size: .7rem;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
}

.board td:nth-child(2) {
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.board tr.is-me td {
    background: var(--accent-soft);
    font-weight: 700;
}

.board-empty {
    margin-top: .5rem;
    color: var(--muted);
}

/* ---------- Animations ---------- */

@keyframes shake {
    0%, 100% { translate: 0; }
    25% { translate: -4px; }
    75% { translate: 4px; }
}

@keyframes swap {
    0%, 100% { transform: none; }
    30% { transform: scale(.85) rotate(-8deg); }
    60% { transform: scale(1.05) rotate(6deg); box-shadow: 0 0 0 4px var(--warning); }
}

@keyframes pulse {
    50% { opacity: .5; }
}

@keyframes pop {
    0% { transform: scale(1.15); opacity: .6; }
    20% { transform: scale(1); opacity: 1; }
}

@keyframes fade {
    from { opacity: 0; }
}

@keyframes rise {
    from { transform: translateY(12px); opacity: 0; }
}

/* ---------- Écrans plus petits ---------- */

@media (max-width: 960px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .side-column {
        position: static;
    }

    .help {
        display: none;
    }
}

@media (max-width: 600px) {
    .layout {
        padding: .75rem .75rem 1.5rem;
    }

    .topbar-inner {
        padding: .5rem .75rem;
    }

    .brand-name {
        font-size: 1.05rem;
        white-space: nowrap;
    }

    .topbar-actions {
        gap: 0;
    }

    .icon-btn {
        width: 2rem;
        height: 2rem;
    }

    .memo-account {
        flex-direction: column;
        align-items: flex-end;
        gap: 0;
        margin-left: .25rem;
        padding-left: .5rem;
        line-height: 1.25;
    }

    .memo-account .link-btn {
        font-size: .8rem;
        white-space: nowrap;
    }

    .account-name {
        max-width: 8rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mode-groups {
        grid-template-columns: 1fr;
    }

    .level-tabs {
        display: flex;
    }

    .level-tab {
        flex: 1;
        padding: .45rem .5rem;
    }

    .hud-stats {
        gap: 1rem;
    }

    .hud-actions {
        width: 100%;
    }

    .hud-actions {
        flex-wrap: nowrap;
    }

    .hud-actions .btn {
        flex: 1 1 0;
        min-width: 0;
        padding: .45rem .4rem;
        font-size: .85rem;
    }

    .duel-bar {
        grid-template-columns: 1fr 1fr;
    }

    .duel-turn {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .case-back {
        border-width: 2px;
    }
}

/* Très petits écrans : le logo suffit, le nom reste lu par les lecteurs d'écran */
@media (max-width: 400px) {
    .brand-name {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
}

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