:root {
  --fondo: #14110f;
  --panel: #1f1a17;
  --panel-2: #2a231f;
  --borde: #3d332c;
  --texto: #ece3d6;
  --tenue: #a39584;
  --oro: #d4a24c;
  --oro-osc: #8f6a2c;
  --rojo: #c0503f;
  --verde: #6fae6a;
  --radio: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; color: var(--oro); margin: 0 0 .6em; font-weight: normal; }
h1 { font-size: 2rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

a { color: var(--oro); }

button, .boton {
  font: inherit;
  background: var(--panel-2);
  color: var(--texto);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: .55em 1em;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .4em;
}
button:hover, .boton:hover { border-color: var(--oro-osc); }
button.principal, .boton.principal { background: var(--oro); color: #1a140c; border-color: var(--oro); font-weight: 600; }
button.principal:hover { filter: brightness(1.08); }
button.peligro { color: var(--rojo); }
button:disabled { opacity: .5; cursor: default; }
button.icono { padding: .35em .6em; }

input, select {
  font: inherit;
  background: var(--fondo);
  color: var(--texto);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: .55em .7em;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--oro-osc); outline-offset: 1px; }

label { display: block; margin-bottom: .8em; color: var(--tenue); font-size: .9rem; }
label > input, label > select { margin-top: .3em; color: var(--texto); }

.panel {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 1rem;
}

.tenue { color: var(--tenue); font-size: .9rem; }
.error { color: var(--rojo); min-height: 1.4em; }
.fila { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.oculto { display: none !important; }

/* ---------- Portada ---------- */
.portada { max-width: 880px; margin: 0 auto; padding: 2rem 16px; }
.portada > header { text-align: center; margin-bottom: 2rem; }
.portada .columnas { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.codigo-entrada { text-transform: uppercase; letter-spacing: .3em; font-size: 1.4rem; text-align: center; }
.mis-partidas { list-style: none; padding: 0; margin: 0; }
.mis-partidas li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5em 0; border-top: 1px solid var(--borde); }

/* ---------- Escenario (jugador y pantalla) ---------- */
.escenario {
  position: fixed;
  inset: 0;
  background: #000 center / contain no-repeat;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: background-image .6s;
}
.escenario .titulo-escena {
  margin-bottom: 4vh;
  padding: .3em 1em;
  background: rgba(0,0,0,.55);
  border-radius: var(--radio);
  font-family: Georgia, serif;
  font-size: clamp(1.1rem, 3vw, 2rem);
  color: var(--oro);
  transition: opacity .6s;
}
.escenario .vacio { position: absolute; inset: 0; display: grid; place-items: center; color: var(--tenue); text-align: center; padding: 16px; }
.barra-flotante {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: 10px;
  display: flex;
  gap: .4rem;
  z-index: 5;
}
.barra-flotante button { background: rgba(20,17,15,.75); backdrop-filter: blur(4px); }

.velo {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(10,8,7,.94);
  display: grid; place-items: center;
  padding: 16px;
}
.velo .panel { width: min(420px, 100%); }

/* ---------- Máster ---------- */
.master { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; padding: 1rem; min-height: 100vh; }
.master aside { display: flex; flex-direction: column; gap: 1rem; }
.master main { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.qr { background: #fff; border-radius: var(--radio); padding: 8px; width: 100%; max-width: 220px; display: block; margin: .5rem auto; }
.codigo-grande { font-size: 2rem; letter-spacing: .25em; text-align: center; color: var(--oro); font-family: ui-monospace, monospace; }
.lista-conectados { list-style: none; padding: 0; margin: 0; }
.lista-conectados li { padding: .3em 0; display: flex; align-items: center; gap: .5em; }
.lista-conectados li::before { content: ""; width: .55em; height: .55em; border-radius: 50%; background: var(--verde); }

.vista-previa {
  aspect-ratio: 16 / 9;
  background: #000 center / contain no-repeat;
  border-radius: var(--radio);
  border: 1px solid var(--borde);
  position: relative;
  display: grid;
  place-items: center;
  color: var(--tenue);
}
.vista-previa .etiqueta { position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.6); padding: .2em .6em; border-radius: 6px; color: var(--oro); }

.escenas { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem; }
.escena {
  background: var(--panel-2);
  border: 2px solid var(--borde);
  border-radius: var(--radio);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.escena.activa { border-color: var(--oro); box-shadow: 0 0 0 3px rgba(212,162,76,.25); }
.escena .miniatura { aspect-ratio: 16/9; background: #000 center / cover no-repeat; cursor: pointer; display: grid; place-items: center; color: var(--tenue); font-size: .85rem; }
.escena .cuerpo { padding: .5rem; display: flex; flex-direction: column; gap: .35rem; }
.escena .nombre { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.escena .musica { font-size: .8rem; color: var(--tenue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.escena .acciones { display: flex; gap: .3rem; flex-wrap: wrap; }
.escena .acciones button { padding: .25em .5em; font-size: .85rem; }

.nueva-escena { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: .6rem; align-items: end; }
.nueva-escena label { margin: 0; }
.archivo-elegido { font-size: .8rem; color: var(--tenue); margin-top: .2em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.audio-control input[type=range] { width: 140px; padding: 0; accent-color: var(--oro); }

dialog { background: var(--panel); color: var(--texto); border: 1px solid var(--borde); border-radius: var(--radio); width: min(460px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }

@media (max-width: 760px) {
  .master { grid-template-columns: 1fr; padding: 16px; }
  .nueva-escena { grid-template-columns: 1fr; }
}

/* ---------- Mapa ---------- */
.mapa {
  position: relative;
  margin: 0 auto;
  background: #2b2520 center / 100% 100% no-repeat;
  border-radius: 6px;
  touch-action: pan-x pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.mapa::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(to right, rgba(0,0,0,.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0,0,0,.28) 1px, transparent 1px);
  background-size: calc(100% / var(--cols)) calc(100% / var(--filas));
  pointer-events: none;
}
.mapa-capa { position: absolute; inset: 0; }
.ficha { position: absolute; transition: left .25s, top .25s; z-index: 1; }
.ficha.arrastrando { transition: none; z-index: 5; opacity: .85; }
.ficha .disco {
  width: 84%; height: 84%; margin: 8%;
  border-radius: 50%;
  background: #3a302a center / cover no-repeat;
  border: 3px solid var(--oro);
  box-shadow: 0 2px 6px rgba(0,0,0,.6);
  display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: clamp(9px, 1.6vw, 18px);
  overflow: hidden;
  position: relative;
}
.ficha.monstruo .disco { border-color: var(--rojo); background-color: #4a2420; }
.ficha.mia .disco { border-color: #5fb3ff; }
.ficha.turno .disco { box-shadow: 0 0 0 3px #fff, 0 0 16px 6px rgba(255,220,120,.9); }
.ficha.seleccionada .disco { outline: 3px dashed #fff; outline-offset: 2px; }
.ficha.derrotado { filter: grayscale(1) brightness(.55); }
.ficha.derrotado .disco::after { content: "✕"; position: absolute; font-size: 2em; color: var(--rojo); }
.ficha.oculta { opacity: .45; }
.ficha.movible { cursor: grab; touch-action: none; }
.ficha .rotulo {
  position: absolute; left: 50%; top: 100%; transform: translate(-50%, -2px);
  white-space: nowrap; font-size: clamp(8px, 1.1vw, 12px);
  background: rgba(0,0,0,.7); padding: 0 .35em; border-radius: 4px; pointer-events: none;
}

.barra-pg { height: 8px; background: #000; border-radius: 4px; overflow: hidden; }
.barra-pg > div { height: 100%; transition: width .3s; }
.cifras-pg { font-size: .85rem; margin-top: 2px; }
.cifras-pg .temp { color: #5fb3ff; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { font-size: .78rem; padding: .15em .55em; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--borde); }
.chip.activo { background: var(--rojo); border-color: var(--rojo); color: #fff; }
button.chip { cursor: pointer; }

textarea { font: inherit; background: var(--fondo); color: var(--texto); border: 1px solid var(--borde); border-radius: var(--radio); padding: .55em .7em; width: 100%; margin-top: .3em; resize: vertical; }

/* ---------- Máster: pestañas y listas ---------- */
.pestanas { display: flex; gap: .4rem; flex-wrap: wrap; }
.pestanas button { border-radius: var(--radio) var(--radio) 0 0; }
.pestanas button.activa { background: var(--oro); color: #1a140c; border-color: var(--oro); }
.punto { display: inline-block; width: .55em; height: .55em; border-radius: 50%; background: var(--rojo); }
main > [data-vista] { display: flex; flex-direction: column; gap: 1rem; }
main > [data-vista].oculto { display: none; }

.lista-jugadores { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .6rem; }
.lista-jugadores li { border-left: 3px solid var(--verde); padding-left: .5rem; }
.lista-jugadores li.fuera { border-color: var(--borde); opacity: .65; }
.lista-jugadores select { margin-top: .25rem; padding: .3em .5em; }

.notas { white-space: pre-wrap; background: var(--panel-2); border-left: 3px solid var(--oro); padding: .6rem .8rem; border-radius: 6px; margin-top: .6rem; font-size: .92rem; }

.rejilla-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; align-items: end; }
.rejilla-form label { margin: 0; }

.tarjetas-pj { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: .8rem; }
.tarjeta-pj { display: flex; gap: .7rem; background: var(--panel-2); border: 1px solid var(--borde); border-radius: var(--radio); padding: .7rem; }
.tarjeta-pj .cuerpo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .25rem; }
.retrato { width: 72px; height: 72px; flex: none; border-radius: 50%; background: #3a302a center / cover no-repeat; border: 2px solid var(--oro); display: grid; place-items: center; font-size: 1.6rem; }
.control-pg { margin-top: .3rem; }
.control-pg input { padding: .35em .5em; }
.control-pg button { padding: .35em .6em; font-size: .85rem; }

.lista-importar { display: flex; flex-direction: column; }
.fila-ficha { padding: .45em 0; border-top: 1px solid var(--borde); }
.fila-ficha > span:first-child { min-width: 9em; font-weight: 600; }
.fila-ficha > span.tenue { flex: 1; }

.lista-encuentros { display: flex; flex-direction: column; gap: 1rem; }
.encuentro { display: flex; gap: 1rem; flex-wrap: wrap; }
.encuentro .cuerpo { flex: 1; min-width: 260px; }
.miniatura-mapa { width: 220px; aspect-ratio: 16/10; border-radius: 6px; background: #2b2520 center / cover no-repeat; display: grid; place-items: center; color: var(--tenue); flex: none; }
.lista-monstruos { list-style: none; padding: 0; margin: .4rem 0; display: flex; flex-direction: column; gap: .3rem; }
.lista-monstruos input { padding: .3em .4em; }
.lista-monstruos > li { flex-wrap: nowrap; align-items: flex-start; }
.lista-monstruos > li > a { flex: 0 0 11em; overflow-wrap: anywhere; padding-top: .35em; }
.resumen-monstruo { flex: 1; min-width: 0; font-size: .85rem; line-height: 1.35; padding-top: .3em; }
.resumen-monstruo .ataque-resumen { overflow-wrap: anywhere; }
.lista-monstruos .quitar { margin-left: auto; flex: none; }
.renombrar { margin-left: .4em; padding: .1em .35em; font-size: .8rem; background: transparent; border-color: transparent; vertical-align: middle; }
.renombrar:hover { border-color: var(--borde); }
.buscador { margin-top: .5rem; }
.resultados { max-height: 260px; overflow: auto; margin-top: .4rem; }
.fila-monstruo { padding: .3em 0; border-top: 1px solid var(--borde); }
.fila-monstruo > a { min-width: 9em; }
.fila-monstruo > .tenue { flex: 1; }
.fila-monstruo button { padding: .25em .6em; font-size: .85rem; }
details summary { cursor: pointer; color: var(--oro); }
.atributos { display: grid; grid-template-columns: repeat(6, 1fr); text-align: center; gap: .3rem; margin: .6rem 0; font-size: .9rem; }
#dialogo-monstruo { width: min(640px, calc(100% - 32px)); }
#dialogo-monstruo p { margin: .35em 0; font-size: .92rem; }

/* ---------- Máster: combate ---------- */
.combate { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1rem; align-items: start; }
.marco-mapa { width: 100%; height: min(72vh, 800px); display: flex; align-items: center; justify-content: center; }
.fila-iniciativa { padding: .25em 0; }
.fila-iniciativa input { padding: .3em .4em; }
.fila-iniciativa.monstruo span:nth-child(2) { color: #e8a598; }
.orden { list-style: none; padding: 0; margin: .6rem 0 0; display: flex; flex-direction: column; gap: .25rem; }
.orden li { display: flex; gap: .5rem; align-items: center; padding: .35em .5em; border-radius: 6px; background: var(--panel-2); cursor: pointer; border: 1px solid transparent; }
.orden li.turno { border-color: var(--oro); background: #3b2f1c; }
.orden li.derrotado { opacity: .45; text-decoration: line-through; }
.orden li.oculta { font-style: italic; opacity: .7; }
.orden li.seleccionada { outline: 1px dashed #fff; }
.orden .ini { width: 2em; text-align: center; font-weight: 700; color: var(--oro); }
.orden .nombre { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.orden .pg-mini { font-size: .8rem; color: var(--tenue); }
.detalle { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--borde); display: flex; flex-direction: column; gap: .35rem; }

@media (max-width: 1100px) {
  .combate { grid-template-columns: 1fr; }
  .marco-mapa { height: 60vh; }
}

/* ---------- Jugador y pantalla: combate ---------- */
.vista-combate {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 8px 96px;
  background: var(--fondo);
}
.cabecera-combate { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; padding: 4px 250px .5rem 4px; min-height: 48px; }
@media (max-width: 600px) { .cabecera-combate { padding-right: 4px; padding-top: 52px; } }
.aviso-turno { font-family: Georgia, serif; font-size: clamp(1rem, 2.6vw, 1.6rem); color: var(--oro); }
.aviso-turno.mio { color: #fff; background: var(--oro-osc); padding: .15em .8em; border-radius: var(--radio); animation: latido 1.4s ease-in-out infinite; }
@keyframes latido { 50% { box-shadow: 0 0 18px 4px rgba(212,162,76,.7); } }
.vista-combate .marco-mapa { flex: 1; min-height: 0; height: auto; }
.orden-tira { display: flex; gap: .3rem; overflow-x: auto; padding: .5rem 0 0; justify-content: safe center; }
.orden-tira .chip { white-space: nowrap; }
.chip.enemigo { color: #e8a598; }
.chip.activo.enemigo { color: #fff; }

.mi-tarjeta {
  position: fixed; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom));
  display: flex; gap: .7rem; align-items: center;
  background: rgba(31,26,23,.95); border: 1px solid var(--borde); border-radius: var(--radio);
  padding: .5rem .7rem; z-index: 4;
  max-width: 560px; margin: 0 auto;
}
.mi-tarjeta .retrato { width: 56px; height: 56px; font-size: 1.3rem; }
.mi-tarjeta .cuerpo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .2rem; }
.escenario:not(.oculto) ~ .mi-tarjeta { opacity: .92; }

.aviso-flotante {
  position: fixed; left: 50%; top: 18%; transform: translateX(-50%); z-index: 20;
  background: var(--panel-2); border: 1px solid var(--oro-osc); padding: .6em 1.1em; border-radius: var(--radio);
  box-shadow: 0 6px 24px rgba(0,0,0,.6); max-width: calc(100% - 32px); text-align: center;
}

.lista-elegir { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .5rem; }
.opcion-pj { justify-content: flex-start; text-align: left; padding: .5rem; }
.opcion-pj .retrato { width: 52px; height: 52px; font-size: 1.2rem; }

.mi-tarjeta:not(.oculto) ~ .escenario .titulo-escena, body:has(.mi-tarjeta:not(.oculto)) .escenario .titulo-escena { margin-bottom: 110px; }
.marco-mapa.ampliado { overflow: auto; justify-content: flex-start; align-items: flex-start; -webkit-overflow-scrolling: touch; }
.marco-mapa.ampliado .mapa { flex: none; }
.marco-mapa.con-zoom { overflow: auto; justify-content: flex-start; align-items: flex-start; -webkit-overflow-scrolling: touch; }
.marco-mapa.con-zoom .mapa { flex: none; }
.mandos-zoom { position: absolute; z-index: 6; display: flex; gap: 2px; background: rgba(20, 16, 14, .82);
  border: 1px solid var(--borde); border-radius: 8px; padding: 2px; }
.mandos-zoom button { padding: .2em .55em; min-width: 2.2em; font-size: .95rem; background: transparent; border-color: transparent; }
.mandos-zoom button:hover { border-color: var(--borde); }
.mandos-zoom .nivel { font-size: .78rem; min-width: 3.6em; color: var(--tenue); }

.rejilla-avatares { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin: .6rem 0; }
.opcion-avatar { aspect-ratio: 1; padding: 0; border-radius: 50%; background: #000 center / cover no-repeat; border: 3px solid var(--borde); }
.opcion-avatar.elegido, .opcion-avatar:hover { border-color: var(--oro); }

/* ---------- Niebla, áreas y medidas ---------- */
.mapa-areas { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.mapa-niebla { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: .55; z-index: 1; filter: blur(3px); }
.mapa-niebla.opaca { opacity: 1; filter: blur(4px); }
.mapa-ruta { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; overflow: visible; }
.mapa-ruta polyline { fill: none; stroke: #ffd76a; stroke-width: .09; stroke-dasharray: .25 .15; stroke-linecap: round; stroke-linejoin: round; opacity: .9; filter: drop-shadow(0 0 .05px #000); }
.mapa.con-pincel { cursor: crosshair; }
.mapa-capa { z-index: 2; }
.mapa-areas { z-index: 0; }
.ficha.mia, .ficha.turno { z-index: 3; }
.area { fill: rgba(255, 120, 40, .28); stroke: #ff9a3c; stroke-width: .06; }
.area.de-jugador { fill: rgba(80, 160, 255, .26); stroke: #5fb3ff; }
.area.editable { cursor: move; }
.area.seleccionada { stroke: #fff; stroke-width: .1; stroke-dasharray: .3 .2; }
.origen-area { fill: #fff; pointer-events: none; }
.nombre-area { font-size: .55px; fill: #fff; text-anchor: middle; paint-order: stroke; stroke: rgba(0,0,0,.8); stroke-width: .12px; pointer-events: none; }
.ficha.en-area .disco { box-shadow: 0 0 0 3px #ff9a3c, 0 2px 6px rgba(0,0,0,.6); }
.medida {
  position: absolute; z-index: 6; transform: translate(-50%, -120%); pointer-events: none;
  background: rgba(0,0,0,.85); color: #fff; padding: .15em .5em; border-radius: 6px; font-size: .8rem; white-space: nowrap;
}
.medida.corriendo { background: #8a6a12; }
.medida.excedido { background: var(--rojo); }

.salvaciones-muerte { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.salvaciones-muerte .marcas { letter-spacing: .15em; font-size: 1.05rem; }
.salvaciones-muerte .marcas .ok { color: var(--verde); }
.salvaciones-muerte .marcas .ko { color: var(--rojo); }
.salvaciones-muerte button { padding: .3em .6em; font-size: .85rem; }

.recursos { display: flex; flex-direction: column; gap: .35rem; }
.recurso { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.recurso .nombre-recurso { flex: 1; min-width: 4.5em; font-size: .9rem; }
.casillas { display: flex; gap: .25rem; }
.casilla { width: 1.5em; height: 1.5em; border-radius: 4px; border: 2px solid var(--oro-osc); background: transparent; padding: 0; cursor: pointer; }
.casilla.gastada { background: var(--oro); border-color: var(--oro); }

.tabla-bonos { display: grid; grid-template-columns: 1fr auto; gap: .1rem .8rem; font-size: .9rem; }
.tabla-bonos .competente { color: var(--oro); }
.seccion-ficha { white-space: pre-wrap; font-size: .9rem; line-height: 1.45; }
.seccion-ficha summary { font-family: Georgia, serif; font-size: 1rem; margin: .4rem 0; }

.pestanas-ficha { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .6rem; }
.pestanas-ficha button { padding: .3em .7em; font-size: .85rem; }
.pestanas-ficha button.activa { background: var(--oro); color: #1a140c; border-color: var(--oro); }
#dialogo-ficha, #dialogo-ficha-completa { width: min(640px, calc(100% - 24px)); max-height: 88vh; }

.registro { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column-reverse; gap: .2rem; max-height: 65vh; overflow: auto; }
.registro li { font-size: .9rem; padding: .25em .4em; border-radius: 4px; }
.registro li:nth-child(odd) { background: var(--panel-2); }
.registro .hora { color: var(--tenue); font-size: .78rem; margin-right: .5em; font-variant-numeric: tabular-nums; }
.registro li.privado { border-left: 3px solid var(--oro-osc); }

.biblioteca { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; max-height: 60vh; overflow: auto; margin: .6rem 0; }
.item-biblioteca { background: var(--panel-2); border: 2px solid var(--borde); border-radius: var(--radio); padding: .4rem; display: flex; flex-direction: column; gap: .3rem; cursor: pointer; font-size: .8rem; text-align: left; color: var(--texto); }
.item-biblioteca:hover { border-color: var(--oro); }
.item-biblioteca .vista { aspect-ratio: 16/10; background: #000 center / cover no-repeat; border-radius: 6px; display: grid; place-items: center; font-size: 1.6rem; }
.item-biblioteca .nombre-item { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#dialogo-biblioteca { width: min(760px, calc(100% - 24px)); }
.elegido-biblioteca { font-size: .8rem; color: var(--oro); margin-top: .2em; }
.boton-biblioteca { font-size: .8rem; padding: .25em .6em; margin-top: .3em; }

.herramientas-mapa { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--borde); }
.herramientas-mapa .fila button { padding: .3em .6em; font-size: .85rem; }
.herramientas-mapa button.activo { background: var(--oro); color: #1a140c; border-color: var(--oro); }
.herramientas-mapa select, .herramientas-mapa input[type=number], .herramientas-mapa input[type=text] { padding: .3em .5em; width: auto; }
.panel-area { position: fixed; left: 8px; right: 8px; bottom: 110px; z-index: 8; max-width: 520px; margin: 0 auto; background: rgba(31,26,23,.97); border: 1px solid var(--oro-osc); border-radius: var(--radio); padding: .7rem; display: flex; flex-direction: column; gap: .5rem; }
.panel-area .fila > * { flex: 1; }
.panel-area select, .panel-area input { padding: .35em .5em; }
.mapa-capa { pointer-events: none; }
.mapa-capa .ficha { pointer-events: auto; }
#controles-niebla.apagado { opacity: .5; }
button.activo { background: var(--oro); color: #1a140c; border-color: var(--oro); }
.mi-tarjeta .salvaciones-muerte { margin-top: .3rem; }
.mi-tarjeta .salvaciones-muerte button { padding: .25em .5em; font-size: .8rem; }

/* ---------- Muros, puertas y trampas ---------- */
.mapa-elementos { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; overflow: visible; }
.mapa-elementos .elemento-mapa { pointer-events: auto; cursor: pointer; }
.mapa-elementos .muro.invisible { stroke: #7fd3ff; stroke-dasharray: .15 .12; stroke-width: .1; opacity: .9; }
.mapa-elementos .muro { stroke: #e04a3a; stroke-width: .14; stroke-linecap: round; opacity: .85; }
.mapa-elementos .puerta { stroke: #a0642a; stroke-width: .3; stroke-linecap: butt; }
.mapa-elementos .puerta.abierta { stroke: #6fae6a; stroke-dasharray: .12 .12; stroke-width: .18; }
.mapa-elementos .trampa rect { fill: rgba(224, 74, 58, .75); stroke: #fff; stroke-width: .05; }
.mapa-elementos .trampa.escondida rect { fill: rgba(224, 74, 58, .3); stroke-dasharray: .1 .08; }
.mapa-elementos .trampa text { font-size: .6px; font-weight: 700; fill: #fff; text-anchor: middle; pointer-events: none; }
.mapa-elementos .inicio-muro { fill: #ffdc6b; }
.fila-ataque input { padding: .3em .45em; }
.fila-ataque .n { flex: 1; min-width: 8em; }
.resultado-ataque p { margin: .4em 0; }
.lista-botin { list-style: none; padding: 0; margin: .5rem 0; display: flex; flex-direction: column; gap: .3rem; }
.lista-botin input, .lista-botin select { padding: .25em .4em; width: auto; }
.lista-botin .nombre-objeto { flex: 1; min-width: 8em; }
.nuevo-objeto { flex: 1; }
.oro input { padding: .3em .4em; }
.tarjeta-pnj {
  position: fixed; left: 50%; top: 12%; transform: translateX(-50%); z-index: 9;
  width: min(420px, calc(100% - 32px)); background: rgba(31,26,23,.96); border: 2px solid var(--oro-osc);
  border-radius: var(--radio); padding: 1rem; display: flex; gap: 1rem; align-items: center; box-shadow: 0 10px 40px rgba(0,0,0,.7);
}
.tarjeta-pnj .retrato { width: 110px; height: 110px; font-size: 2.4rem; }
.tarjeta-pnj h2 { margin: 0 0 .3rem; }
.tarjeta-pnj p { margin: 0; white-space: pre-wrap; font-size: .95rem; }
@media (min-width: 900px) { .tarjeta-pnj { width: 560px; } .tarjeta-pnj .retrato { width: 160px; height: 160px; } }
.lista-pnj, .lista-sonidos { display: flex; flex-direction: column; gap: .5rem; }
.pnj-fila { display: flex; gap: .6rem; align-items: center; }
.pnj-fila .retrato { width: 52px; height: 52px; font-size: 1.2rem; }
.pnj-fila .cuerpo { flex: 1; min-width: 0; }
.botones-sonido { display: flex; flex-wrap: wrap; gap: .5rem; }
.botones-sonido button { padding: .3em .7em; font-size: .85rem; }
.ambiente-activo input[type=range] { width: 120px; padding: 0; accent-color: var(--oro); }
.ataques-monstruo { display: flex; flex-direction: column; gap: .35rem; }
.ataques-monstruo select, .estado-nuevo input, .estado-nuevo select { padding: .3em .4em; width: auto; }

/* El mapa se queda a la vista; la columna de la derecha se desplaza por su cuenta. */
.combate > .zona-mapa { position: sticky; top: 1rem; }
.combate .zona-iniciativa { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; overscroll-behavior: contain; }
@media (max-width: 1100px) {
  .combate .zona-mapa, .combate .zona-iniciativa { position: static; max-height: none; }
}
.mini-monstruo { width: 38px; height: 38px; padding: 0; border-radius: 50%; border: 2px solid var(--rojo); background: #000 center / cover no-repeat; flex: none; }
.mini-monstruo:hover { border-color: var(--oro); }
.control-area { cursor: pointer; }
.control-area circle { stroke: #fff; stroke-width: .06; }
.control-area text { fill: #fff; text-anchor: middle; font-weight: 700; pointer-events: none; }
.control-area.borrar-area circle { fill: var(--rojo); }
.control-area.girar-area circle { fill: var(--oro-osc); }
.control-area.girar-area { cursor: grab; }

.grupo-sonidos { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; width: 100%; }
.grupo-sonidos > .tenue { min-width: 6.5em; font-size: .8rem; }
.grupo-sonidos button { padding: .3em .7em; font-size: .85rem; }
.rejilla-ambientes { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .2rem .6rem; margin-top: .4rem; }

/* ---------- Móvil: botón flotante y hojas ---------- */
.fab { position: fixed; right: 12px; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 15; display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; }
.fab.oculto { display: none; }
.fab-boton {
  width: 58px; height: 58px; border-radius: 50%; justify-content: center; font-size: 1.6rem; padding: 0;
  background: var(--oro); color: #1a140c; border: none; box-shadow: 0 6px 20px rgba(0,0,0,.6);
}
.fab-menu { display: flex; flex-direction: column; align-items: flex-end; gap: .45rem; }
.fab-menu button {
  border-radius: 999px; padding: .35em .45em .35em 1em; gap: .6em; justify-content: flex-end;
  background: rgba(31,26,23,.97); box-shadow: 0 4px 14px rgba(0,0,0,.55); font-size: .95rem;
}
.fab-menu button i { font-style: normal; width: 2.1em; height: 2.1em; display: grid; place-items: center; border-radius: 50%; background: var(--panel-2); }
.fab-menu button.oculto { display: none; }
.hoja {
  position: fixed; left: 8px; right: 8px; bottom: calc(160px + env(safe-area-inset-bottom)); top: auto; margin: 0 auto;
  width: auto; max-width: 560px; max-height: calc(100vh - 230px); overflow-y: auto; z-index: 12;
  background: rgba(31,26,23,.98); border: 1px solid var(--oro-osc); border-radius: var(--radio); padding: .8rem;
  box-shadow: 0 10px 40px rgba(0,0,0,.7);
}
dialog.hoja { color: var(--texto); }
dialog.hoja:not([open]) { display: none; }
.vista-combate { padding-right: 8px; }
.cabecera-combate { padding-right: 4px !important; padding-top: 4px !important; }

/* Mapas con ambientación: roca y muros con textura */
.mapa-elementos .macizo { pointer-events: none; }
.mapa-elementos .macizo-sombra { fill: rgba(0,0,0,.38); pointer-events: none; }
.mapa-elementos .muro-borde { stroke: #120c08; stroke-width: .5; stroke-linecap: square; pointer-events: none; }
.mapa-elementos .muro.con-textura { stroke-width: .38; stroke-linecap: square; opacity: 1; }
.mapa-elementos .puerta { stroke: #8a5a2b; }

/* Decorados (muebles, árboles, rocas…) */
.mapa-decorados { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.mapa-decorados .decorado { position: absolute; image-rendering: pixelated; pointer-events: none; transform-origin: center; filter: drop-shadow(0 2px 2px rgba(0,0,0,.45)); }
.mapa-decorados.editable .decorado { pointer-events: auto; cursor: move; }
.mapa-decorados .decorado.seleccionado { outline: 2px dashed #fff; outline-offset: 1px; }
.control-decorado { position: absolute; z-index: 4; width: 26px; height: 26px; padding: 0; border-radius: 50%; justify-content: center; transform: translate(-50%, -50%); pointer-events: auto; font-size: .9rem; border: 2px solid #fff; color: #fff; }
.control-decorado.borrar { background: var(--rojo); }
.control-decorado.girar { background: var(--oro-osc); }

.paleta-decorados { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: .3rem; max-height: 180px; overflow: auto; }
.paleta-decorados .pieza { padding: 3px; aspect-ratio: 1; justify-content: center; background: #3a3530; }
.paleta-decorados .pieza img { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
.paleta-decorados .pieza.activo { outline: 3px solid var(--oro); }

/* Puertas con tablones; abiertas se ven giradas sobre la bisagra */
.mapa-elementos .puerta { stroke-width: .34; stroke-linecap: butt; }
.mapa-elementos .puerta.abierta { stroke-dasharray: none; opacity: 1; }
.mapa-elementos .hueco-puerta { stroke: rgba(0,0,0,.35); stroke-width: .12; stroke-dasharray: .12 .1; pointer-events: none; }
.mapa-elementos .zona-puerta { stroke: transparent; stroke-width: .5; }
.mapa-elementos .resalte-seleccion { stroke: #fff; stroke-width: .6; stroke-opacity: .35; stroke-dasharray: .2 .15; pointer-events: none; }
.mapa-elementos .trampa.seleccionada rect { stroke: #fff; stroke-width: .12; }
.mapa-controles { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.control-elemento { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; padding: .15em .55em; border-radius: 999px;
  font-size: .8rem; border: 2px solid #fff; color: #fff; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.6); }
.control-elemento.borrar { background: var(--rojo); width: 28px; height: 28px; padding: 0; justify-content: center; }
.control-elemento.puerta { background: var(--oro-osc); }

/* Editor: vista previa, imán y ventanas */
.mapa-elementos .vista-previa-muro { stroke: #ffdc6b; stroke-width: .12; stroke-dasharray: .25 .15; pointer-events: none; }
.mapa-elementos .iman-muro { fill: none; stroke: #ffdc6b; stroke-width: .07; pointer-events: none; }
.mapa-elementos .iman-muro-enganchado { fill: #6fd36a; stroke: #fff; stroke-width: .05; pointer-events: none; }
.mapa-elementos .vista-previa-puerta { stroke: #ffdc6b; stroke-width: .3; stroke-linecap: round; pointer-events: none; }
.mapa-elementos .muro-objetivo { stroke: #6fd4ff; stroke-width: .5; stroke-opacity: .5; pointer-events: none; }
.mapa-elementos .puerta.ventana { stroke: #5a4632; stroke-width: .16; }
.mapa-elementos .cristal { stroke: #9fdcff; stroke-width: .12; stroke-opacity: .85; pointer-events: none; }
.mapa-elementos .puerta.ventana.abierta { stroke: #8a6a44; }

/* ---------- Combate: mapa + fichas de iniciativa debajo; columna de herramientas ---------- */
.columna-combate { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.columna-combate .marco-mapa { height: min(62vh, 760px); }
.tira-iniciativa { display: flex; flex-direction: column; gap: .6rem; }
.tira-iniciativa .fila { gap: .5rem; }
.fichas-iniciativa { display: flex; gap: .6rem; overflow-x: auto; padding-bottom: .3rem; }
.ficha-ini {
  flex: none; width: 128px; background: var(--panel-2); border: 2px solid var(--borde); border-radius: var(--radio);
  padding: .45rem; display: flex; flex-direction: column; gap: .25rem; cursor: pointer;
}
.ficha-ini.monstruo { border-color: #6a2a24; }
.ficha-ini.pj { border-color: var(--oro-osc); }
.ficha-ini.turno { border-color: var(--oro); box-shadow: 0 0 0 3px rgba(212,162,76,.35); background: #3b2f1c; }
.ficha-ini.seleccionada { outline: 2px dashed #fff; outline-offset: 2px; }
.ficha-ini.derrotado { opacity: .45; filter: grayscale(1); }
.ficha-ini.oculta { opacity: .65; border-style: dashed; }
.ficha-ini .cabeza { display: flex; justify-content: space-between; align-items: center; }
.ficha-ini .retrato { width: 44px; height: 44px; font-size: 1rem; }
.ficha-ini .ini { font-size: 1.35rem; font-weight: 700; color: var(--oro); width: 2.6em; text-align: center; }
.ficha-ini input.ini { padding: .1em .2em; font-size: 1.1rem; }
.ficha-ini .nombre { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ficha-ini .cifras-pg { font-size: .75rem; }
.ficha-ini .chips .chip { font-size: .65rem; }

/* ---------- Sonido en combate ---------- */
.pestanas-sonido { display: flex; gap: .3rem; }
.pestanas-sonido button { flex: 1; padding: .35em .4em; font-size: .85rem; justify-content: center; }
.pestanas-sonido button.activo { background: var(--oro); color: #1a140c; border-color: var(--oro); }
.bloque-sonido { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: .3rem; }
.grupo-favoritos { display: flex; flex-direction: column; gap: .2rem; padding-bottom: .3rem; border-bottom: 1px solid var(--borde); }
.grupo-sonido summary { font-size: .85rem; }
.fila-sonido { display: flex; gap: .3rem; align-items: center; margin: .15rem 0; }
.fila-sonido .tocar { flex: 1; padding: .3em .6em; font-size: .85rem; justify-content: flex-start; }
.fila-sonido.sonando .tocar { border-color: var(--verde); background: #23331f; }
.fila-sonido .estrella { padding: .2em .45em; color: var(--tenue); background: transparent; border-color: transparent; font-size: 1.05rem; }
.fila-sonido .estrella.activa { color: var(--oro); }
#sonando-ahora .fila { gap: .4rem; }

.mapa-elementos .muro.natural { stroke: rgba(255,255,255,.45); stroke-width: .07; stroke-dasharray: .15 .12; }

/* Retrato que el máster puede cambiar con un clic. */
.retrato.cambiable { cursor: pointer; position: relative; }
.retrato.cambiable::after { content: '📷'; position: absolute; right: -4px; bottom: -4px; font-size: .9rem; background: var(--fondo, #221b16); border: 1px solid var(--oro); border-radius: 50%; width: 1.6rem; height: 1.6rem; display: grid; place-items: center; opacity: .75; }
.retrato.cambiable:hover::after { opacity: 1; }

.lista-ataques { margin: .3rem 0; padding-left: 1.1rem; display: grid; gap: .45rem; }
.lista-ataques li span { display: block; }
.lista-ataques .datos-hechizo { font-size: .8rem; }
.seccion-ficha .lista-hechizos { white-space: normal; }
.lista-hechizos h3 { font-family: Georgia, serif; color: var(--oro); font-size: 1rem; margin: .9rem 0 .2rem; border-bottom: 1px solid #ffffff22; padding-bottom: .15rem; }
.lista-hechizos h4 { font-size: .95rem; margin: .6rem 0 .1rem; }
.lista-hechizos ul { margin: 0; padding-left: 1.1rem; display: grid; gap: .2rem; }
.lista-hechizos .datos-hechizo { list-style: none; margin-left: -1.1rem; opacity: .7; font-size: .82rem; }

/* Barra lateral de combate: «Añadir monstruo» arriba y aire al final para que nada quede pegado al borde. */
.combate .zona-iniciativa { padding-bottom: 2.5rem; }
.anadir-combate { margin-bottom: .5rem; }
.anadir-combate > summary { font-weight: bold; color: var(--oro); cursor: pointer; }
#detalle .retrato { width: 52px; height: 52px; font-size: 1.2rem; }
#detalle { margin-top: .5rem; }
.miniatura-mapa:has(.miniatura-plano) { position: relative; overflow: hidden; }
.miniatura-plano svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Pestaña Enemigos */
.rejilla-enemigos { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; margin: .5rem 0 1.2rem; }
.tarjeta-enemigo { display: flex; flex-direction: column; gap: .25rem; padding: .6rem; border: 1px solid var(--borde); border-radius: 8px; background: #ffffff08; }
.tarjeta-enemigo.propia { border-color: var(--oro); }
.imagen-enemigo { aspect-ratio: 1; width: 100%; border-radius: 6px; border: 0; padding: 0; background: #2b2520 center / cover no-repeat; cursor: pointer; }
.imagen-enemigo:hover { outline: 2px solid var(--oro); }
.tarjeta-enemigo .fila { gap: .3rem; margin-top: .2rem; }
.tarjeta-enemigo .fila button { padding: .3em .6em; font-size: .85rem; }

/* Editor: fichas aún en su posición por defecto (sin colocar a mano). */
.ficha.por-defecto .disco { outline: 2px dashed #ffffffaa; outline-offset: 2px; }
