/* =======================
   FONT + RESET
======================= */
* {
  font-family: "Press Start 2P", cursive;
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

/* =======================
   FOND (marron clair animé)
======================= */
body {
  background: linear-gradient(45deg, #cfa77e, #e2c5a2, #cfa77e);
  background-size: 400% 400%;
  animation: fondAnime 12s ease infinite;

  height: 100vh;
  overflow: hidden;

  display: flex;
  flex-direction: column;
}

@keyframes fondAnime {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* =======================
   ✅ BANDE (HUD) EN HAUT
======================= */
.topHud {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;

  width: min(1024px, calc(100vw - 24px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;

  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 4px solid #000;
  border-radius: 12px;

  box-shadow: 0 0 0 6px #a00000, 0 0 0 12px #000000;
  font-size: 10px;
}

.topHud-left {
  display: flex;
  gap: 10px;
  align-items: center;
}

.topHud-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hudBtn {
  border: 3px solid #000;
  background: #ffd37a;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 10px;
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hudBtn:hover {
  background: #ffeea3;
  transform: scale(1.03);
}

.hudBtn.active {
  background: #fff1b8;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
}

.hudName {
  font-size: 10px;
  padding: 6px 8px;
  border: 3px solid #000;
  border-radius: 10px;
  background: #fff;
}

/* =======================
   WRAPPER (zone sous HUD)
======================= */
#gameWrapper {
  flex: 1;
  width: 100vw;
  height: 100vh;
  padding-top: 90px; /* place HUD */

  display: flex;
  justify-content: center;
  align-items: center;
}

/* =======================
   ✅ VIEWPORT = CADRE ROUGE AUTOUR DU JEU + DIALOGUE
======================= */
#gameViewport {
  position: relative;

  /* ✅ le cadre sera autour de tout */
  background: #fff;

  border: 16px solid #ff2e2e;
  border-radius: 14px;

  box-shadow:
    0 0 0 8px #a00000,
    0 0 0 16px #000,
    0 18px 40px rgba(0, 0, 0, 0.55);

  padding: 18px; /* espace entre cadre rouge et contenu */
}

/* =======================
   CANVAS (pas étiré)
======================= */
canvas {
  display: block;
  border: 4px solid #000;
  image-rendering: pixelated;
  background: black;

  width: auto;
  height: auto;
  aspect-ratio: 1024 / 576;

  max-width: calc(100vw - 80px);
  max-height: calc(100vh - 220px);
}

/* =======================
   OVERLAY NOIR (transition combat)
======================= */
#overlappingDiv {
  position: absolute;
  inset: 18px; /* = padding du viewport */
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  background: black;
}

/* =======================
   ✅ DIALOGUE PNJ (DANS LE CADRE)
======================= */
#characterDialogueBox {
  width: 100%;
  height: 140px;

  background: #fff;
  border: 4px solid #000;
  border-top: 0;

  padding: 12px;
  display: none;

  z-index: 20;
}

/* =======================
   MISSION BANNER
======================= */
.mission-banner {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 25;

  display: none;
  max-width: 420px;
  padding: 8px 10px;

  background: #fff3c4;
  border: 4px solid #000;
  border-radius: 12px;
  box-shadow: 0 0 0 6px #a00000, 0 0 0 12px #000;

  font-size: 9px;
  line-height: 1.4;
}

.mission-banner.show {
  display: block;
}

/* =======================
   STATS PANEL
======================= */
.stats-panel {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.45);
}

.stats-panel.hidden {
  display: none;
}

.stats-panel .stats-card {
  width: min(520px, 92vw);
  background: #fff;
  border: 6px solid #000;
  border-radius: 16px;
  padding: 18px;
  text-align: center;
  box-shadow: 0 0 0 8px #a00000, 0 0 0 16px #000;
}

.stats-panel h2 {
  margin: 0 0 12px 0;
  font-size: 12px;
}

.stats-panel p {
  margin: 8px 0;
  font-size: 10px;
}

.stats-actions {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.stats-actions .btn {
  border: 4px solid #000;
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  font-weight: 900;
  font-size: 10px;
  cursor: pointer;
  box-shadow: 0 4px 0 #000;
}

.stats-actions .btn:hover {
  transform: translateY(-1px);
}

.stats-actions .btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #000;
}

.stats-actions .btn.danger {
  background: #111;
  color: #fff;
}

/* =======================
   JOURNAL PANEL
======================= */
.journal-panel {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 35;
  width: min(320px, 86vw);
  background: #fff;
  border: 4px solid #000;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 0 0 6px #a00000, 0 0 0 12px #000;
}

.journal-panel.hidden {
  display: none;
}

.journal-panel h3 {
  margin: 0 0 8px 0;
  font-size: 10px;
}

.journal-panel h3,
.inventory-panel h3 {
  text-transform: uppercase;
  letter-spacing: 1px;
}

.journal-panel ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  font-size: 9px;
}

.journal-panel li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.journal-panel .check {
  width: 12px;
  height: 12px;
  border: 2px solid #000;
  display: inline-block;
  background: #fff;
}

.journal-panel .check.done {
  background: #ffd37a;
}

/* =======================
   INVENTORY PANEL
======================= */
.inventory-panel {
  position: absolute;
  top: 24px;
  left: 24px;
  z-index: 35;
  width: min(320px, 86vw);
  background: #fff;
  border: 4px solid #000;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 0 0 6px #a00000, 0 0 0 12px #000;
}

.journal-panel,
.inventory-panel {
  animation: panelPop 140ms ease-out;
}

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

.inventory-panel.hidden {
  display: none;
}

.inventory-panel h3 {
  margin: 0 0 8px 0;
  font-size: 10px;
}

.inventory-panel ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  font-size: 9px;
}

.inventory-panel li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inventory-panel .item-btn {
  border: 3px solid #000;
  background: #ffd37a;
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 8px;
}

.inventory-panel .item-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =======================
   UI COMBAT (cachée par défaut)
======================= */
#userInterface {
  display: none;
}

/* =======================
   UI COMBAT (zone + attaques)
======================= */
#userInterface {
  position: absolute;
  inset: 18px; /* alignÃ© au padding du viewport */
  z-index: 30;
  pointer-events: none; /* on rÃ©active sur les zones cliquables */
}

#userInterface .status-box {
  position: absolute;
  width: 320px;
  background: #fff;
  border: 4px solid #000;
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 0 0 6px #a00000, 0 0 0 12px #000;
  font-size: 10px;
}

#userInterface .enemy-box {
  top: 16px;
  left: 16px;
}

#userInterface .player-box {
  bottom: 160px;
  right: 16px;
}

#userInterface .status-box h1 {
  margin: 0 0 8px 0;
  font-size: 10px;
}

.health-container {
  position: relative;
  width: 100%;
  height: 14px;
  border: 3px solid #000;
  border-radius: 10px;
  background: #2b2b2b;
  overflow: hidden;
}

.health-background {
  position: absolute;
  inset: 0;
  background: #7d0a0a;
}

.health-bar {
  position: absolute;
  inset: 0;
  background: #28c76f;
  width: 100%;
  transition: width 200ms ease;
}

#userInterface .bottom-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 140px;
  display: grid;
  grid-template-columns: 1fr 1fr 200px;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border: 4px solid #000;
  border-radius: 12px;
  box-shadow: 0 0 0 6px #a00000, 0 0 0 12px #000;
  pointer-events: auto;
}

#dialogueBox {
  border: 3px solid #000;
  border-radius: 10px;
  padding: 10px;
  background: #f9f9f9;
  font-size: 10px;
  line-height: 1.4;
  overflow: hidden;
}

#attacksBox {
  border: 3px solid #000;
  border-radius: 10px;
  padding: 8px;
  background: #f3f1e7;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#attacksBox button {
  border: 3px solid #000;
  background: #ffd37a;
  padding: 8px 6px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 9px;
  text-transform: uppercase;
  box-shadow: 0 3px 0 #000;
}

#attacksBox button:hover {
  background: #ffeea3;
  transform: translateY(-1px);
}

#attacksBox button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #000;
}

.attack-type-box {
  border: 3px solid #000;
  border-radius: 10px;
  padding: 10px;
  background: #0f0f0f;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.attack-type-box h1 {
  margin: 0;
  font-size: 10px;
  letter-spacing: 1px;
}

@media (max-width: 860px) {
  #userInterface .bottom-menu {
    grid-template-columns: 1fr;
    height: auto;
  }

  #userInterface .player-box {
    bottom: 200px;
  }
}

/* =======================
   MENU PAUSE
======================= */
.hidden {
  display: none !important;
}

.pause-menu {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.pause-panel {
  width: min(320px, 92vw);
  background: #fff;
  border: 6px solid #000;
  border-radius: 16px;
  padding: 18px;
  text-align: center;

  box-shadow: 0 0 0 8px #a00000, 0 0 0 16px #000;
}

.pause-panel h2 {
  margin-bottom: 14px;
  font-size: 14px;
}

.pause-panel .btn {
  width: 100%;
  margin: 8px 0;
  padding: 12px;
  font-weight: 900;
  border: 4px solid #000;
  border-radius: 14px;
  background: #f6f6f6;
  cursor: pointer;
  font-size: 10px;
}

.pause-panel .danger {
  background: #e10606;
  color: #fff;
}

/* =======================
   POPUP NOM
======================= */
#nameModal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  background: rgba(0, 0, 0, 0.7);
  z-index: 10000;
}

.nameModalContent {
  background: white;
  border: 6px solid black;
  padding: 18px;
  width: min(420px, 92vw);
  text-align: center;

  box-shadow: 0 0 0 8px #a00000, 0 0 0 16px #000;
}

#nameInput {
  width: 92%;
  padding: 10px;
  margin: 14px 0;
  border: 3px solid black;
  font-size: 12px;
  outline: none;
}

#startGameBtn {
  padding: 10px 14px;
  border: 3px solid black;
  background: #ffd37a;
  cursor: pointer;
  font-size: 12px;
}

#nameError {
  display: none;
  margin-top: 10px;
  font-size: 10px;
  color: #a00000;
}

/* =======================
   INTRO MESSAGE (centre + animation)
======================= */
.intro-message {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  background: rgba(0, 0, 0, 0.55);
  z-index: 99999;
  padding: 18px;
}

.intro-message > p {
  width: min(620px, 92vw);
  background: rgba(255, 255, 255, 0.95);
  border: 6px solid #000;
  border-radius: 18px;
  padding: 18px;

  font-size: 10px;
  line-height: 1.6;

  box-shadow: 0 0 0 8px #a00000, 0 0 0 16px #000;
}

.intro-message.show > p {
  animation: introPop 260ms ease-out both;
}

@keyframes introPop {
  from {
    transform: translateY(10px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}
/* =======================
   ✍️ TYPEWRITER + HINT (▶)
======================= */
#characterDialogueBox,
.intro-message > p {
  position: relative;
}

.dialogueText {
  display: block;
  white-space: pre-line; /* garde les retours à la ligne */
}

.nextHint {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 12px;
  opacity: 0;
  animation: hintBlink 0.7s infinite;
  pointer-events: none;
}

.nextHint.show {
  opacity: 1;
}

@keyframes hintBlink {
  0%, 100% { transform: translateY(0); opacity: 0.2; }
  50% { transform: translateY(-2px); opacity: 1; }
}
