/* ============================================================
   Système de fenêtres "bureau" : titre fixe, contenu/liste/réglages
   déplaçables, légende et boutique fixes, bouton recherche + lightbox.
   Chargé après overlay.css. Style commun des fenêtres : section 9 du
   cahier des charges (coins arrondis, ombre portée).
   ============================================================ */

.win {
  position: fixed;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid #333;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.win-titlebar {
  flex: 0 0 auto;
  padding: 6px 10px;
  background: #111;
  border-bottom: 1px solid #333;
  color: #a6e22e;
  font-size: 11px;
  cursor: move;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.win-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 12px;
}

.win-close {
  background: transparent;
  border: none;
  color: #f8f8f2;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  padding: 0 2px;
}
.win-close:hover {
  color: #a6e22e;
}

.win[data-draggable] .win-titlebar {
  cursor: grab;
}
.win[data-draggable].dragging .win-titlebar {
  cursor: grabbing;
}

/* ── Titre ASCII + menu : fixe, toujours visible, fond transparent ── */
#site-title {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 40;
  width: 10vw;
  min-width: 220px;
  background: transparent;
  pointer-events: none; /* laisse passer les clics vers la carte, sauf sur les liens */
}
#site-title-ascii {
  margin: 0;
  color: #66d9ef;
  font-size: clamp(9px, 0.34vw, 22px);
  line-height: 1.15;
  white-space: pre;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.9);
}
#site-menu {
  margin-top: 6px;
  pointer-events: auto;
  font-size: 11px;
}
#site-menu a {
  display: inline-block;
  margin-right: 8px;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
}

/* ── Bouton recherche : fixe, haut-droite ── */
#search-button {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 40;
  width: min(20vw, 20vh);
  height: min(20vw, 20vh);
  max-width: 140px;
  max-height: 140px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid #333;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#search-button:hover {
  border-color: #a6e22e;
}
#search-button img {
  width: 55%;
  height: 55%;
  opacity: 0.9;
}

/* ── Lightbox recherche : réutilise .lightbox-overlay (style.css) ── */
#search-lightbox .win {
  position: static;
  width: min(600px, 90vw);
  max-height: 80vh;
}

/* ── Fenêtre de contenu ── */
#content-window {
  left: 16px;
  top: 130px;
  width: 25vw;
  min-width: 260px;
  height: 60vh;
  min-height: 200px;
  max-width: 90vw;
  max-height: 85vh;
  z-index: 15;
  resize: both;
}
#content-window .win-body {
  resize: none; /* le resize natif est porté par #content-window lui-même */
}

/* ── Fenêtre liste des nœuds ── */
#nodelist-window {
  left: 16px;
  bottom: 16px;
  width: 25vw; /* même largeur que #content-window au chargement */
  min-width: 260px;
  height: 20vh;
  min-height: 120px;
  z-index: 15;
}

/* ── Fenêtre de réglages d'affichage ── */
#settings-window {
  right: 16px;
  top: 32.5vh;
  width: 25vw;
  min-width: 240px;
  height: 35vh;
  min-height: 220px;
  z-index: 15;
}
#settings-window .win-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.color-mode-btn {
  background: transparent;
  border: 1px solid #333;
  color: #f8f8f2;
  font-family: inherit;
  font-size: 12px;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
}
.color-mode-btn:hover {
  border-color: #666;
}
.color-mode-btn.active {
  border-color: #a6e22e;
  color: #a6e22e;
}

/* ── Fenêtre légende / échelle ── */
#legend-window {
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: 35vw;
  min-width: 260px;
  height: 5vh;
  min-height: 40px;
  z-index: 15;
}
#legend-window .win-body {
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}
.legend-gradient {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, hsl(240, 70%, 55%), hsl(120, 70%, 55%), hsl(0, 70%, 55%));
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #999999;
}

/* ── Fenêtre boutique ── */
#shop-window {
  right: 16px;
  bottom: 16px;
  width: 25vw;
  min-width: 220px;
  height: 20vh;
  min-height: 140px;
  z-index: 15;
}
.shop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #222;
  text-decoration: none;
  color: #f8f8f2;
}
.shop-item:last-child {
  border-bottom: none;
}
.shop-item img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border: 1px solid #333;
  flex: 0 0 auto;
}
.shop-item-titre {
  font-size: 11px;
  color: #a6e22e;
}
#shop-body .shop-empty {
  color: #555;
  font-size: 11px;
}

/* ── Tiroir mobile (cf. js/mobile-drawer.js) ──────────────────────────────
   #mobile-drawer reçoit (en JS) #site-menu, #content-window,
   #nodelist-window, #settings-window, #shop-window. Sur desktop c'est
   neutre (display:contents) : ces éléments gardent leur position/taille
   habituelle, définie plus haut dans ce fichier. */
#mobile-drawer { display: contents; }
#mobile-drawer-toggle,
#mobile-drawer-backdrop {
  display: none;
}
/* bouton fermer de la fenêtre contenu : uniquement utile en lightbox mobile */
#content-lightbox-close { display: none; }

@media (max-width: 768px) {
  /* Le modèle "fenêtres flottantes" ne tient pas sur un petit écran (une
     fenêtre à 90vw ancrée à gauche et une autre ancrée à droite se
     recouvrent presque entièrement). Seuls la carte, le logo, le bouton
     recherche et la fenêtre échelle restent affichés directement ; tout le
     reste (menu + fenêtres) passe dans un tiroir coulissant depuis la
     droite, ouvert via le bouton burger en bas à droite. */
  html, body { overflow: hidden; }

  /* le menu quitte sa place sous le logo (il est déplacé dans le tiroir) */
  #site-title #site-menu { display: none; }
  #site-title { width: 60vw; }
  #site-title-ascii { font-size: 1.6vw; }

  /* la fenêtre échelle reste seule, fixe en bas, hors du tiroir */
  #legend-window { width: 90vw; }

  #mobile-drawer-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    position: fixed;
    right: 16px;
    bottom: 16px;
    width: 52px;
    height: 52px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid #333;
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
    z-index: 60;
    cursor: pointer;
  }
  #mobile-drawer-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: #f8f8f2;
    transition: transform 0.2s, opacity 0.2s;
  }
  #mobile-drawer-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  #mobile-drawer-toggle.open span:nth-child(2) { opacity: 0; }
  #mobile-drawer-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  #mobile-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 45;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  #mobile-drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  #mobile-drawer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 75vw;
    max-width: 420px;
    padding: 16px 12px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.95);
    border-left: 1px solid #333;
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.6);
    overflow-y: auto;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  #mobile-drawer.open { transform: translateX(0); }

  #mobile-drawer #site-menu {
    display: block;
    font-size: 13px;
    flex: 0 0 auto;
  }
  #mobile-drawer #site-menu a { display: block; margin: 4px 0; }

  #mobile-drawer .win {
    position: static;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 45vh;
    margin: 0;
    flex: 0 0 auto;
    resize: none;
    transform: none;
  }

  /* clic sur un nœud (cf. js/mobile-drawer.js, évènement pgp:pagechange) :
     la fenêtre de contenu sort du tiroir et s'affiche en lightbox par-dessus
     tout, l'échelle disparaît le temps de la lecture. */
  #content-window.mobile-content-lightbox {
    position: fixed;
    inset: 8vh 6vw;
    width: auto;
    max-width: none;
    min-width: 0;
    height: auto;
    max-height: 84vh;
    min-height: 0;
    margin: 0;
    resize: none;
    z-index: 55;
  }
  #content-window.mobile-content-lightbox #content-lightbox-close {
    display: inline-block;
  }
  #legend-window.hidden-mobile { display: none; }
}
