* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(180deg, #87CEEB 0%, #B0E7FF 60%, #D8F5D0 100%); user-select: none; }
#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* HUD */
#hud { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between;
  padding: 12px 14px; pointer-events: none; z-index: 5; }
.hud-left, .hud-right { display: flex; gap: 8px; align-items: center; }
.hud-pill { background: rgba(20,25,40,.72); color: #fff; padding: 8px 14px; border-radius: 999px;
  font-weight: 700; font-size: 15px; backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.15); }
.hud-btn { pointer-events: auto; background: rgba(20,25,40,.72); color: #fff; border: 1px solid rgba(255,255,255,.15);
  border-radius: 12px; padding: 8px 12px; font-size: 16px; cursor: pointer; }
.hud-btn:hover { background: rgba(40,50,80,.85); }

#toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); background: rgba(20,25,40,.85);
  color: #fff; padding: 10px 20px; border-radius: 12px; font-weight: 700; opacity: 0; transition: opacity .3s; z-index: 6; pointer-events: none; }
#toast.show { opacity: 1; }

/* Overlays */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(15,20,35,.55); backdrop-filter: blur(6px); z-index: 10; padding: 16px; overflow-y: auto; }
.card { background: #fff; border-radius: 24px; padding: 32px 36px; text-align: center; max-width: 480px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); border-bottom: 6px solid #dfe6ee; max-height: 88vh; overflow-y: auto; }
.card h1 { font-size: 34px; letter-spacing: 1px; }
.card h2 { font-size: 28px; margin-bottom: 12px; }
.subtitle { color: #666; margin: 6px 0 16px; font-weight: 600; }
.howto { background: #f2f5f9; border-radius: 14px; padding: 14px; font-size: 14px; line-height: 2; margin-bottom: 18px; color: #334; }
kbd { background: #222; color: #fff; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-family: monospace; }
.big-btn { background: linear-gradient(180deg, #4ade80, #22c55e); color: #fff; border: none; font-size: 20px; font-weight: 800;
  padding: 14px 42px; border-radius: 16px; cursor: pointer; box-shadow: 0 6px 0 #15803d; transition: transform .1s; width: 100%; margin-top: 6px; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #15803d; }
.ghost-btn { background: #eef2f7; border: none; padding: 10px 20px; border-radius: 12px; margin-top: 10px; cursor: pointer; font-weight: 700; width: 100%; }
.ghost-btn:hover { background: #dfe7f0; }
.final-score { font-size: 22px; font-weight: 800; margin: 12px 0; }
.final-time { color: #555; font-weight: 600; margin-bottom: 12px; }
.win-card { border-bottom-color: #fbbf24; }
.hint { margin-top: 12px; font-size: 13px; color: #888; }
.mode-choices { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.mode-btn { font-size: 20px; padding: 16px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.mode-icon { font-size: 26px; }

/* Éditeur — réutilise .admin-* + variantes */
#editor-panel { position: fixed; top: 64px; left: 12px; width: 320px; max-height: calc(100vh - 90px);
  overflow-y: auto; background: rgba(15,20,35,.94); color: #fff; border-radius: 16px; z-index: 20;
  border: 1px solid rgba(251,191,36,.4); box-shadow: 0 12px 40px rgba(0,0,0,.5); padding: 12px 14px 16px; }
#editor-panel .admin-section h3 { color: #fbbf24; }
#btn-editor-close { background: #333; color: #fff; border: none; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.editor-tools { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 8px; }
.editor-tools button { font-size: 18px; padding: 8px 4px; background: #2b3550; color: #fff;
  border: 1px solid rgba(255,255,255,.15); border-radius: 10px; cursor: pointer; }
.editor-tools button:hover { background: #3b4769; }
.editor-tools button.active { background: #f59e0b; border-color: #fbbf24; }
.editor-counts { font-size: 12px; color: #ccc; text-align: center; margin: -4px 0 10px; }
#editor-panel select { background: #2b3550; color: #fff; border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px; padding: 5px 6px; font-size: 12px; }
#editor-panel input[type=color] { width: 44px; height: 28px; border: none; border-radius: 8px; background: none; cursor: pointer; }
#editor-panel input[type=number] { width: 62px; }
#editor-playtest { font-size: 16px; padding: 12px; }
#editor-dot-0.filled, #editor-dot-1.filled, #editor-dot-2.filled { color: #22c55e; }

/* Multi */
.multi-box { background: #eef4ff; border: 2px dashed #93c5fd; border-radius: 14px; padding: 14px; margin-top: 14px; width: 100%; box-sizing: border-box; }
.multi-title { font-weight: 800; font-size: 13px; margin-bottom: 8px; color: #1d4ed8; }
.multi-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: stretch; flex-wrap: wrap; }
.multi-row .ghost-btn { margin-top: 0; flex: 1; min-width: 120px; white-space: nowrap; }
#multi-status { min-height: 18px; word-break: break-word; }
#hud-net { border-color: rgba(96,165,250,.6); }
/* Code invitation PeerJS */
.host-code-badge { display: block; text-align: center; font-family: monospace; font-size: 32px; font-weight: 900;
  letter-spacing: 8px; background: #fff; border: 3px dashed #2563eb; border-radius: 14px; padding: 14px 10px; margin: 8px 0;
  color: #1e40af; box-shadow: 0 2px 10px rgba(37,99,235,.15); user-select: all; }
#join-code-input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
#host-link-preview { word-break: break-all; font-size: 11px; color: #2563eb; }
/* QR archivé — styles conservés pour backup mais non utilisés */
/* .qr-canvas, .qr-video, .qr-text voir src/game/qrBackup.js */

/* Admin gate (menu) */
.admin-gate-box { background: #fef9e7; border: 2px dashed #fbbf24; border-radius: 14px; padding: 12px; margin-top: 14px; }
.admin-gate-box .multi-title { color: #92400e; }
.admin-gate-box input { flex: 1; min-width: 120px; border: 2px solid #fbbf24; border-radius: 12px; padding: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.admin-gate-box input:focus { outline: none; border-color: #f59e0b; }

/* Stamina HUD */
#hud-stamina { position: fixed; bottom: 14px; left: 14px; background: rgba(20,25,40,.82); border: 1px solid rgba(255,255,255,.2); border-radius: 12px; padding: 8px 12px; z-index: 5; min-width: 160px; backdrop-filter: blur(6px); }
.stamina-label { font-size: 11px; font-weight: 800; color: #fbbf24; letter-spacing: 0.5px; }
.stamina-bar { height: 8px; background: rgba(255,255,255,.2); border-radius: 999px; overflow: hidden; margin: 6px 0; }
#stamina-fill { height: 100%; width: 100%; background: linear-gradient(90deg,#22c55e,#4ade80); transition: width .15s, background .2s; }
#stamina-fill.cooldown { background: linear-gradient(90deg,#ef4444,#f87171); }
.stamina-text { font-size: 10px; font-weight: 800; color: #fff; text-align: center; }

/* Admin */
#btn-admin { border-color: rgba(251,191,36,.5); }
#btn-admin.locked, #btn-editor.locked { opacity: .45; filter: grayscale(1); cursor: not-allowed; }
#btn-admin.locked::after, #btn-editor.locked::after { content: ' 🔒'; }
#admin-panel { position: fixed; top: 64px; right: 12px; width: 300px; max-height: calc(100vh - 90px);
  overflow-y: auto; background: rgba(15,20,35,.94); color: #fff; border-radius: 16px; z-index: 20;
  border: 1px solid rgba(255,255,255,.15); box-shadow: 0 12px 40px rgba(0,0,0,.5); padding: 12px 14px 16px; }
.admin-header { display: flex; justify-content: space-between; align-items: center; font-weight: 800; margin-bottom: 8px; }
.admin-header small { color: #fbbf24; font-weight: 600; }
#btn-admin-close { background: #333; color: #fff; border: none; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.admin-info { background: rgba(251,191,36,.15); border: 1px solid rgba(251,191,36,.4); border-radius: 10px;
  padding: 6px 10px; font-size: 13px; font-weight: 700; margin-bottom: 10px; text-align: center; }
.admin-section { background: rgba(255,255,255,.06); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.admin-section h3 { font-size: 14px; margin-bottom: 8px; color: #fbbf24; }
.admin-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.admin-row button { background: #2b3550; color: #fff; border: 1px solid rgba(255,255,255,.15); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-weight: 700; }
.admin-row button:hover { background: #3b4769; }
.admin-row button.active { background: #22c55e; border-color: #22c55e; }
.admin-wide { flex: 1; white-space: nowrap; }
.admin-row input[type=number] { width: 56px; padding: 6px; border-radius: 8px; border: none; text-align: center; font-weight: 800; }
.admin-row input[type=range] { flex: 1; accent-color: #22c55e; }
.admin-label { font-size: 12px; color: #aaa; min-width: 52px; }
.admin-check { display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 600; cursor: pointer; margin-top: 4px; }
.admin-check input { width: 16px; height: 16px; accent-color: #22c55e; }
.admin-hint { font-size: 11px; color: #999; margin-top: 6px; }

/* Touch */
#touch-controls { position: fixed; inset: auto 0 0 0; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 24px 28px; z-index: 7; pointer-events: none; }
#joystick { width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.25);
  border: 2px solid rgba(255,255,255,.5); position: relative; pointer-events: auto; }
#stick { width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,.9);
  position: absolute; left: 37px; top: 37px; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
#btn-jump { width: 84px; height: 84px; border-radius: 50%; border: none; font-size: 30px; font-weight: 900; color: #fff;
  background: linear-gradient(180deg, #4ade80, #22c55e); box-shadow: 0 6px 0 #15803d; pointer-events: auto; }
#btn-jump:active { transform: translateY(4px); box-shadow: none; }

/* Save select (Mario Galaxy) */
.save-card { max-width: 560px; }
.save-slots { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.save-slot { display: flex; align-items: center; gap: 14px; background: #f2f5f9; border: 2px solid #dfe6ee; border-radius: 16px; padding: 14px 16px; cursor: pointer; text-align: left; transition: transform .1s, border-color .2s; }
.save-slot:hover { transform: translateY(-2px); border-color: #93c5fd; }
.save-slot.active { border-color: #22c55e; background: #eafff0; }
.save-slot.empty { border-style: dashed; }
.save-slot-num { width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(180deg,#60a5fa,#2563eb); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 20px; flex-shrink: 0; }
.save-slot.empty .save-slot-num { background: #cbd5e1; }
.save-slot-info { flex: 1; min-width: 0; }
.save-slot-title { font-weight: 800; font-size: 16px; color: #1e293b; }
.save-slot-meta { font-size: 13px; color: #64748b; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-slot-actions { display: flex; gap: 6px; }
.save-slot-actions button { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 6px 10px; cursor: pointer; font-weight: 700; font-size: 12px; }
.save-slot-actions button:hover { background: #fee2e2; border-color: #fca5a5; }
.save-slot-actions .btn-continue { background: #22c55e; color: #fff; border-color: #16a34a; }
.save-slot-actions .btn-continue:hover { background: #16a34a; }

/* World / Level Select (Mario Bros) */
.world-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
.world-card { background: linear-gradient(180deg,#f0f9ff,#e0f2fe); border: 3px solid #bae6fd; border-radius: 18px; padding: 18px; cursor: pointer; text-align: center; transition: transform .15s, border-color .2s, box-shadow .2s; position: relative; overflow: hidden; }
.world-card:hover { transform: translateY(-4px) scale(1.02); border-color: #38bdf8; box-shadow: 0 12px 24px rgba(0,0,0,.15); }
.world-card.locked { background: #f1f5f9; border-color: #cbd5e1; cursor: not-allowed; opacity: .7; filter: grayscale(.5); }
.world-card.locked:hover { transform: none; box-shadow: none; }
.world-card.forest { background: linear-gradient(180deg,#dcfce7,#bbf7d0); border-color: #4ade80; }
.world-card.snow { background: linear-gradient(180deg,#f0f9ff,#e0f2fe); border-color: #38bdf8; }
.world-card-icon { font-size: 42px; margin-bottom: 8px; }
.world-card h3 { font-size: 18px; font-weight: 900; color: #1e293b; }
.world-card p { font-size: 13px; color: #64748b; margin-top: 4px; }
.world-card .lock-badge { position: absolute; top: 10px; right: 10px; font-size: 18px; }
.level-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
.level-card { background: #f8fafc; border: 2px solid #e2e8f0; border-radius: 14px; padding: 14px 10px; cursor: pointer; text-align: center; transition: all .15s; }
.level-card:hover { transform: translateY(-3px); border-color: #4ade80; background: #f0fdf4; }
.level-card.locked { opacity: .5; cursor: not-allowed; filter: grayscale(.7); }
.level-card .lvl-num { font-size: 22px; font-weight: 900; color: #1e293b; }
.level-card .lvl-name { font-size: 12px; color: #64748b; margin-top: 4px; }

/* Responsive Mobile */
@media (max-width: 768px) {
  #hud { flex-wrap: wrap; gap: 6px; padding: 8px; }
  .hud-left, .hud-right { gap: 6px; flex-wrap: wrap; }
  .hud-pill { font-size: 13px; padding: 6px 10px; }
  .hud-btn { padding: 6px 10px; font-size: 14px; }
  .overlay { align-items: flex-start; padding: 12px; overflow-y: auto; }
  .card, .save-card { max-width: 100%; padding: 20px 16px; margin: auto 0; }
  .card h1 { font-size: 26px; }
  .howto { font-size: 13px; padding: 10px; }
  #admin-panel, #editor-panel { left: 50%; right: auto; transform: translateX(-50%); width: min(92vw, 340px); max-height: 72vh; top: 12px; z-index: 25; }
  #touch-controls { padding: 0 16px 16px; z-index: 7; }
  #joystick { width: 110px; height: 110px; }
  #stick { width: 48px; height: 48px; left: 31px; top: 31px; }
  #btn-jump { width: 72px; height: 72px; font-size: 26px; }
}
@media (max-width: 600px) {
  .card { padding: 20px 14px; } .card h1 { font-size: 22px; }
  .hud-pill { font-size: 11px; padding: 5px 8px; }
  .save-slot { flex-direction: column; align-items: stretch; }
  .save-slot-actions { justify-content: stretch; }
  .save-slot-actions button { flex: 1; }
  .multi-row { flex-direction: column; }
  .multi-row .ghost-btn { width: 100%; min-width: unset; }
  #toast { top: 60px; font-size: 13px; padding: 8px 14px; max-width: 90vw; text-align: center; }
}
@media (max-width: 380px) {
  .card { padding: 16px 12px; }
  .big-btn { font-size: 18px; padding: 12px 24px; }
  #joystick { width: 96px; height: 96px; }
  #stick { width: 42px; height: 42px; left: 27px; top: 27px; }
  #btn-jump { width: 64px; height: 64px; font-size: 22px; }
}
/* Empêche les panneaux de bloquer le bouton fermer sur mobile */
.admin-header button, #btn-admin-close, #btn-editor-close { min-width: 32px; min-height: 32px; }
/* Quand un overlay est ouvert, masque les contrôles tactiles pour éviter les clics fantômes */
.overlay:not(.hidden) ~ #touch-controls { display: none; }
/* Badge version du déploiement, tout en bas de la page — toujours au-dessus du blur */
#app-version { position: fixed; left: 50%; bottom: 4px; transform: translateX(-50%);
  font-size: 11px; color: rgba(255,255,255,.9); background: rgba(15,20,35,.75);
  padding: 3px 12px; border-radius: 999px; z-index: 100; pointer-events: none; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.15); backdrop-filter: blur(4px); }
