/* Style Rétro PS1 - Slender */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background-color: #000;
    font-family: 'Courier New', Courier, monospace;
    color: #e0e0e0;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    /* Mobile : hauteur réellement visible (sans la barre d'adresse) */
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}

/* Canvas WebGL 3D avec rendu rétro PS1 */
#three-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Canvas 2D pour les parasites cathodiques / VHS et scanlines */
#overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    image-rendering: pixelated;
    /* Lignes de balayage CRT : une ligne sombre sur deux des 240 lignes du canvas */
    background-image: linear-gradient(rgba(0, 0, 0, 0.18) 50%, transparent 50%);
    /* --scan-rows : moitié des lignes du canvas (réglé en JS, 180 en portrait) */
    background-size: 100% calc(100% / var(--scan-rows, 120));
}

/* Vignette d'obscurité périphérique */
.vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 6;
    background: radial-gradient(circle at center, transparent 40%, rgba(0, 0, 0, 0.75) 85%, rgba(0, 0, 0, 0.98) 100%);
}

/* Screamer de l'observateur : œil plein écran, filtre rouge, 0.5 s */
#screamer {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: none;
    pointer-events: none;
    background: #000;
    overflow: hidden;
}

#screamer-eye {
    position: absolute;
    inset: 0;
    background-repeat: no-repeat;
    background-size: 1600% 100%; /* 16 images côte à côte */
    image-rendering: pixelated;
}

/* L'œil regarde partout : les 16 images défilent en 0.5 s, avec tremblement */
#screamer.play #screamer-eye {
    animation: screamer-frames 0.5s steps(16, jump-none) forwards,
               screamer-shake 0.08s steps(2) infinite;
}

@keyframes screamer-frames {
    from { background-position: 0% 0; }
    to { background-position: 100% 0; }
}

/* Filtre rouge par-dessus l'image */
#screamer::after {
    content: '';
    position: absolute;
    inset: 0;
    background: #ff0000;
    mix-blend-mode: multiply;
}

@keyframes screamer-shake {
    0% { transform: scale(1.15) translate(-1.5%, 1%); }
    100% { transform: scale(1.25) translate(1.5%, -1%); }
}

/* Screamer du chat : GIF plein écran en boucle aller-retour pendant 10 s (taille réglée en JS) */
#cat-screamer {
    position: absolute;
    inset: 0;
    z-index: 16;
    display: none;
    pointer-events: none;
    background: #000;
    overflow: hidden;
}

#cat-screamer-img {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-repeat: no-repeat;
    image-rendering: pixelated;
}

/* Interface en jeu (HUD) */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    display: none;
}

/* Compteur de notes en haut à gauche */
.note-counter {
    position: absolute;
    top: 24px;
    left: 28px;
    font-size: 20px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #f5f5f5;
    text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 0 0 10px rgba(255,255,255,0.4);
}

.note-counter span {
    font-weight: bold;
    color: #ffdd88;
}

/* Viseur central (petit point PS1) */
.crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.7);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    box-shadow: 0 0 4px #000;
}

/* Message d'interaction avec la note */
#interaction-prompt {
    position: absolute;
    top: 58%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 1.5px;
    color: #ffea79;
    text-shadow: 2px 2px 0 #000, 0 0 8px rgba(255, 234, 121, 0.6);
    background: rgba(0, 0, 0, 0.65);
    padding: 6px 14px;
    border: 1px solid rgba(255, 234, 121, 0.4);
    display: none;
}

/* Indicateurs en bas à gauche : Endurance et Lampe */
.bottom-hud {
    position: absolute;
    bottom: 24px;
    left: 28px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    letter-spacing: 1px;
    text-shadow: 1px 1px 0 #000;
}

/* Rythme cardiaque (bas droite) : BPM, même style que les autres indicateurs */
#heart-rate {
    position: absolute;
    bottom: 24px;
    right: 28px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    letter-spacing: 1px;
    text-shadow: 1px 1px 0 #000;
}

#bpm-value {
    min-width: 26px;
    text-align: right;
}

#heart-rate .bpm-unit {
    color: #888;
}

/* Cœur qui s'emballe : même rouge que l'endurance basse */
#heart-rate.fast #bpm-value {
    color: #c03030;
}

/* Barre d'endurance */
.stamina-track {
    width: 140px;
    height: 8px;
    background: rgba(30, 30, 30, 0.8);
    border: 1px solid #555;
    overflow: hidden;
}

.stamina-bar {
    width: 100%;
    height: 100%;
    background: #50b070;
    transition: width 0.05s linear, background-color 0.2s;
}

.stamina-bar.low {
    background: #c03030;
}

/* État lampe-torche */
.flashlight-status {
    color: #ffdd88;
}

.flashlight-status.off {
    color: #666;
}

/* Écrans de menu (Titre, Défaite, Victoire) */
.screen-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 7, 6, 0.92);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 20;
    padding: 20px;
}

.screen-box {
    max-width: 620px;
    max-height: 100%;
    overflow-y: auto;
    background: rgba(12, 14, 12, 0.95);
    border: 2px solid #3d453b;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.9), inset 0 0 15px rgba(0,0,0,0.8);
    padding: 35px 40px;
    animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

h1.game-title {
    font-size: 32px;
    color: #eaeaea;
    letter-spacing: 4px;
    margin-bottom: 8px;
    text-transform: uppercase;
    text-shadow: 2px 2px 0 #550000, 0 0 15px rgba(255, 50, 50, 0.3);
}

p.subtitle {
    font-size: 14px;
    color: #889988;
    margin-bottom: 24px;
    letter-spacing: 1px;
}

.instructions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    text-align: left;
    margin: 20px 0;
    background: rgba(0, 0, 0, 0.5);
    padding: 16px;
    border: 1px solid #283028;
    font-size: 13px;
    line-height: 1.5;
}

.instructions-grid kbd {
    background: #2a2e2b;
    border: 1px solid #4d574f;
    padding: 2px 6px;
    font-size: 12px;
    color: #fff;
    border-radius: 3px;
    margin-right: 6px;
}

.lore-text {
    font-size: 13px;
    color: #a0a6a0;
    font-style: italic;
    margin: 15px 0 25px 0;
    line-height: 1.4;
}

.btn-retro {
    background: #1d2b20;
    color: #d8f0d8;
    border: 2px solid #3e6044;
    padding: 12px 28px;
    font-size: 16px;
    font-family: inherit;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 0 #0d160f;
}

.btn-retro:hover {
    background: #2c4432;
    border-color: #60986b;
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #0d160f;
}

.btn-retro:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #0d160f;
}

/* Menu de départ : bouton « Play more games » en haut à gauche (vers wiwis.dev) */
.start-more {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top, 0px));
    left: calc(14px + env(safe-area-inset-left, 0px));
    z-index: 1;
    padding: 8px 16px;
    font-size: 13px;
    text-decoration: none;
}

/* Écran Game Over */
#game-over-screen {
    display: none;
    background: rgba(18, 0, 2, 0.94);
}

#game-over-screen h1 {
    color: #c91823;
    text-shadow: 3px 3px 0 #000, 0 0 20px rgba(200, 20, 30, 0.8);
}

/* Leaderboard en haut à droite */
#leaderboard {
    display: none; /* affiché seulement quand un autre joueur est là */
    position: absolute;
    top: 20px;
    right: 20px;
    min-width: 200px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid #283028;
    padding: 8px 12px;
    font-size: 14px;
    text-shadow: 1px 1px 0 #000;
}

#leaderboard .lb-title {
    color: #889988;
    font-size: 12px;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 4px;
}

#leaderboard ol {
    list-style: none;
}

#leaderboard li {
    display: flex;
    gap: 6px;
    padding: 1px 0;
    color: #cfcfcf;
}

#leaderboard li.me {
    color: #ffdd88;
    font-weight: bold;
}

#leaderboard .lb-rank {
    width: 22px;
    color: #777;
}

#leaderboard li.me .lb-rank {
    color: #ffdd88;
}

#leaderboard .lb-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Nombre de notes de chaque joueur */
#leaderboard .lb-notes {
    color: #889988;
}

#leaderboard li.me .lb-notes {
    color: #ffdd88;
}

/* Personnalisation dans le menu de départ */
.custom-panel {
    display: flex;
    gap: 18px;
    align-items: center;
    text-align: left;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #283028;
    padding: 12px 16px;
    margin: 16px 0;
}

.custom-options {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.custom-label {
    font-size: 12px;
    color: #889988;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-top: 4px;
}

#pseudo-input {
    background: #101410;
    border: 2px solid #3e6044;
    color: #fff;
    font-family: inherit;
    font-size: 16px;
    padding: 6px 10px;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
}

#pseudo-input:focus {
    border-color: #60986b;
}

.option-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.face-btn {
    background: #1d2b20;
    color: #d8f0d8;
    border: 2px solid #3e6044;
    padding: 4px 10px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}

.face-btn.selected {
    border-color: #ffdd88;
    color: #ffdd88;
}

@media (max-width: 560px) {
    .custom-panel {
        flex-direction: column;
    }
}

/* Menu d'emotes (Espace) : roue à 4 choix autour du centre de l'écran */
#emote-menu {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: 20;
}

#emote-menu.open {
    display: block;
}

#emote-menu .emote-center {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 92px;
    height: 92px;
    border-radius: 50%;
    border: 1px dashed rgba(255, 234, 121, 0.35);
    background: rgba(0, 0, 0, 0.55);
    color: rgba(255, 234, 121, 0.6);
    font-size: 11px;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#emote-menu .emote-option {
    position: absolute;
    left: calc(var(--x) * 120px);
    top: calc(var(--y) * 105px);
    transform: translate(-50%, -50%);
    min-width: 120px;
    text-align: center;
    font-size: 15px;
    font-weight: bold;
    letter-spacing: 1px;
    color: #d8d0b0;
    text-shadow: 2px 2px 0 #000;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 234, 121, 0.3);
    padding: 8px 12px;
}

#emote-menu .emote-option.selected {
    color: #ffea79;
    border-color: #ffea79;
    background: rgba(60, 50, 10, 0.85);
    box-shadow: 0 0 10px rgba(255, 234, 121, 0.45);
}

#emote-menu .emote-key {
    display: inline-block;
    margin-right: 8px;
    padding: 0 5px;
    border: 1px solid currentColor;
    font-size: 12px;
}

/* Contrôles reconfigurables dans le menu de départ (même style que la personnalisation) */
.controls-panel {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.controls-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
}

.controls-head .custom-label {
    margin-top: 0;
}

.controls-hint {
    font-size: 12px;
    color: #667766;
    font-style: italic;
    margin-top: -4px;
}

.link-btn {
    background: none;
    border: none;
    color: #889988;
    font-family: inherit;
    font-size: 12px;
    letter-spacing: 1px;
    text-decoration: underline dotted;
    cursor: pointer;
    padding: 0;
}

.link-btn:hover {
    color: #ffdd88;
}

.bind-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 24px;
}

.bind-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #d8f0d8;
    padding: 3px 0;
    border-bottom: 1px dashed #283028;
}

.bind-key {
    min-width: 72px;
    background: #1d2b20;
    color: #d8f0d8;
    border: 2px solid #3e6044;
    font-family: inherit;
    font-size: 13px;
    padding: 3px 10px;
    cursor: pointer;
    text-align: center;
}

.bind-key:hover {
    border-color: #60986b;
    color: #fff;
}

.bind-key.listening {
    border-color: #ffdd88;
    color: #ffdd88;
    font-size: 11px;
    animation: bindBlink 0.9s steps(2, start) infinite;
}

@keyframes bindBlink {
    to { opacity: 0.4; }
}

.bind-fixed {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 12px;
    color: #889988;
    padding-top: 4px;
}

.bind-fixed kbd {
    background: #2a2e2b;
    border: 1px solid #4d574f;
    padding: 1px 5px;
    font-size: 11px;
    font-family: inherit;
    color: #fff;
    border-radius: 3px;
    margin-right: 4px;
}

@media (max-width: 560px) {
    .bind-list {
        grid-template-columns: 1fr;
    }
}

/* ===== Fin du jeu ===== */

/* « KILL THE MONSTER ! » au centre de l'écran */
#cine-message {
    position: absolute;
    top: 38%;
    left: 0;
    right: 0;
    z-index: 12;
    pointer-events: none;
    text-align: center;
    font-size: clamp(32px, 7vw, 76px);
    font-weight: bold;
    letter-spacing: 6px;
    color: #ffd24a;
    text-shadow: 3px 3px 0 #000, 0 0 24px rgba(255, 190, 40, 0.9), 0 0 60px rgba(255, 140, 0, 0.6);
    opacity: 0;
}

#cine-message.show {
    animation-name: cine-pop;
    animation-timing-function: ease-out;
    animation-fill-mode: forwards;
}

@keyframes cine-pop {
    0% { opacity: 0; transform: scale(2.2); filter: blur(6px); }
    8% { opacity: 1; transform: scale(1); filter: blur(0); }
    12% { transform: scale(1.06); }
    16% { transform: scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: scale(0.96); }
}

/* Notification sombre tout en haut (ex : un autre joueur trouve une note) */
#top-notice {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -100%);
    z-index: 12;
    pointer-events: none;
    max-width: calc(100% - 32px);
    padding: 8px 18px 9px;
    background: rgba(0, 0, 0, 0.82);
    border: 1px solid #2a2a2a;
    border-top: none;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.8);
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    letter-spacing: 2px;
    color: #b8b0a0;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.9);
    white-space: nowrap;
    overflow: hidden;
    opacity: 0;
    transition: transform 0.25s ease-out, opacity 0.25s ease-out;
}

#top-notice.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

#top-notice.hide {
    transition: opacity 0.8s ease-in;
    transform: translate(-50%, 0);
    opacity: 0;
}

.top-notice-cursor {
    animation: top-notice-blink 0.6s steps(1) infinite;
}

@keyframes top-notice-blink {
    50% { opacity: 0; }
}

/* « YOU WIN » puis « for now... » */
#win-title {
    position: absolute;
    top: 16%;
    left: 0;
    right: 0;
    z-index: 12;
    pointer-events: none;
    text-align: center;
    opacity: 0;
    transition: opacity 2.5s ease;
}

#win-title.show {
    opacity: 1;
}

.win-main {
    font-size: clamp(44px, 10vw, 110px);
    font-weight: bold;
    letter-spacing: 14px;
    color: #fffaf0;
    text-shadow: 4px 4px 0 #000, 0 0 30px rgba(255, 230, 170, 0.85), 0 0 80px rgba(255, 200, 120, 0.5);
}

#win-sub {
    margin-top: 10px;
    font-size: clamp(20px, 3.4vw, 38px);
    font-style: italic;
    letter-spacing: 6px;
    color: #e01e2a;
    text-shadow: 2px 2px 0 #000, 0 0 18px rgba(200, 10, 20, 0.8);
    opacity: 0;
    transition: opacity 3s ease;
}

#win-sub.show {
    opacity: 1;
}

/* Écran noir final, au-dessus de tout */
#fade-black {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: #000;
    opacity: 0;
    pointer-events: none;
}

/* La vignette s'éclaircit à l'aube et se referme quand la nuit retombe */
.vignette {
    transition: opacity 4s ease;
}

/* Multijoueur : état de la connexion dans le menu, réapparition */
.net-status {
    margin: 4px 0 14px;
    font-size: 12px;
    color: #667766;
    letter-spacing: 1px;
    line-height: 1.5;
}

.net-status.online {
    color: #9fd29f;
}

.respawn-text {
    display: none;
    margin: 18px 0 4px;
    font-size: 16px;
    color: #d8d2c4;
    letter-spacing: 2px;
    animation: respawn-blink 1s steps(2) infinite;
}

@keyframes respawn-blink {
    50% { opacity: 0.45; }
}

/* Confirmation avant de retourner au menu (Échap) */
#quit-confirm {
    display: none;
    z-index: 60;
    background: rgba(5, 7, 6, 0.75);
}

.quit-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Réglages du menu : souris, volume, luminosité */
.settings-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 24px;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #d8f0d8;
    padding: 3px 0;
    border-bottom: 1px dashed #283028;
    cursor: pointer;
}

.setting-name {
    flex: 1;
    white-space: nowrap;
}

.setting-row input[type="range"] {
    width: 90px;
    accent-color: #60986b;
    cursor: pointer;
}

.setting-row input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: #60986b;
    cursor: pointer;
}

.setting-value {
    min-width: 42px;
    text-align: right;
    font-size: 12px;
    color: #889988;
}

/* Menu pause : sensibilité et luminosité, sur une colonne */
.pause-settings {
    grid-template-columns: 1fr;
    max-width: 360px;
    margin: 0 auto 18px;
    text-align: left;
}

@media (max-width: 560px) {
    .settings-list {
        grid-template-columns: 1fr;
    }
}

/* Résumé de la nuit : stats de tous les joueurs après la fin */
#summary-screen {
    display: none;
    z-index: 40;
    background: rgba(2, 3, 3, 0.96);
}

.summary-box {
    max-width: 820px;
    width: calc(100% - 32px);
}

.summary-scroll {
    overflow-x: auto;
    margin: 4px 0 18px;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.summary-table th {
    font-size: 11px;
    font-weight: normal;
    color: #889988;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 6px 8px;
    border-bottom: 1px solid #3d453b;
    text-align: right;
}

.summary-table td {
    padding: 7px 8px;
    color: #d8d2c4;
    border-bottom: 1px dashed #283028;
    text-align: right;
}

.summary-table th:first-child,
.summary-table td:first-child {
    text-align: left;
}

.summary-table tr.me td {
    color: #ffdd88;
}

.summary-table tr.winner td:first-child::before {
    content: '\2605  ';
    color: #ffdd88;
}

.summary-table .zero {
    color: #556055;
}

.summary-awards {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 18px;
    text-align: left;
    margin: 0 0 24px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #283028;
    padding: 12px 16px;
}

.summary-awards:empty {
    display: none;
}

.summary-awards li {
    font-size: 12px;
    color: #a0a6a0;
    line-height: 1.4;
    opacity: 0;
    animation: awardIn 0.5s ease-out forwards;
}

.summary-awards .award-title {
    display: block;
    color: #c91823;
    letter-spacing: 2px;
    font-size: 11px;
    text-shadow: 1px 1px 0 #000;
}

.summary-awards .award-name {
    color: #eaeaea;
}

@keyframes awardIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 560px) {
    .summary-awards {
        grid-template-columns: 1fr;
    }
}

/* ===== Smartphone / tablette : contrôles tactiles, jeu en paysage ===== */

/* Marges de sécurité : encoche, coins arrondis, barre d'accueil */
:root {
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
}

/* Textes du menu propres au tactile ou au clavier */
body.touch .desk-only {
    display: none !important;
}

body:not(.touch) .touch-only {
    display: none !important;
}

/* Pas de zoom au doigt (pincer, double toucher) ; les menus défilent normalement */
body.touch {
    touch-action: pan-x pan-y;
}

/* Couche tactile : tout l'écran (sous les textes du HUD qui laissent passer les doigts) */
#touch-controls {
    display: none;
    position: absolute;
    inset: 0;
    pointer-events: auto;
    touch-action: none;
}

body.touch #touch-controls {
    display: block;
}

/* Joystick : repère au repos en bas à gauche ; il se place sous le pouce dès qu'on
   touche la moitié gauche de l'écran */
#touch-stick {
    position: absolute;
    left: calc(108px + var(--sal));
    top: calc(100% - 104px - var(--sab));
    width: 124px;
    height: 124px;
    margin: -62px 0 0 -62px;
    border-radius: 50%;
    border: 2px solid rgba(216, 240, 216, 0.22);
    background: radial-gradient(circle, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.45) 100%);
    box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.6);
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.2s, border-color 0.15s, box-shadow 0.15s;
}

#touch-stick.active {
    opacity: 1;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#touch-stick.running {
    border-color: rgba(255, 221, 136, 0.75);
    box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.6), 0 0 14px rgba(255, 221, 136, 0.35);
}

.touch-stick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 52px;
    height: 52px;
    margin: -26px 0 0 -26px;
    border-radius: 50%;
    background: rgba(216, 240, 216, 0.28);
    border: 2px solid rgba(216, 240, 216, 0.5);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
}

#touch-stick.running .touch-stick-knob {
    background: rgba(255, 221, 136, 0.35);
    border-color: rgba(255, 221, 136, 0.85);
}

/* Au-dessus du bouton même poussé tout en haut (il dépasse du cercle) */
.touch-stick-run {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 26px);
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 3px;
    color: #ffdd88;
    text-shadow: 1px 1px 0 #000;
    opacity: 0;
    transition: opacity 0.15s;
}

#touch-stick.running .touch-stick-run {
    opacity: 1;
}

/* Boutons ronds, style rétro du HUD (zone de toucher un peu plus grande que le dessin) */
.touch-btn {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(216, 240, 216, 0.3);
    color: rgba(216, 240, 216, 0.75);
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 1px;
    text-shadow: 1px 1px 0 #000;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
    transition: transform 0.08s, background-color 0.15s;
}

.touch-btn::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: inherit;
}

.touch-btn.pressed {
    transform: scale(0.9);
    background: rgba(60, 70, 60, 0.6);
}

.touch-btn.on {
    color: #ffdd88;
    border-color: rgba(255, 221, 136, 0.6);
}

/* Pouce droit : la lampe (le plus utilisé) dans le coin, les autres en arc autour */
.touch-btn-light {
    right: calc(28px + var(--sar));
    bottom: calc(30px + var(--sab));
    width: 76px;
    height: 76px;
    font-size: 13px;
}

.touch-btn-emote {
    right: calc(132px + var(--sar));
    bottom: calc(26px + var(--sab));
}

/* En haut à droite : plein écran (quand on en est sorti) et menu */
.touch-btn-menu,
.touch-btn-full {
    top: calc(10px + var(--sat));
    width: 42px;
    height: 42px;
    border-radius: 4px;
}

.touch-btn-menu {
    right: calc(12px + var(--sar));
    font-size: 14px;
    letter-spacing: 2px;
}

.touch-btn-full {
    display: none;
    right: calc(62px + var(--sar));
}

body.fs-off .touch-btn-full {
    display: flex;
}

/* HUD en mode tactile : les infos en haut, le bas de l'écran est pour les pouces */
body.touch .note-counter {
    top: calc(12px + var(--sat));
    left: calc(16px + var(--sal));
    font-size: 16px;
    letter-spacing: 1px;
}

body.touch .bottom-hud {
    top: calc(38px + var(--sat));
    bottom: auto;
    left: calc(16px + var(--sal));
}

/* La lampe est affichée par son bouton */
body.touch .bottom-hud .hud-item:first-child {
    display: none;
}

body.touch .hud-item {
    font-size: 10px;
    gap: 8px;
}

body.touch .stamina-track {
    width: 112px;
    height: 7px;
}

/* BPM à gauche des boutons du haut, à la même hauteur */
body.touch #heart-rate {
    top: calc(10px + var(--sat));
    bottom: auto;
    right: calc(66px + var(--sar));
    height: 42px;
    font-size: 13px;
}

body.touch.fs-off #heart-rate {
    right: calc(116px + var(--sar));
}

/* Classement (multijoueur) sous le compteur de notes */
body.touch #leaderboard {
    top: calc(60px + var(--sat));
    left: calc(16px + var(--sal));
    right: auto;
    min-width: 0;
    width: 160px;
    padding: 6px 8px;
    font-size: 11px;
}

body.touch #leaderboard .lb-title {
    font-size: 9px;
}

body.touch #leaderboard .lb-rank {
    width: 16px;
}

/* Note devant soi : invite qui pulse, on touche l'écran pour la prendre */
body.touch #interaction-prompt {
    top: 64%;
    font-size: 14px;
    padding: 9px 18px;
    white-space: nowrap;
    animation: prompt-pulse 1.1s ease-in-out infinite;
}

@keyframes prompt-pulse {
    50% { box-shadow: 0 0 14px rgba(255, 234, 121, 0.45); }
}

/* Roue d'emotes plus large que haute : on touche un choix, ailleurs pour fermer */
body.touch #emote-menu .emote-option {
    left: calc(var(--x) * 116px);
    top: calc(var(--y) * 78px);
    min-width: 108px;
    font-size: 13px;
    white-space: nowrap;
    padding: 11px 12px;
}

body.touch #emote-menu .emote-key {
    display: none;
}

body.touch #emote-menu .emote-center {
    width: 72px;
    height: 72px;
    font-size: 10px;
}

/* Notification du haut : entre le compteur de notes et le BPM */
body.touch #top-notice {
    max-width: calc(100% - 300px - var(--sal) - var(--sar));
    font-size: 12px;
    letter-spacing: 1px;
    padding: 7px 14px 8px;
}

/* Aide des contrôles tactiles dans le menu */
.touch-help {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    font-size: 12px;
    color: #d8f0d8;
}

/* Une ligne : la touche, puis l'explication (qui revient à la ligne sous elle-même) */
.touch-help span {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: baseline;
    column-gap: 8px;
}

.touch-help kbd {
    display: inline-block;
    min-width: 92px;
    background: #2a2e2b;
    border: 1px solid #4d574f;
    padding: 1px 5px;
    font-size: 11px;
    font-family: inherit;
    color: #fff;
    border-radius: 3px;
    text-align: center;
}

/* iPhone dans Safari : pas de plein écran, sauf depuis l'écran d'accueil */
.touch-tip {
    display: none;
    margin-top: 2px;
    font-size: 11px;
    font-style: italic;
    line-height: 1.4;
    color: #889988;
}

body.ios-tip .touch-tip {
    display: block;
}

/* Réglages : curseurs faciles à attraper au doigt */
body.touch .setting-row {
    padding: 6px 0;
}

body.touch .setting-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

body.touch .setting-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 0 1 120px;
    min-width: 70px;
    height: 28px;
    margin: 0;
    background: transparent;
    touch-action: pan-y;
}

body.touch .setting-row input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: #3e6044;
}

body.touch .setting-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    margin-top: -9px;
    border-radius: 50%;
    background: #d8f0d8;
    border: 2px solid #60986b;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
}

body.touch .setting-row input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: #3e6044;
}

body.touch .setting-row input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #d8f0d8;
    border: 2px solid #60986b;
}

body.touch .setting-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
}

body.touch .face-btn {
    padding: 8px 12px;
}

/* Pas d'effet de survol collé après un toucher ; bouton enfoncé pendant le toucher */
body.touch .btn-retro:hover {
    background: #1d2b20;
    border-color: #3e6044;
    color: #d8f0d8;
    transform: none;
    box-shadow: 0 4px 0 #0d160f;
}

body.touch .btn-retro:active {
    background: #2c4432;
    transform: translateY(2px);
    box-shadow: 0 1px 0 #0d160f;
}

/* Téléphone tenu en portrait : écran « tournez le téléphone », au-dessus de tout */
#rotate-screen {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: calc(24px + var(--sat)) calc(28px + var(--sar)) calc(24px + var(--sab)) calc(28px + var(--sal));
    background: radial-gradient(ellipse at center, #0e140f 0%, #030403 78%);
    text-align: center;
    touch-action: none;
}

/* Même règle que js/touch.js : écran tactile en portrait, moins de 600 px de large (téléphone) */
@media (orientation: portrait) and (max-width: 599px) {
    body.touch #rotate-screen {
        display: flex;
    }
}

/* Téléphone dessiné qui se couche ; ce qu'il affiche (deux yeux rouges) reste droit */
.rotate-phone {
    position: relative;
    width: 46px;
    height: 80px;
    margin-bottom: 18px;
    border: 3px solid #d8f0d8;
    border-radius: 9px;
    box-shadow: 0 0 22px rgba(216, 240, 216, 0.12);
    animation: rotate-phone 2.6s ease-in-out infinite;
}

.rotate-phone::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    width: 12px;
    height: 3px;
    margin-left: -6px;
    border-radius: 2px;
    background: #d8f0d8;
}

.rotate-phone::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 4px;
    margin: -2px 0 0 -7px;
    background:
        radial-gradient(circle at 2px 2px, #ff3030 0 2px, transparent 2.5px),
        radial-gradient(circle at 12px 2px, #ff3030 0 2px, transparent 2.5px);
    filter: drop-shadow(0 0 3px #ff2020);
    animation: rotate-eyes 2.6s ease-in-out infinite;
}

@keyframes rotate-phone {
    0%, 15% { transform: rotate(0deg); }
    40%, 80% { transform: rotate(-90deg); }
    100% { transform: rotate(0deg); }
}

@keyframes rotate-eyes {
    0%, 15% { transform: rotate(0deg); }
    40%, 80% { transform: rotate(90deg); }
    100% { transform: rotate(0deg); }
}

.rotate-title {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: #eaeaea;
    text-shadow: 2px 2px 0 #550000, 0 0 15px rgba(255, 50, 50, 0.3);
}

.rotate-text {
    font-size: 13px;
    font-style: italic;
    color: #a0a6a0;
}

/* Android : le bouton passe en plein écran et couche l'écran tout seul */
#rotate-btn {
    display: none;
    margin-top: 10px;
}

body.can-lock #rotate-btn {
    display: inline-block;
}

.rotate-hint {
    margin-top: 6px;
    font-size: 11px;
    letter-spacing: 1px;
    line-height: 1.5;
    color: #667766;
}

/* Fenêtres étroites (ordinateur) : menus plus compacts */
@media (max-width: 560px) {
    .screen-overlay {
        padding: calc(10px + var(--sat)) calc(10px + var(--sar)) calc(10px + var(--sab)) calc(10px + var(--sal));
    }

    .screen-box {
        width: 100%;
        padding: 22px 16px;
    }

    h1.game-title {
        font-size: 25px;
        letter-spacing: 3px;
    }

    p.subtitle {
        font-size: 12px;
        margin-bottom: 14px;
    }

    .lore-text {
        margin: 10px 0 14px;
    }

    .custom-panel {
        gap: 10px;
        padding: 10px 12px;
        margin: 10px 0;
    }

    .summary-box {
        width: 100%;
    }

    .quit-buttons .btn-retro {
        width: 100%;
    }

    #top-notice {
        font-size: 12px;
        letter-spacing: 1px;
        padding: 7px 12px 8px;
    }

    #cine-message {
        font-size: 26px;
        letter-spacing: 3px;
        padding: 0 12px;
    }

    .win-main {
        font-size: 44px;
        letter-spacing: 8px;
    }

    #win-sub {
        font-size: 20px;
        letter-spacing: 4px;
    }
}

/* Le menu de départ garde une seule colonne ailleurs que sur un téléphone en paysage */
.menu-side {
    display: contents;
}

/* ===== Téléphone en paysage : menus sur toute la hauteur, sans rien à chercher ===== */
@media (orientation: landscape) and (max-height: 500px) {
    body.touch .screen-overlay {
        padding: calc(8px + var(--sat)) calc(10px + var(--sar)) calc(8px + var(--sab)) calc(10px + var(--sal));
    }

    body.touch .screen-box {
        padding: 18px 28px;
    }

    body.touch h1.game-title {
        font-size: 24px;
        letter-spacing: 3px;
        margin-bottom: 4px;
    }

    body.touch p.subtitle {
        font-size: 11px;
        margin-bottom: 10px;
    }

    body.touch .lore-text {
        font-size: 12px;
        margin: 8px 0 14px;
    }

    body.touch .btn-retro {
        padding: 11px 24px;
        font-size: 15px;
    }

    /* Menu de départ en deux colonnes : à gauche le titre, l'histoire et le bouton
       (toujours visible), à droite le profil, les contrôles et les réglages (qui défilent) */
    body.touch .start-box {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
        grid-template-rows: auto auto minmax(0, 1fr) auto auto;
        grid-template-areas:
            "title side"
            "sub   side"
            "lore  side"
            "net   side"
            "start side";
        column-gap: 22px;
        width: 100%;
        max-width: 980px;
        height: 100%;
        overflow: hidden;
        padding: 16px 14px 16px 22px;
    }

    body.touch .start-box > .game-title {
        grid-area: title;
    }

    body.touch .start-box > .subtitle {
        grid-area: sub;
        margin-bottom: 0;
    }

    /* L'histoire occupe la place libre (centrée), et défile si l'écran est vraiment petit */
    body.touch .start-box > .lore-text {
        grid-area: lore;
        align-self: center;
        max-height: 100%;
        overflow-y: auto;
        margin: 10px 0;
    }

    body.touch .start-box > .net-status {
        grid-area: net;
        margin: 0 0 8px;
        font-size: 11px;
    }

    body.touch .start-box > #start-btn {
        grid-area: start;
        width: 100%;
    }

    body.touch .start-box .menu-side {
        display: block;
        grid-area: side;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding-right: 6px;
        scrollbar-width: thin;
        scrollbar-color: #3d453b transparent;
    }

    body.touch .menu-side .custom-panel {
        margin: 0 0 8px;
        padding: 10px 12px;
    }

    body.touch .menu-side .custom-panel:last-child {
        margin-bottom: 0;
    }

    /* Profil : pseudo sur une ligne, les 4 humeurs sur une autre */
    body.touch .menu-side .custom-options {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        gap: 8px 12px;
    }

    body.touch .menu-side .custom-options .custom-label {
        margin: 0;
    }

    body.touch .menu-side .custom-options div.custom-label,
    body.touch .menu-side #face-list {
        grid-column: 1 / -1;
    }

    body.touch #pseudo-input {
        min-width: 0;
        width: 100%;
    }

    body.touch #face-list {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    body.touch #face-list .face-btn {
        min-width: 0;
        padding: 8px 2px;
        font-size: 11px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.touch .touch-help {
        gap: 5px;
        font-size: 11px;
    }

    body.touch .touch-help kbd {
        min-width: 86px;
    }

    body.touch .menu-side .settings-list {
        grid-template-columns: 1fr;
    }

    /* Mort, retour au menu : boîtes plus basses */
    body.touch #game-over-screen .lore-text {
        margin: 8px 0;
    }

    body.touch .respawn-text {
        margin: 10px 0 2px;
    }

    body.touch .quit-buttons .btn-retro {
        width: auto;
    }

    /* Résumé de fin : sur toute la largeur, le bouton reste visible en bas */
    body.touch .summary-box {
        width: 100%;
        max-width: 920px;
        padding: 14px 18px 0;
    }

    body.touch .summary-box .subtitle {
        margin-bottom: 8px;
    }

    body.touch .summary-scroll {
        margin: 0 0 10px;
    }

    body.touch .summary-table {
        font-size: 12px;
    }

    body.touch .summary-table th {
        font-size: 10px;
        padding: 4px 6px;
    }

    body.touch .summary-table td {
        padding: 5px 6px;
    }

    body.touch .summary-awards {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px 14px;
        padding: 10px 12px;
        margin-bottom: 10px;
    }

    /* Le bouton reste en bas, sur une bande de la couleur de la boîte : ce qui défile
       passe dessous proprement */
    body.touch #summary-btn,
    body.touch #summary-btn:hover {
        position: sticky;
        bottom: 10px;
        width: 100%;
        margin-bottom: 10px;
        box-shadow: 0 4px 0 #0d160f, 0 0 0 10px #0b0d0b;
    }

    body.touch #summary-btn:active {
        box-shadow: 0 1px 0 #0d160f, 0 0 0 10px #0b0d0b;
    }

    /* Textes de la fin du jeu à la taille d'un écran bas ; « PSEUDO WINS » (pseudo de
       14 lettres compris) tient sur une ligne */
    body.touch #cine-message {
        top: 32%;
        font-size: clamp(22px, 4.4vw, 36px);
        letter-spacing: 0.12em;
        padding: 0 calc(20px + var(--sar)) 0 calc(20px + var(--sal));
    }

    body.touch #win-title {
        top: 20%;
        padding: 0 calc(12px + var(--sar)) 0 calc(12px + var(--sal));
    }

    body.touch .win-main {
        font-size: clamp(26px, 6vw, 60px);
        letter-spacing: 0.16em;
    }

    body.touch #win-sub {
        margin-top: 4px;
        font-size: clamp(16px, 3vw, 26px);
        letter-spacing: 0.2em;
    }

    /* Pendant « X WINS » le classement s'efface (il passerait sous le titre) */
    body.touch #leaderboard {
        transition: opacity 0.6s;
    }

    body.touch #game-container:has(#win-title.show) #leaderboard {
        opacity: 0;
    }
}

/* Téléphones étroits en paysage (iPhone SE 1re génération, petits Android) */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 640px) {
    body.touch .start-box {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        column-gap: 14px;
        padding: 12px 10px 12px 14px;
    }

    body.touch .start-box > .game-title {
        font-size: 20px;
        letter-spacing: 2px;
    }

    body.touch .start-box > .subtitle,
    body.touch .start-box > .net-status {
        font-size: 10px;
        letter-spacing: 0;
    }

    body.touch .start-box > .lore-text {
        font-size: 11px;
    }

    body.touch .start-box > #start-btn {
        padding: 10px 8px;
        font-size: 13px;
        letter-spacing: 1px;
    }

    body.touch .menu-side .custom-panel {
        padding: 8px 10px;
    }

    body.touch .menu-side .custom-options {
        column-gap: 8px;
    }

    body.touch #face-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.touch .touch-help {
        font-size: 10px;
    }

    body.touch .touch-help kbd {
        min-width: 70px;
        font-size: 10px;
    }
}

/* Très petits téléphones en paysage (ou barre du navigateur affichée) : commandes plus serrées */
@media (orientation: landscape) and (max-height: 340px) {
    body.touch #touch-stick {
        left: calc(96px + var(--sal));
        top: calc(100% - 92px - var(--sab));
        width: 112px;
        height: 112px;
        margin: -56px 0 0 -56px;
    }

    body.touch .touch-btn-light {
        right: calc(24px + var(--sar));
        bottom: calc(24px + var(--sab));
        width: 68px;
        height: 68px;
    }

    body.touch .touch-btn-emote {
        right: calc(116px + var(--sar));
        bottom: calc(20px + var(--sab));
        width: 50px;
        height: 50px;
    }

    body.touch #leaderboard {
        top: calc(56px + var(--sat));
    }

    body.touch .lore-text {
        font-size: 11px;
    }
}

/* Tactile : bouton « Play more games » du menu de départ plus petit (ne cache pas le menu) */
body.touch .btn-retro.start-more {
    top: calc(8px + var(--sat));
    left: calc(10px + var(--sal));
    padding: 7px 12px;
    font-size: 11px;
    letter-spacing: 1px;
}

/* Fenêtre pas assez large pour que le bouton tienne à côté du menu : le menu descend sous le bouton */
@media (max-width: 1040px) {
    #start-screen {
        padding-top: calc(62px + var(--sat));
    }
}

/* Téléphone en paysage : le menu garde toute la hauteur, seul le titre (colonne de gauche) descend */
@media (orientation: landscape) and (max-height: 500px) {
    body.touch #start-screen {
        padding-top: calc(8px + var(--sat));
    }

    body.touch .start-box > .game-title {
        margin-top: 28px;
    }
}
