/* =================================================================
   SNAKOS — feuille de style
   Identité visuelle : arcade rétro / HUD militaire, inspirée du
   cobra au fusil de la pochette du jeu (grille sarcelle, dorures
   venin, rouge sang, coins chanfreinés façon viseur).
   Organisée par sections : reset, variables (jour/nuit), layout,
   composants, responsive (tablette / mobile paysage / portrait).
   ================================================================= */

/* ---------- Reset ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

input, select, button {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

html, body {
    height: 100dvh;
    overflow: hidden;
    touch-action: manipulation;
    position: fixed;
    width: 100%;
}

/* ---------- Variables : thème "Jour" (grille sarcelle claire) ---------- */
:root {
    /* Typographie : une tête d'affiche pixel-art (avec parcimonie),
       une police "stencil" technique pour l'interface, une police
       mono pour les chiffres façon compteur digital. */
    --font-display: 'Press Start 2P', 'Poetsen One', cursive;
    --font-body: 'Chakra Petch', 'Nunito', sans-serif;
    --font-mono: 'Share Tech Mono', 'Chakra Petch', monospace;

    /* Palette */
    --bg-base: #cfe6e2;
    --bg-grid: rgba(11, 61, 68, 0.12);
    --bg-vignette: rgba(6, 30, 34, 0.22);

    --ink: #10262c;
    --ink-soft: #3d5a5f;
    --paper: #f4f0df;
    --paper-strong: #fffdf4;

    --border: #10262c;
    --gold: #b9790f;
    --gold-bright: #e8a627;
    --red: #b8202f;
    --red-bright: #d7364a;
    --teal-accent: #0f6b74;
    --teal-glow: #2a9d8f;

    --shadow-col: rgba(12, 30, 35, 0.4);
    --shadow-sm: 0 2px 0 var(--shadow-col);
    --shadow-md: 0 6px 16px rgba(10, 25, 30, 0.28);
    --shadow-lg: 0 18px 44px rgba(8, 20, 24, 0.4);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --chamfer: 12px;
    --chamfer-sm: 7px;

    /* Géométrie de la zone de jeu — recalculée par les media queries
       ci-dessous ; le canvas se dimensionne à partir de ces variables
       (voir #gameCanvas) pour ne jamais déborder de l'écran. */
    --container-pad: 22px;
    --gap: clamp(16px, 2.6vw, 40px);
    --panel-w: 200px;
    --chrome-h: 84px;
    --canvas-max: 660px;
}

/* ---------- Thème "Nuit" (ink profond, glow néon) ---------- */
.dark-theme {
    --bg-base: #071417;
    --bg-grid: rgba(255, 255, 255, 0.05);
    --bg-vignette: rgba(0, 0, 0, 0.55);

    --ink: #eef1e6;
    --ink-soft: #9db3b4;
    --paper: #112a2f;
    --paper-strong: #163841;

    --border: #e8a627;
    --gold: #e8a627;
    --gold-bright: #ffce5c;
    --red: #ff5464;
    --red-bright: #ff7a86;
    --teal-accent: #37c2c8;
    --teal-glow: #37c2c8;

    --shadow-col: rgba(0, 0, 0, 0.7);
    --shadow-sm: 0 2px 0 var(--shadow-col);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.65);
}

/* ---------- Accessibilité ---------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible,
canvas:focus-visible {
    outline: 3px solid var(--teal-glow);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

.hidden {
    display: none !important;
}

/* ---------- Fond & conteneur principal ---------- */
body {
    font-family: var(--font-body);
    background-color: var(--bg-base);
    background-image:
        linear-gradient(var(--bg-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
        radial-gradient(ellipse at center, transparent 45%, var(--bg-vignette) 145%);
    background-size: 42px 42px, 42px 42px, 100% 100%;
    animation: gridDrift 50s linear infinite;
    height: 100dvh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--ink-soft);
    padding: 10px;
    transition: background-color 0.35s ease;
}

@keyframes gridDrift {
    0% { background-position: 0 0, 0 0, 0 0; }
    100% { background-position: 420px 0, 0 420px, 0 0; }
}

#gameContainer {
    background: var(--paper);
    border-radius: var(--radius-lg);
    padding: var(--container-pad);
    box-shadow: var(--shadow-lg), 0 0 0 2px var(--border);
    text-align: center;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background 0.35s ease, border-color 0.35s ease;
}

/* Bouton retour vers le portail de jeux */
.back-btn {
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1010;
    line-height: 0;
}

.back-btn img {
    width: 60px;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
    transition: transform 0.2s ease;
}

.back-btn img:hover {
    transform: scale(1.08) rotate(-3deg);
}

.back-btn img:active {
    transform: scale(0.95);
}

/* ---------- En-tête ---------- */
#gameHeader {
    margin-bottom: 8px;
    text-align: center;
    flex: 0 0 auto;
}

#gameHeader h1 {
    font-family: var(--font-display);
    font-size: clamp(0.85em, 1.9vw, 1.5em);
    letter-spacing: 0.04em;
    color: var(--red);
    text-shadow: 2px 2px 0 var(--border), 4px 4px 0 var(--shadow-col);
    text-transform: uppercase;
}

/* ---------- Zone de jeu : panneau gauche / canvas / panneau droit ---------- */
#gamePlayArea {
    position: relative;
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 0;
    min-width: 0;
    gap: var(--gap);
}

#leftPanel, #rightPanel {
    flex: 0 0 var(--panel-w);
    width: var(--panel-w);
    max-width: var(--panel-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--gold) transparent;
}

#leftPanel::-webkit-scrollbar, #rightPanel::-webkit-scrollbar, #achievementsList::-webkit-scrollbar {
    width: 6px;
}

#leftPanel::-webkit-scrollbar-thumb, #rightPanel::-webkit-scrollbar-thumb, #achievementsList::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 4px;
}

#leftPanel {
    align-items: stretch;
    text-align: right;
}

#rightPanel {
    align-items: stretch;
    text-align: left;
}

/* Conteneur du canvas : occupe l'espace restant, centre le canvas.
   Le canvas fait partie du flux flex normal, ce qui empêche tout
   chevauchement avec les panneaux latéraux. */
#canvasContainer {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Taille du canvas : la plus petite des trois contraintes suivantes,
   recalculée uniquement via les variables --panel-w/--gap/--chrome-h/
   --canvas-max définies par les media queries. Une seule règle pour
   tous les formats d'écran = pas de divergence possible avec le JS. */
#gameCanvas {
    display: block;
    aspect-ratio: 1 / 1;
    width: min(
        calc(100vw - (var(--panel-w) * 2) - (var(--gap) * 2) - (var(--container-pad) * 2)),
        calc(100dvh - var(--chrome-h) - (var(--container-pad) * 2)),
        var(--canvas-max)
    );
    height: auto;
    border: 4px solid var(--border);
    border-radius: var(--radius-sm);
    background: #afd971;
    /* Double liseré façon bezel d'écran d'arcade */
    box-shadow:
        0 0 0 3px var(--gold),
        0 0 0 6px var(--border),
        var(--shadow-lg);
    margin: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.35s ease;
    touch-action: none;
}

#gameCanvas:hover {
    transform: translateY(-2px);
}

.dark-theme #gameCanvas {
    box-shadow:
        0 0 0 3px var(--gold),
        0 0 0 6px var(--border),
        0 0 30px rgba(232, 166, 39, 0.25),
        var(--shadow-lg);
}

/* ---------- Puces de score / kills / niveau / combo ---------- */
#scoresContainer {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

#scoreDisplay, #killsDisplay, #levelDisplay, #comboDisplay {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-family: var(--font-mono);
    font-size: 1.05em;
    font-weight: 700;
    color: var(--ink);
    padding: 6px 12px;
    background: var(--paper-strong);
    border: 2px solid var(--border);
    clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 9px, 100% 100%, 0 100%);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

.dark-theme #scoreDisplay,
.dark-theme #killsDisplay,
.dark-theme #levelDisplay,
.dark-theme #comboDisplay {
    color: var(--gold-bright);
    text-shadow: 0 0 8px rgba(232, 166, 39, 0.5);
}

#scoreIcon, #killsIcon {
    width: 20px;
    height: 20px;
    image-rendering: pixelated;
}

#comboDisplay {
    color: var(--red);
    background: var(--paper-strong);
    border-color: var(--red);
    animation: comboPulse 0.6s ease-in-out infinite;
    align-self: flex-end;
}

.dark-theme #comboDisplay {
    color: var(--red-bright);
    text-shadow: 0 0 8px rgba(255, 84, 100, 0.55);
}

@keyframes comboPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

/* ---------- Panneaux d'info (contrôles / réglages) ---------- */
#controlsInfo, #gameSettings {
    padding: 12px 14px;
    background: var(--paper-strong);
    border: 2px solid var(--border);
    clip-path: polygon(0 0, calc(100% - var(--chamfer)) 0, 100% var(--chamfer), 100% 100%, 0 100%);
}

#controlsInfo {
    text-align: right;
}

#controlsInfo h3 {
    font-family: var(--font-display);
    color: var(--teal-accent);
    margin-bottom: 8px;
    font-size: 0.6em;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

#controlsInfo p {
    font-family: var(--font-body);
    font-weight: 600;
    margin: 3px 0;
    font-size: 0.85em;
    color: var(--ink-soft);
    line-height: 1.35;
}

#gameSettings {
    flex: 1;
    text-align: left;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting {
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.setting label {
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.85em;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--ink);
}

select, input[type="range"] {
    font-family: var(--font-body);
    font-weight: 600;
    padding: 5px 9px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    background: var(--paper);
    color: var(--ink);
    min-width: 0; /* autorise le rétrécissement dans .setting (flex row) sur les très petits écrans */
}

.setting > * {
    min-width: 0; /* idem pour le label : évite tout débordement du panneau sur les plus petites largeurs */
}

select:disabled {
    background-color: rgba(120, 120, 120, 0.15);
    color: #8a8a8a;
    border-color: #8a8a8a;
    cursor: not-allowed;
    opacity: 0.7;
}

input[type="range"] {
    width: 100px;
    height: 20px;
    accent-color: var(--gold-bright);
}

/* ---------- Icônes vectorielles (remplacent les émoticônes, voir js/icons.js) ---------- */
.icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    flex-shrink: 0;
    color: currentColor;
}

/* Espacement quand une icône précède du texte dans un flux normal (bouton,
   titre, paragraphe) — inutile dans les conteneurs flex qui gèrent déjà
   l'espacement via `gap` (ex. #comboDisplay, .achievement-toast). */
.icon-inline {
    margin-right: 0.4em;
}

/* ---------- Boutons : bevel "pixel" avec ombre franche, sans dégradé ---------- */
button {
    background: var(--paper-strong);
    color: var(--ink);
    border: 2px solid var(--border);
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    cursor: pointer;
    margin: 3px;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
    box-shadow: 3px 3px 0 var(--border);
    font-size: 0.85em;
}

button:hover:not(:disabled) {
    background: var(--gold-bright);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 var(--border);
}

button:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--border);
}

button:disabled {
    background: rgba(120, 120, 120, 0.25);
    color: #8a8a8a;
    border-color: #8a8a8a;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#themeToggle {
    min-width: 120px;
}

#achievementsBtn {
    background: var(--gold-bright);
    color: var(--ink);
}

#achievementsBtn:hover:not(:disabled) {
    background: var(--gold);
}

#playAgain {
    background: var(--teal-glow);
    color: var(--ink);
}

#playAgain:hover:not(:disabled) {
    background: var(--gold-bright);
}

@media (pointer: coarse) {
    button {
        min-height: 44px;
    }
}

/* ---------- Écran de fin de partie ---------- */
#gameOverScreen, #achievementsScreen {
    position: fixed;
    inset: 0;
    background: rgba(4, 12, 14, 0.78);
    backdrop-filter: blur(2px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 16px;
}

#gameOverContent, #achievementsContent {
    background: var(--paper);
    padding: clamp(20px, 4vw, 40px);
    border: 3px solid var(--border);
    box-shadow: var(--shadow-lg), 0 0 0 3px var(--gold);
    text-align: center;
    width: min(92vw, 480px);
    max-height: 88dvh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.dark-theme #gameOverContent,
.dark-theme #achievementsContent {
    background: var(--paper-strong);
}

#gameOverContent h2 {
    font-family: var(--font-display);
    color: var(--red);
    font-size: clamp(1em, 3.4vw, 1.5em);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-shadow: 2px 2px 0 var(--border);
    margin-bottom: 18px;
}

#gameOverContent p {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 1.05em;
    margin: 8px 0;
    color: var(--ink-soft);
}

#gameOverContent p span {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--ink);
}

.dark-theme #gameOverContent p span {
    color: var(--gold-bright);
}

#gameStats {
    margin: 10px 0;
    padding: 12px;
    background: var(--paper-strong);
    border: 2px solid var(--border);
}

#newBestScoreBanner {
    font-family: var(--font-body);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.95em;
    color: var(--ink);
    background: var(--gold-bright);
    border: 2px solid var(--border);
    padding: 8px 12px;
    animation: bestScorePulse 1.4s ease-in-out infinite;
}

@keyframes bestScorePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

#playAgain {
    align-self: center;
    margin-top: 10px;
    padding: 11px 26px;
    font-size: 1em;
}

/* ---------- Panneau des succès ---------- */
#achievementsContent h2 {
    font-family: var(--font-display);
    color: var(--gold);
    font-size: clamp(0.85em, 3vw, 1.1em);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-shadow: 2px 2px 0 var(--border);
    margin-bottom: 18px;
}

.dark-theme #achievementsContent h2 {
    color: var(--gold-bright);
}

#achievementsList {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding-right: 4px;
    margin-bottom: 15px;
}

.achievement-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 2px solid var(--border);
    clip-path: polygon(0 0, calc(100% - var(--chamfer-sm)) 0, 100% var(--chamfer-sm), 100% 100%, 0 100%);
    text-align: left;
    font-family: var(--font-body);
}

.achievement-card.unlocked {
    background: rgba(232, 166, 39, 0.16);
    border-color: var(--gold);
}

.achievement-card.locked {
    background: rgba(120, 120, 120, 0.08);
    border-color: #8a8a8a;
    opacity: 0.65;
}

.achievement-card-icon {
    font-size: 1.8em;
    flex: 0 0 auto;
    width: 40px;
    text-align: center;
}

.achievement-card-title {
    font-weight: 700;
    font-size: 1em;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--ink);
}

.achievement-card-desc {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--ink-soft);
    margin-top: 2px;
}

/* ---------- Notifications de succès ---------- */
#achievementToasts {
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: min(90vw, 300px);
}

.achievement-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--ink);
    color: var(--paper);
    padding: 10px 16px;
    border: 2px solid var(--gold-bright);
    clip-path: polygon(0 0, calc(100% - var(--chamfer-sm)) 0, 100% var(--chamfer-sm), 100% 100%, 0 100%);
    box-shadow: var(--shadow-lg);
    font-family: var(--font-body);
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.achievement-toast.show {
    opacity: 1;
    transform: translateX(0);
}

.achievement-toast-icon {
    font-size: 1.8em;
    flex: 0 0 auto;
}

.achievement-toast-text strong {
    display: block;
    font-family: var(--font-display);
    font-size: 0.55em;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--gold-bright);
    margin-bottom: 3px;
}

.achievement-toast-title {
    font-size: 0.95em;
    font-weight: 700;
}

.achievement-toast-desc {
    font-size: 0.75em;
    font-weight: 600;
    color: #b7c2c3;
    margin-top: 2px;
}

/* ---------- Contrôles tactiles (D-pad + tir) ---------- */
#touchControls {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

#touchControls.hidden {
    display: none;
}

#dpad {
    position: absolute;
    left: max(12px, env(safe-area-inset-left));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 128px;
    height: 128px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 3px;
    pointer-events: auto;
}

.dpad-btn {
    background: rgba(16, 38, 44, 0.62);
    color: var(--gold-bright);
    border: 2px solid rgba(232, 166, 39, 0.75);
    border-radius: var(--radius-sm);
    font-size: 1.4em;
    margin: 0;
    padding: 0;
    box-shadow: none;
    touch-action: none;
}

.dpad-btn:active {
    background: rgba(232, 166, 39, 0.7);
    color: var(--ink);
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

#btnShoot {
    position: absolute;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(22px, env(safe-area-inset-bottom));
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(184, 32, 47, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.8);
    font-size: 1.6em;
    pointer-events: auto;
    touch-action: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

#btnShoot:active {
    background: rgba(184, 32, 47, 0.95);
}

/* ---------- Message de rotation (smartphone en portrait) ---------- */
.orientation-notice h2 {
    font-family: var(--font-display);
    font-size: 1.1em;
    letter-spacing: 0.03em;
}

.orientation-notice p {
    font-family: var(--font-body);
    font-weight: 600;
}

/* =================================================================
   RESPONSIVE
   ================================================================= */

/* ---- Grands écrans / PC ---- */
@media (min-width: 1200px) {
    :root {
        --container-pad: 24px;
        --panel-w: 220px;
        --chrome-h: 90px;
        --canvas-max: 680px;
    }
}

@media (min-width: 1025px) and (max-width: 1199px) {
    :root {
        --container-pad: 20px;
        --panel-w: 200px;
        --chrome-h: 86px;
        --canvas-max: 600px;
    }
}

/* ---- Tablettes / petits laptops ---- */
@media (min-width: 900px) and (max-width: 1024px) {
    :root {
        --container-pad: 18px;
        --panel-w: 170px;
        --chrome-h: 78px;
        --canvas-max: 540px;
    }
}

@media (min-width: 769px) and (max-width: 899px) {
    :root {
        --container-pad: 16px;
        --panel-w: 150px;
        --chrome-h: 72px;
        --canvas-max: 460px;
        --gap: 16px;
    }

    #controlsInfo p { font-size: 0.75em; }
}

/* Masquer le message de rotation sur PC/tablette large */
@media (min-width: 769px) {
    .orientation-notice {
        display: none !important;
    }
}

/* ---- Message de rotation (smartphone en portrait) ---- */
@media (max-width: 768px) {
    .orientation-notice {
        display: none;
        position: fixed;
        inset: 0;
        background-color: var(--bg-base);
        background-image:
            linear-gradient(var(--bg-grid) 1px, transparent 1px),
            linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
        background-size: 32px 32px;
        color: var(--ink);
        z-index: 9999;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
        padding: 24px;
    }

    .orientation-notice h2 {
        color: var(--red);
        text-shadow: 2px 2px 0 var(--border);
        font-size: 1.3em;
        margin-bottom: 18px;
    }

    .orientation-notice p {
        font-size: 1.1em;
        margin: 8px 0;
        max-width: 320px;
    }

    .rotate-icon {
        font-size: 3.6em;
        margin: 18px 0;
        animation: rotate 2s infinite;
        filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
    }

    @keyframes rotate {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
}

@media (max-width: 768px) and (orientation: portrait) {
    #gameContainer {
        display: none !important;
    }

    .orientation-notice {
        display: flex !important;
    }
}

/* ---- Smartphone en mode paysage (l'écran de jeu principal) ---- */
@media (max-width: 900px) and (orientation: landscape) {
    :root {
        --container-pad: 10px;
        --panel-w: 0px; /* les panneaux passent en overlay (voir plus bas), ils ne réservent plus de largeur au canvas */
        --chrome-h: 46px;
        --canvas-max: 480px;
        --gap: 10px;
        --chamfer: 8px;
    }

    body { padding: 0; animation: none; }

    #gameContainer {
        border-radius: 0;
    }

    #gameHeader {
        /* Le titre cède sa place au canvas ; le HUD (score) est maintenant
           affiché en overlay directement sur le canvas, voir plus bas. */
        display: none;
    }

    /* ---- Panneaux gauche/droite : superposés au canvas au lieu de lui
       prendre de la largeur, pour maximiser la zone de jeu sur un petit
       écran. Le score reste visible (utile en jeu) ; les réglages se
       réduisent au bouton Pause pendant l'action (voir .hud-minimal
       plus bas) et reviennent en entier dès que la partie est en pause. ---- */
    #leftPanel, #rightPanel {
        position: absolute;
        top: max(8px, env(safe-area-inset-top));
        z-index: 6;
        width: auto;
        max-width: 48%;
        max-height: 70%;
        background: rgba(9, 26, 30, 0.62);
        backdrop-filter: blur(3px);
        border: 1px solid rgba(232, 166, 39, 0.35);
        border-radius: var(--radius-sm);
        padding: 5px 7px;
        gap: 5px;
        transition: opacity 0.2s ease;
    }

    #leftPanel {
        left: max(8px, env(safe-area-inset-left));
        align-items: flex-start;
        text-align: left;
    }

    #rightPanel {
        right: max(8px, env(safe-area-inset-right));
        align-items: flex-end;
        text-align: right;
    }

    #scoresContainer {
        justify-content: flex-start;
    }

    /* Instructions clavier/tactile : utiles avant la première partie sur
       desktop, mais redondantes sur mobile où le D-pad tactile est déjà
       visible à l'écran — on les masque pour gagner de la place. */
    #controlsInfo {
        display: none;
    }

    /* Pendant l'action (pas en pause), on ne garde que le bouton Pause :
       le reste des réglages (difficulté, volume, langue, thème, plein
       écran, succès, redémarrer) est de toute façon peu utile en pleine
       partie, et la difficulté est déjà désactivée pendant le jeu. */
    #gameContainer.hud-minimal #gameSettings > *:not(#pauseGame) {
        display: none;
    }

    #gameContainer.hud-minimal #rightPanel {
        padding: 3px;
    }

    #scoreDisplay, #killsDisplay, #levelDisplay, #comboDisplay {
        font-size: 0.78em;
        padding: 4px 9px;
        gap: 5px;
    }

    #scoreIcon, #killsIcon {
        width: 16px;
        height: 16px;
    }

    #gameCanvas {
        border-width: 3px;
        box-shadow: 0 0 0 2px var(--gold), 0 0 0 4px var(--border), var(--shadow-lg);
    }

    #gameSettings { gap: 6px; }

    .setting {
        gap: 4px;
        font-size: 0.72em;
    }

    .setting label {
        font-size: 0.72em;
    }

    button {
        padding: 5px 8px;
        font-size: 0.68em;
        min-width: 0;
        margin: 1px;
    }

    input[type="range"] { width: 46px; }

    select {
        font-size: 0.68em;
        padding: 2px 4px;
    }

    #dpad {
        width: 104px;
        height: 104px;
    }

    .dpad-btn { font-size: 1.15em; }

    #btnShoot {
        width: 58px;
        height: 58px;
        font-size: 1.3em;
    }
}

/* ---- Très petits smartphones en paysage (hauteur réduite) ---- */
@media (max-width: 900px) and (max-height: 460px) and (orientation: landscape) {
    :root {
        --container-pad: 6px;
        --panel-w: 0px; /* toujours en overlay, voir la media query précédente */
        --chrome-h: 30px;
        --canvas-max: 360px;
        --gap: 6px;
    }

    #scoreDisplay, #killsDisplay, #levelDisplay, #comboDisplay {
        font-size: 0.68em;
        padding: 3px 7px;
    }

    #leftPanel, #rightPanel {
        max-height: 90%;
        padding: 3px 5px;
    }

    #gameSettings { gap: 4px; }

    button {
        padding: 4px 6px;
        font-size: 0.62em;
    }

    #dpad {
        width: 88px;
        height: 88px;
    }

    #btnShoot {
        width: 50px;
        height: 50px;
        font-size: 1.1em;
    }
}

@media (max-width: 900px) and (orientation: landscape) {
    /* Centrées en haut plutôt qu'en pleine largeur, pour ne pas chevaucher
       les panneaux score/pause désormais superposés au canvas de chaque côté */
    #achievementToasts {
        left: 50%;
        right: auto;
        top: max(8px, env(safe-area-inset-top));
        transform: translateX(-50%);
        max-width: min(70vw, 320px);
    }
}
