/* Interface dans le style du HUD de Captain Comic : palette EGA, biseaux, police BIOS 8x8 */
:root {
  --k: #000000;   /* 0  noir        */
  --b: #0000aa;   /* 1  bleu        */
  --c: #00aaaa;   /* 3  cyan        */
  --r: #aa0000;   /* 4  rouge       */
  --g7: #aaaaaa;  /* 7  gris clair  */
  --g8: #555555;  /* 8  gris fonce  */
  --lg: #55ff55;  /* 10 vert clair  */
  --lc: #55ffff;  /* 11 cyan clair  */
  --lr: #ff5555;  /* 12 rouge clair */
  --y: #ffff55;   /* 14 jaune       */
  --w: #ffffff;   /* 15 blanc       */
  --bev: 3px;
  --px: 'CC8x8', ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Le fond est porte par body seul : il se propage alors a tout l'ecran, y compris sous les barres d'iOS */
html, body {
  margin: 0; height: 100%; color: var(--w);
  font-family: var(--px); font-size: 16px; line-height: 1.25;
  overflow: hidden; overscroll-behavior: none; touch-action: none;
  background-repeat: repeat; image-rendering: pixelated;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-font-smoothing: none; font-smooth: never;
}
body { background-color: #14161f; }
#app { position: fixed; inset: 0; touch-action: none; }
/* Le conteneur du terrain est place et dimensionne par js/layout.js */
#stage { position: absolute; left: 0; top: 0; width: 0; height: 0; }
#cv { display: block; width: 100%; height: 100%; background: var(--k); image-rendering: pixelated; image-rendering: crisp-edges; }
.gfx-hd #cv { image-rendering: auto; }
/* Cadre facon ecran de jeu : filet noir, biseau gris clair, filet noir, ombre portee */
#stage, .hud { box-shadow: 0 0 0 3px var(--k), 0 0 0 6px var(--g7), 0 0 0 8px var(--k), 0 6px 18px 8px rgba(0, 0, 0, 0.55); }
button.ui, #menu, #nameBox, #saveBox { touch-action: manipulation; }
canvas[data-icon] { display: block; pointer-events: none; }
canvas[data-icon].px { image-rendering: pixelated; image-rendering: crisp-edges; }
.hidden { display: none !important; }

/* Bloc biseaute facon HUD : lumiere en haut a gauche, ombre en bas a droite, contour noir */
.bevel, #pad .btn, button.ui, .seg button, .actions button, #nameForm button, .code button {
  background: var(--g7); color: var(--k); border: 0; border-radius: 0;
  box-shadow: inset var(--bev) var(--bev) 0 var(--w), inset calc(-1 * var(--bev)) calc(-1 * var(--bev)) 0 var(--g8), 0 0 0 2px var(--k);
  font: inherit; cursor: pointer;
}
.pressed, #pad .btn.on, button.ui:active, .seg button:active, .actions button:active, #nameForm button:active, .code button:active {
  box-shadow: inset var(--bev) var(--bev) 0 var(--g8), inset calc(-1 * var(--bev)) calc(-1 * var(--bev)) 0 var(--w), 0 0 0 2px var(--k);
}
/* Touches de jeu et barre du haut : touches d'arcade en metal gris, biseau double a l'echelle de la touche,
   rainure sombre, et une "epaisseur" sous la touche qui s'enfonce quand on appuie */
#pad .btn, button.ui {
  --b1: max(3px, calc(var(--btn, 44px) * 0.05)); --b2: max(2px, calc(var(--btn, 44px) * 0.03)); --lift: max(3px, calc(var(--btn, 44px) * 0.05));
  background: linear-gradient(180deg, #d2d2d2 0%, #b2b2b2 55%, #979797 100%);
  box-shadow:
    inset var(--b1) var(--b1) 0 var(--w), inset calc(-1 * var(--b1)) calc(-1 * var(--b1)) 0 var(--g8),
    inset calc(var(--b1) + var(--b2)) calc(var(--b1) + var(--b2)) 0 #e6e6e6, inset calc(-1 * (var(--b1) + var(--b2))) calc(-1 * (var(--b1) + var(--b2))) 0 #7a7a7a,
    0 0 0 2px var(--k), 0 var(--lift) 0 2px #2a2a2a, 0 calc(var(--lift) + 4px) 10px 2px rgba(0, 0, 0, 0.55);
  transform: translateY(0);
}
#pad .btn.on, button.ui:active {
  background: linear-gradient(180deg, #8c8c8c 0%, #a4a4a4 50%, #b2b2b2 100%);
  box-shadow:
    inset var(--b1) var(--b1) 0 var(--g8), inset calc(-1 * var(--b1)) calc(-1 * var(--b1)) 0 #c8c8c8,
    0 0 0 2px var(--k), 0 2px 0 2px #2a2a2a, 0 4px 6px 2px rgba(0, 0, 0, 0.5);
  transform: translateY(calc(var(--lift) - 2px));
}
#pad .lbl { color: var(--b); text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.75); }

#hint {
  position: absolute; left: 0; right: 0; bottom: 6px; text-align: center;
  color: var(--y); font-size: 16px; text-shadow: 2px 2px 0 var(--k); pointer-events: none;
  animation: blink 1.1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* ---- Barre du haut (menu, son, plein ecran) ---- */
#topbar { position: absolute; left: 0; top: 0; display: flex; gap: 8px; z-index: 5; }
button.ui { width: 44px; height: 44px; padding: 0; display: flex; align-items: center; justify-content: center; }
button.ui canvas { width: 28px; height: 28px; filter: drop-shadow(1px 1px 0 rgba(255, 255, 255, 0.55)); }

/* ---- Commandes tactiles : placees et dimensionnees par js/layout.js ---- */
#pad { position: absolute; inset: 0; pointer-events: none; z-index: 4; --btn: 80px; --small: 50px; --gap: 10px; --icon: 40px; }
#pad .cluster { position: absolute; display: grid; gap: var(--gap); pointer-events: auto; }
#pad .left { grid-template-columns: repeat(2, var(--btn)); grid-template-rows: var(--btn); }
#pad .right { grid-template-columns: repeat(2, var(--btn)); grid-template-rows: var(--small) var(--btn); grid-template-areas: "tele door" "fire jump"; }
#pad .btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  touch-action: none; font-size: 16px; letter-spacing: 0; width: 100%; height: 100%;
}
#pad .btn canvas { width: var(--icon); height: var(--icon); filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.28)); }
#pad .dir canvas { width: calc(var(--icon) * 1.3); height: calc(var(--icon) * 1.3); }
#pad .btn.off canvas { opacity: 0.25; }
#pad .btn.off .lbl { color: var(--g8); }
#pad .small { flex-direction: row; gap: 4px; }
#pad .small canvas { width: calc(var(--icon) * 0.62); height: calc(var(--icon) * 0.62); }
#pad .small .lbl { font-size: 8px; }
#pad .lbl i { font-style: normal; margin: 0 -4px; } /* la police 8x8 espace trop le I */
#pad .compact .big .lbl, #pad .compact .small .lbl { display: none; }
#pad [data-k="jump"] { grid-area: jump; }
#pad [data-k="fire"] { grid-area: fire; }
#pad [data-k="teleport"] { grid-area: tele; }
#pad [data-k="door"] { grid-area: door; }

/* ---- Panneaux d'indicateurs (disposition moderne) ---- */
.hud { position: absolute; z-index: 3; image-rendering: pixelated; image-rendering: crisp-edges; pointer-events: none; }

/* ---- Menu : boite cyan comme "Game Paused" ---- */
#menu, #nameBox, #saveBox {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55); padding: 12px; overflow-y: auto; touch-action: pan-y;
}
.panel {
  width: min(600px, 100%); max-height: 100%; overflow-y: auto; background: var(--c); color: var(--w);
  border: 4px solid var(--lc); outline: 3px solid var(--k); box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.6);
  padding: 16px 18px; -webkit-user-select: text; user-select: text;
}
.panel h1 { margin: 0 0 14px; font-size: 24px; line-height: 1; font-weight: normal; color: var(--lg); text-align: center; text-shadow: 3px 3px 0 var(--b); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.row > span { color: var(--y); text-shadow: 2px 2px 0 var(--k); }
.seg { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.seg button { padding: 8px 10px; font-size: 16px; }
.seg button.sel { background: var(--b); color: var(--y); box-shadow: inset var(--bev) var(--bev) 0 var(--k), inset calc(-1 * var(--bev)) calc(-1 * var(--bev)) 0 var(--lc), 0 0 0 2px var(--k); }
.note { margin: 0 0 8px; font-size: 8px; line-height: 1.6; color: var(--k); }
details { margin: 14px 0; }
summary { cursor: pointer; color: var(--y); text-shadow: 2px 2px 0 var(--k); }
table.keys { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 8px; line-height: 1.6; background: var(--k); border: 2px solid var(--lc); }
table.keys td { padding: 5px 6px; vertical-align: top; color: var(--lc); }
table.keys td:first-child { color: var(--y); white-space: nowrap; }
.actions { display: flex; gap: 14px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.actions button, #nameForm button { padding: 10px 16px; font-size: 16px; }
button.primary { color: var(--b); }
.credits { margin: 16px 0 0; font-size: 8px; line-height: 1.6; color: var(--k); text-align: center; }
.credits i { font-style: normal; }
#nameForm { display: flex; flex-direction: column; gap: 14px; }
#nameForm label { color: var(--y); text-shadow: 2px 2px 0 var(--k); }
#nameInput {
  font: inherit; font-size: 16px; padding: 10px; border-radius: 0; border: 2px solid var(--lc);
  background: var(--k); color: var(--lc); outline: none;
}


/* ---- Menu : sections ---- */
.panel h2 { margin: 16px 0 4px; font-size: 16px; font-weight: normal; color: var(--k); letter-spacing: 1px; border-bottom: 2px solid var(--b); padding-bottom: 3px; }
.panel h2:first-of-type { margin-top: 6px; }
/* ---- Curseurs de volume ---- */
.vol { display: inline-flex; align-items: center; gap: 10px; }
.vol b { font-weight: normal; min-width: 4ch; text-align: right; color: var(--w); text-shadow: 2px 2px 0 var(--k); }
.vol input[type=range] { -webkit-appearance: none; appearance: none; width: 180px; height: 22px; background: transparent; margin: 0; touch-action: pan-x; }
.vol input[type=range]::-webkit-slider-runnable-track { height: 12px; background: var(--k); border: 2px solid var(--lc); }
.vol input[type=range]::-moz-range-track { height: 8px; background: var(--k); border: 2px solid var(--lc); }
.vol input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 24px; margin-top: -8px; border: 0; border-radius: 0; background: var(--g7);
  box-shadow: inset 3px 3px 0 var(--w), inset -3px -3px 0 var(--g8), 0 0 0 2px var(--k);
}
.vol input[type=range]::-moz-range-thumb {
  width: 16px; height: 24px; border: 0; border-radius: 0; background: var(--g7);
  box-shadow: inset 3px 3px 0 var(--w), inset -3px -3px 0 var(--g8), 0 0 0 2px var(--k);
}

/* ---- Partie sauvegardee : continuer / nouvelle partie ---- */
#saveBox .panel { width: min(420px, 100%); text-align: center; }
.saveInfo { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 6px; padding: 12px; background: var(--k); border: 2px solid var(--lc); color: var(--lc); }
.saveInfo span:first-child { color: var(--y); }
.saveInfo .dim { color: var(--g7); font-size: 8px; }

/* ---- Code de sauvegarde ---- */
.code { display: flex; gap: 10px; margin: 8px 0; }
.code input {
  flex: 1; min-width: 0; font: inherit; font-size: 12px; letter-spacing: 1px; padding: 10px 8px; border-radius: 0;
  border: 2px solid var(--lc); background: var(--k); color: var(--y); outline: none; -webkit-user-select: text; user-select: text;
}
.code input::placeholder { color: var(--g8); }
.code button { padding: 8px 12px; font-size: 16px; }
.code button:disabled { color: var(--g8); cursor: default; }
#codeMsg { color: var(--y); text-shadow: 1px 1px 0 var(--k); min-height: 1em; }
.code.files button { flex: 1; }
