/* Manette (shared/gamepad.js) : curseur des menus, noms des boutons, invite de connexion.
   body.pad : la manette a la main ; body[data-pad] : sa marque (xbox, playstation, nintendo) ;
   --pad-bottom, --pad-left… : ce qui est écrit sur ses boutons. */

/* Curseur : l'élément choisi à la manette */
body.pad .pad-focus {
    outline: 3px solid #ffd27a !important;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(255, 210, 122, 0.16), 0 0 26px rgba(255, 210, 122, 0.42);
}

/* En réglage (A sur un curseur ou une liste) : gauche / droite changent la valeur */
body.pad .pad-focus.pad-editing {
    outline-color: #7fdcff !important;
    box-shadow: 0 0 0 6px rgba(127, 220, 255, 0.18), 0 0 26px rgba(127, 220, 255, 0.45);
}

/* Cartes de choix : le même relief qu'au survol */
body.pad .card.pad-focus {
    transform: translateY(-4px);
    border-color: var(--r);
    box-shadow: 0 0 0 6px rgba(255, 210, 122, 0.16), 0 16px 40px -18px var(--r);
}

/* Noms des boutons : <kbd data-pad="bottom">Espace</kbd> remplace la touche par le bouton de la manette,
   <span class="pad-glyph" data-pad="rt"></span> l'écrit seul */
body.pad kbd[data-pad],
body.pad #btn-reroll kbd {
    font-size: 0 !important;
}

body.pad kbd[data-pad]::after,
body.pad #btn-reroll kbd::after {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text);
}

body.pad [data-pad='bottom']::after { content: var(--pad-bottom, 'A'); }
body.pad [data-pad='right']::after { content: var(--pad-right, 'B'); }
body.pad [data-pad='left']::after { content: var(--pad-left, 'X'); }
body.pad [data-pad='top']::after,
body.pad #btn-reroll kbd::after { content: var(--pad-top, 'Y'); }
body.pad [data-pad='lb']::after { content: var(--pad-lb, 'LB'); }
body.pad [data-pad='rb']::after { content: var(--pad-rb, 'RB'); }
body.pad [data-pad='lt']::after { content: var(--pad-lt, 'LT'); }
body.pad [data-pad='rt']::after { content: var(--pad-rt, 'RT'); }
body.pad [data-pad='start']::after { content: var(--pad-start, '☰'); }

/* Numéros des cartes : inutiles à la manette, le curseur montre le choix */
body.pad .card kbd {
    display: none;
}

.pad-only,
body.pad .pad-hide {
    display: none;
}

body.pad .pad-only {
    display: inline;
}

/* Tablette et manette : les commandes tactiles s'effacent quand la manette joue */
body.pad #touch-controls {
    display: none !important;
}

/* Invite : manette connectée ou déconnectée */
.pad-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    z-index: 120;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    max-width: calc(100vw - 32px);
    padding: 12px 20px;
    border-radius: 14px;
    background: rgba(8, 14, 26, 0.94);
    border: 1px solid rgba(255, 210, 122, 0.35);
    box-shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.85);
    color: #f3f5fb;
    font: 600 14px/1.35 Outfit, system-ui, sans-serif;
    text-align: center;
    opacity: 0;
    transform: translate(-50%, 12px);
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
}

.pad-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.pad-toast small {
    font-size: 12.5px;
    font-weight: 500;
    color: rgba(243, 245, 251, 0.72);
}

.pad-toast kbd {
    min-width: 22px;
    margin: 0 2px;
    font-size: 11.5px;
    font-weight: 700;
    color: #ffd27a;
    border-color: rgba(255, 210, 122, 0.4);
}

/* Clavier à l'écran (shared/pad-keyboard.js) : en bas de l'écran, la page reste visible au-dessus (la
   recherche du Comptoir se met à jour pendant la frappe) */
.pad-keyboard {
    position: fixed;
    left: 50%;
    bottom: 16px;
    z-index: 110;
    width: min(640px, calc(100vw - 24px));
    padding: 14px;
    border-radius: 18px;
    background: rgba(8, 14, 26, 0.96);
    border: 1px solid rgba(255, 210, 122, 0.3);
    box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.9);
    transform: translateX(-50%);
    color: #f3f5fb;
    font: 600 15px/1.2 Outfit, system-ui, sans-serif;
}

.pad-keyboard[hidden] {
    display: none;
}

.pad-keyboard.numeric {
    width: min(300px, calc(100vw - 24px));
}

.vk-head {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.vk-title {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(243, 245, 251, 0.55);
}

.vk-text {
    display: block;
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.14);
    font-size: 18px;
    white-space: pre;
    overflow: hidden;
}

.vk-text.empty::before {
    content: attr(data-placeholder);
    color: rgba(243, 245, 251, 0.35);
}

/* Curseur de saisie */
.vk-text::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1.1em;
    margin-left: 2px;
    vertical-align: -0.15em;
    background: #ffd27a;
    animation: vk-caret 1s steps(1) infinite;
}

@keyframes vk-caret {
    50% { opacity: 0; }
}

.vk-keys {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vk-row {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.vk-key {
    flex: 1 1 0;
    min-width: 0;
    height: 44px;
    padding: 0 4px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: inherit;
    font: inherit;
    white-space: nowrap;
}

.vk-key:hover {
    background: rgba(255, 255, 255, 0.12);
}

.vk-key.on {
    background: rgba(255, 210, 122, 0.22);
    border-color: rgba(255, 210, 122, 0.6);
}

.vk-wide {
    flex-grow: 1.6;
}

.vk-space {
    flex-grow: 3;
}

.vk-ok {
    flex-grow: 1.6;
    color: #2b1a05;
    background: linear-gradient(180deg, #ffe38a, #ffc24d);
    border-color: transparent;
}

.vk-ok:hover {
    background: linear-gradient(180deg, #fff0b3, #ffd36b);
}

/* Pavé de chiffres : trois colonnes */
.pad-keyboard.numeric .vk-key[data-key] {
    flex: 0 0 calc((100% - 12px) / 3);
}

/* Boutons de la manette sur les touches d'action : seulement quand elle a la main */
.vk-key kbd {
    display: none;
    margin-left: 4px;
}

body.pad .vk-key kbd {
    display: inline-block;
}

.vk-ok kbd {
    color: #2b1a05;
    border-color: rgba(43, 26, 5, 0.35);
}

body.pad .vk-ok kbd::after {
    color: #2b1a05;
}

@media (max-width: 480px) {
    .vk-key {
        height: 40px;
        font-size: 14px;
    }

    .vk-row {
        gap: 4px;
    }
}
