/* Mapa del merodeador: capa que se despliega al decir la frase y se desvanece al cerrarla */

:root {
  --ink: #3b2a14;
  --ink-soft: #5a4220;
  --ink-faded: #7a5524;
  --paper: #f6e8bf;
  --t0: 1s; /* la portada ocupa los primeros segundos; el mapa se dibuja despues */
}

/* ---------- Controles flotantes ---------- */
.marauder-dock {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: calc(100vw - 32px);
}
.dock-btn {
  background: #e8d3a0;
  color: var(--ink);
  border: 1px solid #8a6a2f;
  font-family: "IM Fell English", Georgia, serif;
  font-size: 15px;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.dock-btn:hover { background: var(--paper); }
.dock-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.dock-hint {
  font-family: "Caveat", "Segoe Script", cursive;
  font-size: 16px;
  color: #e8d3a0;
  background: rgba(20, 14, 6, 0.8);
  padding: 2px 10px;
  border-radius: 12px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dock-hint:empty { display: none; }

/* ---------- Capa y pergamino ---------- */
.map-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 5, 0.86);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.map-overlay[hidden] { display: none; }
.map-overlay.visible { opacity: 1; }

.parchment {
  position: relative;
  width: min(1100px, 96vw);
  max-height: 95vh;
  overflow: auto;
  padding: 20px 26px 12px;
  color: var(--ink);
  font-family: "IM Fell English", Georgia, "Times New Roman", serif;
  background:
    linear-gradient(90deg, transparent 49.7%, rgba(90, 55, 10, 0.28) 50%, transparent 50.4%),
    linear-gradient(0deg, transparent 49.7%, rgba(90, 55, 10, 0.2) 50%, transparent 50.4%),
    radial-gradient(ellipse at center, #f6e8bf 0%, #ead6a4 55%, #c9a96b 100%);
  border-radius: 6px;
  box-shadow:
    inset 0 0 90px rgba(90, 55, 10, 0.6),
    0 24px 70px rgba(0, 0, 0, 0.7);
  transform-origin: center;
}
/* marco doble, como el borde del mapa */
.parchment::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px double rgba(90, 60, 20, 0.5);
  border-radius: 4px;
  pointer-events: none;
}
.map-overlay.visible .parchment { animation: unfold 0.65s cubic-bezier(0.2, 0.7, 0.2, 1); }

/* ---------- Portada ---------- */
.cover {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
.cover p {
  margin: 0;
  font-family: "Caveat", "Segoe Script", cursive;
  font-size: clamp(20px, 3vw, 30px);
  color: var(--ink-soft);
}
.cover h3 {
  margin: 0;
  font-size: clamp(30px, 6vw, 62px);
  font-weight: 400;
  letter-spacing: 2px;
  color: var(--ink);
}
.map-overlay.visible .cover { animation: cover 1.4s ease forwards 0.05s; }

.map-head, .map-svg, .map-tour, .map-foot, .map-voice { opacity: 0; }
.map-overlay.visible .map-head,
.map-overlay.visible .map-svg,
.map-overlay.visible .map-tour,
.map-overlay.visible .map-foot,
.map-overlay.visible .map-voice { animation: inkIn 0.6s ease forwards 0.9s; }

.map-head { text-align: center; margin-bottom: 2px; }
.map-oath {
  margin: 0;
  font-family: "Caveat", "Segoe Script", cursive;
  font-size: clamp(15px, 2.4vw, 22px);
  color: #6b4a1c;
}
.map-head h2 {
  margin: 0;
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 400;
  letter-spacing: 1px;
}
.map-sub { margin: 2px 0 0; font-style: italic; font-size: 15px; color: var(--ink-soft); }

/* ---------- Mapa ---------- */
.map-svg { width: 100%; height: auto; display: block; }
.map-svg text { font-family: "Caveat", "Segoe Script", cursive; fill: var(--ink); }
.map-svg .t-title { font-size: 25px; font-weight: 700; }
.map-svg .t-sub { font-size: 17px; fill: var(--ink-soft); }
.map-svg .t-live { font-size: 16px; font-weight: 700; }
.map-svg .t-note { font-size: 17px; fill: var(--ink-faded); }
.map-svg .t-num { font-size: 17px; font-weight: 700; fill: var(--paper); }

.map-svg .room rect {
  fill: rgba(255, 244, 214, 0.55);
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-dasharray: var(--len, 800);
  stroke-dashoffset: var(--len, 800);
  fill-opacity: 0;
  transition: fill 0.5s ease, stroke-width 0.4s ease;
}
.map-svg .room.big rect {
  fill: rgba(255, 244, 214, 0.22);
  stroke-dasharray: 9 6;
  stroke-dashoffset: 0;
  fill-opacity: 1;
  opacity: 0;
}
.map-svg .room circle { fill: var(--ink); opacity: 0; }
.map-svg .room text { opacity: 0; }

.map-overlay.visible .map-svg .room rect {
  animation: rectDraw 0.6s ease forwards;
  animation-delay: calc(var(--i) * 0.26s + var(--t0));
}
.map-overlay.visible .map-svg .room.big rect {
  animation: inkIn 0.6s ease forwards;
  animation-delay: calc(var(--i) * 0.26s + var(--t0));
}
.map-overlay.visible .map-svg .room text,
.map-overlay.visible .map-svg .room circle {
  animation: inkIn 0.5s ease forwards;
  animation-delay: calc(var(--i) * 0.26s + var(--t0) + 0.3s);
}

/* sala donde esta parado el cambio: se oscurece y se engrosa el trazo */
.map-svg .room.active rect {
  fill: rgba(255, 224, 150, 0.9);
  stroke-width: 3.6;
}
.map-svg .room.big.active rect { fill: rgba(255, 224, 150, 0.32); stroke-width: 3; }

.map-svg .corridor {
  fill: none;
  stroke: #6b4a1c;
  stroke-width: 2.4;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  stroke-linecap: round;
}
.map-overlay.visible .map-svg .corridor { animation: draw 2.4s ease forwards calc(var(--t0) + 0.15s); }

.map-svg .note, .map-svg .deco { opacity: 0; }
.map-overlay.visible .map-svg .note,
.map-overlay.visible .map-svg .deco { animation: inkIn 0.6s ease forwards calc(var(--t0) + 1.6s); }

.map-svg .live.ok { fill: #1d5a0c; }
.map-svg .live.bad { fill: #a8280e; }

/* ---------- Huellas y nombres que caminan ---------- */
.map-svg .foot { opacity: 0; animation: footfade 6.5s ease-out forwards; }
.map-svg .foot ellipse { fill: var(--ink); }
.map-svg .foot.small ellipse { fill: #5a4220; }

.map-svg .walker-tag {
  font-size: 19px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #ecd9a8;
  stroke-width: 4px;
  stroke-linejoin: round;
}
.map-svg .walker-tag.idle { font-size: 16px; font-weight: 500; fill: var(--ink-faded); opacity: 0.9; }
.map-svg .walker-tag.main { fill: #7a1d0c; }

/* ---------- Recorrido narrado ---------- */
.map-tour {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}
#map-narration {
  flex: 1 1 340px;
  min-height: 2.5em;
  margin: 0;
  text-align: center;
  font-family: "Caveat", "Segoe Script", cursive;
  font-size: 22px;
  line-height: 1.15;
  color: var(--ink);
}
.tour-btn {
  background: rgba(255, 244, 214, 0.55);
  color: var(--ink);
  border: 1px solid #8a6a2f;
  border-radius: 6px;
  padding: 5px 14px;
  font-family: "IM Fell English", Georgia, serif;
  font-size: 15px;
  cursor: pointer;
}
.tour-btn:hover { background: rgba(255, 244, 214, 0.9); }

.map-foot {
  margin: 4px 0 0;
  text-align: center;
  font-family: "Caveat", "Segoe Script", cursive;
  font-size: 20px;
  color: var(--ink-soft);
}
.map-overlay.news #live-commit { animation: newsPulse 0.8s ease 5; }
.map-voice {
  margin: 0 0 4px;
  text-align: center;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-faded);
}

.map-close {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 4;
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid #8a6a2f;
  border-radius: 6px;
  padding: 4px 10px;
  font-family: "Caveat", "Segoe Script", cursive;
  font-size: 18px;
  cursor: pointer;
}
.map-close:hover { background: rgba(138, 106, 47, 0.2); }

/* ---------- Cierre: la tinta se desvanece ---------- */
.mischief {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Caveat", "Segoe Script", cursive;
  font-size: clamp(38px, 7vw, 78px);
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
}
.map-overlay.closing .map-head,
.map-overlay.closing .map-svg,
.map-overlay.closing .map-tour,
.map-overlay.closing .map-foot,
.map-overlay.closing .map-voice,
.map-overlay.closing .map-close {
  animation: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.map-overlay.closing .mischief { animation: mischief 1.2s ease forwards; }
.map-overlay.closing { opacity: 0; transition: opacity 0.35s ease 0.9s; }

/* ---------- Animaciones ---------- */
@keyframes unfold {
  0% { transform: scaleX(0.14) scaleY(0.55) rotate(-2deg); opacity: 0.2; filter: brightness(0.7); }
  55% { transform: scaleX(1.02) scaleY(0.55) rotate(0.4deg); opacity: 1; }
  100% { transform: scaleX(1) scaleY(1) rotate(0); filter: brightness(1); }
}
@keyframes cover {
  0% { opacity: 0; transform: translateY(8px); }
  20% { opacity: 1; transform: translateY(0); }
  78% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes rectDraw { to { stroke-dashoffset: 0; fill-opacity: 1; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes inkIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes footfade {
  0% { opacity: 0; }
  5% { opacity: 0.95; }
  55% { opacity: 0.55; }
  100% { opacity: 0; }
}
@keyframes mischief {
  0% { opacity: 0; }
  30% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes newsPulse {
  0%, 100% { color: inherit; }
  50% { color: #a8280e; }
}

@media (max-width: 720px) {
  .parchment { padding: 14px 12px 8px; }
  .map-head { padding-top: 32px; }
  .map-close { top: 8px; right: 8px; font-size: 16px; }
  .map-sub { font-size: 13px; }
  #map-narration { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  .map-overlay.visible .parchment,
  .map-overlay.visible .cover { animation: none; }
  .cover { display: none; }
  .map-head, .map-svg, .map-tour, .map-foot, .map-voice,
  .map-svg .note, .map-svg .deco,
  .map-svg .room text, .map-svg .room circle { opacity: 1; animation: none !important; }
  .map-svg .room rect { stroke-dashoffset: 0; fill-opacity: 1; animation: none !important; }
  .map-svg .room.big rect { opacity: 1; animation: none !important; }
  .map-svg .corridor { stroke-dashoffset: 0; animation: none !important; }
}

/* ---------- Celulares y pantallas tactiles ---------- */
.parchment { max-height: 95vh; max-height: 95dvh; }

@media (max-width: 760px) {
  .marauder-dock {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-width: none;
    justify-content: stretch;
  }
  .dock-btn {
    flex: 1 1 140px;
    min-height: 46px;
    font-size: 16px;
  }
  .dock-hint {
    flex: 1 1 100%;
    max-width: none;
    text-align: center;
    font-size: 17px;
  }
  .map-overlay { align-items: flex-start; }
  .parchment { width: 100vw; max-height: 100dvh; border-radius: 0; padding-bottom: 80px; }
  .map-svg .t-title { font-size: 24px; }
  .map-svg .walker-tag { font-size: 20px; }
  .map-svg .walker-tag.idle { font-size: 17px; }
  .tour-btn { min-height: 44px; flex: 1 1 40%; font-size: 16px; }
  #map-narration { order: -1; flex-basis: 100%; }
  .map-voice { display: none; }
  .brand { cursor: pointer; }
}

@media (pointer: coarse) {
  .map-close { min-height: 40px; padding: 6px 12px; }
}
