/* ==========================================
   CONFIGURACIÓN GLOBAL Y VARIABLES
   ========================================== */
:root {
    --cafe-oscuro: #5d4037;
    --color-titulo: #f8b18d;
    --color-etiqueta: #f8b18d;

    --cloud-color-blue: #AEE2E9; 
    --cloud-color-orange: #FFB38F;
    --cloud-color-yellow: #FEDB7E;
}

body { 
    margin: 0; 
    display: flex; 
    height: 100vh; 
    font-family: 'Poppins', sans-serif; 
    background: #2c3e50; 
    overflow: hidden; 
}

/* ==========================================
   PANEL LATERAL Y VISUALIZADOR
   ========================================== */
.sidebar { 
    width: 300px; 
    background: #ffffff; 
    padding: 25px; 
    box-shadow: 4px 0 15px rgba(0,0,0,0.3); 
    z-index: 1000; 
    overflow-y: auto; 
}

.field { margin-bottom: 15px; display: flex; flex-direction: column; gap: 5px; }

input[type="text"], select { 
    padding: 10px; 
    border: 1px solid #ddd; 
    border-radius: 5px; 
    font-family: inherit; 
    width: 100%; 
    box-sizing: border-box; 
}

.btn-add { 
    background: #27ae60; 
    color: white; 
    border: none; 
    padding: 15px; 
    cursor: pointer; 
    font-weight: bold; 
    border-radius: 8px; 
    width: 100%; 
}

.viewport {
    flex-grow: 1;
    display: block;
    background: #1a1a1a;
    padding: 40px;
    overflow: auto;
    height: 100vh;
}

#tree-container {
    overflow: hidden; 
    background-image: none !important; 
    width: 794px; 
    height: 1123px;
    position: relative;
    background-size: 100% 100%; 
    background-position: center;
    background-repeat: no-repeat;
    background-color: #fff;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    margin: 0 auto;
}

#tree-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: fill; 
    z-index: 1; 
    pointer-events: none; 
    /* MEJORA DE NITIDEZ */
    image-rendering: -webkit-optimize-contrast !important;
    image-rendering: crisp-edges !important;
}

/* ==========================================
   TÍTULO Y TEXTOS (MANTENIENDO TUS TAMAÑOS ORIGINALES)
   ========================================== */
#title-panel {
    position: absolute;
    top: 80px;
    left: 0;
    width: 100%;
    text-align: center;
    z-index: 10;
}

#nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
}

#main-title {
    font-size: 1rem;
    color: var(--cafe-oscuro);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
}

#surname-title {
    display: inline-block;
    font-family: 'Caveat', cursive;
    font-size: 5.5rem;
    color: var(--color-titulo);
    text-shadow: 2px 2px 0px var(--cafe-oscuro);
    margin: 0;
    cursor: text;
    outline: none;
}

/* ==========================================
   ESTILOS BASE DE FAMILIARES
   ========================================== */
.family-node { 
    position: absolute; 
    cursor: move; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    z-index: 100; 
    pointer-events: auto;
}

.btn-delete {
    position: absolute; top: -5px; right: -5px; background: #ff4757; color: white; 
    border: 2px solid white; border-radius: 50%; width: 26px; height: 26px; cursor: pointer;
    font-size: 16px; font-weight: bold; z-index: 200; display: flex; align-items: center; 
    justify-content: center; opacity: 0; transition: opacity 0.3s; z-index: 500 !important; pointer-events: auto !important;
}
.family-node:hover .btn-delete { opacity: 1; }

/* REGLA MAESTRA PARA NITIDEZ SIN CAMBIAR DISEÑO */
.photo-frame, .name-tag, .member-img, .frame-decoration, .tag-decoration {
    image-rendering: -webkit-optimize-contrast !important;
    image-rendering: crisp-edges !important;
    image-rendering: pixelated !important;
}

/* ==========================================
   TEMA 1: CARTOON
   ========================================== */
.theme-cartoon .photo-frame {
    width: 85px; height: 85px; border-radius: 50%;
    border: 3.5px solid var(--cafe-oscuro); 
    padding: 4px; display: flex; justify-content: center; align-items: center; overflow: hidden;
}
.theme-cartoon .photo-frame img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover;}
.theme-cartoon .name-tag {
    margin-top: 2px; color: var(--cafe-oscuro);
    padding: 6px 25px; text-align: center; font-family: 'Caveat', cursive;
    font-size: 1.4rem; font-weight: bold; position: relative;
    border-radius: 110px 20px 150px 30px / 15px 40px 20px 60px;
}
.theme-cartoon .name-tag::after {
    content: ''; position: absolute; top: 1.5px; left: 1.5px; right: 1.5px; bottom: 1.5px;
    border: 1.5px dotted var(--cafe-oscuro); border-radius: inherit; pointer-events: none; opacity: 0.6;
}

/* ==========================================
   TEMA 3: PIXAR
   ========================================== */
.theme-pixar #main-title { font-family: 'Luckiest Guy', cursive !important; color: #4b3621 !important; }
.theme-pixar #surname-title { font-family: 'Luckiest Guy', cursive !important; font-size: 5rem !important; text-shadow: 3px 3px 0px #4b3621; }
.theme-pixar .photo-frame { width: 90px; height: 90px; position: relative; display: block; overflow: hidden; margin: 0 auto; }
.theme-pixar .member-img { position: absolute; top: 13px; left: 11px; width: 68px; height: 68px; object-fit: cover; z-index: 5; }
.theme-pixar .name-tag { position: absolute; bottom: -30px; left: 50%; font-family: 'Luckiest Guy', cursive !important; margin-left: -45px; width: 90px; height: 30px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding-bottom: 15px; z-index: 50; }
.theme-pixar .member-name { font-size: 0.6rem !important; color: #4b3621 !important; line-height: 1; }
.theme-pixar .member-relation { font-size: 0.5rem !important; color: #c51919 !important; text-transform: uppercase; }

/* ==========================================
   TEMA 4: ELEGANTE
   ========================================== */
.theme-elegant #main-title { font-family: 'Poppins', sans-serif !important; letter-spacing: 5px; font-weight: 300; color: #4b3621 !important; }
.theme-elegant #surname-title { font-family: 'Playfair Display', serif !important; font-style: italic; font-size: 4.5rem !important; color: #b59410 !important; text-shadow: 2px 2px 4px rgba(0,0,0,0.3); }
.theme-elegant .photo-frame { width: 90px; height: 90px; position: relative; border-radius: 50%; display: flex; justify-content: center; align-items: center; }
.theme-elegant .member-img { width: 73px; height: 73px; border-radius: 50%; object-fit: cover; z-index: 5; }
.theme-elegant .name-tag { position: absolute; bottom: -15px; left: 50%; margin-left: -40px; width: 80px; height: 30px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding-bottom: 8px; z-index: 100; }
.theme-elegant .member-name { font-family: 'Playfair Display', serif !important; font-size: 0.6rem !important; color: #3e2723 !important; font-weight: bold; line-height: 0.9; }
.theme-elegant .member-relation { font-family: 'Playfair Display', serif !important; font-size: 0.4rem !important; font-style: italic; color: #5d4037 !important; text-transform: uppercase; }

/* ==========================================
   TEMA 4: VINTAGE (VERSIÓN FINAL ARRASTRABLE)
   ========================================== */
.theme-vintage #main-title { display: none !important; }
.theme-vintage #surname-title { 
    font-family: 'Special Elite', cursive !important; 
    font-size: 4rem !important; 
    color: #3e2723 !important; 
    margin-top: 45px; 
    display: block; 
}

.theme-vintage .family-node { 
    width: 130px; 
    height: 190px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    position: absolute;
    background: rgba(255,255,255,0.01) !important; /* Fondo casi invisible pero sólido para capturar el clic */
    z-index: 100;
    pointer-events: auto !important;
}

/* El marco vintage como base absoluta */
.theme-vintage .frame-decoration.frame-below {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    z-index: 0 !important; /* Capa más baja */
    object-fit: fill !important;
    pointer-events: none !important; /* No interfiere con el ratón */
    display: block !important;
}

.theme-vintage .photo-frame { 
    width: 80px; 
    height: 80px; 
    margin-top: 40px; 
    margin-bottom: 5px;
    position: relative; 
    z-index: 2 !important; 
    background: transparent !important;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none; /* El clic atraviesa hacia el .family-node */
}

.theme-vintage .member-img { 
    width: 75px; 
    height: 75px; 
    border-radius: 50%; 
    border: 1px solid #c5a059; 
    object-fit: cover; 
}

.theme-vintage .name-tag { 
    margin-top: 3px; 
    width: 100% !important; 
    display: flex !important;
    flex-direction: column;
    align-items: center !important;
    justify-content: center;
    background: transparent !important;
    z-index: 3 !important; 
    position: relative;
    pointer-events: none; /* El clic atraviesa hacia el .family-node */
}

/* REGLA CRÍTICA PARA EL BOTÓN DE BORRAR */
.theme-vintage .btn-delete {
    position: absolute;
    top: 10px; /* Ajustado para el diseño vintage */
    right: 10px;
    z-index: 500 !important; /* Siempre por encima de todo */
    pointer-events: auto !important; /* Este SÍ recibe clics */
    opacity: 0; 
    transition: opacity 0.3s;
}

.theme-vintage:hover .btn-delete {
    opacity: 1;
}

.theme-vintage .member-name { 
    font-family: 'Special Elite', cursive !important; 
    font-size: 0.9rem !important; 
    color: #3e2723 !important; 
    font-weight: bold;
    text-align: center;
}

.theme-vintage .member-relation { 
    font-family: 'Oswald', sans-serif !important; 
    font-size: 0.65rem !important; 
    color: #5d4037 !important; 
    text-align: center;
    text-transform: uppercase;
}
/* ==========================================
   TEMA 5: CASUAL (NUBES)
   ========================================== */
.theme-casual #surname-title { color: var(--color-titulo) !important; font-family: 'Playfair Display', serif !important; font-size: 2.8rem !important; font-style: italic; text-shadow: none; }
.theme-casual .family-node { display: flex; flex-direction: column; align-items: center; filter: drop-shadow(0px 4px 6px rgba(0,0,0,0.1)); }
.theme-casual .photo-frame { width: 100px; height: 100px; border-radius: 50%; border: 4px solid #FFB38F; background: #fff; overflow: hidden; z-index: 2; display: flex; justify-content: center; align-items: center; }
.theme-casual .member-img { width: 100%; height: 100%; object-fit: cover; }
.theme-casual .name-tag { margin-top: -15px; padding: 10px 25px; border-radius: 50px; min-width: 80px; text-align: center; z-index: 1; }
.theme-casual .member-name { display: block; font-family: 'Comic Sans MS', sans-serif; font-weight: bold; color: #333; font-size: 0.95rem; }
.theme-casual .member-relation { display: block; font-family: 'Verdana', sans-serif; text-transform: uppercase; font-size: 0.7rem; color: #555; }

/* CLASES DE APOYO PARA MARCOS INYECTADOS */
.frame-decoration, .tag-decoration {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; object-fit: fill;
}
.tag-text-container { position: relative; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; }

/* LIMPIEZA DE FONDOS CSS PARA EVITAR DUPLICIDAD */
.theme-pixar .photo-frame, .theme-elegant .photo-frame, .theme-pixar .name-tag, .theme-elegant .name-tag, .theme-vintage .family-node {
    background-image: none !important;
}
.watermark-site {
    position: absolute;
    bottom: 20px; /* Distancia desde el borde inferior */
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.5); /* Color semi-transparente */
    z-index: 100;
    pointer-events: none; /* Para que no interfiera al mover nodos */
    font-family: sans-serif;
}

/* Ajuste de color según el tema para que siempre sea legible */
.theme-vintage .watermark-site, 
.theme-elegant .watermark-site {
    color: #3e2723; /* Marrón oscuro para temas antiguos */
    font-family: 'Special Elite', cursive;
}

.theme-cartoon .watermark-site,
.theme-pixar .watermark-site {
    color: #ffffff; /* Blanco para temas con fondos oscuros o coloridos */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}