/* ==========================================================================
   AVATAR SELECT — feuille de style
   Style : pixel-art rétro, palette vert/crème sur fond sombre
   Optimisé pour mobile en mode PAYSAGE (landscape)
   ========================================================================== */

/* ----- Polices ----------------------------------------------------------
   - NT Brick Sans : fichier local dans layout/font/NTBrickSans.woff2
   - Kode Mono     : Google Fonts (importée via <link> dans index.html et
                     terminal.html, donc plus de @font-face ici)
   -------------------------------------------------------------------------- */

@font-face {
    font-family: "NT Brick Sans";
    src: url("../font/NTBrickSans.woff2") format("woff2");
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ----- Variables ---------------------------------------------------------- */

:root {
    /* Palette */
    --bg:          #0f1612;
    --bg-2:        #131c17;
    --grid:        #1c2a22;
    --cream:       #e9e4c3;
    --cream-soft:  #d6d2b3;
    --green:       #8bc34a;
    --green-dark:  #6ea63a;
    --green-deep:  #4a7826;
    --shadow:      #000000;

    /* Typo */
    --font-title: "NT Brick Sans", "Courier New", monospace;
    --font-body:  "Kode Mono", "Courier New", monospace;

    /* Tailles — adaptées au mode paysage : on se base sur la HAUTEUR du viewport */
    --avatar-size: clamp(110px, 42vh, 180px);
    --arrow-size:  clamp(26px, 8vh, 38px);

    /* Couleur de fond de l'avatar (modifiable via JS) */
    --avatar-bg:        var(--green);
    --avatar-bg-shade:  rgba(0, 0, 0, 0.18);
}

/* ----- Reset & base ------------------------------------------------------- */

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    /* Hauteur dynamique qui s'adapte à la barre du navigateur mobile.
       100dvh = "dynamic viewport height" : suit l'apparition/disparition de la
       barre d'URL en mobile. Fallback vers 100vh sur vieux navigateurs. */
    min-height: 100vh;
    min-height: 100svh;
    height: 100dvh;
}

body {
    font-family: var(--font-body);
    color: var(--cream);
    background-color: var(--bg);
    background-image:
        linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 32px 32px;
    background-position: -1px -1px;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    /* Évite les bounces iOS (scroll élastique) */
    overscroll-behavior: none;
    /* Évite le double-tap-zoom sur iOS */
    touch-action: manipulation;
    /* Safe area : respecte les notches iPhone et marges des barres système */
    padding:
        env(safe-area-inset-top)
        env(safe-area-inset-right)
        env(safe-area-inset-bottom)
        env(safe-area-inset-left);
}

button {
    font-family: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

img {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* ----- Décorations d'angle ----------------------------------------------- */

.corner {
    position: fixed;
    width: 18px;
    height: 18px;
    border: 2px solid var(--cream-soft);
    opacity: 0.55;
    pointer-events: none;
}

.corner--tl { top: 14px;    left: 14px;    border-right: none;  border-bottom: none; }
.corner--tr { top: 14px;    right: 14px;   border-left: none;   border-bottom: none; }
.corner--bl { bottom: 14px; left: 14px;    border-right: none;  border-top: none;    }
.corner--br { bottom: 14px; right: 14px;   border-left: none;   border-top: none;    }

/* ==========================================================================
   ÉCRAN DE SÉLECTION — layout HORIZONTAL
   ========================================================================== */

.screen {
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100svh;
    padding: 30px 50px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(20px, 6vw, 60px);
}

/* ==========================================================================
   PASTILLE DE COULEUR + PALETTE
   ========================================================================== */

.color-pill {
    position: absolute;
    top: 22px;
    left: 22px;
    width: 24px;
    height: 24px;
    background-color: var(--avatar-bg);
    border: 2px solid var(--cream);
    border-radius: 4px;
    box-shadow:
        inset 0 0 0 2px var(--bg),
        0 0 0 2px var(--avatar-bg);
    transition: transform 0.15s ease;
    z-index: 10;
}

.color-pill::before {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 7px;
    height: 7px;
    background-color: rgba(0, 0, 0, 0.25);
}

.color-pill:hover    { transform: scale(1.08); }
.color-pill:active   { transform: scale(0.95); }

.color-palette {
    position: fixed;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    width: 96px;
    background-color: var(--bg-2);
    border: 2px solid var(--cream-soft);
    z-index: 50;
    animation: paletteIn 0.18s ease-out;
}

.color-palette[hidden] { display: none; }

.color-palette__swatch {
    width: 24px;
    height: 24px;
    border: 2px solid var(--bg);
    cursor: pointer;
    transition: transform 0.12s ease;
    position: relative;
}

.color-palette__swatch:hover {
    transform: scale(1.12);
}

.color-palette__swatch--active {
    outline: 2px solid var(--cream);
    outline-offset: 2px;
}

@keyframes paletteIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   SÉLECTEUR D'AVATAR (à GAUCHE en landscape)
   ========================================================================== */

.avatar-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(12px, 3vw, 22px);
    flex-shrink: 0;
}

.arrow {
    width: var(--arrow-size);
    height: calc(var(--arrow-size) * 1.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.arrow svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: var(--cream-soft);
    stroke-width: 4;
    stroke-linecap: square;
    stroke-linejoin: miter;
}

.arrow:hover svg { stroke: var(--cream); }
.arrow:hover     { transform: scale(1.1);  }
.arrow:active    { transform: scale(0.92); }

.arrow--left:active  { transform: translateX(-3px) scale(0.92); }
.arrow--right:active { transform: translateX(3px)  scale(0.92); }

/* ----- Cadre avatar ------------------------------------------------------ */

.avatar-frame {
    position: relative;
    width: var(--avatar-size);
    height: var(--avatar-size);
    background-color: var(--avatar-bg);
    border: 2px solid var(--bg);
    box-shadow:
        0 0 0 2px var(--avatar-bg),
        inset 0 -8px 0 var(--avatar-bg-shade);
    overflow: hidden;
    transition: background-color 0.25s ease;
}

.avatar-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
    background-size: 16px 16px;
    pointer-events: none;
}

.avatar-image {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 8%;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.avatar-image.is-switching {
    opacity: 0;
    transform: scale(0.9);
}

/* ==========================================================================
   COLONNE DROITE — Nom + Bouton
   ========================================================================== */

.right-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    flex-shrink: 0;
}

/* ----- Nom du joueur ---------------------------------------------------- */

.name-field { position: relative; }

.name-input {
    font-family: var(--font-title);
    font-size: clamp(24px, 6vh, 36px);
    color: var(--cream);
    background: transparent;
    border: none;
    outline: none;
    text-align: center;
    letter-spacing: 1px;
    width: clamp(180px, 30vw, 260px);
    padding: 4px 8px 8px;
    caret-color: var(--green);
}

.name-input::selection {
    background: var(--green-deep);
    color: var(--cream);
}

.name-underline {
    display: block;
    height: 4px;
    width: 100%;
    background-image:
        repeating-linear-gradient(
            to right,
            var(--green) 0,
            var(--green) 8px,
            transparent 8px,
            transparent 12px
        );
    margin-top: -2px;
    transition: background-image 0.2s ease;
}

.name-field:focus-within .name-underline {
    background-image:
        repeating-linear-gradient(
            to right,
            var(--cream) 0,
            var(--cream) 8px,
            transparent 8px,
            transparent 12px
        );
}

/* ----- Bouton VALIDER --------------------------------------------------- */

.validate-btn {
    position: relative;
    padding: 12px 32px;
    font-family: var(--font-title);
    font-size: clamp(16px, 4vh, 22px);
    color: var(--bg);
    background-color: var(--green);
    border: 2px solid var(--cream);
    letter-spacing: 2px;
    text-transform: uppercase;
    transition: transform 0.12s ease, background-color 0.15s ease;
}

.validate-btn::before {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background-color: rgba(0, 0, 0, 0.22);
}

.validate-btn__label  { position: relative; z-index: 2; }

.validate-btn__shadow {
    position: absolute;
    inset: 4px -4px -4px 4px;
    background-color: var(--green-deep);
    z-index: -1;
    transition: inset 0.12s ease;
}

.validate-btn:hover {
    background-color: var(--green-dark);
    transform: translate(-2px, -2px);
}

.validate-btn:hover .validate-btn__shadow {
    inset: 6px -6px -6px 6px;
}

.validate-btn:active {
    transform: translate(2px, 2px);
}

.validate-btn:active .validate-btn__shadow {
    inset: 0;
}

/* ==========================================================================
   ANIMATIONS D'ENTRÉE
   ========================================================================== */

.color-pill,
.avatar-selector,
.right-col {
    animation: fadeUp 0.5s ease-out backwards;
}

.color-pill      { animation-delay: 0.05s; }
.avatar-selector { animation-delay: 0.15s; }
.right-col       { animation-delay: 0.25s; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   BOUTONS GÉNÉRIQUES (utilisés sur card / roulette / reveal)
   ========================================================================== */

.btn {
    position: relative;
    padding: 12px 24px;
    font-family: var(--font-title);
    font-size: clamp(13px, 3.2vh, 17px);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    border: 2px solid var(--cream);
    transition: transform 0.12s ease, background-color 0.15s ease;
    cursor: pointer;
    text-align: center;
    color: var(--cream);
    background-color: transparent;
    white-space: nowrap;
    box-sizing: border-box;
}

.btn--primary {
    color: var(--bg);
    background-color: var(--green);
}

.btn--primary::before {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 8px;
    height: 8px;
    background-color: rgba(0, 0, 0, 0.22);
}

.btn__label  { position: relative; z-index: 2; }

.btn__shadow {
    position: absolute;
    inset: 4px -4px -4px 4px;
    background-color: var(--green-deep);
    z-index: -1;
    transition: inset 0.12s ease;
}

.btn--primary:hover {
    background-color: var(--green-dark);
    transform: translate(-2px, -2px);
}

.btn--primary:hover .btn__shadow {
    inset: 6px -6px -6px 6px;
}

.btn--primary:active {
    transform: translate(2px, 2px);
}

.btn--primary:active .btn__shadow {
    inset: 0;
}

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

.btn--ghost:hover {
    background-color: rgba(207, 217, 180, 0.08);
    transform: translateY(-2px);
}

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

/* ==========================================================================
   BOUTONS MUTE (musique / sfx) — en haut à droite, style pixel art
   ========================================================================== */

.audio-toggles {
    position: fixed;
    /* Décalage qui prend en compte le notch s'il y en a un */
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: calc(14px + env(safe-area-inset-right, 0px));
    display: flex;
    gap: 8px;
    z-index: 200;
}

/* ----- Bouton Installer (PWA) — apparaît sur Android quand dispo --- */

.install-btn {
    position: fixed;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    right:  calc(14px + env(safe-area-inset-right, 0px));
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px 8px 10px;
    background-color: var(--bg-2);
    border: 2px solid var(--green);
    color: var(--cream);
    font-family: var(--font-body);
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    z-index: 199;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
    animation: fadeUp 0.4s ease-out backwards;
}

.install-btn:hover {
    background-color: var(--green);
    color: var(--bg);
    transform: translate(-1px, -1px);
}

.install-btn:active {
    transform: translate(1px, 1px);
}

.install-btn svg {
    width: 16px;
    height: 16px;
    fill: var(--green);
    flex-shrink: 0;
}

.install-btn:hover svg { fill: var(--bg); }

.audio-toggle {
    width: 32px;
    height: 32px;
    padding: 0;
    background-color: var(--bg-2);
    border: 2px solid var(--cream-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s ease, background-color 0.15s ease;
    position: relative;
    box-sizing: border-box;
}

.audio-toggle::before {
    /* petit coin pixel décoratif */
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 4px;
    height: 4px;
    background-color: rgba(0, 0, 0, 0.3);
}

.audio-toggle:hover {
    background-color: var(--bg);
    transform: translate(-1px, -1px);
}

.audio-toggle:active {
    transform: translate(1px, 1px);
}

.audio-toggle svg {
    width: 22px;
    height: 22px;
    fill: var(--cream);
    transition: fill 0.15s ease;
}

/* Quand muté : icône grisée + croix rouge */
.audio-toggle[data-state="muted"] {
    border-color: rgba(207, 217, 180, 0.4);
}

.audio-toggle[data-state="muted"] svg {
    fill: rgba(207, 217, 180, 0.4);
}

.audio-toggle[data-state="muted"] .mute-x {
    fill: #b03737;
}

.audio-toggle .wave {
    fill: var(--cream);
}

/* Sur petits écrans landscape : un peu plus petit */
@media (orientation: landscape) and (max-height: 380px) {
    .audio-toggles { top: 8px; right: 10px; gap: 6px; }
    .audio-toggle  { width: 26px; height: 26px; border-width: 2px; }
    .audio-toggle svg { width: 18px; height: 18px; }
}

/* Le coin décoratif en haut à droite ne doit pas chevaucher les toggles */
.corner--tr {
    /* on le décale pour ne pas être en conflit */
    /* Note: laissé inchangé, les toggles sont à 14px, le coin à 14px aussi.
       Les toggles passent au-dessus grâce au z-index */
}

/* ==========================================================================
   FALLBACK PORTRAIT — invite à tourner l'appareil
   ========================================================================== */

.rotate-hint {
    display: none;
    position: fixed;
    inset: 0;
    background-color: var(--bg);
    z-index: 1000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 30px;
    text-align: center;
}

.rotate-hint__icon {
    width: 56px;
    height: 84px;
    border: 3px solid var(--cream);
    border-radius: 6px;
    position: relative;
    animation: rotateHint 1.8s ease-in-out infinite;
}

.rotate-hint__icon::after {
    content: "";
    position: absolute;
    inset: 6px;
    border: 2px dashed var(--green);
}

.rotate-hint__text {
    font-family: var(--font-title);
    font-size: 18px;
    color: var(--cream);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.rotate-hint__sub {
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--cream-soft);
    opacity: 0.7;
}

@keyframes rotateHint {
    0%, 35%   { transform: rotate(0deg); }
    65%, 100% { transform: rotate(-90deg); }
}

@media (orientation: portrait) {
    .rotate-hint { display: flex; }
}

/* ==========================================================================
   RESPONSIVE — petits écrans en landscape (iPhone SE etc.)
   ========================================================================== */

@media (orientation: landscape) and (max-height: 380px) {
    .screen { padding: 18px 40px; gap: 30px; }
    .corner { width: 12px; height: 12px; }
    .color-pill { top: 14px; left: 14px; width: 20px; height: 20px; }
    .color-palette { top: 42px; left: 14px; padding: 6px; gap: 5px; width: 86px; }
    .color-palette__swatch { width: 22px; height: 22px; }
}